NOTE: The patches in this file are taken from the CVS repository for the VisualBoyAdvance project; they are distributed under the same license as VisualBoyAdvance itself (GPL version 2 or later). diff -urN ../VisualBoyAdvance-1.7.2/.cvsignore ./.cvsignore --- ../VisualBoyAdvance-1.7.2/.cvsignore 1970-01-01 09:00:00 +0900 +++ ./.cvsignore 2004-01-21 12:40:10 +0900 @@ -0,0 +1,2 @@ +autom4te.cache +.DS_Store diff -urN ../VisualBoyAdvance-1.7.2/AUTHORS ./AUTHORS --- ../VisualBoyAdvance-1.7.2/AUTHORS 2004-05-22 23:02:30 +0900 +++ ./AUTHORS 2006-04-30 04:06:28 +0900 @@ -12,3 +12,4 @@ - KVA: ARM/THUMB disassembler - kxu: GTK+ interface - Yann Parmentier aka kohai: new icons +- Spacy: Windows, Visual Studio 2005, DirectX \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/ChangeLog.1.5.1 ./ChangeLog.1.5.1 --- ../VisualBoyAdvance-1.7.2/ChangeLog.1.5.1 1970-01-01 09:00:00 +0900 +++ ./ChangeLog.1.5.1 2003-07-19 21:03:55 +0900 @@ -0,0 +1,323 @@ +2003-06-08 Forgotten + + * src/Sound.cpp (soundMix): fixed sound ratio problem with DS channels + +2003-06-04 Forgotten + + * src/Cheats.cpp (cheatsAdd): fixed bug that changed ROM with some codes + +2003-06-03 Forgotten + + * src/RTC.cpp (rtcWrite): fixed problem on last day of the month + +2003-06-02 Forgotten + + * src/SDL.cpp: changed pause when inactive default to false + +2003-05-28 Forgotten + + * src/arm-new.h: added PowerPC assembly code contributed by Jeffrey Lim + * src/thumb.h: added PowerPC assembly code contributed by Jeffrey Lim + +2003-05-26 Forgotten + + * src/win32/skin.cpp: make skin region optional + * src/Cheats.cpp (cheatsCheckKeys): extra AR support + * src/win32/Win32.cpp (systemReadJoypad): disallow L+R,U+D to be pressed together + * src/SDL.cpp (systemReadJoypad): disallow L+R,U+D to be pressed together + +2003-05-22 Forgotten + + * src/Cheats.cpp: add support for AR codes (thanks P.S.) + +2003-05-20 Forgotten + + * src/win32/skinButton.cpp (OnMouseLeave): try to detect when mouse is not over button better + +2003-05-14 Forgotten + + * src/win32/OpenGL.cpp: fix fullscreen problem + * src/win32/Win32.cpp: fix stretch to fit problem + * src/win32/Direct3D.cpp: fix stretch to fit problem + * src/win32/GDIDisplay.cpp: fix speed display + +2003-05-13 Forgotten + + * src/VisualBoyAdvance.cfg: changed separator to equal sign + * src/win32/Wnd.cpp: added default and create message support + * src/win32/Win32.cpp (WindowProc): update menu with accelerators when changing modes + * src/win32/Commands.cpp (winAccelGetID): added method to retrieve accelerator IDs and minimize function + * src/win32/skin.cpp: added button support and error messages + * src/win32/skinButton.cpp: created + +2003-04-24 Forgotten + + * src/win32/AcceleratorManager.cpp (Load): allow user to delete the default accelerators + * src/win32/WriteAVI.cpp (SetSoundFormat): added sound support + * src/Mode5.cpp: minor rendering optimization + * src/Mode4.cpp: minor rendering optimization + * src/Mode3.cpp: minor rendering optimization + * src/Mode2.cpp: minor rendering optimization + * src/Mode1.cpp: minor rendering optimization + * src/Mode0.cpp: minor rendering optimization + * src/GBA.cpp (CPUUpdateRenderBuffers): minor rendering improvement + +2003-04-19 Forgotten + + * src/win32/Win32.cpp (initApp): fixed Gameboy Printer initialization + * src/win32/Win32.cpp (WindowProc): fixed popup menu problem on Win 95/98/Me (unimplemented Unicode functions) + * src/win32/AcceleratorManager.cpp (UpdateMenu): take into account Win 95/98/Me + +2003-04-15 Forgotten + + * src/win32/skin.cpp (Hook): moved SetWindowRgn to after resizing and style change + +2003-04-07 Forgotten + + * VBA: too many changes to detail... + +2003-02-02 Forgotten + + * src/win32/Win32.cpp: added throttle support + * src/GBA.cpp (CPUUpdateRegister): fixed some wrong timer assumption (bad copy/paste) + +2003-01-29 Forgotten + + * src/win32/Win32.cpp: use registry or INI to store settings + * src/win32/Reg.cpp: use registry or INI to store settings + * src/win32/AcceleratorManager.cpp: use Reg.cpp to store settings + +2003-01-25 Forgotten + + * src/win32/Win32.cpp (WindowProc): minimize problem when minimizing emulator in fullscreen mode and filter is active + * src/win32/Win32.cpp (updateLayersMenu): added support to enable/disable GB/GBC layers + +2003-01-21 Forgotten + + * src/elf.cpp (elfReadProgram): added support for DW_FORM_strp + * src/interframe.cpp: added missing EMMS instructions to GCC inline assembly + * src/admame.cpp: added missing EMMS instructions to GCC inline assembly + +2003-01-20 Forgotten + + * src/win32/Win32.cpp (initApp): fixed disable SFX flag not being read + +2003-01-18 Forgotten + + * src/gb/GB.cpp (gbEmulate): changed interface with emulator for joypad + * src/GBA.cpp (CPULoop): changed interface with emulator for joypad + * src/win32/Win32.cpp: added support for multiple joypad configuration + +2003-01-14 Forgotten + + * src/win32/Win32.cpp (initApp): fixed problem when video mode was never selected + +2003-01-13 Forgotten + + * src/SDL.cpp: show detailed speed data + added auto frameskip support + CTRL+F to toggle fullscreen + +2003-01-12 Forgotten + + * src/win32/Win32.cpp: added some debugging for DDRAW and DINPUT + * src/win32/Win32.cpp: changed rendering when menu is active with triple buffering + +2003-01-11 Forgotten + + * src/GBA.cpp (CPULoop): set emulation speed value + * src/win32/Win32.cpp: added support for fullscreen speed display + * src/win32/Win32.cpp: support for triple buffering in fullscreen mode + * src/gb/GB.cpp (gbEmulate): set emulation speed value + * src/SDL.cpp: added support for fullscreen speed display + +2003-01-08 Forgotten + + * src/win32/Win32.cpp (systemMessage): fixed problem displaying error messages in fullscreen mode + * src/win32/Win32.cpp: added support to other resolutions for fullscreen mode + +2003-01-05 Forgotten + + * src/win32/Win32.cpp (detectMMX): added support for AMD CPUs + * src/win32/TileViewer.cpp: now shows all tiles in 256 mode + * src/elf.cpp (elfCleanUp): fixed crash when reloading an ELF file + * src/win32/Commands.cpp: added interframe blending commands + * src/win32/Win32.cpp: added interframe blending support + * src/SDL.cpp: added interframe blending support + +2003-01-03 Forgotten + + * src/win32/Win32.cpp: added bilinear filter support + * src/SDL.cpp: added bilinear filter support + +2002-12-11 Forgotten + + * src/Flash.cpp (flashSetSize): fixed reversed device ID and manufacturer ID + +2002-12-09 Forgotten + + * src/win32/Win32.cpp (fileExportGSASnapshot): change default title to internal name + * src/win32/Win32.cpp (WindowProc): added sound volume option + * src/win32/Win32.cpp (updateFileMenu): allow pausing even if not emulating yet + * src/win32/Win32.cpp: added AVI writing support + +2002-12-02 Forgotten + + * src/win32/Commands.cpp: added missing options + * src/win32/Win32.cpp (updateFilter): added 32-bit mode support for Kreed filters + * src/SDL.cpp (main): added 32-bit mode support for Kreed filters + * src/2xSaI.cpp (Scale_2xSaI): added 32-bit mode support + +2002-12-01 Forgotten + + * src/tvmode.cpp (TVMode32): 32-bit mode support + * src/simple2x.cpp (Simple2x32): 32-bit mode support + * src/pixel.cpp (Pixelate32): 32-bit mode support + * src/motionblur.cpp (MotionBlur32): 32-bit mode support + * src/admame.cpp (AdMame2x32): 32-bit mode support + * src/SDL.cpp (systemDrawScreen): added support for filters in 32-bit mode + * src/win32/Win32.cpp (updateFilter): added support for filters in 32-bit mode + +2002-11-29 Forgotten + + * src/Sound.cpp (soundMix): respect sound rations for CGB and DS + * src/GBA.cpp (CPULoadRom): fill memory to simulate no cartridge connected + +2002-11-28 Forgotten + + * src/GBA.cpp (CPULoop): renamed arm-new.cpp and thumb.cpp to .h + +2002-11-27 Forgotten + + * src/win32/Win32.cpp (fileOpen): add option for no IPS patching + * src/SDL.cpp (main): add option for no IPS patching + +2002-11-26 Forgotten + + * src/GBA.cpp (CPULoadRom): check for memory allocation error + * src/GBA.cpp (CPUWriteBatteryFile): fixed error message when failed to write battery file + +2002-11-25 Forgotten + + * src/SDL.cpp (systemSoundInit): correct sound type for big endian systems + * src/Gfx.h (gfxDrawSprites): fixed big endian problem with rotation sprites + * src/bios.cpp (BIOS_MidiKey2Freq): small clean up on logging + * src/win32/MemoryViewer.cpp (setCaretPos): show current edit address + * src/win32/MemoryViewer.cpp (OnLoad): added load/save memory support + * src/win32/RomInfo.cpp (OnInitDialog): fixed bug showing maker code/name in some old GB roms + +2002-11-24 Forgotten + + * src/SDL.cpp: added flag for help and configuration file + +2002-11-23 Forgotten + + * src/win32/GBACheats.cpp: cleaned up some unused stuff + * src/SDL.cpp: added support for long options + * src/Flash.cpp: added support for 128K Flash (thanks DesktopMan) + * src/GBA.cpp: added support for 128K Flash + +2002-11-21 Forgotten + + * src/gb/gbSGB.cpp: fixed big endian problems + * src/win32/Win32.cpp (updateVideoMenu): fixed missing check marks on layers menu + +2002-11-20 Forgotten + + * src/SDL.cpp (main): added profiling support + * src/GBA.cpp: added profiling support + * src/prof/prof.cpp: added profiling support + +2002-11-14 Forgotten + + * src/win32/Win32.cpp (systemWriteDataToSoundBuffer): remove test code that causes slowdown + +2002-11-13 Forgotten + + * src/SDL.cpp (sdlFindPreferences): improve search for configuration file + +2002-11-12 Forgotten + + * src/SDL.cpp (sdlReadPreferences): fixed incorrect variable being used for saveType + (main): removeIntros was not being used + (main): apply IPS patch automatically if it exists + * src/Util.cpp (utilApplyIPS): added IPS patching code + * src/win32/Win32.cpp (fileOpen): apply IPS patch automatically if it exists + +2002-11-07 Forgotten + + * src/SDL.cpp (main): fixed crash when trying load file that does not exist + * src/SDL.cpp (systemUpdateMotionSensor): implemented motion sensor for the SDL version + +2002-11-06 Forgotten + + * src/elf.cpp: fix wrong usage of CPUReadMemory + * src/admame.cpp: fixed incorrect #ifdef usage + * configure.in: added test for socklen_t type + * src/remote.cpp: fix problem compiling in some systems + * src/GBA.cpp (CPULoop): added support for movement sensor + * src/GBA.cpp (CPUReset): added support for selecting save type available + +2002-11-05 Forgotten + + * src/win32/DirectoriesDlg.cpp (browseForDir): fix bug when changing directory using the Browse button + +2002-11-04 Forgotten + + * src/GBA.cpp (CPUUpdateRegister): do not change timer data when writting to register TMxD. Only a restart or overflow will change the value + +2002-11-02 Forgotten + + * src/GBA.cpp (CPUWriteGSASnapshot): Compute CRC of save + +2002-10-31 Forgotten + + * src/GBA.cpp (CPUWriteGSASnapshot): fixed a few bytes in the snapshot + * src/Sound.cpp (soundEvent): fixed envelope reload bugs + * src/bios.cpp (BIOS_MidiKey2Freq): Added method (user contribution) + * src/Gfx.h: fixed problems in big endian machines + +2002-10-29 Forgotten + + * src/thumb.cpp: fixed bugs in C core + +2002-10-28 Forgotten + + * src/GBA.cpp (CPUSoftwareInterrupt): improved message about BIOS calls that are not emulated and need a BIOS file + * src/GBA.cpp (CPUInit): fix bug setting reable IO positions + +2002-10-27 Forgotten + + * src/SDL.cpp (sdlReadPreferences): Fixed warning if MMX not in use when reading the configuration file + * src/SDL.cpp (main): Fixed crash if BIOS file not specified correctly + * src/win32/Win32.cpp: Support for higher frameskip + * src/SDL.cpp: Support for higher frameskip + +2002-10-26 Forgotten + + * src/win32/Win32.cpp: Add 800x600 support + +2002-10-25 Forgotten + + * src/win32/Win32.cpp (fileExportGSASnapshot): added code + * src/win32/ExportGSASnapshot.cpp: Created dialog + * src/win32/Commands.cpp: Added new menu options + +2002-10-24 Forgotten + + * src/GBA.cpp (CPUReadGSASnapshot): Now skipping notes if they exist + +2002-10-23 Forgotten + + * src/win32/Win32.cpp (initApp): remember freeze recent list flag + +2002-10-22 Forgotten + + * win32/.cvsignore: added output directories and MSVC files to ignore + * src/win32/.cvsignore: Added vba.aps to ignore list + * src/TestEmu.cpp (systemPauseOnFrame): Added missing return statement + * INSTALL: Updated GCC requirements + * src/win32/Win32.cpp: added flag to freeze recent list + * src/win32/vba.rc: added flag to freeze recent list + * Initial Public Version + diff -urN ../VisualBoyAdvance-1.7.2/ChangeLog.1.7 ./ChangeLog.1.7 --- ../VisualBoyAdvance-1.7.2/ChangeLog.1.7 1970-01-01 09:00:00 +0900 +++ ./ChangeLog.1.7 2004-01-20 09:45:50 +0900 @@ -0,0 +1,157 @@ +2003-09-03 Forgotten + + * src/armdis.cpp: fixed thumb disassembly bug with ldsb and ldrh opcodes + +2003-08-23 Forgotten + + * src/win32/Win32.cpp (updateRenderMethod0): return true if render type did not change + * src/bios.cpp (BIOS_CpuSet): fixed bug introduced in previous fix + * src/GBA.cpp (CPULoop): fixed slowdown problem introduced in version 1.6 + +2003-08-09 Forgotten + + * src/GBA.cpp (CPUCheckDMA): fix minor DMA problem introduced with previous fixes + * src/GBA.cpp: fix DMA timings and add DMA hack fix + * src/Util.cpp (utilGBAFindSave): change search slightly + * src/agbprint.cpp (agbPrintWrite): return true to avoid warning message + * src/win32/TileViewer.cpp (OnMapInfo): fixed tile information when in 256 color mode + * src/win32/Win32.cpp (initApp): fix bug when initially switching to INI + +2003-08-02 Forgotten + + * src/win32/TileViewer.cpp (render): fixed TileViewer for 256 color display (incorrect tile and address) + +2003-08-01 Forgotten + + * src/win32/Win32.cpp (initApp): changed default rewind interval to 0 (disabled) + * src/bios.cpp (BIOS_CpuFastSet): fixed + * src/bios.cpp (BIOS_CpuSet): fixed + +2003-07-21 Forgotten + + * src/win32/Win32.cpp (fileMoviePlay): added message when playing movie + * src/Sound.cpp (soundTick): produce mute sound while in sleep state + * src/GBA.cpp (CPULoop): improve stop state/sleep support + +2003-07-19 Forgotten + + * src/win32/Win32.cpp (updateFileMenu): allow customize in fullscreen (not at 320x240 though) + +2003-07-18 Forgotten + + * src/win32/MapView.cpp (renderTextScreen): fixed rendering when 512x512 + * src/win32/MapView.cpp (GetTextClickAddress): fixed click address for text screens when size > 256 + +2003-07-16 Forgotten + + * src/Sound.cpp (soundEvent): fix sound envelope bug when set to 0 + +2003-07-15 Forgotten + + * src/TestEmu.cpp (systemGbBorderOn): fixed TestEmu compilation + * src/SDL.cpp: added save type NONE support + * src/win32/Win32.cpp (helpBugReport): fixed bug with bug report when emulating GB/GBC program + +2003-07-13 Forgotten + + * src/Util.cpp (utilGBAFindSave): added enhanced save type detection + +2003-07-09 Forgotten + * src/SDL.cpp: rewind default to disabled + * src/win32/Win32.cpp: rewind default to disabled + * src/win32/RewindInterval.cpp (OnOk): allow a rewind interval between 0 and 600 seconds - 0 to disable it + * src/win32/Win32.cpp (fileMoviePlay): put a warning when playing a movie + * src/GBA.cpp (CPUReadState): fix sound problem loading old save states + +2003-07-08 Forgotten + + * src/armdis.cpp: fixed thumb disassembly bug + * src/win32/Win32.cpp: fix rewind enable and reset when loading a game + * src/win32/Reg.cpp (regQueryBinaryValue): fix problem saving binary settings into INI + +2003-07-05 Forgotten + + * src/Mode0.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + * src/Mode1.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + * src/Mode2.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + * src/Mode3.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + * src/Mode4.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + * src/Mode5.cpp (mode0RenderLineAll): fixed priority between OBJ Win and Windows + +2003-07-04 Forgotten + + * src/win32/Win32.cpp: menu toggle can have a customizable accelerator + * src/win32/Commands.cpp: added file toggle menu + +2003-07-02 Forgotten + + * src/SDL.cpp: fixed type on pause-when-inactive option + +2003-06-29 Forgotten + + * src/win32/Reg.cpp (regExportSettingsToINI): also exporting settings for viewers + +2003-06-28 Forgotten + + * src/win32/Win32.cpp (WindowProc): added rewind interval configuration + * src/bios.cpp (BIOS_SndDriverJmpTableCopy): simple emulation of function 0x2a + +2003-06-26 Forgotten + + * src/win32/Win32.cpp: added movie version for future updates + +2003-06-25 Forgotten + + * src/win32/Win32.cpp (helpFAQ): added FAQ menu to take to website + +2003-06-24 Forgotten + + * src/win32/Win32.cpp (helpBugReport): added bug report option + * src/SDL.cpp: added rewind support + +2003-06-21 Forgotten + + * src/GBA.cpp (CPULoadRom): speed up loading + +2003-06-20 Forgotten + + * src/gb/GB.cpp: added rewind support + +2003-06-19 Forgotten + + * src/Cheats.cpp (cheatsCheckKeys): added support for slowdown codes + * src/elf.cpp (elfGetAddressSymbol): fix crash debugging the initialization code + +2003-06-17 Forgotten + + * src/GBA.cpp: added rewind support + * src/Win32.cpp: added rewind support + * src/Util.cpp: added memory gzip support for rewind + +2003-06-15 Forgotten + + * src/Gfx.h (gfxDrawSprites): emulate sprite priority bug + * src/GBA.cpp: fix for DMA emulation problems + +2003-06-13 Forgotten + + * src/SDL.cpp: support for automatic SGB border + * src/win32/Win32.cpp (systemGbBorderOn): support for automatic SGB border + * src/gb/gbSGB.cpp: added support for automatic SGB border + * src/GBA.cpp: fixed bug with enable/disable layers introduced in version 1.5.1 + +2003-06-12 Forgotten + + * src/SDL.cpp: added sound off/enable support + * src/VisualBoyAdvance.cfg: added sound off/enable flags + * src/win32/Win32.cpp: added auto hide menu support + * src/GBA.cpp, src/gb/GB.cpp: code cleanup + +2003-06-11 Forgotten + + * src/win32/Win32.cpp: added movie support + +2003-06-10 Forgotten + + * GBACheats.cpp: fixed bug with enable/disable cheats + diff -urN ../VisualBoyAdvance-1.7.2/ChangeLog.1.7.1 ./ChangeLog.1.7.1 --- ../VisualBoyAdvance-1.7.2/ChangeLog.1.7.1 1970-01-01 09:00:00 +0900 +++ ./ChangeLog.1.7.1 2004-03-20 09:18:32 +0900 @@ -0,0 +1,97 @@ +2004-02-07 Forgotten + + * src/SDL.cpp (main): disable remove intros option + * src/win32/MainWndOptions.cpp (OnUpdateOptionsEmulatorRemoveintrosgba): disable remove intros option + * src/win32/MainWnd.cpp: disable remove intros option + * src/win32/VBA.cpp: fix power management code + * src/win32/MainWnd.cpp (OnMySysCommand): fix power management code + * src/win32/MainWndFile.cpp: fix power management code + +2004-02-06 Forgotten + + * src/Sound.cpp (soundSetQuality): avoid turning sound on if sound off is checked + * src/gb/gbSound.cpp (gbSoundSetQuality): avoid turning sound on if sound off is checked + * src/GBA.cpp (CPUSoftwareInterrupt): added SWI call to exit emulator + +2004-02-05 Forgotten + + * src/win32/MainWnd.cpp (FileRun): update battery file more often + * src/win32/VBA.cpp (system10Frames): update battery file more often + * src/gb/gbMemory.cpp: update battery file more often + * src/gb/GB.cpp: update battery file more often + * src/System.h: update battery file more often + * src/Sram.cpp (sramWrite): update battery file more often + * src/SDL.cpp (main): update battery file more often + * src/GBA.cpp: update battery file more often + * src/Flash.cpp (flashWrite): update battery file more often + * src/EEprom.cpp (eepromWrite): update battery file more often + +2004-01-30 Forgotten + + * src/win32/OpenGL.cpp (render): fix memory leak in OpenGL rendering + +2004-01-29 Forgotten + + * src/gb/gbCodes.h: fix HALT when no matching in IE and IF + +2004-01-28 Forgotten + + * src/prof/prof.cpp: fix compile warnings + * src/win32/MainWndTools.cpp: switch to use structure functions + * src/win32/MainWndFile.cpp: switch to use structure functions + * src/win32/VBA.cpp (VBA): use structure instead of individual functions for emulation + * src/win32/VBA.h (class VBA): use structure instead of individual functions for emulation + * src/win32/MainWnd.cpp: switch to use structure functions + * src/System.h: structure for emulator functions + * src/win32/MainWnd.cpp (FileRun): save rom size for later use + * src/win32/BugReport.cpp (createReport): include cart save strings to bug report + +2004-01-25 Forgotten + + * src/win32/AboutDialog.cpp (OnInitDialog): fix problem with translator URLs not working correctly and force URL to new site + * src/win32/MainWndHelp.cpp (OnHelpFaq): update FAQ URL to new site + +2004-01-21 Forgotten + + * src/Util.cpp (utilLoad): fix possible memory corruption when loading files with a passed in memory location + +2004-01-20 Forgotten + + * src/Port.h (READ32LE): big endian updates from flea + * src/GBA.cpp: big endian updates from flea + * src/Cheats.cpp: big endian updates from flea + * src/win32/VBA.cpp (VBA): initialize default GB color palette + * src/win32/Direct3D.cpp (initialize): avoid resetting GB colors set by user + * src/win32/OpenGL.cpp (initialize): avoid resetting GB colors set by user + * src/win32/GDIDisplay.cpp (initialize): avoid resetting GB colors set by user + * src/win32/DirectDraw.cpp (initializeOffscreen): avoid resetting GB colors set by user + +2004-01-19 Forgotten + + * src/gb/GB.cpp (gbEmulate): reset the window line before starting a new frame + * src/elf.cpp (elfRead): fix memory leak + * src/GBA.cpp (CPULoadRom): avoid crash with invalid ELF file + +2004-01-18 Forgotten + + * src/win32/FileDlg.cpp (FileDlg): fix problem on 320x240 mode + * src/win32/ZoomControl.cpp (OnPaint): fix crash on map/oam/tile viewer + +2004-01-16 Forgotten + + * win32/GBMemoryViewerDlg.cpp (OnLoad): fixed bug loading memory dump + * win32/MemoryViewerDlg.cpp (OnLoad): fixed bug loading memory dump + +2004-01-15 Forgotten + + * win32/VBA.cpp: store throttle value + +2004-01-14 Forgotten + + * win32/VBA.cpp (adjustDestRect): fix multi-mon support + * win32/FileDlg.cpp (FileDlg): fix problem on VC 7.1 + * win32/MainWnd.cpp (OnActivateApp): fix compile errors on VC 7.1 + * win32/GBCheatsDlg.cpp: fix compile errors on VC 7.1 + * win32/GBACheats.cpp: fix compile errors on VC 7.1 + * bios.cpp: fix compile errors on VC 7.1 + diff -urN ../VisualBoyAdvance-1.7.2/INSTALL ./INSTALL --- ../VisualBoyAdvance-1.7.2/INSTALL 2004-05-22 23:06:32 +0900 +++ ./INSTALL 2006-08-25 21:28:38 +0900 @@ -65,6 +65,49 @@ 2. Windows ---------- +2.1 Visual C++ 2005 Express Edition +----------------------------------- + +If you want to use the free express edition of Visual C++ 2005, +you have to do the following steps prior to the normal setup procedure of Visual C++/Studio 2005: +!!! You will not be able to build the MFC (GUI) version of VBA, only the SDL build will succeed !!! +- First download and install VC++ 2005 Express from http://msdn.microsoft.com/vstudio/express/visualC/default.aspx +- Now follow the guide at http://msdn2.microsoft.com/en-us/library/ms235626.aspx +- Now continue with section [2.2] + +2.2 Visual C++ 2005 +------------------- + +Needed software: +- Microsoft Visual C++ 2005 (buy if not using Express Edition or if MFC build is required) + > http://msdn.microsoft.com/visualc/ + > You do not need the DLL runtimes and the .NET Framework +- Microsoft Platform SDK (free, optional, essential only for express edition) + > http://www.microsoft.com/downloads/details.aspx?FamilyId=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&displaylang=en +- Microsoft DirectX 9.0 SDK (free, essential) + > http://msdn.com/directx/sdk + (August 2006 version as I write these lines) +- Yasm (free, essential) + > http://www.tortall.net/projects/yasm/ + > Follow the install guide at http://www.tortall.net/projects/yasm/wiki/VisualStudio2005 +- AMD CodeAnalyst (optional, AMD CPU required) + > http://developer.amd.com/cawin.aspx?session_id=FB$37649@DJEBIGID + > Free and easy profiling for AMD CPUs (32bit and 64bit), Visual Studio 2005 plugin + + Those are all packages for now. The VBA source also includes the + sources and/or binaries of various free libraries for zip and image support. + Those can be accessed through the "dependencies" folder in the main + solution file. The main solution file includes references to all files + for all platforms. At the moment, only MFC and SDL build targets for + 32bit Windows are configured. GTK+ and 64bit Windows support are also possible, + but are not yet added for several reasons. + + You can now open the project file: "win32/vba_vs2005.sln". + Info: If you use the express edition of VC++ 2005, you will receive three neglectable warnings. + +2.3 Visual C++ 6.0 and Visual C++ 2002 +-------------------------------------- + Needed software: - nasm: see above for URL. Install it in the default directory - Microsoft Visual C++ 6.0 or greater: to compile diff -urN ../VisualBoyAdvance-1.7.2/Makefile.in ./Makefile.in --- ../VisualBoyAdvance-1.7.2/Makefile.in 2004-05-14 06:39:02 +0900 +++ ./Makefile.in 2004-09-30 07:23:13 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/NEWS ./NEWS --- ../VisualBoyAdvance-1.7.2/NEWS 2004-05-21 05:22:43 +0900 +++ ./NEWS 2004-12-21 00:02:43 +0900 @@ -1,3 +1,52 @@ +Version 1.8.0: +Core changes: +- added almost all AR V3 cheat codes (PokemonHacker) +- added prefetch emulation +- added full CBA support (verified for every CBA code type) +- added emulation for DMA interaction with reading from invalid address +- fixed CPU init for 256Mbit roms +- fixed HuffUnComp bug regarding tree size (SF #984608) +- fixed RTC support for day of the week (fixed at Sunday before) +- fixed loading of ELF multiboot files (thanks J.W.) +- fixed bug on CBA code type 5 +- fixed OBJWIN rendering bug when sprite wraps around (SF #1065447) +- fixed battery saving bug when save type equals to Flash or Sram +- fixed a compilation warning +- fixed BIOS ArcTan and ArcTan2 emulation (several bugs) +- fixed some instruction having incorrect cycles (caused SDL debugger to skip several instructions) +- fixed lq2x filter (was using hq2x code) +- fixed some bugs with IntrWait emulation +- fixed some timer bugs +- fixed memory timing when loading a save state (was using the timings before loading the state) +- fixed bug writing to IO register past 0x4000400 (no mirroring) +- initialize sram and flash memory to 0xff instead of 0x00 +- clean flash/sram on load/reload +- ignore 8-bit writes to OBJ and OAM memory +- major AR V1/2/3 support by PokemonHacker +- simplified GBA emulation loop (easier to understand and maintain) + +Windows: +- added dialog to edit game overrides +- added GPL link to Help menu +- fixed GB Disassemble crash when going to another address +- fixed a minor repaint bug when focus changed +- fixed problem displaying rom names that use & character +- fixed palette save name bug +- moved vsync code to where it should be +- moved common palette initialization and cleaned up rendering code to use it + +SDL versions: +- SDL debugger improvements adapted from VBA-H: + - break on change + - conditional breakpoints (ARM and THUMB) + - dump load and save (memory) + - edit register (exception of R15) + - disassemble to file + - save and load state from debugger + +Other: +- fixed some compilation issues (libpng, gtkmm) + Version 1.7.2: Core changes: - fixed bugs on ELF clean up diff -urN ../VisualBoyAdvance-1.7.2/README ./README --- ../VisualBoyAdvance-1.7.2/README 2004-05-22 23:05:38 +0900 +++ ./README 2004-12-21 00:02:43 +0900 @@ -1,4 +1,4 @@ -Welcome to version 1.7.2 of VisualBoyAdvance [SDL]. +Welcome to version 1.8.0 of VisualBoyAdvance [SDL]. This is a GB/GBC/GBA emulator for Windows, Linux, MacOS X and BeOS. Features diff -urN ../VisualBoyAdvance-1.7.2/README-win.txt ./README-win.txt --- ../VisualBoyAdvance-1.7.2/README-win.txt 2004-05-22 22:57:38 +0900 +++ ./README-win.txt 2006-08-24 07:11:54 +0900 @@ -1,4 +1,4 @@ -Welcome to VisualBoyAdvance version 1.7.2. +Welcome to VisualBoyAdvance version 1.8.0. Compiling the sources --------------------- @@ -40,11 +40,13 @@ The 1 thorugh 4 joypads allow you to have different settings which can be easily switched. -System requirements -------------------- +Recommended System Requirements +------------------------------- -Fast computer (Pentium III 500 Mhz recommended) and Microsoft DirectX 7 or -greater. +CPU: 800MHz with MMX & SSE +RAM: 64MB free +GPU: Graphics card with drivers supporting DirectX9 +OS: Windows 2000 with DirectX9 runtime Translations ------------ @@ -147,6 +149,7 @@ can defined the following settings on a per game basis by using an INI file called vba-over.ini in the same directory as the emulator: +comment=You can add any text you like here, for example the full name of the game, but not exceeding 255 characters rtcEnabled=<0 for false, anything else for true> flashSize=<65536 or 131072> saveType=<0 for automatic, 1 for EEPROM, 2 for SRAM, 3 for Flash or 4 for @@ -164,6 +167,9 @@ flashSize=131072 saveType=0 +An easier way to change the per game settings is to use the Game overrides dialog in the MFC version of VBA. +Select Menu>Options>Emulator>Game Overrides... to open the dialog. Just make your changes and click OK. + FAQ --- diff -urN ../VisualBoyAdvance-1.7.2/VERSION ./VERSION --- ../VisualBoyAdvance-1.7.2/VERSION 2004-03-24 02:21:53 +0900 +++ ./VERSION 2004-12-21 00:02:43 +0900 @@ -1 +1 @@ -VisualBoyAdvance 1.7.2 +VisualBoyAdvance 1.8.0 diff -urN ../VisualBoyAdvance-1.7.2/aclocal.m4 ./aclocal.m4 --- ../VisualBoyAdvance-1.7.2/aclocal.m4 2004-05-14 06:38:53 +0900 +++ ./aclocal.m4 2004-09-30 07:10:53 +0900 @@ -1647,6 +1647,64 @@ LEX=${am_missing_run}flex fi]) + +dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not) +dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page +dnl also defines GSTUFF_PKG_ERRORS on error +AC_DEFUN(PKG_CHECK_MODULES, [ + succeeded=no + + if test -z "$PKG_CONFIG"; then + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + fi + + if test "$PKG_CONFIG" = "no" ; then + echo "*** The pkg-config script could not be found. Make sure it is" + echo "*** in your path, or set the PKG_CONFIG environment variable" + echo "*** to the full path to pkg-config." + echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config." + else + PKG_CONFIG_MIN_VERSION=0.9.0 + if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then + AC_MSG_CHECKING(for $2) + + if $PKG_CONFIG --exists "$2" ; then + AC_MSG_RESULT(yes) + succeeded=yes + + AC_MSG_CHECKING($1_CFLAGS) + $1_CFLAGS=`$PKG_CONFIG --cflags "$2"` + AC_MSG_RESULT($$1_CFLAGS) + + AC_MSG_CHECKING($1_LIBS) + $1_LIBS=`$PKG_CONFIG --libs "$2"` + AC_MSG_RESULT($$1_LIBS) + else + $1_CFLAGS="" + $1_LIBS="" + ## If we have a custom action on failure, don't print errors, but + ## do set a variable so people can do so. + $1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` + ifelse([$4], ,echo $$1_PKG_ERRORS,) + fi + + AC_SUBST($1_CFLAGS) + AC_SUBST($1_LIBS) + else + echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer." + echo "*** See http://www.freedesktop.org/software/pkgconfig" + fi + fi + + if test $succeeded = yes; then + ifelse([$3], , :, [$3]) + else + ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4]) + fi +]) + + + # gettext.m4 serial 28 (gettext-0.13) dnl Copyright (C) 1995-2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU @@ -4277,61 +4335,3 @@ fi ]) - -dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not) -dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page -dnl also defines GSTUFF_PKG_ERRORS on error -AC_DEFUN(PKG_CHECK_MODULES, [ - succeeded=no - - if test -z "$PKG_CONFIG"; then - AC_PATH_PROG(PKG_CONFIG, pkg-config, no) - fi - - if test "$PKG_CONFIG" = "no" ; then - echo "*** The pkg-config script could not be found. Make sure it is" - echo "*** in your path, or set the PKG_CONFIG environment variable" - echo "*** to the full path to pkg-config." - echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config." - else - PKG_CONFIG_MIN_VERSION=0.9.0 - if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then - AC_MSG_CHECKING(for $2) - - if $PKG_CONFIG --exists "$2" ; then - AC_MSG_RESULT(yes) - succeeded=yes - - AC_MSG_CHECKING($1_CFLAGS) - $1_CFLAGS=`$PKG_CONFIG --cflags "$2"` - AC_MSG_RESULT($$1_CFLAGS) - - AC_MSG_CHECKING($1_LIBS) - $1_LIBS=`$PKG_CONFIG --libs "$2"` - AC_MSG_RESULT($$1_LIBS) - else - $1_CFLAGS="" - $1_LIBS="" - ## If we have a custom action on failure, don't print errors, but - ## do set a variable so people can do so. - $1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` - ifelse([$4], ,echo $$1_PKG_ERRORS,) - fi - - AC_SUBST($1_CFLAGS) - AC_SUBST($1_LIBS) - else - echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer." - echo "*** See http://www.freedesktop.org/software/pkgconfig" - fi - fi - - if test $succeeded = yes; then - ifelse([$3], , :, [$3]) - else - ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4]) - fi -]) - - - diff -urN ../VisualBoyAdvance-1.7.2/configure ./configure --- ../VisualBoyAdvance-1.7.2/configure 2004-05-14 06:39:06 +0900 +++ ./configure 2006-09-04 06:52:24 +0900 @@ -309,7 +309,7 @@ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE YACC LEX LEXLIB LEX_OUTPUT_ROOT CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE RANLIB ac_ct_RANLIB NASM CPP EGREP SDL_CONFIG SDL_CFLAGS SDL_LIBS MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE LIBICONV LTLIBICONV INTLLIBS LIBINTL LTLIBINTL POSUB GETTEXT_PACKAGE PKG_CONFIG GTKMM_CFLAGS GTKMM_LIBS GTKMM_CPPFLAGS VBA_EXTRA VBA_SRC_EXTRA VBA_LIBS LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE am__leading_dot CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE YACC LEX LEXLIB LEX_OUTPUT_ROOT CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE RANLIB ac_ct_RANLIB NASM PKG_CONFIG LIBPNG_CFLAGS LIBPNG_LIBS CPP EGREP SDL_CONFIG SDL_CFLAGS SDL_LIBS MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE LIBICONV LTLIBICONV INTLLIBS LIBINTL LTLIBINTL POSUB GETTEXT_PACKAGE GTKMM_CFLAGS GTKMM_LIBS GTKMM_CPPFLAGS VBA_EXTRA VBA_SRC_EXTRA VBA_LIBS LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -1705,7 +1705,7 @@ # Define the identity of the package. PACKAGE=VisualBoyAdvance - VERSION=1.7.2 + VERSION=1.8.0 cat >>confdefs.h <<_ACEOF @@ -3950,83 +3950,6 @@ fi -echo "$as_me:$LINENO: checking for png_create_write_struct in -lpng" >&5 -echo $ECHO_N "checking for png_create_write_struct in -lpng... $ECHO_C" >&6 -if test "${ac_cv_lib_png_png_create_write_struct+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpng -lz $LIBS" -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char png_create_write_struct (); -int -main () -{ -png_create_write_struct (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_png_png_create_write_struct=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_lib_png_png_create_write_struct=no -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:$LINENO: result: $ac_cv_lib_png_png_create_write_struct" >&5 -echo "${ECHO_T}$ac_cv_lib_png_png_create_write_struct" >&6 -if test $ac_cv_lib_png_png_create_write_struct = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBPNG 1 -_ACEOF - - LIBS="-lpng $LIBS" - -else - { { echo "$as_me:$LINENO: error: *** Cannot compile without libpng." >&5 -echo "$as_me: error: *** Cannot compile without libpng." >&2;} - { (exit 1); exit 1; }; } -fi - - echo "$as_me:$LINENO: checking for pthread_yield in -lpthread" >&5 echo $ECHO_N "checking for pthread_yield in -lpthread... $ECHO_C" >&6 if test "${ac_cv_lib_pthread_pthread_yield+set}" = set; then @@ -4100,6 +4023,107 @@ fi + + succeeded=no + + if test -z "$PKG_CONFIG"; then + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_path_PKG_CONFIG+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + + test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no" + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG + +if test -n "$PKG_CONFIG"; then + echo "$as_me:$LINENO: result: $PKG_CONFIG" >&5 +echo "${ECHO_T}$PKG_CONFIG" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + fi + + if test "$PKG_CONFIG" = "no" ; then + echo "*** The pkg-config script could not be found. Make sure it is" + echo "*** in your path, or set the PKG_CONFIG environment variable" + echo "*** to the full path to pkg-config." + echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config." + else + PKG_CONFIG_MIN_VERSION=0.9.0 + if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then + echo "$as_me:$LINENO: checking for libpng" >&5 +echo $ECHO_N "checking for libpng... $ECHO_C" >&6 + + if $PKG_CONFIG --exists "libpng" ; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + succeeded=yes + + echo "$as_me:$LINENO: checking LIBPNG_CFLAGS" >&5 +echo $ECHO_N "checking LIBPNG_CFLAGS... $ECHO_C" >&6 + LIBPNG_CFLAGS=`$PKG_CONFIG --cflags "libpng"` + echo "$as_me:$LINENO: result: $LIBPNG_CFLAGS" >&5 +echo "${ECHO_T}$LIBPNG_CFLAGS" >&6 + + echo "$as_me:$LINENO: checking LIBPNG_LIBS" >&5 +echo $ECHO_N "checking LIBPNG_LIBS... $ECHO_C" >&6 + LIBPNG_LIBS=`$PKG_CONFIG --libs "libpng"` + echo "$as_me:$LINENO: result: $LIBPNG_LIBS" >&5 +echo "${ECHO_T}$LIBPNG_LIBS" >&6 + else + LIBPNG_CFLAGS="" + LIBPNG_LIBS="" + ## If we have a custom action on failure, don't print errors, but + ## do set a variable so people can do so. + LIBPNG_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libpng"` + echo $LIBPNG_PKG_ERRORS + fi + + + + else + echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer." + echo "*** See http://www.freedesktop.org/software/pkgconfig" + fi + fi + + if test $succeeded = yes; then + : + else + { { echo "$as_me:$LINENO: error: Library requirements (libpng) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&5 +echo "$as_me: error: Library requirements (libpng) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&2;} + { (exit 1); exit 1; }; } + fi + +CPPFLAGS="$CPPFLAGS $LIBPNG_CFLAGS" +LIBS="$LIBS $LIBPNG_LIBS" + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4338,6 +4362,7 @@ echo "$as_me:$LINENO: checking for X" >&5 echo $ECHO_N "checking for X... $ECHO_C" >&6 +ac_path_x_has_been_run=yes # Check whether --with-x or --without-x was given. if test "${with_x+set}" = set; then @@ -4430,7 +4455,7 @@ /usr/openwin/share/include' if test "$ac_x_includes" = no; then - # Guess where to find include files, by looking for Intrinsic.h. + # Guess where to find include files, by looking for a specified header file. # First, try using that file with no special directory specified. cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -4438,7 +4463,7 @@ cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include _ACEOF if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 @@ -4465,7 +4490,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 for ac_dir in $ac_x_header_dirs; do - if test -r "$ac_dir/X11/Intrinsic.h"; then + if test -r "$ac_dir/X11/Xlib.h"; then ac_x_includes=$ac_dir break fi @@ -4479,18 +4504,18 @@ # See if we find them without any special options. # Don't add to $LIBS permanently. ac_save_LIBS=$LIBS - LIBS="-lXt $LIBS" + LIBS="-lX11 $LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include int main () { -XtMalloc (0) +XrmInitialize () ; return 0; } @@ -4528,7 +4553,7 @@ do # Don't even attempt the hair of trying to link an X program! for ac_extension in a so sl; do - if test -r $ac_dir/libXt.$ac_extension; then + if test -r $ac_dir/libX11.$ac_extension; then ac_x_libraries=$ac_dir break 2 fi @@ -4564,8 +4589,12 @@ # Update the cache value to reflect the command line values. ac_cv_have_x="have_x=yes \ ac_x_includes=$x_includes ac_x_libraries=$x_libraries" - echo "$as_me:$LINENO: result: libraries $x_libraries, headers $x_includes" >&5 -echo "${ECHO_T}libraries $x_libraries, headers $x_includes" >&6 + # It might be that x_includes is empty (headers are found in the + # standard search path. Then output the corresponding message + ac_out_x_includes=$x_includes + test "x$x_includes" = x && ac_out_x_includes="in standard search path" + echo "$as_me:$LINENO: result: libraries $x_libraries, headers $ac_out_x_includes" >&5 +echo "${ECHO_T}libraries $x_libraries, headers $ac_out_x_includes" >&6 fi echo "$as_me:$LINENO: checking for egrep" >&5 @@ -5624,6 +5653,8 @@ VBA_LIBS="../gb/libgb.a" +CXXFLAGS="$CXXFLAGS -DBKPT_SUPPORT" + if test "x$enable_c_core" = xyes; then CXXFLAGS="$CXXFLAGS -DC_CORE" fi @@ -7819,7 +7850,7 @@ done - GETTEXT_PACKAGE=vba-1.7.2 + GETTEXT_PACKAGE=vba-1.8.0 @@ -8691,6 +8722,9 @@ s,@RANLIB@,$RANLIB,;t t s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t s,@NASM@,$NASM,;t t +s,@PKG_CONFIG@,$PKG_CONFIG,;t t +s,@LIBPNG_CFLAGS@,$LIBPNG_CFLAGS,;t t +s,@LIBPNG_LIBS@,$LIBPNG_LIBS,;t t s,@CPP@,$CPP,;t t s,@EGREP@,$EGREP,;t t s,@SDL_CONFIG@,$SDL_CONFIG,;t t @@ -8709,7 +8743,6 @@ s,@LTLIBINTL@,$LTLIBINTL,;t t s,@POSUB@,$POSUB,;t t s,@GETTEXT_PACKAGE@,$GETTEXT_PACKAGE,;t t -s,@PKG_CONFIG@,$PKG_CONFIG,;t t s,@GTKMM_CFLAGS@,$GTKMM_CFLAGS,;t t s,@GTKMM_LIBS@,$GTKMM_LIBS,;t t s,@GTKMM_CPPFLAGS@,$GTKMM_CPPFLAGS,;t t diff -urN ../VisualBoyAdvance-1.7.2/configure.in ./configure.in --- ../VisualBoyAdvance-1.7.2/configure.in 2004-05-14 06:38:35 +0900 +++ ./configure.in 2006-09-04 06:52:24 +0900 @@ -16,7 +16,7 @@ ;; esac -AM_INIT_AUTOMAKE(VisualBoyAdvance, 1.7.2) +AM_INIT_AUTOMAKE(VisualBoyAdvance, 1.8.0) AC_ARG_ENABLE(c-core, AC_HELP_STRING([--enable-c-core],[enable C core (default is no on x86 targets)]), @@ -63,10 +63,12 @@ dnl Checks for libraries. AC_CHECK_LIB(z, gzopen, , AC_MSG_ERROR([*** Cannot compile without zlib.])) -AC_CHECK_LIB(png, png_create_write_struct, - , AC_MSG_ERROR([*** Cannot compile without libpng.]), [-lz]) AC_CHECK_LIB(pthread, pthread_yield) +PKG_CHECK_MODULES(LIBPNG, libpng) +CPPFLAGS="$CPPFLAGS $LIBPNG_CFLAGS" +LIBS="$LIBS $LIBPNG_LIBS" + dnl Checks for header files. AC_PATH_X AC_HEADER_STDC @@ -102,6 +104,8 @@ VBA_LIBS="../gb/libgb.a" +CXXFLAGS="$CXXFLAGS -DBKPT_SUPPORT" + if test "x$enable_c_core" = xyes; then CXXFLAGS="$CXXFLAGS -DC_CORE" fi @@ -138,7 +142,7 @@ ALL_LINGUAS="fr" AM_GNU_GETTEXT(external) AC_CHECK_HEADERS(libintl.h) - GETTEXT_PACKAGE=vba-1.7.2 + GETTEXT_PACKAGE=vba-1.8.0 AC_SUBST(GETTEXT_PACKAGE) PKG_CHECK_MODULES(GTKMM, gtkmm-$gtk_version >= 2.0.0 libglademm-$gtk_version >= 2.1.0) diff -urN ../VisualBoyAdvance-1.7.2/fix-timestamps ./fix-timestamps --- ../VisualBoyAdvance-1.7.2/fix-timestamps 1970-01-01 09:00:00 +0900 +++ ./fix-timestamps 2004-01-18 08:09:27 +0900 @@ -0,0 +1,4 @@ +#! /bin/sh +touch acinclude.m4 aclocal.m4 +touch configure +touch `find . -name Makefile.in` diff -urN ../VisualBoyAdvance-1.7.2/m4/Makefile.in ./m4/Makefile.in --- ../VisualBoyAdvance-1.7.2/m4/Makefile.in 2004-05-14 06:39:37 +0900 +++ ./m4/Makefile.in 2004-09-30 07:23:40 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ Binary files ../VisualBoyAdvance-1.7.2/po/fr.gmo and ./po/fr.gmo differ diff -urN ../VisualBoyAdvance-1.7.2/po/fr.po ./po/fr.po --- ../VisualBoyAdvance-1.7.2/po/fr.po 2004-05-22 01:03:26 +0900 +++ ./po/fr.po 2006-09-04 06:52:24 +0900 @@ -9,29 +9,30 @@ msgstr "" "Project-Id-Version: VisualBoyAdvance 1.7.2\n" "Report-Msgid-Bugs-To: undefined\n" -"POT-Creation-Date: 2004-05-21 18:02+0200\n" -"PO-Revision-Date: 2004-05-21 18:03+0200\n" +"POT-Creation-Date: 2006-09-03 22:57+0200\n" +"PO-Revision-Date: 2006-09-03 23:45+0200\n" "Last-Translator: Sébastien Guignot \n" "Language-Team: French <@>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: src/Cheats.cpp:653 src/Cheats.cpp:658 src/Cheats.cpp:667 src/Cheats.cpp:675 +#: src/Cheats.cpp:1473 src/Cheats.cpp:1478 src/Cheats.cpp:1487 +#: src/Cheats.cpp:1495 #, c-format msgid "Invalid cheat code '%s'" msgstr "Cheat code incorrect '%s'" -#: src/Cheats.cpp:694 +#: src/Cheats.cpp:1524 #, c-format msgid "Invalid cheat code address: %08x" msgstr "Adresse de cheat code incorrecte : %08x" -#: src/Cheats.cpp:738 src/Cheats.cpp:747 +#: src/Cheats.cpp:1603 src/Cheats.cpp:1612 msgid "Invalid GSA code. Format is XXXXXXXXYYYYYYYY" msgstr "Code GSA incorrect. Le format est XXXXXXXXYYYYYYYY" -#: src/Cheats.cpp:773 +#: src/Cheats.cpp:1638 #, c-format msgid "" "Warning: cheats are for game %s. Current game is %s.\n" @@ -40,12 +41,12 @@ "Avertissement : les cheats sont pour le jeu %s. Le jeu courant est %s.\n" "Les codes peuvent ne pas fonctionner correctement." -#: src/Cheats.cpp:1307 src/Cheats.cpp:1316 src/Cheats.cpp:1323 -#: src/Cheats.cpp:1331 +#: src/Cheats.cpp:2458 src/Cheats.cpp:2467 src/Cheats.cpp:2474 +#: src/Cheats.cpp:2482 msgid "Invalid CBA code. Format is XXXXXXXX YYYY." msgstr "Code CBA incorrect. Le format est XXXXXXXX YYYY." -#: src/Cheats.cpp:1385 +#: src/Cheats.cpp:2538 msgid "" "Warning: Codes seem to be for a different game.\n" "Codes may not work correctly." @@ -53,86 +54,86 @@ "Avertissement : les codes semblent être faits pour un autre jeu.\n" "Ils peuvent ne pas fonctionner correctement." -#: src/Cheats.cpp:1545 src/gb/gbCheats.cpp:130 +#: src/Cheats.cpp:2723 src/gb/gbCheats.cpp:132 #, c-format msgid "Unsupported cheat list version %d" msgstr "Version de liste de cheats %d non supportée" -#: src/Cheats.cpp:1558 src/gb/gbCheats.cpp:143 +#: src/Cheats.cpp:2737 src/gb/gbCheats.cpp:145 #, c-format msgid "Unsupported cheat list type %d" msgstr "Type de liste de cheats %d non supporté" -#: src/elf.cpp:2814 +#: src/elf.cpp:2811 #, c-format msgid "Not a valid ELF file %s" msgstr "%s n'est pas un fichier ELF correct" -#: src/GBA.cpp:664 src/GBA.cpp:849 src/GBA.cpp:887 src/Util.cpp:61 -#: src/Util.cpp:270 src/gb/GB.cpp:1662 src/gb/GB.cpp:1679 src/gb/GB.cpp:1696 -#: src/gb/GB.cpp:1719 src/gb/GB.cpp:1736 +#: src/GBA.cpp:863 src/GBA.cpp:1084 src/GBA.cpp:1122 src/Util.cpp:69 +#: src/Util.cpp:278 src/gb/GB.cpp:2708 src/gb/GB.cpp:2728 src/gb/GB.cpp:2750 +#: src/gb/GB.cpp:2777 src/gb/GB.cpp:2797 src/gb/GB.cpp:2815 src/gb/GB.cpp:2845 #, c-format msgid "Error creating file %s" msgstr "Erreur lors de la création du fichier %s" -#: src/GBA.cpp:701 +#: src/GBA.cpp:900 #, c-format msgid "Unsupported VisualBoyAdvance save game version %d" msgstr "Version de sauvegarde VisualBoyAdvance %d non supportée" -#: src/GBA.cpp:715 +#: src/GBA.cpp:914 #, c-format msgid "Cannot load save game for %s" msgstr "Impossible de charger la sauvegarde pour %s" -#: src/GBA.cpp:724 +#: src/GBA.cpp:923 src/gb/GB.cpp:3628 msgid "Save game is not using the BIOS files" msgstr "La sauvegarde n'utilise pas de fichier BIOS" -#: src/GBA.cpp:727 +#: src/GBA.cpp:926 src/gb/GB.cpp:3631 msgid "Save game is using the BIOS file" msgstr "La sauvegarde utilise le fichier BIOS" -#: src/GBA.cpp:807 +#: src/GBA.cpp:1035 #, c-format msgid "Unsupported save type %d" msgstr "Type de sauvegarde %d non supporté" -#: src/GBA.cpp:922 src/GBA.cpp:989 src/Util.cpp:588 src/Util.cpp:700 -#: src/gb/gbCheats.cpp:400 src/gb/GB.cpp:1977 +#: src/GBA.cpp:1157 src/GBA.cpp:1224 src/Util.cpp:596 src/Util.cpp:708 +#: src/gb/gbCheats.cpp:409 src/gb/GB.cpp:3368 #, c-format msgid "Cannot open file %s" msgstr "Impossible d'ouvrir le fichier %s" -#: src/GBA.cpp:957 src/gb/GB.cpp:1991 +#: src/GBA.cpp:1192 src/gb/GB.cpp:3381 #, c-format msgid "Cannot import snapshot for %s. Current game is %s" msgstr "Impossible d'importer le snapshot pour %s. Le jeu courant est %s" -#: src/GBA.cpp:971 src/gb/GB.cpp:2018 +#: src/GBA.cpp:1206 src/gb/GB.cpp:3408 #, c-format msgid "Unsupported snapshot file %s" msgstr "Fichier snapshot %s non supporté" -#: src/GBA.cpp:1274 src/GBA.cpp:1280 src/GBA.cpp:1329 src/GBA.cpp:1336 -#: src/GBA.cpp:1343 src/GBA.cpp:1350 src/GBA.cpp:1357 src/GBA.cpp:1364 -#: src/GBA.cpp:1371 src/Util.cpp:767 src/Util.cpp:825 src/Util.cpp:933 +#: src/GBA.cpp:1508 src/GBA.cpp:1514 src/GBA.cpp:1563 src/GBA.cpp:1570 +#: src/GBA.cpp:1577 src/GBA.cpp:1584 src/GBA.cpp:1591 src/GBA.cpp:1598 +#: src/GBA.cpp:1605 src/Util.cpp:775 src/Util.cpp:833 src/Util.cpp:941 #, c-format msgid "Failed to allocate memory for %s" msgstr "Échec de l'allocation de mémoire pour : %s" -#: src/GBA.cpp:1292 src/Util.cpp:756 src/Util.cpp:802 src/Util.cpp:816 -#: src/Util.cpp:920 +#: src/GBA.cpp:1526 src/Util.cpp:764 src/Util.cpp:810 src/Util.cpp:824 +#: src/Util.cpp:928 #, c-format msgid "Error opening image %s" msgstr "Erreur lors de l'ouverture de l'image %s" -#: src/GBA.cpp:1606 +#: src/GBA.cpp:1859 #, c-format msgid "Unsupported ARM mode %02x" msgstr "Mode ARM %02x non supporté" -#: src/GBA.cpp:1839 +#: src/GBA.cpp:2198 #, c-format msgid "" "Unsupported BIOS function %02x called from %08x. A BIOS file is needed in " @@ -141,93 +142,111 @@ "Fonction du BIOS %02x non supportée appelée depuis %08x. Un fichier BIOS est " "nécessaire pour obtenir un comportement correct." -#: src/GBA.cpp:2947 +#: src/GBA.cpp:3400 msgid "Invalid BIOS file size" msgstr "Taille de fichier BIOS incorrecte" -#: src/RTC.cpp:157 +#: src/RTC.cpp:159 #, c-format msgid "Unknown RTC command %02x" msgstr "Commande RTC %02x inconnue" -#: src/Util.cpp:596 src/Util.cpp:616 src/Util.cpp:707 src/Util.cpp:727 +#: src/Util.cpp:604 src/Util.cpp:624 src/Util.cpp:715 src/Util.cpp:735 #, c-format msgid "Bad ZIP file %s" msgstr "Fichier ZIP incorrect : %s" -#: src/Util.cpp:639 src/Util.cpp:745 +#: src/Util.cpp:647 src/Util.cpp:753 #, c-format msgid "No image found on ZIP file %s" msgstr "Pas d'image trouvée dans le fichier ZIP %s" -#: src/Util.cpp:783 src/Util.cpp:838 src/Util.cpp:877 src/Util.cpp:946 +#: src/Util.cpp:791 src/Util.cpp:846 src/Util.cpp:885 src/Util.cpp:954 #, c-format msgid "Error reading image %s" msgstr "Erreur lors de la lecture de l'image %s" -#: src/Util.cpp:889 +#: src/Util.cpp:897 #, c-format msgid "No image found on RAR file %s" msgstr "Pas d'image trouvée dans le fichier RAR %s" -#: src/gb/gbCheats.cpp:194 src/gb/gbCheats.cpp:304 +#: src/gb/gbCheats.cpp:192 src/gb/gbCheats.cpp:310 msgid "Maximum number of cheats reached." msgstr "Le nombre maximum de cheats a été atteint." -#: src/gb/gbCheats.cpp:200 +#: src/gb/gbCheats.cpp:198 #, c-format msgid "Invalid GameShark code: %s" msgstr "Code GameShark incorrect : %s" -#: src/gb/gbCheats.cpp:310 +#: src/gb/gbCheats.cpp:227 +#, c-format +msgid "Wrong GameShark code type : %s" +msgstr "Code GameShark incorrect : %s" + +#: src/gb/gbCheats.cpp:230 +#, c-format +msgid "Unsupported GameShark code type : %s" +msgstr "Code GameShark %s non supporté" + +#: src/gb/gbCheats.cpp:316 #, c-format msgid "Invalid GameGenie code: %s" msgstr "Code GameGenie incorrect : %s" -#: src/gb/gbCheats.cpp:355 +#: src/gb/gbCheats.cpp:364 #, c-format msgid "Invalid cheat to remove %d" msgstr "Cheat à supprimer %d incorrect" -#: src/gb/gbCodesCB.h:1285 src/gb/gbCodes.h:1404 +#: src/gb/gbCodesCB.h:1287 src/gb/gbCodes.h:1456 #, c-format msgid "Unknown opcode %02x at %04x" msgstr "Opcode %02x inconnu à %04x" -#: src/gb/GB.cpp:1761 src/gb/GB.cpp:1785 src/gb/GB.cpp:1810 src/gb/GB.cpp:1842 -#: src/gb/GB.cpp:1866 +#: src/gb/GB.cpp:2123 +msgid "Invalid BOOTROM file size" +msgstr "Taille de fichier BIOS incorrecte" + +#: src/gb/GB.cpp:2875 src/gb/GB.cpp:2890 src/gb/GB.cpp:2921 src/gb/GB.cpp:2937 +#: src/gb/GB.cpp:2972 src/gb/GB.cpp:3002 src/gb/GB.cpp:3029 src/gb/GB.cpp:3045 +#: src/gb/GB.cpp:3075 src/gb/GB.cpp:3091 src/gb/GB.cpp:3129 src/gb/GB.cpp:3159 +#: src/gb/GB.cpp:3187 src/gb/GB.cpp:3202 #, c-format -msgid "Failed to read complete save game %s (%d)" -msgstr "La lecture de la sauvegarde %s complète a échouée (%d)" +msgid "" +"Battery file's size incompatible with the rom settings %s (%d).\n" +"Warning : save of the battery file is now disabled !" +msgstr "" -#: src/gb/GB.cpp:1818 +#: src/gb/GB.cpp:2981 src/gb/GB.cpp:2987 src/gb/GB.cpp:3138 src/gb/GB.cpp:3144 #, c-format msgid "Failed to read RTC from save game %s (continuing)" msgstr "" "La lecture de la RTC de la sauvegarde %s a échoué (le chargement se poursuit)" -#: src/gb/GB.cpp:2195 +#: src/gb/GB.cpp:3601 #, c-format msgid "Unsupported VisualBoy save game version %d" msgstr "Version de sauvegarde VisualBoy %d non supportée" -#: src/gb/GB.cpp:2205 +#: src/gb/GB.cpp:3611 #, c-format msgid "Cannot load save game for %s. Playing %s" msgstr "" "Impossible de charger la sauvegarde pour le jeu %s. Le jeu %s est en cours." -#: src/gb/GB.cpp:2464 +#: src/gb/GB.cpp:4061 #, c-format msgid "Unsupported rom size %02x" msgstr "Taille de rom %02x non supportée" -#: src/gb/GB.cpp:2476 +#: src/gb/GB.cpp:4116 #, c-format msgid "Unsupported ram size %02x" msgstr "Taille de ram %02x non supportée" -#: src/gb/GB.cpp:2552 +#: src/gb/GB.cpp:4258 #, c-format msgid "Unknown cartridge type %02x" msgstr "Type de cartouche %02x inconnu" @@ -1072,43 +1091,46 @@ msgid "Only GBA images are supported." msgstr "Seules les images GBA sont supportées." -#: src/gtk/window.cpp:1427 +#: src/gtk/window.cpp:1421 #, c-format msgid "Unknown file type %s" msgstr "Type de fichier inconnu %s" -#: src/gtk/window.cpp:1708 src/gtk/window.cpp:1722 +#: src/gtk/window.cpp:1702 src/gtk/window.cpp:1716 msgid "Open" msgstr "Ouvrir" -#: src/gtk/window.cpp:1749 +#: src/gtk/window.cpp:1743 msgid "All Gameboy Advance files" msgstr "Tous les fichiers Gameboy Advance" -#: src/gtk/window.cpp:1756 +#: src/gtk/window.cpp:1750 msgid "Gameboy Advance files" msgstr "Fichiers Gameboy Advance" -#: src/gtk/window.cpp:1763 +#: src/gtk/window.cpp:1757 msgid "Gameboy files" msgstr "Fichiers Gameboy" -#: src/gtk/window.cpp:1793 +#: src/gtk/window.cpp:1787 msgid "Loaded battery" msgstr "Batterie chargée" -#: src/gtk/window.cpp:1812 +#: src/gtk/window.cpp:1806 msgid "Saved battery" msgstr "Batterie enregistrée" -#: src/gtk/window.cpp:1870 src/gtk/window.cpp:1917 +#: src/gtk/window.cpp:1864 src/gtk/window.cpp:1911 msgid "----/--/-- --:--:--" msgstr "--/--/---- --:--:--" -#: src/gtk/window.cpp:1902 +#: src/gtk/window.cpp:1896 msgid "%Y/%m/%d %H:%M:%S" msgstr "%d/%m/%Y %H:%M:%S" -#: src/prof/prof.cpp:143 +#: src/prof/prof.cpp:137 msgid "No space for profiling buffer(s)\n" msgstr "Pas de place pour le(s) tampon(s) de profil\n" + +#~ msgid "Failed to read complete save game %s (%d)" +#~ msgstr "La lecture de la sauvegarde %s complète a échouée (%d)" diff -urN ../VisualBoyAdvance-1.7.2/po/stamp-po ./po/stamp-po --- ../VisualBoyAdvance-1.7.2/po/stamp-po 2004-05-22 01:03:36 +0900 +++ ./po/stamp-po 1970-01-01 09:00:00 +0900 @@ -1 +0,0 @@ -timestamp diff -urN ../VisualBoyAdvance-1.7.2/po/vba-1.8.0.pot ./po/vba-1.8.0.pot --- ../VisualBoyAdvance-1.7.2/po/vba-1.8.0.pot 1970-01-01 09:00:00 +0900 +++ ./po/vba-1.8.0.pot 2006-09-04 06:52:24 +0900 @@ -0,0 +1,1115 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR VBA development team +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: undefined\n" +"POT-Creation-Date: 2006-09-03 22:57+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/Cheats.cpp:1473 src/Cheats.cpp:1478 src/Cheats.cpp:1487 +#: src/Cheats.cpp:1495 +#, c-format +msgid "Invalid cheat code '%s'" +msgstr "" + +#: src/Cheats.cpp:1524 +#, c-format +msgid "Invalid cheat code address: %08x" +msgstr "" + +#: src/Cheats.cpp:1603 src/Cheats.cpp:1612 +msgid "Invalid GSA code. Format is XXXXXXXXYYYYYYYY" +msgstr "" + +#: src/Cheats.cpp:1638 +#, c-format +msgid "" +"Warning: cheats are for game %s. Current game is %s.\n" +"Codes may not work correctly." +msgstr "" + +#: src/Cheats.cpp:2458 src/Cheats.cpp:2467 src/Cheats.cpp:2474 +#: src/Cheats.cpp:2482 +msgid "Invalid CBA code. Format is XXXXXXXX YYYY." +msgstr "" + +#: src/Cheats.cpp:2538 +msgid "" +"Warning: Codes seem to be for a different game.\n" +"Codes may not work correctly." +msgstr "" + +#: src/Cheats.cpp:2723 src/gb/gbCheats.cpp:132 +#, c-format +msgid "Unsupported cheat list version %d" +msgstr "" + +#: src/Cheats.cpp:2737 src/gb/gbCheats.cpp:145 +#, c-format +msgid "Unsupported cheat list type %d" +msgstr "" + +#: src/elf.cpp:2811 +#, c-format +msgid "Not a valid ELF file %s" +msgstr "" + +#: src/GBA.cpp:863 src/GBA.cpp:1084 src/GBA.cpp:1122 src/Util.cpp:69 +#: src/Util.cpp:278 src/gb/GB.cpp:2708 src/gb/GB.cpp:2728 src/gb/GB.cpp:2750 +#: src/gb/GB.cpp:2777 src/gb/GB.cpp:2797 src/gb/GB.cpp:2815 src/gb/GB.cpp:2845 +#, c-format +msgid "Error creating file %s" +msgstr "" + +#: src/GBA.cpp:900 +#, c-format +msgid "Unsupported VisualBoyAdvance save game version %d" +msgstr "" + +#: src/GBA.cpp:914 +#, c-format +msgid "Cannot load save game for %s" +msgstr "" + +#: src/GBA.cpp:923 src/gb/GB.cpp:3628 +msgid "Save game is not using the BIOS files" +msgstr "" + +#: src/GBA.cpp:926 src/gb/GB.cpp:3631 +msgid "Save game is using the BIOS file" +msgstr "" + +#: src/GBA.cpp:1035 +#, c-format +msgid "Unsupported save type %d" +msgstr "" + +#: src/GBA.cpp:1157 src/GBA.cpp:1224 src/Util.cpp:596 src/Util.cpp:708 +#: src/gb/gbCheats.cpp:409 src/gb/GB.cpp:3368 +#, c-format +msgid "Cannot open file %s" +msgstr "" + +#: src/GBA.cpp:1192 src/gb/GB.cpp:3381 +#, c-format +msgid "Cannot import snapshot for %s. Current game is %s" +msgstr "" + +#: src/GBA.cpp:1206 src/gb/GB.cpp:3408 +#, c-format +msgid "Unsupported snapshot file %s" +msgstr "" + +#: src/GBA.cpp:1508 src/GBA.cpp:1514 src/GBA.cpp:1563 src/GBA.cpp:1570 +#: src/GBA.cpp:1577 src/GBA.cpp:1584 src/GBA.cpp:1591 src/GBA.cpp:1598 +#: src/GBA.cpp:1605 src/Util.cpp:775 src/Util.cpp:833 src/Util.cpp:941 +#, c-format +msgid "Failed to allocate memory for %s" +msgstr "" + +#: src/GBA.cpp:1526 src/Util.cpp:764 src/Util.cpp:810 src/Util.cpp:824 +#: src/Util.cpp:928 +#, c-format +msgid "Error opening image %s" +msgstr "" + +#: src/GBA.cpp:1859 +#, c-format +msgid "Unsupported ARM mode %02x" +msgstr "" + +#: src/GBA.cpp:2198 +#, c-format +msgid "" +"Unsupported BIOS function %02x called from %08x. A BIOS file is needed in " +"order to get correct behaviour." +msgstr "" + +#: src/GBA.cpp:3400 +msgid "Invalid BIOS file size" +msgstr "" + +#: src/RTC.cpp:159 +#, c-format +msgid "Unknown RTC command %02x" +msgstr "" + +#: src/Util.cpp:604 src/Util.cpp:624 src/Util.cpp:715 src/Util.cpp:735 +#, c-format +msgid "Bad ZIP file %s" +msgstr "" + +#: src/Util.cpp:647 src/Util.cpp:753 +#, c-format +msgid "No image found on ZIP file %s" +msgstr "" + +#: src/Util.cpp:791 src/Util.cpp:846 src/Util.cpp:885 src/Util.cpp:954 +#, c-format +msgid "Error reading image %s" +msgstr "" + +#: src/Util.cpp:897 +#, c-format +msgid "No image found on RAR file %s" +msgstr "" + +#: src/gb/gbCheats.cpp:192 src/gb/gbCheats.cpp:310 +msgid "Maximum number of cheats reached." +msgstr "" + +#: src/gb/gbCheats.cpp:198 +#, c-format +msgid "Invalid GameShark code: %s" +msgstr "" + +#: src/gb/gbCheats.cpp:227 +#, c-format +msgid "Wrong GameShark code type : %s" +msgstr "" + +#: src/gb/gbCheats.cpp:230 +#, c-format +msgid "Unsupported GameShark code type : %s" +msgstr "" + +#: src/gb/gbCheats.cpp:316 +#, c-format +msgid "Invalid GameGenie code: %s" +msgstr "" + +#: src/gb/gbCheats.cpp:364 +#, c-format +msgid "Invalid cheat to remove %d" +msgstr "" + +#: src/gb/gbCodesCB.h:1287 src/gb/gbCodes.h:1456 +#, c-format +msgid "Unknown opcode %02x at %04x" +msgstr "" + +#: src/gb/GB.cpp:2123 +msgid "Invalid BOOTROM file size" +msgstr "" + +#: src/gb/GB.cpp:2875 src/gb/GB.cpp:2890 src/gb/GB.cpp:2921 src/gb/GB.cpp:2937 +#: src/gb/GB.cpp:2972 src/gb/GB.cpp:3002 src/gb/GB.cpp:3029 src/gb/GB.cpp:3045 +#: src/gb/GB.cpp:3075 src/gb/GB.cpp:3091 src/gb/GB.cpp:3129 src/gb/GB.cpp:3159 +#: src/gb/GB.cpp:3187 src/gb/GB.cpp:3202 +#, c-format +msgid "" +"Battery file's size incompatible with the rom settings %s (%d).\n" +"Warning : save of the battery file is now disabled !" +msgstr "" + +#: src/gb/GB.cpp:2981 src/gb/GB.cpp:2987 src/gb/GB.cpp:3138 src/gb/GB.cpp:3144 +#, c-format +msgid "Failed to read RTC from save game %s (continuing)" +msgstr "" + +#: src/gb/GB.cpp:3601 +#, c-format +msgid "Unsupported VisualBoy save game version %d" +msgstr "" + +#: src/gb/GB.cpp:3611 +#, c-format +msgid "Cannot load save game for %s. Playing %s" +msgstr "" + +#: src/gb/GB.cpp:4061 +#, c-format +msgid "Unsupported rom size %02x" +msgstr "" + +#: src/gb/GB.cpp:4116 +#, c-format +msgid "Unsupported ram size %02x" +msgstr "" + +#: src/gb/GB.cpp:4258 +#, c-format +msgid "Unknown cartridge type %02x" +msgstr "" + +#: src/gtk/joypadconfig.cpp:202 src/gtk/joypadconfig.cpp:239 +#: src/gtk/joypadconfig.cpp:257 +msgid "" +msgstr "" + +#: src/gtk/main.cpp:61 +#, c-format +msgid "Try `%s --help' for more information.\n" +msgstr "" + +#: src/gtk/main.cpp:65 +#, c-format +msgid "Usage: %s [option ...] [file]\n" +msgstr "" + +#: src/gtk/main.cpp:66 +msgid "" +"\n" +"Options:\n" +" --help Output this help.\n" +" -V, --version Output version information.\n" +msgstr "" + +#: src/gtk/main.cpp:130 +#, c-format +msgid "VisualBoyAdvance version %s [GTK+]\n" +msgstr "" + +#: src/gtk/vba.glade:7 +msgid "VBA" +msgstr "" + +#: src/gtk/vba.glade:37 +msgid "_File" +msgstr "" + +#: src/gtk/vba.glade:46 +msgid "_Open..." +msgstr "" + +#: src/gtk/vba.glade:73 +msgid "_Load..." +msgstr "" + +#: src/gtk/vba.glade:82 +msgid "_Save..." +msgstr "" + +#: src/gtk/vba.glade:91 +msgid "Loa_d game" +msgstr "" + +#: src/gtk/vba.glade:100 +msgid "Most recent" +msgstr "" + +#: src/gtk/vba.glade:108 +msgid "Auto load most recent" +msgstr "" + +#: src/gtk/vba.glade:123 src/gtk/vba.glade:240 +msgid "Slot1" +msgstr "" + +#: src/gtk/vba.glade:132 src/gtk/vba.glade:249 +msgid "Slot2" +msgstr "" + +#: src/gtk/vba.glade:141 src/gtk/vba.glade:258 +msgid "Slot3" +msgstr "" + +#: src/gtk/vba.glade:150 src/gtk/vba.glade:267 +msgid "Slot4" +msgstr "" + +#: src/gtk/vba.glade:159 src/gtk/vba.glade:276 +msgid "Slot5" +msgstr "" + +#: src/gtk/vba.glade:168 src/gtk/vba.glade:285 +msgid "Slot6" +msgstr "" + +#: src/gtk/vba.glade:177 src/gtk/vba.glade:294 +msgid "Slot7" +msgstr "" + +#: src/gtk/vba.glade:186 src/gtk/vba.glade:303 +msgid "Slot8" +msgstr "" + +#: src/gtk/vba.glade:195 src/gtk/vba.glade:312 +msgid "Slot9" +msgstr "" + +#: src/gtk/vba.glade:204 src/gtk/vba.glade:321 +msgid "Slot10" +msgstr "" + +#: src/gtk/vba.glade:217 +msgid "S_ave game" +msgstr "" + +#: src/gtk/vba.glade:226 +msgid "Oldest slot" +msgstr "" + +#: src/gtk/vba.glade:340 +msgid "_Pause" +msgstr "" + +#: src/gtk/vba.glade:350 src/gtk/vba.glade:374 +msgid "_Reset" +msgstr "" + +#: src/gtk/vba.glade:365 +msgid "Rece_nt" +msgstr "" + +#: src/gtk/vba.glade:382 +msgid "_Freeze" +msgstr "" + +#: src/gtk/vba.glade:407 +msgid "_Import" +msgstr "" + +#: src/gtk/vba.glade:416 src/gtk/vba.glade:437 +msgid "_Battery file..." +msgstr "" + +#: src/gtk/vba.glade:428 +msgid "E_xport" +msgstr "" + +#: src/gtk/vba.glade:455 +msgid "Screen capt_ure..." +msgstr "" + +#: src/gtk/vba.glade:469 +msgid "_Close" +msgstr "" + +#: src/gtk/vba.glade:489 +msgid "_Exit" +msgstr "" + +#: src/gtk/vba.glade:514 +msgid "_Options" +msgstr "" + +#: src/gtk/vba.glade:523 +msgid "_Frameskip" +msgstr "" + +#: src/gtk/vba.glade:532 +msgid "_Throttle" +msgstr "" + +#: src/gtk/vba.glade:541 +msgid "_No throttle" +msgstr "" + +#: src/gtk/vba.glade:550 src/gtk/vba.glade:1315 +msgid "25%" +msgstr "" + +#: src/gtk/vba.glade:560 src/gtk/vba.glade:1324 +msgid "50%" +msgstr "" + +#: src/gtk/vba.glade:570 src/gtk/vba.glade:1334 +msgid "100%" +msgstr "" + +#: src/gtk/vba.glade:580 +msgid "150%" +msgstr "" + +#: src/gtk/vba.glade:590 src/gtk/vba.glade:1344 +msgid "200%" +msgstr "" + +#: src/gtk/vba.glade:600 +msgid "_Other..." +msgstr "" + +#: src/gtk/vba.glade:620 src/gtk/vba.glade:981 src/gtk/vba.glade:1415 +msgid "_Automatic" +msgstr "" + +#: src/gtk/vba.glade:629 +msgid "_0" +msgstr "" + +#: src/gtk/vba.glade:639 src/gtk/vba.glade:1753 +msgid "_1" +msgstr "" + +#: src/gtk/vba.glade:649 src/gtk/vba.glade:1762 +msgid "_2" +msgstr "" + +#: src/gtk/vba.glade:659 src/gtk/vba.glade:1772 +msgid "_3" +msgstr "" + +#: src/gtk/vba.glade:669 src/gtk/vba.glade:1782 +msgid "_4" +msgstr "" + +#: src/gtk/vba.glade:679 +msgid "_5" +msgstr "" + +#: src/gtk/vba.glade:689 +msgid "_6" +msgstr "" + +#: src/gtk/vba.glade:699 +msgid "_7" +msgstr "" + +#: src/gtk/vba.glade:709 +msgid "_8" +msgstr "" + +#: src/gtk/vba.glade:719 +msgid "_9" +msgstr "" + +#: src/gtk/vba.glade:733 +msgid "_Video" +msgstr "" + +#: src/gtk/vba.glade:742 +msgid "_1x" +msgstr "" + +#: src/gtk/vba.glade:751 +msgid "_2x" +msgstr "" + +#: src/gtk/vba.glade:761 +msgid "_3x" +msgstr "" + +#: src/gtk/vba.glade:771 +msgid "_4x" +msgstr "" + +#: src/gtk/vba.glade:781 +msgid "_5x" +msgstr "" + +#: src/gtk/vba.glade:791 +msgid "_6x" +msgstr "" + +#: src/gtk/vba.glade:807 +msgid "_Layers" +msgstr "" + +#: src/gtk/vba.glade:816 +msgid "BG0" +msgstr "" + +#: src/gtk/vba.glade:826 +msgid "BG1" +msgstr "" + +#: src/gtk/vba.glade:836 +msgid "BG2" +msgstr "" + +#: src/gtk/vba.glade:846 +msgid "BG3" +msgstr "" + +#: src/gtk/vba.glade:856 +msgid "OBJ" +msgstr "" + +#: src/gtk/vba.glade:866 +msgid "WIN0" +msgstr "" + +#: src/gtk/vba.glade:876 +msgid "WIN1" +msgstr "" + +#: src/gtk/vba.glade:886 +msgid "OBJWIN" +msgstr "" + +#: src/gtk/vba.glade:904 +msgid "_Emulator" +msgstr "" + +#: src/gtk/vba.glade:913 +msgid "Directories..." +msgstr "" + +#: src/gtk/vba.glade:921 +msgid "Pause when inactive window" +msgstr "" + +#: src/gtk/vba.glade:930 +msgid "Show speed" +msgstr "" + +#: src/gtk/vba.glade:939 src/gtk/vba.glade:1030 +msgid "None" +msgstr "" + +#: src/gtk/vba.glade:948 +msgid "Percentage" +msgstr "" + +#: src/gtk/vba.glade:958 +msgid "Detailed" +msgstr "" + +#: src/gtk/vba.glade:972 +msgid "Save type" +msgstr "" + +#: src/gtk/vba.glade:990 +msgid "EEPROM" +msgstr "" + +#: src/gtk/vba.glade:1000 +msgid "SRAM" +msgstr "" + +#: src/gtk/vba.glade:1010 +msgid "Flash" +msgstr "" + +#: src/gtk/vba.glade:1020 +msgid "EEPROM+Sensor" +msgstr "" + +#: src/gtk/vba.glade:1046 +msgid "Flash 64K" +msgstr "" + +#: src/gtk/vba.glade:1055 +msgid "Flash 128K" +msgstr "" + +#: src/gtk/vba.glade:1075 +msgid "_Select BIOS file..." +msgstr "" + +#: src/gtk/vba.glade:1083 +msgid "_Use BIOS file" +msgstr "" + +#: src/gtk/vba.glade:1098 +msgid "Screenshot format" +msgstr "" + +#: src/gtk/vba.glade:1107 +msgid "_PNG" +msgstr "" + +#: src/gtk/vba.glade:1116 +msgid "_BMP" +msgstr "" + +#: src/gtk/vba.glade:1134 +msgid "_Sound" +msgstr "" + +#: src/gtk/vba.glade:1143 +msgid "O_ff" +msgstr "" + +#: src/gtk/vba.glade:1152 +msgid "_Mute" +msgstr "" + +#: src/gtk/vba.glade:1162 +msgid "_On" +msgstr "" + +#: src/gtk/vba.glade:1178 +msgid "Echo" +msgstr "" + +#: src/gtk/vba.glade:1187 +msgid "Low pass filter" +msgstr "" + +#: src/gtk/vba.glade:1196 +msgid "Reverse stereo" +msgstr "" + +#: src/gtk/vba.glade:1211 +msgid "Channel _1" +msgstr "" + +#: src/gtk/vba.glade:1220 +msgid "Channel _2" +msgstr "" + +#: src/gtk/vba.glade:1229 +msgid "Channel _3" +msgstr "" + +#: src/gtk/vba.glade:1238 +msgid "Channel _4" +msgstr "" + +#: src/gtk/vba.glade:1247 +msgid "Channel _A" +msgstr "" + +#: src/gtk/vba.glade:1256 +msgid "Channel _B" +msgstr "" + +#: src/gtk/vba.glade:1271 +msgid "11 _Khz" +msgstr "" + +#: src/gtk/vba.glade:1280 +msgid "22 K_hz" +msgstr "" + +#: src/gtk/vba.glade:1290 +msgid "44 Kh_z" +msgstr "" + +#: src/gtk/vba.glade:1306 +msgid "_Volume" +msgstr "" + +#: src/gtk/vba.glade:1354 +msgid "300%" +msgstr "" + +#: src/gtk/vba.glade:1364 +msgid "400%" +msgstr "" + +#: src/gtk/vba.glade:1382 +msgid "_Gameboy" +msgstr "" + +#: src/gtk/vba.glade:1391 +msgid "_Border" +msgstr "" + +#: src/gtk/vba.glade:1400 +msgid "_Printer" +msgstr "" + +#: src/gtk/vba.glade:1424 +msgid "_GBA" +msgstr "" + +#: src/gtk/vba.glade:1434 +msgid "_CGB/GBC" +msgstr "" + +#: src/gtk/vba.glade:1444 +msgid "_SGB" +msgstr "" + +#: src/gtk/vba.glade:1454 +msgid "SGB_2" +msgstr "" + +#: src/gtk/vba.glade:1464 +msgid "G_B" +msgstr "" + +#: src/gtk/vba.glade:1478 +msgid "F_ilter" +msgstr "" + +#: src/gtk/vba.glade:1487 +msgid "Interframe _blending" +msgstr "" + +#: src/gtk/vba.glade:1496 src/gtk/vba.glade:1535 +msgid "_None" +msgstr "" + +#: src/gtk/vba.glade:1505 +msgid "_Smart" +msgstr "" + +#: src/gtk/vba.glade:1515 src/gtk/vba.glade:1594 +msgid "_Motion Blur" +msgstr "" + +#: src/gtk/vba.glade:1544 +msgid "_TV Mode" +msgstr "" + +#: src/gtk/vba.glade:1554 +msgid "_2xSaI" +msgstr "" + +#: src/gtk/vba.glade:1564 +msgid "_Super 2xSaI" +msgstr "" + +#: src/gtk/vba.glade:1574 +msgid "Super _Eagle" +msgstr "" + +#: src/gtk/vba.glade:1584 +msgid "_Pixelate" +msgstr "" + +#: src/gtk/vba.glade:1604 +msgid "_AdvanceMAME 2x" +msgstr "" + +#: src/gtk/vba.glade:1614 +msgid "S_imple 2x" +msgstr "" + +#: src/gtk/vba.glade:1624 +msgid "Bilinea_r" +msgstr "" + +#: src/gtk/vba.glade:1634 +msgid "Bilinear Pl_us" +msgstr "" + +#: src/gtk/vba.glade:1644 +msgid "S_canlines" +msgstr "" + +#: src/gtk/vba.glade:1654 +msgid "h_q2x" +msgstr "" + +#: src/gtk/vba.glade:1664 +msgid "_lq2x" +msgstr "" + +#: src/gtk/vba.glade:1680 +msgid "_Disable MMX" +msgstr "" + +#: src/gtk/vba.glade:1693 +msgid "_Joypad" +msgstr "" + +#: src/gtk/vba.glade:1702 +msgid "_Configure" +msgstr "" + +#: src/gtk/vba.glade:1711 +msgid "_1..." +msgstr "" + +#: src/gtk/vba.glade:1719 +msgid "_2..." +msgstr "" + +#: src/gtk/vba.glade:1727 +msgid "_3..." +msgstr "" + +#: src/gtk/vba.glade:1735 +msgid "_4..." +msgstr "" + +#: src/gtk/vba.glade:1798 +msgid "_Autofire" +msgstr "" + +#: src/gtk/vba.glade:1807 +msgid "_A" +msgstr "" + +#: src/gtk/vba.glade:1817 +msgid "_B" +msgstr "" + +#: src/gtk/vba.glade:1827 +msgid "_L" +msgstr "" + +#: src/gtk/vba.glade:1837 +msgid "_R" +msgstr "" + +#: src/gtk/vba.glade:1859 +msgid "_Tools" +msgstr "" + +#: src/gtk/vba.glade:1868 +msgid "_GDB" +msgstr "" + +#: src/gtk/vba.glade:1877 +msgid "_Wait connection..." +msgstr "" + +#: src/gtk/vba.glade:1885 +msgid "_Load and wait..." +msgstr "" + +#: src/gtk/vba.glade:1893 +msgid "_Break" +msgstr "" + +#: src/gtk/vba.glade:1901 +msgid "_Disconnect" +msgstr "" + +#: src/gtk/vba.glade:1917 +msgid "_Help" +msgstr "" + +#: src/gtk/vba.glade:1926 +msgid "_About" +msgstr "" + +#: src/gtk/vba.glade:1967 +msgid "About VBA" +msgstr "" + +#: src/gtk/vba.glade:2054 +msgid "An emulator for Gameboy(TM) and GameboyAdvance(TM)." +msgstr "" + +#: src/gtk/vba.glade:2076 +msgid "Special thanks to Yann Parmentier aka \"kohai\" for the icons." +msgstr "" + +#: src/gtk/vba.glade:2098 +msgid "" +"Copyright (C) 2004 Forgotten and the VBA development team" +msgstr "" + +#: src/gtk/vba.glade:2120 +msgid "Throttle" +msgstr "" + +#: src/gtk/vba.glade:2191 +msgid "Throttle : " +msgstr "" + +#: src/gtk/vba.glade:2231 +msgid " %" +msgstr "" + +#: src/gtk/vba.glade:2262 +msgid "Directories" +msgstr "" + +#: src/gtk/vba.glade:2328 +msgid "GBA roms : " +msgstr "" + +#: src/gtk/vba.glade:2358 src/gtk/vba.glade:2511 src/gtk/vba.glade:2612 +#: src/gtk/vba.glade:2713 src/gtk/vba.glade:2790 src/gtk/vba.glade:2921 +#: src/gtk/vba.glade:3207 src/gtk/vba.glade:3229 src/gtk/vba.glade:3251 +#: src/gtk/vba.glade:3273 src/gtk/vba.glade:3295 src/gtk/vba.glade:3317 +#: src/gtk/vba.glade:3339 src/gtk/vba.glade:3361 src/gtk/vba.glade:3383 +#: src/gtk/vba.glade:3405 src/gtk/vba.glade:3427 +msgid "*" +msgstr "" + +#: src/gtk/vba.glade:2429 +msgid "GB roms : " +msgstr "" + +#: src/gtk/vba.glade:2481 +msgid "Batteries : " +msgstr "" + +#: src/gtk/vba.glade:2582 +msgid "Saves : " +msgstr "" + +#: src/gtk/vba.glade:2683 +msgid "Captures : " +msgstr "" + +#: src/gtk/vba.glade:2841 +msgid "Joypad config" +msgstr "" + +#: src/gtk/vba.glade:2937 +msgid "Down : " +msgstr "" + +#: src/gtk/vba.glade:2961 +msgid "Left : " +msgstr "" + +#: src/gtk/vba.glade:2985 +msgid "Right : " +msgstr "" + +#: src/gtk/vba.glade:3009 +msgid "Button A : " +msgstr "" + +#: src/gtk/vba.glade:3033 +msgid "Button B : " +msgstr "" + +#: src/gtk/vba.glade:3057 +msgid "Button L : " +msgstr "" + +#: src/gtk/vba.glade:3081 +msgid "Button R : " +msgstr "" + +#: src/gtk/vba.glade:3105 +msgid "Select : " +msgstr "" + +#: src/gtk/vba.glade:3129 +msgid "Start : " +msgstr "" + +#: src/gtk/vba.glade:3153 +msgid "Speed : " +msgstr "" + +#: src/gtk/vba.glade:3177 +msgid "Capture : " +msgstr "" + +#: src/gtk/vba.glade:3443 +msgid "Up : " +msgstr "" + +#: src/gtk/vba.glade:3477 +msgid "TCP port" +msgstr "" + +#: src/gtk/vba.glade:3548 +msgid "Port : " +msgstr "" + +#: src/gtk/windowcallbacks.cpp:80 src/gtk/windowcallbacks.cpp:94 +msgid "Load game" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:109 src/gtk/windowcallbacks.cpp:163 +msgid "VisualBoyAdvance save game" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:131 src/gtk/windowcallbacks.cpp:146 +msgid "Save game" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:181 src/gtk/windowcallbacks.cpp:466 +#: src/gtk/windowcallbacks.cpp:585 +msgid "File already exists. Overwrite it?" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:318 src/gtk/windowcallbacks.cpp:332 +msgid "Import battery file" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:347 src/gtk/windowcallbacks.cpp:424 +msgid "Battery file" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:351 src/gtk/windowcallbacks.cpp:428 +msgid "Flash save" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:362 +msgid "" +"Importing a battery file will erase any saved games and reset the emulator. " +"Do you want to continue?" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:380 +#, c-format +msgid "Failed to import battery file %s." +msgstr "" + +#: src/gtk/windowcallbacks.cpp:392 src/gtk/windowcallbacks.cpp:407 +msgid "Export battery file" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:494 +#, c-format +msgid "Failed to export battery file %s." +msgstr "" + +#: src/gtk/windowcallbacks.cpp:506 src/gtk/windowcallbacks.cpp:521 +msgid "Save screenshot" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:538 +msgid "PNG image" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:542 +msgid "BMP image" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:824 src/gtk/windowcallbacks.cpp:844 +msgid "Select directory" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:872 src/gtk/windowcallbacks.cpp:882 +msgid "Select BIOS file" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:898 +msgid "All files" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:902 +msgid "Gameboy Advance BIOS" +msgstr "" + +#: src/gtk/windowcallbacks.cpp:1336 +msgid "Only GBA images are supported." +msgstr "" + +#: src/gtk/window.cpp:1421 +#, c-format +msgid "Unknown file type %s" +msgstr "" + +#: src/gtk/window.cpp:1702 src/gtk/window.cpp:1716 +msgid "Open" +msgstr "" + +#: src/gtk/window.cpp:1743 +msgid "All Gameboy Advance files" +msgstr "" + +#: src/gtk/window.cpp:1750 +msgid "Gameboy Advance files" +msgstr "" + +#: src/gtk/window.cpp:1757 +msgid "Gameboy files" +msgstr "" + +#: src/gtk/window.cpp:1787 +msgid "Loaded battery" +msgstr "" + +#: src/gtk/window.cpp:1806 +msgid "Saved battery" +msgstr "" + +#: src/gtk/window.cpp:1864 src/gtk/window.cpp:1911 +msgid "----/--/-- --:--:--" +msgstr "" + +#: src/gtk/window.cpp:1896 +msgid "%Y/%m/%d %H:%M:%S" +msgstr "" + +#: src/prof/prof.cpp:137 +msgid "No space for profiling buffer(s)\n" +msgstr "" diff -urN ../VisualBoyAdvance-1.7.2/src/2xSaI.cpp ./src/2xSaI.cpp --- ../VisualBoyAdvance-1.7.2/src/2xSaI.cpp 2004-01-26 11:12:15 +0900 +++ ./src/2xSaI.cpp 2004-09-16 07:12:51 +0900 @@ -1,6 +1,8 @@ #include "System.h" #include "Port.h" +extern int RGB_LOW_BITS_MASK; + extern "C" { @@ -48,6 +50,7 @@ greenMask = 0x7E0; qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE; hq2x_init(16); + RGB_LOW_BITS_MASK = 0x0821; } else if (BitFormat == 555) { colorMask = 0x7BDE7BDE; lowPixelMask = 0x04210421; @@ -57,6 +60,7 @@ greenMask = 0x3E0; qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE; hq2x_init(15); + RGB_LOW_BITS_MASK = 0x0421; } else { return 0; } @@ -67,6 +71,7 @@ qlowpixelMask = 0x030303; qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe; hq2x_init(32); + RGB_LOW_BITS_MASK = 0x010101; } else return 0; diff -urN ../VisualBoyAdvance-1.7.2/src/AutoBuild.h ./src/AutoBuild.h --- ../VisualBoyAdvance-1.7.2/src/AutoBuild.h 2004-05-16 06:36:44 +0900 +++ ./src/AutoBuild.h 2004-12-19 08:09:56 +0900 @@ -20,12 +20,12 @@ #ifndef __AUTOBUILD_H__ #define __AUTOBUILD_H__ #ifndef VERSION -#define VERSION "1.7.2" +#define VERSION "1.8.0" #endif //change the FALSE to TRUE for autoincrement of build number #define INCREMENT_VERSION FALSE -#define FILEVER 1,7,2,560 -#define PRODUCTVER 1,7,2,560 -#define STRFILEVER "1, 7, 2, 560\0" -#define STRPRODUCTVER "1, 7, 2, 560\0" +#define FILEVER 1,8,0,600 +#define PRODUCTVER 1,8,0,600 +#define STRFILEVER "1, 8, 0, 600\0" +#define STRPRODUCTVER "1, 8, 0, 600\0" #endif //__AUTOBUILD_H__ diff -urN ../VisualBoyAdvance-1.7.2/src/Cheats.cpp ./src/Cheats.cpp --- ../VisualBoyAdvance-1.7.2/src/Cheats.cpp 2004-05-13 23:38:33 +0900 +++ ./src/Cheats.cpp 2006-06-25 05:21:47 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,25 +29,34 @@ #include "Util.h" /** - * Gameshark code types: + * Gameshark code types: (based on AR v1.0) * * NNNNNNNN 001DC0DE - ID code for the game (game 4 character name) from ROM - * DEADFACE XXXXXXXX - changes decryption seeds + * DEADFACE XXXXXXXX - changes decryption seeds // Not supported by VBA. * 0AAAAAAA 000000YY - 8-bit constant write * 1AAAAAAA 0000YYYY - 16-bit constant write * 2AAAAAAA YYYYYYYY - 32-bit constant write - * 3AAAAAAA YYYYYYYY - ?? - * 6AAAAAAA 0000YYYY - 16-bit ROM Patch (address >> 1) - * 6AAAAAAA 1000YYYY - 16-bit ROM Patch ? (address >> 1) - * 6AAAAAAA 2000YYYY - 16-bit ROM Patch ? (address >> 1) + * 30XXAAAA YYYYYYYY - 32bit Group Write, 8/16/32bit Sub/Add (depending on the XX value). + * 6AAAAAAA Z000YYYY - 16-bit ROM Patch (address >> 1). Z selects the Rom Patching register. + * - AR v1/2 hardware only supports Z=0. + * - AR v3 hardware should support Z=0,1,2 or 3. * 8A1AAAAA 000000YY - 8-bit button write * 8A2AAAAA 0000YYYY - 16-bit button write - * 8A3AAAAA YYYYYYYY - 32-bit button write + * 8A4AAAAA YYYYYYYY - 32-bit button write // BUGGY ! Only writes 00000000 on the AR v1.0. * 80F00000 0000YYYY - button slow motion - * DAAAAAAA 0000YYYY - if address contains 16-bit value enable next code + * DAAAAAAA 00Z0YYYY - Z = 0 : if 16-bit value at address != YYYY skip next line + * - Z = 1 : if 16-bit value at address == YYYY skip next line + * - Z = 2 : if 16-bit value at address > YYYY (Unsigned) skip next line + * - Z = 3 : if 16-bit value at address < YYYY (Unsigned) skip next line + * E0CCYYYY ZAAAAAAA - Z = 0 : if 16-bit value at address != YYYY skip CC lines + * - Z = 1 : if 16-bit value at address == YYYY skip CC lines + * - Z = 2 : if 16-bit value at address > YYYY (Unsigned) skip CC lines + * - Z = 3 : if 16-bit value at address < YYYY (Unsigned) skip CC lines * FAAAAAAA 0000YYYY - Master code function * - * CodeBreaker codes types: + * + * + * CodeBreaker codes types: (based on the CBA clone "Cheatcode S" v1.1) * * 0000AAAA 000Y - Game CRC (Y are flags: 8 - CRC, 2 - DI) * 1AAAAAAA YYYY - Master Code function (store address at ((YYYY << 0x16) @@ -56,65 +65,150 @@ * 3AAAAAAA YYYY - 8-bit constant write * 4AAAAAAA YYYY - Slide code * XXXXCCCC IIII (C is count and I is address increment, X is value incr.) - * 5AAAAAAA CCCC - Super code (Write bytes to address, CCCC is count) + * 5AAAAAAA CCCC - Super code (Write bytes to address, 2*CCCC is count) * BBBBBBBB BBBB * 6AAAAAAA YYYY - 16-bit and * 7AAAAAAA YYYY - if address contains 16-bit value enable next code * 8AAAAAAA YYYY - 16-bit constant write * 9AAAAAAA YYYY - change decryption (when first code only?) * AAAAAAAA YYYY - if address does not contain 16-bit value enable next code - * BAAAAAAA YYYY - if 16-bit < YYYY - * CAAAAAAA YYYY - if 16-bit > YYYY - * D0000020 YYYY - if button keys equal value enable next code - * EAAAAAAA YYYY - increase value stored in address - */ -#define UNKNOWN_CODE -1 -#define INT_8_BIT_WRITE 0 -#define INT_16_BIT_WRITE 1 -#define INT_32_BIT_WRITE 2 -#define GSA_16_BIT_ROM_PATCH 3 -#define GSA_8_BIT_GS_WRITE 4 -#define GSA_16_BIT_GS_WRITE 5 -#define GSA_32_BIT_GS_WRITE 6 -#define CBA_IF_KEYS_PRESSED 7 -#define CBA_IF_TRUE 8 -#define CBA_SLIDE_CODE 9 -#define CBA_IF_FALSE 10 -#define CBA_AND 11 -#define GSA_8_BIT_GS_WRITE2 12 -#define GSA_16_BIT_GS_WRITE2 13 -#define GSA_32_BIT_GS_WRITE2 14 -#define GSA_16_BIT_ROM_PATCH2 15 -#define GSA_8_BIT_SLIDE 16 -#define GSA_16_BIT_SLIDE 17 -#define GSA_32_BIT_SLIDE 18 -#define GSA_8_BIT_IF_TRUE 19 -#define GSA_32_BIT_IF_TRUE 20 -#define GSA_8_BIT_IF_FALSE 21 -#define GSA_32_BIT_IF_FALSE 22 -#define GSA_8_BIT_FILL 23 -#define GSA_16_BIT_FILL 24 -#define GSA_8_BIT_IF_TRUE2 25 -#define GSA_16_BIT_IF_TRUE2 26 -#define GSA_32_BIT_IF_TRUE2 27 -#define GSA_8_BIT_IF_FALSE2 28 -#define GSA_16_BIT_IF_FALSE2 29 -#define GSA_32_BIT_IF_FALSE2 30 -#define GSA_SLOWDOWN 31 -#define CBA_ADD 32 -#define CBA_OR 33 -#define CBA_LT 34 -#define CBA_GT 35 -#define CBA_SUPER 36 + * BAAAAAAA YYYY - if 16-bit value at address <= YYYY skip next code + * CAAAAAAA YYYY - if 16-bit value at address >= YYYY skip next code + * D00000X0 YYYY - if button keys ... enable next code (else skip next code) + * EAAAAAAA YYYY - increase 16/32bit value stored in address + * FAAAAAAA YYYY - if 16-bit value at address AND YYYY = 0 then skip next code + **/ + +#define UNKNOWN_CODE -1 +#define INT_8_BIT_WRITE 0 +#define INT_16_BIT_WRITE 1 +#define INT_32_BIT_WRITE 2 +#define GSA_16_BIT_ROM_PATCH 3 +#define GSA_8_BIT_GS_WRITE 4 +#define GSA_16_BIT_GS_WRITE 5 +#define GSA_32_BIT_GS_WRITE 6 +#define CBA_IF_KEYS_PRESSED 7 +#define CBA_IF_TRUE 8 +#define CBA_SLIDE_CODE 9 +#define CBA_IF_FALSE 10 +#define CBA_AND 11 +#define GSA_8_BIT_GS_WRITE2 12 +#define GSA_16_BIT_GS_WRITE2 13 +#define GSA_32_BIT_GS_WRITE2 14 +#define GSA_16_BIT_ROM_PATCH2C 15 +#define GSA_8_BIT_SLIDE 16 +#define GSA_16_BIT_SLIDE 17 +#define GSA_32_BIT_SLIDE 18 +#define GSA_8_BIT_IF_TRUE 19 +#define GSA_32_BIT_IF_TRUE 20 +#define GSA_8_BIT_IF_FALSE 21 +#define GSA_32_BIT_IF_FALSE 22 +#define GSA_8_BIT_FILL 23 +#define GSA_16_BIT_FILL 24 +#define GSA_8_BIT_IF_TRUE2 25 +#define GSA_16_BIT_IF_TRUE2 26 +#define GSA_32_BIT_IF_TRUE2 27 +#define GSA_8_BIT_IF_FALSE2 28 +#define GSA_16_BIT_IF_FALSE2 29 +#define GSA_32_BIT_IF_FALSE2 30 +#define GSA_SLOWDOWN 31 +#define CBA_ADD 32 +#define CBA_OR 33 +#define CBA_LT 34 +#define CBA_GT 35 +#define CBA_SUPER 36 +#define GSA_8_BIT_POINTER 37 +#define GSA_16_BIT_POINTER 38 +#define GSA_32_BIT_POINTER 39 +#define GSA_8_BIT_ADD 40 +#define GSA_16_BIT_ADD 41 +#define GSA_32_BIT_ADD 42 +#define GSA_8_BIT_IF_LOWER_U 43 +#define GSA_16_BIT_IF_LOWER_U 44 +#define GSA_32_BIT_IF_LOWER_U 45 +#define GSA_8_BIT_IF_HIGHER_U 46 +#define GSA_16_BIT_IF_HIGHER_U 47 +#define GSA_32_BIT_IF_HIGHER_U 48 +#define GSA_8_BIT_IF_AND 49 +#define GSA_16_BIT_IF_AND 50 +#define GSA_32_BIT_IF_AND 51 +#define GSA_8_BIT_IF_LOWER_U2 52 +#define GSA_16_BIT_IF_LOWER_U2 53 +#define GSA_32_BIT_IF_LOWER_U2 54 +#define GSA_8_BIT_IF_HIGHER_U2 55 +#define GSA_16_BIT_IF_HIGHER_U2 56 +#define GSA_32_BIT_IF_HIGHER_U2 57 +#define GSA_8_BIT_IF_AND2 58 +#define GSA_16_BIT_IF_AND2 59 +#define GSA_32_BIT_IF_AND2 60 +#define GSA_ALWAYS 61 +#define GSA_ALWAYS2 62 +#define GSA_8_BIT_IF_LOWER_S 63 +#define GSA_16_BIT_IF_LOWER_S 64 +#define GSA_32_BIT_IF_LOWER_S 65 +#define GSA_8_BIT_IF_HIGHER_S 66 +#define GSA_16_BIT_IF_HIGHER_S 67 +#define GSA_32_BIT_IF_HIGHER_S 68 +#define GSA_8_BIT_IF_LOWER_S2 69 +#define GSA_16_BIT_IF_LOWER_S2 70 +#define GSA_32_BIT_IF_LOWER_S2 71 +#define GSA_8_BIT_IF_HIGHER_S2 72 +#define GSA_16_BIT_IF_HIGHER_S2 73 +#define GSA_32_BIT_IF_HIGHER_S2 74 +#define GSA_16_BIT_WRITE_IOREGS 75 +#define GSA_32_BIT_WRITE_IOREGS 76 +#define GSA_CODES_ON 77 +#define GSA_8_BIT_IF_TRUE3 78 +#define GSA_16_BIT_IF_TRUE3 79 +#define GSA_32_BIT_IF_TRUE3 80 +#define GSA_8_BIT_IF_FALSE3 81 +#define GSA_16_BIT_IF_FALSE3 82 +#define GSA_32_BIT_IF_FALSE3 83 +#define GSA_8_BIT_IF_LOWER_S3 84 +#define GSA_16_BIT_IF_LOWER_S3 85 +#define GSA_32_BIT_IF_LOWER_S3 86 +#define GSA_8_BIT_IF_HIGHER_S3 87 +#define GSA_16_BIT_IF_HIGHER_S3 88 +#define GSA_32_BIT_IF_HIGHER_S3 89 +#define GSA_8_BIT_IF_LOWER_U3 90 +#define GSA_16_BIT_IF_LOWER_U3 91 +#define GSA_32_BIT_IF_LOWER_U3 92 +#define GSA_8_BIT_IF_HIGHER_U3 93 +#define GSA_16_BIT_IF_HIGHER_U3 94 +#define GSA_32_BIT_IF_HIGHER_U3 95 +#define GSA_8_BIT_IF_AND3 96 +#define GSA_16_BIT_IF_AND3 97 +#define GSA_32_BIT_IF_AND3 98 +#define GSA_ALWAYS3 99 +#define GSA_16_BIT_ROM_PATCH2D 100 +#define GSA_16_BIT_ROM_PATCH2E 101 +#define GSA_16_BIT_ROM_PATCH2F 102 +#define GSA_GROUP_WRITE 103 +#define GSA_32_BIT_ADD2 104 +#define GSA_32_BIT_SUB2 105 +#define GSA_16_BIT_IF_LOWER_OR_EQ_U 106 +#define GSA_16_BIT_IF_HIGHER_OR_EQ_U 107 +#define GSA_16_BIT_MIF_TRUE 108 +#define GSA_16_BIT_MIF_FALSE 109 +#define GSA_16_BIT_MIF_LOWER_OR_EQ_U 110 +#define GSA_16_BIT_MIF_HIGHER_OR_EQ_U 111 +#define MASTER_CODE 112 +#define CHEATS_16_BIT_WRITE 114 +#define CHEATS_32_BIT_WRITE 115 CheatsData cheatsList[100]; int cheatsNumber = 0; +u32 rompatch2addr [4]; +u16 rompatch2val [4]; +u16 rompatch2oldval [4]; u8 cheatsCBASeedBuffer[0x30]; u32 cheatsCBASeed[4]; u32 cheatsCBATemporaryValue = 0; u16 cheatsCBATable[256]; bool cheatsCBATableGenerated = false; +u16 super = 0; +extern u32 mastercode; u8 cheatsCBACurrentSeed[12] = { 0x00, 0x00, 0x00, 0x00, @@ -122,15 +216,119 @@ 0x00, 0x00, 0x00, 0x00 }; +u32 seeds_v1[4]; +u32 seeds_v3[4]; + +u32 seed_gen(u8 upper, u8 seed, u8 *deadtable1, u8 *deadtable2); + +//seed tables for AR v1 +u8 v1_deadtable1[256] = { + 0x31, 0x1C, 0x23, 0xE5, 0x89, 0x8E, 0xA1, 0x37, 0x74, 0x6D, 0x67, 0xFC, 0x1F, 0xC0, 0xB1, 0x94, + 0x3B, 0x05, 0x56, 0x86, 0x00, 0x24, 0xF0, 0x17, 0x72, 0xA2, 0x3D, 0x1B, 0xE3, 0x17, 0xC5, 0x0B, + 0xB9, 0xE2, 0xBD, 0x58, 0x71, 0x1B, 0x2C, 0xFF, 0xE4, 0xC9, 0x4C, 0x5E, 0xC9, 0x55, 0x33, 0x45, + 0x7C, 0x3F, 0xB2, 0x51, 0xFE, 0x10, 0x7E, 0x75, 0x3C, 0x90, 0x8D, 0xDA, 0x94, 0x38, 0xC3, 0xE9, + 0x95, 0xEA, 0xCE, 0xA6, 0x06, 0xE0, 0x4F, 0x3F, 0x2A, 0xE3, 0x3A, 0xE4, 0x43, 0xBD, 0x7F, 0xDA, + 0x55, 0xF0, 0xEA, 0xCB, 0x2C, 0xA8, 0x47, 0x61, 0xA0, 0xEF, 0xCB, 0x13, 0x18, 0x20, 0xAF, 0x3E, + 0x4D, 0x9E, 0x1E, 0x77, 0x51, 0xC5, 0x51, 0x20, 0xCF, 0x21, 0xF9, 0x39, 0x94, 0xDE, 0xDD, 0x79, + 0x4E, 0x80, 0xC4, 0x9D, 0x94, 0xD5, 0x95, 0x01, 0x27, 0x27, 0xBD, 0x6D, 0x78, 0xB5, 0xD1, 0x31, + 0x6A, 0x65, 0x74, 0x74, 0x58, 0xB3, 0x7C, 0xC9, 0x5A, 0xED, 0x50, 0x03, 0xC4, 0xA2, 0x94, 0x4B, + 0xF0, 0x58, 0x09, 0x6F, 0x3E, 0x7D, 0xAE, 0x7D, 0x58, 0xA0, 0x2C, 0x91, 0xBB, 0xE1, 0x70, 0xEB, + 0x73, 0xA6, 0x9A, 0x44, 0x25, 0x90, 0x16, 0x62, 0x53, 0xAE, 0x08, 0xEB, 0xDC, 0xF0, 0xEE, 0x77, + 0xC2, 0xDE, 0x81, 0xE8, 0x30, 0x89, 0xDB, 0xFE, 0xBC, 0xC2, 0xDF, 0x26, 0xE9, 0x8B, 0xD6, 0x93, + 0xF0, 0xCB, 0x56, 0x90, 0xC0, 0x46, 0x68, 0x15, 0x43, 0xCB, 0xE9, 0x98, 0xE3, 0xAF, 0x31, 0x25, + 0x4D, 0x7B, 0xF3, 0xB1, 0x74, 0xE2, 0x64, 0xAC, 0xD9, 0xF6, 0xA0, 0xD5, 0x0B, 0x9B, 0x49, 0x52, + 0x69, 0x3B, 0x71, 0x00, 0x2F, 0xBB, 0xBA, 0x08, 0xB1, 0xAE, 0xBB, 0xB3, 0xE1, 0xC9, 0xA6, 0x7F, + 0x17, 0x97, 0x28, 0x72, 0x12, 0x6E, 0x91, 0xAE, 0x3A, 0xA2, 0x35, 0x46, 0x27, 0xF8, 0x12, 0x50 +}; +u8 v1_deadtable2[256] = { + 0xD8, 0x65, 0x04, 0xC2, 0x65, 0xD5, 0xB0, 0x0C, 0xDF, 0x9D, 0xF0, 0xC3, 0x9A, 0x17, 0xC9, 0xA6, + 0xE1, 0xAC, 0x0D, 0x14, 0x2F, 0x3C, 0x2C, 0x87, 0xA2, 0xBF, 0x4D, 0x5F, 0xAC, 0x2D, 0x9D, 0xE1, + 0x0C, 0x9C, 0xE7, 0x7F, 0xFC, 0xA8, 0x66, 0x59, 0xAC, 0x18, 0xD7, 0x05, 0xF0, 0xBF, 0xD1, 0x8B, + 0x35, 0x9F, 0x59, 0xB4, 0xBA, 0x55, 0xB2, 0x85, 0xFD, 0xB1, 0x72, 0x06, 0x73, 0xA4, 0xDB, 0x48, + 0x7B, 0x5F, 0x67, 0xA5, 0x95, 0xB9, 0xA5, 0x4A, 0xCF, 0xD1, 0x44, 0xF3, 0x81, 0xF5, 0x6D, 0xF6, + 0x3A, 0xC3, 0x57, 0x83, 0xFA, 0x8E, 0x15, 0x2A, 0xA2, 0x04, 0xB2, 0x9D, 0xA8, 0x0D, 0x7F, 0xB8, + 0x0F, 0xF6, 0xAC, 0xBE, 0x97, 0xCE, 0x16, 0xE6, 0x31, 0x10, 0x60, 0x16, 0xB5, 0x83, 0x45, 0xEE, + 0xD7, 0x5F, 0x2C, 0x08, 0x58, 0xB1, 0xFD, 0x7E, 0x79, 0x00, 0x34, 0xAD, 0xB5, 0x31, 0x34, 0x39, + 0xAF, 0xA8, 0xDD, 0x52, 0x6A, 0xB0, 0x60, 0x35, 0xB8, 0x1D, 0x52, 0xF5, 0xF5, 0x30, 0x00, 0x7B, + 0xF4, 0xBA, 0x03, 0xCB, 0x3A, 0x84, 0x14, 0x8A, 0x6A, 0xEF, 0x21, 0xBD, 0x01, 0xD8, 0xA0, 0xD4, + 0x43, 0xBE, 0x23, 0xE7, 0x76, 0x27, 0x2C, 0x3F, 0x4D, 0x3F, 0x43, 0x18, 0xA7, 0xC3, 0x47, 0xA5, + 0x7A, 0x1D, 0x02, 0x55, 0x09, 0xD1, 0xFF, 0x55, 0x5E, 0x17, 0xA0, 0x56, 0xF4, 0xC9, 0x6B, 0x90, + 0xB4, 0x80, 0xA5, 0x07, 0x22, 0xFB, 0x22, 0x0D, 0xD9, 0xC0, 0x5B, 0x08, 0x35, 0x05, 0xC1, 0x75, + 0x4F, 0xD0, 0x51, 0x2D, 0x2E, 0x5E, 0x69, 0xE7, 0x3B, 0xC2, 0xDA, 0xFF, 0xF6, 0xCE, 0x3E, 0x76, + 0xE8, 0x36, 0x8C, 0x39, 0xD8, 0xF3, 0xE9, 0xA6, 0x42, 0xE6, 0xC1, 0x4C, 0x05, 0xBE, 0x17, 0xF2, + 0x5C, 0x1B, 0x19, 0xDB, 0x0F, 0xF3, 0xF8, 0x49, 0xEB, 0x36, 0xF6, 0x40, 0x6F, 0xAD, 0xC1, 0x8C +}; + +//seed tables for AR v3 +u8 v3_deadtable1[256] = { + 0xD0, 0xFF, 0xBA, 0xE5, 0xC1, 0xC7, 0xDB, 0x5B, 0x16, 0xE3, 0x6E, 0x26, 0x62, 0x31, 0x2E, 0x2A, + 0xD1, 0xBB, 0x4A, 0xE6, 0xAE, 0x2F, 0x0A, 0x90, 0x29, 0x90, 0xB6, 0x67, 0x58, 0x2A, 0xB4, 0x45, + 0x7B, 0xCB, 0xF0, 0x73, 0x84, 0x30, 0x81, 0xC2, 0xD7, 0xBE, 0x89, 0xD7, 0x4E, 0x73, 0x5C, 0xC7, + 0x80, 0x1B, 0xE5, 0xE4, 0x43, 0xC7, 0x46, 0xD6, 0x6F, 0x7B, 0xBF, 0xED, 0xE5, 0x27, 0xD1, 0xB5, + 0xD0, 0xD8, 0xA3, 0xCB, 0x2B, 0x30, 0xA4, 0xF0, 0x84, 0x14, 0x72, 0x5C, 0xFF, 0xA4, 0xFB, 0x54, + 0x9D, 0x70, 0xE2, 0xFF, 0xBE, 0xE8, 0x24, 0x76, 0xE5, 0x15, 0xFB, 0x1A, 0xBC, 0x87, 0x02, 0x2A, + 0x58, 0x8F, 0x9A, 0x95, 0xBD, 0xAE, 0x8D, 0x0C, 0xA5, 0x4C, 0xF2, 0x5C, 0x7D, 0xAD, 0x51, 0xFB, + 0xB1, 0x22, 0x07, 0xE0, 0x29, 0x7C, 0xEB, 0x98, 0x14, 0xC6, 0x31, 0x97, 0xE4, 0x34, 0x8F, 0xCC, + 0x99, 0x56, 0x9F, 0x78, 0x43, 0x91, 0x85, 0x3F, 0xC2, 0xD0, 0xD1, 0x80, 0xD1, 0x77, 0xA7, 0xE2, + 0x43, 0x99, 0x1D, 0x2F, 0x8B, 0x6A, 0xE4, 0x66, 0x82, 0xF7, 0x2B, 0x0B, 0x65, 0x14, 0xC0, 0xC2, + 0x1D, 0x96, 0x78, 0x1C, 0xC4, 0xC3, 0xD2, 0xB1, 0x64, 0x07, 0xD7, 0x6F, 0x02, 0xE9, 0x44, 0x31, + 0xDB, 0x3C, 0xEB, 0x93, 0xED, 0x9A, 0x57, 0x05, 0xB9, 0x0E, 0xAF, 0x1F, 0x48, 0x11, 0xDC, 0x35, + 0x6C, 0xB8, 0xEE, 0x2A, 0x48, 0x2B, 0xBC, 0x89, 0x12, 0x59, 0xCB, 0xD1, 0x18, 0xEA, 0x72, 0x11, + 0x01, 0x75, 0x3B, 0xB5, 0x56, 0xF4, 0x8B, 0xA0, 0x41, 0x75, 0x86, 0x7B, 0x94, 0x12, 0x2D, 0x4C, + 0x0C, 0x22, 0xC9, 0x4A, 0xD8, 0xB1, 0x8D, 0xF0, 0x55, 0x2E, 0x77, 0x50, 0x1C, 0x64, 0x77, 0xAA, + 0x3E, 0xAC, 0xD3, 0x3D, 0xCE, 0x60, 0xCA, 0x5D, 0xA0, 0x92, 0x78, 0xC6, 0x51, 0xFE, 0xF9, 0x30 +}; +u8 v3_deadtable2[256] = { + 0xAA, 0xAF, 0xF0, 0x72, 0x90, 0xF7, 0x71, 0x27, 0x06, 0x11, 0xEB, 0x9C, 0x37, 0x12, 0x72, 0xAA, + 0x65, 0xBC, 0x0D, 0x4A, 0x76, 0xF6, 0x5C, 0xAA, 0xB0, 0x7A, 0x7D, 0x81, 0xC1, 0xCE, 0x2F, 0x9F, + 0x02, 0x75, 0x38, 0xC8, 0xFC, 0x66, 0x05, 0xC2, 0x2C, 0xBD, 0x91, 0xAD, 0x03, 0xB1, 0x88, 0x93, + 0x31, 0xC6, 0xAB, 0x40, 0x23, 0x43, 0x76, 0x54, 0xCA, 0xE7, 0x00, 0x96, 0x9F, 0xD8, 0x24, 0x8B, + 0xE4, 0xDC, 0xDE, 0x48, 0x2C, 0xCB, 0xF7, 0x84, 0x1D, 0x45, 0xE5, 0xF1, 0x75, 0xA0, 0xED, 0xCD, + 0x4B, 0x24, 0x8A, 0xB3, 0x98, 0x7B, 0x12, 0xB8, 0xF5, 0x63, 0x97, 0xB3, 0xA6, 0xA6, 0x0B, 0xDC, + 0xD8, 0x4C, 0xA8, 0x99, 0x27, 0x0F, 0x8F, 0x94, 0x63, 0x0F, 0xB0, 0x11, 0x94, 0xC7, 0xE9, 0x7F, + 0x3B, 0x40, 0x72, 0x4C, 0xDB, 0x84, 0x78, 0xFE, 0xB8, 0x56, 0x08, 0x80, 0xDF, 0x20, 0x2F, 0xB9, + 0x66, 0x2D, 0x60, 0x63, 0xF5, 0x18, 0x15, 0x1B, 0x86, 0x85, 0xB9, 0xB4, 0x68, 0x0E, 0xC6, 0xD1, + 0x8A, 0x81, 0x2B, 0xB3, 0xF6, 0x48, 0xF0, 0x4F, 0x9C, 0x28, 0x1C, 0xA4, 0x51, 0x2F, 0xD7, 0x4B, + 0x17, 0xE7, 0xCC, 0x50, 0x9F, 0xD0, 0xD1, 0x40, 0x0C, 0x0D, 0xCA, 0x83, 0xFA, 0x5E, 0xCA, 0xEC, + 0xBF, 0x4E, 0x7C, 0x8F, 0xF0, 0xAE, 0xC2, 0xD3, 0x28, 0x41, 0x9B, 0xC8, 0x04, 0xB9, 0x4A, 0xBA, + 0x72, 0xE2, 0xB5, 0x06, 0x2C, 0x1E, 0x0B, 0x2C, 0x7F, 0x11, 0xA9, 0x26, 0x51, 0x9D, 0x3F, 0xF8, + 0x62, 0x11, 0x2E, 0x89, 0xD2, 0x9D, 0x35, 0xB1, 0xE4, 0x0A, 0x4D, 0x93, 0x01, 0xA7, 0xD1, 0x2D, + 0x00, 0x87, 0xE2, 0x2D, 0xA4, 0xE9, 0x0A, 0x06, 0x66, 0xF8, 0x1F, 0x44, 0x75, 0xB5, 0x6B, 0x1C, + 0xFC, 0x31, 0x09, 0x48, 0xA3, 0xFF, 0x92, 0x12, 0x58, 0xE9, 0xFA, 0xAE, 0x4F, 0xE2, 0xB4, 0xCC +}; + +#define debuggerReadMemory(addr) \ + READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define debuggerReadHalfWord(addr) \ + READ16LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define debuggerReadByte(addr) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] + +#define debuggerWriteMemory(addr, value) \ + WRITE32LE(&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], value) + +#define debuggerWriteHalfWord(addr, value) \ + WRITE16LE(&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], value) + +#define debuggerWriteByte(addr, value) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) + + #define CHEAT_IS_HEX(a) ( ((a)>='A' && (a) <='F') || ((a) >='0' && (a) <= '9')) #define CHEAT_PATCH_ROM_16BIT(a,v) \ - WRITE16LE(((u16 *)&rom[(a) & 0x1ffffff]), v); + WRITE16LE(((u16 *)&rom[(a) & 0x1ffffff]), v); + +#define CHEAT_PATCH_ROM_32BIT(a,v) \ + WRITE32LE(((u32 *)&rom[(a) & 0x1ffffff]), v); static bool isMultilineWithData(int i) { // we consider it a multiline code if it has more than one line of data // otherwise, it can still be considered a single code + // (Only CBA codes can be true multilines !!!) if(i < cheatsNumber && i >= 0) switch(cheatsList[i].size) { case INT_8_BIT_WRITE: @@ -159,18 +357,96 @@ case GSA_SLOWDOWN: case CBA_ADD: case CBA_OR: - return false; - // the codes below have two lines of data - case CBA_SLIDE_CODE: + case CBA_LT: + case CBA_GT: + case GSA_8_BIT_POINTER: + case GSA_16_BIT_POINTER: + case GSA_32_BIT_POINTER: + case GSA_8_BIT_ADD: + case GSA_16_BIT_ADD: + case GSA_32_BIT_ADD: + case GSA_8_BIT_IF_LOWER_U: + case GSA_16_BIT_IF_LOWER_U: + case GSA_32_BIT_IF_LOWER_U: + case GSA_8_BIT_IF_HIGHER_U: + case GSA_16_BIT_IF_HIGHER_U: + case GSA_32_BIT_IF_HIGHER_U: + case GSA_8_BIT_IF_AND: + case GSA_16_BIT_IF_AND: + case GSA_32_BIT_IF_AND: + case GSA_8_BIT_IF_LOWER_U2: + case GSA_16_BIT_IF_LOWER_U2: + case GSA_32_BIT_IF_LOWER_U2: + case GSA_8_BIT_IF_HIGHER_U2: + case GSA_16_BIT_IF_HIGHER_U2: + case GSA_32_BIT_IF_HIGHER_U2: + case GSA_8_BIT_IF_AND2: + case GSA_16_BIT_IF_AND2: + case GSA_32_BIT_IF_AND2: + case GSA_ALWAYS: + case GSA_ALWAYS2: + case GSA_8_BIT_IF_LOWER_S: + case GSA_16_BIT_IF_LOWER_S: + case GSA_32_BIT_IF_LOWER_S: + case GSA_8_BIT_IF_HIGHER_S: + case GSA_16_BIT_IF_HIGHER_S: + case GSA_32_BIT_IF_HIGHER_S: + case GSA_8_BIT_IF_LOWER_S2: + case GSA_16_BIT_IF_LOWER_S2: + case GSA_32_BIT_IF_LOWER_S2: + case GSA_8_BIT_IF_HIGHER_S2: + case GSA_16_BIT_IF_HIGHER_S2: + case GSA_32_BIT_IF_HIGHER_S2: + case GSA_16_BIT_WRITE_IOREGS: + case GSA_32_BIT_WRITE_IOREGS: + case GSA_CODES_ON: + case GSA_8_BIT_IF_TRUE3: + case GSA_16_BIT_IF_TRUE3: + case GSA_32_BIT_IF_TRUE3: + case GSA_8_BIT_IF_FALSE3: + case GSA_16_BIT_IF_FALSE3: + case GSA_32_BIT_IF_FALSE3: + case GSA_8_BIT_IF_LOWER_S3: + case GSA_16_BIT_IF_LOWER_S3: + case GSA_32_BIT_IF_LOWER_S3: + case GSA_8_BIT_IF_HIGHER_S3: + case GSA_16_BIT_IF_HIGHER_S3: + case GSA_32_BIT_IF_HIGHER_S3: + case GSA_8_BIT_IF_LOWER_U3: + case GSA_16_BIT_IF_LOWER_U3: + case GSA_32_BIT_IF_LOWER_U3: + case GSA_8_BIT_IF_HIGHER_U3: + case GSA_16_BIT_IF_HIGHER_U3: + case GSA_32_BIT_IF_HIGHER_U3: + case GSA_8_BIT_IF_AND3: + case GSA_16_BIT_IF_AND3: + case GSA_32_BIT_IF_AND3: + case GSA_ALWAYS3: case GSA_8_BIT_GS_WRITE2: case GSA_16_BIT_GS_WRITE2: case GSA_32_BIT_GS_WRITE2: - case GSA_16_BIT_ROM_PATCH2: + case GSA_16_BIT_ROM_PATCH2C: + case GSA_16_BIT_ROM_PATCH2D: + case GSA_16_BIT_ROM_PATCH2E: + case GSA_16_BIT_ROM_PATCH2F: case GSA_8_BIT_SLIDE: case GSA_16_BIT_SLIDE: case GSA_32_BIT_SLIDE: - case CBA_LT: - case CBA_GT: + case GSA_GROUP_WRITE: + case GSA_32_BIT_ADD2: + case GSA_32_BIT_SUB2: + case GSA_16_BIT_IF_LOWER_OR_EQ_U: + case GSA_16_BIT_IF_HIGHER_OR_EQ_U: + case GSA_16_BIT_MIF_TRUE: + case GSA_16_BIT_MIF_FALSE: + case GSA_16_BIT_MIF_LOWER_OR_EQ_U: + case GSA_16_BIT_MIF_HIGHER_OR_EQ_U: + case MASTER_CODE: + case CHEATS_16_BIT_WRITE: + case CHEATS_32_BIT_WRITE: + return false; + // the codes below have two lines of data + case CBA_SLIDE_CODE: case CBA_SUPER: return true; } @@ -197,15 +473,59 @@ case GSA_SLOWDOWN: case CBA_ADD: case CBA_OR: - return 1; - case CBA_IF_KEYS_PRESSED: - case CBA_IF_TRUE: - case CBA_IF_FALSE: - case CBA_SLIDE_CODE: + case GSA_8_BIT_POINTER: + case GSA_16_BIT_POINTER: + case GSA_32_BIT_POINTER: + case GSA_8_BIT_ADD: + case GSA_16_BIT_ADD: + case GSA_32_BIT_ADD: + case GSA_CODES_ON: + case GSA_8_BIT_IF_TRUE3: + case GSA_16_BIT_IF_TRUE3: + case GSA_32_BIT_IF_TRUE3: + case GSA_8_BIT_IF_FALSE3: + case GSA_16_BIT_IF_FALSE3: + case GSA_32_BIT_IF_FALSE3: + case GSA_8_BIT_IF_LOWER_S3: + case GSA_16_BIT_IF_LOWER_S3: + case GSA_32_BIT_IF_LOWER_S3: + case GSA_8_BIT_IF_HIGHER_S3: + case GSA_16_BIT_IF_HIGHER_S3: + case GSA_32_BIT_IF_HIGHER_S3: + case GSA_8_BIT_IF_LOWER_U3: + case GSA_16_BIT_IF_LOWER_U3: + case GSA_32_BIT_IF_LOWER_U3: + case GSA_8_BIT_IF_HIGHER_U3: + case GSA_16_BIT_IF_HIGHER_U3: + case GSA_32_BIT_IF_HIGHER_U3: + case GSA_8_BIT_IF_AND3: + case GSA_16_BIT_IF_AND3: + case GSA_32_BIT_IF_AND3: + case GSA_8_BIT_IF_LOWER_U: + case GSA_16_BIT_IF_LOWER_U: + case GSA_32_BIT_IF_LOWER_U: + case GSA_8_BIT_IF_HIGHER_U: + case GSA_16_BIT_IF_HIGHER_U: + case GSA_32_BIT_IF_HIGHER_U: + case GSA_8_BIT_IF_AND: + case GSA_16_BIT_IF_AND: + case GSA_32_BIT_IF_AND: + case GSA_ALWAYS: + case GSA_8_BIT_IF_LOWER_S: + case GSA_16_BIT_IF_LOWER_S: + case GSA_32_BIT_IF_LOWER_S: + case GSA_8_BIT_IF_HIGHER_S: + case GSA_16_BIT_IF_HIGHER_S: + case GSA_32_BIT_IF_HIGHER_S: + case GSA_16_BIT_WRITE_IOREGS: + case GSA_32_BIT_WRITE_IOREGS: case GSA_8_BIT_GS_WRITE2: case GSA_16_BIT_GS_WRITE2: case GSA_32_BIT_GS_WRITE2: - case GSA_16_BIT_ROM_PATCH2: + case GSA_16_BIT_ROM_PATCH2C: + case GSA_16_BIT_ROM_PATCH2D: + case GSA_16_BIT_ROM_PATCH2E: + case GSA_16_BIT_ROM_PATCH2F: case GSA_8_BIT_SLIDE: case GSA_16_BIT_SLIDE: case GSA_32_BIT_SLIDE: @@ -215,111 +535,136 @@ case GSA_32_BIT_IF_FALSE: case CBA_LT: case CBA_GT: - return 2; + case CBA_IF_TRUE: + case CBA_IF_FALSE: case GSA_8_BIT_IF_TRUE2: case GSA_16_BIT_IF_TRUE2: case GSA_32_BIT_IF_TRUE2: case GSA_8_BIT_IF_FALSE2: case GSA_16_BIT_IF_FALSE2: case GSA_32_BIT_IF_FALSE2: - return 3; + case GSA_8_BIT_IF_LOWER_U2: + case GSA_16_BIT_IF_LOWER_U2: + case GSA_32_BIT_IF_LOWER_U2: + case GSA_8_BIT_IF_HIGHER_U2: + case GSA_16_BIT_IF_HIGHER_U2: + case GSA_32_BIT_IF_HIGHER_U2: + case GSA_8_BIT_IF_AND2: + case GSA_16_BIT_IF_AND2: + case GSA_32_BIT_IF_AND2: + case GSA_ALWAYS2: + case GSA_8_BIT_IF_LOWER_S2: + case GSA_16_BIT_IF_LOWER_S2: + case GSA_32_BIT_IF_LOWER_S2: + case GSA_8_BIT_IF_HIGHER_S2: + case GSA_16_BIT_IF_HIGHER_S2: + case GSA_32_BIT_IF_HIGHER_S2: + case GSA_GROUP_WRITE: + case GSA_32_BIT_ADD2: + case GSA_32_BIT_SUB2: + case GSA_16_BIT_IF_LOWER_OR_EQ_U: + case GSA_16_BIT_IF_HIGHER_OR_EQ_U: + case GSA_16_BIT_MIF_TRUE: + case GSA_16_BIT_MIF_FALSE: + case GSA_16_BIT_MIF_LOWER_OR_EQ_U: + case GSA_16_BIT_MIF_HIGHER_OR_EQ_U: + case MASTER_CODE: + case CHEATS_16_BIT_WRITE: + case CHEATS_32_BIT_WRITE: + case UNKNOWN_CODE: + return 1; + case CBA_IF_KEYS_PRESSED: + case CBA_SLIDE_CODE: + return 2; case CBA_SUPER: - return (cheatsList[num].value+5)/6; + return ((((cheatsList[num].value-1) & 0xFFFF)/3) + 1); } return 1; } int cheatsCheckKeys(u32 keys, u32 extended) { + bool onoff = true; int ticks = 0; - for(int i = 0; i < cheatsNumber; i++) { + int i; + mastercode = 0; + + for (i = 0; i<4; i++) + if (rompatch2addr [i] != 0) { + CHEAT_PATCH_ROM_16BIT(rompatch2addr [i],rompatch2oldval [i]); + rompatch2addr [i] = 0; + } + + for (i = 0; i < cheatsNumber; i++) { if(!cheatsList[i].enabled) { // make sure we skip other lines in this code i += getCodeLength(i)-1; continue; } switch(cheatsList[i].size) { - case INT_8_BIT_WRITE: - CPUWriteByte(cheatsList[i].address, cheatsList[i].value); + case GSA_CODES_ON: + onoff = true; break; - case INT_16_BIT_WRITE: - CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value); - break; - case INT_32_BIT_WRITE: - CPUWriteMemory(cheatsList[i].address, cheatsList[i].value); + case GSA_SLOWDOWN: + // check if button was pressed and released, if so toggle our state + if((cheatsList[i].status & 4) && !(extended & 4)) + cheatsList[i].status ^= 1; + if(extended & 4) + cheatsList[i].status |= 4; + else + cheatsList[i].status &= ~4; + + if(cheatsList[i].status & 1) + ticks += ((cheatsList[i].value & 0xFFFF) * 7); break; - case GSA_16_BIT_ROM_PATCH: - if((cheatsList[i].status & 1) == 0) { - if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { - cheatsList[i].oldValue = CPUReadHalfWord(cheatsList[i].address); - cheatsList[i].status |= 1; - CHEAT_PATCH_ROM_16BIT(cheatsList[i].address, cheatsList[i].value); + case GSA_8_BIT_SLIDE: + i++; + if(i < cheatsNumber) { + u32 addr = cheatsList[i-1].value; + u8 value = cheatsList[i].rawaddress; + int vinc = (cheatsList[i].value >> 24) & 255; + int count = (cheatsList[i].value >> 16) & 255; + int ainc = (cheatsList[i].value & 0xffff); + while(count > 0) { + CPUWriteByte(addr, value); + value += vinc; + addr += ainc; + count--; } } break; - case GSA_8_BIT_GS_WRITE: - if(extended & 4) { - CPUWriteByte(cheatsList[i].address, cheatsList[i].value); - } - break; - case GSA_16_BIT_GS_WRITE: - if(extended & 4) { - CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value); - } - break; - case GSA_32_BIT_GS_WRITE: - if(extended & 4) { - CPUWriteMemory(cheatsList[i].address, cheatsList[i].value); - } - break; - case CBA_IF_KEYS_PRESSED: - { - u16 value = cheatsList[i].value; - u32 addr = cheatsList[i].address; - if((addr & 0x30) == 0x20) { - if((keys & value) != value) { - i++; - } - } else if((addr & 0x30) == 0x10) { - if((keys & value) == value) { - i++; - } + case GSA_16_BIT_SLIDE: + i++; + if(i < cheatsNumber) { + u32 addr = cheatsList[i-1].value; + u16 value = cheatsList[i].rawaddress; + int vinc = (cheatsList[i].value >> 24) & 255; + int count = (cheatsList[i].value >> 16) & 255; + int ainc = (cheatsList[i].value & 0xffff)*2; + while(count > 0) { + CPUWriteHalfWord(addr, value); + value += vinc; + addr += ainc; + count--; } } break; - case CBA_IF_TRUE: - if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { - i++; - } - break; - case CBA_SLIDE_CODE: - { - u32 address = cheatsList[i].address; - u16 value = cheatsList[i].value; - i++; - if(i < cheatsNumber) { - int count = (cheatsList[i].address & 0xFFFF); - u16 vinc = (cheatsList[i].address >> 16) & 0xFFFF; - int inc = cheatsList[i].value; - - for(int x = 0; x < count; x++) { - CPUWriteHalfWord(address, value); - address += inc; - value += vinc; - } + case GSA_32_BIT_SLIDE: + i++; + if(i < cheatsNumber) { + u32 addr = cheatsList[i-1].value; + u32 value = cheatsList[i].rawaddress; + int vinc = (cheatsList[i].value >> 24) & 255; + int count = (cheatsList[i].value >> 16) & 255; + int ainc = (cheatsList[i].value & 0xffff)*4; + while(count > 0) { + CPUWriteMemory(addr, value); + value += vinc; + addr += ainc; + count--; } } break; - case CBA_IF_FALSE: - if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) { - i++; - } - break; - case CBA_AND: - CPUWriteHalfWord(cheatsList[i].address, - CPUReadHalfWord(cheatsList[i].address) & - cheatsList[i].value); - break; case GSA_8_BIT_GS_WRITE2: i++; if(i < cheatsNumber) { @@ -344,196 +689,644 @@ } } break; - case GSA_16_BIT_ROM_PATCH2: - i++; - if(i < cheatsNumber) { - if((cheatsList[i-1].status & 1) == 0) { - u32 addr = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000; - if(CPUReadHalfWord(addr) != (cheatsList[i].address & 0xFFFF)) { - cheatsList[i-1].oldValue = CPUReadHalfWord(addr); - cheatsList[i-1].status |= 1; - CHEAT_PATCH_ROM_16BIT(addr,cheatsList[i].address & 0xFFFF); + case GSA_16_BIT_ROM_PATCH: + if((cheatsList[i].status & 1) == 0) { + if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { + cheatsList[i].oldValue = CPUReadHalfWord(cheatsList[i].address); + cheatsList[i].status |= 1; + CHEAT_PATCH_ROM_16BIT(cheatsList[i].address, cheatsList[i].value); } } + break; + case GSA_16_BIT_ROM_PATCH2C: + i++; + if(i < cheatsNumber) { + rompatch2addr [0] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000; + rompatch2oldval [0] = CPUReadHalfWord(rompatch2addr [0]); + rompatch2val [0] = cheatsList[i].rawaddress & 0xFFFF; } break; - case GSA_8_BIT_SLIDE: + case GSA_16_BIT_ROM_PATCH2D: i++; if(i < cheatsNumber) { - u32 addr = cheatsList[i-1].value; - u8 value = cheatsList[i].address; - int vinc = (cheatsList[i].value >> 24) & 255; - int count = (cheatsList[i].value >> 16) & 255; - int ainc = (cheatsList[i].value & 0xffff); - while(count > 0) { - CPUWriteByte(addr, value); - value += vinc; - addr += ainc; - count--; - } + rompatch2addr [1] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000; + rompatch2oldval [1] = CPUReadHalfWord(rompatch2addr [1]); + rompatch2val [1] = cheatsList[i].rawaddress & 0xFFFF; } break; - case GSA_16_BIT_SLIDE: + case GSA_16_BIT_ROM_PATCH2E: i++; if(i < cheatsNumber) { - u32 addr = cheatsList[i-1].value; - u16 value = cheatsList[i].address; - int vinc = (cheatsList[i].value >> 24) & 255; - int count = (cheatsList[i].value >> 16) & 255; - int ainc = (cheatsList[i].value & 0xffff)*2; - while(count > 0) { - CPUWriteHalfWord(addr, value); - value += vinc; - addr += ainc; - count--; - } + rompatch2addr [2] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000; + rompatch2oldval [2] = CPUReadHalfWord(rompatch2addr [2]); + rompatch2val [2] = cheatsList[i].rawaddress & 0xFFFF; } break; - case GSA_32_BIT_SLIDE: + case GSA_16_BIT_ROM_PATCH2F: i++; if(i < cheatsNumber) { - u32 addr = cheatsList[i-1].value; - u32 value = cheatsList[i].address; - int vinc = (cheatsList[i].value >> 24) & 255; - int count = (cheatsList[i].value >> 16) & 255; - int ainc = (cheatsList[i].value & 0xffff)*4; - while(count > 0) { - CPUWriteMemory(addr, value); - value += vinc; - addr += ainc; - count--; + rompatch2addr [3] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000; + rompatch2oldval [3] = CPUReadHalfWord(rompatch2addr [3]); + rompatch2val [3] = cheatsList[i].rawaddress & 0xFFFF; + } + break; + case MASTER_CODE: + mastercode = cheatsList[i].address; + break; + } + if (onoff) { + switch(cheatsList[i].size) { + case INT_8_BIT_WRITE: + CPUWriteByte(cheatsList[i].address, cheatsList[i].value); + break; + case INT_16_BIT_WRITE: + CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value); + break; + case INT_32_BIT_WRITE: + CPUWriteMemory(cheatsList[i].address, cheatsList[i].value); + break; + case GSA_8_BIT_GS_WRITE: + if(extended & 4) { + CPUWriteByte(cheatsList[i].address, cheatsList[i].value); + } + break; + case GSA_16_BIT_GS_WRITE: + if(extended & 4) { + CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value); + } + break; + case GSA_32_BIT_GS_WRITE: + if(extended & 4) { + CPUWriteMemory(cheatsList[i].address, cheatsList[i].value); + } + break; + case CBA_IF_KEYS_PRESSED: + { + u16 value = cheatsList[i].value; + u32 addr = cheatsList[i].address; + if((addr & 0xF0) == 0x20) { + if((keys & value) == 0) { + i++; + } + } else if((addr & 0xF0) == 0x10) { + if((keys & value) == value) { + i++; + } + } else if((addr & 0xF0) == 0x00) { + if(((~keys) & 0x3FF) == value) { + i++; + } + } + } + break; + case CBA_IF_TRUE: + if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { + i++; + } + break; + case CBA_SLIDE_CODE: + { + u32 address = cheatsList[i].address; + u16 value = cheatsList[i].value; + i++; + if(i < cheatsNumber) { + int count = ((cheatsList[i].address - 1) & 0xFFFF); + u16 vinc = (cheatsList[i].address >> 16) & 0xFFFF; + int inc = cheatsList[i].value; + for(int x = 0; x <= count ; x++) { + CPUWriteHalfWord(address, value); + address += inc; + value += vinc; + } + } + } + break; + case CBA_IF_FALSE: + if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value){ + i++; + } + break; + case CBA_AND: + CPUWriteHalfWord(cheatsList[i].address, + CPUReadHalfWord(cheatsList[i].address) & + cheatsList[i].value); + break; + case GSA_8_BIT_IF_TRUE: + if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) { + i++; + } + break; + case GSA_32_BIT_IF_TRUE: + if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) { + i++; + } + break; + case GSA_8_BIT_IF_FALSE: + if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) { + i++; + } + break; + case GSA_32_BIT_IF_FALSE: + if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) { + i++; + } + break; + case GSA_8_BIT_FILL: + { + u32 addr = cheatsList[i].address; + u8 v = cheatsList[i].value & 0xff; + u32 end = addr + (cheatsList[i].value >> 8); + do { + CPUWriteByte(addr, v); + addr++; + } while (addr <= end); + } + break; + case GSA_16_BIT_FILL: + { + u32 addr = cheatsList[i].address; + u16 v = cheatsList[i].value & 0xffff; + u32 end = addr + ((cheatsList[i].value >> 16) << 1); + do { + CPUWriteHalfWord(addr, v); + addr+=2; + } while (addr <= end); + } + break; + case GSA_8_BIT_IF_TRUE2: + if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) { + i+=2; + } + break; + case GSA_16_BIT_IF_TRUE2: + if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { + i+=2; + } + break; + case GSA_32_BIT_IF_TRUE2: + if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) { + i+=2; + } + break; + case GSA_8_BIT_IF_FALSE2: + if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) { + i+=2; + } + break; + case GSA_16_BIT_IF_FALSE2: + if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) { + i+=2; + } + break; + case GSA_32_BIT_IF_FALSE2: + if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) { + i+=2; + } + break; + case CBA_ADD: + if ((cheatsList[i].address & 1) == 0) { + CPUWriteHalfWord(cheatsList[i].address, + CPUReadHalfWord(cheatsList[i].address) + + cheatsList[i].value); + } else { + CPUWriteMemory(cheatsList[i].address & 0x0FFFFFFE, + CPUReadMemory(cheatsList[i].address & 0x0FFFFFFE) + + cheatsList[i].value); + } + break; + case CBA_OR: + CPUWriteHalfWord(cheatsList[i].address, + CPUReadHalfWord(cheatsList[i].address) | + cheatsList[i].value); + break; + case CBA_GT: + if (!(CPUReadHalfWord(cheatsList[i].address) > cheatsList[i].value)){ + i++; + } + break; + case CBA_LT: + if (!(CPUReadHalfWord(cheatsList[i].address) < cheatsList[i].value)){ + i++; + } + break; + case CBA_SUPER: + { + int count = 2*((cheatsList[i].value -1) & 0xFFFF)+1; + u32 address = cheatsList[i].address; + for(int x = 0; x <= count; x++) { + u8 b; + int res = x % 6; + if (res==0) + i++; + if(res < 4) + b = (cheatsList[i].address >> (24-8*res)) & 0xFF; + else + b = (cheatsList[i].value >> (8 - 8*(res-4))) & 0xFF; + CPUWriteByte(address, b); + address++; + } + } + break; + case GSA_8_BIT_POINTER : + if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) || + (CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)) + { + CPUWriteByte(CPUReadMemory(cheatsList[i].address)+((cheatsList[i].value & 0xFFFFFF00) >> 8), + cheatsList[i].value & 0xFF); + } + break; + case GSA_16_BIT_POINTER : + if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) || + (CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)) + { + CPUWriteHalfWord(CPUReadMemory(cheatsList[i].address)+((cheatsList[i].value & 0xFFFF0000) >> 15), + cheatsList[i].value & 0xFFFF); + } + break; + case GSA_32_BIT_POINTER : + if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) || + (CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)) + { + CPUWriteMemory(CPUReadMemory(cheatsList[i].address), + cheatsList[i].value); + } + break; + case GSA_8_BIT_ADD : + CPUWriteByte(cheatsList[i].address, + (cheatsList[i].value & 0xFF) + CPUReadMemory(cheatsList[i].address) & 0xFF); + break; + case GSA_16_BIT_ADD : + CPUWriteHalfWord(cheatsList[i].address, + (cheatsList[i].value & 0xFFFF) + CPUReadMemory(cheatsList[i].address) & 0xFFFF); + break; + case GSA_32_BIT_ADD : + CPUWriteMemory(cheatsList[i].address , + cheatsList[i].value + CPUReadMemory(cheatsList[i].address) & 0xFFFFFFFF); + break; + case GSA_8_BIT_IF_LOWER_U: + if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) { + i++; + } + break; + case GSA_16_BIT_IF_LOWER_U: + if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) { + i++; + } + break; + case GSA_32_BIT_IF_LOWER_U: + if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) { + i++; + } + break; + case GSA_8_BIT_IF_HIGHER_U: + if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) { + i++; + } + break; + case GSA_16_BIT_IF_HIGHER_U: + if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) { + i++; + } + break; + case GSA_32_BIT_IF_HIGHER_U: + if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) { + i++; + } + break; + case GSA_8_BIT_IF_AND: + if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) { + i++; + } + break; + case GSA_16_BIT_IF_AND: + if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) { + i++; + } + break; + case GSA_32_BIT_IF_AND: + if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) { + i++; + } + break; + case GSA_8_BIT_IF_LOWER_U2: + if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) { + i+=2; + } + break; + case GSA_16_BIT_IF_LOWER_U2: + if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) { + i+=2; + } + break; + case GSA_32_BIT_IF_LOWER_U2: + if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) { + i+=2; + } + break; + case GSA_8_BIT_IF_HIGHER_U2: + if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) { + i+=2; + } + break; + case GSA_16_BIT_IF_HIGHER_U2: + if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) { + i+=2; + } + break; + case GSA_32_BIT_IF_HIGHER_U2: + if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) { + i+=2; + } + break; + case GSA_8_BIT_IF_AND2: + if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) { + i+=2; + } + break; + case GSA_16_BIT_IF_AND2: + if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) { + i+=2; + } + break; + case GSA_32_BIT_IF_AND2: + if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) { + i+=2; + } + break; + case GSA_ALWAYS: + i++; + break; + case GSA_ALWAYS2: + i+=2; + break; + case GSA_8_BIT_IF_LOWER_S: + if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) { + i++; + } + break; + case GSA_16_BIT_IF_LOWER_S: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) { + i++; + } + break; + case GSA_32_BIT_IF_LOWER_S: + if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) { + i++; + } + break; + case GSA_8_BIT_IF_HIGHER_S: + if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) { + i++; + } + break; + case GSA_16_BIT_IF_HIGHER_S: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) { + i++; + } + break; + case GSA_32_BIT_IF_HIGHER_S: + if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) { + i++; + } + break; + case GSA_8_BIT_IF_LOWER_S2: + if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) { + i+=2; + } + break; + case GSA_16_BIT_IF_LOWER_S2: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) { + i+=2; + } + break; + case GSA_32_BIT_IF_LOWER_S2: + if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) { + i+=2; + } + break; + case GSA_8_BIT_IF_HIGHER_S2: + if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) { + i+=2; + } + break; + case GSA_16_BIT_IF_HIGHER_S2: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) { + i+=2; + } + break; + case GSA_32_BIT_IF_HIGHER_S2: + if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) { + i+=2; + } + break; + case GSA_16_BIT_WRITE_IOREGS: + if ((cheatsList[i].address <= 0x3FF) && (cheatsList[i].address != 0x6) && + (cheatsList[i].address != 0x130)) + ioMem[cheatsList[i].address & 0x3FE]=cheatsList[i].value & 0xFFFF; + break; + case GSA_32_BIT_WRITE_IOREGS: + if (cheatsList[i].address<=0x3FF) + { + if (((cheatsList[i].address & 0x3FC) != 0x6) && ((cheatsList[i].address & 0x3FC) != 0x130)) + ioMem[cheatsList[i].address & 0x3FC]= (cheatsList[i].value & 0xFFFF); + if ((((cheatsList[i].address & 0x3FC)+2) != 0x6) && ((cheatsList[i].address & 0x3FC) +2) != 0x130) + ioMem[(cheatsList[i].address & 0x3FC) + 2 ]= ((cheatsList[i].value>>16 ) & 0xFFFF); + } + break; + case GSA_8_BIT_IF_TRUE3: + if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) { + onoff=false; + } + break; + case GSA_16_BIT_IF_TRUE3: + if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { + onoff=false; + } + break; + case GSA_32_BIT_IF_TRUE3: + if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) { + onoff=false; + } + break; + case GSA_8_BIT_IF_FALSE3: + if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) { + onoff=false; + } + break; + case GSA_16_BIT_IF_FALSE3: + if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) { + onoff=false; + } + break; + case GSA_32_BIT_IF_FALSE3: + if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) { + onoff=false; + } + break; + case GSA_8_BIT_IF_LOWER_S3: + if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) { + onoff=false; + } + break; + case GSA_16_BIT_IF_LOWER_S3: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) { + onoff=false; + } + break; + case GSA_32_BIT_IF_LOWER_S3: + if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) { + onoff=false; + } + break; + case GSA_8_BIT_IF_HIGHER_S3: + if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) { + onoff=false; + } + break; + case GSA_16_BIT_IF_HIGHER_S3: + if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) { + onoff=false; + } + break; + case GSA_32_BIT_IF_HIGHER_S3: + if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) { + onoff=false; + } + break; + case GSA_8_BIT_IF_LOWER_U3: + if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) { + onoff=false; + } + break; + case GSA_16_BIT_IF_LOWER_U3: + if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) { + onoff=false; + } + break; + case GSA_32_BIT_IF_LOWER_U3: + if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) { + onoff=false; + } + break; + case GSA_8_BIT_IF_HIGHER_U3: + if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) { + onoff=false; + } + break; + case GSA_16_BIT_IF_HIGHER_U3: + if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) { + onoff=false; + } + break; + case GSA_32_BIT_IF_HIGHER_U3: + if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) { + onoff=false; } - } - break; - case GSA_8_BIT_IF_TRUE: - if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) { - i++; - } - break; - case GSA_32_BIT_IF_TRUE: - if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) { - i++; - } - break; - case GSA_8_BIT_IF_FALSE: - if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) { - i++; - } - break; - case GSA_32_BIT_IF_FALSE: - if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) { - i++; - } - break; - case GSA_8_BIT_FILL: - { - u32 addr = cheatsList[i].address; - u8 v = cheatsList[i].value & 0xff; - u32 end = addr + (cheatsList[i].value >> 8); - do { - CPUWriteByte(addr, v); - addr++; - } while (addr <= end); - } - break; - case GSA_16_BIT_FILL: - { - u32 addr = cheatsList[i].address; - u16 v = cheatsList[i].value & 0xffff; - u32 end = addr + ((cheatsList[i].value >> 16) << 1); - do { - CPUWriteHalfWord(addr, v); - addr+=2; - } while (addr <= end); - } - break; - case GSA_8_BIT_IF_TRUE2: - if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) { - i+=2; - } - break; - case GSA_16_BIT_IF_TRUE2: - if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { - i+=2; - } - break; - case GSA_32_BIT_IF_TRUE2: - if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) { - i+=2; - } - break; - case GSA_8_BIT_IF_FALSE2: - if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) { - i+=2; - } - break; - case GSA_16_BIT_IF_FALSE2: - if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) { - i+=2; - } - break; - case GSA_32_BIT_IF_FALSE2: - if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) { - i+=2; - } - break; - case GSA_SLOWDOWN: - // check if button was pressed and released, if so toggle our state - if((cheatsList[i].status & 4) && !(extended & 4)) - cheatsList[i].status ^= 1; - if(extended & 4) - cheatsList[i].status |= 4; - else - cheatsList[i].status &= ~4; - - if(cheatsList[i].status & 1) - ticks += 2*256*((cheatsList[i].value >> 8) & 255); - break; - case CBA_ADD: - CPUWriteHalfWord(cheatsList[i].address, - CPUReadHalfWord(cheatsList[i].address) + - (u16)cheatsList[i].value); - break; - case CBA_OR: - CPUWriteHalfWord(cheatsList[i].address, - CPUReadHalfWord(cheatsList[i].address) | - cheatsList[i].value); - break; - case CBA_LT: - if(CPUReadHalfWord(cheatsList[i].address) >= cheatsList[i].value) + break; + case GSA_8_BIT_IF_AND3: + if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) { + onoff=false; + } + break; + case GSA_16_BIT_IF_AND3: + if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) { + onoff=false; + } + break; + case GSA_32_BIT_IF_AND3: + if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) { + onoff=false; + } + break; + case GSA_ALWAYS3: + if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) { + onoff=false; + } + break; + case GSA_GROUP_WRITE: + { + int count = ((cheatsList[i].address) & 0xFFFE) +1; + u32 value = cheatsList[i].value; + if (count==0) + i++; + else + for (int x = 1; x <= count; x++) { + if ((x % 2) ==0){ + if (x> (24-8*res)) & 0xFF; - else - b = (cheatsList[i].value >> (8 - 8*(res-4))) & 0x0FF; - CPUWriteByte(address, b); - address++; - if(x && !res) - i++; + break; + case GSA_16_BIT_IF_LOWER_OR_EQ_U: + if(CPUReadHalfWord(cheatsList[i].address) > cheatsList[i].value) { + i++; } - if(count % 6) + break; + case GSA_16_BIT_IF_HIGHER_OR_EQ_U: + if(CPUReadHalfWord(cheatsList[i].address) < cheatsList[i].value) { i++; + } + break; + case GSA_16_BIT_MIF_TRUE: + if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) { + i+=((cheatsList[i].rawaddress >> 0x10) & 0xFF); + } + break; + case GSA_16_BIT_MIF_FALSE: + if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) { + i+=(cheatsList[i].rawaddress >> 0x10) & 0xFF; + } + break; + case GSA_16_BIT_MIF_LOWER_OR_EQ_U: + if(CPUReadHalfWord(cheatsList[i].address) > cheatsList[i].value) { + i+=(cheatsList[i].rawaddress >> 0x10) & 0xFF; + } + break; + case GSA_16_BIT_MIF_HIGHER_OR_EQ_U: + if(CPUReadHalfWord(cheatsList[i].address) < cheatsList[i].value) { + i+=(cheatsList[i].rawaddress >> 0x10) & 0xFF; + } + break; + case CHEATS_16_BIT_WRITE: + if ((cheatsList[i].address>>24)>=0x08) { + CHEAT_PATCH_ROM_16BIT(cheatsList[i].address, cheatsList[i].value); + } else { + CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value); + } + break; + case CHEATS_32_BIT_WRITE: + if ((cheatsList[i].address>>24)>=0x08) { + CHEAT_PATCH_ROM_32BIT(cheatsList[i].address, cheatsList[i].value); + } else { + CPUWriteMemory(cheatsList[i].address, cheatsList[i].value); + } + break; } - break; } } + for (i = 0; i<4; i++) + if (rompatch2addr [i] != 0) + CHEAT_PATCH_ROM_16BIT(rompatch2addr [i],rompatch2val [i]); return ticks; } void cheatsAdd(const char *codeStr, const char *desc, + u32 rawaddress, u32 address, u32 value, int code, @@ -543,6 +1336,7 @@ int x = cheatsNumber; cheatsList[x].code = code; cheatsList[x].size = size; + cheatsList[x].rawaddress = rawaddress; cheatsList[x].address = address; cheatsList[x].value = value; strcpy(cheatsList[x].codestring, codeStr); @@ -562,6 +1356,12 @@ case INT_32_BIT_WRITE: cheatsList[x].oldValue = CPUReadMemory(address); break; + case CHEATS_16_BIT_WRITE: + cheatsList[x].oldValue = CPUReadHalfWord(address); + break; + case CHEATS_32_BIT_WRITE: + cheatsList[x].oldValue = CPUReadMemory(address); + break; } cheatsNumber++; } @@ -583,6 +1383,19 @@ case INT_32_BIT_WRITE: CPUWriteMemory(cheatsList[x].address, cheatsList[x].oldValue); break; + case CHEATS_16_BIT_WRITE: + if ((cheatsList[x].address>>24)>=0x08) { + CHEAT_PATCH_ROM_16BIT(cheatsList[x].address, cheatsList[x].oldValue); + } else { + CPUWriteHalfWord(cheatsList[x].address, cheatsList[x].oldValue); + } + break; + case CHEATS_32_BIT_WRITE: + if ((cheatsList[x].address>>24)>=0x08) { + CHEAT_PATCH_ROM_32BIT(cheatsList[x].address, cheatsList[x].oldValue); + } else { + CPUWriteMemory(cheatsList[x].address, cheatsList[x].oldValue); + } case GSA_16_BIT_ROM_PATCH: if(cheatsList[x].status & 1) { cheatsList[x].status &= ~1; @@ -590,14 +1403,17 @@ cheatsList[x].oldValue); } break; - case GSA_16_BIT_ROM_PATCH2: + case GSA_16_BIT_ROM_PATCH2C: + case GSA_16_BIT_ROM_PATCH2D: + case GSA_16_BIT_ROM_PATCH2E: + case GSA_16_BIT_ROM_PATCH2F: if(cheatsList[x].status & 1) { cheatsList[x].status &= ~1; - CHEAT_PATCH_ROM_16BIT(((cheatsList[x].value & 0x00FFFFFF) << 1)+ - 0x8000000, - cheatsList[x].oldValue); } break; + case MASTER_CODE: + mastercode=0; + break; } } if((x+1) < cheatsNumber) { @@ -619,6 +1435,7 @@ { if(i >= 0 && i < cheatsNumber) { cheatsList[i].enabled = true; + mastercode = 0; } } @@ -633,14 +1450,17 @@ cheatsList[i].oldValue); } break; - case GSA_16_BIT_ROM_PATCH2: + case GSA_16_BIT_ROM_PATCH2C: + case GSA_16_BIT_ROM_PATCH2D: + case GSA_16_BIT_ROM_PATCH2E: + case GSA_16_BIT_ROM_PATCH2F: if(cheatsList[i].status & 1) { cheatsList[i].status &= ~1; - CHEAT_PATCH_ROM_16BIT(((cheatsList[i].value & 0x00FFFFFF) << 1)+ - 0x8000000, - cheatsList[i].oldValue); } break; + case MASTER_CODE: + mastercode=0; + break; } cheatsList[i].enabled = false; } @@ -648,7 +1468,7 @@ bool cheatsVerifyCheatCode(const char *code, const char *desc) { - int len = strlen(code); + size_t len = strlen(code); if(len != 11 && len != 13 && len != 17) { systemMessage(MSG_INVALID_CHEAT_CODE, N_("Invalid cheat code '%s'"), code); return false; @@ -659,7 +1479,7 @@ return false; } - int i; + size_t i; for(i = 0; i < 8; i++) { if(!CHEAT_IS_HEX(code[i])) { // wrong cheat @@ -686,8 +1506,18 @@ sscanf(buffer, "%x", &address); switch(address >> 24) { - case 2: - case 3: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: break; default: systemMessage(MSG_INVALID_CHEAT_CODE_ADDRESS, @@ -700,10 +1530,10 @@ sscanf(buffer, "%x", &value); int type = 0; if(len == 13) - type = 1; + type = 114; if(len == 17) - type = 2; - cheatsAdd(code, desc, address, value, type, type); + type = 115; + cheatsAdd(code, desc, address, address, value, type, type); return true; } @@ -712,11 +1542,46 @@ cheatsVerifyCheatCode(code, desc); } -void cheatsDecryptGSACode(u32& address, u32& value, bool v3) +u16 cheatsGSAGetDeadface(bool v3) +{ + for(int i = cheatsNumber-1; i >= 0; i--) + if ((cheatsList[i].address == 0xDEADFACE) && (cheatsList[i].code == (v3 ? 257 : 256))) + return cheatsList[i].value & 0xFFFF; + return 0; +} + +void cheatsGSAChangeEncryption(u16 value, bool v3) { + int i; + u8 *deadtable1, *deadtable2; + + if (v3) { + deadtable1 = (u8*)(&v3_deadtable1); + deadtable2 = (u8*)(&v3_deadtable2); + for (i = 0; i < 4; i++) + seeds_v3[i] = seed_gen(((value & 0xFF00) >> 8), (value & 0xFF) + i, deadtable1, deadtable2); + } + else { + deadtable1 = (u8*)(&v1_deadtable1); + deadtable2 = (u8*)(&v1_deadtable2); + for (i = 0; i < 4; i++){ + seeds_v1[i] = seed_gen(((value & 0xFF00) >> 8), (value & 0xFF) + i, deadtable1, deadtable2); + } + } +} + +u32 seed_gen(u8 upper, u8 seed, u8 *deadtable1, u8 *deadtable2) { + int i; + u32 newseed = 0; + + for (i = 0; i < 4; i++) + newseed = ((newseed << 8) | ((deadtable1[(i + upper) & 0xFF] + deadtable2[seed]) & 0xFF)); + + return newseed; +} + +void cheatsDecryptGSACode(u32& address, u32& value, bool v3) { u32 rollingseed = 0xC6EF3720; - u32 seeds_v1[] = { 0x09F4FBBD, 0x9681884A, 0x352027E9, 0xF3DEE5A7 }; - u32 seeds_v3[] = { 0x7AA9648F, 0x7FAE6994, 0xC0EFAAD5, 0x42712C57 }; u32 *seeds = v3 ? seeds_v3 : seeds_v1; int bitsleft = 32; @@ -758,7 +1623,7 @@ buffer[8] = 0; u32 value; sscanf(buffer, "%x", &value); - + cheatsGSAChangeEncryption(cheatsGSAGetDeadface (v3), v3); cheatsDecryptGSACode(address, value, v3); if(value == 0x1DC0DE) { @@ -773,17 +1638,26 @@ systemMessage(MSG_GBA_CODE_WARNING, N_("Warning: cheats are for game %s. Current game is %s.\nCodes may not work correctly."), buffer, buffer2); } - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, v3 ? 257 : 256, + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, v3 ? 257 : 256, UNKNOWN_CODE); return; } if(isMultilineWithData(cheatsNumber-1)) { - cheatsAdd(code, desc, address, value, v3 ? 257 : 256, UNKNOWN_CODE); + cheatsAdd(code, desc, address, address, value, v3 ? 257 : 256, UNKNOWN_CODE); return; } if(v3) { - int type = (address >> 25) & 127; + int type = ((address >> 25) & 127) | ((address >> 17) & 0x80); u32 addr = (address & 0x00F00000) << 4 | (address & 0x0003FFFF); + u16 mcode = (address>>24 & 0xFF); + + if ((mcode & 0xFE) == 0xC4) + { + cheatsAdd(code, desc, address, (address & 0x1FFFFFF) | (0x08000000), + value, 257, MASTER_CODE); + mastercode = (address & 0x1FFFFFF) | (0x08000000); + } + else switch(type) { case 0x00: if(address == 0) { @@ -791,83 +1665,278 @@ addr = (value & 0x00F00000) << 4 | (value & 0x0003FFFF); switch(type) { case 0x04: - cheatsAdd(code, desc, 0, value & 0x00FFFFFF, 257, GSA_SLOWDOWN); + cheatsAdd(code, desc, address, 0, value & 0x00FFFFFF, 257, GSA_SLOWDOWN); break; case 0x08: - cheatsAdd(code, desc, 0, addr, 257, GSA_8_BIT_GS_WRITE2); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_8_BIT_GS_WRITE2); break; case 0x09: - cheatsAdd(code, desc, 0, addr, 257, GSA_16_BIT_GS_WRITE2); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_16_BIT_GS_WRITE2); break; case 0x0a: - cheatsAdd(code, desc, 0, addr, 257, GSA_32_BIT_GS_WRITE2); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_32_BIT_GS_WRITE2); break; case 0x0c: + cheatsAdd(code, desc, address, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2C); + break; case 0x0d: + cheatsAdd(code, desc, address, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2D); + break; case 0x0e: + cheatsAdd(code, desc, address, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2E); + break; case 0x0f: - cheatsAdd(code, desc, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2); + cheatsAdd(code, desc, address, 0, value & 0x00FFFFFF, 257, GSA_16_BIT_ROM_PATCH2F); + break; + case 0x20: + cheatsAdd(code, desc, address, 0, addr, 257, GSA_CODES_ON); break; case 0x40: - cheatsAdd(code, desc, 0, addr, 257, GSA_8_BIT_SLIDE); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_8_BIT_SLIDE); break; case 0x41: - cheatsAdd(code, desc, 0, addr, 257, GSA_16_BIT_SLIDE); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_16_BIT_SLIDE); break; case 0x42: - cheatsAdd(code, desc, 0, addr, 257, GSA_32_BIT_SLIDE); + cheatsAdd(code, desc, address, 0, addr, 257, GSA_32_BIT_SLIDE); break; default: - cheatsAdd(code, desc, address, value, 257, UNKNOWN_CODE); + cheatsAdd(code, desc, address, address, value, 257, UNKNOWN_CODE); break; } } else - cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_FILL); + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_FILL); break; case 0x01: - cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_FILL); + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_FILL); break; case 0x02: - cheatsAdd(code, desc, addr, value, 257, INT_32_BIT_WRITE); + cheatsAdd(code, desc, address, addr, value, 257, INT_32_BIT_WRITE); break; case 0x04: - cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_TRUE); + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_TRUE); break; case 0x05: - cheatsAdd(code, desc, addr, value, 257, CBA_IF_TRUE); + cheatsAdd(code, desc, address, addr, value, 257, CBA_IF_TRUE); break; case 0x06: - cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_TRUE); + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_TRUE); + break; + case 0x07: + cheatsAdd(code, desc, address, addr, value, 257, GSA_ALWAYS); break; case 0x08: - cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_FALSE); + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_FALSE); break; case 0x09: - cheatsAdd(code, desc, addr, value, 257, CBA_IF_FALSE); + cheatsAdd(code, desc, address, addr, value, 257, CBA_IF_FALSE); break; case 0x0a: - cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_FALSE); + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_FALSE); + break; + case 0xc: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_S); + break; + case 0xd: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_S); + break; + case 0xe: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_S); + break; + case 0x10: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_S); + break; + case 0x11: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_S); + break; + case 0x12: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_S); + break; + case 0x14: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_U); + break; + case 0x15: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_U); + break; + case 0x16: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_U); + break; + case 0x18: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_U); + break; + case 0x19: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_U); + break; + case 0x1A: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_U); + break; + case 0x1C: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_AND); + break; + case 0x1D: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_AND); + break; + case 0x1E: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_AND); + break; + case 0x20: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_POINTER); + break; + case 0x21: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_POINTER); + break; + case 0x22: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_POINTER); break; case 0x24: - cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_TRUE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_TRUE2); break; case 0x25: - cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_IF_TRUE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_TRUE2); break; case 0x26: - cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_TRUE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_TRUE2); + break; + case 0x27: + cheatsAdd(code, desc, address, addr, value, 257, GSA_ALWAYS2); break; case 0x28: - cheatsAdd(code, desc, addr, value, 257, GSA_8_BIT_IF_FALSE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_FALSE2); break; case 0x29: - cheatsAdd(code, desc, addr, value, 257, GSA_16_BIT_IF_FALSE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_FALSE2); break; case 0x2a: - cheatsAdd(code, desc, addr, value, 257, GSA_32_BIT_IF_FALSE2); + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_FALSE2); + break; + case 0x2c: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_S2); + break; + case 0x2d: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_S2); + break; + case 0x2e: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_S2); + break; + case 0x30: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_S2); + break; + case 0x31: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_S2); + break; + case 0x32: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_S2); + break; + case 0x34: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_U2); + break; + case 0x35: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_U2); + break; + case 0x36: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_U2); + break; + case 0x38: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_U2); + break; + case 0x39: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_U2); + break; + case 0x3A: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_U2); + break; + case 0x3C: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_AND2); + break; + case 0x3D: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_AND2); + break; + case 0x3E: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_AND2); + break; + case 0x40: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_ADD); + break; + case 0x41: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_ADD); + break; + case 0x42: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_ADD); + break; + case 0x44: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_TRUE3); + break; + case 0x45: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_TRUE3); + break; + case 0x46: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_TRUE3); + break; + case 0x47: + cheatsAdd(code, desc, address, addr, value, 257, GSA_ALWAYS3); + break; + case 0x48: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_FALSE3); + break; + case 0x49: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_FALSE3); + break; + case 0x4a: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_FALSE3); + break; + case 0x4c: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_S3); + break; + case 0x4d: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_S3); + break; + case 0x4e: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_S3); + break; + case 0x50: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_S3); + break; + case 0x51: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_S3); + break; + case 0x52: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_S3); + break; + case 0x54: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_LOWER_U3); + break; + case 0x55: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_LOWER_U3); + break; + case 0x56: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_LOWER_U3); + break; + case 0x58: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_HIGHER_U3); + break; + case 0x59: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_HIGHER_U3); + break; + case 0x5a: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_HIGHER_U3); + break; + case 0x5c: + cheatsAdd(code, desc, address, addr, value, 257, GSA_8_BIT_IF_AND3); + break; + case 0x5d: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_IF_AND3); + break; + case 0x5e: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_IF_AND3); + break; + case 0x63: + cheatsAdd(code, desc, address, addr, value, 257, GSA_16_BIT_WRITE_IOREGS); + break; + case 0xE3: + cheatsAdd(code, desc, address, addr, value, 257, GSA_32_BIT_WRITE_IOREGS); break; default: - cheatsAdd(code, desc, address, value, 257, UNKNOWN_CODE); + cheatsAdd(code, desc, address, address, value, 257, UNKNOWN_CODE); break; } } else { @@ -876,54 +1945,136 @@ case 0: case 1: case 2: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256, type); + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 256, type); + break; + case 3: + switch ((address >> 0x10) & 0xFF){ + case 0x00: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 256, GSA_GROUP_WRITE); + break; + case 0x10: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFF, 256, GSA_32_BIT_ADD ); + break; + case 0x20: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, (~(address & 0xFF)+1), 256, GSA_32_BIT_ADD ); + break; + case 0x30: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFFFF, 256, GSA_32_BIT_ADD ); + break; + case 0x40: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, (~(address & 0xFFFF)+1), 256, GSA_32_BIT_ADD ); + break; + case 0x50: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 256, GSA_32_BIT_ADD2); + break; + case 0x60: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 256, GSA_32_BIT_SUB2); + break; + default: + // unsupported code + cheatsAdd(code, desc, address, address, value, 256, + UNKNOWN_CODE); + break; + } break; case 6: address <<= 1; - type = (address >> 28) & 15; - if(type == 0x0c) { - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256, + type = (value >> 24) & 0xFF; + if(type == 0x00) { + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0xFFFF, 256, GSA_16_BIT_ROM_PATCH); break; } // unsupported code - cheatsAdd(code, desc, address, value, 256, + cheatsAdd(code, desc, address, address, value, 256, UNKNOWN_CODE); break; case 8: switch((address >> 20) & 15) { case 1: - cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256, + cheatsAdd(code, desc, address, address & 0x0F0FFFFF, value, 256, GSA_8_BIT_GS_WRITE); break; case 2: - cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256, + cheatsAdd(code, desc, address, address & 0x0F0FFFFF, value, 256, GSA_16_BIT_GS_WRITE); break; - case 3: - cheatsAdd(code, desc, address & 0x0F0FFFFF, value, 256, + case 4: + // This code is buggy : the value is always set to 0 ! + cheatsAdd(code, desc, address, address & 0x0F0FFFFF, 0, 256, GSA_32_BIT_GS_WRITE); + break; case 15: - cheatsAdd(code, desc, 0, value & 0xFF00, 256, GSA_SLOWDOWN); + cheatsAdd(code, desc, address, 0, value & 0xFFFF, 256, GSA_SLOWDOWN); break; default: // unsupported code - cheatsAdd(code, desc, address, value, 256, + cheatsAdd(code, desc, address, address, value, 256, UNKNOWN_CODE); break; } break; case 0x0d: if(address != 0xDEADFACE) { - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 256, + switch((value >> 20) & 0xF) { + case 0: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0xFFFF, 256, CBA_IF_TRUE); + break; + case 1: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0xFFFF, 256, + CBA_IF_FALSE); + break; + case 2: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0xFFFF, 256, + GSA_16_BIT_IF_LOWER_OR_EQ_U); + break; + case 3: + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0xFFFF, 256, + GSA_16_BIT_IF_HIGHER_OR_EQ_U); + break; + default: + // unsupported code + cheatsAdd(code, desc, address, address, value, 256, + UNKNOWN_CODE); + break; + } } else - cheatsAdd(code, desc, address, value, 256, + cheatsAdd(code, desc, address, address, value, 256, UNKNOWN_CODE); break; - default: + case 0x0e: + switch((value >> 28) & 0xF) { + case 0: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFFFF, 256, + GSA_16_BIT_MIF_TRUE); + break; + case 1: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFFFF, 256, + GSA_16_BIT_MIF_FALSE); + break; + case 2: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFFFF, 256, + GSA_16_BIT_MIF_LOWER_OR_EQ_U); + break; + case 3: + cheatsAdd(code, desc, address, value & 0x0FFFFFFF, address & 0xFFFF, 256, + GSA_16_BIT_MIF_HIGHER_OR_EQ_U); + break; + default: + // unsupported code + cheatsAdd(code, desc, address, address, value, 256, + UNKNOWN_CODE); + break; + } + break; + case 0x0f: + cheatsAdd(code, desc, address, (address & 0xFFFFFFF), value, 256, MASTER_CODE); + mastercode = (address & 0xFFFFFFF); + break; + default: // unsupported code - cheatsAdd(code, desc, address, value, 256, + cheatsAdd(code, desc, address, address, value, 256, UNKNOWN_CODE); break; } @@ -1359,7 +2510,7 @@ u32 seed[8]; cheatsCBAParseSeedCode(address, value, seed); cheatsCBAChangeEncryption(seed); - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, UNKNOWN_CODE); + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 512, UNKNOWN_CODE); } else { if(cheatsCBAShouldDecrypt()) cheatsCBADecrypt(array); @@ -1369,8 +2520,10 @@ int type = (address >> 28) & 15; - if(isMultilineWithData(cheatsNumber-1)) { - cheatsAdd(code, desc, address, value, 512, UNKNOWN_CODE); + if(isMultilineWithData(cheatsNumber-1) || (super>0)) { + cheatsAdd(code, desc, address, address, value, 512, UNKNOWN_CODE); + if (super>0) + super-= 1; return; } @@ -1384,61 +2537,71 @@ systemMessage(MSG_CBA_CODE_WARNING, N_("Warning: Codes seem to be for a different game.\nCodes may not work correctly.")); } - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 512, UNKNOWN_CODE); } break; + case 0x01: + cheatsAdd(code, desc, address, (address & 0x1FFFFFF) | 0x08000000, value, 512, MASTER_CODE); + mastercode = (address & 0x1FFFFFF) | 0x08000000; + break; case 0x02: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, CBA_OR); break; case 0x03: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 512, INT_8_BIT_WRITE); break; case 0x04: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, CBA_SLIDE_CODE); break; case 0x05: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, - CBA_SUPER); + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, + CBA_SUPER); + super = getCodeLength(cheatsNumber-1); break; case 0x06: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, CBA_AND); break; case 0x07: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, CBA_IF_TRUE); break; case 0x08: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, INT_16_BIT_WRITE); break; case 0x0a: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, CBA_IF_FALSE); break; case 0x0b: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, - CBA_LT); + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, + CBA_GT); break; case 0x0c: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, - CBA_GT); + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, + CBA_LT); break; case 0x0d: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + if ((address & 0xF0)<0x30) + cheatsAdd(code, desc, address, address & 0xF0, value, 512, CBA_IF_KEYS_PRESSED); break; case 0x0e: - cheatsAdd(code, desc, address & 0x0FFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value & 0x8000 ? value | 0xFFFF0000 : value, 512, CBA_ADD); break; + case 0x0f: + cheatsAdd(code, desc, address, address & 0x0FFFFFFE, value, 512, + GSA_16_BIT_IF_AND); + break; default: // unsupported code - cheatsAdd(code, desc, address & 0xFFFFFFFF, value, 512, + cheatsAdd(code, desc, address, address & 0xFFFFFFFF, value, 512, UNKNOWN_CODE); break; } @@ -1452,17 +2615,33 @@ utilGzWrite(file, cheatsList, sizeof(cheatsList)); } -void cheatsReadGame(gzFile file) +void cheatsReadGame(gzFile file, int version) { cheatsNumber = 0; cheatsNumber = utilReadInt(file); - utilGzRead(file, cheatsList, sizeof(cheatsList)); + if (version > 8) + utilGzRead(file, cheatsList, sizeof(cheatsList)); + bool firstCodeBreaker = true; for(int i = 0; i < cheatsNumber; i++) { + if (version <9) + { + cheatsList[i].code = utilReadInt(file); + cheatsList[i].size = utilReadInt(file); + cheatsList[i].status = utilReadInt(file); + cheatsList[i].enabled = utilReadInt(file) ? true : false; + utilGzRead(file, &cheatsList[i].address, sizeof(u32)); + cheatsList[i].rawaddress = cheatsList[i].address; + utilGzRead(file, &cheatsList[i].value, sizeof(u32)); + utilGzRead(file, &cheatsList[i].oldValue, sizeof(u32)); + utilGzRead(file, &cheatsList[i].codestring, 20*sizeof(char)); + utilGzRead(file, &cheatsList[i].desc, 32*sizeof(char)); + } + cheatsList[i].status = 0; if(!cheatsList[i].codestring[0]) { switch(cheatsList[i].size) { @@ -1515,7 +2694,7 @@ return; int version = 1; fwrite(&version, 1, sizeof(version), f); - int type = 0; + int type = 1; fwrite(&type, 1, sizeof(type), f); fwrite(&cheatsNumber, 1, sizeof(cheatsNumber), f); fwrite(cheatsList, 1, sizeof(cheatsList), f); @@ -1524,7 +2703,6 @@ bool cheatsLoadCheatList(const char *file) { - cheatsNumber = 0; int count = 0; @@ -1553,7 +2731,8 @@ return false; } - if(type != 0) { + + if((type != 0) && (type != 1)) { systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE, N_("Unsupported cheat list type %d"), type); fclose(f); @@ -1564,10 +2743,31 @@ fclose(f); return false; } - - if(fread(cheatsList, 1, sizeof(cheatsList), f) != sizeof(cheatsList)) { - fclose(f); - return false; + if (type == 1) + { + if(fread(cheatsList, 1, sizeof(cheatsList), f) != sizeof(cheatsList)) { + fclose(f); + return false; + } + } + else if (type == 0) + { + for(int i = 0; i < count; i++) { + fread(&cheatsList[i].code, 1, sizeof(int),f); + fread(&cheatsList[i].size, 1, sizeof(int),f); + fread(&cheatsList[i].status, 1, sizeof(int),f); + fread(&cheatsList[i].enabled, 1, sizeof(int),f); + cheatsList[i].enabled = cheatsList[i].enabled ? true : false; + fread(&cheatsList[i].address, 1, sizeof(u32),f); + cheatsList[i].rawaddress = cheatsList[i].address; + fread(&cheatsList[i].value, 1, sizeof(u32),f); + fread(&cheatsList[i].oldValue, 1, sizeof(u32),f); + fread(&cheatsList[i].codestring, 1, 20*sizeof(char),f); + if(fread(&cheatsList[i].desc, 1, 32*sizeof(char),f) != 32*sizeof(char)) { + fclose(f); + return false; + } + } } bool firstCodeBreaker = true; @@ -1615,59 +2815,80 @@ return true; } -extern int *extCpuLoopTicks; -extern int *extClockTicks; -extern int *extTicks; -extern int cpuSavedTicks; - -extern void debuggerBreakOnWrite(u32 *, u32, u32, int); - -#define CPU_BREAK_LOOP \ - cpuSavedTicks = cpuSavedTicks - *extCpuLoopTicks;\ - *extCpuLoopTicks = *extClockTicks;\ - *extTicks = *extClockTicks; +extern int cpuNextEvent; + +extern void debuggerBreakOnWrite(u32 , u32, u32, int, int); + +static u8 cheatsGetType(u32 address) +{ + switch(address >> 24) { + case 2: + return freezeWorkRAM[address & 0x3FFFF]; + case 3: + return freezeInternalRAM[address & 0x7FFF]; + case 5: + return freezePRAM[address & 0x3FC]; + case 6: + if (address > 0x06010000) + return freezeVRAM[address & 0x17FFF]; + else + return freezeVRAM[address & 0x1FFFF]; + case 7: + return freezeOAM[address & 0x3FC]; + } + return 0; +} -void cheatsWriteMemory(u32 *address, u32 value, u32 mask) +void cheatsWriteMemory(u32 address, u32 value) { #ifdef BKPT_SUPPORT #ifdef SDL if(cheatsNumber == 0) { - debuggerBreakOnWrite(address, *address, value, 2); - CPU_BREAK_LOOP; - *address = value; - return; + int type = cheatsGetType(address); + u32 oldValue = debuggerReadMemory(address); + if(type == 1 || (type == 2 && oldValue != value)) { + debuggerBreakOnWrite(address, oldValue, value, 2, type); + cpuNextEvent = 0; + } + debuggerWriteMemory(address, value); } #endif #endif } -void cheatsWriteHalfWord(u16 *address, u16 value, u16 mask) +void cheatsWriteHalfWord(u32 address, u16 value) { #ifdef BKPT_SUPPORT #ifdef SDL if(cheatsNumber == 0) { - debuggerBreakOnWrite((u32 *)address, *address, value, 1); - CPU_BREAK_LOOP; - *address = value; - return; + int type = cheatsGetType(address); + u16 oldValue = debuggerReadHalfWord(address); + if(type == 1 || (type == 2 && oldValue != value)) { + debuggerBreakOnWrite(address, oldValue, value, 1, type); + cpuNextEvent = 0; + } + debuggerWriteHalfWord(address, value); } #endif #endif } #if defined BKPT_SUPPORT && defined SDL -void cheatsWriteByte(u8 *address, u8 value) +void cheatsWriteByte(u32 address, u8 value) #else -void cheatsWriteByte(u8 *, u8) +void cheatsWriteByte(u32, u8) #endif { #ifdef BKPT_SUPPORT #ifdef SDL if(cheatsNumber == 0) { - debuggerBreakOnWrite((u32 *)address, *address, value, 0); - CPU_BREAK_LOOP; - *address = value; - return; + int type = cheatsGetType(address); + u8 oldValue = debuggerReadByte(address); + if(type == 1 || (type == 2 && oldValue != value)) { + debuggerBreakOnWrite(address, oldValue, value, 0, type); + cpuNextEvent = 0; + } + debuggerWriteByte(address, value); } #endif #endif diff -urN ../VisualBoyAdvance-1.7.2/src/Cheats.h ./src/Cheats.h --- ../VisualBoyAdvance-1.7.2/src/Cheats.h 2004-05-13 23:06:42 +0900 +++ ./src/Cheats.h 2006-04-30 23:35:35 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ int size; int status; bool enabled; + u32 rawaddress; u32 address; u32 value; u32 oldValue; @@ -32,7 +33,7 @@ char desc[32]; }; -extern void cheatsAdd(const char *,const char *,u32,u32,int,int); +extern void cheatsAdd(const char *,const char *,u32, u32,u32,int,int); extern void cheatsAddCheatCode(const char *code, const char *desc); extern void cheatsAddGSACode(const char *code, const char *desc, bool v3); extern void cheatsAddCBACode(const char *code, const char *desc); @@ -42,12 +43,12 @@ extern void cheatsEnable(int number); extern void cheatsDisable(int number); extern void cheatsSaveGame(gzFile file); -extern void cheatsReadGame(gzFile file); +extern void cheatsReadGame(gzFile file, int version); extern void cheatsSaveCheatList(const char *file); extern bool cheatsLoadCheatList(const char *file); -extern void cheatsWriteMemory(u32 *, u32, u32); -extern void cheatsWriteHalfWord(u16 *, u16, u16); -extern void cheatsWriteByte(u8 *, u8); +extern void cheatsWriteMemory(u32, u32); +extern void cheatsWriteHalfWord(u32, u16); +extern void cheatsWriteByte(u32, u8); extern int cheatsCheckKeys(u32,u32); extern int cheatsNumber; extern CheatsData cheatsList[100]; diff -urN ../VisualBoyAdvance-1.7.2/src/EEprom.cpp ./src/EEprom.cpp --- ../VisualBoyAdvance-1.7.2/src/EEprom.cpp 2004-05-13 23:38:22 +0900 +++ ./src/EEprom.cpp 2005-06-25 15:15:34 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include #include "GBA.h" #include "EEprom.h" #include "Util.h" @@ -42,6 +43,11 @@ { NULL, 0 } }; +void eepromInit() +{ + memset(eepromData, 255, sizeof(eepromData)); +} + void eepromReset() { eepromMode = EEPROM_IDLE; diff -urN ../VisualBoyAdvance-1.7.2/src/EEprom.h ./src/EEprom.h --- ../VisualBoyAdvance-1.7.2/src/EEprom.h 2004-05-13 23:06:31 +0900 +++ ./src/EEprom.h 2006-06-07 06:04:20 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,10 +20,11 @@ #ifndef VBA_EEPROM_H #define VBA_EEPROM_H -extern void eepromSaveGame(gzFile gzFile); -extern void eepromReadGame(gzFile gzFile, int version); +extern void eepromSaveGame(gzFile _gzFile); +extern void eepromReadGame(gzFile _gzFile, int version); extern int eepromRead(u32 address); extern void eepromWrite(u32 address, u8 value); +extern void eepromInit(); extern void eepromReset(); extern u8 eepromData[0x2000]; extern bool eepromInUse; diff -urN ../VisualBoyAdvance-1.7.2/src/Flash.cpp ./src/Flash.cpp --- ../VisualBoyAdvance-1.7.2/src/Flash.cpp 2004-05-13 23:38:11 +0900 +++ ./src/Flash.cpp 2006-04-30 23:36:24 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -67,6 +67,11 @@ { NULL, 0 } }; +void flashInit() +{ + memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory)); +} + void flashReset() { flashState = FLASH_READ_ARRAY; @@ -95,7 +100,6 @@ void flashSetSize(int size) { // log("Setting flash size to %d\n", size); - flashSize = size; if(size == 0x10000) { flashDeviceID = 0x1b; flashManufacturerID = 0x32; @@ -103,6 +107,11 @@ flashDeviceID = 0x13; //0x09; flashManufacturerID = 0x62; //0xc2; } + // Added to make 64k saves compatible with 128k ones + // (allow wrongfuly set 64k saves to work for Pokemon games) + if ((size == 0x20000) && (flashSize == 0x10000)) + memcpy((u8 *)(flashSaveMemory+0x10000), (u8 *)(flashSaveMemory), 0x10000); + flashSize = size; } u8 flashRead(u32 address) @@ -146,6 +155,13 @@ (*cpuSaveGameFunc)(address, byte); } +void flashDelayedWrite(u32 address, u8 byte) +{ + saveType = 2; + cpuSaveGameFunc = flashWrite; + flashWrite(address, byte); +} + void flashWrite(u32 address, u8 byte) { // log("Writing %02x at %08x\n", byte, address); diff -urN ../VisualBoyAdvance-1.7.2/src/Flash.h ./src/Flash.h --- ../VisualBoyAdvance-1.7.2/src/Flash.h 2004-05-13 23:05:20 +0900 +++ ./src/Flash.h 2006-06-07 06:04:20 +0900 @@ -20,14 +20,16 @@ #ifndef VBA_FLASH_H #define VBA_FLASH_H -extern void flashSaveGame(gzFile gzFile); -extern void flashReadGame(gzFile gzFile, int version); +extern void flashSaveGame(gzFile _gzFile); +extern void flashReadGame(gzFile _gzFile, int version); extern u8 flashRead(u32 address); extern void flashWrite(u32 address, u8 byte); +extern void flashDelayedWrite(u32 address, u8 byte); extern u8 flashSaveMemory[0x20000]; extern void flashSaveDecide(u32 address, u8 byte); extern void flashReset(); extern void flashSetSize(int size); +extern void flashInit(); extern int flashSize; #endif // VBA_FLASH_H diff -urN ../VisualBoyAdvance-1.7.2/src/GBA.cpp ./src/GBA.cpp --- ../VisualBoyAdvance-1.7.2/src/GBA.cpp 2004-05-13 23:37:59 +0900 +++ ./src/GBA.cpp 2006-08-25 23:13:38 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -42,32 +42,51 @@ #include "prof/prof.h" #endif -#define UPDATE_REG(address, value) WRITE16LE(((u16 *)&ioMem[address]),value) +#define UPDATE_REG(address, value)\ + {\ + WRITE16LE(((u16 *)&ioMem[address]),value);\ + }\ + +#define ARM_PREFETCH \ + {\ + cpuPrefetch[0] = CPUReadMemoryQuick(armNextPC);\ + cpuPrefetch[1] = CPUReadMemoryQuick(armNextPC+4);\ + } + +#define THUMB_PREFETCH \ + {\ + cpuPrefetch[0] = CPUReadHalfWordQuick(armNextPC);\ + cpuPrefetch[1] = CPUReadHalfWordQuick(armNextPC+2);\ + } + +#define ARM_PREFETCH_NEXT \ + cpuPrefetch[1] = CPUReadMemoryQuick(armNextPC+4); + +#define THUMB_PREFETCH_NEXT\ + cpuPrefetch[1] = CPUReadHalfWordQuick(armNextPC+2); #ifdef __GNUC__ #define _stricmp strcasecmp #endif -#define CPU_BREAK_LOOP \ - cpuSavedTicks = cpuSavedTicks - *extCpuLoopTicks;\ - *extCpuLoopTicks = *extClockTicks; - -#define CPU_BREAK_LOOP_2 \ - cpuSavedTicks = cpuSavedTicks - *extCpuLoopTicks;\ - *extCpuLoopTicks = *extClockTicks;\ - *extTicks = *extClockTicks; extern int emulating; +int SWITicks = 0; +int IRQTicks = 0; +u32 mastercode = 0; +int layerEnableDelay = 0; +bool busPrefetch = false; +bool busPrefetchEnable = false; +u32 busPrefetchCount = 0; int cpuDmaTicksToUpdate = 0; int cpuDmaCount = 0; -bool cpuDmaHack = 0; +bool cpuDmaHack = false; u32 cpuDmaLast = 0; int dummyAddress = 0; -int *extCpuLoopTicks = NULL; -int *extClockTicks = NULL; -int *extTicks = NULL; +bool cpuBreakLoop = false; +int cpuNextEvent = 0; int gbaSaveType = 0; // used to remember the save type on reset bool intState = false; @@ -79,29 +98,42 @@ bool cpuEEPROMEnabled = true; bool cpuEEPROMSensorEnabled = false; +u32 cpuPrefetch[2]; + +int cpuTotalTicks = 0; #ifdef PROFILING int profilingTicks = 0; int profilingTicksReload = 0; -static char *profilBuffer = NULL; -static int profilSize = 0; -static u32 profilLowPC = 0; -static int profilScale = 0; -#endif -bool freezeWorkRAM[0x40000]; -bool freezeInternalRAM[0x8000]; -int lcdTicks = 960; +static profile_segment *profilSegment = NULL; +#endif + +#ifdef BKPT_SUPPORT +u8 freezeWorkRAM[0x40000]; +u8 freezeInternalRAM[0x8000]; +u8 freezeVRAM[0x18000]; +u8 freezePRAM[0x400]; +u8 freezeOAM[0x400]; +bool debugger_last; +#endif + +int lcdTicks = (useBios && !skipBios) ? 1008 : 208; +u8 timerOnOffDelay = 0; +u16 timer0Value = 0; bool timer0On = false; int timer0Ticks = 0; int timer0Reload = 0; int timer0ClockReload = 0; +u16 timer1Value = 0; bool timer1On = false; int timer1Ticks = 0; int timer1Reload = 0; int timer1ClockReload = 0; +u16 timer2Value = 0; bool timer2On = false; int timer2Ticks = 0; int timer2Reload = 0; int timer2ClockReload = 0; +u16 timer3Value = 0; bool timer3On = false; int timer3Ticks = 0; int timer3Reload = 0; @@ -129,62 +161,38 @@ int captureNumber = 0; const int TIMER_TICKS[4] = { - 1, - 64, - 256, - 1024 -}; - -const int thumbCycles[] = { -// 0 1 2 3 4 5 6 7 8 9 a b c d e f - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3 - 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 4 - 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 5 - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 6 - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 7 - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 8 - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 9 - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // a - 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1, // b - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // c - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, // d - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // e - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // f + 0, + 6, + 8, + 10 }; -const int gamepakRamWaitState[4] = { 4, 3, 2, 8 }; -const int gamepakWaitState[8] = { 4, 3, 2, 8, 4, 3, 2, 8 }; -const int gamepakWaitState0[8] = { 2, 2, 2, 2, 1, 1, 1, 1 }; -const int gamepakWaitState1[8] = { 4, 4, 4, 4, 1, 1, 1, 1 }; -const int gamepakWaitState2[8] = { 8, 8, 8, 8, 1, 1, 1, 1 }; +const u32 objTilesAddress [3] = {0x010000, 0x014000, 0x014000}; +const u8 gamepakRamWaitState[4] = { 4, 3, 2, 8 }; +const u8 gamepakWaitState[4] = { 4, 3, 2, 8 }; +const u8 gamepakWaitState0[2] = { 2, 1 }; +const u8 gamepakWaitState1[2] = { 4, 1 }; +const u8 gamepakWaitState2[2] = { 8, 1 }; +const bool isInRom [16]= + { false, false, false, false, false, false, false, false, + true, true, true, true, true, true, false, false }; -int memoryWait[16] = +u8 memoryWait[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0 }; -int memoryWait32[16] = - { 0, 0, 9, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 0 }; -int memoryWaitSeq[16] = +u8 memoryWait32[16] = + { 0, 0, 5, 0, 0, 1, 1, 0, 7, 7, 9, 9, 13, 13, 4, 0 }; +u8 memoryWaitSeq[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4, 0 }; -int memoryWaitSeq32[16] = - { 2, 0, 3, 0, 0, 2, 2, 0, 4, 4, 8, 8, 16, 16, 8, 0 }; -int memoryWaitFetch[16] = - { 3, 0, 3, 0, 0, 1, 1, 0, 4, 4, 4, 4, 4, 4, 4, 0 }; -int memoryWaitFetch32[16] = - { 6, 0, 6, 0, 0, 2, 2, 0, 8, 8, 8, 8, 8, 8, 8, 0 }; - -const int cpuMemoryWait[16] = { - 0, 0, 2, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 2, 2, 0, 0 -}; -const int cpuMemoryWait32[16] = { - 0, 0, 3, 0, 0, 0, 0, 0, - 3, 3, 3, 3, 3, 3, 0, 0 -}; - -const bool memory32[16] = - { true, false, false, true, true, false, false, true, false, false, false, false, false, false, true, false}; +u8 memoryWaitSeq32[16] = + { 0, 0, 5, 0, 0, 1, 1, 0, 5, 5, 9, 9, 17, 17, 4, 0 }; + +// The videoMemoryWait constants are used to add some waitstates +// if the opcode access video memory data outside of vblank/hblank +// It seems to happen on only one ticks for each pixel. +// Not used for now (too problematic with current code). +//const u8 videoMemoryWait[16] = +// {0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + u8 biosProtected[4]; @@ -320,7 +328,6 @@ 0xE3A00001, 0xE3A01001, 0xE92D4010, -0xE3A0C301, 0xE3A03000, 0xE3A04001, 0xE3500000, @@ -330,11 +337,12 @@ 0x0AFFFFFC, 0xE8BD4010, 0xE12FFF1E, +0xE3A0C301, 0xE5CC3208, 0xE15C20B8, 0xE0110002, -0x10200002, -0x114C00B8, +0x10222000, +0x114C20B8, 0xE5CC4208, 0xE12FFF1E, 0xE92D500F, @@ -487,16 +495,12 @@ { NULL, 0 } }; -//int cpuLoopTicks = 0; -int cpuSavedTicks = 0; +static int romSize = 0x2000000; #ifdef PROFILING -void cpuProfil(char *buf, int size, u32 lowPC, int scale) +void cpuProfil(profile_segment *seg) { - profilBuffer = buf; - profilSize = size; - profilLowPC = lowPC; - profilScale = scale; + profilSegment = seg; } void cpuEnableProfiling(int hz) @@ -508,26 +512,211 @@ } #endif -inline int CPUUpdateTicksAccess32(u32 address) + +// Waitstates when accessing data +inline int dataTicksAccess16(u32 address) // DATA 8/16bits NON SEQ { - return memoryWait32[(address>>24)&15]; + int addr = (address>>24)&15; + int value = memoryWait[addr]; + + if ((addr>=0x08) || (addr < 0x02)) + { + busPrefetchCount=0; + busPrefetch=false; + } + else if (busPrefetch) + { + int waitState = value; + if (!waitState) + waitState = 1; + busPrefetchCount = ((++busPrefetchCount)<>24)&15]; + int addr = (address>>24)&15; + int value = memoryWait32[addr]; + + if ((addr>=0x08) || (addr < 0x02)) + { + busPrefetchCount=0; + busPrefetch=false; + } + else if (busPrefetch) + { + int waitState = value; + if (!waitState) + waitState = 1; + busPrefetchCount = ((++busPrefetchCount)<>24)&15]; + int addr = (address>>24)&15; + int value = memoryWaitSeq[addr]; + + if ((addr>=0x08) || (addr < 0x02)) + { + busPrefetchCount=0; + busPrefetch=false; + } + else if (busPrefetch) + { + int waitState = value; + if (!waitState) + waitState = 1; + busPrefetchCount = ((++busPrefetchCount)<>24)&15; + int value = memoryWaitSeq32[addr]; + + if ((addr>=0x08) || (addr < 0x02)) + { + busPrefetchCount=0; + busPrefetch=false; + } + else if (busPrefetch) + { + int waitState = value; + if (!waitState) + waitState = 1; + busPrefetchCount = ((++busPrefetchCount)<>24)&15]; + int addr = (address>>24)&15; + + if ((addr>=0x08) && (addr<=0x0D)) + { + if (busPrefetchCount&0x1) + { + if (busPrefetchCount&0x2) + { + busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00); + return 0; + } + busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00); + return memoryWaitSeq[addr]-1; + } + else + { + busPrefetchCount=0; + return memoryWait[addr]; + } + } + else + { + busPrefetchCount = 0; + return memoryWait[addr]; + } +} + +inline int codeTicksAccess32(u32 address) // ARM NON SEQ +{ + int addr = (address>>24)&15; + + if ((addr>=0x08) && (addr<=0x0D)) + { + if (busPrefetchCount&0x1) + { + if (busPrefetchCount&0x2) + { + busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00); + return 0; + } + busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00); + return memoryWaitSeq[addr] - 1; + } + else + { + busPrefetchCount = 0; + return memoryWait32[addr]; + } + } + else + { + busPrefetchCount = 0; + return memoryWait32[addr]; + } +} + +inline int codeTicksAccessSeq16(u32 address) // THUMB SEQ +{ + int addr = (address>>24)&15; + + if ((addr>=0x08) && (addr<=0x0D)) + { + if (busPrefetchCount&0x1) + { + busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00); + return 0; + } + else + if (busPrefetchCount>0xFF) + { + busPrefetchCount=0; + return memoryWait[addr]; + } + else + return memoryWaitSeq[addr]; + } + else + { + busPrefetchCount = 0; + return memoryWaitSeq[addr]; + } +} + +inline int codeTicksAccessSeq32(u32 address) // ARM SEQ +{ + int addr = (address>>24)&15; + + if ((addr>=0x08) && (addr<=0x0D)) + { + if (busPrefetchCount&0x1) + { + if (busPrefetchCount&0x2) + { + busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00); + return 0; + } + busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00); + return memoryWaitSeq[addr]; + } + else + if (busPrefetchCount>0xFF) + { + busPrefetchCount=0; + return memoryWait32[addr]; + } + else + return memoryWaitSeq32[addr]; + } + else + { + return memoryWaitSeq32[addr]; + } } + inline int CPUUpdateTicks() { int cpuLoopTicks = lcdTicks; @@ -535,7 +724,7 @@ if(soundTicks < cpuLoopTicks) cpuLoopTicks = soundTicks; - if(timer0On && !(TM0CNT & 4) && (timer0Ticks < cpuLoopTicks)) { + if(timer0On && (timer0Ticks < cpuLoopTicks)) { cpuLoopTicks = timer0Ticks; } if(timer1On && !(TM1CNT & 4) && (timer1Ticks < cpuLoopTicks)) { @@ -554,7 +743,17 @@ } } #endif - cpuSavedTicks = cpuLoopTicks; + + if (SWITicks) { + if (SWITicks < cpuLoopTicks) + cpuLoopTicks = SWITicks; + } + + if (IRQTicks) { + if (IRQTicks < cpuLoopTicks) + cpuLoopTicks = IRQTicks; + } + return cpuLoopTicks; } @@ -634,7 +833,7 @@ // new to version 0.7.1 utilWriteInt(gzFile, stopState); // new to version 0.8 - utilWriteInt(gzFile, intState); + utilWriteInt(gzFile, IRQTicks); utilGzWrite(gzFile, internalRAM, 0x8000); utilGzWrite(gzFile, paletteRAM, 0x400); @@ -738,9 +937,21 @@ stopState = utilReadInt(gzFile) ? true : false; if(version < SAVE_GAME_VERSION_4) + { + IRQTicks = 0; intState = false; + } else - intState = utilReadInt(gzFile) ? true : false; + { + IRQTicks = utilReadInt(gzFile); + if (IRQTicks>0) + intState = true; + else + { + intState = false; + IRQTicks = 0; + } + } utilGzRead(gzFile, internalRAM, 0x8000); utilGzRead(gzFile, paletteRAM, 0x400); @@ -758,7 +969,7 @@ soundReadGame(gzFile, version); if(version > SAVE_GAME_VERSION_1) { - cheatsReadGame(gzFile); + cheatsReadGame(gzFile, version); } if(version > SAVE_GAME_VERSION_6) { rtcReadGame(gzFile); @@ -782,6 +993,18 @@ SWAP(dma3Dest, DM3DAD_H, DM3DAD_L); } + if(version <= SAVE_GAME_VERSION_8) { + timer0ClockReload = TIMER_TICKS[TM0CNT & 3]; + timer1ClockReload = TIMER_TICKS[TM1CNT & 3]; + timer2ClockReload = TIMER_TICKS[TM2CNT & 3]; + timer3ClockReload = TIMER_TICKS[TM3CNT & 3]; + + timer0Ticks = ((0x10000 - TM0D) << timer0ClockReload) - timer0Ticks; + timer1Ticks = ((0x10000 - TM1D) << timer1ClockReload) - timer1Ticks; + timer2Ticks = ((0x10000 - TM2D) << timer2ClockReload) - timer2Ticks; + timer3Ticks = ((0x10000 - TM3D) << timer3ClockReload) - timer3Ticks; + } + // set pointers! layerEnable = layerSettings & DISPCNT; @@ -802,6 +1025,11 @@ cpuSaveGameFunc = flashWrite; gbaSaveType = 2; break; + case 3: + break; + case 5: + gbaSaveType = 5; + break; default: systemMessage(MSG_UNSUPPORTED_SAVE_TYPE, N_("Unsupported save type %d"), saveType); @@ -811,6 +1039,13 @@ gbaSaveType = 3; systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; + if(armState) { + ARM_PREFETCH; + } else { + THUMB_PREFETCH; + } + + CPUUpdateRegister(0x204, CPUReadHalfWordQuick(0x4000204)); return true; } @@ -880,7 +1115,7 @@ } } - if(gbaSaveType) { + if((gbaSaveType) && (gbaSaveType!=5)) { FILE *file = fopen(fileName, "wb"); if(!file) { @@ -997,13 +1232,13 @@ fwrite("SharkPortSave", 1, 0x0d, file); utilPutDword(buffer, 0x000f0000); fwrite(buffer, 1, 4, file); // save type 0x000f0000 = GBA save - utilPutDword(buffer, strlen(title)); + utilPutDword(buffer, (u32)strlen(title)); fwrite(buffer, 1, 4, file); // title length fwrite(title, 1, strlen(title), file); - utilPutDword(buffer, strlen(desc)); + utilPutDword(buffer, (u32)strlen(desc)); fwrite(buffer, 1, 4, file); // desc length fwrite(desc, 1, strlen(desc), file); - utilPutDword(buffer, strlen(notes)); + utilPutDword(buffer, (u32)strlen(notes)); fwrite(buffer, 1, 4, file); // notes length fwrite(notes, 1, strlen(notes), file); int saveSize = 0x10000; @@ -1130,7 +1365,7 @@ bool CPUIsZipFile(const char * file) { if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".zip") == 0) @@ -1145,7 +1380,7 @@ { cpuIsMultiBoot = false; if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".gba") == 0) @@ -1169,7 +1404,7 @@ bool CPUIsGBABios(const char * file) { if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".gba") == 0) @@ -1189,7 +1424,7 @@ bool CPUIsELF(const char *file) { if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".elf") == 0) @@ -1261,8 +1496,7 @@ int CPULoadRom(const char *szFile) { - int size = 0x2000000; - + romSize = 0x2000000; if(rom != NULL) { CPUCleanUp(); } @@ -1297,8 +1531,8 @@ workRAM = NULL; return 0; } - bool res = elfRead(szFile, size, f); - if(!res || size == 0) { + bool res = elfRead(szFile, romSize, f); + if(!res || romSize == 0) { free(rom); rom = NULL; free(workRAM); @@ -1309,7 +1543,7 @@ } else if(!utilLoad(szFile, utilIsGBAImage, whereToLoad, - size)) { + romSize)) { free(rom); rom = NULL; free(workRAM); @@ -1317,9 +1551,9 @@ return 0; } - u16 *temp = (u16 *)(rom+((size+1)&~1)); + u16 *temp = (u16 *)(rom+((romSize+1)&~1)); int i; - for(i = (size+1)&~1; i < 0x2000000; i+=2) { + for(i = (romSize+1)&~1; i < 0x2000000; i+=2) { WRITE16LE(temp, (i >> 1) & 0xFFFF); temp++; } @@ -1374,9 +1608,29 @@ return 0; } + flashInit(); + eepromInit(); + CPUUpdateRenderBuffers(true); - return size; + return romSize; +} + +void doMirroring (bool b) +{ + u32 mirroredRomSize = (((romSize)>>20) & 0x3F)<<20; + u32 mirroredRomAddress = romSize; + if ((mirroredRomSize <=0x800000) && (b)) + { + mirroredRomAddress = mirroredRomSize; + if (mirroredRomSize==0) + mirroredRomSize=0x100000; + while (mirroredRomAddress<0x01000000) + { + memcpy ((u16 *)(rom+mirroredRomAddress), (u16 *)(rom), mirroredRomSize); + mirroredRomAddress+=mirroredRomSize; + } + } } void CPUUpdateRender() @@ -1470,9 +1724,8 @@ armState = (CPSR & 0x20) ? false : true; armIrqEnable = (CPSR & 0x80) ? false : true; if(breakLoop) { - if(armIrqEnable && (IF & IE) && (IME & 1)) { - CPU_BREAK_LOOP_2; - } + if (armIrqEnable && (IF & IE) && (IME & 1)) + cpuNextEvent = cpuTotalTicks; } } @@ -1626,6 +1879,7 @@ armState = true; armIrqEnable = false; armNextPC = 0x04; + ARM_PREFETCH; reg[15].I += 4; } @@ -1639,6 +1893,7 @@ armState = true; armIrqEnable = false; armNextPC = 0x08; + ARM_PREFETCH; reg[15].I += 4; } @@ -1678,7 +1933,8 @@ #ifdef SDL if(comment == 0xf9) { emulating = 0; - CPU_BREAK_LOOP_2; + cpuNextEvent = cpuTotalTicks; + cpuBreakLoop = true; return; } #endif @@ -1704,6 +1960,7 @@ switch(comment) { case 0x00: BIOS_SoftReset(); + ARM_PREFETCH; break; case 0x01: BIOS_RegisterRamReset(); @@ -1717,6 +1974,7 @@ #endif holdState = true; holdType = -1; + cpuNextEvent = cpuTotalTicks; break; case 0x03: #ifdef DEV_VERSION @@ -1728,6 +1986,7 @@ holdState = true; holdType = -1; stopState = true; + cpuNextEvent = cpuTotalTicks; break; case 0x04: #ifdef DEV_VERSION @@ -1765,11 +2024,52 @@ BIOS_ArcTan2(); break; case 0x0B: + { + int len = (reg[2].I & 0x1FFFFF) >>1; + if (!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + len) & 0xe000000) == 0)) + { + if ((reg[2].I >> 24) & 1) + { + if ((reg[2].I >> 26) & 1) + SWITicks = (7 + memoryWait32[(reg[1].I>>24) & 0xF]) * (len>>1); + else + SWITicks = (8 + memoryWait[(reg[1].I>>24) & 0xF]) * (len); + } + else + { + if ((reg[2].I >> 26) & 1) + SWITicks = (10 + memoryWait32[(reg[0].I>>24) & 0xF] + + memoryWait32[(reg[1].I>>24) & 0xF]) * (len>>1); + else + SWITicks = (11 + memoryWait[(reg[0].I>>24) & 0xF] + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } + } + } BIOS_CpuSet(); break; case 0x0C: + { + int len = (reg[2].I & 0x1FFFFF) >>5; + if (!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + len) & 0xe000000) == 0)) + { + if ((reg[2].I >> 24) & 1) + SWITicks = (6 + memoryWait32[(reg[1].I>>24) & 0xF] + + 7 * (memoryWaitSeq32[(reg[1].I>>24) & 0xF] + 1)) * len; + else + SWITicks = (9 + memoryWait32[(reg[0].I>>24) & 0xF] + + memoryWait32[(reg[1].I>>24) & 0xF] + + 7 * (memoryWaitSeq32[(reg[0].I>>24) & 0xF] + + memoryWaitSeq32[(reg[1].I>>24) & 0xF] + 2)) * len; + } + } BIOS_CpuFastSet(); break; + case 0x0D: + BIOS_GetBiosChecksum(); + break; case 0x0E: BIOS_BgAffineSet(); break; @@ -1777,30 +2077,89 @@ BIOS_ObjAffineSet(); break; case 0x10: + { + int len = CPUReadHalfWord(reg[2].I); + if (!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + len) & 0xe000000) == 0)) + SWITicks = (32 + memoryWait[(reg[0].I>>24) & 0xF]) * len; + } BIOS_BitUnPack(); break; case 0x11: + { + u32 len = CPUReadMemory(reg[0].I) >> 8; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (9 + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_LZ77UnCompWram(); break; case 0x12: + { + u32 len = CPUReadMemory(reg[0].I) >> 8; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (19 + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_LZ77UnCompVram(); break; case 0x13: + { + u32 len = CPUReadMemory(reg[0].I) >> 8; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (29 + (memoryWait[(reg[0].I>>24) & 0xF]<<1)) * len; + } BIOS_HuffUnComp(); break; case 0x14: + { + u32 len = CPUReadMemory(reg[0].I) >> 8; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (11 + memoryWait[(reg[0].I>>24) & 0xF] + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_RLUnCompWram(); break; case 0x15: + { + u32 len = CPUReadMemory(reg[0].I) >> 9; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (34 + (memoryWait[(reg[0].I>>24) & 0xF] << 1) + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_RLUnCompVram(); break; case 0x16: + { + u32 len = CPUReadMemory(reg[0].I) >> 8; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (13 + memoryWait[(reg[0].I>>24) & 0xF] + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_Diff8bitUnFilterWram(); break; case 0x17: + { + u32 len = CPUReadMemory(reg[0].I) >> 9; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (39 + (memoryWait[(reg[0].I>>24) & 0xF]<<1) + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_Diff8bitUnFilterVram(); break; case 0x18: + { + u32 len = CPUReadMemory(reg[0].I) >> 9; + if(!(((reg[0].I & 0xe000000) == 0) || + ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0)) + SWITicks = (13 + memoryWait[(reg[0].I>>24) & 0xF] + + memoryWait[(reg[1].I>>24) & 0xF]) * len; + } BIOS_Diff16bitUnFilter(); break; case 0x19: @@ -1859,17 +2218,33 @@ DISPSTAT &= 0xFFFB; UPDATE_REG(0x4, DISPSTAT); } + if (layerEnableDelay>0) + { + layerEnableDelay--; + if (layerEnableDelay==1) + layerEnable = layerSettings & DISPCNT; + } + } void doDMA(u32 &s, u32 &d, u32 si, u32 di, u32 c, int transfer32) { int sm = s >> 24; int dm = d >> 24; - + int sw = 0; + int dw = 0; int sc = c; cpuDmaCount = c; + // This is done to get the correct waitstates. + if (sm>15) + sm=15; + if (dm>15) + dm=15; + //if ((sm>=0x05) && (sm<=0x07) || (dm>=0x05) && (dm <=0x07)) + // blank = (((DISPSTAT | ((DISPSTAT>>1)&1))==1) ? true : false); + if(transfer32) { s &= 0xFFFFFFFC; if(s < 0x02000000 && (reg[15].I >> 24)) { @@ -1880,7 +2255,8 @@ } } else { while(c != 0) { - CPUWriteMemory(d, CPUReadMemory(s)); + cpuDmaLast = CPUReadMemory(s); + CPUWriteMemory(d, cpuDmaLast); d += di; s += si; c--; @@ -1900,6 +2276,7 @@ while(c != 0) { cpuDmaLast = CPUReadHalfWord(s); CPUWriteHalfWord(d, cpuDmaLast); + cpuDmaLast |= (cpuDmaLast<<16); d += di; s += si; c--; @@ -1909,30 +2286,28 @@ cpuDmaCount = 0; - int sw = 1+memoryWaitSeq[sm & 15]; - int dw = 1+memoryWaitSeq[dm & 15]; - int totalTicks = 0; if(transfer32) { - if(!memory32[sm & 15]) - sw <<= 1; - if(!memory32[dm & 15]) - dw <<= 1; + sw =1+memoryWaitSeq32[sm & 15]; + dw =1+memoryWaitSeq32[dm & 15]; + totalTicks = (sw+dw)*(sc-1) + 6 + memoryWait32[sm & 15] + + memoryWaitSeq32[dm & 15]; + } + else + { + sw = 1+memoryWaitSeq[sm & 15]; + dw = 1+memoryWaitSeq[dm & 15]; + totalTicks = (sw+dw)*(sc-1) + 6 + memoryWait[sm & 15] + + memoryWaitSeq[dm & 15]; } - - totalTicks = (sw+dw)*sc; cpuDmaTicksToUpdate += totalTicks; - if(*extCpuLoopTicks >= 0) { - CPU_BREAK_LOOP; - } } void CPUCheckDMA(int reason, int dmamask) { - cpuDmaHack = 0; // DMA 0 if((DM0CNT_H & 0x8000) && (dmamask & 1)) { if(((DM0CNT_H >> 12) & 3) == reason) { @@ -1971,10 +2346,12 @@ doDMA(dma0Source, dma0Dest, sourceIncrement, destIncrement, DM0CNT_L ? DM0CNT_L : 0x4000, DM0CNT_H & 0x0400); - cpuDmaHack = 1; + cpuDmaHack = true; + if(DM0CNT_H & 0x4000) { IF |= 0x0100; UPDATE_REG(0x202, IF); + cpuNextEvent = cpuTotalTicks; } if(((DM0CNT_H >> 5) & 3) == 3) { @@ -2038,11 +2415,12 @@ DM1CNT_L ? DM1CNT_L : 0x4000, DM1CNT_H & 0x0400); } - cpuDmaHack = 1; - + cpuDmaHack = true; + if(DM1CNT_H & 0x4000) { IF |= 0x0200; UPDATE_REG(0x202, IF); + cpuNextEvent = cpuTotalTicks; } if(((DM1CNT_H >> 5) & 3) == 3) { @@ -2107,10 +2485,12 @@ DM2CNT_L ? DM2CNT_L : 0x4000, DM2CNT_H & 0x0400); } - cpuDmaHack = 1; + cpuDmaHack = true; + if(DM2CNT_H & 0x4000) { IF |= 0x0400; UPDATE_REG(0x202, IF); + cpuNextEvent = cpuTotalTicks; } if(((DM2CNT_H >> 5) & 3) == 3) { @@ -2165,6 +2545,7 @@ if(DM3CNT_H & 0x4000) { IF |= 0x0800; UPDATE_REG(0x202, IF); + cpuNextEvent = cpuTotalTicks; } if(((DM3CNT_H >> 5) & 3) == 3) { @@ -2177,7 +2558,6 @@ } } } - cpuDmaHack = 0; } void CPUUpdateRegister(u32 address, u16 value) @@ -2185,15 +2565,27 @@ switch(address) { case 0x00: { + if ((value & 7) >5) + DISPCNT = (value &7); bool change = ((DISPCNT ^ value) & 0x80) ? true : false; bool changeBG = ((DISPCNT ^ value) & 0x0F00) ? true : false; + u16 changeBGon = (((~DISPCNT) & value) & 0x0F00); DISPCNT = (value & 0xFFF7); UPDATE_REG(0x00, DISPCNT); - layerEnable = layerSettings & value; + + if (changeBGon) + { + layerEnableDelay=4; + layerEnable = layerSettings & value & (~changeBGon); + } + else + layerEnable = layerSettings & value; + // CPUUpdateTicks(); + windowOn = (layerEnable & 0x6000) ? true : false; if(change && !((value & 0x80))) { if(!(DISPSTAT & 1)) { - lcdTicks = 960; + lcdTicks = 1008; // VCOUNT = 0; // UPDATE_REG(0x06, VCOUNT); DISPSTAT &= 0xFFFC; @@ -2206,7 +2598,6 @@ // we only care about changes in BG0-BG3 if(changeBG) CPUUpdateRenderBuffers(false); - // CPUUpdateTicks(); } break; case 0x04: @@ -2554,70 +2945,37 @@ } } break; - case 0x100: + case 0x100: timer0Reload = value; break; case 0x102: - timer0Ticks = timer0ClockReload = TIMER_TICKS[value & 3]; - if(!timer0On && (value & 0x80)) { - // reload the counter - TM0D = timer0Reload; - if(timer0ClockReload == 1) - timer0Ticks = 0x10000 - TM0D; - UPDATE_REG(0x100, TM0D); - } - timer0On = value & 0x80 ? true : false; - TM0CNT = value & 0xC7; - UPDATE_REG(0x102, TM0CNT); - // CPUUpdateTicks(); + timer0Value = value; + timerOnOffDelay|=1; + cpuNextEvent = cpuTotalTicks; break; case 0x104: timer1Reload = value; break; case 0x106: - timer1Ticks = timer1ClockReload = TIMER_TICKS[value & 3]; - if(!timer1On && (value & 0x80)) { - // reload the counter - TM1D = timer1Reload; - if(timer1ClockReload == 1) - timer1Ticks = 0x10000 - TM1D; - UPDATE_REG(0x104, TM1D); - } - timer1On = value & 0x80 ? true : false; - TM1CNT = value & 0xC7; - UPDATE_REG(0x106, TM1CNT); + timer1Value = value; + timerOnOffDelay|=2; + cpuNextEvent = cpuTotalTicks; break; case 0x108: timer2Reload = value; break; case 0x10A: - timer2Ticks = timer2ClockReload = TIMER_TICKS[value & 3]; - if(!timer2On && (value & 0x80)) { - // reload the counter - TM2D = timer2Reload; - if(timer2ClockReload == 1) - timer2Ticks = 0x10000 - TM2D; - UPDATE_REG(0x108, TM2D); - } - timer2On = value & 0x80 ? true : false; - TM2CNT = value & 0xC7; - UPDATE_REG(0x10A, TM2CNT); + timer2Value = value; + timerOnOffDelay|=4; + cpuNextEvent = cpuTotalTicks; break; case 0x10C: timer3Reload = value; break; case 0x10E: - timer3Ticks = timer3ClockReload = TIMER_TICKS[value & 3]; - if(!timer3On && (value & 0x80)) { - // reload the counter - TM3D = timer3Reload; - if(timer3ClockReload == 1) - timer3Ticks = 0x10000 - TM3D; - UPDATE_REG(0x10C, TM3D); - } - timer3On = value & 0x80 ? true : false; - TM3CNT = value & 0xC7; - UPDATE_REG(0x10E, TM3CNT); + timer3Value = value; + timerOnOffDelay|=8; + cpuNextEvent = cpuTotalTicks; break; case 0x128: if(value & 0x80) { @@ -2641,9 +2999,8 @@ case 0x200: IE = value & 0x3FFF; UPDATE_REG(0x200, IE); - if((IME & 1) && (IF & IE) && armIrqEnable) { - CPU_BREAK_LOOP_2; - } + if ((IME & 1) && (IF & IE) && armIrqEnable) + cpuNextEvent = cpuTotalTicks; break; case 0x202: IF ^= (value & IF); @@ -2651,54 +3008,54 @@ break; case 0x204: { - int i; memoryWait[0x0e] = memoryWaitSeq[0x0e] = gamepakRamWaitState[value & 3]; if(!speedHack) { - memoryWait[0x08] = memoryWait[0x09] = gamepakWaitState[(value >> 2) & 7]; + memoryWait[0x08] = memoryWait[0x09] = gamepakWaitState[(value >> 2) & 3]; memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = - gamepakWaitState0[(value >> 2) & 7]; + gamepakWaitState0[(value >> 4) & 1]; - memoryWait[0x0a] = memoryWait[0x0b] = gamepakWaitState[(value >> 5) & 7]; + memoryWait[0x0a] = memoryWait[0x0b] = gamepakWaitState[(value >> 5) & 3]; memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] = - gamepakWaitState1[(value >> 5) & 7]; + gamepakWaitState1[(value >> 7) & 1]; - memoryWait[0x0c] = memoryWait[0x0d] = gamepakWaitState[(value >> 8) & 7]; + memoryWait[0x0c] = memoryWait[0x0d] = gamepakWaitState[(value >> 8) & 3]; memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] = - gamepakWaitState2[(value >> 8) & 7]; + gamepakWaitState2[(value >> 10) & 1]; } else { - memoryWait[0x08] = memoryWait[0x09] = 4; - memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = 2; + memoryWait[0x08] = memoryWait[0x09] = 3; + memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = 1; - memoryWait[0x0a] = memoryWait[0x0b] = 4; - memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] = 4; + memoryWait[0x0a] = memoryWait[0x0b] = 3; + memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] = 1; - memoryWait[0x0c] = memoryWait[0x0d] = 4; - memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] = 8; + memoryWait[0x0c] = memoryWait[0x0d] = 3; + memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] = 1; } - for(i = 0; i < 16; i++) { - memoryWaitFetch32[i] = memoryWait32[i] = memoryWait[i] * - (memory32[i] ? 1 : 2); - memoryWaitFetch[i] = memoryWait[i]; + + for(int i = 8; i < 15; i++) { + memoryWait32[i] = memoryWait[i] + memoryWaitSeq[i] + 1; + memoryWaitSeq32[i] = memoryWaitSeq[i]*2 + 1; } - memoryWaitFetch32[3] += 1; - memoryWaitFetch32[2] += 3; - - if(value & 0x4000) { - for(i = 8; i < 16; i++) { - memoryWaitFetch32[i] = 2*cpuMemoryWait[i]; - memoryWaitFetch[i] = cpuMemoryWait[i]; - } + + if((value & 0x4000) == 0x4000) { + busPrefetchEnable = true; + busPrefetch = false; + busPrefetchCount = 0; + } else { + busPrefetchEnable = false; + busPrefetch = false; + busPrefetchCount = 0; } - UPDATE_REG(0x204, value); + UPDATE_REG(0x204, value & 0x7FFF); + } break; case 0x208: IME = value & 1; UPDATE_REG(0x208, IME); - if((IME & 1) && (IF & IE) && armIrqEnable) { - CPU_BREAK_LOOP_2; - } + if ((IME & 1) && (IF & IE) && armIrqEnable) + cpuNextEvent = cpuTotalTicks; break; case 0x300: if(value != 0) @@ -2711,6 +3068,65 @@ } } +void applyTimer () +{ + if (timerOnOffDelay & 1) + { + timer0ClockReload = TIMER_TICKS[timer0Value & 3]; + if(!timer0On && (timer0Value & 0x80)) { + // reload the counter + TM0D = timer0Reload; + timer0Ticks = (0x10000 - TM0D) << timer0ClockReload; + UPDATE_REG(0x100, TM0D); + } + timer0On = timer0Value & 0x80 ? true : false; + TM0CNT = timer0Value & 0xC7; + UPDATE_REG(0x102, TM0CNT); + // CPUUpdateTicks(); + } + if (timerOnOffDelay & 2) + { + timer1ClockReload = TIMER_TICKS[timer1Value & 3]; + if(!timer1On && (timer1Value & 0x80)) { + // reload the counter + TM1D = timer1Reload; + timer1Ticks = (0x10000 - TM1D) << timer1ClockReload; + UPDATE_REG(0x104, TM1D); + } + timer1On = timer1Value & 0x80 ? true : false; + TM1CNT = timer1Value & 0xC7; + UPDATE_REG(0x106, TM1CNT); + } + if (timerOnOffDelay & 4) + { + timer2ClockReload = TIMER_TICKS[timer2Value & 3]; + if(!timer2On && (timer2Value & 0x80)) { + // reload the counter + TM2D = timer2Reload; + timer2Ticks = (0x10000 - TM2D) << timer2ClockReload; + UPDATE_REG(0x108, TM2D); + } + timer2On = timer2Value & 0x80 ? true : false; + TM2CNT = timer2Value & 0xC7; + UPDATE_REG(0x10A, TM2CNT); + } + if (timerOnOffDelay & 8) + { + timer3ClockReload = TIMER_TICKS[timer3Value & 3]; + if(!timer3On && (timer3Value & 0x80)) { + // reload the counter + TM3D = timer3Reload; + timer3Ticks = (0x10000 - TM3D) << timer3ClockReload; + UPDATE_REG(0x10C, TM3D); + } + timer3On = timer3Value & 0x80 ? true : false; + TM3CNT = timer3Value & 0xC7; + UPDATE_REG(0x10E, TM3CNT); + } + cpuNextEvent = CPUUpdateTicks(); + timerOnOffDelay = 0; +} + void CPUWriteHalfWord(u32 address, u16 value) { #ifdef DEV_VERSION @@ -2726,38 +3142,58 @@ switch(address >> 24) { case 2: -#ifdef SDL +#ifdef BKPT_SUPPORT if(*((u16 *)&freezeWorkRAM[address & 0x3FFFE])) - cheatsWriteHalfWord((u16 *)&workRAM[address & 0x3FFFE], - value, - *((u16 *)&freezeWorkRAM[address & 0x3FFFE])); + cheatsWriteHalfWord(address & 0x203FFFE, + value); else #endif WRITE16LE(((u16 *)&workRAM[address & 0x3FFFE]),value); break; case 3: -#ifdef SDL +#ifdef BKPT_SUPPORT if(*((u16 *)&freezeInternalRAM[address & 0x7ffe])) - cheatsWriteHalfWord((u16 *)&internalRAM[address & 0x7ffe], - value, - *((u16 *)&freezeInternalRAM[address & 0x7ffe])); + cheatsWriteHalfWord(address & 0x3007ffe, + value); else #endif WRITE16LE(((u16 *)&internalRAM[address & 0x7ffe]), value); break; case 4: - CPUUpdateRegister(address & 0x3fe, value); + if(address < 0x4000400) + CPUUpdateRegister(address & 0x3fe, value); + else goto unwritable; break; case 5: +#ifdef BKPT_SUPPORT + if(*((u16 *)&freezePRAM[address & 0x03fe])) + cheatsWriteHalfWord(address & 0x70003fe, + value); + else +#endif WRITE16LE(((u16 *)&paletteRAM[address & 0x3fe]), value); break; case 6: - if(address & 0x10000) - WRITE16LE(((u16 *)&vram[address & 0x17ffe]), value); + address = (address & 0x1fffe); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + return; + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; +#ifdef BKPT_SUPPORT + if(*((u16 *)&freezeVRAM[address])) + cheatsWriteHalfWord(address + 0x06000000, + value); else - WRITE16LE(((u16 *)&vram[address & 0x1fffe]), value); +#endif + WRITE16LE(((u16 *)&vram[address]), value); break; case 7: +#ifdef BKPT_SUPPORT + if(*((u16 *)&freezeOAM[address & 0x03fe])) + cheatsWriteHalfWord(address & 0x70003fe, + value); + else +#endif WRITE16LE(((u16 *)&oam[address & 0x3fe]), value); break; case 8: @@ -2797,99 +3233,113 @@ { switch(address >> 24) { case 2: -#ifdef SDL +#ifdef BKPT_SUPPORT if(freezeWorkRAM[address & 0x3FFFF]) - cheatsWriteByte(&workRAM[address & 0x3FFFF], b); + cheatsWriteByte(address & 0x203FFFF, b); else #endif workRAM[address & 0x3FFFF] = b; break; case 3: -#ifdef SDL +#ifdef BKPT_SUPPORT if(freezeInternalRAM[address & 0x7fff]) - cheatsWriteByte(&internalRAM[address & 0x7fff], b); + cheatsWriteByte(address & 0x3007fff, b); else #endif internalRAM[address & 0x7fff] = b; break; case 4: - switch(address & 0x3FF) { - case 0x301: - if(b == 0x80) - stopState = true; - holdState = 1; - holdType = -1; - break; - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x68: - case 0x69: - case 0x6c: - case 0x6d: - case 0x70: - case 0x71: - case 0x72: - case 0x73: - case 0x74: - case 0x75: - case 0x78: - case 0x79: - case 0x7c: - case 0x7d: - case 0x80: - case 0x81: - case 0x84: - case 0x85: - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0x94: - case 0x95: - case 0x96: - case 0x97: - case 0x98: - case 0x99: - case 0x9a: - case 0x9b: - case 0x9c: - case 0x9d: - case 0x9e: - case 0x9f: - soundEvent(address&0xFF, b); + if(address < 0x4000400) { + switch(address & 0x3FF) { + case 0x301: + if(b == 0x80) + stopState = true; + holdState = 1; + holdType = -1; + cpuNextEvent = cpuTotalTicks; + break; + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x68: + case 0x69: + case 0x6c: + case 0x6d: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x78: + case 0x79: + case 0x7c: + case 0x7d: + case 0x80: + case 0x81: + case 0x84: + case 0x85: + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + case 0x98: + case 0x99: + case 0x9a: + case 0x9b: + case 0x9c: + case 0x9d: + case 0x9e: + case 0x9f: + soundEvent(address&0xFF, b); + break; + default: + if(address & 1) + CPUUpdateRegister(address & 0x3fe, + ((READ16LE(((u16 *)&ioMem[address & 0x3fe]))) + & 0x00FF) | + b<<8); + else + CPUUpdateRegister(address & 0x3fe, + ((READ16LE(((u16 *)&ioMem[address & 0x3fe])) & 0xFF00) | b)); + } break; - default: - // if(address & 1) { - // CPUWriteHalfWord(address-1, (CPUReadHalfWord(address-1)&0x00FF)|((int)b<<8)); - // } else - if(address & 1) - CPUUpdateRegister(address & 0x3fe, - ((READ16LE(((u16 *)&ioMem[address & 0x3fe]))) - & 0x00FF) | - b<<8); - else - CPUUpdateRegister(address & 0x3fe, - ((READ16LE(((u16 *)&ioMem[address & 0x3fe])) & 0xFF00) | b)); - } + } else goto unwritable; break; case 5: // no need to switch *((u16 *)&paletteRAM[address & 0x3FE]) = (b << 8) | b; break; case 6: - // no need to switch - if(address & 0x10000) - *((u16 *)&vram[address & 0x17FFE]) = (b << 8) | b; - else - *((u16 *)&vram[address & 0x1FFFE]) = (b << 8) | b; + address = (address & 0x1fffe); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + return; + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; + + // no need to switch + // byte writes to OBJ VRAM are ignored + if ((address) < objTilesAddress[((DISPCNT&7)+1)>>2]) + { +#ifdef BKPT_SUPPORT + if(freezeVRAM[address]) + cheatsWriteByte(address + 0x06000000, b); + else +#endif + *((u16 *)&vram[address]) = (b << 8) | b; + } break; case 7: // no need to switch - *((u16 *)&oam[address & 0x3FE]) = (b << 8) | b; + // byte writes to OAM are ignored + // *((u16 *)&oam[address & 0x3FE]) = (b << 8) | b; break; case 13: if(cpuEEPROMEnabled) { @@ -2898,8 +3348,11 @@ } goto unwritable; case 14: - if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled) { - (*cpuSaveGameFunc)(address, b); + if (!(saveType == 5) && (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)) { + + //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) { + + (*cpuSaveGameFunc)(address, b); break; } // default @@ -3008,8 +3461,12 @@ for(i = 0x304; i < 0x400; i++) ioReadable[i] = false; - *((u16 *)&rom[0x1fe209c]) = 0xdffa; // SWI 0xFA - *((u16 *)&rom[0x1fe209e]) = 0x4770; // BX LR + if(romSize < 0x1fe2000) { + *((u16 *)&rom[0x1fe209c]) = 0xdffa; // SWI 0xFA + *((u16 *)&rom[0x1fe209e]) = 0x4770; // BX LR + } else { + agbPrintEnable(false); + } } void CPUReset() @@ -3028,7 +3485,7 @@ } } rtcReset(); - // clen registers + // clean registers memset(®[0], 0, sizeof(reg)); // clean OAM memset(oam, 0, 0x400); @@ -3043,7 +3500,7 @@ DISPCNT = 0x0080; DISPSTAT = 0x0000; - VCOUNT = 0x0000; + VCOUNT = (useBios && !skipBios) ? 0 :0x007E; BG0CNT = 0x0000; BG1CNT = 0x0000; BG2CNT = 0x0000; @@ -3132,7 +3589,7 @@ if(useBios && !skipBios) { reg[15].I = 0x00000000; armMode = 0x13; - armIrqEnable = false; + armIrqEnable = false; } else { reg[13].I = 0x03007F00; reg[15].I = 0x08000000; @@ -3145,6 +3602,7 @@ armState = true; C_FLAG = V_FLAG = N_FLAG = Z_FLAG = false; UPDATE_REG(0x00, DISPCNT); + UPDATE_REG(0x06, VCOUNT); UPDATE_REG(0x20, BG2PA); UPDATE_REG(0x26, BG2PD); UPDATE_REG(0x30, BG3PA); @@ -3169,7 +3627,7 @@ biosProtected[2] = 0x29; biosProtected[3] = 0xe1; - lcdTicks = 960; + lcdTicks = (useBios && !skipBios) ? 1008 : 208; timer0On = false; timer0Ticks = 0; timer0Reload = 0; @@ -3259,44 +3717,59 @@ cpuFlashEnabled = true; cpuEEPROMEnabled = true; cpuEEPROMSensorEnabled = false; + saveType = gbaSaveType = 0; break; case 1: // EEPROM cpuSramEnabled = false; cpuFlashEnabled = false; cpuEEPROMEnabled = true; cpuEEPROMSensorEnabled = false; + saveType = gbaSaveType = 3; + // EEPROM usage is automatically detected break; case 2: // SRAM cpuSramEnabled = true; cpuFlashEnabled = false; cpuEEPROMEnabled = false; cpuEEPROMSensorEnabled = false; - cpuSaveGameFunc = sramWrite; + cpuSaveGameFunc = sramDelayedWrite; // to insure we detect the write + saveType = gbaSaveType = 1; break; case 3: // FLASH cpuSramEnabled = false; cpuFlashEnabled = true; cpuEEPROMEnabled = false; cpuEEPROMSensorEnabled = false; - cpuSaveGameFunc = flashWrite; + cpuSaveGameFunc = flashDelayedWrite; // to insure we detect the write + saveType = gbaSaveType = 2; break; case 4: // EEPROM+Sensor cpuSramEnabled = false; cpuFlashEnabled = false; cpuEEPROMEnabled = true; cpuEEPROMSensorEnabled = true; + // EEPROM usage is automatically detected + saveType = gbaSaveType = 3; break; case 5: // NONE cpuSramEnabled = false; cpuFlashEnabled = false; cpuEEPROMEnabled = false; cpuEEPROMSensorEnabled = false; + // no save at all + saveType = gbaSaveType = 5; break; } + ARM_PREFETCH; + systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; - + + cpuDmaHack = false; + lastTime = systemGetClock(); + + SWITicks = 0; } void CPUInterrupt() @@ -3313,6 +3786,7 @@ armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; // if(!holdState) biosProtected[0] = 0x02; @@ -3345,30 +3819,30 @@ void CPULoop(int ticks) { int clockTicks; - int cpuLoopTicks = 0; int timerOverflow = 0; - // variables used by the CPU core + // variable used by the CPU core + cpuTotalTicks = 0; + cpuBreakLoop = false; + cpuNextEvent = CPUUpdateTicks(); + if(cpuNextEvent > ticks) + cpuNextEvent = ticks; - extCpuLoopTicks = &cpuLoopTicks; - extClockTicks = &clockTicks; - extTicks = &ticks; - cpuLoopTicks = CPUUpdateTicks(); - if(cpuLoopTicks > ticks) { - cpuLoopTicks = ticks; - cpuSavedTicks = ticks; - } - - if(intState) { - cpuLoopTicks = 5; - cpuSavedTicks = 5; - } - for(;;) { #ifndef FINAL_VERSION if(systemDebug) { if(systemDebug >= 10 && !holdState) { CPUUpdateCPSR(); +#ifdef BKPT_SUPPORT + if (debugger_last) + { + sprintf(buffer, "R00=%08x R01=%08x R02=%08x R03=%08x R04=%08x R05=%08x R06=%08x R07=%08x R08=%08x R09=%08x R10=%08x R11=%08x R12=%08x R13=%08x R14=%08x R15=%08x R16=%08x R17=%08x\n", + oldreg[0], oldreg[1], oldreg[2], oldreg[3], oldreg[4], oldreg[5], + oldreg[6], oldreg[7], oldreg[8], oldreg[9], oldreg[10], oldreg[11], + oldreg[12], oldreg[13], oldreg[14], oldreg[15], oldreg[16], + oldreg[17]); + } +#endif sprintf(buffer, "R00=%08x R01=%08x R02=%08x R03=%08x R04=%08x R05=%08x R06=%08x R07=%08x R08=%08x R09=%08x R10=%08x R11=%08x R12=%08x R13=%08x R14=%08x R15=%08x R16=%08x R17=%08x\n", reg[0].I, reg[1].I, reg[2].I, reg[3].I, reg[4].I, reg[5].I, reg[6].I, reg[7].I, reg[8].I, reg[9].I, reg[10].I, reg[11].I, @@ -3388,63 +3862,72 @@ #endif } } -#endif +#endif /* FINAL_VERSION */ + + if(!holdState && !SWITicks) { + + // Emulates the Cheat System (m) code + if((cheatsEnabled) && (mastercode) && (mastercode == armNextPC)) + { + u32 joy = 0; + if(systemReadJoypads()) + joy = systemReadJoypad(-1); + u32 ext = (joy >> 10); + cpuTotalTicks += cheatsCheckKeys(P1^0x3FF, ext); + } + + if ((armNextPC & 0x0803FFFF) == 0x08020000) + busPrefetchCount=0x100; - if(!holdState) { if(armState) { #include "arm-new.h" } else { #include "thumb.h" } - } else { - clockTicks = lcdTicks; + } else + clockTicks = CPUUpdateTicks(); - if(soundTicks < clockTicks) - clockTicks = soundTicks; - - if(timer0On && (timer0Ticks < clockTicks)) { - clockTicks = timer0Ticks; - } - if(timer1On && (timer1Ticks < clockTicks)) { - clockTicks = timer1Ticks; - } - if(timer2On && (timer2Ticks < clockTicks)) { - clockTicks = timer2Ticks; - } - if(timer3On && (timer3Ticks < clockTicks)) { - clockTicks = timer3Ticks; - } -#ifdef PROFILING - if(profilingTicksReload != 0) { - if(profilingTicks < clockTicks) { - clockTicks = profilingTicks; - } + cpuTotalTicks += clockTicks; + + + if(cpuTotalTicks >= cpuNextEvent) { + int remainingTicks = cpuTotalTicks - cpuNextEvent; + + if (SWITicks) + { + SWITicks-=clockTicks; + if (SWITicks<0) + SWITicks = 0; } -#endif - } + + clockTicks = cpuNextEvent; + cpuTotalTicks = 0; + cpuDmaHack = false; - cpuLoopTicks -= clockTicks; - if((cpuLoopTicks <= 0)) { - if(cpuSavedTicks) { - clockTicks = cpuSavedTicks;// + cpuLoopTicks; + updateLoop: + + if (IRQTicks) + { + IRQTicks -= clockTicks; + if (IRQTicks<0) + IRQTicks = 0; } - cpuDmaTicksToUpdate = -cpuLoopTicks; - updateLoop: lcdTicks -= clockTicks; + if(lcdTicks <= 0) { if(DISPSTAT & 1) { // V-BLANK // if in V-Blank mode, keep computing... if(DISPSTAT & 2) { - lcdTicks += 960; + lcdTicks += 1008; VCOUNT++; UPDATE_REG(0x06, VCOUNT); DISPSTAT &= 0xFFFD; UPDATE_REG(0x04, DISPSTAT); CPUCompareVCOUNT(); } else { - lcdTicks += 272; + lcdTicks += 224; DISPSTAT |= 2; UPDATE_REG(0x04, DISPSTAT); if(DISPSTAT & 16) { @@ -3453,7 +3936,7 @@ } } - if(VCOUNT >= 228) { + if(VCOUNT >= 228) { //Reaching last line DISPSTAT &= 0xFFFC; UPDATE_REG(0x04, DISPSTAT); VCOUNT = 0; @@ -3469,8 +3952,8 @@ // if in H-Blank, leave it and move to drawing mode VCOUNT++; UPDATE_REG(0x06, VCOUNT); - - lcdTicks += (960); + + lcdTicks += 1008; DISPSTAT &= 0xFFFD; if(VCOUNT == 160) { count++; @@ -3518,10 +4001,9 @@ } u32 ext = (joy >> 10); - int cheatTicks = 0; - if(cheatsEnabled) - cheatsCheckKeys(P1^0x3FF, ext); - cpuDmaTicksToUpdate += cheatTicks; + // If no (m) code is enabled, apply the cheats at each LCDline + if((cheatsEnabled) && (mastercode==0)) + remainingTicks += cheatsCheckKeys(P1^0x3FF, ext); speedup = (ext & 1) ? true : false; capture = (ext & 2) ? true : false; @@ -3530,7 +4012,7 @@ systemScreenCapture(captureNumber); } capturePrevious = capture; - + DISPSTAT |= 1; DISPSTAT &= 0xFFFD; UPDATE_REG(0x04, DISPSTAT); @@ -3549,14 +4031,14 @@ } UPDATE_REG(0x04, DISPSTAT); - - CPUCompareVCOUNT(); + CPUCompareVCOUNT(); + } else { - if(frameCount >= framesToSkip) { - (*renderLine)(); - + if(frameCount >= framesToSkip) + { + (*renderLine)(); switch(systemColorDepth) { - case 16: + case 16: { u16 *dest = (u16 *)pix + 242 * (VCOUNT+1); for(int x = 0; x < 240;) { @@ -3584,7 +4066,7 @@ *dest++ = 0; } break; - case 24: + case 24: { u8 *dest = (u8 *)pix + 240 * VCOUNT * 3; for(int x = 0; x < 240;) { @@ -3626,7 +4108,7 @@ } } break; - case 32: + case 32: { u32 *dest = (u32 *)pix + 241 * (VCOUNT+1); for(int x = 0; x < 240; ) { @@ -3634,7 +4116,7 @@ *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; - + *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; *dest++ = systemColorMap32[lineMix[x++] & 0xFFFF]; @@ -3657,7 +4139,7 @@ // entering H-Blank DISPSTAT |= 2; UPDATE_REG(0x04, DISPSTAT); - lcdTicks += 272; + lcdTicks += 224; CPUCheckDMA(2, 0x0f); if(DISPSTAT & 16) { IF |= 2; @@ -3669,37 +4151,18 @@ if(!stopState) { if(timer0On) { - if(timer0ClockReload == 1) { - u32 tm0d = TM0D + clockTicks; - if(tm0d > 0xffff) { - tm0d += timer0Reload; - timerOverflow |= 1; - soundTimerOverflow(0); - if(TM0CNT & 0x40) { - IF |= 0x08; - UPDATE_REG(0x202, IF); - } - } - TM0D = tm0d; - timer0Ticks = 0x10000 - TM0D; - UPDATE_REG(0x100, TM0D); - } else { - timer0Ticks -= clockTicks; - if(timer0Ticks <= 0) { - timer0Ticks += timer0ClockReload; - TM0D++; - if(TM0D == 0) { - TM0D = timer0Reload; - timerOverflow |= 1; - soundTimerOverflow(0); - if(TM0CNT & 0x40) { - IF |= 0x08; - UPDATE_REG(0x202, IF); - } - } - UPDATE_REG(0x100, TM0D); + timer0Ticks -= clockTicks; + if(timer0Ticks <= 0) { + timer0Ticks += (0x10000 - timer0Reload) << timer0ClockReload; + timerOverflow |= 1; + soundTimerOverflow(0); + if(TM0CNT & 0x40) { + IF |= 0x08; + UPDATE_REG(0x202, IF); } } + TM0D = 0xFFFF - (timer0Ticks >> timer0ClockReload); + UPDATE_REG(0x100, TM0D); } if(timer1On) { @@ -3718,38 +4181,18 @@ UPDATE_REG(0x104, TM1D); } } else { - if(timer1ClockReload == 1) { - u32 tm1d = TM1D + clockTicks; - if(tm1d > 0xffff) { - tm1d += timer1Reload; - timerOverflow |= 2; - soundTimerOverflow(1); - if(TM1CNT & 0x40) { - IF |= 0x10; - UPDATE_REG(0x202, IF); - } - } - TM1D = tm1d; - timer1Ticks = 0x10000 - TM1D; - UPDATE_REG(0x104, TM1D); - } else { - timer1Ticks -= clockTicks; - if(timer1Ticks <= 0) { - timer1Ticks += timer1ClockReload; - TM1D++; - - if(TM1D == 0) { - TM1D = timer1Reload; - timerOverflow |= 2; - soundTimerOverflow(1); - if(TM1CNT & 0x40) { - IF |= 0x10; - UPDATE_REG(0x202, IF); - } - } - UPDATE_REG(0x104, TM1D); + timer1Ticks -= clockTicks; + if(timer1Ticks <= 0) { + timer1Ticks += (0x10000 - timer1Reload) << timer1ClockReload; + timerOverflow |= 2; + soundTimerOverflow(1); + if(TM1CNT & 0x40) { + IF |= 0x10; + UPDATE_REG(0x202, IF); } } + TM1D = 0xFFFF - (timer1Ticks >> timer1ClockReload); + UPDATE_REG(0x104, TM1D); } } @@ -3768,36 +4211,17 @@ UPDATE_REG(0x108, TM2D); } } else { - if(timer2ClockReload == 1) { - u32 tm2d = TM2D + clockTicks; - if(tm2d > 0xffff) { - tm2d += timer2Reload; - timerOverflow |= 4; - if(TM2CNT & 0x40) { - IF |= 0x20; - UPDATE_REG(0x202, IF); - } - } - TM2D = tm2d; - timer2Ticks = 0x10000 - TM2D; - UPDATE_REG(0x108, TM2D); - } else { - timer2Ticks -= clockTicks; - if(timer2Ticks <= 0) { - timer2Ticks += timer2ClockReload; - TM2D++; - - if(TM2D == 0) { - TM2D = timer2Reload; - timerOverflow |= 4; - if(TM2CNT & 0x40) { - IF |= 0x20; - UPDATE_REG(0x202, IF); - } - } - UPDATE_REG(0x108, TM2D); + timer2Ticks -= clockTicks; + if(timer2Ticks <= 0) { + timer2Ticks += (0x10000 - timer2Reload) << timer2ClockReload; + timerOverflow |= 4; + if(TM2CNT & 0x40) { + IF |= 0x20; + UPDATE_REG(0x202, IF); } } + TM2D = 0xFFFF - (timer2Ticks >> timer2ClockReload); + UPDATE_REG(0x108, TM2D); } } @@ -3812,41 +4236,26 @@ UPDATE_REG(0x202, IF); } } - UPDATE_REG(0x10c, TM3D); + UPDATE_REG(0x10C, TM3D); } } else { - if(timer3ClockReload == 1) { - u32 tm3d = TM3D + clockTicks; - if(tm3d > 0xffff) { - tm3d += timer3Reload; - if(TM3CNT & 0x40) { - IF |= 0x40; - UPDATE_REG(0x202, IF); - } - } - TM3D = tm3d; - timer3Ticks = 0x10000 - TM3D; - UPDATE_REG(0x10C, TM3D); - } else { - timer3Ticks -= clockTicks; - if(timer3Ticks <= 0) { - timer3Ticks += timer3ClockReload; - TM3D++; - - if(TM3D == 0) { - TM3D = timer3Reload; - if(TM3CNT & 0x40) { - IF |= 0x40; - UPDATE_REG(0x202, IF); - } - } - UPDATE_REG(0x10C, TM3D); + timer3Ticks -= clockTicks; + if(timer3Ticks <= 0) { + timer3Ticks += (0x10000 - timer3Reload) << timer3ClockReload; + if(TM3CNT & 0x40) { + IF |= 0x40; + UPDATE_REG(0x202, IF); } } + TM3D = 0xFFFF - (timer3Ticks >> timer3ClockReload); + UPDATE_REG(0x10C, TM3D); } } } - // we shouldn't be doing sound in stop state, but we lose synchronization + + timerOverflow = 0; + + // we shouldn't be doing sound in stop state, but we loose synchronization // if sound is disabled, so in stop state, soundTick will just produce // mute sound soundTicks -= clockTicks; @@ -3854,33 +4263,40 @@ soundTick(); soundTicks += SOUND_CLOCK_TICKS; } - timerOverflow = 0; #ifdef PROFILING profilingTicks -= clockTicks; if(profilingTicks <= 0) { profilingTicks += profilingTicksReload; - if(profilBuffer && profilSize) { - u16 *b = (u16 *)profilBuffer; - int pc = ((reg[15].I - profilLowPC) * profilScale)/0x10000; - if(pc >= 0 && pc < profilSize) { + if(profilSegment) { + profile_segment *seg = profilSegment; + do { + u16 *b = (u16 *)seg->sbuf; + int pc = ((reg[15].I - seg->s_lowpc) * seg->s_scale)/0x10000; + if(pc >= 0 && pc < seg->ssiz) { b[pc]++; + break; } + + seg = seg->next; + } while(seg); } } #endif ticks -= clockTicks; - cpuLoopTicks = CPUUpdateTicks(); + cpuNextEvent = CPUUpdateTicks(); if(cpuDmaTicksToUpdate > 0) { - clockTicks = cpuSavedTicks; - if(clockTicks > cpuDmaTicksToUpdate) + if(cpuDmaTicksToUpdate > cpuNextEvent) + clockTicks = cpuNextEvent; + else clockTicks = cpuDmaTicksToUpdate; cpuDmaTicksToUpdate -= clockTicks; if(cpuDmaTicksToUpdate < 0) cpuDmaTicksToUpdate = 0; + cpuDmaHack = true; goto updateLoop; } @@ -3889,35 +4305,68 @@ if(stopState) res &= 0x3080; if(res) { - if(intState) { - CPUInterrupt(); - intState = false; - if(holdState) { + if (intState) + { + if (!IRQTicks) + { + CPUInterrupt(); + intState = false; holdState = false; stopState = false; - } - } else { - if(!holdState) { + holdType = 0; + } + } + else + { + if (!holdState) + { intState = true; - cpuLoopTicks = 5; - cpuSavedTicks = 5; - } else { - CPUInterrupt(); - if(holdState) { - holdState = false; - stopState = false; - } + IRQTicks=7; + if (cpuNextEvent> IRQTicks) + cpuNextEvent = IRQTicks; + } + else + { + CPUInterrupt(); + holdState = false; + stopState = false; + holdType = 0; } } + + // Stops the SWI Ticks emulation if an IRQ is executed + //(to avoid problems with nested IRQ/SWI) + if (SWITicks) + SWITicks = 0; } } - - if(ticks <= 0) + + if(remainingTicks > 0) { + if(remainingTicks > cpuNextEvent) + clockTicks = cpuNextEvent; + else + clockTicks = remainingTicks; + remainingTicks -= clockTicks; + if(remainingTicks < 0) + remainingTicks = 0; + goto updateLoop; + } + + if (timerOnOffDelay) + applyTimer(); + + if(cpuNextEvent > ticks) + cpuNextEvent = ticks; + + if(ticks <= 0 || cpuBreakLoop) break; + } } } + + struct EmulatedSystem GBASystem = { // emuMain CPULoop, @@ -3931,7 +4380,7 @@ CPUWriteBatteryFile, // emuReadState CPUReadState, - // emuWriteState + // emuWriteState CPUWriteState, // emuReadMemState CPUReadMemState, diff -urN ../VisualBoyAdvance-1.7.2/src/GBA.h ./src/GBA.h --- ../VisualBoyAdvance-1.7.2/src/GBA.h 2004-05-13 23:04:58 +0900 +++ ./src/GBA.h 2006-08-25 23:13:38 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -30,7 +30,8 @@ #define SAVE_GAME_VERSION_6 6 #define SAVE_GAME_VERSION_7 7 #define SAVE_GAME_VERSION_8 8 -#define SAVE_GAME_VERSION SAVE_GAME_VERSION_8 +#define SAVE_GAME_VERSION_9 9 +#define SAVE_GAME_VERSION SAVE_GAME_VERSION_9 typedef struct { u8 *address; @@ -83,8 +84,17 @@ extern int armMode; extern void (*cpuSaveGameFunc)(u32,u8); -extern bool freezeWorkRAM[0x40000]; -extern bool freezeInternalRAM[0x8000]; +#ifdef BKPT_SUPPORT +extern u8 freezeWorkRAM[0x40000]; +extern u8 freezeInternalRAM[0x8000]; +extern u8 freezeVRAM[0x18000]; +extern u8 freezeOAM[0x400]; +extern u8 freezePRAM[0x400]; +extern bool debugger_last; +extern int oldreg[17]; +extern char oldbuffer[10]; +#endif + extern bool CPUReadGSASnapshot(const char *); extern bool CPUWriteGSASnapshot(const char *, const char *, const char *, const char *); extern bool CPUWriteBatteryFile(const char *); @@ -100,7 +110,9 @@ extern bool CPUWriteMemState(char *, int); extern bool CPUWriteState(const char *); extern int CPULoadRom(const char *); +extern void doMirroring(bool); extern void CPUUpdateRegister(u32, u16); +extern void applyTimer (); extern void CPUWriteHalfWord(u32, u16); extern void CPUWriteByte(u32, u8); extern void CPUInit(const char *,bool); @@ -110,7 +122,8 @@ extern bool CPUIsGBAImage(const char *); extern bool CPUIsZipFile(const char *); #ifdef PROFILING -extern void cpuProfil(char *buffer, int, u32, int); +#include "prof/prof.h" +extern void cpuProfil(profile_segment *seg); extern void cpuEnableProfiling(int hz); #endif diff -urN ../VisualBoyAdvance-1.7.2/src/GBAinline.h ./src/GBAinline.h --- ../VisualBoyAdvance-1.7.2/src/GBAinline.h 2004-05-13 23:04:44 +0900 +++ ./src/GBAinline.h 2006-09-04 06:52:25 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -28,6 +28,21 @@ extern bool cpuFlashEnabled; extern bool cpuEEPROMEnabled; extern bool cpuEEPROMSensorEnabled; +extern bool cpuDmaHack; +extern u32 cpuDmaLast; +extern bool timer0On; +extern int timer0Ticks; +extern int timer0ClockReload; +extern bool timer1On; +extern int timer1Ticks; +extern int timer1ClockReload; +extern bool timer2On; +extern int timer2Ticks; +extern int timer2ClockReload; +extern bool timer3On; +extern int timer3Ticks; +extern int timer3ClockReload; +extern int cpuTotalTicks; #define CPUReadByteQuick(addr) \ map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] @@ -38,7 +53,7 @@ #define CPUReadMemoryQuick(addr) \ READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) -inline u32 CPUReadMemory(u32 address) +static inline u32 CPUReadMemory(u32 address) { #ifdef DEV_VERSION @@ -86,7 +101,15 @@ value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC])); break; case 6: - value = READ32LE(((u32 *)&vram[address & 0x1fffc])); + address = (address & 0x1fffc); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + { + value = 0; + break; + } + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; + value = READ32LE(((u32 *)&vram[address])); break; case 7: value = READ32LE(((u32 *)&oam[address & 0x3FC])); @@ -116,18 +139,17 @@ armNextPC - 4 : armNextPC - 2); } #endif - - // if(ioMem[0x205] & 0x40) { + + if(cpuDmaHack) { + value = cpuDmaLast; + } else { if(armState) { value = CPUReadMemoryQuick(reg[15].I); } else { value = CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16; } - // } else { - // value = *((u32 *)&bios[address & 0x3ffc]); - // } - // return 0xFFFFFFFF; + } } if(address & 3) { @@ -156,7 +178,7 @@ extern u32 myROM[]; -inline u32 CPUReadHalfWord(u32 address) +static inline u32 CPUReadHalfWord(u32 address) { #ifdef DEV_VERSION if(address & 1) { @@ -192,14 +214,38 @@ break; case 4: if((address < 0x4000400) && ioReadable[address & 0x3fe]) + { value = READ16LE(((u16 *)&ioMem[address & 0x3fe])); + if (((address & 0x3fe)>0xFF) && ((address & 0x3fe)<0x10E)) + { + if (((address & 0x3fe) == 0x100) && timer0On) + value = 0xFFFF - ((timer0Ticks-cpuTotalTicks) >> timer0ClockReload); + else + if (((address & 0x3fe) == 0x104) && timer1On && !(TM1CNT & 4)) + value = 0xFFFF - ((timer1Ticks-cpuTotalTicks) >> timer1ClockReload); + else + if (((address & 0x3fe) == 0x108) && timer2On && !(TM2CNT & 4)) + value = 0xFFFF - ((timer2Ticks-cpuTotalTicks) >> timer2ClockReload); + else + if (((address & 0x3fe) == 0x10C) && timer3On && !(TM3CNT & 4)) + value = 0xFFFF - ((timer3Ticks-cpuTotalTicks) >> timer3ClockReload); + } + } else goto unreadable; break; case 5: value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe])); break; case 6: - value = READ16LE(((u16 *)&vram[address & 0x1fffe])); + address = (address & 0x1fffe); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + { + value = 0; + break; + } + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; + value = READ16LE(((u16 *)&vram[address])); break; case 7: value = READ16LE(((u16 *)&oam[address & 0x3fe])); @@ -232,11 +278,8 @@ armNextPC - 4 : armNextPC - 2); } #endif - extern bool cpuDmaHack; - extern u32 cpuDmaLast; - extern int cpuDmaCount; - if(cpuDmaHack && cpuDmaCount) { - value = (u16)cpuDmaLast; + if(cpuDmaHack) { + value = cpuDmaLast & 0xFFFF; } else { if(armState) { value = CPUReadHalfWordQuick(reg[15].I + (address & 2)); @@ -244,10 +287,6 @@ value = CPUReadHalfWordQuick(reg[15].I); } } - // return value; - // if(address & 1) - // value = (value >> 8) | ((value & 0xFF) << 24); - // return 0xFFFF; break; } @@ -258,7 +297,7 @@ return value; } -inline u16 CPUReadHalfWordSigned(u32 address) +static inline u16 CPUReadHalfWordSigned(u32 address) { u16 value = CPUReadHalfWord(address); if((address & 1)) @@ -266,7 +305,7 @@ return value; } -inline u8 CPUReadByte(u32 address) +static inline u8 CPUReadByte(u32 address) { switch(address >> 24) { case 0: @@ -293,7 +332,12 @@ case 5: return paletteRAM[address & 0x3ff]; case 6: - return vram[address & 0x1ffff]; + address = (address & 0x1ffff); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + return 0; + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; + return vram[address]; case 7: return oam[address & 0x3ff]; case 8: @@ -325,28 +369,31 @@ default: unreadable: #ifdef DEV_VERSION - if(systemVerbose & VERBOSE_ILLEGAL_READ) { - log("Illegal byte read: %08x at %08x\n", address, armMode ? - armNextPC - 4 : armNextPC - 2); - } + if(systemVerbose & VERBOSE_ILLEGAL_READ) { + log("Illegal byte read: %08x at %08x\n", address, armMode ? + armNextPC - 4 : armNextPC - 2); + } #endif - - if(armState) { - return CPUReadByteQuick(reg[15].I+(address & 3)); + if(cpuDmaHack) { + return cpuDmaLast & 0xFF; } else { - return CPUReadByteQuick(reg[15].I+(address & 1)); + if(armState) { + return CPUReadByteQuick(reg[15].I+(address & 3)); + } else { + return CPUReadByteQuick(reg[15].I+(address & 1)); + } } - // return 0xFF; break; } } -inline void CPUWriteMemory(u32 address, u32 value) +static inline void CPUWriteMemory(u32 address, u32 value) { + #ifdef DEV_VERSION if(address & 3) { if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) { - log("Unaliagned word write: %08x to %08x from %08x\n", + log("Unaligned word write: %08x to %08x from %08x\n", value, address, armMode ? armNextPC - 4 : armNextPC - 2); @@ -356,39 +403,60 @@ switch(address >> 24) { case 0x02: -#ifdef SDL +#ifdef BKPT_SUPPORT if(*((u32 *)&freezeWorkRAM[address & 0x3FFFC])) - cheatsWriteMemory((u32 *)&workRAM[address & 0x3FFFC], - value, - *((u32 *)&freezeWorkRAM[address & 0x3FFFC])); + cheatsWriteMemory(address & 0x203FFFC, + value); else #endif WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value); break; case 0x03: -#ifdef SDL +#ifdef BKPT_SUPPORT if(*((u32 *)&freezeInternalRAM[address & 0x7ffc])) - cheatsWriteMemory((u32 *)&internalRAM[address & 0x7FFC], - value, - *((u32 *)&freezeInternalRAM[address & 0x7ffc])); + cheatsWriteMemory(address & 0x3007FFC, + value); else #endif WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value); break; case 0x04: - CPUUpdateRegister((address & 0x3FC), value & 0xFFFF); - CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16)); + if(address < 0x4000400) { + CPUUpdateRegister((address & 0x3FC), value & 0xFFFF); + CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16)); + } else goto unwritable; break; case 0x05: +#ifdef BKPT_SUPPORT + if(*((u32 *)&freezePRAM[address & 0x3fc])) + cheatsWriteMemory(address & 0x70003FC, + value); + else +#endif WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value); break; case 0x06: - if(address & 0x10000) - WRITE32LE(((u32 *)&vram[address & 0x17ffc]), value); + address = (address & 0x1fffc); + if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000)) + return; + if ((address & 0x18000) == 0x18000) + address &= 0x17fff; + +#ifdef BKPT_SUPPORT + if(*((u32 *)&freezeVRAM[address])) + cheatsWriteMemory(address + 0x06000000, value); else - WRITE32LE(((u32 *)&vram[address & 0x1fffc]), value); +#endif + + WRITE32LE(((u32 *)&vram[address]), value); break; case 0x07: +#ifdef BKPT_SUPPORT + if(*((u32 *)&freezeOAM[address & 0x3fc])) + cheatsWriteMemory(address & 0x70003FC, + value); + else +#endif WRITE32LE(((u32 *)&oam[address & 0x3fc]), value); break; case 0x0D: diff -urN ../VisualBoyAdvance-1.7.2/src/Gfx.cpp ./src/Gfx.cpp --- ../VisualBoyAdvance-1.7.2/src/Gfx.cpp 2004-05-13 23:37:47 +0900 +++ ./src/Gfx.cpp 2005-09-03 21:28:23 +0900 @@ -22,7 +22,6 @@ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; - u32 line0[240]; u32 line1[240]; u32 line2[240]; @@ -32,6 +31,7 @@ u32 lineMix[240]; bool gfxInWin0[240]; bool gfxInWin1[240]; +int lineOBJpixleft[128]; int gfxBG2Changed = 0; int gfxBG3Changed = 0; diff -urN ../VisualBoyAdvance-1.7.2/src/Gfx.h ./src/Gfx.h --- ../VisualBoyAdvance-1.7.2/src/Gfx.h 2004-05-13 23:04:18 +0900 +++ ./src/Gfx.h 2006-08-25 23:50:53 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -100,6 +100,7 @@ extern u32 lineMix[240]; extern bool gfxInWin0[240]; extern bool gfxInWin1[240]; +extern int lineOBJpixleft[128]; extern int gfxBG2Changed; extern int gfxBG3Changed; @@ -305,7 +306,7 @@ int dy = pc & 0x7FFF; if(pc & 0x8000) dy |= 0xFFFF8000; - int dmy = pd & 0x7FFFF; + int dmy = pd & 0x7FFF; if(pd & 0x8000) dmy |= 0xFFFF8000; @@ -462,7 +463,7 @@ int dy = pc & 0x7FFF; if(pc & 0x8000) dy |= 0xFFFF8000; - int dmy = pd & 0x7FFFF; + int dmy = pd & 0x7FFF; if(pd & 0x8000) dmy |= 0xFFFF8000; @@ -560,7 +561,7 @@ int dy = pc & 0x7FFF; if(pc & 0x8000) dy |= 0xFFFF8000; - int dmy = pd & 0x7FFFF; + int dmy = pd & 0x7FFF; if(pd & 0x8000) dmy |= 0xFFFF8000; @@ -661,7 +662,7 @@ int dy = pc & 0x7FFF; if(pc & 0x8000) dy |= 0xFFFF8000; - int dmy = pd & 0x7FFFF; + int dmy = pd & 0x7FFF; if(pd & 0x8000) dmy |= 0xFFFF8000; @@ -731,6 +732,10 @@ inline void gfxDrawSprites(u32 *lineOBJ) { + // lineOBJpix is used to keep track of the drawn OBJs + // and to stop drawing them if the 'maximum number of OBJ per line' + // has been reached. + int lineOBJpix = (DISPCNT & 0x20) ? 954 : 1226; int m=0; gfxClearArray(lineOBJ); if(layerEnable & 0x1000) { @@ -744,55 +749,37 @@ u16 a2 = READ16LE(sprites++); sprites++; - // ignore OBJ-WIN - if((a0 & 0x0c00) == 0x0800) - continue; - - int sizeY = 8; - int sizeX = 8; - - switch(((a0 >>12) & 0x0c)|(a1>>14)) { - case 0: - break; - case 1: - sizeX = sizeY = 16; - break; - case 2: - sizeX = sizeY = 32; - break; - case 3: - sizeX = sizeY = 64; - break; - case 4: - sizeX = 16; - break; - case 5: - sizeX = 32; - break; - case 6: - sizeX = 32; - sizeY = 16; - break; - case 7: - sizeX = 64; - sizeY = 32; - break; - case 8: - sizeY = 16; - break; - case 9: - sizeY = 32; - break; - case 10: - sizeX = 16; - sizeY = 32; - break; - case 11: - sizeX = 32; - sizeY = 64; - break; - default: + lineOBJpixleft[x]=lineOBJpix; + + lineOBJpix-=2; + if (lineOBJpix<=0) continue; + + if ((a0 & 0x0c00) == 0x0c00) + a0 &=0xF3FF; + + if ((a0>>14) == 3) + { + a0 &= 0x3FFF; + a1 &= 0x3FFF; + } + + int sizeX = 8<<(a1>>14); + int sizeY = sizeX; + + if ((a0>>14) & 1) + { + if (sizeX<32) + sizeX<<=1; + if (sizeY>8) + sizeY>>=1; + } + else if ((a0>>14) & 2) + { + if (sizeX>8) + sizeX>>=1; + if (sizeY<32) + sizeY<<=1; } #ifdef SPRITE_DEBUG @@ -801,9 +788,45 @@ #endif int sy = (a0 & 255); + int sx = (a1 & 0x1FF); + + // computes ticks used by OBJ-WIN if OBJWIN is enabled + if (((a0 & 0x0c00) == 0x0800) && (layerEnable & 0x8000)) + { + if ((a0 & 0x0300) == 0x0300) + { + sizeX<<=1; + sizeY<<=1; + } + if((sy+sizeY) > 256) + sy -= 256; + if ((sx+sizeX)> 512) + sx-=512; + if (sx<0) + { + sizeX+=sx; + sx = 0; + } + else if ((sx+sizeX)>240) + sizeX=240-sx; + if ((VCOUNT>=sy) && (VCOUNT 160) - sy -= 256; if(a0 & 0x0100) { int fieldX = sizeX; @@ -812,11 +835,18 @@ fieldX <<= 1; fieldY <<= 1; } - + if((sy+fieldY) > 256) + sy -= 256; int t = VCOUNT - sy; if((t >= 0) && (t < fieldY)) { - int sx = (a1 & 0x1FF); - if((sx < 240) || (((sx + fieldX) & 511) < 240)) { + int startpix = 0; + if ((sx+fieldX)> 512) + { + startpix=512-sx; + } + if (lineOBJpix>0) + if((sx < 240) || startpix) { + lineOBJpix-=8; // int t2 = t - (fieldY >> 1); int rot = (a1 >> 9) & 0x1F; u16 *OAM = (u16 *)oam; @@ -854,6 +884,10 @@ else c &= 0x3FE; for(int x = 0; x < fieldX; x++) { + if (x >= startpix) + lineOBJpix-=2; + if (lineOBJpix<0) + continue; int xxx = realX >> 8; int yyy = realY >> 8; @@ -885,7 +919,7 @@ lineOBJ[sx] = 0x001F; #endif } - sx = (sx+1)&511;; + sx = (sx+1)&511; realX += dx; realY += dy; } @@ -897,8 +931,12 @@ int inc = 32; if(DISPCNT & 0x40) inc = sizeX >> 3; - int palette = (a2 >> 8) & 0xF0; + int palette = (a2 >> 8) & 0xF0; for(int x = 0; x < fieldX; x++) { + if (x >= startpix) + lineOBJpix-=2; + if (lineOBJpix<0) + continue; int xxx = realX >> 8; int yyy = realY >> 8; if(xxx < 0 || xxx >= sizeX || @@ -934,7 +972,7 @@ if(t == 0 || t == maskY || x == 0 || x == maskX) lineOBJ[sx] = 0x001F; #endif - sx = (sx+1)&511;; + sx = (sx+1)&511; realX += dx; realY += dy; @@ -943,10 +981,17 @@ } } } else { + if(sy+sizeY > 256) + sy -= 256; int t = VCOUNT - sy; if((t >= 0) && (t < sizeY)) { - int sx = (a1 & 0x1FF); - if(((sx < 240)||(((sx+sizeX)&511)<240)) && !(a0 & 0x0200)) { + int startpix = 0; + if ((sx+sizeX)> 512) + { + startpix=512-sx; + } + if((sx < 240) || startpix) { + lineOBJpix+=2; if(a0 & 0x2000) { if(a1 & 0x2000) t = sizeY - t - 1; @@ -976,6 +1021,10 @@ u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6); for(int xx = 0; xx < sizeX; xx++) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if ((color==0) && (((prio >> 25)&3) < @@ -1048,6 +1097,10 @@ if(a1 & 0x1000) { xxx = 7; for(int xx = sizeX - 1; xx >= 0; xx--) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if(xx & 1) { @@ -1088,6 +1141,10 @@ } } else { for(int xx = 0; xx < sizeX; xx++) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if(xx & 1) { @@ -1139,70 +1196,51 @@ inline void gfxDrawOBJWin(u32 *lineOBJWin) { gfxClearArray(lineOBJWin); - if(layerEnable & 0x8000) { + if((layerEnable & 0x9000) == 0x9000) { u16 *sprites = (u16 *)oam; // u16 *spritePalette = &((u16 *)paletteRAM)[256]; for(int x = 0; x < 128 ; x++) { + int lineOBJpix = lineOBJpixleft[x]; u16 a0 = READ16LE(sprites++); u16 a1 = READ16LE(sprites++); u16 a2 = READ16LE(sprites++); sprites++; - // ignore non OBJ-WIN - if((a0 & 0x0c00) != 0x0800) + if (lineOBJpix<=0) continue; + + // ignores non OBJ-WIN and disabled OBJ-WIN + if(((a0 & 0x0c00) != 0x0800) || ((a0 & 0x0300) == 0x0200)) + continue; + + if ((a0 & 0x0c00) == 0x0c00) + a0 &=0xF3FF; - int sizeY = 8; - int sizeX = 8; + if ((a0>>14) == 3) + { + a0 &= 0x3FFF; + a1 &= 0x3FFF; + } - switch(((a0 >>12) & 0x0c)|(a1>>14)) { - case 0: - break; - case 1: - sizeX = sizeY = 16; - break; - case 2: - sizeX = sizeY = 32; - break; - case 3: - sizeX = sizeY = 64; - break; - case 4: - sizeX = 16; - break; - case 5: - sizeX = 32; - break; - case 6: - sizeX = 32; - sizeY = 16; - break; - case 7: - sizeX = 64; - sizeY = 32; - break; - case 8: - sizeY = 16; - break; - case 9: - sizeY = 32; - break; - case 10: - sizeX = 16; - sizeY = 32; - break; - case 11: - sizeX = 32; - sizeY = 64; - break; - default: - continue; + int sizeX = 8<<(a1>>14); + int sizeY = sizeX; + + if ((a0>>14) & 1) + { + if (sizeX<32) + sizeX<<=1; + if (sizeY>8) + sizeY>>=1; + } + else if ((a0>>14) & 2) + { + if (sizeX>8) + sizeX>>=1; + if (sizeY<32) + sizeY<<=1; } int sy = (a0 & 255); - - if(sy > 160) - sy -= 256; if(a0 & 0x0100) { int fieldX = sizeX; @@ -1211,11 +1249,18 @@ fieldX <<= 1; fieldY <<= 1; } - + if((sy+fieldY) > 256) + sy -= 256; int t = VCOUNT - sy; if((t >= 0) && (t < fieldY)) { int sx = (a1 & 0x1FF); - if((sx < 240) || (((sx + fieldX) & 511) < 240)) { + int startpix = 0; + if ((sx+fieldX)> 512) + { + startpix=512-sx; + } + if((sx < 240) || startpix) { + lineOBJpix-=8; // int t2 = t - (fieldY >> 1); int rot = (a1 >> 9) & 0x1F; u16 *OAM = (u16 *)oam; @@ -1249,11 +1294,16 @@ else c &= 0x3FE; for(int x = 0; x < fieldX; x++) { + if (x >= startpix) + lineOBJpix-=2; + if (lineOBJpix<0) + continue; int xxx = realX >> 8; int yyy = realY >> 8; if(xxx < 0 || xxx >= sizeX || - yyy < 0 || yyy >= sizeY) { + yyy < 0 || yyy >= sizeY || + sx >= 240) { } else { u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5) + ((yyy & 7)<<3) + ((xxx >> 3)<<6) + @@ -1262,7 +1312,7 @@ lineOBJWin[sx] = 1; } } - sx = (sx+1)&511;; + sx = (sx+1)&511; realX += dx; realY += dy; } @@ -1276,6 +1326,10 @@ inc = sizeX >> 3; // int palette = (a2 >> 8) & 0xF0; for(int x = 0; x < fieldX; x++) { + if (x >= startpix) + lineOBJpix-=2; + if (lineOBJpix<0) + continue; int xxx = realX >> 8; int yyy = realY >> 8; @@ -1284,7 +1338,8 @@ // lineOBJ[sx] = 0x001F | prio; // } else { if(xxx < 0 || xxx >= sizeX || - yyy < 0 || yyy >= sizeY){ + yyy < 0 || yyy >= sizeY || + sx >= 240) { } else { u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5) + ((yyy & 7)<<2) + ((xxx >> 3)<<5) + @@ -1299,7 +1354,7 @@ } } // } - sx = (sx+1)&511;; + sx = (sx+1)&511; realX += dx; realY += dy; } @@ -1307,10 +1362,18 @@ } } } else { + if((sy+sizeY) > 256) + sy -= 256; int t = VCOUNT - sy; if((t >= 0) && (t < sizeY)) { int sx = (a1 & 0x1FF); - if(((sx < 240)||(((sx+sizeX)&511)<240)) && !(a0 & 0x0200)) { + int startpix = 0; + if ((sx+sizeX)> 512) + { + startpix=512-sx; + } + if((sx < 240) || startpix) { + lineOBJpix+=2; if(a0 & 0x2000) { if(a1 & 0x2000) t = sizeY - t - 1; @@ -1333,6 +1396,10 @@ xxx = 7; // u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6); for(int xx = 0; xx < sizeX; xx++) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if(color) { @@ -1382,6 +1449,10 @@ if(a1 & 0x1000) { xxx = 7; for(int xx = sizeX - 1; xx >= 0; xx--) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if(xx & 1) { @@ -1406,6 +1477,10 @@ } } else { for(int xx = 0; xx < sizeX; xx++) { + if (xx >= startpix) + lineOBJpix--; + if (lineOBJpix<0) + continue; if(sx < 240) { u8 color = vram[address]; if(xx & 1) { @@ -1528,10 +1603,10 @@ int g0 = ((color2 >> 5) & 0x1F); int b0 = ((color2 >> 10) & 0x1F); - r = ((r * ca) >> 4) + ((r0 * cb) >> 4); - g = ((g * ca) >> 4) + ((g0 * cb) >> 4); - b = ((b * ca) >> 4) + ((b0 * cb) >> 4); - + r = ((r * ca) + (r0 * cb)) >> 4; + g = ((g * ca) + (g0 * cb)) >> 4; + b = ((b * ca) + (b0 * cb)) >> 4; + if(r > 31) r = 31; if(g > 31) @@ -1557,9 +1632,9 @@ int g0 = ((color2 >> 5) & 0x1F); int b0 = ((color2 >> 10) & 0x1F); - r = ((r * ca) >> 4) + ((r0 * cb) >> 4); - g = ((g * ca) >> 4) + ((g0 * cb) >> 4); - b = ((b * ca) >> 4) + ((b0 * cb) >> 4); + r = ((r * ca) + (r0 * cb)) >> 4; + g = ((g * ca) + (g0 * cb)) >> 4; + b = ((b * ca) + (b0 * cb)) >> 4; if(r > 31) r = 31; diff -urN ../VisualBoyAdvance-1.7.2/src/Globals.cpp ./src/Globals.cpp --- ../VisualBoyAdvance-1.7.2/src/Globals.cpp 2004-05-13 23:37:29 +0900 +++ ./src/Globals.cpp 2006-08-01 00:51:01 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,6 +18,11 @@ #include "GBA.h" +#ifdef BKPT_SUPPORT +int oldreg[17]; +char oldbuffer[10]; +#endif + reg_pair reg[45]; memoryMap map[256]; bool ioReadable[0x400]; @@ -43,8 +48,8 @@ int layerEnable = 0xff00; bool speedHack = false; int cpuSaveType = 0; -bool cpuEnhancedDetection = true; bool cheatsEnabled = true; +bool mirroringEnable = false; u8 *bios = NULL; u8 *rom = NULL; diff -urN ../VisualBoyAdvance-1.7.2/src/Globals.h ./src/Globals.h --- ../VisualBoyAdvance-1.7.2/src/Globals.h 2004-05-13 23:04:03 +0900 +++ ./src/Globals.h 2006-08-01 00:51:01 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,6 +20,8 @@ #ifndef VBA_GLOBALS_H #define VBA_GLOBALS_H +#include "GBA.h" + #define VERBOSE_SWI 1 #define VERBOSE_UNALIGNED_MEMORY 2 #define VERBOSE_ILLEGAL_WRITE 4 @@ -55,8 +57,8 @@ extern int layerEnable; extern bool speedHack; extern int cpuSaveType; -extern bool cpuEnhancedDetection; extern bool cheatsEnabled; +extern bool mirroringEnable; extern u8 *bios; extern u8 *rom; diff -urN ../VisualBoyAdvance-1.7.2/src/Makefile.in ./src/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/Makefile.in 2004-05-21 03:17:48 +0900 +++ ./src/Makefile.in 2004-09-30 07:23:29 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/NLS.h ./src/NLS.h --- ../VisualBoyAdvance-1.7.2/src/NLS.h 2004-05-13 23:03:44 +0900 +++ ./src/NLS.h 2006-06-07 00:19:25 +0900 @@ -60,3 +60,5 @@ #define MSG_INVALID_CBA_CODE 39 #define MSG_CBA_CODE_WARNING 40 #define MSG_OUT_OF_MEMORY 41 +#define MSG_WRONG_GAMESHARK_CODE 42 +#define MSG_UNSUPPORTED_GAMESHARK_CODE 43 diff -urN ../VisualBoyAdvance-1.7.2/src/RTC.cpp ./src/RTC.cpp --- ../VisualBoyAdvance-1.7.2/src/RTC.cpp 2004-05-13 23:36:17 +0900 +++ ./src/RTC.cpp 2006-01-04 22:42:59 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -119,6 +119,8 @@ rtcClockData.data[0] = 0x40; rtcClockData.state = DATA; break; + case 0x64: + break; case 0x65: { struct tm *newtime; @@ -131,7 +133,7 @@ rtcClockData.data[0] = toBCD(newtime->tm_year); rtcClockData.data[1] = toBCD(newtime->tm_mon+1); rtcClockData.data[2] = toBCD(newtime->tm_mday); - rtcClockData.data[3] = 0; + rtcClockData.data[3] = toBCD(newtime->tm_wday); rtcClockData.data[4] = toBCD(newtime->tm_hour); rtcClockData.data[5] = toBCD(newtime->tm_min); rtcClockData.data[6] = toBCD(newtime->tm_sec); diff -urN ../VisualBoyAdvance-1.7.2/src/Sound.cpp ./src/Sound.cpp --- ../VisualBoyAdvance-1.7.2/src/Sound.cpp 2004-05-13 23:36:07 +0900 +++ ./src/Sound.cpp 2006-08-25 22:30:08 +0900 @@ -1,6 +1,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,15 +19,16 @@ #include +#include "Sound.h" + #include "GBA.h" #include "Globals.h" -#include "Sound.h" #include "Util.h" #define USE_TICKS_AS 380 #define SOUND_MAGIC 0x60000000 #define SOUND_MAGIC_2 0x30000000 -#define NOISE_MAGIC 5 +#define NOISE_MAGIC 5 extern bool stopState; @@ -387,8 +389,8 @@ sound2Index = 0; sound2On = 1; } - break; - ioMem[address] = data; + ioMem[address] = data; + break; case NR30: data &= 0xe0; if(!(data & 0x80)) { @@ -541,7 +543,7 @@ switch(address) { case SGCNT0_H: data &= 0xFF0F; - soundControl = data & 0x770F;; + soundControl = data & 0x770F; if(data & 0x0800) { soundDSFifoAWriteIndex = 0; soundDSFifoAIndex = 0; @@ -560,7 +562,7 @@ } soundDSBEnabled = (data & 0x3000) ? true : false; soundDSBTimer = (data & 0x4000) ? 1 : 0; - *((u16 *)&ioMem[address]) = data; + *((u16 *)&ioMem[address]) = soundControl; break; case FIFOA_L: case FIFOA_H: @@ -865,7 +867,7 @@ } soundDSAValue = (soundDSFifoA[soundDSFifoAIndex]); - soundDSFifoAIndex = (++soundDSFifoAIndex) & 31; + soundDSFifoAIndex = (soundDSFifoAIndex + 1) & 31; soundDSFifoACount--; } else soundDSAValue = 0; @@ -894,7 +896,7 @@ } soundDSBValue = (soundDSFifoB[soundDSFifoBIndex]); - soundDSFifoBIndex = (++soundDSFifoBIndex) & 31; + soundDSFifoBIndex = (soundDSFifoBIndex + 1) & 31; soundDSFifoBCount--; } else { soundDSBValue = 0; diff -urN ../VisualBoyAdvance-1.7.2/src/Sound.h ./src/Sound.h --- ../VisualBoyAdvance-1.7.2/src/Sound.h 2004-05-13 23:03:07 +0900 +++ ./src/Sound.h 2006-06-07 06:04:20 +0900 @@ -2,6 +2,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,6 +21,8 @@ #ifndef VBA_SOUND_H #define VBA_SOUND_H +#include "System.h" + #define NR10 0x60 #define NR11 0x62 #define NR12 0x63 @@ -47,23 +50,22 @@ #define FIFOB_L 0xa4 #define FIFOB_H 0xa6 -extern void soundTick(); -extern void soundShutdown(); -extern bool soundInit(); -extern void soundPause(); -extern void soundResume(); -extern void soundEnable(int); -extern void soundDisable(int); -extern int soundGetEnable(); -extern void soundReset(); -extern void soundSaveGame(gzFile); -extern void soundReadGame(gzFile, int); -extern void soundEvent(u32, u8); -extern void soundEvent(u32, u16); -extern void soundTimerOverflow(int); -extern void soundSetQuality(int); +void soundTick(); +void soundShutdown(); +bool soundInit(); +void soundPause(); +void soundResume(); +void soundEnable(int); +void soundDisable(int); +int soundGetEnable(); +void soundReset(); +void soundSaveGame(gzFile); +void soundReadGame(gzFile, int); +void soundEvent(u32, u8); +void soundEvent(u32, u16); +void soundTimerOverflow(int); +void soundSetQuality(int); -//extern int SOUND_TICKS; extern int SOUND_CLOCK_TICKS; extern int soundTicks; extern int soundPaused; diff -urN ../VisualBoyAdvance-1.7.2/src/Sram.cpp ./src/Sram.cpp --- ../VisualBoyAdvance-1.7.2/src/Sram.cpp 2004-05-13 23:35:57 +0900 +++ ./src/Sram.cpp 2004-11-15 03:54:14 +0900 @@ -17,6 +17,7 @@ // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "GBA.h" +#include "Globals.h" #include "Flash.h" #include "Sram.h" @@ -24,6 +25,12 @@ { return flashSaveMemory[address & 0xFFFF]; } +void sramDelayedWrite(u32 address, u8 byte) +{ + saveType = 1; + cpuSaveGameFunc = sramWrite; + sramWrite(address, byte); +} void sramWrite(u32 address, u8 byte) { diff -urN ../VisualBoyAdvance-1.7.2/src/Sram.h ./src/Sram.h --- ../VisualBoyAdvance-1.7.2/src/Sram.h 2004-05-13 23:02:56 +0900 +++ ./src/Sram.h 2004-11-15 03:54:14 +0900 @@ -22,5 +22,6 @@ extern u8 sramRead(u32 address); extern void sramWrite(u32 address, u8 byte); +extern void sramDelayedWrite(u32 address, u8 byte); #endif // VBA_SRAM_H diff -urN ../VisualBoyAdvance-1.7.2/src/System.h ./src/System.h --- ../VisualBoyAdvance-1.7.2/src/System.h 2004-05-13 23:02:43 +0900 +++ ./src/System.h 2006-06-22 01:58:15 +0900 @@ -106,6 +106,12 @@ extern void systemFrame(); extern void systemGbBorderOn(); +extern void Sm60FPS_Init(); +extern bool Sm60FPS_CanSkipFrame(); +extern void Sm60FPS_Sleep(); +extern void DbgMsg(const char *msg, ...); +extern void winlog(const char *,...); + extern bool systemSoundOn; extern u16 systemColorMap16[0x10000]; extern u32 systemColorMap32[0x10000]; @@ -118,6 +124,7 @@ extern int systemVerbose; extern int systemFrameSkip; extern int systemSaveUpdateCounter; +extern int systemSpeed; #define SYSTEM_SAVE_UPDATED 30 #define SYSTEM_SAVE_NOT_UPDATED 0 diff -urN ../VisualBoyAdvance-1.7.2/src/Util.cpp ./src/Util.cpp --- ../VisualBoyAdvance-1.7.2/src/Util.cpp 2004-05-21 02:42:37 +0900 +++ ./src/Util.cpp 2006-05-27 23:47:32 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -47,9 +47,17 @@ #define _stricmp strcasecmp #endif // ! _MSC_VER -static int (*utilGzWriteFunc)(gzFile, const voidp, unsigned int) = NULL; -static int (*utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL; -static int (*utilGzCloseFunc)(gzFile) = NULL; +extern int systemColorDepth; +extern int systemRedShift; +extern int systemGreenShift; +extern int systemBlueShift; + +extern u16 systemColorMap16[0x10000]; +extern u32 systemColorMap32[0x10000]; + +static int (ZEXPORT *utilGzWriteFunc)(gzFile, const voidp, unsigned int) = NULL; +static int (ZEXPORT *utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL; +static int (ZEXPORT *utilGzCloseFunc)(gzFile) = NULL; bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix) { @@ -478,7 +486,7 @@ { cpuIsMultiBoot = false; if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".gba") == 0) @@ -502,7 +510,7 @@ bool utilIsGBImage(const char * file) { if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".gb") == 0) @@ -522,7 +530,7 @@ bool utilIsZipFile(const char *file) { if(strlen(file) > 4) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".zip") == 0) @@ -552,7 +560,7 @@ bool utilIsGzipFile(const char *file) { if(strlen(file) > 3) { - char * p = strrchr(file,'.'); + const char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".gz") == 0) @@ -937,11 +945,11 @@ } size = fileSize; } - int read = fileSize <= size ? fileSize : size; - int r = fread(image, 1, read, f); + size_t read = fileSize <= size ? fileSize : size; + size_t r = fread(image, 1, read, f); fclose(f); - if(r != (int)read) { + if(r != read) { systemMessage(MSG_ERROR_READING_IMAGE, N_("Error reading image %s"), file); if(data == NULL) @@ -984,7 +992,7 @@ gzFile utilGzOpen(const char *file, const char *mode) { - utilGzWriteFunc = (int (*)(void *,void * const, unsigned int))gzwrite; + utilGzWriteFunc = (int (ZEXPORT *)(void *,void * const, unsigned int))gzwrite; utilGzReadFunc = gzread; utilGzCloseFunc = gzclose; @@ -1034,22 +1042,22 @@ if(d == 0x52504545) { if(memcmp(p, "EEPROM_", 7) == 0) { if(saveType == 0) - saveType = 1; + saveType = 3; } } else if (d == 0x4D415253) { if(memcmp(p, "SRAM_", 5) == 0) { if(saveType == 0) - saveType = 2; + saveType = 1; } } else if (d == 0x53414C46) { if(memcmp(p, "FLASH1M_", 8) == 0) { if(saveType == 0) { - saveType = 3; + saveType = 2; flashSize = 0x20000; } } else if(memcmp(p, "FLASH", 5) == 0) { if(saveType == 0) { - saveType = 3; + saveType = 2; flashSize = 0x10000; } } @@ -1067,3 +1075,28 @@ cpuSaveType = saveType; flashSetSize(flashSize); } + +void utilUpdateSystemColorMaps() +{ + switch(systemColorDepth) { + case 16: + { + for(int i = 0; i < 0x10000; i++) { + systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | + (((i & 0x3e0) >> 5) << systemGreenShift) | + (((i & 0x7c00) >> 10) << systemBlueShift); + } + } + break; + case 24: + case 32: + { + for(int i = 0; i < 0x10000; i++) { + systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | + (((i & 0x3e0) >> 5) << systemGreenShift) | + (((i & 0x7c00) >> 10) << systemBlueShift); + } + } + break; + } +} diff -urN ../VisualBoyAdvance-1.7.2/src/Util.h ./src/Util.h --- ../VisualBoyAdvance-1.7.2/src/Util.h 2004-05-13 23:02:08 +0900 +++ ./src/Util.h 2004-09-16 07:12:52 +0900 @@ -61,4 +61,5 @@ extern int utilGzClose(gzFile file); extern long utilGzMemTell(gzFile file); extern void utilGBAFindSave(const u8 *, const int); +extern void utilUpdateSystemColorMaps(); #endif diff -urN ../VisualBoyAdvance-1.7.2/src/arm-new.h ./src/arm-new.h --- ../VisualBoyAdvance-1.7.2/src/arm-new.h 2004-05-13 22:57:11 +0900 +++ ./src/arm-new.h 2006-08-25 22:30:08 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -1113,26 +1113,34 @@ bool C_OUT = C_FLAG;\ u32 value;\ \ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_LSL_REG\ } else {\ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1148,6 +1156,12 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_LSR_REG\ } else {\ @@ -1156,20 +1170,22 @@ }\ \ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1185,6 +1201,12 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ASR_REG\ } else {\ @@ -1198,20 +1220,22 @@ }\ \ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1227,26 +1251,34 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ROR_REG\ } else {\ LOGICAL_RRX_REG\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1256,12 +1288,17 @@ case BASE+1:\ {\ /* OP Rd,Rb,Rm LSL Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -1276,20 +1313,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1299,12 +1338,17 @@ case BASE+3:\ {\ /* OP Rd,Rb,Rm LSR Rs */ \ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -1319,20 +1363,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1342,12 +1388,17 @@ case BASE+5:\ {\ /* OP Rd,Rb,Rm ASR Rs */ \ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift < 32) {\ if(shift) {\ LOGICAL_ASR_REG\ @@ -1364,20 +1415,22 @@ }\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1387,12 +1440,17 @@ case BASE+7:\ {\ /* OP Rd,Rb,Rm ROR Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ shift &= 0x1f;\ if(shift) {\ @@ -1406,20 +1464,22 @@ C_OUT = (value & 0x80000000 ? true : false);\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1448,26 +1508,34 @@ int dest = (opcode >> 12) & 0x0F;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ROR_IMM\ } else {\ value = opcode & 0xff;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1484,6 +1552,12 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ \ if(shift) {\ LOGICAL_LSL_REG\ @@ -1491,20 +1565,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1519,6 +1595,12 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_LSR_REG\ } else {\ @@ -1527,20 +1609,22 @@ }\ \ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1555,6 +1639,12 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ASR_REG\ } else {\ @@ -1568,20 +1658,22 @@ }\ \ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1596,26 +1688,34 @@ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ROR_REG\ } else {\ LOGICAL_RRX_REG\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1625,11 +1725,16 @@ case BASE+1:\ {\ /* OP Rd,Rb,Rm LSL Rs */\ - clockTicks++;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -1644,20 +1749,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1667,11 +1774,16 @@ case BASE+3:\ {\ /* OP Rd,Rb,Rm LSR Rs */ \ - clockTicks++;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -1686,20 +1798,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1709,11 +1823,16 @@ case BASE+5:\ {\ /* OP Rd,Rb,Rm ASR Rs */ \ - clockTicks++;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift < 32) {\ if(shift) {\ LOGICAL_ASR_REG\ @@ -1730,20 +1849,22 @@ }\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1753,11 +1874,16 @@ case BASE+7:\ {\ /* OP Rd,Rb,Rm ROR Rs */\ - clockTicks++;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ shift &= 0x1f;\ if(shift) {\ @@ -1771,20 +1897,22 @@ C_OUT = (value & 0x80000000 ? true : false);\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1812,26 +1940,34 @@ int dest = (opcode >> 12) & 0x0F;\ bool C_OUT = C_FLAG;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ LOGICAL_ROR_IMM\ } else {\ value = opcode & 0xff;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1848,26 +1984,34 @@ int shift = (opcode >> 7) & 0x1F;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ ARITHMETIC_LSL_REG\ } else {\ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1882,26 +2026,34 @@ int shift = (opcode >> 7) & 0x1F;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ ARITHMETIC_LSR_REG\ } else {\ value = 0;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1916,6 +2068,12 @@ int shift = (opcode >> 7) & 0x1F;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ ARITHMETIC_ASR_REG\ } else {\ @@ -1924,20 +2082,22 @@ } else value = 0;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1952,26 +2112,34 @@ int shift = (opcode >> 7) & 0x1F;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ ARITHMETIC_ROR_REG\ } else {\ ARITHMETIC_RRX_REG\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -1981,11 +2149,16 @@ case BASE+1:\ {\ /* OP Rd,Rb,Rm LSL Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -1996,20 +2169,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -2019,11 +2194,16 @@ case BASE+3:\ {\ /* OP Rd,Rb,Rm LSR Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ if(shift == 32) {\ value = 0;\ @@ -2034,20 +2214,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -2057,11 +2239,16 @@ case BASE+5:\ {\ /* OP Rd,Rb,Rm ASR Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift < 32) {\ if(shift) {\ ARITHMETIC_ASR_REG\ @@ -2074,20 +2261,22 @@ } else value = 0;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -2097,11 +2286,16 @@ case BASE+7:\ {\ /* OP Rd,Rb,Rm ROR Rs */\ - clockTicks++;\ int base = (opcode >> 16) & 0x0F;\ int shift = reg[(opcode >> 8)&15].B.B0;\ int dest = (opcode>>12) & 15;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ if(shift) {\ shift &= 0x1f;\ if(shift) {\ @@ -2113,20 +2307,22 @@ value = reg[opcode & 0x0F].I;\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -2154,24 +2350,32 @@ int base = (opcode >> 16) & 0x0F;\ int dest = (opcode >> 12) & 0x0F;\ u32 value;\ + if ((dest == 15)||((opcode & 0x02000010)==0x10))\ + {\ + clockTicks = 1+codeTicksAccess32(armNextPC);\ + if ((opcode & 0x02000010)==0x10)\ + clockTicks++;\ + }\ {\ ARITHMETIC_ROR_IMM\ }\ if(dest == 15) {\ + clockTicks+=2+codeTicksAccessSeq32(armNextPC)+codeTicksAccessSeq32(armNextPC);\ OPCODE2\ /* todo */\ if(opcode & 0x00100000) {\ - clockTicks++;\ CPUSwitchMode(reg[17].I & 0x1f, false);\ }\ if(armState) {\ reg[15].I &= 0xFFFFFFFC;\ armNextPC = reg[15].I;\ reg[15].I += 4;\ + ARM_PREFETCH;\ } else {\ reg[15].I &= 0xFFFFFFFE;\ armNextPC = reg[15].I;\ reg[15].I += 2;\ + THUMB_PREFETCH;\ }\ } else {\ OPCODE \ @@ -2179,9 +2383,16 @@ }\ break; - u32 opcode = CPUReadMemoryQuick(armNextPC); + u32 opcode = cpuPrefetch[0]; + cpuPrefetch[0] = cpuPrefetch[1]; + + busPrefetch = false; + if (busPrefetchCount & 0xFFFFFE00) + busPrefetchCount = 0x100 | (busPrefetchCount & 0xFF); - clockTicks = memoryWaitFetch32[(armNextPC >> 24) & 15]; + + clockTicks = 0;//codeTicksAccessSeq32(armNextPC)+1; + int oldArmNextPC = armNextPC; #ifndef FINAL_VERSION if(armNextPC == stop) { @@ -2191,6 +2402,8 @@ armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH_NEXT; + int cond = opcode >> 28; // suggested optimization for frequent cases bool cond_res; @@ -2260,18 +2473,23 @@ // MUL Rd, Rm, Rs int dest = (opcode >> 16) & 0x0F; int mult = (opcode & 0x0F); + clockTicks = 1; u32 rs = reg[(opcode >> 8) & 0x0F].I; reg[dest].I = reg[mult].I * rs; if(((s32)rs)<0) - rs = ~rs; + rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if ((rs & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if ((rs & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 16) & 0x0F; int mult = (opcode & 0x0F); + clockTicks = 1; u32 rs = reg[(opcode >> 8) & 0x0F].I; reg[dest].I = reg[mult].I * rs; N_FLAG = (reg[dest].I & 0x80000000) ? true : false; @@ -2286,24 +2505,30 @@ if(((s32)rs)<0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if ((rs & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if ((rs & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); address -= offset; reg[base].I = address; @@ -2313,11 +2538,14 @@ case 0x06b: { // STRH Rd, [Rn], #-offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); address -= offset; reg[base].I = address; @@ -2327,11 +2555,14 @@ case 0x0ab: { // STRH Rd, [Rn], Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); address += offset; reg[base].I = address; @@ -2341,11 +2572,14 @@ case 0x0eb: { // STRH Rd, [Rn], #offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); address += offset; reg[base].I = address; @@ -2354,20 +2588,26 @@ case 0x10b: { // STRH Rd, [Rn, -Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); } break; case 0x12b: { // STRH Rd, [Rn, -Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); reg[base].I = address; } @@ -2375,20 +2615,26 @@ case 0x14b: { // STRH Rd, [Rn, -#offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); } break; case 0x16b: { // STRH Rd, [Rn, -#offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); reg[base].I = address; } @@ -2396,20 +2642,26 @@ case 0x18b: { // STRH Rd, [Rn, Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); } break; case 0x1ab: { // STRH Rd, [Rn, Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); reg[base].I = address; } @@ -2417,20 +2669,26 @@ case 0x1cb: { // STRH Rd, [Rn, #offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); } break; case 0x1eb: { // STRH Rd, [Rn, #offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 4 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); CPUWriteHalfWord(address, reg[dest].W.W0); reg[base].I = address; } @@ -2439,456 +2697,852 @@ case 0x03b: { // LDRH Rd, [Rn], -Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x05b: case 0x07b: { // LDRH Rd, [Rn], #-offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks=0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x09b: case 0x0bb: { // LDRH Rd, [Rn], Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x0db: case 0x0fb: { // LDRH Rd, [Rn], #offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x11b: { // LDRH Rd, [Rn, -Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x13b: { // LDRH Rd, [Rn, -Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x15b: { // LDRH Rd, [Rn, -#offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x17b: { // LDRH Rd, [Rn, -#offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x19b: { // LDRH Rd, [Rn, Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1bb: { // LDRH Rd, [Rn, Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1db: { // LDRH Rd, [Rn, #offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1fb: { // LDRH Rd, [Rn, #offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = CPUReadHalfWord(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x01d: case 0x03d: { // LDRSB Rd, [Rn], -Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x05d: case 0x07d: { // LDRSB Rd, [Rn], #-offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x09d: case 0x0bd: { // LDRSB Rd, [Rn], Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x0dd: case 0x0fd: { // LDRSB Rd, [Rn], #offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x11d: { // LDRSB Rd, [Rn, -Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x13d: { // LDRSB Rd, [Rn, -Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x15d: { // LDRSB Rd, [Rn, -#offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x17d: { // LDRSB Rd, [Rn, -#offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x19d: { // LDRSB Rd, [Rn, Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1bd: { // LDRSB Rd, [Rn, Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1dd: { // LDRSB Rd, [Rn, #offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1fd: { // LDRSB Rd, [Rn, #offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s8)CPUReadByte(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x01f: case 0x03f: { // LDRSH Rd, [Rn], -Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x05f: case 0x07f: { // LDRSH Rd, [Rn], #-offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) { address -= offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x09f: case 0x0bf: { // LDRSH Rd, [Rn], Rm + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x0df: case 0x0ff: { // LDRSH Rd, [Rn], #offset + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I; int offset = (opcode & 0x0F) | ((opcode >> 4) & 0xF0); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) { address += offset; reg[base].I = address; } + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x11f: { // LDRSH Rd, [Rn, -Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x13f: { // LDRSH Rd, [Rn, -Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x15f: { // LDRSH Rd, [Rn, -#offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x17f: { // LDRSH Rd, [Rn, -#offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I - ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x19f: { // LDRSH Rd, [Rn, Rm] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1bf: { // LDRSH Rd, [Rn, Rm]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + reg[opcode & 0x0F].I; - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1df: { // LDRSH Rd, [Rn, #offset] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x1ff: { // LDRSH Rd, [Rn, #offset]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode >> 16) & 0x0F; int dest = (opcode >> 12) & 0x0F; u32 address = reg[base].I + ((opcode & 0x0F)|((opcode>>4)&0xF0)); - clockTicks += 3 + CPUUpdateTicksAccess16(address); reg[dest].I = (s16)CPUReadHalfWordSigned(address); if(dest != base) reg[base].I = address; + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; LOGICAL_DATA_OPCODE_WITHOUT_base(OP_EOR, OP_EOR, 0x020); @@ -2896,25 +3550,28 @@ case 0x029: { // MLA Rd, Rm, Rs, Rn + clockTicks = 2; int dest = (opcode >> 16) & 0x0F; int mult = (opcode & 0x0F); u32 rs = reg[(opcode >> 8) & 0x0F].I; reg[dest].I = reg[mult].I * rs + reg[(opcode>>12)&0x0f].I; - if(((s32)rs)<0) - rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if ((rs & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if ((rs & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 16) & 0x0F; int mult = (opcode & 0x0F); u32 rs = reg[(opcode >> 8) & 0x0F].I; @@ -2924,13 +3581,16 @@ if(((s32)rs)<0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if ((rs & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if ((rs & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 8) & 0x0F].I; int destLo = (opcode >> 12) & 0x0F; @@ -2950,18 +3611,22 @@ reg[destLo].I = (u32)uTemp; reg[destHi].I = (u32)(uTemp >> 32); if ((usource & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if ((usource & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if ((usource & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 8) & 0x0F].I; int destLo = (opcode >> 12) & 0x0F; @@ -2972,13 +3637,16 @@ Z_FLAG = (uTemp) ? false : true; N_FLAG = (reg[destHi].I & 0x80000000) ? true : false; if ((usource & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if ((usource & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if ((usource & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 8) & 0x0F].I; int destLo = (opcode >> 12) & 0x0F; @@ -2997,18 +3666,22 @@ reg[destLo].I = (u32)uTemp; reg[destHi].I = (u32)(uTemp >> 32); if ((usource & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if ((usource & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if ((usource & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 8) & 0x0F].I; int destLo = (opcode >> 12) & 0x0F; @@ -3022,13 +3695,16 @@ Z_FLAG = (uTemp) ? false : true; N_FLAG = (reg[destHi].I & 0x80000000) ? true : false; if ((usource & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if ((usource & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if ((usource & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 12) & 0x0F; int destHi = (opcode >> 16) & 0x0F; u32 rs = reg[(opcode >> 8) & 0x0F].I; @@ -3047,18 +3724,22 @@ if(((s32)rs) < 0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if((rs & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if((rs & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 12) & 0x0F; int destHi = (opcode >> 16) & 0x0F; u32 rs = reg[(opcode >> 8) & 0x0F].I; @@ -3072,13 +3753,16 @@ if(((s32)rs) < 0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 2; + clockTicks += 0; else if((rs & 0xFFFF0000) == 0) - clockTicks += 3; + clockTicks += 1; else if((rs & 0xFF000000) == 0) - clockTicks += 4; + clockTicks += 2; else - clockTicks += 5; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 12) & 0x0F; int destHi = (opcode >> 16) & 0x0F; u32 rs = reg[(opcode >> 8) & 0x0F].I; @@ -3100,18 +3785,21 @@ if(((s32)rs) < 0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if((rs & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if((rs & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 12) & 0x0F; int destHi = (opcode >> 16) & 0x0F; u32 rs = reg[(opcode >> 8) & 0x0F].I; @@ -3128,13 +3816,15 @@ if(((s32)rs) < 0) rs = ~rs; if((rs & 0xFFFFFF00) == 0) - clockTicks += 3; + clockTicks += 0; else if((rs & 0xFFFF0000) == 0) - clockTicks += 4; + clockTicks += 1; else if((rs & 0xFF000000) == 0) - clockTicks += 5; + clockTicks += 2; else - clockTicks += 6; + clockTicks += 3; + if (!busPrefetchCount) + busPrefetchCount = ((++busPrefetchCount)<> 12) & 15].I = temp; + clockTicks = 4 + dataTicksAccess32(address) + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; LOGICAL_DATA_OPCODE(OP_TEQ, OP_TEQ, 0x130); @@ -3174,23 +3866,33 @@ CPUSwitchMode(newValue & 0x1f, false); reg[16].I = newValue; CPUUpdateFlags(); + if(!armState) { // this should not be allowed, but it seems to work + THUMB_PREFETCH; + reg[15].I = armNextPC + 2; + } } break; case 0x121: { // BX Rm // TODO: check if right instruction... - clockTicks += 3; int base = opcode & 0x0F; + busPrefetchCount=0; armState = reg[base].I & 1 ? false : true; if(armState) { reg[15].I = reg[base].I & 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks = codeTicksAccessSeq32(armNextPC) + + codeTicksAccessSeq32(armNextPC) + codeTicksAccess32(armNextPC) + 3; } else { reg[15].I = reg[base].I & 0xFFFFFFFE; armNextPC = reg[15].I; reg[15].I += 2; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC) + + codeTicksAccessSeq16(armNextPC) + codeTicksAccess16(armNextPC) + 3; } } break; @@ -3207,6 +3909,8 @@ u32 temp = CPUReadByte(address); CPUWriteByte(address, reg[opcode&15].B.B0); reg[(opcode>>12)&15].I = temp; + clockTicks = 4 + dataTicksAccess32(address) + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; ARITHMETIC_DATA_OPCODE(OP_CMN, OP_CMN, 0x170); @@ -3284,6 +3988,10 @@ CPUSwitchMode(newValue & 0x1f, false); reg[16].I = newValue; CPUUpdateFlags(); + if(!armState) { // this should not be allowed, but it seems to work + THUMB_PREFETCH; + reg[15].I = armNextPC + 2; + } } break; case 0x360: @@ -3326,13 +4034,16 @@ CASE_16(0x420) { // STR Rd, [Rn], -# + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x480) @@ -3340,64 +4051,81 @@ CASE_16(0x4a0) { // STR Rd, [Rn], # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x500) { // STR Rd, [Rn, -#] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x520) { // STR Rd, [Rn, -#]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x580) { // STR Rd, [Rn, #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5a0) { // STR Rd, [Rn, #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x410) { // LDR Rd, [Rn], -# + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3405,18 +4133,23 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I -= offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x430) { // LDRT Rd, [Rn], -# + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3424,12 +4157,23 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I -= offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x490) { // LDR Rd, [Rn], # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3437,18 +4181,23 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I += offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x4b0) { // LDRT Rd, [Rn], # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3456,29 +4205,45 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I += offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x510) { // LDR Rd, [Rn, -#] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x530) { // LDR Rd, [Rn, -#]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3486,35 +4251,45 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } - } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); + } break; CASE_16(0x590) { // LDR Rd, [Rn, #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5b0) { // LDR Rd, [Rn, #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3522,13 +4297,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x440) @@ -3536,73 +4314,91 @@ CASE_16(0x460) { // STRB Rd, [Rn], -# + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x4c0) // T versions shouldn't be different on GBA CASE_16(0x4e0) - // STRB Rd, [Rn], # { + // STRB Rd, [Rn], # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x540) { // STRB Rd, [Rn, -#] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x560) { // STRB Rd, [Rn, -#]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5c0) { // STRB Rd, [Rn, #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5e0) { // STRB Rd, [Rn, #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteByte(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x450) @@ -3610,6 +4406,8 @@ CASE_16(0x470) { // LDRB Rd, [Rn], -# + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3617,13 +4415,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I -= offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x4d0) CASE_16(0x4f0) // T versions should not be different { // LDRB Rd, [Rn], # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3631,23 +4440,45 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I += offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x550) { // LDRB Rd, [Rn, -#] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x570) { // LDRB Rd, [Rn, -#]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3655,23 +4486,45 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5d0) { // LDRB Rd, [Rn, #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; CASE_16(0x5f0) { // LDRB Rd, [Rn, #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = opcode & 0xFFF; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -3679,7 +4532,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x600: @@ -3689,13 +4551,16 @@ case 0x628: { // STR Rd, [Rn], -Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x602: @@ -3705,6 +4570,8 @@ case 0x62a: { // STR Rd, [Rn], -Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -3712,7 +4579,8 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x604: @@ -3722,6 +4590,8 @@ case 0x62c: { // STR Rd, [Rn], -Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -3735,7 +4605,8 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x606: @@ -3745,6 +4616,8 @@ case 0x62e: { // STR Rd, [Rn], -Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -3757,7 +4630,8 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address - value; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x680: @@ -3767,13 +4641,16 @@ case 0x6a8: { // STR Rd, [Rn], Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x682: @@ -3783,6 +4660,8 @@ case 0x6aa: { // STR Rd, [Rn], Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -3790,7 +4669,8 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x684: @@ -3800,6 +4680,8 @@ case 0x6ac: { // STR Rd, [Rn], Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -3813,7 +4695,8 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x686: @@ -3823,6 +4706,8 @@ case 0x6ae: { // STR Rd, [Rn], Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -3835,38 +4720,47 @@ u32 address = reg[base].I; CPUWriteMemory(address, reg[dest].I); reg[base].I = address + value; - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x700: case 0x708: { // STR Rd, [Rn, -Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x702: case 0x70a: { // STR Rd, [Rn, -Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x704: case 0x70c: { // STR Rd, [Rn, -Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -3879,13 +4773,16 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x706: case 0x70e: { // STR Rd, [Rn, -Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -3897,26 +4794,32 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - value; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x720: case 0x728: { // STR Rd, [Rn, -Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x722: case 0x72a: { // STR Rd, [Rn, -Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -3924,13 +4827,16 @@ u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x724: case 0x72c: { // STR Rd, [Rn, -Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -3944,13 +4850,16 @@ u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x726: case 0x72e: { // STR Rd, [Rn, -Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -3963,38 +4872,47 @@ u32 address = reg[base].I - value; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x780: case 0x788: { // STR Rd, [Rn, Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x782: case 0x78a: { // STR Rd, [Rn, Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x784: case 0x78c: { // STR Rd, [Rn, Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4007,13 +4925,16 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x786: case 0x78e: { // STR Rd, [Rn, Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4025,26 +4946,32 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + value; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7a0: case 0x7a8: { // STR Rd, [Rn, Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7a2: case 0x7aa: { // STR Rd, [Rn, Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4052,13 +4979,16 @@ u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7a4: case 0x7ac: { // STR Rd, [Rn, Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4072,13 +5002,16 @@ u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7a6: case 0x7ae: { // STR Rd, [Rn, Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4091,7 +5024,8 @@ u32 address = reg[base].I + value; reg[base].I = address; CPUWriteMemory(address, reg[dest].I); - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks = 2 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x610: @@ -4101,6 +5035,8 @@ case 0x638: { // LDR Rd, [Rn], -Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -4108,13 +5044,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x612: @@ -4124,6 +5063,8 @@ case 0x63a: { // LDR Rd, [Rn], -Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4132,13 +5073,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x614: @@ -4148,6 +5092,8 @@ case 0x63c: { // LDR Rd, [Rn], -Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4162,13 +5108,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x616: @@ -4178,6 +5127,8 @@ case 0x63e: { // LDR Rd, [Rn], -Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4191,13 +5142,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address - value; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x690: @@ -4207,6 +5161,8 @@ case 0x6b8: { // LDR Rd, [Rn], Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -4214,13 +5170,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x692: @@ -4230,6 +5189,8 @@ case 0x6ba: { // LDR Rd, [Rn], Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4238,13 +5199,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x694: @@ -4254,6 +5218,8 @@ case 0x6bc: { // LDR Rd, [Rn], Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4268,13 +5234,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x696: @@ -4284,6 +5253,8 @@ case 0x6be: { // LDR Rd, [Rn], Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4297,56 +5268,71 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address + value; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x710: case 0x718: { // LDR Rd, [Rn, -Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x712: case 0x71a: { // LDR Rd, [Rn, -Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x714: case 0x71c: { // LDR Rd, [Rn, -Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4359,19 +5345,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x716: case 0x71e: { // LDR Rd, [Rn, -Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4383,19 +5374,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - value; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x730: case 0x738: { // LDR Rd, [Rn, -Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -4403,19 +5399,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x732: case 0x73a: { // LDR Rd, [Rn, -Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4424,19 +5425,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x734: case 0x73c: { // LDR Rd, [Rn, -Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4451,19 +5457,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x736: case 0x73e: { // LDR Rd, [Rn, -Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4477,56 +5488,71 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x790: case 0x798: { // LDR Rd, [Rn, Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x792: case 0x79a: { // LDR Rd, [Rn, Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x794: case 0x79c: { // LDR Rd, [Rn, Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4539,19 +5565,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x796: case 0x79e: { // LDR Rd, [Rn, Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4563,19 +5594,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + value; reg[dest].I = CPUReadMemory(address); - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7b0: case 0x7b8: { // LDR Rd, [Rn, Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -4583,19 +5619,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7b2: case 0x7ba: { // LDR Rd, [Rn, Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4604,19 +5645,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7b4: case 0x7bc: { // LDR Rd, [Rn, Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4631,19 +5677,24 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x7b6: case 0x7be: { // LDR Rd, [Rn, Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4657,13 +5708,16 @@ reg[dest].I = CPUReadMemory(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess32(address); + clockTicks = 0; if(dest == 15) { - clockTicks += 2; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); } + clockTicks += 3 + dataTicksAccess32(address) + + codeTicksAccess32(armNextPC); } break; case 0x640: @@ -4673,13 +5727,16 @@ case 0x668: { // STRB Rd, [Rn], -Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x642: @@ -4689,6 +5746,8 @@ case 0x66a: { // STRB Rd, [Rn], -Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4696,7 +5755,8 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x644: @@ -4706,6 +5766,8 @@ case 0x66c: { // STRB Rd, [Rn], -Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4719,7 +5781,8 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address - offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x646: @@ -4729,6 +5792,8 @@ case 0x66e: { // STRB Rd, [Rn], -Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4741,7 +5806,8 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address - value; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6c0: @@ -4751,13 +5817,16 @@ case 0x6e8: { // STRB Rd, [Rn], Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6c2: @@ -4767,6 +5836,8 @@ case 0x6ea: { // STRB Rd, [Rn], Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4774,7 +5845,8 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6c4: @@ -4783,7 +5855,9 @@ case 0x6e4: case 0x6ec: { - // STR Rd, [Rn], Rm, ASR # + // STRB Rd, [Rn], Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4797,7 +5871,8 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address + offset; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6c6: @@ -4807,6 +5882,8 @@ case 0x6ee: { // STRB Rd, [Rn], Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4819,38 +5896,47 @@ u32 address = reg[base].I; CPUWriteByte(address, reg[dest].B.B0); reg[base].I = address + value; - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x740: case 0x748: { // STRB Rd, [Rn, -Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x742: case 0x74a: { // STRB Rd, [Rn, -Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x744: case 0x74c: { // STRB Rd, [Rn, -Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4863,13 +5949,16 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x746: case 0x74e: { // STRB Rd, [Rn, -Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4881,26 +5970,32 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - value; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x760: case 0x768: { // STRB Rd, [Rn, -Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x762: case 0x76a: { // STRB Rd, [Rn, -Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -4908,13 +6003,16 @@ u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x764: case 0x76c: { // STRB Rd, [Rn, -Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4928,13 +6026,16 @@ u32 address = reg[base].I - offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x766: case 0x76e: { // STRB Rd, [Rn, -Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -4947,38 +6048,47 @@ u32 address = reg[base].I - value; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7c0: case 0x7c8: { // STRB Rd, [Rn, Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7c2: case 0x7ca: { // STRB Rd, [Rn, Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7c4: case 0x7cc: { // STRB Rd, [Rn, Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -4991,13 +6101,16 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7c6: case 0x7ce: { // STRB Rd, [Rn, Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5009,26 +6122,32 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + value; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7e0: case 0x7e8: { // STRB Rd, [Rn, Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7e2: case 0x7ea: { // STRB Rd, [Rn, Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -5036,13 +6155,16 @@ u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7e4: case 0x7ec: { // STRB Rd, [Rn, Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5056,13 +6178,16 @@ u32 address = reg[base].I + offset; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7e6: case 0x7ee: { // STRB Rd, [Rn, Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5075,7 +6200,8 @@ u32 address = reg[base].I + value; reg[base].I = address; CPUWriteByte(address, reg[dest].B.B0); - clockTicks += 2 + CPUUpdateTicksAccess16(address); + clockTicks = 2 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x650: @@ -5085,6 +6211,8 @@ case 0x678: { // LDRB Rd, [Rn], -Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -5092,7 +6220,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x652: @@ -5102,6 +6239,8 @@ case 0x67a: { // LDRB Rd, [Rn], -Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -5110,7 +6249,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x654: @@ -5120,6 +6268,8 @@ case 0x67c: { // LDRB Rd, [Rn], -Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5134,7 +6284,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address - offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x656: @@ -5144,6 +6303,8 @@ case 0x67e: { // LDRB Rd, [Rn], -Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5157,7 +6318,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address - value; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6d0: @@ -5167,6 +6337,8 @@ case 0x6f8: { // LDRB Rd, [Rn], Rm, LSL # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -5174,7 +6346,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6d2: @@ -5184,6 +6365,8 @@ case 0x6fa: { // LDRB Rd, [Rn], Rm, LSR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -5192,7 +6375,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6d4: @@ -5202,6 +6394,8 @@ case 0x6fc: { // LDRB Rd, [Rn], Rm, ASR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5216,7 +6410,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address + offset; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x6d6: @@ -5226,6 +6429,8 @@ case 0x6fe: { // LDRB Rd, [Rn], Rm, ROR # + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5239,38 +6444,71 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address + value; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x750: case 0x758: { // LDRB Rd, [Rn, -Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x752: case 0x75a: { // LDRB Rd, [Rn, -Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x754: case 0x75c: { // LDRB Rd, [Rn, -Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5283,13 +6521,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x756: case 0x75e: { // LDRB Rd, [Rn, -Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5301,13 +6550,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I - value; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x770: case 0x778: { // LDRB Rd, [Rn, -Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -5315,13 +6575,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x772: case 0x77a: { // LDRB Rd, [Rn, -Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -5330,13 +6601,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x774: case 0x77c: { // LDRB Rd, [Rn, -Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5351,13 +6633,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x776: case 0x77e: { // LDRB Rd, [Rn, -Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5371,38 +6664,71 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7d0: case 0x7d8: { // LDRB Rd, [Rn, Rm, LSL #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7d2: case 0x7da: { // LDRB Rd, [Rn, Rm, LSR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7d4: case 0x7dc: { // LDRB Rd, [Rn, Rm, ASR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5415,13 +6741,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + offset; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7d6: case 0x7de: { // LDRB Rd, [Rn, Rm, ROR #] + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5433,13 +6770,24 @@ int base = (opcode >> 16) & 15; u32 address = reg[base].I + value; reg[dest].I = CPUReadByte(address); - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7f0: case 0x7f8: { // LDRB Rd, [Rn, Rm, LSL #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = reg[opcode & 15].I << ((opcode>>7)& 31); int dest = (opcode >> 12) & 15; int base = (opcode >> 16) & 15; @@ -5447,13 +6795,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7f2: case 0x7fa: { // LDRB Rd, [Rn, Rm, LSR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset = shift ? reg[opcode & 15].I >> shift : 0; int dest = (opcode >> 12) & 15; @@ -5462,13 +6821,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7f4: case 0x7fc: { // LDRB Rd, [Rn, Rm, ASR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; int offset; if(shift) @@ -5483,13 +6853,24 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; case 0x7f6: case 0x7fe: { // LDRB Rd, [Rn, Rm, ROR #]! + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int shift = (opcode >> 7) & 31; u32 value = reg[opcode & 15].I; if(shift) { @@ -5503,7 +6884,16 @@ reg[dest].I = CPUReadByte(address); if(dest != base) reg[base].I = address; - clockTicks += 3 + CPUUpdateTicksAccess16(address); + clockTicks = 0; + if(dest == 15) { + reg[15].I &= 0xFFFFFFFC; + armNextPC = reg[15].I; + reg[15].I += 4; + ARM_PREFETCH; + clockTicks += 2 + dataTicksAccessSeq32(address) + dataTicksAccessSeq32(address); + } + clockTicks += 3 + dataTicksAccess16(address) + + codeTicksAccess32(armNextPC); } break; #define STMW_REG(val,num) \ @@ -5511,10 +6901,10 @@ CPUWriteMemory(address, reg[(num)].I);\ if(!offset) {\ reg[base].I = temp;\ - clockTicks += 1 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ } else {\ - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ }\ address += 4;\ } @@ -5522,22 +6912,23 @@ if(opcode & (val)) {\ CPUWriteMemory(address, reg[(num)].I);\ if(!offset) {\ - clockTicks += 1 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ } else {\ - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ }\ address += 4;\ } CASE_16(0x800) - // STMDA Rn, {Rlist} { + // STMDA Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp + 4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -5557,20 +6948,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x820) { // STMDA Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STMW_REG(1, 0); @@ -5591,21 +6984,23 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); reg[base].I = temp; } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x840) { // STMDA Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); @@ -5642,20 +7037,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x860) { // STMDA Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STMW_REG(1, 0); @@ -5692,20 +7089,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); reg[base].I = temp; } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x880) { // STMIA Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -5725,18 +7124,20 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x8a0) { // STMIA Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; u32 temp = reg[base].I + 4*(cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); @@ -5759,18 +7160,20 @@ CPUWriteMemory(address, reg[15].I+4); if(!offset) { reg[base].I = temp; - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); } else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x8c0) { // STMIA Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -5803,18 +7206,20 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x8e0) { // STMIA Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; u32 temp = reg[base].I + 4*(cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); @@ -5850,21 +7255,23 @@ CPUWriteMemory(address, reg[15].I+4); if(!offset) { reg[base].I = temp; - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); } else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x900) { // STMDB Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -5884,20 +7291,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x920) { // STMDB Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STMW_REG(1, 0); @@ -5918,21 +7327,23 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); reg[base].I = temp; } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x940) { // STMDB Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); @@ -5969,20 +7380,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x960) { // STMDB Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STMW_REG(1, 0); @@ -6019,20 +7432,22 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); reg[base].I = temp; } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x980) - // STMIB Rn, {Rlist} { + // STMIB Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -6052,18 +7467,20 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x9a0) { // STMIB Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; u32 temp = reg[base].I + 4*(cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); @@ -6086,18 +7503,20 @@ CPUWriteMemory(address, reg[15].I+4); if(!offset) { reg[base].I = temp; - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); } else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x9c0) { // STMIB Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; STM_REG(1, 0); STM_REG(2, 1); @@ -6130,18 +7549,20 @@ if(opcode & 32768) { CPUWriteMemory(address, reg[15].I+4); if(!offset) - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; CASE_16(0x9e0) { // STMIB Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; int offset = 0; u32 temp = reg[base].I + 4*(cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]); @@ -6177,10 +7598,11 @@ CPUWriteMemory(address, reg[15].I+4); if(!offset) { reg[base].I = temp; - clockTicks += 1 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); } else - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); } + clockTicks += 1 + codeTicksAccess32(armNextPC); } break; @@ -6188,9 +7610,9 @@ if(opcode & (val)) {\ reg[(num)].I = CPUReadMemory(address);\ if(offset)\ - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ else {\ - clockTicks += 1 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ }\ address += 4;\ @@ -6199,11 +7621,13 @@ CASE_16(0x810) { // LDMDA Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp + 4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6222,23 +7646,28 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x830) { // LDMDA Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp + 4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6257,13 +7686,17 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); if(!(opcode & (1 << base))) reg[base].I = temp; } @@ -6271,11 +7704,13 @@ CASE_16(0x850) { // LDMDA Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp + 4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6295,18 +7730,16 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); CPUSwitchMode(reg[17].I & 0x1f, false); if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6339,17 +7772,25 @@ LDM_REG(8192, 13); LDM_REG(16384, 14); } + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x870) { // LDMDA Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (temp + 4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6369,10 +7810,6 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if(!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); if(!(opcode & (1 << base))) reg[base].I = temp; @@ -6381,9 +7818,11 @@ if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6419,16 +7858,24 @@ if(!(opcode & (1 << base))) reg[base].I = temp; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x890) { // LDMIA Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6447,23 +7894,29 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x8b0) { // LDMIA Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6482,13 +7935,17 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); if(!(opcode & (1 << base))) reg[base].I = temp; } @@ -6496,9 +7953,11 @@ CASE_16(0x8d0) { // LDMIA Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6518,18 +7977,16 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); CPUSwitchMode(reg[17].I & 0x1f, false); if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6562,17 +8019,25 @@ LDM_REG(8192, 13); LDM_REG(16384, 14); } + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x8f0) { // LDMIA Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = reg[base].I & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6592,10 +8057,6 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if(!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); if(!(opcode & (1 << base))) reg[base].I = temp; @@ -6604,9 +8065,11 @@ if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6642,18 +8105,26 @@ if(!(opcode & (1 << base))) reg[base].I = temp; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x910) { // LDMDB Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6672,23 +8143,29 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x930) { // LDMDB Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6707,13 +8184,17 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); if(!(opcode & (1 << base))) reg[base].I = temp; } @@ -6721,11 +8202,13 @@ CASE_16(0x950) { // LDMDB Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6745,18 +8228,16 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); CPUSwitchMode(reg[17].I & 0x1f, false); if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6789,17 +8270,25 @@ LDM_REG(8192, 13); LDM_REG(16384, 14); } + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x970) { // LDMDB Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = temp & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6819,10 +8308,6 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if(!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); if(!(opcode & (1 << base))) reg[base].I = temp; @@ -6831,9 +8316,11 @@ if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -6869,16 +8356,24 @@ if(!(opcode & (1 << base))) reg[base].I = temp; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x990) { // LDMIB Rn, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6897,23 +8392,29 @@ LDM_REG(16384, 14); if(opcode & 32768) { reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x9b0) { // LDMIB Rn!, {Rlist} + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; LDM_REG(1, 0); LDM_REG(2, 1); @@ -6933,12 +8434,21 @@ if(opcode & 32768) { reg[15].I = CPUReadMemory(address); if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); + armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); if(!(opcode & (1 << base))) reg[base].I = temp; } @@ -6946,9 +8456,11 @@ CASE_16(0x9d0) { // LDMIB Rn, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -6968,18 +8480,16 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if (!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); CPUSwitchMode(reg[17].I & 0x1f, false); if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -7012,17 +8522,25 @@ LDM_REG(8192, 13); LDM_REG(16384, 14); } + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_16(0x9f0) { // LDMIB Rn!, {Rlist}^ + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int base = (opcode & 0x000F0000) >> 16; u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]); u32 address = (reg[base].I+4) & 0xFFFFFFFC; - clockTicks += 2; + clockTicks = 0; int offset = 0; if(opcode & 0x8000) { LDM_REG(1, 0); @@ -7042,10 +8560,6 @@ LDM_REG(16384, 14); reg[15].I = CPUReadMemory(address); - if(!offset) - clockTicks += 2 + CPUUpdateTicksAccess32(address); - else - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address); if(!(opcode & (1 << base))) reg[base].I = temp; @@ -7054,9 +8568,11 @@ if(armState) { armNextPC = reg[15].I & 0xFFFFFFFC; reg[15].I = armNextPC + 4; + ARM_PREFETCH; } else { armNextPC = reg[15].I & 0xFFFFFFFE; reg[15].I = armNextPC + 2; + THUMB_PREFETCH; } } else { LDM_REG(1, 0); @@ -7092,13 +8608,18 @@ if(!(opcode & (1 << base))) reg[base].I = temp; + if (!offset) + clockTicks += 1 + dataTicksAccess32(address); + else + clockTicks += 1 + dataTicksAccessSeq32(address); + clockTicks += 1 + codeTicksAccessSeq32(armNextPC); } + clockTicks += 2 + codeTicksAccess32(armNextPC); } break; CASE_256(0xa00) { // B - clockTicks += 3; int offset = opcode & 0x00FFFFFF; if(offset & 0x00800000) { offset |= 0xFF000000; @@ -7107,12 +8628,16 @@ reg[15].I += offset; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks = codeTicksAccessSeq32(armNextPC) + 1; + clockTicks += 2 + codeTicksAccess32(armNextPC) + + codeTicksAccessSeq32(armNextPC); + busPrefetchCount=0; } break; CASE_256(0xb00) { // BL - clockTicks += 3; int offset = opcode & 0x00FFFFFF; if(offset & 0x00800000) { offset |= 0xFF000000; @@ -7122,12 +8647,21 @@ reg[15].I += offset; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks = codeTicksAccessSeq32(armNextPC) + 1; + clockTicks += 2 + codeTicksAccess32(armNextPC) + + codeTicksAccessSeq32(armNextPC); + busPrefetchCount=0; } break; CASE_256(0xf00) // SWI - clockTicks += 3; - CPUSoftwareInterrupt(opcode & 0x00FFFFFF); + clockTicks = codeTicksAccessSeq32(armNextPC) + 1; + clockTicks += 2 + codeTicksAccess32(armNextPC) + + codeTicksAccessSeq32(armNextPC); + busPrefetchCount=0; + CPUSoftwareInterrupt(opcode & 0x00FFFFFF); + break; #ifdef GP_SUPPORT case 0xe11: @@ -7162,3 +8696,6 @@ // END } } + +if (clockTicks == 0) + clockTicks = codeTicksAccessSeq32(oldArmNextPC) + 1; diff -urN ../VisualBoyAdvance-1.7.2/src/armdis.cpp ./src/armdis.cpp --- ../VisualBoyAdvance-1.7.2/src/armdis.cpp 2004-05-13 23:34:51 +0900 +++ ./src/armdis.cpp 2006-01-07 04:40:08 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -117,8 +117,8 @@ {0xfa00, 0x5800, "ldr%b %r0, [%r3, %r6]"}, // Format 8 {0xfe00, 0x5200, "strh %r0, [%r3, %r6]"}, - {0xfe00, 0x5600, "ldrh %r0, [%r3, %r6]"}, - {0xfe00, 0x5a00, "ldsb %r0, [%r3, %r6]"}, + {0xfe00, 0x5600, "ldsb %r0, [%r3, %r6]"}, + {0xfe00, 0x5a00, "ldrh %r0, [%r3, %r6]"}, {0xfe00, 0x5e00, "ldsh %r0, [%r3, %r6]"}, // Format 9 {0xe800, 0x6000, "str%B %r0, [%r3, %p]"}, diff -urN ../VisualBoyAdvance-1.7.2/src/bios.cpp ./src/bios.cpp --- ../VisualBoyAdvance-1.7.2/src/bios.cpp 2004-05-13 23:34:20 +0900 +++ ./src/bios.cpp 2006-04-30 23:35:05 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -70,7 +70,7 @@ } #endif - s32 a = -((s32)(reg[0].I * reg[0].I)) >> 14; + s32 a = -(((s32)(reg[0].I*reg[0].I)) >> 14); s32 b = ((0xA9 * a) >> 14) + 0x390; b = ((b * a) >> 14) + 0x91C; b = ((b * a) >> 14) + 0xFB6; @@ -78,7 +78,8 @@ b = ((b * a) >> 14) + 0x2081; b = ((b * a) >> 14) + 0x3651; b = ((b * a) >> 14) + 0xA2F9; - reg[0].I = (reg[0].I * b) >> 16; + a = ((s32)reg[0].I * b) >> 16; + reg[0].I = a; #ifdef DEV_VERSION if(systemVerbose & VERBOSE_SWI) { @@ -99,36 +100,33 @@ } #endif - s16 x = reg[0].I; - s16 y = reg[1].I; - + s32 x = reg[0].I; + s32 y = reg[1].I; + u32 res = 0; if (y == 0) { - reg[0].I = 0x8000 & x; - reg[3].I = 0x170; + res = ((x>>16) & 0x8000); } else { if (x == 0) { - reg[0].I = (0x8000 & y) + 0x4000; - reg[3].I = 0x170; + res = ((y>>16) & 0x8000) + 0x4000; } else { - if (abs(x) > abs(y)) { + if ((abs(x) > abs(y)) || ((abs(x) == abs(y)) && (!((x<0) && (y<0))))) { reg[1].I = x; reg[0].I = y << 14; BIOS_Div(); BIOS_ArcTan(); if (x < 0) - reg[0].I = 0x8000 + reg[0].I; + res = 0x8000 + reg[0].I; else - reg[0].I = ((y & 0x8000) << 1 ) + reg[0].I; - reg[3].I = 0x170; + res = (((y>>16) & 0x8000)<<1) + reg[0].I; } else { reg[0].I = x << 14; BIOS_Div(); BIOS_ArcTan(); - reg[0].I = (0x4000 + (y & 0x8000)) - reg[0].I; - reg[3].I = 0x170; + res = (0x4000 + ((y>>16) & 0x8000)) - reg[0].I; } } } + reg[0].I = res; #ifdef DEV_VERSION if(systemVerbose & VERBOSE_SWI) { @@ -136,7 +134,7 @@ reg[0].I); } #endif -} +} void BIOS_BitUnPack() { @@ -155,7 +153,11 @@ u32 header = reg[2].I; int len = CPUReadHalfWord(header); - // check address + // check address + if(((source & 0xe000000) == 0) || + ((source + len) & 0xe000000) == 0) + return; + int bits = CPUReadByte(header+2); int revbits = 8 - bits; // u32 value = 0; @@ -179,7 +181,7 @@ break; u32 d = b & mask; u32 temp = d >> bitcount; - if(!temp && addBase) { + if(d || addBase) { temp += base; } data |= temp << bitwritecount; @@ -196,6 +198,11 @@ } } +void BIOS_GetBiosChecksum() +{ + reg[0].I=0xBAAE187F; +} + void BIOS_BgAffineSet() { #ifdef DEV_VERSION @@ -280,7 +287,7 @@ dest &= 0xFFFFFFFC; // fill ? if((cnt >> 24) & 1) { - u32 value = CPUReadMemory(source); + u32 value = (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); while(count) { CPUWriteMemory(dest, value); dest += 4; @@ -289,7 +296,7 @@ } else { // copy while(count) { - CPUWriteMemory(dest, CPUReadMemory(source)); + CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source))); source += 4; dest += 4; count--; @@ -298,7 +305,7 @@ } else { // 16-bit fill? if((cnt >> 24) & 1) { - u16 value = CPUReadHalfWord(source); + u16 value = (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); while(count) { CPUWriteHalfWord(dest, value); dest += 2; @@ -307,7 +314,7 @@ } else { // copy while(count) { - CPUWriteHalfWord(dest, CPUReadHalfWord(source)); + CPUWriteHalfWord(dest, (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source))); source += 2; dest += 2; count--; @@ -343,7 +350,7 @@ if((cnt >> 24) & 1) { while(count > 0) { // BIOS always transfers 32 bytes at a time - u32 value = CPUReadMemory(source); + u32 value = (source>0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source)); for(int i = 0; i < 8; i++) { CPUWriteMemory(dest, value); dest += 4; @@ -355,7 +362,7 @@ while(count > 0) { // BIOS always transfers 32 bytes at a time for(int i = 0; i < 8; i++) { - CPUWriteMemory(dest, CPUReadMemory(source)); + CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0xBAFFFFFB :CPUReadMemory(source))); source += 4; dest += 4; } @@ -548,7 +555,7 @@ u32 treeStart = source; - source += (treeSize<<1) + 1; + source += ((treeSize+1)<<1)-1; // minus because we already skipped one byte int len = header >> 8; @@ -866,6 +873,8 @@ { // no need to trace here. this is only called directly from GBA.cpp // to emulate bios initialization + + CPUUpdateRegister(0x0, 0x80); if(flags) { if(flags & 0x01) { @@ -891,18 +900,16 @@ if(flags & 0x80) { int i; - for(i = 0; i < 8; i++) + for(i = 0; i < 0x10; i++) CPUUpdateRegister(0x200+i*2, 0); - CPUUpdateRegister(0x202, 0xFFFF); - - for(i = 0; i < 8; i++) + for(i = 0; i < 0xF; i++) CPUUpdateRegister(0x4+i*2, 0); - for(i = 0; i < 16; i++) + for(i = 0; i < 0x20; i++) CPUUpdateRegister(0x20+i*2, 0); - for(i = 0; i < 24; i++) + for(i = 0; i < 0x18; i++) CPUUpdateRegister(0xb0+i*2, 0); CPUUpdateRegister(0x130, 0); @@ -965,7 +972,7 @@ u32 source = reg[0].I; u32 dest = reg[1].I; - u32 header = CPUReadMemory(source); + u32 header = CPUReadMemory(source & 0xFFFFFFFC); source += 4; if(((source & 0xe000000) == 0) || @@ -1034,7 +1041,7 @@ u32 source = reg[0].I; u32 dest = reg[1].I; - u32 header = CPUReadMemory(source); + u32 header = CPUReadMemory(source & 0xFFFFFFFC); source += 4; if(((source & 0xe000000) == 0) || diff -urN ../VisualBoyAdvance-1.7.2/src/bios.h ./src/bios.h --- ../VisualBoyAdvance-1.7.2/src/bios.h 2004-05-13 22:56:47 +0900 +++ ./src/bios.h 2006-04-30 23:35:05 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ extern void BIOS_ArcTan(); extern void BIOS_ArcTan2(); extern void BIOS_BitUnPack(); +extern void BIOS_GetBiosChecksum(); extern void BIOS_BgAffineSet(); extern void BIOS_CpuSet(); extern void BIOS_CpuFastSet(); diff -urN ../VisualBoyAdvance-1.7.2/src/elf.cpp ./src/elf.cpp --- ../VisualBoyAdvance-1.7.2/src/elf.cpp 2004-05-13 23:34:08 +0900 +++ ./src/elf.cpp 2006-06-08 23:12:18 +0900 @@ -820,7 +820,7 @@ *bytesRead = 1; return NULL; } - *bytesRead = strlen((char *)data) + 1; + *bytesRead = (int)strlen((char *)data) + 1; return (char *)data; } @@ -961,8 +961,7 @@ data += bytes; break; case DW_FORM_ref_addr: - attr->value = (elfDebugInfo->infodata + elfRead4Bytes(data)) - - elfGetCompileUnitForData(data)->top; + attr->value = (u32)((elfDebugInfo->infodata + elfRead4Bytes(data)) - elfGetCompileUnitForData(data)->top); data += 4; break; case DW_FORM_ref4: @@ -970,11 +969,7 @@ data += 4; break; case DW_FORM_ref_udata: - attr->value = (elfDebugInfo->infodata + - (elfGetCompileUnitForData(data)->top - - elfDebugInfo->infodata) + - elfReadLEB128(data, &bytes)) - - elfCurrentUnit->top; + attr->value = (u32)((elfDebugInfo->infodata + (elfGetCompileUnitForData(data)->top - elfDebugInfo->infodata) + elfReadLEB128(data, &bytes)) - elfCurrentUnit->top); data += bytes; break; case DW_FORM_indirect: @@ -1070,7 +1065,7 @@ ELFcie *cies = NULL; while(data < end) { - u32 offset = data - topOffset; + u32 offset = (u32)(data - topOffset); u32 len = elfRead4Bytes(data); data += 4; @@ -1110,7 +1105,7 @@ cie->returnAddress = *data++; cie->data = data; - cie->dataLen = dataEnd - data; + cie->dataLen = (u32)(dataEnd - data); } else { ELFfde *fde = (ELFfde *)calloc(1, sizeof(ELFfde)); @@ -1136,7 +1131,7 @@ data += 4; fde->data = data; - fde->dataLen = dataEnd - data; + fde->dataLen = (u32)(dataEnd - data); if((elfFdeCount %10) == 0) { elfFdes = (ELFfde **)realloc(elfFdes, (elfFdeCount+10) * @@ -2659,6 +2654,7 @@ memcpy(&workRAM[READ32LE(&ph->paddr) & 0x3ffff], data + READ32LE(&ph->offset), READ32LE(&ph->filesz)); + size += READ32LE(&ph->filesz); } } else { if(READ32LE(&ph->paddr) >= 0x8000000 && @@ -2708,6 +2704,7 @@ memcpy(&workRAM[READ32LE(&sh[i]->addr) & 0x3ffff], data + READ32LE(&sh[i]->offset), READ32LE(&sh[i]->size)); + size += READ32LE(&sh[i]->size); } } else { if(READ32LE(&sh[i]->addr) >= 0x8000000 && @@ -2760,7 +2757,7 @@ while(ddata < end) { unit = elfParseCompUnit(ddata, abbrevdata); - unit->offset = ddata-debugdata; + unit->offset = (u32)(ddata-debugdata); elfParseLineInfo(unit, data); if(last == NULL) elfCompileUnits = unit; diff -urN ../VisualBoyAdvance-1.7.2/src/expr-lex.cpp ./src/expr-lex.cpp --- ../VisualBoyAdvance-1.7.2/src/expr-lex.cpp 2003-06-06 23:17:21 +0900 +++ ./src/expr-lex.cpp 2006-09-04 06:52:25 +0900 @@ -2,7 +2,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvsroot/vba/VisualBoyAdvance/src/expr-lex.cpp,v 1.2 2003/06/06 14:17:21 forgotten Exp $ + * $Header: /cvsroot/vba/VisualBoyAdvance/src/expr-lex.cpp,v 1.4 2006/09/03 21:52:25 kxu Exp $ */ #define FLEX_SCANNER @@ -386,6 +386,7 @@ #ifndef __GNUC__ #include #define isatty _isatty +#define fileno _fileno #endif char *exprString; diff -urN ../VisualBoyAdvance-1.7.2/src/expr.l ./src/expr.l --- ../VisualBoyAdvance-1.7.2/src/expr.l 2002-10-20 22:03:12 +0900 +++ ./src/expr.l 2006-09-04 06:52:25 +0900 @@ -4,6 +4,7 @@ #ifndef __GNUC__ #include #define isatty _isatty +#define fileno _fileno #endif char *exprString; diff -urN ../VisualBoyAdvance-1.7.2/src/exprNode.cpp ./src/exprNode.cpp --- ../VisualBoyAdvance-1.7.2/src/exprNode.cpp 2004-05-13 23:33:47 +0900 +++ ./src/exprNode.cpp 2006-09-04 06:52:25 +0900 @@ -25,6 +25,10 @@ #include "elf.h" #include "exprNode.h" +#ifndef __GNUC__ +#define strdup _strdup +#endif + extern char *yytext; #define debuggerReadMemory(addr) \ diff -urN ../VisualBoyAdvance-1.7.2/src/gb/GB.cpp ./src/gb/GB.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/GB.cpp 2004-05-14 04:35:26 +0900 +++ ./src/gb/GB.cpp 2006-08-25 22:30:09 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ extern bool speedup; bool gbUpdateSizes(); +bool inBios = false; // debugging bool memorydebug = false; @@ -51,6 +52,7 @@ void (*mapper)(u16,u8) = NULL; void (*mapperRAM)(u16,u8) = NULL; u8 (*mapperReadRAM)(u16) = NULL; +void (*mapperUpdateClock)() = NULL; // registers gbRegister PC; @@ -59,7 +61,7 @@ gbRegister BC; gbRegister DE; gbRegister HL; -u16 IFF; +u16 IFF = 0; // 0xff04 u8 register_DIV = 0; // 0xff05 @@ -121,29 +123,79 @@ // state variables +// general +int clockTicks = 0; +bool gbSystemMessage = false; +int gbGBCColorType = 0; +int gbHardware = 0; +int gbRomType = 0; +int gbRemainingClockTicks = 0; +int gbOldClockTicks = 0; +int gbIntBreak = 0; +int gbInterruptLaunched = 0; +u8 gbCheatingDevice = 0; // 1 = GS, 2 = GG +// breakpoint +bool breakpoint = false; // interrupt -int gbInterrupt = 0; +int gbInt48Signal = 0; int gbInterruptWait = 0; // serial int gbSerialOn = 0; int gbSerialTicks = 0; int gbSerialBits = 0; // timer -int gbTimerOn = 0; -int gbTimerTicks = 0; -int gbTimerClockTicks = 0; +bool gbTimerOn = false; +int gbTimerTicks = GBTIMER_MODE_0_CLOCK_TICKS; +int gbTimerClockTicks = GBTIMER_MODE_0_CLOCK_TICKS; int gbTimerMode = 0; +bool gbIncreased = false; +// The internal timer is always active, and it is +// not reset by writing to register_TIMA/TMA, but by +// writing to register_DIV... +int gbInternalTimer = 0x55; +const u8 gbTimerMask [4] = {0xff, 0x3, 0xf, 0x3f}; +const u8 gbTimerBug [8] = {0x80, 0x80, 0x02, 0x02, 0x0, 0xff, 0x0, 0xff}; +bool gbTimerModeChange = false; +bool gbTimerOnChange = false; // lcd +bool gbScreenOn = true; int gbLcdMode = 2; -int gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS; -int gbLcdLYIncrementTicks = 0; +int gbLcdModeDelayed = 2; +int gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS-1; +int gbLcdTicksDelayed = GBLCD_MODE_2_CLOCK_TICKS; +int gbLcdLYIncrementTicks = 114; +int gbLcdLYIncrementTicksDelayed = 115; +int gbScreenTicks = 0; +u8 gbSCYLine[300]; +u8 gbSCXLine[300]; +u8 gbBgpLine[300]; +u8 gbObp0Line [300]; +u8 gbObp1Line [300]; +u8 gbSpritesTicks [300]; +u8 oldRegister_WY; +bool gbLYChangeHappened = false; +bool gbLCDChangeHappened = false; +int gbLine99Ticks = 1; +int gbRegisterLYLCDCOffOn = 0; +int inUseRegister_WY = 0; + +// Used to keep track of the line that ellapse +// when screen is off +int gbWhiteScreen = 0; +bool gbBlackScreen = false; +int register_LCDCBusy = 0; + // div int gbDivTicks = GBDIV_CLOCK_TICKS; // cgb int gbVramBank = 0; int gbWramBank = 1; -int gbHdmaSource = 0x0000; -int gbHdmaDestination = 0x8000; +//sgb +bool gbSgbResetFlag = false; +// gbHdmaDestination is 0x99d0 on startup (tested on HW) +// but I'm not sure what gbHdmaSource is... +int gbHdmaSource = 0x99d0; +int gbHdmaDestination = 0x99d0; int gbHdmaBytes = 0x0000; int gbHdmaOn = 0; int gbSpeed = 0; @@ -158,6 +210,7 @@ int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS; // emulator features int gbBattery = 0; +bool gbBatteryError = false; int gbCaptureNumber = 0; bool gbCapture = false; bool gbCapturePrevious = false; @@ -185,7 +238,7 @@ }; int gbRamSizes[6] = { 0x00000000, // 0K - 0x00000800, // 2K + 0x00002000, // 2K // Changed to 2000 to avoid problems with gbMemoryMap... 0x00002000, // 8K 0x00008000, // 32K 0x00020000, // 128K @@ -215,9 +268,9 @@ 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, // a 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, // b 2, 3, 3, 4, 3, 4, 2, 4, 2, 4, 3, 2, 3, 6, 2, 4, // c - 2, 3, 3, 0, 3, 4, 2, 4, 2, 4, 3, 0, 3, 0, 2, 4, // d - 3, 3, 2, 0, 0, 4, 2, 4, 4, 1, 4, 0, 0, 0, 2, 4, // e - 3, 3, 2, 1, 0, 4, 2, 4, 3, 2, 4, 1, 0, 0, 2, 4 // f + 2, 3, 3, 1, 3, 4, 2, 4, 2, 4, 3, 1, 3, 1, 2, 4, // d + 3, 3, 2, 1, 1, 4, 2, 4, 4, 1, 4, 1, 1, 1, 2, 4, // e + 3, 3, 2, 1, 1, 4, 2, 4, 3, 2, 4, 1, 0, 1, 2, 4 // f }; int gbCyclesCB[] = { @@ -230,14 +283,14 @@ 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // 5 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // 6 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // 7 - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // 8 - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // 9 - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // a - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // b - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // c - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // d - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2, // e - 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 3, 2 // f + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // 8 + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // 9 + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // a + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // b + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // c + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // d + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, // e + 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2 // f }; u16 DAATable[] = { @@ -499,7 +552,7 @@ 0x9250,0x9350,0x9450,0x9550,0x9650,0x9750,0x9850,0x9950, }; -u8 ZeroTable[] = { +u8 ZeroTable[256] = { 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -536,7 +589,8 @@ #define GBSAVE_GAME_VERSION_8 8 #define GBSAVE_GAME_VERSION_9 9 #define GBSAVE_GAME_VERSION_10 10 -#define GBSAVE_GAME_VERSION GBSAVE_GAME_VERSION_10 +#define GBSAVE_GAME_VERSION_11 11 +#define GBSAVE_GAME_VERSION GBSAVE_GAME_VERSION_11 int inline gbGetValue(int min,int max,int v) { @@ -596,45 +650,72 @@ void gbDoHdma() { - gbCopyMemory(gbHdmaDestination, - gbHdmaSource, + + gbCopyMemory((gbHdmaDestination & 0x1ff0) | 0x8000, + gbHdmaSource & 0xfff0, 0x10); - + gbHdmaDestination += 0x10; + if (gbHdmaDestination == 0xa000) + gbHdmaDestination = 0x8000; + gbHdmaSource += 0x10; + if (gbHdmaSource == 0x8000) + gbHdmaSource = 0xa000; - register_HDMA2 += 0x10; - if(register_HDMA2 == 0x00) - register_HDMA1++; - - register_HDMA4 += 0x10; - if(register_HDMA4 == 0x00) - register_HDMA3++; + register_HDMA2 = gbHdmaSource & 0xff; + register_HDMA1 = gbHdmaSource>>8; + + register_HDMA4 = gbHdmaDestination & 0xff; + register_HDMA3 = gbHdmaDestination>>8; - if(gbHdmaDestination == 0x96b0) - gbHdmaBytes = gbHdmaBytes; gbHdmaBytes -= 0x10; - register_HDMA5--; + gbMemory[0xff55] = --register_HDMA5; if(register_HDMA5 == 0xff) gbHdmaOn = 0; + +// We need to add the dmaClockticks for HDMA ! + if(gbSpeed) + gbDmaTicks = 17; + else + gbDmaTicks = 9; + + if (IFF & 0x80) + gbDmaTicks++; + } // fix for Harley and Lego Racers void gbCompareLYToLYC() { - if(register_LY == register_LYC) { - // mark that we have a match - register_STAT |= 4; + if(register_LCDC & 0x80) { + if(register_LY == register_LYC) { + + // mark that we have a match + register_STAT |= 4; - // check if we need an interrupt - if((register_STAT & 0x40) && (register_IE & 2)) - gbInterrupt |= 2; - } else // no match - register_STAT &= 0xfb; + // check if we need an interrupt + if (register_STAT & 0x40) + { + // send LCD interrupt only if no interrupt 48h signal... + if (!gbInt48Signal) + { + register_IF |=2; + } + gbInt48Signal |= 8; + } + } + else // no match + { + register_STAT &= 0xfb; + gbInt48Signal &=~8; + } + } } void gbWriteMemory(register u16 address, register u8 value) { + if(address < 0x8000) { #ifndef FINAL_VERSION if(memorydebug && (address>0x3fff || address < 0x2000)) { @@ -643,17 +724,31 @@ value, PC.W); } + #endif if(mapper) (*mapper)(address, value); return; + } - + if(address < 0xa000) { - gbMemoryMap[address>>12][address&0x0fff] = value; + // No access to Vram during mode 3 + // (used to emulate the gfx differences between GB & GBC-GBA/SP in Stunt Racer) + if ((gbLcdModeDelayed !=3) || + // This part is used to emulate a small difference between hardwares + // (check 8-in-1's arrow on GBA/GBC to verify it) + ((register_LY == 0) && ((gbHardware & 0xa) && (gbScreenOn==false) && + (register_LCDC & 0x80)) && + (gbLcdLYIncrementTicksDelayed ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))) + gbMemoryMap[address>>12][address&0x0fff] = value; return; } - + + // Used for the mirroring of 0xC000 in 0xE000 + if ((address >= 0xe000) && (address < 0xfe00)) + address &= ~0x2000; + if(address < 0xc000) { #ifndef FINAL_VERSION if(memorydebug) { @@ -663,474 +758,831 @@ PC.W); } #endif - - if(mapper) - (*mapperRAM)(address, value); + + // Is that a correct fix ??? (it used to be 'if (mapper)')... + if(mapperRAM) + (*mapperRAM)(address, value); return; } - + + if(address < 0xfe00) { gbMemoryMap[address>>12][address & 0x0fff] = value; return; } - - if(address < 0xff00) { + + // OAM not accessible during mode 2 & 3. + if(address < 0xfea0) + { + if (((gbHardware & 0xa) && ((gbLcdMode | gbLcdModeDelayed) &2)) || + ((gbHardware & 5) && (((gbLcdModeDelayed == 2) && + (gbLcdTicksDelayed<=GBLCD_MODE_2_CLOCK_TICKS)) || + (gbLcdModeDelayed == 3)))) + return; + else + { + gbMemory[address] = value; + return; + } + } + + + + if((address > 0xfea0) && (address < 0xff00)){ // GBC allows reading/writing to that area gbMemory[address] = value; return; - } - + } + switch(address & 0x00ff) { - case 0x00: { - gbMemory[0xff00] = ((gbMemory[0xff00] & 0xcf) | - (value & 0x30)); - if(gbSgbMode) { - gbSgbDoBitTransfer(value); + + case 0x00: { + gbMemory[0xff00] = ((gbMemory[0xff00] & 0xcf) | + (value & 0x30) | 0xc0); + if(gbSgbMode) { + gbSgbDoBitTransfer(value); + } + return; } - - return; - } - case 0x01: { - gbMemory[0xff01] = value; - return; - } + case 0x01: { + gbMemory[0xff01] = value; + return; + } - // serial control - case 0x02: { - gbSerialOn = (value & 0x80); - gbMemory[0xff02] = value; - if(gbSerialOn) { - gbSerialTicks = GBSERIAL_CLOCK_TICKS; + // serial control + case 0x02: { + gbSerialOn = (value & 0x80); + gbMemory[0xff02] = value; + if(gbSerialOn) { + gbSerialTicks = GBSERIAL_CLOCK_TICKS; #ifdef LINK_EMULATION - if(linkConnected) { - if(value & 1) { - linkSendByte(0x100|gbMemory[0xFF01]); - Sleep(5); + if(linkConnected) { + if(value & 1) { + linkSendByte(0x100|gbMemory[0xFF01]); + Sleep(5); + } } - } #endif - } + } - gbSerialBits = 0; - return; - } + gbSerialBits = 0; + return; + } - // DIV register resets on any write - case 0x04: { - register_DIV = 0; - return; - } - case 0x05: - register_TIMA = value; - return; + case 0x04: { + // DIV register resets on any write + // (not totally perfect, but better than nothing) + gbMemory[0xff04] = register_DIV = 0; + gbDivTicks = GBDIV_CLOCK_TICKS; + // Another weird timer 'bug' : + // Writing to DIV register resets the internal timer, + // and can also increase TIMA/trigger an interrupt + // in some cases... + if (gbTimerOn && !(gbInternalTimer & (gbTimerClockTicks>>1))) + { + gbMemory[0xff05] = ++register_TIMA; + if(register_TIMA == 0) { + // timer overflow! + + // reload timer modulo + gbMemory[0xff05] = register_TIMA = register_TMA; + + // flag interrupt + gbMemory[0xff0f] = register_IF |= 4; + } + } + gbInternalTimer = 0xff; + return; + } + case 0x05: + gbMemory[0xff05] = register_TIMA = value; + return; - case 0x06: - register_TMA = value; - return; - - // TIMER control - case 0x07: { - register_TAC = value; + case 0x06: + gbMemory[0xff06] = register_TMA = value; + return; - gbTimerOn = (value & 4); - gbTimerMode = value & 3; - // register_TIMA = register_TMA; - switch(gbTimerMode) { - case 0: - gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_0_CLOCK_TICKS; - break; - case 1: - gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_1_CLOCK_TICKS; - break; - case 2: - gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_2_CLOCK_TICKS; - break; - case 3: - gbTimerClockTicks = gbTimerTicks = GBTIMER_MODE_3_CLOCK_TICKS; - break; - } - return; - } + // TIMER control + case 0x07: { - case 0x0f: { - register_IF = value; - gbInterrupt = value; - return; - } - - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - case 0x20: - case 0x21: - case 0x22: - case 0x23: - case 0x24: - case 0x25: - case 0x26: { - SOUND_EVENT(address,value); - return; - } - case 0x40: { - int lcdChange = (register_LCDC & 0x80) ^ (value & 0x80); + gbTimerModeChange = (((value & 3) != (register_TAC&3)) && (value & register_TAC & 4)) ? true : false; + gbTimerOnChange = (((value ^ register_TAC) & 4) == 4) ? true : false; + + gbTimerOn = (value & 4) ? true : false; - if(lcdChange) { - if(value & 0x80) { - gbLcdTicks = GBLCD_MODE_1_CLOCK_TICKS; - gbLcdMode = 0; - register_STAT &= 0xfc; - register_LY = 0x00; - } else { - gbLcdTicks = 0; - gbLcdMode = 0; - register_STAT &= 0xfc; - register_LY = 0x00; - } - // compareLYToLYC(); - } - // don't draw the window if it was not enabled and not being drawn before - if(!(register_LCDC & 0x20) && (value & 0x20) && gbWindowLine == -1 && - register_LY > register_WY) - gbWindowLine = 144; + if (gbTimerOnChange || gbTimerModeChange) + { + gbTimerMode = value & 3; - register_LCDC = value; + switch(gbTimerMode) { + case 0: + gbTimerClockTicks = GBTIMER_MODE_0_CLOCK_TICKS; + break; + case 1: + gbTimerClockTicks = GBTIMER_MODE_1_CLOCK_TICKS; + break; + case 2: + gbTimerClockTicks = GBTIMER_MODE_2_CLOCK_TICKS; + break; + case 3: + gbTimerClockTicks = GBTIMER_MODE_3_CLOCK_TICKS; + break; + } + } - return; - } - // STAT - case 0x41: { - //register_STAT = (register_STAT & 0x87) | - // (value & 0x7c); - register_STAT = (value & 0xf8) | (register_STAT & 0x07); // fix ? - // GB bug from Devrs FAQ - if(!gbCgbMode && (register_LCDC & 0x80) && gbLcdMode < 2) - gbInterrupt |= 2; - return; - } + // This looks weird, but this emulates a bug in which register_TIMA + // is increased when writing to register_TAC + // (This fixes Korodice's long-delay between menus bug). + + if (gbTimerOnChange || gbTimerModeChange) + { + bool temp = false; - // SCY - case 0x42: { - register_SCY = value; - return; - } - - // SCX - case 0x43: { - register_SCX = value; - return; - } - - // LY - case 0x44: { - // read only - return; - } + if ((gbTimerOn && !gbTimerModeChange) && (gbTimerMode & 2) && + !(gbInternalTimer & 0x80) && (gbInternalTimer & (gbTimerClockTicks>>1)) && + !(gbInternalTimer & (gbTimerClockTicks>>5))) + temp = true; + else if ((!gbTimerOn && !gbTimerModeChange && gbTimerOnChange ) && ((gbTimerTicks-1) < (gbTimerClockTicks>>1))) + temp = true; + else if (gbTimerOn && gbTimerModeChange && !gbTimerOnChange) + { + switch(gbTimerMode & 3) + { + case 0x00: + temp = false; + break; + case 0x01: + if (((gbInternalTimer & 0x82) == 2) && (gbTimerTicks>(clockTicks+1))) + temp = true; + break; + case 0x02: + if (((gbInternalTimer & 0x88) == 0x8) && (gbTimerTicks>(clockTicks+1))) + temp = true; + break; + case 0x03: + if (((gbInternalTimer & 0xA0) == 0x20) && (gbTimerTicks>(clockTicks+1))) + temp = true; + break; + } + } - // LYC - case 0x45: { - register_LYC = value; - if((register_LCDC & 0x80)) { - gbCompareLYToLYC(); + if (temp) + { + gbMemory[0xff05] = ++register_TIMA; + if((register_TIMA & 0xff) == 0) { + // timer overflow! + + // reload timer modulo + gbMemory[0xff05] = register_TIMA = register_TMA; + + // flag interrupt + gbMemory[0xff0f] = register_IF |= 4; + } + } + } + gbMemory[0xff07] = register_TAC = value; + return; } - return; - } - - // DMA! - case 0x46: { - int source = value * 0x0100; - - gbCopyMemory(0xfe00, - source, - 0xa0); - register_DMA = value; - return; - } - - // BGP - case 0x47: { - gbBgp[0] = value & 0x03; - gbBgp[1] = (value & 0x0c)>>2; - gbBgp[2] = (value & 0x30)>>4; - gbBgp[3] = (value & 0xc0)>>6; - break; - } - - // OBP0 - case 0x48: { - gbObp0[0] = value & 0x03; - gbObp0[1] = (value & 0x0c)>>2; - gbObp0[2] = (value & 0x30)>>4; - gbObp0[3] = (value & 0xc0)>>6; - break; - } - - // OBP1 - case 0x49: { - gbObp1[0] = value & 0x03; - gbObp1[1] = (value & 0x0c)>>2; - gbObp1[2] = (value & 0x30)>>4; - gbObp1[3] = (value & 0xc0)>>6; - break; - } - case 0x4a: - register_WY = value; - return; - - case 0x4b: - register_WX = value; - return; - - // KEY1 - case 0x4d: { - if(gbCgbMode) { - gbMemory[0xff4d] = (gbMemory[0xff4d] & 0x80) | (value & 1); + case 0x0f: { + gbMemory[0xff0f] = register_IF = value; + //gbMemory[0xff0f] = register_IE |= value; return; } - } - break; - - // VBK - case 0x4f: { - if(gbCgbMode) { - value = value & 1; - if(value == gbVramBank) + + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1a: + case 0x1b: + case 0x1c: + case 0x1d: + case 0x1e: + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: { + if (gbMemory[NR52] & 0x80) { + SOUND_EVENT(address,value); return; - - int vramAddress = value * 0x2000; - gbMemoryMap[0x08] = &gbVram[vramAddress]; - gbMemoryMap[0x09] = &gbVram[vramAddress + 0x1000]; - - gbVramBank = value; - register_VBK = value; + } } - return; - } - break; - // HDMA1 - case 0x51: { - if(gbCgbMode) { - if(value > 0x7f && value < 0xa0) - value = 0; - - gbHdmaSource = (value << 8) | (register_HDMA2 & 0xf0); - - register_HDMA1 = value; - return; - } - } - break; - - // HDMA2 - case 0x52: { - if(gbCgbMode) { - value = value & 0xf0; - - gbHdmaSource = (register_HDMA1 << 8) | (value); - - register_HDMA2 = value; + case 0x26: { + SOUND_EVENT(address,value); return; } - } - break; - // HDMA3 - case 0x53: { - if(gbCgbMode) { - value = value & 0x1f; - gbHdmaDestination = (value << 8) | (register_HDMA4 & 0xf0); - gbHdmaDestination += 0x8000; - register_HDMA3 = value; + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3a: + case 0x3b: + case 0x3c: + case 0x3d: + case 0x3e: + case 0x3f: { + gbMemory[address] = value; return; } - } - break; + + case 0x40: { + int lcdChange = (register_LCDC & 0x80) ^ (value & 0x80); + + // don't draw the window if it was not enabled and not being drawn before + if(!(register_LCDC & 0x20) && (value & 0x20) && gbWindowLine == -1 && + register_LY > register_WY) + gbWindowLine = 146; + // 007 fix : don't draw the first window's 1st line if it's enable 'too late' + // (ie. if register_LY == register_WY when enabling it) + // and move it to the next line + else if (!(register_LCDC & 0x20) && (value & 0x20) && (register_LY == register_WY)) + gbWindowLine = -2; + + + gbMemory[0xff40] = register_LCDC = value; + + + if(lcdChange) { + if((value & 0x80) && (!register_LCDCBusy)) { + + // if (!gbWhiteScreen && !gbSgbMask) + + // systemDrawScreen(); + + + + gbRegisterLYLCDCOffOn = (register_LY + 144) % 154; + + gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS - (gbSpeed ? 2 : 1); + gbLcdTicksDelayed = GBLCD_MODE_2_CLOCK_TICKS - (gbSpeed ? 1 : 0); + gbLcdLYIncrementTicks = GBLY_INCREMENT_CLOCK_TICKS - (gbSpeed ? 2 : 1); + gbLcdLYIncrementTicksDelayed = GBLY_INCREMENT_CLOCK_TICKS - (gbSpeed ? 1 : 0); + gbLcdMode = 2; + gbLcdModeDelayed = 2; + gbMemory[0xff41] = register_STAT = (register_STAT & 0xfc) | 2; + gbMemory[0xff44] = register_LY = 0x00; + gbInt48Signal = 0; + gbLYChangeHappened = false; + gbLCDChangeHappened = false; + gbWindowLine = 146; + oldRegister_WY = 146; + + // Fix for Namco Gallery Vol.2 + // (along with updating register_LCDC at the start of 'case 0x40') : + if(register_STAT & 0x20) + { + // send LCD interrupt only if no interrupt 48h signal... + if (!gbInt48Signal) + { + gbMemory[0xff0f] = register_IF |= 2; + } + gbInt48Signal |= 4; + } + gbCompareLYToLYC(); + + } else { - // HDMA4 - case 0x54: { - if(gbCgbMode) { - value = value & 0xf0; - gbHdmaDestination = ((register_HDMA3 & 0x1f) << 8) | value; - gbHdmaDestination += 0x8000; - register_HDMA4 = value; + register_LCDCBusy = clockTicks+6; + + //used to update the screen with white lines when it's off. + //(it looks strange, but it's pretty accurate) + + gbWhiteScreen = 0; + + gbScreenTicks = ((150-register_LY)*GBLY_INCREMENT_CLOCK_TICKS + + (49<<(gbSpeed ? 1 : 0))); + + // disable the screen rendering + gbScreenOn = false; + gbLcdTicks = 0; + gbLcdMode = 0; + gbLcdModeDelayed = 0; + gbMemory[0xff41] = register_STAT &= 0xfc; + gbInt48Signal = 0; + } + } return; } - } - break; - - // HDMA5 - case 0x55: { - if(gbCgbMode) { - gbHdmaBytes = 16 + (value & 0x7f) * 16; - if(gbHdmaOn) { - if(value & 0x80) { - register_HDMA5 = (value & 0x7f); - } else { - register_HDMA5 = 0xff; - gbHdmaOn = 0; + + // STAT + case 0x41: { + //register_STAT = (register_STAT & 0x87) | + // (value & 0x7c); + gbMemory[0xff41] = register_STAT = (value & 0xf8) | (register_STAT & 0x07); // fix ? + // GB bug from Devrs FAQ + // Corrected : it happens if Lcd Mode<2, but also if LY == LYC whatever + // Lcd Mode is, and if !gbInt48Signal in all cases. The screen being off + // doesn't matter (the bug will still happen). + // That fixes 'Satoru Nakajima - F-1 Hero' crash bug. + + if((gbHardware & 5) && (((!gbInt48Signal) && (gbLcdMode<2) && (register_LCDC & 0x80)) || + (register_LY == register_LYC))) + { + gbMemory[0xff0f] = register_IF |=2; + } + + gbInt48Signal &= ((register_STAT>>3) & 0xF); + + if((register_LCDC & 0x80)) { + if ((register_STAT & 0x08) && (gbLcdMode == 0)) + { + if (!gbInt48Signal) + { + gbMemory[0xff0f] = register_IF |=2; + } + gbInt48Signal |= 1; } - } else { - if(value & 0x80) { - gbHdmaOn = 1; - register_HDMA5 = value & 0x7f; - if(gbLcdMode == 0) - gbDoHdma(); - } else { - // we need to take the time it takes to complete the transfer into - // account... according to GB DEV FAQs, the setup time is the same - // for single and double speed, but the actual transfer takes the - // same time - if(gbSpeed) - gbDmaTicks = 231 + 16 * (value & 0x7f); - else - gbDmaTicks = 231 + 8 * (value & 0x7f); - gbCopyMemory(gbHdmaDestination, - gbHdmaSource, - gbHdmaBytes); - gbHdmaDestination += gbHdmaBytes; - gbHdmaSource += gbHdmaBytes; - - register_HDMA3 = ((gbHdmaDestination - 0x8000) >> 8) & 0x1f; - register_HDMA4 = gbHdmaDestination & 0xf0; - register_HDMA1 = (gbHdmaSource >> 8) & 0xff; - register_HDMA2 = gbHdmaSource & 0xf0; + if ((register_STAT & 0x10) && (gbLcdMode == 1)) + { + if (!gbInt48Signal) + { + gbMemory[0xff0f] = register_IF |=2; + } + gbInt48Signal |= 2; + } + if ((register_STAT & 0x20) && (gbLcdMode == 2)) + { + if (!gbInt48Signal) + { + gbMemory[0xff0f] = register_IF |=2; + } + gbInt48Signal |= 4; } + gbCompareLYToLYC(); + + gbMemory[0xff0f] = register_IF; + gbMemory[0xff41] = register_STAT; + } return; } - } - break; - - // BCPS - case 0x68: { - if(gbCgbMode) { - int paletteIndex = (value & 0x3f) >> 1; - int paletteHiLo = (value & 0x01); - - gbMemory[0xff68] = value; - gbMemory[0xff69] = (paletteHiLo ? - (gbPalette[paletteIndex] >> 8) : - (gbPalette[paletteIndex] & 0x00ff)); - return; - } - } - break; - - // BCPD - case 0x69: { - if(gbCgbMode) { - int v = gbMemory[0xff68]; - int paletteIndex = (v & 0x3f) >> 1; - int paletteHiLo = (v & 0x01); - gbMemory[0xff69] = value; - gbPalette[paletteIndex] = (paletteHiLo ? - ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : - ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff; - - if(gbMemory[0xff68] & 0x80) { - int index = ((gbMemory[0xff68] & 0x3f) + 1) & 0x3f; - - gbMemory[0xff68] = (gbMemory[0xff68] & 0x80) | index; - - gbMemory[0xff69] = (index & 1 ? - (gbPalette[index>>1] >> 8) : - (gbPalette[index>>1] & 0x00ff)); - + + // SCY + case 0x42: { + int temp = -1; + + if ((gbLcdMode == 3) || (gbLcdModeDelayed == 3)) + temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) - + gbLcdLYIncrementTicks); + + if (temp >=0) + { + for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++) + if (temp < 300) + gbSCYLine[i] = value; } + + else + memset(gbSCYLine, value, sizeof(gbSCYLine)); + + gbMemory[0xff42] = register_SCY = value; return; } - } - break; - // OCPS - case 0x6a: { - if(gbCgbMode) { - int paletteIndex = (value & 0x3f) >> 1; - int paletteHiLo = (value & 0x01); - - paletteIndex += 32; + // SCX + case 0x43: { + int temp = -1; + + if (gbLcdModeDelayed == 3) + temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) - + gbLcdLYIncrementTicksDelayed); + + if (temp >=0) + { + for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++) + if (temp < 300) + gbSCXLine[i] = value; + } - gbMemory[0xff6a] = value; - gbMemory[0xff6b] = (paletteHiLo ? - (gbPalette[paletteIndex] >> 8) : - (gbPalette[paletteIndex] & 0x00ff)); + else + memset(gbSCXLine, value, sizeof(gbSCXLine)); + + gbMemory[0xff43] = register_SCX = value; return; } - } - break; - // OCPD - case 0x6b: { - if(gbCgbMode) { - int v = gbMemory[0xff6a]; - int paletteIndex = (v & 0x3f) >> 1; - int paletteHiLo = (v & 0x01); - - paletteIndex += 32; - - gbMemory[0xff6b] = value; - gbPalette[paletteIndex] = (paletteHiLo ? - ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : - ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff; - if(gbMemory[0xff6a] & 0x80) { - int index = ((gbMemory[0xff6a] & 0x3f) + 1) & 0x3f; - - gbMemory[0xff6a] = (gbMemory[0xff6a] & 0x80) | index; - - gbMemory[0xff6b] = (index & 1 ? - (gbPalette[(index>>1) + 32] >> 8) : - (gbPalette[(index>>1) + 32] & 0x00ff)); - - } + // LY + case 0x44: { + // read only return; } - } - break; - - // SVBK - case 0x70: { - if(gbCgbMode) { - value = value & 7; - - int bank = value; - if(value == 0) - bank = 1; - if(bank == gbWramBank) + // LYC + case 0x45: { + if (register_LYC != value) + { + gbMemory[0xff45] = register_LYC = value; + if(register_LCDC & 0x80) { + gbCompareLYToLYC(); + } + } + return; + } + + // DMA! + case 0x46: { + int source = value * 0x0100; + + gbCopyMemory(0xfe00, + source, + 0xa0); + gbMemory[0xff46] = register_DMA = value; + return; + } + + // BGP + case 0x47: { + + int temp = -1; + + gbMemory[0xff47] = value; + + if (gbLcdModeDelayed == 3) + temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) - + gbLcdLYIncrementTicksDelayed); + + if (temp >=0) + { + for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++) + if (temp < 300) + gbBgpLine[i] = value; + } + else + memset(gbBgpLine,value,sizeof(gbBgpLine)); + + gbBgp[0] = value & 0x03; + gbBgp[1] = (value & 0x0c)>>2; + gbBgp[2] = (value & 0x30)>>4; + gbBgp[3] = (value & 0xc0)>>6; + break; + } + + // OBP0 + case 0x48: { + int temp = -1; + + gbMemory[0xff48] = value; + + if (gbLcdModeDelayed == 3) + temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) - + gbLcdLYIncrementTicksDelayed); + + if (temp >=0) + { + for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++) + if (temp < 300) + gbObp0Line[i] = value; + } + else + memset(gbObp0Line,value,sizeof(gbObp0Line)); + + gbObp0[0] = value & 0x03; + gbObp0[1] = (value & 0x0c)>>2; + gbObp0[2] = (value & 0x30)>>4; + gbObp0[3] = (value & 0xc0)>>6; + break; + } + + // OBP1 + case 0x49: { + int temp = -1; + + gbMemory[0xff49] = value; + + if (gbLcdModeDelayed == 3) + temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) - + gbLcdLYIncrementTicksDelayed); + + if (temp >=0) + { + for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++) + if (temp < 300) + gbObp1Line[i] = value; + } + else + memset(gbObp1Line,value,sizeof(gbObp1Line)); + + gbObp1[0] = value & 0x03; + gbObp1[1] = (value & 0x0c)>>2; + gbObp1[2] = (value & 0x30)>>4; + gbObp1[3] = (value & 0xc0)>>6; + break; + } + + // WY + case 0x4a: + gbMemory[0xff4a] = register_WY = value; + if ((register_LY <= register_WY) && ((gbWindowLine < 0) || (gbWindowLine>=144))) + { + gbWindowLine = -1; + oldRegister_WY = register_WY; + } + return; + + // WX + case 0x4b: + gbMemory[0xff4b] = register_WX = value; + return; + + // KEY1 + case 0x4d: { + if(gbCgbMode) { + gbMemory[0xff4d] = (gbMemory[0xff4d] & 0x80) | (value & 1) | 0x7e; return; + } + } + break; + + // VBK + case 0x4f: { + if(gbCgbMode) { + value = value & 1; + if(value == gbVramBank) + return; - int wramAddress = bank * 0x1000; - gbMemoryMap[0x0d] = &gbWram[wramAddress]; + int vramAddress = value * 0x2000; + gbMemoryMap[0x08] = &gbVram[vramAddress]; + gbMemoryMap[0x09] = &gbVram[vramAddress + 0x1000]; - gbWramBank = bank; - register_SVBK = value; + gbVramBank = value; + register_VBK = value; + } return; } - } - break; + break; + + // BOOTROM disable register (also gbCgbMode enabler if value & 0x10 ?) + case 0x50 : + { + if (useBios && inBios && !skipBios && (value & 1)) + { + gbMemoryMap[0x00] = &gbRom[0x0000]; + memcpy ((u8 *)(gbRom+0x100), (u8 *)(gbMemory + 0x100), 0xF00); + inBios = false; + } + } + + // HDMA1 + case 0x51: { + if(gbCgbMode) { + if(value > 0x7f && value < 0xa0) + value = 0; + + gbHdmaSource = (value << 8) | (gbHdmaSource & 0xf0); + + register_HDMA1 = value; + return; + } + } + break; - case 0xff: { - register_IE = value; - register_IF &= value; - return; + // HDMA2 + case 0x52: { + if(gbCgbMode) { + value = value & 0xf0; + + gbHdmaSource = (gbHdmaSource & 0xff00) | (value); + + register_HDMA2 = value; + return; + } + } + break; + + // HDMA3 + case 0x53: { + if(gbCgbMode) { + value = value & 0x1f; + gbHdmaDestination = (value << 8) | (gbHdmaDestination & 0xf0); + gbHdmaDestination |= 0x8000; + register_HDMA3 = value; + return; + } + } + break; + + // HDMA4 + case 0x54: { + if(gbCgbMode) { + value = value & 0xf0; + gbHdmaDestination = (gbHdmaDestination & 0x1f00) | value; + gbHdmaDestination |= 0x8000; + register_HDMA4 = value; + return; + } + } + break; + + // HDMA5 + case 0x55: { + + if(gbCgbMode) { + gbHdmaBytes = 16 + (value & 0x7f) * 16; + if(gbHdmaOn) { + if(value & 0x80) { + gbMemory[0xff55] = register_HDMA5 = (value & 0x7f); + } else { + register_HDMA5 = 0xff; + gbHdmaOn = 0; + } + } else { + if(value & 0x80) { + gbHdmaOn = 1; + gbMemory[0xff55] = register_HDMA5 = value & 0x7f; + if(gbLcdModeDelayed == 0) + gbDoHdma(); + } else { + // we need to take the time it takes to complete the transfer into + // account... according to GB DEV FAQs, the setup time is the same + // for single and double speed, but the actual transfer takes the + // same time + if(gbSpeed) + gbDmaTicks = 2+16 * ((value & 0x7f) +1); + else + gbDmaTicks = 1+8 * ((value & 0x7f)+1); + + gbCopyMemory((gbHdmaDestination & 0x1ff0) | 0x8000, + gbHdmaSource & 0xfff0, + gbHdmaBytes); + gbHdmaDestination += gbHdmaBytes; + gbHdmaSource += gbHdmaBytes; + + gbMemory[0xff51] = register_HDMA1 = 0xff;// = (gbHdmaSource >> 8) & 0xff; + gbMemory[0xff52] = register_HDMA2 = 0xff;// = gbHdmaSource & 0xf0; + gbMemory[0xff53] = register_HDMA3 = 0xff;// = ((gbHdmaDestination - 0x8000) >> 8) & 0x1f; + gbMemory[0xff54] = register_HDMA4 = 0xff;// = gbHdmaDestination & 0xf0; + gbMemory[0xff55] = register_HDMA5 = 0xff; + } + } + return; + } + } + break; + + // BCPS + case 0x68: { + if(gbCgbMode) { + int paletteIndex = (value & 0x3f) >> 1; + int paletteHiLo = (value & 0x01); + + gbMemory[0xff68] = value; + + gbMemory[0xff69] = (paletteHiLo ? + (gbPalette[paletteIndex] >> 8) : + (gbPalette[paletteIndex] & 0x00ff)); + return; + } + } + break; + + // BCPD + case 0x69: { + if(gbCgbMode) { + int v = gbMemory[0xff68]; + int paletteIndex = (v & 0x3f) >> 1; + int paletteHiLo = (v & 0x01); + + // No access to gbPalette during mode 3 (Color Panel Demo) + if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks>=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-1)))) && (!gbSpeed)) || + (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || + ((gbLcdMode == 3) && (gbLcdTicks>(GBLCD_MODE_3_CLOCK_TICKS-2))) || + ((gbLcdMode == 0) && (gbLcdTicks<=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-2)))))) + { + gbMemory[0xff69] = value; + gbPalette[paletteIndex] = (paletteHiLo ? + ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : + ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff; + } + + + if(gbMemory[0xff68] & 0x80) { + int index = ((gbMemory[0xff68] & 0x3f) + 1) & 0x3f; + + gbMemory[0xff68] = (gbMemory[0xff68] & 0x80) | index; + gbMemory[0xff69] = (index & 1 ? + (gbPalette[index>>1] >> 8) : + (gbPalette[index>>1] & 0x00ff)); + } + return; + } + } + break; + + // OCPS + case 0x6a: { + if(gbCgbMode) { + int paletteIndex = (value & 0x3f) >> 1; + int paletteHiLo = (value & 0x01); + + paletteIndex += 32; + + gbMemory[0xff6a] = value; + + gbMemory[0xff6b] = (paletteHiLo ? + (gbPalette[paletteIndex] >> 8) : + (gbPalette[paletteIndex] & 0x00ff)); + return; + } + } + break; + + // OCPD + case 0x6b: { + + if(gbCgbMode) { + int v = gbMemory[0xff6a]; + int paletteIndex = (v & 0x3f) >> 1; + int paletteHiLo = (v & 0x01); + + paletteIndex += 32; + + // No access to gbPalette during mode 3 (Color Panel Demo) + if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks>=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-1)))) && (!gbSpeed)) || + (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || + ((gbLcdMode == 3) && (gbLcdTicks>(GBLCD_MODE_3_CLOCK_TICKS-2))) || + ((gbLcdMode == 0) && (gbLcdTicks<=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-2)))))) + { + gbMemory[0xff6b] = value; + gbPalette[paletteIndex] = (paletteHiLo ? + ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : + ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff; + } + + if(gbMemory[0xff6a] & 0x80) { + int index = ((gbMemory[0xff6a] & 0x3f) + 1) & 0x3f; + + gbMemory[0xff6a] = (gbMemory[0xff6a] & 0x80) | index; + + gbMemory[0xff6b] = (index & 1 ? + (gbPalette[(index>>1) + 32] >> 8) : + (gbPalette[(index>>1) + 32] & 0x00ff)); + } + return; + } + } + break; + + case 0x6c: { + gbMemory[0xff6c] = 0xfe | value; + return; + } + + + // SVBK + case 0x70: { + if(gbCgbMode) { + value = value & 7; + + int bank = value; + if(value == 0) + bank = 1; + + if(bank == gbWramBank) + return; + + int wramAddress = bank * 0x1000; + gbMemoryMap[0x0d] = &gbWram[wramAddress]; + + gbWramBank = bank; + gbMemory[0xff70] = register_SVBK = value; + return; + } + } + + case 0x75:{ + gbMemory[0xff75] = 0x8f | value; + return; + } + + case 0xff: { + gbMemory[0xffff] = register_IE = value; + return; + } } + + if(address < 0xff80) + { + gbMemory[address] = value; + return; } - + gbMemory[address] = value; } @@ -1139,6 +1591,27 @@ if(gbCheatMap[address]) return gbCheatRead(address); + if(address < 0x8000) + return gbMemoryMap[address>>12][address&0x0fff]; + + if(address < 0xa000) + { + // A lot of 'ugly' checks... But only way to emulate this particular behaviour... + if (((gbHardware & 0xa) && ((gbLcdModeDelayed !=3) || ((register_LY == 0) && + (gbScreenOn==false) && (register_LCDC & 0x80)) && + (gbLcdLYIncrementTicksDelayed ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))) || + ((gbHardware & 0x5) && (gbLcdModeDelayed !=3) && + ((gbLcdMode !=3) || ((register_LY == 0) && ((gbScreenOn==false) && + (register_LCDC & 0x80)) && + (gbLcdLYIncrementTicks ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))))) + return gbMemoryMap[address>>12][address&0x0fff]; + return 0xff; + } + + // Used for the mirroring of 0xC000 in 0xE000 + if ((address >= 0xe000) && (address < 0xfe00)) + address &= ~0x2000; + switch(address & 0xf000) { case 0x0a: case 0x0b: @@ -1148,6 +1621,10 @@ case 0x0f: if(address > 0xff00) { switch(address & 0x00ff) { + case 0x02: + return (gbMemory[0xff02]); + case 0x03: + return (0xff); case 0x04: return register_DIV; case 0x05: @@ -1156,17 +1633,33 @@ return register_TMA; case 0x07: return (0xf8 | register_TAC); + case 0x08: + case 0x09: + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x0e: + return (0xff); case 0x0f: - return (0xe0 | register_IF); + return (0xe0 | gbMemory[0xff0f]); case 0x40: return register_LCDC; case 0x41: - return (0x80 | register_STAT); + // This is a GB/C only bug (ie. not GBA/SP). + if ((gbHardware & 7) && (gbLcdMode == 2) && (gbLcdModeDelayed == 1) && (!gbSpeed)) + return (0x80 | gbMemory[0xff41] & 0xFC); + else + return (0x80 | gbMemory[0xff41]); case 0x42: return register_SCY; case 0x43: return register_SCX; case 0x44: + if (((gbHardware & 7) && ((gbLcdMode == 1) && (gbLcdTicks == 0x71))) || + (!(register_LCDC && 0x80))) + return 0; + else return register_LY; case 0x45: return register_LYC; @@ -1176,6 +1669,8 @@ return register_WY; case 0x4b: return register_WX; + case 0x4c: + return 0xff; case 0x4f: return (0xfe | register_VBK); case 0x51: @@ -1188,14 +1683,55 @@ return register_HDMA4; case 0x55: return register_HDMA5; + case 0x68: + case 0x6a: + if (gbCgbMode) + return (0x40 | gbMemory[address]); + else + return 0xc0; + case 0x69: + case 0x6b: + if (gbCgbMode) + { + // No access to gbPalette during mode 3 (Color Panel Demo) + if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks>=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-1)))) && (!gbSpeed)) || + (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || + ((gbLcdMode == 3) && (gbLcdTicks>(GBLCD_MODE_3_CLOCK_TICKS-2))) || + ((gbLcdMode == 0) && (gbLcdTicks<=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-2)))))) + return (gbMemory[address]); + else + return 0xff; + } + else + return 0xff; case 0x70: - return (0xf8 | register_SVBK); + if (gbCgbMode) + return (0xf8 | register_SVBK); + else + return 0xff; case 0xff: return register_IE; } } + // OAM not accessible during mode 2 & 3. + if(((address >= 0xfe00) && (address<0xfea0)) && + ((gbLcdMode | gbLcdModeDelayed) &2)) + return 0xff; break; } + + if ((address >= 0xfea0) && (address < 0xff00)) + { + if (gbHardware & 1) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0x00 : 0xff ); + else if (gbHardware & 2) + return gbMemoryMap[address>>12][address & 0x0fff]; + else if (gbHardware & 4) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0xff : 0x00 ); + else if (gbHardware & 8) + return ((address & 0xf0) |((address & 0xf0)>>4)); + } + return gbMemoryMap[address>>12][address & 0x0fff]; } @@ -1203,10 +1739,28 @@ { if(gbCheatMap[address]) return gbCheatRead(address); - - if(address < 0xa000) + + + if(address < 0x8000) return gbMemoryMap[address>>12][address&0x0fff]; + if(address < 0xa000) + { + // A lot of 'ugly' checks... But only way to emulate this particular behaviour... + if (((gbHardware & 0xa) && ((gbLcdModeDelayed !=3) || ((register_LY == 0) && + (gbScreenOn==false) && (register_LCDC & 0x80)) && + (gbLcdLYIncrementTicksDelayed ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))) || + ((gbHardware & 0x5) && (gbLcdModeDelayed !=3) && + ((gbLcdMode !=3) || ((register_LY == 0) && ((gbScreenOn==false) && + (register_LCDC & 0x80)) && + (gbLcdLYIncrementTicks ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))))) + return gbMemoryMap[address>>12][address&0x0fff]; + return 0xff; + } + + if ((address >= 0xe000) && (address < 0xfe00)) + address &= ~0x2000; + if(address < 0xc000) { #ifndef FINAL_VERSION if(memorydebug) { @@ -1215,11 +1769,18 @@ PC.W); } #endif - + + // for the 2kb ram limit (fixes crash in shawu's story + // but now its sram test fails, as the it expects 8kb and not 2kb... + // So use the 'genericflashcard' option to fix it). + if (address<=(0xa000+gbRamSizeMask)) + { if(mapperReadRAM) return mapperReadRAM(address); return gbMemoryMap[address>>12][address & 0x0fff]; } + return 0xff; + } if(address >= 0xff00) { switch(address & 0x00ff) { @@ -1310,8 +1871,10 @@ break; case 0x01: return gbMemory[0xff01]; + case 0x02: + return (gbMemory[0xff02]); case 0x04: - return register_DIV; + return register_DIV; case 0x05: return register_TIMA; case 0x06: @@ -1319,17 +1882,45 @@ case 0x07: return (0xf8 | register_TAC); case 0x0f: - return (0xe0 | register_IF); - case 0x40: + return (0xe0 | gbMemory[0xff0f]); + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + if ((gbMemory[NR30] & 0x80) && (gbMemory[NR34] & 0x80)) + return 0xFF; + else + return gbMemoryMap[address>>12][address & 0x0fff]; + case 0x40: return register_LCDC; case 0x41: - return (0x80 | register_STAT); + // This is a GB/C only bug (ie. not GBA/SP). + if ((gbHardware & 7) && (gbLcdMode == 2) && (gbLcdModeDelayed == 1) && (!gbSpeed)) + return (0x80 | gbMemory[0xff41] & 0xFC); + else + return (0x80 | gbMemory[0xff41]); case 0x42: return register_SCY; case 0x43: return register_SCX; case 0x44: - return register_LY; + if (((gbHardware & 7) && ((gbLcdMode == 1) && (gbLcdTicks == 0x71))) || + (!(register_LCDC && 0x80))) + return (0); + else + return register_LY; case 0x45: return register_LYC; case 0x46: @@ -1350,27 +1941,62 @@ return register_HDMA4; case 0x55: return register_HDMA5; + case 0x68: + case 0x6a: + if (gbCgbMode) + return (0x40 | gbMemory[address]); + else + return 0xc0; + case 0x69: + case 0x6b: + if (gbCgbMode) + { + // No access to gbPalette during mode 3 (Color Panel Demo) + if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks>=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-1)))) && (!gbSpeed)) || + (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || + ((gbLcdMode == 3) && (gbLcdTicks>(GBLCD_MODE_3_CLOCK_TICKS-2))) || + ((gbLcdMode == 0) && (gbLcdTicks<=(GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]-2)))))) + return (gbMemory[address]); + else + return 0xff; + } + else + return 0xff; case 0x70: - return (0xf8 | register_SVBK); + if (gbCgbMode) + return (0xf8 | register_SVBK); + else + return 0xff; case 0xff: return register_IE; } } - + // OAM not accessible during mode 2 & 3. + if(((address >= 0xfe00) && (address<0xfea0)) && + (((gbLcdMode | gbLcdModeDelayed) &2) && + (!(gbSpeed && (gbHardware & 0x2) && !(gbLcdModeDelayed & 2) && (gbLcdMode == 2))) || + (gbSpeed && (gbHardware & 0x2) && (gbLcdModeDelayed == 0) && (gbLcdTicksDelayed == (GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]))))) + return 0xff; + + if ((address >= 0xfea0) && (address < 0xff00)) + { + if (gbHardware & 1) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0x00 : 0xff ); + else if (gbHardware & 2) + return gbMemoryMap[address>>12][address & 0x0fff]; + else if (gbHardware & 4) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0xff : 0x00 ); + else if (gbHardware & 8) + return ((address & 0xf0) |((address & 0xf0)>>4)); + } + return gbMemoryMap[address>>12][address & 0x0fff]; } void gbVblank_interrupt() { - if(IFF & 0x80) { - PC.W++; - IFF &= 0x7f; - } - gbInterrupt &= 0xfe; - - IFF &= 0x7e; - register_IF &= 0xfe; - + gbCheatWrite(false); // Emulates GS codes. + gbMemory[0xff0f] = register_IF &= 0xfe; gbWriteMemory(--SP.W, PC.B.B1); gbWriteMemory(--SP.W, PC.B.B0); PC.W = 0x40; @@ -1378,221 +2004,617 @@ void gbLcd_interrupt() { - if(IFF & 0x80) { - PC.W++; - IFF &= 0x7f; - } - gbInterrupt &= 0xfd; - IFF &= 0x7e; - register_IF &= 0xfd; - + gbMemory[0xff0f] = register_IF &= 0xfd; gbWriteMemory(--SP.W, PC.B.B1); gbWriteMemory(--SP.W, PC.B.B0); - PC.W = 0x48; } void gbTimer_interrupt() { - if(IFF & 0x80) { - PC.W++; - IFF &= 0x7f; - } - IFF &= 0x7e; - gbInterrupt &= 0xfb; - register_IF &= 0xfb; - + gbMemory[0xff0f] = register_IF &= 0xfb; gbWriteMemory(--SP.W, PC.B.B1); gbWriteMemory(--SP.W, PC.B.B0); - PC.W = 0x50; } void gbSerial_interrupt() { - if(IFF & 0x80) { - PC.W++; - IFF &= 0x7f; - } - IFF &= 0x7e; - gbInterrupt &= 0xf7; - register_IF &= 0xf7; - + gbMemory[0xff0f] = register_IF &= 0xf7; gbWriteMemory(--SP.W, PC.B.B1); gbWriteMemory(--SP.W, PC.B.B0); - PC.W = 0x58; } void gbJoypad_interrupt() { - if(IFF & 0x80) { - PC.W++; - IFF &= 0x7f; - } - IFF &= 0x7e; - gbInterrupt &= 0xef; - register_IF &= 0xef; - + gbMemory[0xff0f] = register_IF &= 0xef; gbWriteMemory(--SP.W, PC.B.B1); gbWriteMemory(--SP.W, PC.B.B0); - PC.W = 0x60; } void gbSpeedSwitch() { + gbBlackScreen = true; if(gbSpeed == 0) { gbSpeed = 1; - GBLCD_MODE_0_CLOCK_TICKS = 51 * 2; //127; //51 * 2; + GBLCD_MODE_0_CLOCK_TICKS = 51 * 2; GBLCD_MODE_1_CLOCK_TICKS = 1140 * 2; - GBLCD_MODE_2_CLOCK_TICKS = 20 * 2; //52; //20 * 2; - GBLCD_MODE_3_CLOCK_TICKS = 43 * 2; //99; //43 * 2; - GBDIV_CLOCK_TICKS = 64 * 2; + GBLCD_MODE_2_CLOCK_TICKS = 20 * 2; + GBLCD_MODE_3_CLOCK_TICKS = 43 * 2; GBLY_INCREMENT_CLOCK_TICKS = 114 * 2; - GBTIMER_MODE_0_CLOCK_TICKS = 256; //256*2; - GBTIMER_MODE_1_CLOCK_TICKS = 4; //4*2; - GBTIMER_MODE_2_CLOCK_TICKS = 16; //16*2; - GBTIMER_MODE_3_CLOCK_TICKS = 64; //64*2; + GBDIV_CLOCK_TICKS = 64; + GBTIMER_MODE_0_CLOCK_TICKS = 256; + GBTIMER_MODE_1_CLOCK_TICKS = 4; + GBTIMER_MODE_2_CLOCK_TICKS = 16; + GBTIMER_MODE_3_CLOCK_TICKS = 64; GBSERIAL_CLOCK_TICKS = 128 * 2; - gbDivTicks *= 2; gbLcdTicks *= 2; + gbLcdTicksDelayed *=2; + gbLcdTicksDelayed--; gbLcdLYIncrementTicks *= 2; - // timerTicks *= 2; - // timerClockTicks *= 2; + gbLcdLYIncrementTicksDelayed *= 2; + gbLcdLYIncrementTicksDelayed--; gbSerialTicks *= 2; SOUND_CLOCK_TICKS = soundQuality * 24 * 2; soundTicks *= 2; - // synchronizeTicks *= 2; - // SYNCHRONIZE_CLOCK_TICKS *= 2; + gbLine99Ticks = 3; } else { gbSpeed = 0; GBLCD_MODE_0_CLOCK_TICKS = 51; GBLCD_MODE_1_CLOCK_TICKS = 1140; GBLCD_MODE_2_CLOCK_TICKS = 20; GBLCD_MODE_3_CLOCK_TICKS = 43; - GBDIV_CLOCK_TICKS = 64; GBLY_INCREMENT_CLOCK_TICKS = 114; + GBDIV_CLOCK_TICKS = 64; GBTIMER_MODE_0_CLOCK_TICKS = 256; GBTIMER_MODE_1_CLOCK_TICKS = 4; GBTIMER_MODE_2_CLOCK_TICKS = 16; GBTIMER_MODE_3_CLOCK_TICKS = 64; GBSERIAL_CLOCK_TICKS = 128; - gbDivTicks /= 2; - gbLcdTicks /= 2; - gbLcdLYIncrementTicks /= 2; - // timerTicks /= 2; - // timerClockTicks /= 2; + gbLcdTicks >>= 1; + gbLcdTicksDelayed++; + gbLcdTicksDelayed >>=1; + gbLcdLYIncrementTicks >>= 1; + gbLcdLYIncrementTicksDelayed++; + gbLcdLYIncrementTicksDelayed >>= 1; gbSerialTicks /= 2; SOUND_CLOCK_TICKS = soundQuality * 24; - soundTicks /= 2; - // synchronizeTicks /= 2; - // SYNCHRONIZE_CLOCK_TICKS /= 2; + soundTicks /= 2; + gbLine99Ticks = 1; + if (gbHardware & 8) + gbLine99Ticks++; } + gbDmaTicks += (134)*GBLY_INCREMENT_CLOCK_TICKS + (37<<(gbSpeed ? 1 : 0)); } -void gbReset() +bool CPUIsGBBios(const char * file) { - SP.W = 0xfffe; - AF.W = 0x01b0; - BC.W = 0x0013; - DE.W = 0x00d8; - HL.W = 0x014d; - PC.W = 0x0100; - IFF = 0; - gbInterrupt = 1; - gbInterruptWait = 0; + if(strlen(file) > 4) { + const char * p = strrchr(file,'.'); + + if(p != NULL) { + if(_stricmp(p, ".gb") == 0) + return true; + if(_stricmp(p, ".bin") == 0) + return true; + if(_stricmp(p, ".bios") == 0) + return true; + } + } - register_DIV = 0; - register_TIMA = 0; - register_TMA = 0; - register_TAC = 0; - register_IF = 1; - register_LCDC = 0x91; - register_STAT = 0; - register_SCY = 0; - register_SCX = 0; - register_LY = 0; - register_LYC = 0; - register_DMA = 0; - register_WY = 0; - register_WX = 0; - register_VBK = 0; - register_HDMA1 = 0; - register_HDMA2 = 0; - register_HDMA3 = 0; - register_HDMA4 = 0; - register_HDMA5 = 0; - register_SVBK = 0; - register_IE = 0; + return false; +} - if(gbCgbMode) { - if(gbSgbMode) { - if(gbEmulatorType == 5) - AF.W = 0xffb0; +void gbCPUInit(const char *biosFileName, bool useBiosFile) +{ + useBios = false; + if (useBiosFile) + { + int size = 0x100; + if(utilLoad(biosFileName, + CPUIsGBBios, + bios, + size)) { + if(size == 0x100) + useBios = true; else - AF.W = 0x01b0; - BC.W = 0x0013; - DE.W = 0x00d8; - HL.W = 0x014d; - for(int i = 0; i < 8; i++) - gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; - } else { - AF.W = 0x11b0; - BC.W = 0x0000; - DE.W = 0xff56; - HL.W = 0x000d; + systemMessage(MSG_INVALID_BIOS_FILE_SIZE, N_("Invalid BOOTROM file size")); } - if(gbEmulatorType == 4) - BC.B.B1 |= 0x01; - - register_HDMA5 = 0xff; - gbMemory[0xff68] = 0xc0; - gbMemory[0xff6a] = 0xc0; - } else { - for(int i = 0; i < 8; i++) - gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; + } +} + +void gbGetHardwareType() +{ + gbCgbMode = 0; + gbSgbMode = 0; + if(gbRom[0x143] & 0x80) { + if((gbEmulatorType == 0) || + gbEmulatorType == 1 || + gbEmulatorType == 4) { + gbCgbMode = 1; + } + } + + if((gbCgbMode == 0 ) && (gbRom[0x146] == 0x03)) { + if(gbEmulatorType == 0 || + gbEmulatorType == 2 || + gbEmulatorType == 5) + gbSgbMode = 1; } + gbHardware = 1; // GB + if (((gbCgbMode == 1) && (gbEmulatorType == 0)) || (gbEmulatorType == 1)) + gbHardware = 2; // GBC + else if (((gbSgbMode == 1) && (gbEmulatorType == 0)) || (gbEmulatorType == 2) || (gbEmulatorType == 5)) + gbHardware = 4; // SGB(2) + else if (gbEmulatorType == 4) + gbHardware = 8; // GBA + + gbGBCColorType = 0; + if (gbHardware & 8) // If GBA is selected, choose the GBA default settings. + gbGBCColorType = 2; // (0 = GBC, 1 = GBA, 2 = GBASP) +} + +void gbReset() +{ + gbGetHardwareType(); + + oldRegister_WY = 146; + gbInterruptLaunched = 0; + + if(gbCgbMode == 1) { + if (gbVram == NULL) + gbVram = (u8 *)malloc(0x4000); + if (gbWram == NULL) + gbWram = (u8 *)malloc(0x8000); + memset(gbVram,0,0x4000); + memset(gbPalette,0, 2*128); + } + else + { + if(gbVram != NULL) { + free(gbVram); + gbVram = NULL; + } + if(gbWram != NULL) { + free(gbWram); + gbWram = NULL; + } + } + + gbLYChangeHappened = false; + gbLCDChangeHappened = false; + gbBlackScreen = false; + gbInterruptWait = 0; + gbDmaTicks = 0; + clockTicks = 0; + if(gbSpeed) { gbSpeedSwitch(); gbMemory[0xff4d] = 0; } + + // clean Wram + // This kinda emulates the startup state of Wram on GB/C (not very accurate, + // but way closer to the reality than filling it with 00es or FFes). + // On GBA/GBASP, it's kinda filled with random data. + // In all cases, most of the 2nd bank is filled with 00s. + // The starting data are important for some 'buggy' games, like Buster Brothers or + // Karamuchou ha Oosawagi!. + if (gbMemory != NULL) + { + memset(gbMemory,0xff, 65536); + for (int temp = 0xC000; temp < 0xE000; temp++) + if ((temp & 0x8) ^((temp & 0x800)>>8)) + { + if ((gbHardware & 0x02) && (gbGBCColorType == 0)) + gbMemory[temp] = 0x0; + else + gbMemory[temp] = 0x0f; + } + + else + gbMemory[temp] = 0xff; + } + + + + // clean LineBuffer + if (gbLineBuffer != NULL) + memset(gbLineBuffer, 0, sizeof(gbLineBuffer)); + // clean Pix + if (pix != NULL) + memset(pix, 0, sizeof(pix)); + // clean Vram + if (gbVram != NULL) + memset(gbVram, 0, 0x4000); + // clean Wram 2 + // This kinda emulates the startup state of Wram on GBC (not very accurate, + // but way closer to the reality than filling it with 00es or FFes). + // On GBA/GBASP, it's kinda filled with random data. + // In all cases, most of the 2nd bank is filled with 00s. + // The starting data are important for some 'buggy' games, like Buster Brothers or + // Karamuchou ha Oosawagi! + if (gbWram != NULL) + { + for (int i = 0; i<8; i++) + if (i != 2) + memcpy ((u16 *)(gbWram+i*0x1000), (u16 *)(gbMemory+0xC000), 0x1000); + } + + memset(gbSCYLine,0,sizeof(gbSCYLine)); + memset(gbSCXLine,0,sizeof(gbSCXLine)); + memset(gbBgpLine,0xfc,sizeof(gbBgpLine)); + if (gbHardware & 5) + { + memset(gbObp0Line,0xff,sizeof(gbObp0Line)); + memset(gbObp1Line,0xff,sizeof(gbObp1Line)); + } + else + { + memset(gbObp0Line,0x0,sizeof(gbObp0Line)); + memset(gbObp1Line,0x0,sizeof(gbObp1Line)); + } + memset(gbSpritesTicks,0x0,sizeof(gbSpritesTicks)); + + SP.W = 0xfffe; + AF.W = 0x01b0; + BC.W = 0x0013; + DE.W = 0x00d8; + HL.W = 0x014d; + PC.W = 0x0100; + IFF = 0; + gbInt48Signal = 0; - gbDivTicks = GBDIV_CLOCK_TICKS; - gbLcdMode = 2; - gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS; - gbLcdLYIncrementTicks = 0; - gbTimerTicks = 0; - gbTimerClockTicks = 0; + register_TIMA = 0; + register_TMA = 0; + register_TAC = 0; + gbMemory[0xff0f] = register_IF = 1; + gbMemory[0xff40] = register_LCDC = 0x91; + gbMemory[0xff47] = 0xfc; + + if (gbCgbMode) + gbMemory[0xff4d] = 0x7e; + else + gbMemory[0xff4d] = 0xff; + + if (!gbCgbMode) + gbMemory[0xff70] = gbMemory[0xff74] = 0xff; + + if (gbCgbMode) + gbMemory[0xff56] = 0x3e; + else + gbMemory[0xff56] = 0xff; + + register_SCY = 0; + register_SCX = 0; + register_LYC = 0; + register_DMA = 0xff; + register_WY = 0; + register_WX = 0; + register_VBK = 0; + register_HDMA1 = 0xff; + register_HDMA2 = 0xff; + register_HDMA3 = 0xff; + register_HDMA4 = 0xff; + register_HDMA5 = 0xff; + register_SVBK = 0; + register_IE = 0; + + if (gbCgbMode) + gbMemory[0xff02] = 0x7c; + else + gbMemory[0xff02] = 0x7e; + + gbMemory[0xff03] = 0xff; + int i; + for (i = 0x8; i<0xf; i++) + gbMemory[0xff00+i] = 0xff; + + gbMemory[0xff13] = 0xff; + gbMemory[0xff15] = 0xff; + gbMemory[0xff18] = 0xff; + gbMemory[0xff1d] = 0xff; + gbMemory[0xff1f] = 0xff; + + for (i = 0x27; i<0x30; i++) + gbMemory[0xff00+i] = 0xff; + + gbMemory[0xff4c] = 0xff; + gbMemory[0xff4e] = 0xff; + gbMemory[0xff50] = 0xff; + + for (i = 0x57; i<0x68; i++) + gbMemory[0xff00+i] = 0xff; + + for (i = 0x5d; i<0x70; i++) + gbMemory[0xff00+i] = 0xff; + + gbMemory[0xff71] = 0xff; + + for (i = 0x78; i<0x80; i++) + gbMemory[0xff00+i] = 0xff; + + if (gbHardware & 0xa) + { + + if (gbHardware & 2) + { + AF.W = 0x1180; + BC.W = 0x0000; + } + else + { + AF.W = 0x1100; + BC.W = 0x0100; // GBA/SP have B = 0x01 (which means GBC & GBA/SP bootrom are different !) + } + + gbMemory[0xff26] = 0xf1; + if (gbCgbMode) + { + + gbMemory[0xff31] = 0xff; + gbMemory[0xff33] = 0xff; + gbMemory[0xff35] = 0xff; + gbMemory[0xff37] = 0xff; + gbMemory[0xff39] = 0xff; + gbMemory[0xff3b] = 0xff; + gbMemory[0xff3d] = 0xff; + + gbMemory[0xff44] = register_LY = 0x90; + gbDivTicks = 0x19 + ((gbHardware & 2) >> 1); + gbInternalTimer = 0x58 + ((gbHardware & 2) >> 1); + gbLcdTicks = GBLCD_MODE_1_CLOCK_TICKS - + (register_LY-0x8F)*GBLY_INCREMENT_CLOCK_TICKS + 72 + ((gbHardware & 2) >> 1); + gbLcdLYIncrementTicks = 72 + ((gbHardware & 2) >> 1); + gbMemory[0xff04] = register_DIV = 0x1E; + } + else + { + gbMemory[0xff44] = register_LY = 0x94; + gbDivTicks = 0x22 + ((gbHardware & 2) >> 1); + gbInternalTimer = 0x61 + ((gbHardware & 2) >> 1); + gbLcdTicks = GBLCD_MODE_1_CLOCK_TICKS - + (register_LY-0x8F)*GBLY_INCREMENT_CLOCK_TICKS + 25 + ((gbHardware & 2) >> 1); + gbLcdLYIncrementTicks = 25 + ((gbHardware & 2) >> 1); + gbMemory[0xff04] = register_DIV = 0x26; + } + + + DE.W = 0xff56; + HL.W = 0x000d; + + register_HDMA5 = 0xff; + gbMemory[0xff68] = 0xc0; + gbMemory[0xff6a] = 0xc0; + + + gbMemory[0xff41] = register_STAT = 0x81; + gbLcdMode = 1; + } + else + { + if (gbHardware & 4) + { + if(gbEmulatorType == 5) + AF.W = 0xffb0; + else + AF.W = 0x01b0; + BC.W = 0x0013; + DE.W = 0x00d8; + HL.W = 0x014d; + } + gbDivTicks = 14; + gbInternalTimer = gbDivTicks--; + gbMemory[0xff04] = register_DIV = 0xAB; + gbMemory[0xff41] = register_STAT = 0x85; + gbMemory[0xff44] = register_LY = 0x00; + gbLcdTicks = 15; + gbLcdLYIncrementTicks = 114+gbLcdTicks; + gbLcdMode = 1; + + // used for the handling of the gb Boot Rom + if ((gbHardware & 5) && (bios != NULL) && useBios && !skipBios) + { + memcpy ((u8 *)(gbMemory), (u8 *)(gbRom), 0x1000); + memcpy ((u8 *)(gbMemory), (u8 *)(bios), 0x100); + gbWhiteScreen = 0; + + gbInternalTimer = 0x3e; + gbDivTicks = 0x3f; + gbMemory[0xff04] = register_DIV = 0x00; + PC.W = 0x0000; + register_LCDC = 0x11; + gbScreenOn = false; + gbLcdTicks = 0; + gbLcdMode = 0; + gbLcdModeDelayed = 0; + gbMemory[0xff41] = register_STAT &= 0xfc; + gbInt48Signal = 0; + gbLcdLYIncrementTicks = GBLY_INCREMENT_CLOCK_TICKS; + } + } + + gbLine99Ticks = 1; + if (gbHardware & 8) + gbLine99Ticks++; + + gbLcdModeDelayed = gbLcdMode; + gbLcdTicksDelayed = gbLcdTicks+1; + gbLcdLYIncrementTicksDelayed = gbLcdLYIncrementTicks+1; + + + gbTimerModeChange = false; + gbTimerOnChange = false; + gbTimerOn = false; + + if(gbCgbMode) { + for (int i = 0; i<0x20; i++) + gbPalette[i] = 0x7fff; + + // This is just to show that the starting values of the OBJ palettes are different + // between the 3 consoles, and that they 'kinda' stay the same at each reset + // (they can slightly change, somehow (randomly?)). + // You can check the effects of gbGBCColorType on the "Vila Caldan Color" gbc demo. + // Note that you could also check the Div register to check on which system the game + // is running (GB,GBC and GBA(SP) have different startup values). + // Unfortunatly, I don't have any SGB system, so I can't get their starting values. + + if (gbGBCColorType == 0) // GBC Hardware + { + gbPalette[0x20] = 0x0600; + gbPalette[0x21] = 0xfdf3; + gbPalette[0x22] = 0x041c; + gbPalette[0x23] = 0xf5db; + gbPalette[0x24] = 0x4419; + gbPalette[0x25] = 0x57ea; + gbPalette[0x26] = 0x2808; + gbPalette[0x27] = 0x9b75; + gbPalette[0x28] = 0x129b; + gbPalette[0x29] = 0xfce0; + gbPalette[0x2a] = 0x22da; + gbPalette[0x2b] = 0x4ac5; + gbPalette[0x2c] = 0x2d71; + gbPalette[0x2d] = 0xf0c2; + gbPalette[0x2e] = 0x5137; + gbPalette[0x2f] = 0x2d41; + gbPalette[0x30] = 0x6b2d; + gbPalette[0x31] = 0x2215; + gbPalette[0x32] = 0xbe0a; + gbPalette[0x33] = 0xc053; + gbPalette[0x34] = 0xfe5f; + gbPalette[0x35] = 0xe000; + gbPalette[0x36] = 0xbe10; + gbPalette[0x37] = 0x914d; + gbPalette[0x38] = 0x7f91; + gbPalette[0x39] = 0x02b5; + gbPalette[0x3a] = 0x77ac; + gbPalette[0x3b] = 0x14e5; + gbPalette[0x3c] = 0xcf89; + gbPalette[0x3d] = 0xa03d; + gbPalette[0x3e] = 0xfd50; + gbPalette[0x3f] = 0x91ff; + } + else if (gbGBCColorType == 1) // GBA Hardware + { + gbPalette[0x20] = 0xbe00; + gbPalette[0x21] = 0xfdfd; + gbPalette[0x22] = 0xbd69; + gbPalette[0x23] = 0x7baf; + gbPalette[0x24] = 0xf5ff; + gbPalette[0x25] = 0x3f8f; + gbPalette[0x26] = 0xcee5; + gbPalette[0x27] = 0x5bf7; + gbPalette[0x28] = 0xb35b; + gbPalette[0x29] = 0xef97; + gbPalette[0x2a] = 0xef9f; + gbPalette[0x2b] = 0x97f7; + gbPalette[0x2c] = 0x82bf; + gbPalette[0x2d] = 0x9f3d; + gbPalette[0x2e] = 0xddde; + gbPalette[0x2f] = 0xbad5; + gbPalette[0x30] = 0x3cba; + gbPalette[0x31] = 0xdfd7; + gbPalette[0x32] = 0xedea; + gbPalette[0x33] = 0xfeda; + gbPalette[0x34] = 0xf7f9; + gbPalette[0x35] = 0xfdee; + gbPalette[0x36] = 0x6d2f; + gbPalette[0x37] = 0xf0e6; + gbPalette[0x38] = 0xf7f0; + gbPalette[0x39] = 0xf296; + gbPalette[0x3a] = 0x3bf1; + gbPalette[0x3b] = 0xe211; + gbPalette[0x3c] = 0x69ba; + gbPalette[0x3d] = 0x3d0d; + gbPalette[0x3e] = 0xdfd3; + gbPalette[0x3f] = 0xa6ba; + } + else if (gbGBCColorType == 2) // GBASP Hardware + { + gbPalette[0x20] = 0x9c00; + gbPalette[0x21] = 0x6340; + gbPalette[0x22] = 0x10c6; + gbPalette[0x23] = 0xdb97; + gbPalette[0x24] = 0x7622; + gbPalette[0x25] = 0x3e57; + gbPalette[0x26] = 0x2e12; + gbPalette[0x27] = 0x95c3; + gbPalette[0x28] = 0x1095; + gbPalette[0x29] = 0x488c; + gbPalette[0x2a] = 0x8241; + gbPalette[0x2b] = 0xde8c; + gbPalette[0x2c] = 0xfabc; + gbPalette[0x2d] = 0x0e81; + gbPalette[0x2e] = 0x7675; + gbPalette[0x2f] = 0xfdec; + gbPalette[0x30] = 0xddfd; + gbPalette[0x31] = 0x5995; + gbPalette[0x32] = 0x066a; + gbPalette[0x33] = 0xed1e; + gbPalette[0x34] = 0x1e84; + gbPalette[0x35] = 0x1d14; + gbPalette[0x36] = 0x11c3; + gbPalette[0x37] = 0x2749; + gbPalette[0x38] = 0xa727; + gbPalette[0x39] = 0x6266; + gbPalette[0x3a] = 0xe27b; + gbPalette[0x3b] = 0xe3fc; + gbPalette[0x3c] = 0x1f76; + gbPalette[0x3d] = 0xf158; + gbPalette[0x3e] = 0x468e; + gbPalette[0x3f] = 0xa540; + } + } else { + if(gbSgbMode) { + for(int i = 0; i < 8; i++) + gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; + + } + for(int i = 0; i < 8; i++) + gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; + } + + GBTIMER_MODE_0_CLOCK_TICKS = 256; + GBTIMER_MODE_1_CLOCK_TICKS = 4; + GBTIMER_MODE_2_CLOCK_TICKS = 16; + GBTIMER_MODE_3_CLOCK_TICKS = 64; + + GBLY_INCREMENT_CLOCK_TICKS = 114; + gbTimerTicks = GBTIMER_MODE_0_CLOCK_TICKS; + gbTimerClockTicks = GBTIMER_MODE_0_CLOCK_TICKS; gbSerialTicks = 0; gbSerialBits = 0; gbSerialOn = 0; gbWindowLine = -1; - gbTimerOn = 0; + gbTimerOn = false; gbTimerMode = 0; - // gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS; gbSpeed = 0; gbJoymask[0] = gbJoymask[1] = gbJoymask[2] = gbJoymask[3] = 0; if(gbCgbMode) { gbSpeed = 0; gbHdmaOn = 0; - gbHdmaSource = 0x0000; - gbHdmaDestination = 0x8000; + gbHdmaSource = 0x99d0; + gbHdmaDestination = 0x99d0; gbVramBank = 0; gbWramBank = 1; - register_LY = 0x90; - gbLcdMode = 1; - for(int i = 0; i < 64; i++) - gbPalette[i] = 0x7fff; + } - if(gbSgbMode) { + // used to clean the borders + if (gbSgbMode) + { + gbSgbResetFlag = true; gbSgbReset(); + if (gbBorderOn) + gbSgbRenderBorder(); + gbSgbResetFlag = false; } - for(int i =0; i < 4; i++) + for(i = 0; i < 4; i++) gbBgp[i] = gbObp0[i] = gbObp1[i] = i; memset(&gbDataMBC1,0, sizeof(gbDataMBC1)); @@ -1613,7 +2635,23 @@ memset(&gbDataHuC3, 0, sizeof(gbDataHuC3)); gbDataHuC3.mapperROMBank = 1; - gbMemoryMap[0x00] = &gbRom[0x0000]; + memset(&gbDataTAMA5,0, 26*sizeof(int)); + gbDataTAMA5.mapperROMBank = 1; + + memset(&gbDataMMM01,0, sizeof(gbDataMMM01)); + gbDataMMM01.mapperROMBank = 1; + + if (useBios && !skipBios && (gbHardware & 5)) + { + gbMemoryMap[0x00] = &gbMemory[0x0000]; + inBios = true; + } + else + { + gbMemoryMap[0x00] = &gbRom[0x0000]; + inBios = false; + } + gbMemoryMap[0x01] = &gbRom[0x1000]; gbMemoryMap[0x02] = &gbRom[0x2000]; gbMemoryMap[0x03] = &gbRom[0x3000]; @@ -1638,7 +2676,7 @@ gbMemoryMap[0x0c] = &gbMemory[0xc000]; gbMemoryMap[0x0d] = &gbMemory[0xd000]; gbMemoryMap[0x0e] = &gbMemory[0xe000]; - gbMemoryMap[0x0f] = &gbMemory[0xf000]; + gbMemoryMap[0x0f] = &gbMemory[0xf000]; } if(gbRam) { @@ -1652,146 +2690,418 @@ gbLastTime = systemGetClock(); gbFrameCount = 0; + + gbScreenOn = true; + gbSystemMessage = false; + + gbCheatWrite(true); // Emulates GS codes. + } void gbWriteSaveMBC1(const char * name) { - FILE *gzFile = fopen(name,"wb"); + if (gbRam) + { + FILE *gzFile = fopen(name,"wb"); - if(gzFile == NULL) { - systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); - return; - } + if(gzFile == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } - fwrite(gbRam, - 1, - gbRamSize, - gzFile); + fwrite(gbRam, + 1, + (gbRamSizeMask+1), + gzFile); - fclose(gzFile); + fclose(gzFile); + } } void gbWriteSaveMBC2(const char * name) { - FILE *file = fopen(name, "wb"); + if (gbRam) + { + FILE *file = fopen(name, "wb"); - if(file == NULL) { - systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); - return; - } + if(file == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } - fwrite(&gbMemory[0xa000], - 1, - 256, - file); + fwrite(&gbMemory[0xa000], + 1, + 256, + file); - fclose(file); + fclose(file); + } } void gbWriteSaveMBC3(const char * name, bool extendedSave) { + if (gbRam || extendedSave) + { + FILE *gzFile = fopen(name,"wb"); + if (gbRam) + { + + if(gzFile == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } + + fwrite(gbRam, + 1, + (gbRamSizeMask+1), + gzFile); + } + + if(extendedSave) + fwrite(&gbDataMBC3.mapperSeconds, + 1, + 10*sizeof(int) + sizeof(time_t), + gzFile); + + fclose(gzFile); + } +} + +void gbWriteSaveMBC5(const char * name) +{ + if (gbRam) + { + FILE *gzFile = fopen(name,"wb"); + + if(gzFile == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } + + fwrite(gbRam, + 1, + (gbRamSizeMask+1), + gzFile); + + fclose(gzFile); + } +} + +void gbWriteSaveMBC7(const char * name) +{ + if (gbRam) + { + FILE *file = fopen(name, "wb"); + + if(file == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } + + fwrite(&gbMemory[0xa000], + 1, + 256, + file); + + fclose(file); + } +} + +void gbWriteSaveTAMA5(const char * name, bool extendedSave) +{ FILE *gzFile = fopen(name,"wb"); if(gzFile == NULL) { systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); return; } - - fwrite(gbRam, + if (gbRam) + fwrite(gbRam, + 1, + (gbRamSizeMask+1), + gzFile); + + fwrite(gbTAMA5ram, 1, - gbRamSize, + (gbTAMA5ramSize), gzFile); if(extendedSave) - fwrite(&gbDataMBC3.mapperSeconds, + fwrite(&gbDataTAMA5.mapperSeconds, 1, - 10*sizeof(int) + sizeof(time_t), + 14*sizeof(int) + sizeof(time_t), gzFile); fclose(gzFile); } -void gbWriteSaveMBC5(const char * name) +void gbWriteSaveMMM01(const char * name) { - FILE *gzFile = fopen(name,"wb"); + if (gbRam) + { + FILE *gzFile = fopen(name,"wb"); - if(gzFile == NULL) { - systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); - return; - } + if(gzFile == NULL) { + systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); + return; + } - fwrite(gbRam, - 1, - gbRamSize, - gzFile); - - fclose(gzFile); + fwrite(gbRam, + 1, + (gbRamSizeMask+1), + gzFile); + + fclose(gzFile); + } } -void gbWriteSaveMBC7(const char * name) + +bool gbReadSaveMBC1(const char * name) { - FILE *file = fopen(name, "wb"); + if (gbRam) + { + gzFile gzFile = gzopen(name, "rb"); - if(file == NULL) { - systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), name); - return; + if(gzFile == NULL) { + return false; + } + + int read = gzread(gzFile, + gbRam, + (gbRamSizeMask+1)); + + if(read != (gbRamSizeMask+1)) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } + + // Also checks if the battery file it bigger than gbRamSizeMask+1 ! + u8 data[1]; + data[0] = 0; + + read = gzread(gzFile, + data, + 1); + if(read >0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } + + gzclose(gzFile); + return true; } + else + return false; +} - fwrite(&gbMemory[0xa000], - 1, - 256, - file); - fclose(file); +bool gbReadSaveMBC2(const char * name) +{ + if (gbRam) + { + FILE *file = fopen(name, "rb"); + + if(file == NULL) { + return false; + } + + size_t read = fread(&gbMemory[0xa000], + 1, + 256, + file); + + if(read != 256) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + fclose(file); + gbBatteryError = true; + return false; + } + + // Also checks if the battery file it bigger than gbRamSizeMask+1 ! + u8 data[1]; + data[0] = 0; + + read = fread(&data[0], + 1, + 1, + file); + if(read > 0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + fclose(file); + gbBatteryError = true; + return false; + } + + fclose(file); + return true; + } + else + return false; } -bool gbReadSaveMBC1(const char * name) +bool gbReadSaveMBC3(const char * name) { gzFile gzFile = gzopen(name, "rb"); if(gzFile == NULL) { return false; } + + int read = 0; + + if (gbRam) + read = gzread(gzFile, + gbRam, + (gbRamSizeMask+1)); + else + read = (gbRamSizeMask+1); + + + bool res = true; - int read = gzread(gzFile, - gbRam, - gbRamSize); - - if(read != gbRamSize) { - systemMessage(MSG_FAILED_TO_READ_SGM, N_("Failed to read complete save game %s (%d)"), name, read); - gzclose(gzFile); - return false; + if(read != (gbRamSizeMask+1)) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gbBatteryError = true; + res = false; + } else if ((gbRomType == 0xf) || (gbRomType == 0x10)){ + read = gzread(gzFile, + &gbDataMBC3.mapperSeconds, + sizeof(int)*10 + sizeof(time_t)); + + if(read != (sizeof(int)*10 + sizeof(time_t)) && read != 0) { + systemMessage(MSG_FAILED_TO_READ_RTC,N_("Failed to read RTC from save game %s (continuing)"), + name); + res = false; + } + else if (read == 0) + { + systemMessage(MSG_FAILED_TO_READ_RTC,N_("Failed to read RTC from save game %s (continuing)"), + name); + res = false; + } + else + { + // Also checks if the battery file it bigger than gbRamSizeMask+1+RTC ! + u8 data[1]; + data[0] = 0; + + read = gzread(gzFile, + data, + 1); + if(read >0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gbBatteryError = true; + res = false; + } + } } gzclose(gzFile); - return true; + return res; } -bool gbReadSaveMBC2(const char * name) +bool gbReadSaveMBC5(const char * name) { - FILE *file = fopen(name, "rb"); + if (gbRam) + { + gzFile gzFile = gzopen(name, "rb"); - if(file == NULL) { - return false; + if(gzFile == NULL) { + return false; + } + + int read = gzread(gzFile, + gbRam, + (gbRamSizeMask+1)); + + if(read != (gbRamSizeMask+1)) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } + + + // Also checks if the battery file it bigger than gbRamSizeMask+1 ! + u8 data[1]; + data[0] = 0; + + read = gzread(gzFile, + data, + 1); + if(read >0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } + + gzclose(gzFile); + return true; } + else + return false; +} - int read = fread(&gbMemory[0xa000], - 1, - 256, - file); +bool gbReadSaveMBC7(const char * name) +{ + if (gbRam) + { + FILE *file = fopen(name, "rb"); + + if(file == NULL) { + return false; + } + + size_t read = fread(&gbMemory[0xa000], + 1, + 256, + file); + + if(read != 256) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + fclose(file); + gbBatteryError = true; + return false; + } + + // Also checks if the battery file it bigger than gbRamSizeMask+1 ! + u8 data[1]; + data[0] = 0; + + read = fread(&data[0], + 1, + 1, + file); + if(read > 0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + fclose(file); + gbBatteryError = true; + return false; + } - if(read != 256) { - systemMessage(MSG_FAILED_TO_READ_SGM, - N_("Failed to read complete save game %s (%d)"), name, read); fclose(file); - return false; + return true; } - - fclose(file); - return true; + else + return false; } -bool gbReadSaveMBC3(const char * name) +bool gbReadSaveTAMA5(const char * name) { gzFile gzFile = gzopen(name, "rb"); @@ -1799,25 +3109,57 @@ return false; } - int read = gzread(gzFile, - gbRam, - gbRamSize); + int read = 0; + + if (gbRam) + read = gzread(gzFile, + gbRam, + (gbRamSizeMask+1)); + else + read = gbRamSizeMask; + + read += gzread(gzFile, + gbTAMA5ram, + gbTAMA5ramSize); bool res = true; - if(read != gbRamSize) { + if(read != (gbRamSizeMask+gbTAMA5ramSize+1)) { systemMessage(MSG_FAILED_TO_READ_SGM, - N_("Failed to read complete save game %s (%d)"), name, read); + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gbBatteryError = true; + res = false; } else { read = gzread(gzFile, - &gbDataMBC3.mapperSeconds, - sizeof(int)*10 + sizeof(time_t)); + &gbDataTAMA5.mapperSeconds, + sizeof(int)*14 + sizeof(time_t)); - if(read != (sizeof(int)*10 + sizeof(time_t)) && read != 0) { - systemMessage(MSG_FAILED_TO_READ_RTC, - N_("Failed to read RTC from save game %s (continuing)"), - name); - res = false; + if(read != (sizeof(int)*14 + sizeof(time_t)) && read != 0) { + systemMessage(MSG_FAILED_TO_READ_RTC,N_("Failed to read RTC from save game %s (continuing)"), + name); + res = false; + } + else if (read == 0) + { + systemMessage(MSG_FAILED_TO_READ_RTC,N_("Failed to read RTC from save game %s (continuing)"), + name); + res = false; + } + else + { + // Also checks if the battery file it bigger than gbRamSizeMask+1+RTC ! + u8 data[1]; + data[0] = 0; + + read = gzread(gzFile, + data, + 1); + if(read >0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gbBatteryError = true; + res = false; + } } } @@ -1825,51 +3167,49 @@ return res; } -bool gbReadSaveMBC5(const char * name) -{ - gzFile gzFile = gzopen(name, "rb"); - if(gzFile == NULL) { - return false; - } +bool gbReadSaveMMM01(const char * name) +{ + if (gbRam) + { + gzFile gzFile = gzopen(name, "rb"); + + if(gzFile == NULL) { + return false; + } + + int read = gzread(gzFile, + gbRam, + (gbRamSizeMask+1)); + + if(read != (gbRamSizeMask+1)) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } + + // Also checks if the battery file it bigger than gbRamSizeMask+1 ! + u8 data[1]; + data[0] = 0; - int read = gzread(gzFile, - gbRam, - gbRamSize); + read = gzread(gzFile, + data, + 1); + if(read >0) { + systemMessage(MSG_FAILED_TO_READ_SGM, + N_("Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !"), name, read); + gzclose(gzFile); + gbBatteryError = true; + return false; + } - if(read != gbRamSize) { - systemMessage(MSG_FAILED_TO_READ_SGM, - N_("Failed to read complete save game %s (%d)"), name, read); gzclose(gzFile); - return false; - } - - gzclose(gzFile); - return true; -} - -bool gbReadSaveMBC7(const char * name) -{ - FILE *file = fopen(name, "rb"); - - if(file == NULL) { - return false; + return true; } - - int read = fread(&gbMemory[0xa000], - 1, - 256, - file); - - if(read != 256) { - systemMessage(MSG_FAILED_TO_READ_SGM, - N_("Failed to read complete save game %s (%d)"), name, read); - fclose(file); + else return false; - } - - fclose(file); - return true; } void gbInit() @@ -1878,7 +3218,6 @@ gbSgbInit(); gbMemory = (u8 *)malloc(65536); - memset(gbMemory,0, 65536); pix = (u8 *)calloc(1,4*257*226); @@ -1888,20 +3227,23 @@ bool gbWriteBatteryFile(const char *file, bool extendedSave) { if(gbBattery) { - int type = gbRom[0x147]; - - switch(type) { + switch(gbRomType) { case 0x03: gbWriteSaveMBC1(file); break; case 0x06: gbWriteSaveMBC2(file); break; + case 0x0d: + gbWriteSaveMMM01(file); + break; case 0x0f: case 0x10: - case 0x13: gbWriteSaveMBC3(file, extendedSave); break; + case 0x13: + case 0xfc: + gbWriteSaveMBC3(file, false); case 0x1b: case 0x1e: gbWriteSaveMBC5(file); @@ -1909,6 +3251,9 @@ case 0x22: gbWriteSaveMBC7(file); break; + case 0xfd: + gbWriteSaveTAMA5(file, extendedSave); + break; case 0xff: gbWriteSaveMBC1(file); break; @@ -1919,26 +3264,30 @@ bool gbWriteBatteryFile(const char *file) { - gbWriteBatteryFile(file, true); - return true; + if (!gbBatteryError) + { + gbWriteBatteryFile(file, true); + return true; + } + else return false; } bool gbReadBatteryFile(const char *file) { bool res = false; if(gbBattery) { - int type = gbRom[0x147]; - - switch(type) { + switch(gbRomType) { case 0x03: res = gbReadSaveMBC1(file); break; case 0x06: res = gbReadSaveMBC2(file); break; + case 0x0d: + res = gbReadSaveMMM01(file); + break; case 0x0f: case 0x10: - case 0x13: if(!gbReadSaveMBC3(file)) { time(&gbDataMBC3.mapperLastTime); struct tm *lt; @@ -1954,12 +3303,54 @@ } res = true; break; + case 0x13: + case 0xfc: + res = gbReadSaveMBC3(file); case 0x1b: case 0x1e: res = gbReadSaveMBC5(file); break; case 0x22: res = gbReadSaveMBC7(file); + case 0xfd: + if(!gbReadSaveTAMA5(file)) { + u8 gbDaysinMonth [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + time(&gbDataTAMA5.mapperLastTime); + struct tm *lt; + lt = localtime(&gbDataTAMA5.mapperLastTime); + gbDataTAMA5.mapperSeconds = lt->tm_sec; + gbDataTAMA5.mapperMinutes = lt->tm_min; + gbDataTAMA5.mapperHours = lt->tm_hour; + gbDataTAMA5.mapperDays = 1; + gbDataTAMA5.mapperMonths = 1; + gbDataTAMA5.mapperYears = 1970; + int days = lt->tm_yday+365*3; + while (days) + { + gbDataTAMA5.mapperDays++; + days--; + if (gbDataTAMA5.mapperDays>gbDaysinMonth[gbDataTAMA5.mapperMonths-1]) + { + gbDataTAMA5.mapperDays = 1; + gbDataTAMA5.mapperMonths++; + if (gbDataTAMA5.mapperMonths>12) + { + gbDataTAMA5.mapperMonths = 1; + gbDataTAMA5.mapperYears++; + if ((gbDataTAMA5.mapperYears & 3) == 0) + gbDaysinMonth[1] = 29; + else + gbDaysinMonth[1] = 28; + } + } + } + gbDataTAMA5.mapperControl = (gbDataTAMA5.mapperControl & 0xfe) | + (lt->tm_yday > 255 ? 1: 0); + res = false; + break; + } + res = true; + break; case 0xff: res = gbReadSaveMBC1(file); break; @@ -1978,7 +3369,6 @@ return false; } - // long size = ftell(file); fseek(file, 0x4, SEEK_SET); char buffer[16]; char buffer2[16]; @@ -1995,9 +3385,9 @@ return false; } fseek(file, 0x13, SEEK_SET); - int read = 0; + size_t read = 0; int toRead = 0; - switch(gbRom[0x147]) { + switch(gbRomType) { case 0x03: case 0x0f: case 0x10: @@ -2005,8 +3395,8 @@ case 0x1b: case 0x1e: case 0xff: - read = fread(gbRam, 1, gbRamSize, file); - toRead = gbRamSize; + read = fread(gbRam, 1, (gbRamSizeMask+1), file); + toRead = (gbRamSizeMask+1); break; case 0x06: case 0x22: @@ -2053,7 +3443,7 @@ { &gbTimerClockTicks, sizeof(int) }, { &gbSerialTicks, sizeof(int) }, { &gbSerialBits, sizeof(int) }, - { &gbInterrupt, sizeof(int) }, + { &gbInt48Signal, sizeof(int) }, { &gbInterruptWait, sizeof(int) }, { &gbSynchronizeTicks, sizeof(int) }, { &gbTimerOn, sizeof(int) }, @@ -2109,9 +3499,13 @@ static bool gbWriteSaveState(gzFile gzFile) { + utilWriteInt(gzFile, GBSAVE_GAME_VERSION); utilGzWrite(gzFile, &gbRom[0x134], 15); + + utilWriteInt(gzFile, useBios); + utilWriteInt(gzFile, inBios); utilWriteData(gzFile, gbSaveGameStruct); @@ -2120,24 +3514,24 @@ if(gbSgbMode) { gbSgbSaveGame(gzFile); } - + utilGzWrite(gzFile, &gbDataMBC1, sizeof(gbDataMBC1)); utilGzWrite(gzFile, &gbDataMBC2, sizeof(gbDataMBC2)); utilGzWrite(gzFile, &gbDataMBC3, sizeof(gbDataMBC3)); utilGzWrite(gzFile, &gbDataMBC5, sizeof(gbDataMBC5)); utilGzWrite(gzFile, &gbDataHuC1, sizeof(gbDataHuC1)); utilGzWrite(gzFile, &gbDataHuC3, sizeof(gbDataHuC3)); - - // not saved anymore - // gzwrite(gzFile, pix, 256*224*sizeof(u16)); + utilGzWrite(gzFile, &gbDataTAMA5, sizeof(gbDataTAMA5)); + if (gbTAMA5ram != NULL) + utilGzWrite(gzFile, gbTAMA5ram, gbTAMA5ramSize); + utilGzWrite(gzFile, &gbDataMMM01, sizeof(gbDataMMM01)); utilGzWrite(gzFile, gbPalette, 128 * sizeof(u16)); - // todo: remove - utilGzWrite(gzFile, gbPalette, 128 * sizeof(u16)); utilGzWrite(gzFile, &gbMemory[0x8000], 0x8000); if(gbRamSize && gbRam) { + utilWriteInt(gzFile, gbRamSize); utilGzWrite(gzFile, gbRam, gbRamSize); } @@ -2149,7 +3543,19 @@ gbSoundSaveGame(gzFile); gbCheatsSaveGame(gzFile); - + + utilWriteInt(gzFile, gbLcdModeDelayed); + utilWriteInt(gzFile, gbLcdTicksDelayed); + utilWriteInt(gzFile, gbLcdLYIncrementTicksDelayed); + utilWriteInt(gzFile, gbSpritesTicks[299]); + utilWriteInt(gzFile, gbTimerModeChange); + utilWriteInt(gzFile, gbTimerOnChange); + utilWriteInt(gzFile, gbHardware); + utilWriteInt(gzFile, gbBlackScreen); + utilWriteInt(gzFile, oldRegister_WY); + utilWriteInt(gzFile, gbWindowLine); + utilWriteInt(gzFile, inUseRegister_WY); + utilWriteInt(gzFile, gbScreenOn); return true; } @@ -2206,9 +3612,58 @@ romname, &gbRom[0x134]); return false; } + + + bool ub = false; + bool ib = false; + + if (version >= 11) + { + ub = utilReadInt(gzFile) ? true : false; + ib = utilReadInt(gzFile) ? true : false; + + if((ub != useBios) && (ib)) { + if(useBios) + systemMessage(MSG_SAVE_GAME_NOT_USING_BIOS, + N_("Save game is not using the BIOS files")); + else + systemMessage(MSG_SAVE_GAME_USING_BIOS, + N_("Save game is using the BIOS file")); + return false; + } + } + + gbReset(); + + inBios = ib; utilReadData(gzFile, gbSaveGameStruct); + + // Correct crash when loading color gameboy save in regular gameboy type. + if (!gbCgbMode) + { + if(gbVram != NULL) { + free(gbVram); + gbVram = NULL; + } + if(gbWram != NULL) { + free(gbWram); + gbWram = NULL; + } + } + else + { + if(gbVram == NULL) + gbVram = (u8 *)malloc(0x4000); + if(gbWram == NULL) + gbWram = (u8 *)malloc(0x8000); + memset(gbVram,0,0x4000); + memset(gbPalette,0, 2*128); + } + + + if(version >= GBSAVE_GAME_VERSION_7) { utilGzRead(gzFile, &IFF, 2); } @@ -2218,8 +3673,10 @@ } else { gbSgbMask = 0; // loading a game at the wrong time causes no display } - - utilGzRead(gzFile, &gbDataMBC1, sizeof(gbDataMBC1)); + if (version<11) + utilGzRead(gzFile, &gbDataMBC1, sizeof(gbDataMBC1) - sizeof(int)); + else + utilGzRead(gzFile, &gbDataMBC1, sizeof(gbDataMBC1)); utilGzRead(gzFile, &gbDataMBC2, sizeof(gbDataMBC2)); if(version < GBSAVE_GAME_VERSION_4) // prior to version 4, there was no adjustment for the time the game @@ -2231,6 +3688,13 @@ utilGzRead(gzFile, &gbDataMBC5, sizeof(gbDataMBC5)); utilGzRead(gzFile, &gbDataHuC1, sizeof(gbDataHuC1)); utilGzRead(gzFile, &gbDataHuC3, sizeof(gbDataHuC3)); + if (version>=11) + { + utilGzRead(gzFile, &gbDataTAMA5, sizeof(gbDataTAMA5)); + if (gbTAMA5ram != NULL) + utilGzRead(gzFile, gbTAMA5ram, gbTAMA5ramSize); + utilGzRead(gzFile, &gbDataMMM01, sizeof(gbDataMMM01)); + } if(version < GBSAVE_GAME_VERSION_5) { utilGzRead(gzFile, pix, 256*224*sizeof(u16)); @@ -2242,8 +3706,8 @@ } else utilGzRead(gzFile, gbPalette, 128 * sizeof(u16)); - // todo: remove - utilGzRead(gzFile, gbPalette, 128 * sizeof(u16)); + if (version < 11) + utilGzRead(gzFile, gbPalette, 128 * sizeof(u16)); if(version < GBSAVE_GAME_VERSION_10) { if(!gbCgbMode && !gbSgbMode) { @@ -2255,10 +3719,35 @@ utilGzRead(gzFile, &gbMemory[0x8000], 0x8000); if(gbRamSize && gbRam) { - utilGzRead(gzFile, gbRam, gbRamSize); + if (version < 11) + utilGzRead(gzFile, gbRam, gbRamSize); + else + { + int ramSize = utilReadInt(gzFile); + utilGzRead(gzFile, gbRam, (gbRamSize>ramSize) ? ramSize : gbRamSize); + if (ramSize>gbRamSize) + gzseek(gzFile,ramSize-gbRamSize,SEEK_CUR); + } } - - gbMemoryMap[0x00] = &gbRom[0x0000]; + + memset(gbSCYLine, register_SCY, sizeof(gbSCYLine)); + memset(gbSCXLine, register_SCX, sizeof(gbSCXLine)); + memset(gbBgpLine, (gbBgp[0] | (gbBgp[1]<<2) | (gbBgp[2]<<4) | + (gbBgp[3]<<6)), sizeof(gbBgpLine)); + memset(gbObp0Line, (gbObp0[0] | (gbObp0[1]<<2) | (gbObp0[2]<<4) | + (gbObp0[3]<<6)), sizeof(gbObp0Line)); + memset(gbObp1Line, (gbObp1[0] | (gbObp1[1]<<2) | (gbObp1[2]<<4) | + (gbObp1[3]<<6)), sizeof(gbObp1Line)); + memset(gbSpritesTicks, 0x0, sizeof(gbSpritesTicks)); + + if (inBios) + { + gbMemoryMap[0x00] = &gbMemory[0x0000]; + memcpy ((u8 *)(gbMemory), (u8 *)(gbRom), 0x1000); + memcpy ((u8 *)(gbMemory), (u8 *)(bios), 0x100); + } + else + gbMemoryMap[0x00] = &gbRom[0x0000]; gbMemoryMap[0x01] = &gbRom[0x1000]; gbMemoryMap[0x02] = &gbRom[0x2000]; gbMemoryMap[0x03] = &gbRom[0x3000]; @@ -2275,9 +3764,7 @@ gbMemoryMap[0x0e] = &gbMemory[0xe000]; gbMemoryMap[0x0f] = &gbMemory[0xf000]; - int type = gbRom[0x147]; - - switch(type) { + switch(gbRomType) { case 0x00: case 0x01: case 0x02: @@ -2290,6 +3777,12 @@ // MBC2 memoryUpdateMapMBC2(); break; + case 0x0b: + case 0x0c: + case 0x0d: + // MMM01 + memoryUpdateMapMMM01(); + break; case 0x0f: case 0x10: case 0x11: @@ -2314,6 +3807,14 @@ // MBC 7 memoryUpdateMapMBC7(); break; + case 0x56: + // GS3 + memoryUpdateMapGS3(); + break; + case 0xfd: + // TAMA5 + memoryUpdateMapTAMA5(); + break; case 0xfe: // HuC3 memoryUpdateMapHuC3(); @@ -2339,7 +3840,11 @@ gbSoundReadGame(version, gzFile); - if(gbBorderOn) { + if (gbCgbMode && gbSgbMode) { + gbSgbMode = 0; + } + + if(gbBorderOn && !gbSgbMask) { gbSgbRenderBorder(); } @@ -2348,6 +3853,85 @@ if(version > GBSAVE_GAME_VERSION_1) gbCheatsReadGame(gzFile, version); + if (version<11) + { + gbWriteMemory(0xff00, 0); + gbMemory[0xff04] = register_DIV; + gbMemory[0xff05] = register_TIMA; + gbMemory[0xff06] = register_TMA; + gbMemory[0xff07] = register_TAC; + gbMemory[0xff40] = register_LCDC; + gbMemory[0xff42] = register_SCY; + gbMemory[0xff43] = register_SCX; + gbMemory[0xff44] = register_LY; + gbMemory[0xff45] = register_LYC; + gbMemory[0xff46] = register_DMA; + gbMemory[0xff4a] = register_WY; + gbMemory[0xff4b] = register_WX; + gbMemory[0xff4f] = register_VBK; + gbMemory[0xff51] = register_HDMA1; + gbMemory[0xff52] = register_HDMA2; + gbMemory[0xff53] = register_HDMA3; + gbMemory[0xff54] = register_HDMA4; + gbMemory[0xff55] = register_HDMA5; + gbMemory[0xff70] = register_SVBK; + gbMemory[0xffff] = register_IE; + GBDIV_CLOCK_TICKS = 64; + + if (gbSpeed) + gbDivTicks /=2; + + if ((gbLcdMode == 0) && (register_STAT & 8)) + gbInt48Signal |= 1; + if ((gbLcdMode == 1) && (register_STAT & 0x10)) + gbInt48Signal |= 2; + if ((gbLcdMode == 2) && (register_STAT & 0x20)) + gbInt48Signal |= 4; + if ((register_LY==register_LYC) && (register_STAT & 0x40)) + gbInt48Signal |= 8; + + gbLcdLYIncrementTicks = GBLY_INCREMENT_CLOCK_TICKS; + + if (gbLcdMode == 2) + gbLcdLYIncrementTicks-=GBLCD_MODE_2_CLOCK_TICKS-gbLcdTicks; + else if (gbLcdMode == 3) + gbLcdLYIncrementTicks -=GBLCD_MODE_2_CLOCK_TICKS+GBLCD_MODE_3_CLOCK_TICKS-gbLcdTicks; + else if (gbLcdMode == 0) + gbLcdLYIncrementTicks =gbLcdTicks; + else if (gbLcdMode == 1) + { + gbLcdLYIncrementTicks = gbLcdTicks % GBLY_INCREMENT_CLOCK_TICKS; + if (register_LY == 0x99) + gbLcdLYIncrementTicks =gbLine99Ticks; + else if (register_LY == 0) + gbLcdLYIncrementTicks += GBLY_INCREMENT_CLOCK_TICKS; + } + + gbLcdModeDelayed = gbLcdMode; + gbLcdTicksDelayed = gbLcdTicks--; + gbLcdLYIncrementTicksDelayed = gbLcdLYIncrementTicks--; + gbInterruptWait = 0; + memset(gbSpritesTicks,0,sizeof(gbSpritesTicks)); + } + else + { + gbLcdModeDelayed = utilReadInt(gzFile); + gbLcdTicksDelayed = utilReadInt(gzFile); + gbLcdLYIncrementTicksDelayed = utilReadInt(gzFile); + gbSpritesTicks[299] = utilReadInt(gzFile) & 0xff; + gbTimerModeChange = (utilReadInt(gzFile) ? true : false); + gbTimerOnChange = (utilReadInt(gzFile) ? true : false); + gbHardware = utilReadInt(gzFile); + gbBlackScreen = (utilReadInt(gzFile) ? true : false); + oldRegister_WY = utilReadInt(gzFile); + gbWindowLine = utilReadInt(gzFile); + inUseRegister_WY = utilReadInt(gzFile); + gbScreenOn = (utilReadInt(gzFile) ? true : false); + } + + if (gbSpeed) + gbLine99Ticks *= 2; + systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; return true; @@ -2432,13 +4016,18 @@ gbWram = NULL; } + if(gbTAMA5ram != NULL) { + free(gbTAMA5ram); + gbTAMA5ram = NULL; + } + systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; } bool gbLoadRom(const char *szFile) { int size = 0; - + if(gbRom != NULL) { gbCleanUp(); } @@ -2453,6 +4042,14 @@ return false; gbRomSize = size; + + gbBatteryError = false; + + if(bios != NULL) { + free(bios); + bios = NULL; + } + bios = (u8 *)calloc(1,0x100); return gbUpdateSizes(); } @@ -2467,36 +4064,103 @@ if(gbRomSize < gbRomSizes[gbRom[0x148]]) { gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]); + for (int i = gbRomSize; igbRomSizes[gbRom[0x148]]) && (genericflashcardEnable)) + { + gbRomSize = gbRomSize>>16; + gbRom[0x148] = 0; + if (gbRomSize) + { + while (!((gbRomSize & 1) || (gbRom[0x148] == 7))) + { + gbRom[0x148]++; + gbRomSize>>=1; + } + gbRom[0x148]++; + } + gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]); } gbRomSize = gbRomSizes[gbRom[0x148]]; gbRomSizeMask = gbRomSizesMasks[gbRom[0x148]]; - if(gbRom[0x149] > 5) { + + // The 'genericflashcard' option allows some PD to work. + // However, the setting is dangerous (if you let in enabled + // and play a normal game, it might just break everything). + // That's why it is not saved in the emulator options. + // Also I added some checks in VBA to make sure your saves will not be + // overwritten if you wrongly enable this option for a game + // you already played (and vice-versa, ie. if you forgot to + // enable the option for a game you played with it enabled, like Shawu Story). + u8 ramsize = genericflashcardEnable ? 5 : gbRom[0x149]; + gbRom[0x149] = ramsize; + + if ((gbRom[2] == 0x6D) && (gbRom[5] == 0x47) && (gbRom[6] == 0x65) && (gbRom[7] == 0x6E) && + (gbRom[8] == 0x69) && (gbRom[9] == 0x65) && (gbRom[0xA] == 0x28) && (gbRom[0xB] == 0x54)) + { + gbCheatingDevice = 1; // GameGenie + for (int i = 0; i < 0x20; i++) // Cleans GG hardware registers + gbRom[0x4000+i] = 0; + } + else if (((gbRom[0x104] == 0x44) && (gbRom[0x156] == 0xEA) && (gbRom[0x158] == 0x7F) && + (gbRom[0x159] == 0xEA) && (gbRom[0x15B] == 0x7F)) || ((gbRom[0x165] == 0x3E) && + (gbRom[0x166] == 0xD9) && (gbRom[0x16D] == 0xE1) && (gbRom[0x16E] == 0x7F))) + gbCheatingDevice = 2; // GameShark + else gbCheatingDevice = 0; + + if(ramsize > 5) { systemMessage(MSG_UNSUPPORTED_RAM_SIZE, N_("Unsupported ram size %02x"), gbRom[0x149]); return false; } - gbRamSize = gbRamSizes[gbRom[0x149]]; - gbRamSizeMask = gbRamSizesMasks[gbRom[0x149]]; + gbRamSize = gbRamSizes[ramsize]; + gbRamSizeMask = gbRamSizesMasks[ramsize]; if(gbRamSize) { gbRam = (u8 *)malloc(gbRamSize); - memset(gbRam, 0xFF, gbRamSize); + memset(gbRam, 0xff, gbRamSize); } - int type = gbRom[0x147]; + + gbRomType = gbRom[0x147]; + if (genericflashcardEnable) + { + /*if (gbRomType<2) + gbRomType =3; + else if ((gbRomType == 0xc) || (gbRomType == 0xf) || (gbRomType == 0x12) || + (gbRomType == 0x16) || (gbRomType == 0x1a) || (gbRomType == 0x1d)) + gbRomType++; + else if ((gbRomType == 0xb) || (gbRomType == 0x11) || (gbRomType == 0x15) || + (gbRomType == 0x19) || (gbRomType == 0x1c)) + gbRomType+=2; + else if ((gbRomType == 0x5) || (gbRomType == 0x6)) + gbRomType = 0x1a;*/ + gbRomType = 0x1b; + } + else if (gbCheatingDevice == 1) + gbRomType = 0x55; + else if (gbCheatingDevice == 2) + gbRomType = 0x56; + + gbRom[0x147] = gbRomType; mapperReadRAM = NULL; - switch(type) { + switch(gbRomType) { case 0x00: case 0x01: case 0x02: case 0x03: + case 0x08: + case 0x09: // MBC 1 mapper = mapperMBC1ROM; mapperRAM = mapperMBC1RAM; + mapperReadRAM = mapperMBC1ReadRAM; break; case 0x05: case 0x06: @@ -2506,11 +4170,19 @@ gbRamSize = 0x200; gbRamSizeMask = 0x1ff; break; + case 0x0b: + case 0x0c: + case 0x0d: + // MMM01 + mapper = mapperMMM01ROM; + mapperRAM = mapperMMM01RAM; + break; case 0x0f: case 0x10: case 0x11: case 0x12: case 0x13: + case 0xfc: // MBC 3 mapper = mapperMBC3ROM; mapperRAM = mapperMBC3RAM; @@ -2522,6 +4194,7 @@ // MBC5 mapper = mapperMBC5ROM; mapperRAM = mapperMBC5RAM; + mapperReadRAM = mapperMBC5ReadRAM; break; case 0x1c: case 0x1d: @@ -2529,6 +4202,7 @@ // MBC 5 Rumble mapper = mapperMBC5ROM; mapperRAM = mapperMBC5RAM; + mapperReadRAM = mapperMBC5ReadRAM; break; case 0x22: // MBC 7 @@ -2536,6 +4210,38 @@ mapperRAM = mapperMBC7RAM; mapperReadRAM = mapperMBC7ReadRAM; break; + // GG (GameGenie) + case 0x55: + mapper = mapperGGROM; + break; + case 0x56: + // GS (GameShark) + mapper = mapperGS3ROM; + break; + case 0xfd: + // TAMA5 + if (gbRam!= NULL) + { + free(gbRam); + gbRam = NULL; + } + + ramsize = 3; + gbRamSize = gbRamSizes[3]; + gbRamSizeMask = gbRamSizesMasks[3]; + gbRam = (u8 *)malloc(gbRamSize); + memset(gbRam, 0x0, gbRamSize); + + gbTAMA5ramSize = 0x100; + + if (gbTAMA5ram == NULL) + gbTAMA5ram = (u8 *)malloc(gbTAMA5ramSize); + memset(gbTAMA5ram, 0x0, gbTAMA5ramSize); + + mapperRAM = mapperTAMA5RAM; + mapperReadRAM = mapperTAMA5ReadRAM; + mapperUpdateClock = memoryUpdateTAMA5Clock; + break; case 0xfe: // HuC3 mapper = mapperHuC3ROM; @@ -2549,11 +4255,11 @@ break; default: systemMessage(MSG_UNKNOWN_CARTRIDGE_TYPE, - N_("Unknown cartridge type %02x"), type); + N_("Unknown cartridge type %02x"), gbRomType); return false; } - switch(type) { + switch(gbRomType) { case 0x03: case 0x06: case 0x0f: @@ -2563,42 +4269,17 @@ case 0x1d: case 0x1e: case 0x22: + case 0xfd: case 0xff: gbBattery = 1; break; } - if(gbRom[0x146] == 0x03) { - if(gbEmulatorType == 0 || - gbEmulatorType == 2 || - gbEmulatorType == 5) - gbSgbMode = 1; - else - gbSgbMode = 0; - } else - gbSgbMode = 0; - - if(gbRom[0x143] & 0x80) { - if(gbEmulatorType == 0 || - gbEmulatorType == 1 || - gbEmulatorType == 4 || - gbEmulatorType == 5) { - gbCgbMode = 1; - gbVram = (u8 *)malloc(0x4000); - gbWram = (u8 *)malloc(0x8000); - memset(gbVram,0,0x4000); - memset(gbWram,0,0x8000); - memset(gbPalette,0, 2*128); - } else { - gbCgbMode = 0; - } - } else - gbCgbMode = 0; - gbInit(); - gbReset(); - switch(type) { + //gbReset(); + + switch(gbRomType) { case 0x1c: case 0x1d: case 0x1e: @@ -2608,16 +4289,163 @@ return true; } +int gbGetNextEvent (int clockTicks) +{ + if (register_LCDC & 0x80) + { + if(gbLcdTicks < clockTicks) + clockTicks = gbLcdTicks; + + if(gbLcdTicksDelayed < clockTicks) + clockTicks = gbLcdTicksDelayed; + + if(gbLcdLYIncrementTicksDelayed < clockTicks) + clockTicks = gbLcdLYIncrementTicksDelayed; + } + + if(gbLcdLYIncrementTicks < clockTicks) + clockTicks = gbLcdLYIncrementTicks; + + if(gbSerialOn && (gbSerialTicks < clockTicks)) + clockTicks = gbSerialTicks; + + if(gbTimerOn && (((gbInternalTimer) & gbTimerMask[gbTimerMode])+1 < clockTicks)) + clockTicks = ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1; + + if(soundTicks && (soundTicks < clockTicks)) + clockTicks = soundTicks; + + if ((clockTicks<=0) || (gbInterruptWait)) + clockTicks = 1; + + return clockTicks; +} + +void gbDrawLine() +{ + switch(systemColorDepth) { + case 16: + { + u16 * dest = (u16 *)pix + + (gbBorderLineSkip+2) * (register_LY + gbBorderRowSkip+1) + + gbBorderColumnSkip; + for(int x = 0; x < 160; ) { + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + *dest++ = systemColorMap16[gbLineMix[x++]]; + } + if(gbBorderOn) + dest += gbBorderColumnSkip; + *dest++ = 0; // for filters that read one pixel more + } + break; + + case 24: + { + u8 *dest = (u8 *)pix + + 3*(gbBorderLineSkip * (register_LY + gbBorderRowSkip) + + gbBorderColumnSkip); + for(int x = 0; x < 160;) { + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; + dest+= 3; + } + } + break; + + case 32: + { + u32 * dest = (u32 *)pix + + (gbBorderLineSkip+1) * (register_LY + gbBorderRowSkip+1) + + gbBorderColumnSkip; + for(int x = 0; x < 160;) { + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + *dest++ = systemColorMap32[gbLineMix[x++]]; + } + } + break; + } +} + void gbEmulate(int ticksToStop) { gbRegister tempRegister; u8 tempValue; s8 offset; - int clockTicks = 0; + clockTicks = 0; gbDmaTicks = 0; register int opcode = 0; + + int opcode1 = 0; + int opcode2 = 0; + bool execute = false; while(1) { #ifndef FINAL_VERSION @@ -2633,29 +4461,53 @@ } } #endif + + u16 oldPCW = PC.W; + if(IFF & 0x80) { if(register_LCDC & 0x80) { - clockTicks = gbLcdTicks; + clockTicks = gbLcdTicks; } else - clockTicks = 100; + clockTicks = 1000; + + clockTicks = gbGetNextEvent(clockTicks); + + /*if(gbLcdTicksDelayed < clockTicks) + clockTicks = gbLcdTicksDelayed; + + if(gbLcdLYIncrementTicksDelayed < clockTicks) + clockTicks = gbLcdLYIncrementTicksDelayed; - if(gbLcdMode == 1 && (gbLcdLYIncrementTicks < clockTicks)) + if(gbLcdLYIncrementTicks < clockTicks) clockTicks = gbLcdLYIncrementTicks; if(gbSerialOn && (gbSerialTicks < clockTicks)) clockTicks = gbSerialTicks; - if(gbTimerOn && (gbTimerTicks < clockTicks)) - clockTicks = gbTimerTicks; + if(gbTimerOn && (((gbInternalTimer) & gbTimerMask[gbTimerMode])+1 < clockTicks)) + clockTicks = ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1; if(soundTicks && (soundTicks < clockTicks)) clockTicks = soundTicks; - } else { - opcode = gbReadOpcode(PC.W++); + + if ((clockTicks<=0) || (gbInterruptWait)) + clockTicks = 1;*/ - if(IFF & 0x100) { - IFF &= 0xff; + } else { + + // First we apply the clockTicks, then we execute the opcodes. + opcode1 = 0; + opcode2 = 0; + execute = true; + + opcode2 = opcode1 = opcode = gbReadOpcode(PC.W++); + + // If HALT state was launched while IME = 0 and (register_IF & register_IE & 0x1F), + // PC.W is not incremented for the first byte of the next instruction. + if (IFF & 2) + { PC.W--; + IFF &= ~2; } clockTicks = gbCycles[opcode]; @@ -2663,24 +4515,66 @@ switch(opcode) { case 0xCB: // extended opcode - opcode = gbReadOpcode(PC.W++); + opcode2 = opcode = gbReadOpcode(PC.W++); clockTicks = gbCyclesCB[opcode]; - switch(opcode) { -#include "gbCodesCB.h" - } - break; -#include "gbCodes.h" + break; } + gbOldClockTicks = clockTicks-1; + gbIntBreak = 1; + } + + + if(!emulating) + return; + + // For 'breakpoint' support (opcode 0xFC is considered as a breakpoint) + if ((clockTicks==0) && execute) + { + PC.W = oldPCW; + return; + } + + + if (!(IFF & 0x80)) + clockTicks = 1; + + gbRedoLoop: + + + + if (gbInterruptWait) + gbInterruptWait = 0; + else + gbInterruptLaunched = 0; + + + // Used for the EI/DI instruction's delay. + if (IFF & 0x38) + { + int tempIFF = (IFF >> 4) & 3; + + if (tempIFF <=clockTicks) + { + tempIFF = 0; + IFF |=1; + } + else + tempIFF -= clockTicks; + IFF = (IFF & 0xCF) | (tempIFF <<4); + + if (IFF & 0x08) + IFF &= 0x82; } - if(!emulating) - return; - if(gbDmaTicks) { - clockTicks += gbDmaTicks; - gbDmaTicks = 0; + if (register_LCDCBusy) + { + register_LCDCBusy-=clockTicks; + if (register_LCDCBusy<0) + register_LCDCBusy = 0; } + if(gbSgbMode) { if(gbSgbPacketTimeout) { gbSgbPacketTimeout -= clockTicks; @@ -2695,79 +4589,528 @@ // DIV register emulation gbDivTicks -= clockTicks; while(gbDivTicks <= 0) { - register_DIV++; + gbMemory[0xff04] = ++register_DIV; gbDivTicks += GBDIV_CLOCK_TICKS; } if(register_LCDC & 0x80) { // LCD stuff + gbLcdTicks -= clockTicks; - if(gbLcdMode == 1) { - // during V-BLANK,we need to increment LY at the same rate! - gbLcdLYIncrementTicks -= clockTicks; - while(gbLcdLYIncrementTicks <= 0) { + gbLcdTicksDelayed -= clockTicks; + gbLcdLYIncrementTicks -= clockTicks; + gbLcdLYIncrementTicksDelayed -= clockTicks; + + + // our counters are off, see what we need to do + + // This looks (and kinda is) complicated, however this + // is the only way I found to emulate properly the way + // the real hardware operates... + while(((gbLcdTicks <= 0) && (gbLCDChangeHappened == false)) || + ((gbLcdTicksDelayed <= 0) && (gbLCDChangeHappened == true)) || + ((gbLcdLYIncrementTicks <= 0) && (gbLYChangeHappened == false)) || + ((gbLcdLYIncrementTicksDelayed<=0) && (gbLYChangeHappened == true))) + { + + if ((gbLcdLYIncrementTicks <= 0) && (!gbLYChangeHappened)) + { + gbLYChangeHappened = true; + gbMemory[0xff44] = register_LY = (register_LY + 1) % 154; + + if (register_LY == 0x91) + { + /* if (IFF & 0x80) + gbScreenOn = !gbScreenOn; + else*/ if (register_LCDC & 0x80) + gbScreenOn = true; + } + gbLcdLYIncrementTicks += GBLY_INCREMENT_CLOCK_TICKS; - if(register_LY < 153) { - register_LY++; - - gbCompareLYToLYC(); - - if(register_LY >= 153) - gbLcdLYIncrementTicks = 6; - } else { - register_LY = 0x00; - // reset the window line - gbWindowLine = -1; - gbLcdLYIncrementTicks = GBLY_INCREMENT_CLOCK_TICKS * 2; - gbCompareLYToLYC(); + if (gbLcdMode == 1) + { + + if(register_LY == 153) + gbLcdLYIncrementTicks -= GBLY_INCREMENT_CLOCK_TICKS - gbLine99Ticks; + else if(register_LY == 0) + gbLcdLYIncrementTicks += GBLY_INCREMENT_CLOCK_TICKS - gbLine99Ticks; + } + + // GB only 'bug' : Halt state is broken one tick before LY==LYC interrupt + // is reflected in the registers. + if ((gbHardware & 5) && (IFF & 0x80) && (register_LY == register_LYC) + && (register_STAT & 0x40) && (register_LY != 0)) + { + if (!((gbLcdModeDelayed != 1) && (register_LY==0))) + { + gbInt48Signal &= ~9; + gbCompareLYToLYC(); + gbLYChangeHappened = false; + gbMemory[0xff41] = register_STAT; + gbMemory[0xff0f] = register_IF; + } + + gbLcdLYIncrementTicksDelayed += GBLY_INCREMENT_CLOCK_TICKS - gbLine99Ticks+1; } } - } + + + if ((gbLcdTicks <= 0) && (!gbLCDChangeHappened)) + { + gbLCDChangeHappened = true; + + switch(gbLcdMode) + { + case 0: + { + // H-Blank + // check if we reached the V-Blank period + if(register_LY == 144) { + // Yes, V-Blank + // set the LY increment counter + if (gbHardware & 0x5) + { + register_IF |= 1; // V-Blank interrupt + } + + gbInt48Signal &= ~6; + if(register_STAT & 0x10) + { + // send LCD interrupt only if no interrupt 48h signal... + if ((!(gbInt48Signal & 1)) && ((!(gbInt48Signal & 8)) || (gbHardware & 0x0a))) + { + register_IF |=2; + gbInterruptLaunched |= 2; + if (gbHardware & 0xa) + gbInterruptWait = 1; + } + gbInt48Signal |= 2; + } + gbInt48Signal &= ~1; + + gbLcdTicks += GBLCD_MODE_1_CLOCK_TICKS; + gbLcdMode = 1; + + } else { + // go the the OAM being accessed mode + gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS; + gbLcdMode = 2; + + gbInt48Signal &= ~6; + if(register_STAT & 0x20) + { + // send LCD interrupt only if no interrupt 48h signal... + if (!gbInt48Signal) + { + register_IF |= 2; + gbInterruptLaunched |= 2; + } + gbInt48Signal |= 4; + } + gbInt48Signal &= ~1; + } + } + break; + case 1: + { + // V-Blank + // next mode is OAM being accessed mode + gbInt48Signal &= ~5; + if(register_STAT & 0x20) + { + // send LCD interrupt only if no interrupt 48h signal... + if (!gbInt48Signal) + { + register_IF |= 2; + gbInterruptLaunched |= 2; + if ((gbHardware & 0xa) && (IFF & 0x80)) + gbInterruptWait = 1; + } + gbInt48Signal |= 4; + } + gbInt48Signal &= ~2; + + gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS; + + gbLcdMode = 2; + register_LY = 0x00; + + } + break; + case 2: + { + + // OAM being accessed mode + // next mode is OAM and VRAM in use + if ((gbScreenOn) && (register_LCDC & 0x80)) + { + gbDrawSprites(false); + // Used to add a one tick delay when a window line is drawn. + //(fixes a part of Carmaggedon problem) + if((register_LCDC & 0x01 || gbCgbMode) && (register_LCDC & 0x20) && + (gbWindowLine != -2)) { + + int inUseRegister_WY = 0; + int tempgbWindowLine = gbWindowLine; + + if ((tempgbWindowLine == -1) || (tempgbWindowLine>144)) + { + inUseRegister_WY = oldRegister_WY; + if (register_LY>oldRegister_WY) + tempgbWindowLine = 146; + } + + int wy = inUseRegister_WY; - // our counter is off, see what we need to do - while(gbLcdTicks <= 0) { - int framesToSkip = systemFrameSkip; - if(speedup) - framesToSkip = 9; // try 6 FPS during speedup - switch(gbLcdMode) { - case 0: - // H-Blank - register_LY++; + if(register_LY >= inUseRegister_WY) { - gbCompareLYToLYC(); + if (tempgbWindowLine == -1) + tempgbWindowLine = 0; + + int wx = register_WX; + wx -= 7; + if (wx<0) + wx = 0; + + if((wx <= 159) && (tempgbWindowLine <= 143)) + for (int i = wx; i<300; i++) + if (gbSpeed) + gbSpritesTicks[i]+=3; + else + gbSpritesTicks[i]+=1; + } + } + } + + gbInt48Signal &= ~7; + + gbLcdTicks += GBLCD_MODE_3_CLOCK_TICKS+gbSpritesTicks[299]; + gbLcdMode = 3; + } + break; + case 3: + { + // OAM and VRAM in use + // next mode is H-Blank + + + gbInt48Signal &= ~7; + if(register_STAT & 0x08) + { + // send LCD interrupt only if no interrupt 48h signal... + if (!(gbInt48Signal & 8)) + { + register_IF |= 2; + if ((gbHardware & 0xa) && (IFF & 0x80)) + gbInterruptWait = 1; + } + gbInt48Signal |= 1; + } + + gbLcdTicks += GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]; + + gbLcdMode = 0; + + // No HDMA during HALT ! + if(gbHdmaOn && (!(IFF & 0x80) || (register_IE & register_IF & 0x1f))) { + gbDoHdma(); + } + + } + break; + } + } + + + if ((gbLcdTicksDelayed <= 0) && (gbLCDChangeHappened)) { + int framesToSkip = systemFrameSkip; + if(speedup) + framesToSkip = 9; // try 6 FPS during speedup + //gbLcdTicksDelayed = gbLcdTicks+1; + gbLCDChangeHappened = false; + switch(gbLcdModeDelayed) { + case 0: + { + // H-Blank - // check if we reached the V-Blank period - if(register_LY == 144) { - // Yes, V-Blank - // set the LY increment counter - gbLcdLYIncrementTicks = gbLcdTicks + GBLY_INCREMENT_CLOCK_TICKS; - gbLcdTicks += GBLCD_MODE_1_CLOCK_TICKS; - gbLcdMode = 1; - if(register_LCDC & 0x80) { - gbInterrupt |= 1; // V-Blank interrupt - gbInterruptWait = 6; - if(register_STAT & 0x10) - gbInterrupt |= 2; + memset(gbSCYLine,gbSCYLine[299],sizeof(gbSCYLine)); + memset(gbSCXLine,gbSCXLine[299],sizeof(gbSCXLine)); + memset(gbBgpLine,gbBgpLine[299],sizeof(gbBgpLine)); + memset(gbObp0Line,gbObp0Line[299],sizeof(gbObp0Line)); + memset(gbObp1Line,gbObp1Line[299],sizeof(gbObp1Line)); + memset(gbSpritesTicks,gbSpritesTicks[299],sizeof(gbSpritesTicks)); + + if (gbWindowLine <0) + oldRegister_WY = register_WY; + // check if we reached the V-Blank period + if(register_LY == 144) { + // Yes, V-Blank + // set the LY increment counter + + if(register_LCDC & 0x80) { + if (gbHardware & 0xa) + { + + register_IF |= 1; // V-Blank interrupt + gbInterruptLaunched |=1; + } + + + } + + gbLcdTicksDelayed += GBLCD_MODE_1_CLOCK_TICKS; + gbLcdModeDelayed = 1; + + gbFrameCount++; + systemFrame(); + + if((gbFrameCount % 10) == 0) + system10Frames(60); + + if(gbFrameCount >= 60) { + u32 currentTime = systemGetClock(); + if(currentTime != gbLastTime) + systemShowSpeed(100000/(currentTime - gbLastTime)); + else + systemShowSpeed(0); + gbLastTime = currentTime; + gbFrameCount = 0; + } + + if(systemReadJoypads()) { + // read joystick + if(gbSgbMode && gbSgbMultiplayer) { + if(gbSgbFourPlayers) { + gbJoymask[0] = systemReadJoypad(0); + gbJoymask[1] = systemReadJoypad(1); + gbJoymask[2] = systemReadJoypad(2); + gbJoymask[3] = systemReadJoypad(3); + } else { + gbJoymask[0] = systemReadJoypad(0); + gbJoymask[1] = systemReadJoypad(1); + } + } else { + gbJoymask[0] = systemReadJoypad(-1); + } + } + int newmask = gbJoymask[0] & 255; + + if(gbRomType == 0x22) { + systemUpdateMotionSensor(); + } + + if(newmask) + { + gbMemory[0xff0f] |= 16; + } + + + newmask = (gbJoymask[0] >> 10); + + speedup = (newmask & 1) ? true : false; + gbCapture = (newmask & 2) ? true : false; + + if(gbCapture && !gbCapturePrevious) { + gbCaptureNumber++; + systemScreenCapture(gbCaptureNumber); + } + gbCapturePrevious = gbCapture; + + if(gbFrameSkipCount >= framesToSkip) { + + if(!gbSgbMask) + { + if (gbBorderOn) + gbSgbRenderBorder(); + //if (gbScreenOn) + systemDrawScreen(); } + gbFrameSkipCount = 0; + } else + gbFrameSkipCount++; - gbFrameCount++; + } else { + // go the the OAM being accessed mode + gbLcdTicksDelayed += GBLCD_MODE_2_CLOCK_TICKS; + gbLcdModeDelayed = 2; + gbInt48Signal &= ~3; + } + } + break; + case 1: + { + // V-Blank + // next mode is OAM being accessed mode - systemFrame(); + // gbScreenOn = true; - if((gbFrameCount % 10) == 0) - system10Frames(60); + oldRegister_WY = register_WY; - if(gbFrameCount >= 60) { - u32 currentTime = systemGetClock(); - if(currentTime != gbLastTime) - systemShowSpeed(100000/(currentTime - gbLastTime)); - else - systemShowSpeed(0); - gbLastTime = currentTime; - gbFrameCount = 0; + gbLcdTicksDelayed += GBLCD_MODE_2_CLOCK_TICKS; + gbLcdModeDelayed = 2; + + // reset the window line + gbWindowLine = -1; + } + break; + case 2: + { + // OAM being accessed mode + // next mode is OAM and VRAM in use + gbLcdTicksDelayed += GBLCD_MODE_3_CLOCK_TICKS+gbSpritesTicks[299]; + gbLcdModeDelayed = 3; + } + break; + case 3: + { + + // OAM and VRAM in use + // next mode is H-Blank + if((register_LY < 144) && (register_LCDC & 0x80) && gbScreenOn) { + if(!gbSgbMask) { + if(gbFrameSkipCount >= framesToSkip) { + if (!gbBlackScreen) + { + gbRenderLine(); + gbDrawSprites(true); + } + else if (gbBlackScreen) + { + u16 color = gbColorOption ? gbColorFilter[0] : 0; + if (!gbCgbMode) + color = gbColorOption ? gbColorFilter[gbPalette[3] & 0x7FFF] : + gbPalette[3] & 0x7FFF; + for(int i = 0; i < 160; i++) + { + gbLineMix[i] = color; + gbLineBuffer[i] = 0; + } + } + gbDrawLine(); + } + } + } + gbLcdTicksDelayed += GBLCD_MODE_0_CLOCK_TICKS-gbSpritesTicks[299]; + gbLcdModeDelayed = 0; + } + break; + } + } + + if ((gbLcdLYIncrementTicksDelayed <= 0) && (gbLYChangeHappened == true)) + { + + gbLYChangeHappened = false; + + if (!((gbLcdMode != 1) && (register_LY==0))) + { + { + gbInt48Signal &= ~8; + gbCompareLYToLYC(); + if ((gbInt48Signal == 8) && (!((register_LY == 0) && (gbHardware & 1)))) + gbInterruptLaunched |= 2; + if ((gbHardware & (gbSpeed ? 8 : 2)) && (register_LY==0) && ((register_STAT & 0x44) == 0x44) && (gbLcdLYIncrementTicksDelayed==0)) + { + gbInterruptWait = 1; + + } + } + } + gbLcdLYIncrementTicksDelayed += GBLY_INCREMENT_CLOCK_TICKS; + + if (gbLcdModeDelayed == 1) + { + + if(register_LY == 153) + gbLcdLYIncrementTicksDelayed -= GBLY_INCREMENT_CLOCK_TICKS - gbLine99Ticks; + else if(register_LY == 0) + gbLcdLYIncrementTicksDelayed += GBLY_INCREMENT_CLOCK_TICKS - gbLine99Ticks; + } + gbMemory[0xff0f] = register_IF; + gbMemory[0xff41] = register_STAT; + } + } + gbMemory[0xff0f] = register_IF; + gbMemory[0xff41] = register_STAT = (register_STAT & 0xfc) | gbLcdModeDelayed; + } + else + { + + // Used to update the screen with white lines when it's off. + // (it looks strange, but it's kinda accurate :p) + // You can try the Mario Demo Vx.x for exemple + // (check the bottom 2 lines while moving) + if (!gbWhiteScreen) + { + gbScreenTicks -= clockTicks; + gbLcdLYIncrementTicks -= clockTicks; + while (gbLcdLYIncrementTicks <=0) + { + register_LY = ((register_LY+1)%154); + gbLcdLYIncrementTicks+=GBLY_INCREMENT_CLOCK_TICKS; + } + if (gbScreenTicks <= 0) + { + gbWhiteScreen = 1; + u8 register_LYLcdOff = ((register_LY+154)%154); + for (register_LY=0;register_LY <= 0x90;register_LY++) + { + u16 color = gbColorOption ? gbColorFilter[0x7FFF] : + 0x7FFF; + if (!gbCgbMode) + color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] : + gbPalette[0] & 0x7FFF; + for(int i = 0; i < 160; i++) + { + gbLineMix[i] = color; + gbLineBuffer[i] = 0; } + gbDrawLine(); + } + register_LY = register_LYLcdOff; + } + } + + if (gbWhiteScreen) + { + gbLcdLYIncrementTicks -= clockTicks; + while (gbLcdLYIncrementTicks <=0) + { + register_LY = ((register_LY+1)%154); + gbLcdLYIncrementTicks+=GBLY_INCREMENT_CLOCK_TICKS; + if (register_LY<144) + { + + u16 color = gbColorOption ? gbColorFilter[0x7FFF] : + 0x7FFF; + if (!gbCgbMode) + color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] : + gbPalette[0] & 0x7FFF; + for(int i = 0; i < 160; i++) + { + gbLineMix[i] = color; + gbLineBuffer[i] = 0; + } + gbDrawLine(); + } + else if ((register_LY==144) && (!systemFrameSkip)) + { + int framesToSkip = systemFrameSkip; + if(speedup) + framesToSkip = 9; // try 6 FPS during speedup + if((gbFrameSkipCount >= framesToSkip) || (gbWhiteScreen == 1)) { + gbWhiteScreen = 2; + + if(!gbSgbMask) + { + if (gbBorderOn) + gbSgbRenderBorder(); + //if (gbScreenOn) + systemDrawScreen(); + } + } if(systemReadJoypads()) { // read joystick if(gbSgbMode && gbSgbMultiplayer) { @@ -2784,198 +5127,29 @@ gbJoymask[0] = systemReadJoypad(-1); } } - int newmask = gbJoymask[0] & 255; + gbFrameCount++; - if(gbRom[0x147] == 0x22) { - systemUpdateMotionSensor(); - } - - if(newmask) { - gbInterrupt |= 16; - } + systemFrame(); - newmask = (gbJoymask[0] >> 10); - - speedup = (newmask & 1) ? true : false; - gbCapture = (newmask & 2) ? true : false; + if((gbFrameCount % 10) == 0) + system10Frames(60); - if(gbCapture && !gbCapturePrevious) { - gbCaptureNumber++; - systemScreenCapture(gbCaptureNumber); - } - gbCapturePrevious = gbCapture; - - if(gbFrameSkipCount >= framesToSkip) { - systemDrawScreen(); - gbFrameSkipCount = 0; - } else - gbFrameSkipCount++; - } else { - // go the the OAM being accessed mode - gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS; - gbLcdMode = 2; - - // only one LCD interrupt per line. may need to generalize... - if(!(register_STAT & 0x40) || - (register_LY != register_LYC)) { - if((register_STAT & 0x28) == 0x20) - gbInterrupt |= 2; - } - } - break; - case 1: - // V-Blank - // next mode is OAM being accessed mode - gbLcdTicks += GBLCD_MODE_2_CLOCK_TICKS; - gbLcdMode = 2; - if(!(register_STAT & 0x40) || - (register_LY != register_LYC)) { - if((register_STAT & 0x28) == 0x20) - gbInterrupt |= 2; - } - break; - case 2: - // OAM being accessed mode - - // next mode is OAM and VRAM in use - gbLcdTicks += GBLCD_MODE_3_CLOCK_TICKS; - gbLcdMode = 3; - break; - case 3: - // OAM and VRAM in use - // next mode is H-Blank - if(register_LY < 144) { - if(!gbSgbMask) { - if(gbFrameSkipCount >= framesToSkip) { - gbRenderLine(); - gbDrawSprites(); - - switch(systemColorDepth) { - case 16: - { - u16 * dest = (u16 *)pix + - (gbBorderLineSkip+2) * (register_LY + gbBorderRowSkip+1) - + gbBorderColumnSkip; - for(int x = 0; x < 160; ) { - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - *dest++ = systemColorMap16[gbLineMix[x++]]; - } - if(gbBorderOn) - dest += gbBorderColumnSkip; - *dest++ = 0; // for filters that read one pixel more - } - break; - case 24: - { - u8 *dest = (u8 *)pix + - 3*(gbBorderLineSkip * (register_LY + gbBorderRowSkip) + - gbBorderColumnSkip); - for(int x = 0; x < 160;) { - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - *((u32 *)dest) = systemColorMap32[gbLineMix[x++]]; - dest+= 3; - } - } - break; - case 32: - { - u32 * dest = (u32 *)pix + - (gbBorderLineSkip+1) * (register_LY + gbBorderRowSkip+1) - + gbBorderColumnSkip; - for(int x = 0; x < 160;) { - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - *dest++ = systemColorMap32[gbLineMix[x++]]; - } - } - break; - } - } + if(gbFrameCount >= 60) { + u32 currentTime = systemGetClock(); + if(currentTime != gbLastTime) + systemShowSpeed(100000/(currentTime - gbLastTime)); + else + systemShowSpeed(0); + gbLastTime = currentTime; + gbFrameCount = 0; } } - gbLcdTicks += GBLCD_MODE_0_CLOCK_TICKS; - gbLcdMode = 0; - // only one LCD interrupt per line. may need to generalize... - if(!(register_STAT & 0x40) || - (register_LY != register_LYC)) { - if(register_STAT & 0x08) - gbInterrupt |= 2; - } - if(gbHdmaOn) { - gbDoHdma(); - } - break; } - // mark the correct lcd mode on STAT register - register_STAT = (register_STAT & 0xfc) | gbLcdMode; } } + gbMemory[0xff41] = register_STAT; + // serial emulation if(gbSerialOn) { #ifdef LINK_EMULATION @@ -2992,7 +5166,7 @@ gbMemory[0xff01] = 0xff; gbMemory[0xff02] &= 0x7f; gbSerialOn = 0; - gbInterrupt |= 8; + gbMemory[0xff0f] = register_IF |= 8; gbSerialTicks = 0; } } @@ -3018,7 +5192,7 @@ gbSerialTicks = 0; gbMemory[0xff02] &= 0x7f; gbSerialOn = 0; - gbInterrupt |= 8; + gbMemory[0xff0f] = register_IF |= 8; gbSerialBits = 0; } else gbSerialTicks += GBSERIAL_CLOCK_TICKS; @@ -3029,27 +5203,43 @@ #endif } + + soundTicks -= clockTicks; + + while(soundTicks < 0) { + soundTicks += SOUND_CLOCK_TICKS; + + gbSoundTick(); + } + + // timer emulation + if(gbTimerOn) { - gbTimerTicks -= clockTicks; - + gbTimerTicks= ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1-clockTicks; + while(gbTimerTicks <= 0) { register_TIMA++; - - if(register_TIMA == 0) { - // timer overflow! - + // timer overflow! + if((register_TIMA & 0xff) == 0) { // reload timer modulo register_TIMA = register_TMA; - // flag interrupt - gbInterrupt |= 4; + gbMemory[0xff0f] = register_IF |= 4; } - gbTimerTicks += gbTimerClockTicks; } + gbTimerOnChange = false; + gbTimerModeChange = false; + + gbMemory[0xff05] = register_TIMA; + } + gbInternalTimer -= clockTicks; + while (gbInternalTimer<0) + gbInternalTimer+=0x100; + /* if(soundOffFlag) { if(synchronize && !speedup) { @@ -3077,58 +5267,122 @@ } */ - soundTicks -= clockTicks; + clockTicks = 0; - while(soundTicks < 0) { - soundTicks += SOUND_CLOCK_TICKS; + if (gbIntBreak == 1) + { + gbIntBreak = 0; + if ((register_IE & register_IF & gbInterruptLaunched & 0x3) && + ((IFF & 0x81) == 1) && (!gbInterruptWait) && (execute)) + { + gbIntBreak = 2; + PC.W = oldPCW; + execute = false; + gbOldClockTicks = 0; + } + if (gbOldClockTicks) + { + clockTicks = gbOldClockTicks; + gbOldClockTicks = 0; + goto gbRedoLoop; + } + } - gbSoundTick(); + // Executes the opcode(s), and apply the instruction's remaining clockTicks (if any). + if (execute) + { + switch(opcode1) { + case 0xCB: + // extended opcode + switch(opcode2) { +#include "gbCodesCB.h" + } + break; +#include "gbCodes.h" + } + execute = false; + + if (clockTicks) + { + gbDmaTicks += clockTicks; + clockTicks = 0; + } } - - register_IF = gbInterrupt; - if(IFF & 0x20) { - IFF &= 0xdf; - IFF |= 0x01; - gbInterruptWait = 0; - } else if(gbInterrupt) { - if(gbInterruptWait == 0) { - // gbInterruptWait = 0; - - if(IFF & 0x01) { - if((gbInterrupt & 1) && (register_IE & 1)) { - gbVblank_interrupt(); - continue; - } - - if((gbInterrupt & 2) && (register_IE & 2)) { - gbLcd_interrupt(); - continue; - } - - if((gbInterrupt & 4) && (register_IE & 4)) { - gbTimer_interrupt(); - continue; - } - - if((gbInterrupt & 8) && (register_IE & 8)) { - gbSerial_interrupt(); - continue; - } + if (gbDmaTicks) + { + clockTicks = gbGetNextEvent(gbDmaTicks); - if((gbInterrupt & 16) && (register_IE & 16)) { - gbJoypad_interrupt(); - continue; - } + if (clockTicks<=gbDmaTicks) + gbDmaTicks -= clockTicks; + else + { + clockTicks = gbDmaTicks; + gbDmaTicks = 0; + } + + goto gbRedoLoop; + } + + + // Remove the 'if an IE is pending' flag if IE has finished being executed. + if ((IFF & 0x40) && !(IFF & 0x30)) + IFF &= 0x81; + + + + if ((register_IE & register_IF & 0x1f) && (IFF & 0x81) && (!gbInterruptWait)) + { + + if (IFF & 1) + { + // Add 5 ticks for the interrupt execution time + gbDmaTicks += 5; + + if (gbIntBreak == 2) + { + gbDmaTicks--; + gbIntBreak = 0; } - } else { - gbInterruptWait -= clockTicks; - if(gbInterruptWait < 0) - gbInterruptWait = 0; + + + if(register_IF & register_IE & 1) + gbVblank_interrupt(); + else if(register_IF & register_IE & 2) + gbLcd_interrupt(); + else if(register_IF & register_IE & 4) + gbTimer_interrupt(); + else if(register_IF & register_IE & 8) + gbSerial_interrupt(); + else if(register_IF & register_IE & 16) + gbJoypad_interrupt(); + } + + IFF &= ~0x81; + } + + if (IFF & 0x08) + IFF &=~0x79; + + // Used to apply the interrupt's execution time. + if (gbDmaTicks) + { + clockTicks = gbGetNextEvent(gbDmaTicks); + + if (clockTicks<=gbDmaTicks) + gbDmaTicks -= clockTicks; + else + { + clockTicks = gbDmaTicks; + gbDmaTicks = 0; } + goto gbRedoLoop; } - if(ticksToStop <= 0) { + + gbBlackScreen = false; + + if((ticksToStop <= 0)) { if(!(register_LCDC & 0x80)) { if(systemReadJoypads()) { // read joystick diff -urN ../VisualBoyAdvance-1.7.2/src/gb/GB.h ./src/gb/GB.h --- ../VisualBoyAdvance-1.7.2/src/gb/GB.h 2004-05-13 23:11:09 +0900 +++ ./src/gb/GB.h 2006-06-06 23:25:43 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -38,11 +38,15 @@ extern bool gbLoadRom(const char *); extern void gbEmulate(int); +extern void gbWriteMemory(register u16, register u8); +extern void gbDrawLine(); extern bool gbIsGameboyRom(const char *); extern void gbSoundReset(); extern void gbSoundSetQuality(int); +extern void gbGetHardwareType(); extern void gbReset(); extern void gbCleanUp(); +extern void gbCPUInit(const char *,bool); extern bool gbWriteBatteryFile(const char *); extern bool gbWriteBatteryFile(const char *, bool); extern bool gbReadBatteryFile(const char *); diff -urN ../VisualBoyAdvance-1.7.2/src/gb/Makefile.in ./src/gb/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/gb/Makefile.in 2004-05-14 06:39:48 +0900 +++ ./src/gb/Makefile.in 2004-09-30 07:23:29 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbCheats.cpp ./src/gb/gbCheats.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbCheats.cpp 2004-05-13 23:40:33 +0900 +++ ./src/gb/gbCheats.cpp 2006-06-06 23:25:43 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -27,9 +27,11 @@ #include "gbCheats.h" #include "gbGlobals.h" +#include "GB.h" gbCheat gbCheatList[100]; int gbCheatNumber = 0; +int gbNextCheat = 0; bool gbCheatMap[0x10000]; extern bool cheatsEnabled; @@ -50,7 +52,7 @@ void gbCheatsSaveGame(gzFile gzFile) { utilWriteInt(gzFile, gbCheatNumber); - if(gbCheatNumber) + if(gbCheatNumber>0) utilGzWrite(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber); } @@ -81,7 +83,7 @@ } else { gbCheatNumber = utilReadInt(gzFile); - if(gbCheatNumber) { + if(gbCheatNumber>0) { utilGzRead(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber); } } @@ -163,7 +165,7 @@ bool gbVerifyGsCode(const char *code) { - int len = strlen(code); + size_t len = strlen(code); if(len == 0) return true; @@ -180,10 +182,6 @@ GBCHEAT_HEX_VALUE(code[4]) << 4 | GBCHEAT_HEX_VALUE(code[5]); - if(address < 0xa000 || - address > 0xdfff) - return false; - return true; } @@ -220,15 +218,23 @@ gbCheatList[i].compare = 0; gbCheatList[i].enabled = true; - - gbCheatMap[gbCheatList[i].address] = true; - + + int gsCode = gbCheatList[i].code; + + if ((gsCode !=1) && ((gsCode & 0xF0) !=0x80) && ((gsCode & 0xF0) !=0x90) && + ((gsCode & 0xF0) !=0xA0) && ((gsCode) !=0xF0) && ((gsCode) !=0xF1)) + systemMessage(MSG_WRONG_GAMESHARK_CODE, + N_("Wrong GameShark code type : %s"), code); + else if (((gsCode & 0xF0) ==0xA0) || ((gsCode) ==0xF0) || ((gsCode) ==0xF1)) + systemMessage(MSG_UNSUPPORTED_GAMESHARK_CODE, + N_("Unsupported GameShark code type : %s"), code); + gbCheatNumber++; } bool gbVerifyGgCode(const char *code) { - int len = strlen(code); + size_t len = strlen(code); if(len != 11 && len != 7 && @@ -313,12 +319,12 @@ int i = gbCheatNumber; - int len = strlen(code); + size_t len = strlen(code); strcpy(gbCheatList[i].cheatCode, code); strcpy(gbCheatList[i].cheatDesc, desc); - gbCheatList[i].code = 1; + gbCheatList[i].code = 0x101; gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) + GBCHEAT_HEX_VALUE(code[1]); @@ -338,9 +344,12 @@ compare ^= 0x45; gbCheatList[i].compare = compare; - gbCheatList[i].code = 0; + //gbCheatList[i].code = 0; + gbCheatList[i].code = 0x100; // fix for compare value + } + gbCheatList[i].enabled = true; gbCheatMap[gbCheatList[i].address] = true; @@ -425,6 +434,7 @@ return true; } +// Used to emulated GG codes u8 gbCheatRead(u16 address) { if(!cheatsEnabled) @@ -437,26 +447,72 @@ if(gbMemoryMap[address>>12][address&0xFFF] == gbCheatList[i].compare) return gbCheatList[i].value; break; - case 0x00: - case 0x01: - case 0x80: - return gbCheatList[i].value; - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0x94: - case 0x95: - case 0x96: - case 0x97: - if(address >= 0xd000 && address < 0xe000) { - if(((gbMemoryMap[0x0d] - gbWram)/0x1000) == - (gbCheatList[i].code - 0x90)) - return gbCheatList[i].value; - } else + case 0x101: // GameGenie 6 digits code support return gbCheatList[i].value; + break; } } } return gbMemoryMap[address>>12][address&0xFFF]; } + + +// Used to emulate GS codes. +void gbCheatWrite(bool reboot) +{ + if(cheatsEnabled) + { + u16 address = 0; + + if (gbNextCheat >= gbCheatNumber) + gbNextCheat = 0; + + for(int i = gbNextCheat; i < gbCheatNumber; i++) { + if(gbCheatList[i].enabled) { + address = gbCheatList[i].address; + if ((!reboot) && (address >= 0x8000) && !((address>=0xA000) && (address<0xC000))) + { // These codes are executed one per one, at each Vblank + switch(gbCheatList[i].code) { + case 0x01: + gbWriteMemory(address, gbCheatList[i].value); + gbNextCheat = i+1; + return; + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + case 0x98: + case 0x99: + case 0x9A: + case 0x9B: + case 0x9C: + case 0x9D: + case 0x9E: + case 0x9F: + int oldbank = gbMemory[0xff70]; + gbWriteMemory(0xff70, gbCheatList[i].code & 0xf); + gbWriteMemory(address, gbCheatList[i].value); + gbWriteMemory(0xff70, oldbank); + gbNextCheat = i+1; + return; + } + } + else // These codes are only executed when the game is booted + { + switch(gbCheatList[i].code & 0xF0) { + case 0x80: + gbWriteMemory(0x0000, 0x0A); + gbWriteMemory(0x4000, gbCheatList[i].value & 0xF); + gbWriteMemory(address, gbCheatList[i].value); + gbNextCheat = i+1; + return; + } + } + } + } + } +} \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbCheats.h ./src/gb/gbCheats.h --- ../VisualBoyAdvance-1.7.2/src/gb/gbCheats.h 2004-05-13 23:10:49 +0900 +++ ./src/gb/gbCheats.h 2006-06-06 23:25:43 +0900 @@ -50,6 +50,7 @@ extern void gbCheatEnable(int); extern void gbCheatDisable(int); extern u8 gbCheatRead(u16); +extern void gbCheatWrite(bool); extern int gbCheatNumber; extern gbCheat gbCheatList[100]; diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbCodes.h ./src/gb/gbCodes.h --- ../VisualBoyAdvance-1.7.2/src/gb/gbCodes.h 2004-05-13 23:10:32 +0900 +++ ./src/gb/gbCodes.h 2006-04-30 23:41:32 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ break; case 0x01: // LD BC, NNNN - BC.B.B0=gbReadMemory(PC.W++); - BC.B.B1=gbReadMemory(PC.W++); + BC.B.B0=gbReadOpcode(PC.W++); + BC.B.B1=gbReadOpcode(PC.W++); break; case 0x02: // LD (BC),A @@ -102,7 +102,9 @@ opcode = gbReadOpcode(PC.W++); if(gbCgbMode) { if(gbMemory[0xff4d] & 1) { + gbSpeedSwitch(); + //clockTicks += 228*144-(gbSpeed ? 62 : 63); if(gbSpeed == 0) gbMemory[0xff4d] = 0x00; @@ -113,8 +115,8 @@ break; case 0x11: // LD DE, NNNN - DE.B.B0=gbReadMemory(PC.W++); - DE.B.B1=gbReadMemory(PC.W++); + DE.B.B0=gbReadOpcode(PC.W++); + DE.B.B1=gbReadOpcode(PC.W++); break; case 0x12: // LD (DE),A @@ -147,7 +149,7 @@ break; case 0x18: // JR NN - PC.W+=(s8)gbReadMemory(PC.W)+1; + PC.W+=(s8)gbReadOpcode(PC.W)+1; break; case 0x19: // ADD HL,DE @@ -190,14 +192,14 @@ if(AF.B.B0&Z_FLAG) PC.W++; else { - PC.W+=(s8)gbReadMemory(PC.W)+1; + PC.W+=(s8)gbReadOpcode(PC.W)+1; clockTicks++; } break; case 0x21: // LD HL,NNNN - HL.B.B0=gbReadMemory(PC.W++); - HL.B.B1=gbReadMemory(PC.W++); + HL.B.B0=gbReadOpcode(PC.W++); + HL.B.B1=gbReadOpcode(PC.W++); break; case 0x22: // LDI (HL),A @@ -233,7 +235,7 @@ case 0x28: // JR Z,NN if(AF.B.B0&Z_FLAG) { - PC.W+=(s8)gbReadMemory(PC.W)+1; + PC.W+=(s8)gbReadOpcode(PC.W)+1; clockTicks++; } else PC.W++; @@ -278,14 +280,14 @@ if(AF.B.B0&C_FLAG) PC.W++; else { - PC.W+=(s8)gbReadMemory(PC.W)+1; + PC.W+=(s8)gbReadOpcode(PC.W)+1; clockTicks++; } break; case 0x31: // LD SP,NNNN - SP.B.B0=gbReadMemory(PC.W++); - SP.B.B1=gbReadMemory(PC.W++); + SP.B.B0=gbReadOpcode(PC.W++); + SP.B.B1=gbReadOpcode(PC.W++); break; case 0x32: // LDD (HL),A @@ -318,7 +320,7 @@ case 0x38: // JR C,NN if(AF.B.B0&C_FLAG) { - PC.W+=(s8)gbReadMemory(PC.W)+1; + PC.W+=(s8)gbReadOpcode(PC.W)+1; clockTicks ++; } else PC.W++; @@ -575,16 +577,24 @@ break; case 0x76: // HALT - if(IFF & 1) { + // If an EI is pending, the interrupts are triggered before Halt state !! + // Fix Torpedo Range's intro. + if (IFF & 0x40) + { + IFF &= ~0x70; + IFF |=1; PC.W--; - IFF |= 0x80; - } else { - if((register_IE & register_IF) > 0) - IFF |= 0x100; - else { - PC.W--; - IFF |= 0x81; + } + else + { + // if (IE & IF) and interrupts are disabeld, + // Halt is cancelled. + if ((register_IE & register_IF & 0x1f) && !(IFF & 1)) + { + IFF|=2; } + else + IFF |= 0x80; } break; case 0x77: @@ -1036,16 +1046,16 @@ if(AF.B.B0&Z_FLAG) PC.W+=2; else { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W); PC.W=tempRegister.W; clockTicks++; } break; case 0xc3: // JP NNNN - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W); PC.W=tempRegister.W; break; case 0xc4: @@ -1053,8 +1063,8 @@ if(AF.B.B0&Z_FLAG) PC.W+=2; else { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W++); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W++); gbWriteMemory(--SP.W,PC.B.B1); gbWriteMemory(--SP.W,PC.B.B0); PC.W=tempRegister.W; @@ -1096,8 +1106,8 @@ case 0xca: // JP Z,NNNN if(AF.B.B0&Z_FLAG) { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W); PC.W=tempRegister.W; clockTicks++; } else @@ -1107,8 +1117,8 @@ case 0xcc: // CALL Z,NNNN if(AF.B.B0&Z_FLAG) { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W++); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W++); gbWriteMemory(--SP.W,PC.B.B1); gbWriteMemory(--SP.W,PC.B.B0); PC.W=tempRegister.W; @@ -1118,8 +1128,8 @@ break; case 0xcd: // CALL NNNN - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W++); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W++); gbWriteMemory(--SP.W,PC.B.B1); gbWriteMemory(--SP.W,PC.B.B0); PC.W=tempRegister.W; @@ -1156,20 +1166,24 @@ if(AF.B.B0&C_FLAG) PC.W+=2; else { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W); PC.W=tempRegister.W; clockTicks++; } break; // D3 illegal + case 0xd3: + PC.W--; + IFF = 0; + break; case 0xd4: // CALL NC,NNNN if(AF.B.B0&C_FLAG) PC.W+=2; else { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W++); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W++); gbWriteMemory(--SP.W,PC.B.B1); gbWriteMemory(--SP.W,PC.B.B0); PC.W=tempRegister.W; @@ -1200,7 +1214,7 @@ if(AF.B.B0&C_FLAG) { PC.B.B0=gbReadMemory(SP.W++); PC.B.B1=gbReadMemory(SP.W++); - clockTicks += 4; + clockTicks += 3; } break; case 0xd9: @@ -1212,19 +1226,23 @@ case 0xda: // JP C,NNNN if(AF.B.B0&C_FLAG) { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W); PC.W=tempRegister.W; clockTicks++; } else PC.W+=2; break; // DB illegal + case 0xdb: + PC.W--; + IFF = 0; + break; case 0xdc: // CALL C,NNNN if(AF.B.B0&C_FLAG) { - tempRegister.B.B0=gbReadMemory(PC.W++); - tempRegister.B.B1=gbReadMemory(PC.W++); + tempRegister.B.B0=gbReadOpcode(PC.W++); + tempRegister.B.B1=gbReadOpcode(PC.W++); gbWriteMemory(--SP.W,PC.B.B1); gbWriteMemory(--SP.W,PC.B.B0); PC.W=tempRegister.W; @@ -1233,6 +1251,10 @@ PC.W+=2; break; // DD illegal + case 0xdd: + PC.W--; + IFF = 0; + break; case 0xde: // SBC NN tempValue=gbReadOpcode(PC.W++); @@ -1262,6 +1284,11 @@ break; // E3 illegal // E4 illegal + case 0xe3: + case 0xe4: + PC.W--; + IFF = 0; + break; case 0xe5: // PUSH HL gbWriteMemory(--SP.W,HL.B.B1); @@ -1308,6 +1335,12 @@ // EB illegal // EC illegal // ED illegal + case 0xeb: + case 0xec: + case 0xed: + PC.W--; + IFF = 0; + break; case 0xee: // XOR NN tempValue=gbReadOpcode(PC.W++); @@ -1336,9 +1369,13 @@ case 0xf3: // DI // IFF&=0xFE; - IFF&=(~0x21); + IFF|=0x08; break; // F4 illegal + case 0xf4: + PC.W--; + IFF = 0; + break; case 0xf5: // PUSH AF gbWriteMemory(--SP.W,AF.B.B1); @@ -1383,10 +1420,23 @@ break; case 0xfb: // EI - IFF|=0x20; - break; - // FC illegal + if (!(IFF & 0x30)) + // If an EI is executed right before HALT, + // the interrupts are triggered before the Halt state !! + // Fix Torpedo Range Intro. + // IFF |= 0x10 : 1 ticks before the EI enables the interrupts + // IFF |= 0x40 : marks that an EI is being executed. + IFF|=0x50; + break; + // FC illegal (FC = breakpoint) + case 0xfc: + breakpoint = true; + break; // FD illegal + case 0xfd: + PC.W--; + IFF = 0; + break; case 0xfe: // CP NN tempValue=gbReadOpcode(PC.W++); @@ -1401,7 +1451,10 @@ PC.W=0x0038; break; default: - systemMessage(0, N_("Unknown opcode %02x at %04x"), - gbReadOpcode(PC.W-1),PC.W-1); - emulating = false; + if (gbSystemMessage == false) + { + systemMessage(0, N_("Unknown opcode %02x at %04x"), + gbReadOpcode(PC.W-1),PC.W-1); + gbSystemMessage =true; + } return; diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbCodesCB.h ./src/gb/gbCodesCB.h --- ../VisualBoyAdvance-1.7.2/src/gb/gbCodesCB.h 2004-05-13 23:10:17 +0900 +++ ./src/gb/gbCodesCB.h 2006-01-04 22:38:47 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -1282,7 +1282,10 @@ AF.B.B1|=1<<7; break; default: - systemMessage(0, N_("Unknown opcode %02x at %04x"), - gbReadOpcode(PC.W-1),PC.W-1); - emulating = false; + if (gbSystemMessage == false) + { + systemMessage(0, N_("Unknown opcode %02x at %04x"), + gbReadOpcode(PC.W-1),PC.W-1); + gbSystemMessage =true; + } return; diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbGfx.cpp ./src/gb/gbGfx.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbGfx.cpp 2004-05-13 23:40:13 +0900 +++ ./src/gb/gbGfx.cpp 2006-04-30 23:42:18 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -58,9 +58,12 @@ }; u16 gbLineMix[160]; +u16 gbWindowColor[160]; +extern int inUseRegister_WY; void gbRenderLine() { + memset(gbLineMix, 0, sizeof(gbLineMix)); u8 * bank0; u8 * bank1; if(gbCgbMode) { @@ -86,10 +89,9 @@ if(y >= 144) return; - // int yLine = (y + gbBorderRowSkip) * gbBorderLineSkip; - - int sx = register_SCX; - int sy = register_SCY; + int SpritesTicks = gbSpritesTicks[x]*(gbSpeed ? 2 : 4); + int sx = gbSCXLine[(gbSpeed ? 0 : 4)+SpritesTicks]; + int sy = gbSCYLine[(gbSpeed ? 11 : 5)+SpritesTicks]; sy+=y; @@ -113,16 +115,17 @@ tile_map_address++; - if((register_LCDC & 16) == 0) { - if(tile < 128) tile += 128; - else tile -= 128; - } + if(!(register_LCDC & 0x10)) + tile ^= 0x80; int tile_pattern_address = tile_pattern + tile * 16 + by*2; if(register_LCDC & 0x80) { if((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100)) { while(x < 160) { + + + u8 tile_a = 0; u8 tile_b = 0; @@ -155,7 +158,7 @@ if(gbCgbMode) { c = c + (attrs & 7)*4; } else { - c = gbBgp[c]; + c = (gbBgpLine[x+(gbSpeed ? 5 : 11)+SpritesTicks]>>(c<<1)) &3; if(gbSgbMode && !gbCgbMode) { int dx = x >> 3; int dy = y >> 3; @@ -168,42 +171,92 @@ c = c + 4*palette; } } - gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c]] : - gbPalette[c]; + gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c] & 0x7FFF] : + gbPalette[c] & 0x7FFF; x++; if(x >= 160) break; bx >>= 1; } - tx++; - if(tx == 32) - tx = 0; + bx = 128; - + + SpritesTicks = gbSpritesTicks[x]*(gbSpeed ? 2 : 4); + + sx = gbSCXLine[x+(gbSpeed ? 0 : 4)+SpritesTicks]; + + sy = gbSCYLine[x+(gbSpeed ? 11 : 5)+SpritesTicks]; + + + tx = ((sx+x)>>3) & 0x1f; + + sy+=y; + + sy &= 255; + + ty = sy >> 3; + + by = sy & 7; + + tile_pattern_address = tile_pattern + tile * 16 + by * 2; + + tile_map_line_y = tile_map + ty * 32; + + tile_map_address = tile_map_line_y + tx; + if(bank1) attrs = bank1[tile_map_line_y + tx]; tile = bank0[tile_map_line_y + tx]; - - if((register_LCDC & 16) == 0) { - if(tile < 128) tile += 128; - else tile -= 128; - } + + if(!(register_LCDC & 0x10)) + tile ^= 0x80; + tile_pattern_address = tile_pattern + tile * 16 + by * 2; } } else { - for(int i = 0; i < 160; i++) { - gbLineMix[i] = gbPalette[0]; + // Use gbBgp[0] instead of 0 (?) + // (this fixes white flashes on Last Bible II) + // Also added the gbColorOption (fixes Dracula Densetsu II color problems) + for(int i = 0; i < 160; i++) + { + u16 color = gbColorOption ? gbColorFilter[0x7FFF] : + 0x7FFF; + if (!gbCgbMode) + color = gbColorOption ? gbColorFilter[gbPalette[gbBgpLine[i+(gbSpeed ? 5 : 11)+gbSpritesTicks[i]*(gbSpeed ? 2 : 4)]&3] & 0x7FFF] : + gbPalette[gbBgpLine[i+(gbSpeed ? 5 : 11)+gbSpritesTicks[i]*(gbSpeed ? 2 : 4)]&3] & 0x7FFF; + gbLineMix[i] = color; gbLineBuffer[i] = 0; } } // do the window display - if((register_LCDC & 0x20) && (layerSettings & 0x2000)) { - int wy = register_WY; + // LCDC.0 also enables/disables the window in !gbCgbMode ?!?! + // (tested on real hardware) + // This fixes Last Bible II & Zankurou Musouken + if((register_LCDC & 0x01 || gbCgbMode) && (register_LCDC & 0x20) && + (layerSettings & 0x2000) && (gbWindowLine != -2)) { + int i = 0; + // Fix (accurate emulation) for most of the window display problems + // (ie. Zen - Intergalactic Ninja, Urusei Yatsura...). + if ((gbWindowLine == -1) || (gbWindowLine>144)) + { + inUseRegister_WY = oldRegister_WY; + if (register_LY>oldRegister_WY) + gbWindowLine = 146; + // for (i = 0; i<160; i++) + // gbWindowColor[i] = gbLineMix[i]; + } + + int wy = inUseRegister_WY; - if(y >= wy) { + if(y >= inUseRegister_WY) { + + if (gbWindowLine == -1) + gbWindowLine = 0; + int wx = register_WX; + int swx = 0; wx -= 7; if( wx <= 159 && gbWindowLine <= 143) { @@ -212,10 +265,7 @@ if((register_LCDC & 0x40) != 0) tile_map = 0x1c00; - - if(gbWindowLine == -1) { - gbWindowLine = 0; - } + tx = 0; ty = gbWindowLine >> 3; @@ -223,6 +273,25 @@ bx = 128; by = gbWindowLine & 7; + // Tries to emulate the 'window scrolling bug' when wx == 0 (ie. wx-7 == -7). + // Nothing close to perfect, but good enought for now... + if (wx == -7) + { + swx = 7-((gbSCXLine[0]-1) & 7); + bx >>= ((gbSCXLine[0]+((swx != 1) ? 1 : 0)) & 7); + if (swx == 1) + swx = 2; + + //bx >>= ((gbSCXLine[0]+(((swx>1) && (swx != 7)) ? 1 : 0)) & 7); + + if ((swx == 7)) + { + //wx = 0; + if ((gbWindowLine>0) || (wy == 0)) + swx = 0; + } + } + else if(wx < 0) { bx >>= (-wx); wx = 0; @@ -247,6 +316,10 @@ tile_pattern_address = tile_pattern + tile * 16 + by*2; + if (wx) + for (i = 0; i=0) + { if(attrs & 0x80) gbLineBuffer[x] = 0x300 + c; else @@ -280,8 +355,8 @@ if(gbCgbMode) { c = c + (attrs & 7) * 4; } else { - c = gbBgp[c]; - if(gbSgbMode && ! gbCgbMode) { + c = (gbBgpLine[x+(gbSpeed ? 5 : 11)+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)]>>(c<<1)) &3; + if(gbSgbMode && !gbCgbMode) { int dx = x >> 3; int dy = y >> 3; @@ -293,8 +368,9 @@ c = c + 4*palette; } } - gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c]] : - gbPalette[c]; + gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c] & 0x7FFF] : + gbPalette[c] & 0x7FFF; + } x++; if(x >= 160) break; @@ -314,13 +390,30 @@ } tile_pattern_address = tile_pattern + tile * 16 + by * 2; } + + //for (i = swx; i<160; i++) + // gbLineMix[i] = gbWindowColor[i]; gbWindowLine++; } } } + else if (gbWindowLine == -2) + { + inUseRegister_WY = oldRegister_WY; + if (register_LY>oldRegister_WY) + gbWindowLine = 146; + else + gbWindowLine = 0; + } } else { - for(int i = 0; i < 160; i++) { - gbLineMix[i] = gbPalette[0]; + u16 color = gbColorOption ? gbColorFilter[0x7FFF] : + 0x7FFF; + if (!gbCgbMode) + color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] : + gbPalette[0] & 0x7FFF; + for(int i = 0; i < 160; i++) + { + gbLineMix[i] = color; gbLineBuffer[i] = 0; } } @@ -346,8 +439,11 @@ int init = 0x0000; - // int yLine = (y+gbBorderRowSkip) * gbBorderLineSkip; - + for (int i = 0; i<4; i++) + { + gbObp0[i] = (gbObp0Line[x+11+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)]>>(i<<1)) & 3; + gbObp1[i] = (gbObp1Line[x+11+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)]>>(i<<1)) & 3; + } u8 *pal = gbObp0; int flipx = (flags & 0x20); @@ -366,7 +462,7 @@ int a = 0; int b = 0; - if(gbCgbMode && flags & 0x08) { + if(gbCgbMode && (flags & 0x08)) { a = bank1[address++]; b = bank1[address++]; } else { @@ -392,12 +488,14 @@ continue; u16 color = gbLineBuffer[xxx]; - - if(prio) { + + // Fixes OAM-BG priority + if(prio && (register_LCDC & 1)) { if(color < 0x200 && ((color & 0xFF) != 0)) continue; } - if(color >= 0x300 && color != 0x300) + // Fixes OAM-BG priority for Moorhuhn 2 + if(color >= 0x300 && color != 0x300 && (register_LCDC & 1)) continue; else if(color >= 0x200 && color < 0x300) { int sprite = color & 0xff; @@ -412,7 +510,9 @@ if(sprite < spriteNumber) continue; } else { - if(spriteX < x+8) + // Fixes GB sprites priorities (was '< x + 8' before) + // ('A boy and his blob...' sprites' emulation is now correct) + if(spriteX < x) continue; } } @@ -442,12 +542,12 @@ } } - gbLineMix[xxx] = gbColorOption ? gbColorFilter[gbPalette[c]] : - gbPalette[c]; + gbLineMix[xxx] = gbColorOption ? gbColorFilter[gbPalette[c] & 0x7FFF] : + gbPalette[c] & 0x7FFF; } } -void gbDrawSprites() +void gbDrawSprites(bool draw) { int x = 0; int y = 0; @@ -455,6 +555,9 @@ int size = (register_LCDC & 4); + if (!draw) + memset (gbSpritesTicks, 0, sizeof(gbSpritesTicks)); + if(!(register_LCDC & 0x80)) return; @@ -473,11 +576,19 @@ if(x > 0 && y > 0 && x < 168 && y < 160) { // check if sprite intersects current line int t = yc -y + 16; - if(size && t >=0 && t < 16) { - gbDrawSpriteTile(tile,x-8,yc,t,flags,size,i); - count++; - } else if(!size && t >= 0 && t < 8) { - gbDrawSpriteTile(tile, x-8, yc, t, flags,size,i); + if((size && t >=0 && t < 16) || (!size && t >= 0 && t < 8)) { + if (draw) + gbDrawSpriteTile(tile,x-8,yc,t,flags,size,i); + else + { + for (int j = x-8; j<300; j++) + if (j>=0) + if (gbSpeed) + gbSpritesTicks[j] += 5; + else + gbSpritesTicks[j] += 2+(count&1); + + } count++; } } @@ -486,5 +597,5 @@ break; } } -} - + return; +} \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbGlobals.cpp ./src/gb/gbGlobals.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbGlobals.cpp 2004-05-13 23:40:02 +0900 +++ ./src/gb/gbGlobals.cpp 2006-04-30 23:43:06 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ int gbRomSize = 0; int gbRamSizeMask = 0; int gbRamSize = 0; +int gbTAMA5ramSize = 0; u8 *gbMemory = NULL; u8 *gbVram = NULL; @@ -31,6 +32,7 @@ u8 *gbRam = NULL; u8 *gbWram = NULL; u16 *gbLineBuffer = NULL; +u8 *gbTAMA5ram = NULL; u16 gbPalette[128]; u8 gbBgp[4] = { 0, 1, 2, 3}; @@ -38,6 +40,7 @@ u8 gbObp1[4] = { 0, 1, 2, 3}; int gbWindowLine = -1; +bool genericflashcardEnable = false; int gbCgbMode = 0; u16 gbColorFilter[32768]; diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbGlobals.h ./src/gb/gbGlobals.h --- ../VisualBoyAdvance-1.7.2/src/gb/gbGlobals.h 2004-05-13 23:10:07 +0900 +++ ./src/gb/gbGlobals.h 2006-04-30 23:43:06 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,6 +21,11 @@ extern int gbRomSize; extern int gbRamSize; extern int gbRamSizeMask; +extern int gbTAMA5ramSize; + +extern bool useBios; +extern bool skipBios; +extern u8 *bios; extern u8 *gbRom; extern u8 *gbRam; @@ -28,6 +33,7 @@ extern u8 *gbWram; extern u8 *gbMemory; extern u16 *gbLineBuffer; +extern u8 *gbTAMA5ram; extern u8 *gbMemoryMap[16]; @@ -46,6 +52,19 @@ extern u8 gbObp0[4]; extern u8 gbObp1[4]; extern u16 gbPalette[128]; +extern bool gbScreenOn; +extern bool gbDrawWindow; +extern u8 gbSCYLine[300]; +// gbSCXLine is used for the emulation (bug) of the SX change +// found in the Artic Zone game. +extern u8 gbSCXLine[300]; +// gbBgpLine is used for the emulation of the +// Prehistorik Man's title screen scroller. +extern u8 gbBgpLine[300]; +extern u8 gbObp0Line [300]; +extern u8 gbObp1Line [300]; +// gbSpritesTicks is used for the emulation of Parodius' Laser Beam. +extern u8 gbSpritesTicks[300]; extern u8 register_LCDC; extern u8 register_LY; @@ -54,8 +73,10 @@ extern u8 register_WY; extern u8 register_WX; extern u8 register_VBK; +extern u8 oldRegister_WY; extern int emulating; +extern bool genericflashcardEnable; extern int gbBorderLineSkip; extern int gbBorderRowSkip; @@ -63,6 +84,6 @@ extern int gbDmaTicks; extern void gbRenderLine(); -extern void gbDrawSprites(); +extern void gbDrawSprites(bool); extern u8 (*gbSerialFunction)(u8); diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbMemory.cpp ./src/gb/gbMemory.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbMemory.cpp 2004-05-13 23:39:52 +0900 +++ ./src/gb/gbMemory.cpp 2006-06-06 23:25:43 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,6 +20,12 @@ #include "../Port.h" #include "gbGlobals.h" #include "gbMemory.h" +#include "GB.h" +u8 gbDaysinMonth [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +const u8 gbDisabledRam [8] = {0x80, 0xff, 0xf0, 0x00, 0x30, 0xbf, 0xbf, 0xbf}; +extern int gbHardware; +extern int gbGBCColorType; +extern gbRegister PC; mapperMBC1 gbDataMBC1 = { 0, // RAM enable @@ -27,7 +33,8 @@ 0, // RAM bank 0, // memory model 0, // ROM high address - 0 // RAM address + 0, // RAM address + 0 // Rom Bank 0 remapping }; // MBC1 ROM write registers @@ -41,17 +48,25 @@ break; case 0x2000: // ROM bank select // value = value & 0x1f; - if(value == 0) - value = 1; + if ((value == 1) && (address == 0x2100)) + gbDataMBC1.mapperRomBank0Remapping = 1; + + if((value & 0x1f) == 0) + value += 1; if(value == gbDataMBC1.mapperROMBank) break; tmpAddress = value << 14; // check current model + if (gbDataMBC1.mapperRomBank0Remapping == 3) { + tmpAddress = (value & 0xf) << 14; + tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 18; + } + else if(gbDataMBC1.mapperMemoryModel == 0) { // model is 16/8, so we have a high address in use - tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; + tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; } tmpAddress &= gbRomSizeMask; @@ -63,16 +78,39 @@ break; case 0x4000: // RAM bank select if(gbDataMBC1.mapperMemoryModel == 1) { + if (!gbRamSize) + { + if (gbDataMBC1.mapperRomBank0Remapping == 3) + { + gbDataMBC1.mapperROMHighAddress = value & 0x03; + tmpAddress = (gbDataMBC1.mapperROMHighAddress) << 18; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x00] = &gbRom[tmpAddress]; + gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; + gbMemoryMap[0x04] = &gbRom[tmpAddress + 0x4000]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x5000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x6000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x7000]; + } + else gbDataMBC1.mapperRomBank0Remapping = 0; + } // 4/32 model, RAM bank switching provided value = value & 0x03; if(value == gbDataMBC1.mapperRAMBank) break; tmpAddress = value << 13; tmpAddress &= gbRamSizeMask; - gbMemoryMap[0x0a] = &gbRam[tmpAddress]; - gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; + if(gbRamSize) { + gbMemoryMap[0x0a] = &gbRam[tmpAddress]; + gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; + } gbDataMBC1.mapperRAMBank = value; gbDataMBC1.mapperRAMAddress = tmpAddress; + + if (gbDataMBC1.mapperRomBank0Remapping != 3) + gbDataMBC1.mapperROMHighAddress = 0; } else { // 16/8, set the high address gbDataMBC1.mapperROMHighAddress = value & 0x03; @@ -83,10 +121,57 @@ gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + if(gbRamSize) { + gbMemoryMap[0x0a] = &gbRam[0]; + gbMemoryMap[0x0b] = &gbRam[0x1000]; + } + + gbDataMBC1.mapperRAMBank = 0; } break; case 0x6000: // memory model select gbDataMBC1.mapperMemoryModel = value & 1; + + if(gbDataMBC1.mapperMemoryModel == 1) { + // 4/32 model, RAM bank switching provided + + value = gbDataMBC1.mapperRAMBank & 0x03; + tmpAddress = value << 13; + tmpAddress &= gbRamSizeMask; + if(gbRamSize) { + gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; + gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; + gbDataMBC1.mapperRomBank0Remapping = 0; + } + else gbDataMBC1.mapperRomBank0Remapping |=2; + + gbDataMBC1.mapperRAMBank = value; + gbDataMBC1.mapperRAMAddress = tmpAddress; + + tmpAddress = gbDataMBC1.mapperROMBank << 14; + + + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + + } else { + // 16/8, set the high address + + tmpAddress = gbDataMBC1.mapperROMBank << 14; + tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + if(gbRamSize) { + gbMemoryMap[0x0a] = &gbRam[0]; + gbMemoryMap[0x0b] = &gbRam[0x1000]; + } + } break; } } @@ -102,23 +187,72 @@ } } +// MBC1 read RAM +u8 mapperMBC1ReadRAM(u16 address) +{ + + if(gbDataMBC1.mapperRAMEnable) + return gbMemoryMap[address>>12][address & 0x0fff]; + + if (!genericflashcardEnable) + return 0xff; + else + if ((address & 0x1000) >= 0x1000) + { + // The value returned when reading RAM while it's disabled + // is constant, exept for the GBASP hardware. + // (actually, is the address that read is out of the ROM, the returned value if 0xff...) + if (PC.W>=0xff80) + return 0xff; + else + if ((gbHardware & 0x08) && (gbGBCColorType == 2)) + { + if (address & 1) + return 0xfb; + else + return 0x7a; + } + else + return 0x0a; + } + else + return gbDisabledRam[address & 7]; +} + void memoryUpdateMapMBC1() { int tmpAddress = gbDataMBC1.mapperROMBank << 14; // check current model - if(gbDataMBC1.mapperMemoryModel == 1) { - // model is 16/8, so we have a high address in use - tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; + if (gbDataMBC1.mapperRomBank0Remapping == 3) { + tmpAddress = (gbDataMBC1.mapperROMHighAddress & 3) << 18; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x00] = &gbRom[tmpAddress]; + gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; + + tmpAddress |= (gbDataMBC1.mapperROMBank & 0xf) << 14; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; } + else + { + if(gbDataMBC1.mapperMemoryModel == 0) { + // model is 16/8, so we have a high address in use + tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; + } - tmpAddress &= gbRomSizeMask; - gbMemoryMap[0x04] = &gbRom[tmpAddress]; - gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; - gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; - gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + } - if(gbRamSize) { + if((gbRamSize) && (gbDataMBC1.mapperMemoryModel == 1)){ gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; } @@ -210,7 +344,7 @@ time_t diff = now - gbDataMBC3.mapperLastTime; if(diff > 0) { // update the clock according to the last update time - gbDataMBC3.mapperSeconds += diff % 60; + gbDataMBC3.mapperSeconds += (int)(diff % 60); if(gbDataMBC3.mapperSeconds > 59) { gbDataMBC3.mapperSeconds -= 60; gbDataMBC3.mapperMinutes++; @@ -218,22 +352,22 @@ diff /= 60; - gbDataMBC3.mapperMinutes += diff % 60; - if(gbDataMBC3.mapperMinutes > 60) { + gbDataMBC3.mapperMinutes += (int)(diff % 60); + if(gbDataMBC3.mapperMinutes > 59) { gbDataMBC3.mapperMinutes -= 60; gbDataMBC3.mapperHours++; } diff /= 60; - gbDataMBC3.mapperHours += diff % 24; - if(gbDataMBC3.mapperHours > 24) { + gbDataMBC3.mapperHours += (int)(diff % 24); + if(gbDataMBC3.mapperHours > 23) { gbDataMBC3.mapperHours -= 24; gbDataMBC3.mapperDays++; } diff /= 24; - gbDataMBC3.mapperDays += diff; + gbDataMBC3.mapperDays += (int)(diff & 0xffffffff); if(gbDataMBC3.mapperDays > 255) { if(gbDataMBC3.mapperDays > 511) { gbDataMBC3.mapperDays %= 512; @@ -365,7 +499,30 @@ return gbDataMBC3.mapperLControl; } } - return 0; + + if (!genericflashcardEnable) + return 0xff; + else + if ((address & 0x1000) >= 0x1000) + { + // The value returned when reading RAM while it's disabled + // is constant, exept for the GBASP hardware. + // (actually, is the address that read is out of the ROM, the returned value if 0xff...) + if (PC.W>=0xff80) + return 0xff; + else + if ((gbHardware & 0x08) && (gbGBCColorType == 2)) + { + if (address & 1) + return 0xfb; + else + return 0x7a; + } + else + return 0x0a; + } + else + return gbDisabledRam[address & 7]; } void memoryUpdateMapMBC3() @@ -406,6 +563,7 @@ gbDataMBC5.mapperRAMEnable = ( ( value & 0x0a) == 0x0a ? 1 : 0); break; case 0x2000: // ROM bank select + if(address < 0x3000) { value = value & 0xff; if(value == gbDataMBC5.mapperROMBank) @@ -466,6 +624,38 @@ } } +// MBC5 read RAM +u8 mapperMBC5ReadRAM(u16 address) +{ + + if(gbDataMBC5.mapperRAMEnable) + return gbMemoryMap[address>>12][address & 0x0fff]; + + if (!genericflashcardEnable) + return 0xff; + else + if ((address & 0x1000) >= 0x1000) + { + // The value returned when reading RAM while it's disabled + // is constant, exept for the GBASP hardware. + // (actually, is the address that read is out of the ROM, the returned value if 0xff...) + if (PC.W>=0xff80) + return 0xff; + else + if ((gbHardware & 0x08) && (gbGBCColorType == 2)) + { + if (address & 1) + return 0xfb; + else + return 0x7a; + } + else + return 0x0a; + } + else + return gbDisabledRam[address & 7]; +} + void memoryUpdateMapMBC5() { int tmpAddress = (gbDataMBC5.mapperROMBank << 14) | @@ -568,7 +758,30 @@ case 0xa080: return gbDataMBC7.value; } - return 0xff; + + if (!genericflashcardEnable) + return 0xff; + else + if ((address & 0x1000) >= 0x1000) + { + // The value returned when reading RAM while it's disabled + // is constant, exept for the GBASP hardware. + // (actually, is the address that read is out of the ROM, the returned value if 0xff...) + if (PC.W>=0xff80) + return 0xff; + else + if ((gbHardware & 0x08) && (gbGBCColorType == 2)) + { + if (address & 1) + return 0xfb; + else + return 0x7a; + } + else + return 0x0a; + } + else + return gbDisabledRam[address & 7]; } // MBC7 RAM write @@ -717,7 +930,7 @@ void memoryUpdateMapMBC7() { - int tmpAddress = (gbDataMBC5.mapperROMBank << 14); + int tmpAddress = (gbDataMBC7.mapperROMBank << 14); tmpAddress &= gbRomSizeMask; gbMemoryMap[0x04] = &gbRom[tmpAddress]; @@ -965,3 +1178,540 @@ gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } } + +// TAMA5 (for Tamagotchi 3 (gb)). +// Very basic (and ugly :p) support, only rom bank switching is actually working... +mapperTAMA5 gbDataTAMA5 = { + 1, // RAM enable + 1, // ROM bank + 0, // RAM bank + 0, // RAM address + 0, // RAM Byte select + 0, // mapper command number + 0, // mapper last command; + 0, // commands 0x0 + 0, // commands 0x1 + 0, // commands 0x2 + 0, // commands 0x3 + 0, // commands 0x4 + 0, // commands 0x5 + 0, // commands 0x6 + 0, // commands 0x7 + 0, // commands 0x8 + 0, // commands 0x9 + 0, // commands 0xa + 0, // commands 0xb + 0, // commands 0xc + 0, // commands 0xd + 0, // commands 0xe + 0, // commands 0xf + 0, // register + 0, // timer clock latch + 0, // timer clock register + 0, // timer seconds + 0, // timer minutes + 0, // timer hours + 0, // timer days + 0, // timer months + 0, // timer years + 0, // timer control + 0, // timer latched seconds + 0, // timer latched minutes + 0, // timer latched hours + 0, // timer latched days + 0, // timer latched months + 0, // timer latched years + 0, // timer latched control + (time_t)-1 // last time +}; + + +void memoryUpdateTAMA5Clock() +{ + if ((gbDataTAMA5.mapperYears & 3) == 0) + gbDaysinMonth[1] = 29; + else + gbDaysinMonth[1] = 28; + + time_t now = time(NULL); + time_t diff = now - gbDataTAMA5.mapperLastTime; + if(diff > 0) { + // update the clock according to the last update time + gbDataTAMA5.mapperSeconds += (int)(diff % 60); + if(gbDataTAMA5.mapperSeconds > 59) { + gbDataTAMA5.mapperSeconds -= 60; + gbDataTAMA5.mapperMinutes++; + } + + diff /= 60; + + gbDataTAMA5.mapperMinutes += (int)(diff % 60); + if(gbDataTAMA5.mapperMinutes > 59) { + gbDataTAMA5.mapperMinutes -= 60; + gbDataTAMA5.mapperHours++; + } + + diff /= 60; + + gbDataTAMA5.mapperHours += (int)(diff % 24); + diff /= 24; + if(gbDataTAMA5.mapperHours > 23) { + gbDataTAMA5.mapperHours -= 24; + diff++; + + } + + time_t days = diff; + while (days) + { + gbDataTAMA5.mapperDays++; + days--; + if (gbDataTAMA5.mapperDays>gbDaysinMonth[gbDataTAMA5.mapperMonths-1]) + { + gbDataTAMA5.mapperDays = 1; + gbDataTAMA5.mapperMonths++; + if (gbDataTAMA5.mapperMonths>12) + { + gbDataTAMA5.mapperMonths = 1; + gbDataTAMA5.mapperYears++; + if ((gbDataTAMA5.mapperYears & 3) == 0) + gbDaysinMonth[1] = 29; + else + gbDaysinMonth[1] = 28; + } + } + } + } + gbDataTAMA5.mapperLastTime = now; + +} + + + +// TAMA5 RAM write +void mapperTAMA5RAM(u16 address, u8 value) +{ + if ((address & 0xffff) <= 0xa001) + { + switch (address & 1) + { + case 0: // 'Values' Register + { + value &= 0xf; + gbDataTAMA5.mapperCommands[gbDataTAMA5.mapperCommandNumber] = value; + gbMemoryMap[0xa][0] = value; + + int test = gbDataTAMA5.mapperCommands[gbDataTAMA5.mapperCommandNumber & 0x0e] | + (gbDataTAMA5.mapperCommands[(gbDataTAMA5.mapperCommandNumber & 0x0e) +1]<<4); + + if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 0) // Read Command !!! + { + gbDataTAMA5.mapperROMBank = gbDataTAMA5.mapperCommands[0] | + (gbDataTAMA5.mapperCommands[1]<<4); + + int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); + + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + + gbDataTAMA5.mapperCommands[0x0f] = 0; + } + else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 4) + { + gbDataTAMA5.mapperCommands[0x0f] = 1; + if (gbDataTAMA5.mapperCommandNumber == 4) + gbDataTAMA5.mapperCommands[5] =0; // correct ? + } + else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 6) + { + gbDataTAMA5.mapperRamByteSelect = (gbDataTAMA5.mapperCommands[7]<<4) | + (gbDataTAMA5.mapperCommands[6]&0x0f); + + // Write Commands !!! + if (gbDataTAMA5.mapperCommands[0x0f] && (gbDataTAMA5.mapperCommandNumber == 7)) + { + int data = gbDataTAMA5.mapperCommands[0x04] & 0x0f | + (gbDataTAMA5.mapperCommands[0x05] <<4); + + // Not sure when the write command should reset... + // but it doesn't seem to matter. + // gbDataTAMA5.mapperCommands[0x0f] = 0; + + if (gbDataTAMA5.mapperRamByteSelect == 0x8) // Timer stuff + { + switch (data & 0xf) + { + case 0x7: + gbDataTAMA5.mapperDays = ((gbDataTAMA5.mapperDays)/10)*10 + (data >> 4); + break; + case 0x8: + gbDataTAMA5.mapperDays = (gbDataTAMA5.mapperDays%10) + (data >>4)*10; + break; + case 0x9: + gbDataTAMA5.mapperMonths = ((gbDataTAMA5.mapperMonths)/10)*10 + (data >> 4); + break; + case 0xa: + gbDataTAMA5.mapperMonths = (gbDataTAMA5.mapperMonths%10) + (data >>4)*10; + break; + case 0xb: + gbDataTAMA5.mapperYears = ((gbDataTAMA5.mapperYears)%1000) + (data >> 4)*1000; + break; + case 0xc: + gbDataTAMA5.mapperYears = (gbDataTAMA5.mapperYears%100) + (gbDataTAMA5.mapperYears/1000)*1000 + + (data >>4)*100; + break; + default : + break; + } + } + else if (gbDataTAMA5.mapperRamByteSelect == 0x18) // Timer stuff again + { + memoryUpdateTAMA5Clock(); + gbDataTAMA5.mapperLSeconds = gbDataTAMA5.mapperSeconds; + gbDataTAMA5.mapperLMinutes = gbDataTAMA5.mapperMinutes; + gbDataTAMA5.mapperLHours = gbDataTAMA5.mapperHours; + gbDataTAMA5.mapperLDays = gbDataTAMA5.mapperDays; + gbDataTAMA5.mapperLMonths = gbDataTAMA5.mapperMonths; + gbDataTAMA5.mapperLYears = gbDataTAMA5.mapperYears; + gbDataTAMA5.mapperLControl = gbDataTAMA5.mapperControl; + + int seconds = (gbDataTAMA5.mapperLSeconds / 10)*16 + gbDataTAMA5.mapperLSeconds %10; + int secondsL = (gbDataTAMA5.mapperLSeconds % 10); + int secondsH = (gbDataTAMA5.mapperLSeconds / 10); + int minutes = (gbDataTAMA5.mapperLMinutes / 10)*16 + gbDataTAMA5.mapperLMinutes %10; + int hours = (gbDataTAMA5.mapperLHours / 10)*16 + gbDataTAMA5.mapperLHours %10; + int DaysL = gbDataTAMA5.mapperLDays % 10; + int DaysH = gbDataTAMA5.mapperLDays /10; + int MonthsL = gbDataTAMA5.mapperLMonths % 10; + int MonthsH = gbDataTAMA5.mapperLMonths / 10; + int Years3 = (gbDataTAMA5.mapperLYears / 100) % 10; + int Years4 = (gbDataTAMA5.mapperLYears / 1000); + + switch (data & 0x0f) + { + // I guess cases 0 and 1 are used for secondsL and secondsH + // so the game would update the timer values on screen when + // the seconds reset to 0... ? + case 0x0: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = secondsL; + break; + case 0x1: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = secondsH; + break; + case 0x7: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = DaysL; // days low + break; + case 0x8: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = DaysH; // days high + break; + case 0x9: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = MonthsL; // month low + break; + case 0xa: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = MonthsH; // month high + break; + case 0xb: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = Years4; // years 4th digit + break; + case 0xc: + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = Years3; // years 3rd digit + break; + default : + break; + } + + gbTAMA5ram[0x54] = seconds; // incorrect ? (not used by the game) ? + gbTAMA5ram[0x64] = minutes; + gbTAMA5ram[0x74] = hours; + gbTAMA5ram[0x84] = DaysH*16+DaysL; // incorrect ? (not used by the game) ? + gbTAMA5ram[0x94] = MonthsH*16+MonthsL; // incorrect ? (not used by the game) ? + + time(&gbDataTAMA5.mapperLastTime); + + gbMemoryMap[0xa][0] = 1; + } + else if (gbDataTAMA5.mapperRamByteSelect == 0x28) // Timer stuff again + { + if ((data & 0xf) == 0xb) + gbDataTAMA5.mapperYears = ((gbDataTAMA5.mapperYears>>2)<<2) + (data & 3); + } + else if (gbDataTAMA5.mapperRamByteSelect == 0x44) + { + gbDataTAMA5.mapperMinutes = (data/16)*10 + data%16; + } + else if (gbDataTAMA5.mapperRamByteSelect == 0x54) + { + gbDataTAMA5.mapperHours = (data/16)*10 + data%16; + } + else + { + gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = data; + } + } + } + } + break; + case 1: // 'Commands' Register + { + gbMemoryMap[0xa][1] = gbDataTAMA5.mapperCommandNumber = value; + + // This should be only a 'is the flashrom ready ?' command. + // However as I couldn't find any 'copy' command + // (that seems to be needed for the saving system to work) + // I put it there... + if (value == 0x0a) + { + for (int i = 0; i<0x10; i++) + for (int j = 0; j<0x10; j++) + if (!(j&2)) + gbTAMA5ram[(i*0x10)+j | 2] = gbTAMA5ram[(i*0x10)+j]; + // Enable this to see the content of the flashrom in 0xe000 + /*for (int k = 0; k<0x100; k++) + gbMemoryMap[0xe][k] = gbTAMA5ram[k];*/ + + gbMemoryMap[0xa][0] = gbDataTAMA5.mapperRAMEnable = 1; + } + else + { + if ((value & 0x0e) == 0x0c) + { + gbDataTAMA5.mapperRamByteSelect = gbDataTAMA5.mapperCommands[6] | + (gbDataTAMA5.mapperCommands[7]<<4); + + u8 byte = gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect]; + + gbMemoryMap[0xa][0] = (value & 1) ? byte >> 4 : byte & 0x0f; + + gbDataTAMA5.mapperCommands[0x0f] = 0; + } + } + break; + } + } + } + else + { + if(gbDataTAMA5.mapperRAMEnable) { + if(gbDataTAMA5.mapperRAMBank != -1) { + if(gbRamSize) { + gbMemoryMap[address>>12][address & 0x0fff] = value; + systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; + } + } + } + } +} + + +// TAMA5 read RAM +u8 mapperTAMA5ReadRAM(u16 address) +{ + return gbMemoryMap[address>>12][address & 0xfff]; +} + + +void memoryUpdateMapTAMA5() +{ + int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); + + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + + if(gbRamSize) { + tmpAddress = 0 << 13; + tmpAddress &= gbRamSizeMask; + gbMemoryMap[0x0a] = &gbRam[tmpAddress]; + gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; + } +} + +// MMM01 Used in Momotarou collection (however the rom is corrupted) +mapperMMM01 gbDataMMM01 ={ + 0, // RAM enable + 1, // ROM bank + 0, // RAM bank + 0, // memory model + 0, // ROM high address + 0, // RAM address + 0 // Rom Bank 0 remapping +}; + +// MMM01 ROM write registers +void mapperMMM01ROM(u16 address, u8 value) +{ + int tmpAddress = 0; + + switch(address & 0x6000) { + case 0x0000: // RAM enable register + gbDataMMM01.mapperRAMEnable = ( ( value & 0x0a) == 0x0a ? 1 : 0); + break; + case 0x2000: // ROM bank select + // value = value & 0x1f; + if(value == 0) + value = 1; + if(value == gbDataMMM01.mapperROMBank) + break; + + tmpAddress = value << 14; + + // check current model + if(gbDataMMM01.mapperMemoryModel == 0) { + // model is 16/8, so we have a high address in use + tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; + } + else + tmpAddress |= gbDataMMM01.mapperRomBank0Remapping << 18; + + tmpAddress &= gbRomSizeMask; + gbDataMMM01.mapperROMBank = value; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + break; + case 0x4000: // RAM bank select + if(gbDataMMM01.mapperMemoryModel == 1) { + // 4/32 model, RAM bank switching provided + value = value & 0x03; + if(value == gbDataMBC1.mapperRAMBank) + break; + tmpAddress = value << 13; + tmpAddress &= gbRamSizeMask; + gbMemoryMap[0x0a] = &gbRam[tmpAddress]; + gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; + gbDataMMM01.mapperRAMBank = value; + gbDataMMM01.mapperRAMAddress = tmpAddress; + } else { + // 16/8, set the high address + gbDataMMM01.mapperROMHighAddress = value & 0x03; + tmpAddress = gbDataMMM01.mapperROMBank << 14; + tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + + gbDataMMM01.mapperRomBank0Remapping = ((value<<1) | (value & 0x40 ? 1 : 0)) & 0xff; + tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x00] = &gbRom[tmpAddress]; + gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; + } + break; + case 0x6000: // memory model select + gbDataMMM01.mapperMemoryModel = value & 1; + break; + } +} + +// MMM01 RAM write +void mapperMMM01RAM(u16 address, u8 value) +{ + if(gbDataMMM01.mapperRAMEnable) { + if(gbRamSize) { + gbMemoryMap[address >> 12][address & 0x0fff] = value; + systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; + } + } +} + +void memoryUpdateMapMMM01() +{ + int tmpAddress = gbDataMMM01.mapperROMBank << 14; + + // check current model + if(gbDataMMM01.mapperMemoryModel == 1) { + // model is 16/8, so we have a high address in use + tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; + } + + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; + + tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; + tmpAddress &= gbRomSizeMask; + gbMemoryMap[0x00] = &gbRom[tmpAddress]; + gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; + gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; + gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; + + if(gbRamSize) { + gbMemoryMap[0x0a] = &gbRam[gbDataMMM01.mapperRAMAddress]; + gbMemoryMap[0x0b] = &gbRam[gbDataMMM01.mapperRAMAddress + 0x1000]; + } +} + +// GameGenie ROM write registers +void mapperGGROM(u16 address, u8 value) +{ + int tmpAddress = 0; + + switch(address & 0x6000) { + case 0x0000: // RAM enable register + break; + case 0x2000: // GameGenie has only a half bank + break; + case 0x4000: // GameGenie has no RAM + if ((address >=0x4001) && (address <= 0x4020)) // GG Hardware Registers + gbMemoryMap[address >> 12][address & 0x0fff] = value; + break; + case 0x6000: // GameGenie has only a half bank + break; + } +} + + +// GS3 Used to emulate the GS V3.0 rom bank switching +mapperGS3 gbDataGS3 = { 1 }; // ROM bank + +void mapperGS3ROM(u16 address, u8 value) +{ + int tmpAddress = 0; + + switch(address & 0x6000) { + case 0x0000: // GS has no ram + break; + case 0x2000: // GS has no 'classic' ROM bank select + break; + case 0x4000: // GS has no ram + break; + case 0x6000: // 0x6000 area is RW, and used for GS hardware registers + + if (address == 0x7FE1) // This is the (half) ROM bank select register + { + if(value == gbDataGS3.mapperROMBank) + break; + tmpAddress = value << 13; + + tmpAddress &= gbRomSizeMask; + gbDataGS3.mapperROMBank = value; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + } + else + gbMemoryMap[address>>12][address & 0x0fff] = value; + break; + } +} + +void memoryUpdateMapGS3() +{ + int tmpAddress = gbDataGS3.mapperROMBank << 13; + + tmpAddress &= gbRomSizeMask; + // GS can only change a half ROM bank + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; +} \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbMemory.h ./src/gb/gbMemory.h --- ../VisualBoyAdvance-1.7.2/src/gb/gbMemory.h 2004-05-13 23:09:24 +0900 +++ ./src/gb/gbMemory.h 2006-06-06 23:25:43 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ int mapperMemoryModel; int mapperROMHighAddress; int mapperRAMAddress; + int mapperRomBank0Remapping; }; struct mapperMBC2 { @@ -106,15 +107,62 @@ int mapperRegister8; }; +struct mapperTAMA5 { + int mapperRAMEnable; + int mapperROMBank; + int mapperRAMBank; + int mapperRAMAddress; + int mapperRamByteSelect; + int mapperCommandNumber; + int mapperLastCommandNumber; + int mapperCommands[0x10]; + int mapperRegister; + int mapperClockLatch; + int mapperClockRegister; + int mapperSeconds; + int mapperMinutes; + int mapperHours; + int mapperDays; + int mapperMonths; + int mapperYears; + int mapperControl; + int mapperLSeconds; + int mapperLMinutes; + int mapperLHours; + int mapperLDays; + int mapperLMonths; + int mapperLYears; + int mapperLControl; + time_t mapperLastTime; +}; + +struct mapperMMM01 { + int mapperRAMEnable; + int mapperROMBank; + int mapperRAMBank; + int mapperMemoryModel; + int mapperROMHighAddress; + int mapperRAMAddress; + int mapperRomBank0Remapping; +}; + +struct mapperGS3 { + int mapperROMBank; +}; + extern mapperMBC1 gbDataMBC1; extern mapperMBC2 gbDataMBC2; extern mapperMBC3 gbDataMBC3; extern mapperMBC5 gbDataMBC5; extern mapperHuC1 gbDataHuC1; extern mapperHuC3 gbDataHuC3; +extern mapperTAMA5 gbDataTAMA5; +extern mapperMMM01 gbDataMMM01; +extern mapperGS3 gbDataGS3; void mapperMBC1ROM(u16,u8); void mapperMBC1RAM(u16,u8); +u8 mapperMBC1ReadRAM(u16); void mapperMBC2ROM(u16,u8); void mapperMBC2RAM(u16,u8); void mapperMBC3ROM(u16,u8); @@ -122,6 +170,7 @@ u8 mapperMBC3ReadRAM(u16); void mapperMBC5ROM(u16,u8); void mapperMBC5RAM(u16,u8); +u8 mapperMBC5ReadRAM(u16); void mapperMBC7ROM(u16,u8); void mapperMBC7RAM(u16,u8); u8 mapperMBC7ReadRAM(u16); @@ -130,7 +179,13 @@ void mapperHuC3ROM(u16,u8); void mapperHuC3RAM(u16,u8); u8 mapperHuC3ReadRAM(u16); - +void mapperTAMA5RAM(u16,u8); +u8 mapperTAMA5ReadRAM(u16); +void memoryUpdateTAMA5Clock(); +void mapperMMM01ROM(u16,u8); +void mapperMMM01RAM(u16,u8); +void mapperGGROM(u16,u8); +void mapperGS3ROM(u16,u8); //extern void (*mapper)(u16,u8); //extern void (*mapperRAM)(u16,u8); //extern u8 (*mapperReadRAM)(u16); @@ -142,7 +197,9 @@ extern void memoryUpdateMapMBC7(); extern void memoryUpdateMapHuC1(); extern void memoryUpdateMapHuC3(); - +extern void memoryUpdateMapTAMA5(); +extern void memoryUpdateMapMMM01(); +extern void memoryUpdateMapGS3(); diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbSGB.cpp ./src/gb/gbSGB.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbSGB.cpp 2004-05-14 07:27:47 +0900 +++ ./src/gb/gbSGB.cpp 2006-04-30 23:44:31 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ extern u8 *pix; extern bool speedup; +extern bool gbSgbResetFlag; #define GBSGB_NONE 0 #define GBSGB_RESET 1 @@ -96,7 +97,7 @@ gbSgbBorder[i] = 1 << 2; } - for(i = 0; i < 4; i++) { + for(i = 0; i < 32; i++) { gbPalette[i*4] = (0x1f) | (0x1f << 5) | (0x1f << 10); gbPalette[i*4+1] = (0x15) | (0x15 << 5) | (0x15 << 10); gbPalette[i*4+2] = (0x0c) | (0x0c << 5) | (0x0c << 10); @@ -255,9 +256,12 @@ yyy = 7 - yy; u16 c = gbPalette[palette + color]; - if(!color) - c = gbPalette[0]; - if((yy < 40 || yy >= 184) || (xx < 48 || xx >= 208)) { + + // Fix for Super Snaky ??? + // (it allows SGB borders to not redraw on the GB screen) + //if(!color) + // c = gbPalette[0]; + if(((yy < 40 || yy >= 184) || (xx < 48 || xx >= 208)) && (color || (gbSgbResetFlag == true))) { switch(systemColorDepth) { case 16: gbSgbDraw16Bit(dest + yyy*(256+2) + xxx, c); diff -urN ../VisualBoyAdvance-1.7.2/src/gb/gbSound.cpp ./src/gb/gbSound.cpp --- ../VisualBoyAdvance-1.7.2/src/gb/gbSound.cpp 2004-05-13 23:39:20 +0900 +++ ./src/gb/gbSound.cpp 2006-04-30 23:44:44 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ #define NOISE_MAGIC 5 extern int speed; +extern int gbHardware; extern void soundResume(); @@ -57,6 +58,9 @@ extern int sound1On; extern int sound1ATL; +int sound1ATLreload; +int freq1low; +int freq1high; extern int sound1Skip; extern int sound1Index; extern int sound1Continue; @@ -73,6 +77,9 @@ extern int sound2On; extern int sound2ATL; +int sound2ATLreload; +int freq2low; +int freq2high; extern int sound2Skip; extern int sound2Index; extern int sound2Continue; @@ -84,6 +91,9 @@ extern int sound3On; extern int sound3ATL; +int sound3ATLreload; +int freq3low; +int freq3high; extern int sound3Skip; extern int sound3Index; extern int sound3Continue; @@ -93,6 +103,8 @@ extern int sound4On; extern int sound4Clock; extern int sound4ATL; +int sound4ATLreload; +int freq4; extern int sound4Skip; extern int sound4Index; extern int sound4ShiftRight; @@ -136,14 +148,16 @@ #endif switch(address) { case NR10: + gbMemory[address] = data | 0x80; sound1SweepATL = sound1SweepATLReload = 344 * ((data >> 4) & 7); sound1SweepSteps = data & 7; sound1SweepUpDown = data & 0x08; sound1SweepStep = 0; break; case NR11: + gbMemory[address] = data | 0x3f; sound1Wave = soundWavePattern[data >> 6]; - sound1ATL = 172 * (64 - (data & 0x3f)); + sound1ATL = sound1ATLreload = 172 * (64 - (data & 0x3f)); break; case NR12: sound1EnvelopeVolume = data >> 4; @@ -151,8 +165,10 @@ sound1EnvelopeATLReload = sound1EnvelopeATL = 689 * (data & 7); break; case NR13: - freq = (((int)(gbMemory[NR14] & 7)) << 8) | data; - sound1ATL = 172 * (64 - (gbMemory[NR11] & 0x3f)); + gbMemory[address] = 0xff; + freq1low = data; + freq = ((((int)(freq1high & 7)) << 8) | freq1low); + sound1ATL = sound1ATLreload; freq = 2048 - freq; if(freq) { sound1Skip = SOUND_MAGIC / freq; @@ -160,9 +176,11 @@ sound1Skip = 0; break; case NR14: - freq = (((int)(data&7) << 8) | gbMemory[NR13]); + gbMemory[address] = data | 0xbf; + freq1high = data; + freq = ((((int)(freq1high & 7)) << 8) | freq1low); freq = 2048 - freq; - sound1ATL = 172 * (64 - (gbMemory[NR11] & 0x3f)); + sound1ATL = sound1ATLreload; sound1Continue = data & 0x40; if(freq) { sound1Skip = SOUND_MAGIC / freq; @@ -172,7 +190,6 @@ gbMemory[NR52] |= 1; sound1EnvelopeVolume = gbMemory[NR12] >> 4; sound1EnvelopeUpDown = gbMemory[NR12] & 0x08; - sound1ATL = 172 * (64 - (gbMemory[NR11] & 0x3f)); sound1EnvelopeATLReload = sound1EnvelopeATL = 689 * (gbMemory[NR12] & 7); sound1SweepATL = sound1SweepATLReload = 344 * ((gbMemory[NR10] >> 4) & 7); sound1SweepSteps = gbMemory[NR10] & 7; @@ -184,8 +201,9 @@ } break; case NR21: + gbMemory[address] = data | 0x3f; sound2Wave = soundWavePattern[data >> 6]; - sound2ATL = 172 * (64 - (data & 0x3f)); + sound2ATL = sound2ATLreload = 172 * (64 - (data & 0x3f)); break; case NR22: sound2EnvelopeVolume = data >> 4; @@ -193,8 +211,10 @@ sound2EnvelopeATLReload = sound2EnvelopeATL = 689 * (data & 7); break; case NR23: - freq = (((int)(gbMemory[NR24] & 7)) << 8) | data; - sound2ATL = 172 * (64 - (gbMemory[NR21] & 0x3f)); + gbMemory[address] = 0xff; + freq2low = data; + freq = (((int)(freq2high & 7)) << 8) | freq2low; + sound2ATL = sound2ATLreload; freq = 2048 - freq; if(freq) { sound2Skip = SOUND_MAGIC / freq; @@ -202,9 +222,11 @@ sound2Skip = 0; break; case NR24: - freq = (((int)(data&7) << 8) | gbMemory[NR23]); + gbMemory[address] = data | 0xbf; + freq2high = data; + freq = (((int)(freq2high & 7)) << 8) | freq2low; freq = 2048 - freq; - sound2ATL = 172 * (64 - (gbMemory[NR21] & 0x3f)); + sound2ATL = sound2ATLreload; sound2Continue = data & 0x40; if(freq) { sound2Skip = SOUND_MAGIC / freq; @@ -214,7 +236,7 @@ gbMemory[NR52] |= 2; sound2EnvelopeVolume = gbMemory[NR22] >> 4; sound2EnvelopeUpDown = gbMemory[NR22] & 0x08; - sound2ATL = 172 * (64 - (gbMemory[NR21] & 0x3f)); + sound2ATL = sound2ATLreload; sound2EnvelopeATLReload = sound2EnvelopeATL = 689 * (gbMemory[NR22] & 7); sound2Index = 0; @@ -222,26 +244,33 @@ } break; case NR30: + gbMemory[address] = data | 0x7f; if(!(data & 0x80)) { gbMemory[NR52] &= 0xfb; sound3On = 0; } break; case NR31: - sound3ATL = 172 * (256-data); + gbMemory[address] = 0xff; + sound3ATL = sound3ATLreload = 172 * (256-data); break; case NR32: + gbMemory[address] = data | 0x9f; sound3OutputLevel = (data >> 5) & 3; break; case NR33: - freq = 2048 - (((int)(gbMemory[NR34]&7) << 8) | data); + gbMemory[address] = 0xff; + freq3low = data; + freq = 2048 - (((int)(freq3high&7) << 8) | freq3low); if(freq) { sound3Skip = SOUND_MAGIC_2 / freq; } else sound3Skip = 0; break; case NR34: - freq = 2048 - (((data &7) << 8) | (int)gbMemory[NR33]); + gbMemory[address] = data | 0xbf; + freq3high = data; + freq = 2048 - (((int)(freq3high&7) << 8) | freq3low); if(freq) { sound3Skip = SOUND_MAGIC_2 / freq; } else { @@ -250,13 +279,13 @@ sound3Continue = data & 0x40; if((data & 0x80) && (gbMemory[NR30] & 0x80)) { gbMemory[NR52] |= 4; - sound3ATL = 172 * (256 - gbMemory[NR31]); + sound3ATL = sound3ATLreload; sound3Index = 0; sound3On = 1; } break; case NR41: - sound4ATL = 172 * (64 - (data & 0x3f)); + sound4ATL = sound4ATLreload = 172 * (64 - (data & 0x3f)); break; case NR42: sound4EnvelopeVolume = data >> 4; @@ -264,7 +293,7 @@ sound4EnvelopeATLReload = sound4EnvelopeATL = 689 * (data & 7); break; case NR43: - freq = soundFreqRatio[data & 7]; + freq = freq4 = soundFreqRatio[data & 7]; sound4NSteps = data & 0x08; sound4Skip = (freq << 8) / NOISE_MAGIC; @@ -277,12 +306,13 @@ break; case NR44: + gbMemory[address] = data | 0xbf; sound4Continue = data & 0x40; if(data & 0x80) { gbMemory[NR52] |= 8; sound4EnvelopeVolume = gbMemory[NR42] >> 4; sound4EnvelopeUpDown = gbMemory[NR42] & 0x08; - sound4ATL = 172 * (64 - (gbMemory[NR41] & 0x3f)); + sound4ATL = sound4ATLreload; sound4EnvelopeATLReload = sound4EnvelopeATL = 689 * (gbMemory[NR42] & 7); sound4On = 1; @@ -290,15 +320,6 @@ sound4Index = 0; sound4ShiftIndex = 0; - freq = soundFreqRatio[gbMemory[NR43] & 7]; - - sound4Skip = (freq << 8) / NOISE_MAGIC; - - sound4NSteps = gbMemory[NR43] & 0x08; - - freq = freq / soundShiftClock[gbMemory[NR43] >> 4]; - - sound4ShiftSkip = (freq << 8) / NOISE_MAGIC; if(sound4NSteps) sound4ShiftRight = 0x7fff; else @@ -320,7 +341,9 @@ sound2On = 0; sound3On = 0; sound4On = 0; + gbMemory[address] &= 0xf0; } + gbMemory[address] = data & 0x80 | 0x70 | (gbMemory[address] & 0xf); break; } @@ -384,7 +407,7 @@ sound1SweepATL-=soundQuality; if(sound1SweepATL<=0) { - freq = (((int)(gbMemory[NR14]&7) << 8) | gbMemory[NR13]); + freq = (((int)(freq1high & 7)) << 8) | freq1low; int updown = 1; @@ -409,8 +432,8 @@ sound1SweepATL += sound1SweepATLReload; sound1Skip = SOUND_MAGIC/(2048 - newfreq); - gbMemory[NR13] = newfreq & 0xff; - gbMemory[NR14] = (gbMemory[NR14] & 0xf8) |((newfreq >> 8) & 7); + freq1low = newfreq & 0xff; + freq1high = (freq1high & 0xf8) |((newfreq >> 8) & 7); } } } @@ -462,9 +485,12 @@ void gbSoundChannel3() { - int value = sound3Last; + int value = 0; if(sound3On && (sound3ATL || !sound3Continue)) { + + value = sound3Last; + sound3Index += soundQuality*sound3Skip; sound3Index &= 0x1fffffff; @@ -552,7 +578,7 @@ sound4ATL-=soundQuality; if(sound4ATL <= 0 && sound4Continue) { - gbMemory[NR52] &= 0xfd; + gbMemory[NR52] &= 0xf7; sound4On = 0; } } @@ -592,7 +618,7 @@ } if(gbDigitalSound) - res = soundLevel1*256; + res *= soundLevel1*256; else res *= soundLevel1*60; @@ -654,7 +680,7 @@ } if(gbDigitalSound) - res = soundLevel2*256; + res *= soundLevel2*256; else res *= soundLevel2*60; @@ -822,7 +848,10 @@ gbSoundEvent(0xff24, 0x77); gbSoundEvent(0xff25, 0xf3); - gbSoundEvent(0xff26, 0xf0); + if (gbHardware & 0x4) + gbSoundEvent(0xff26, 0xf0); + else + gbSoundEvent(0xff26, 0xf1); // don't translate if(soundDebug) { @@ -934,6 +963,18 @@ { utilWriteData(gzFile, gbSoundSaveStruct); + utilWriteInt(gzFile, sound1ATLreload); + utilWriteInt(gzFile, freq1low); + utilWriteInt(gzFile, freq1high); + utilWriteInt(gzFile, sound2ATLreload); + utilWriteInt(gzFile, freq2low); + utilWriteInt(gzFile, freq2high); + utilWriteInt(gzFile, sound3ATLreload); + utilWriteInt(gzFile, freq3low); + utilWriteInt(gzFile, freq3high); + utilWriteInt(gzFile, sound4ATLreload); + utilWriteInt(gzFile, freq4); + utilGzWrite(gzFile, soundBuffer, 4*735); utilGzWrite(gzFile, soundFinalWave, 2*735); utilGzWrite(gzFile, &soundQuality, sizeof(int)); @@ -943,6 +984,35 @@ { utilReadData(gzFile, gbSoundSaveStruct); + if (version<11) + { + sound1ATLreload = 172 * (64 - (gbMemory[NR11] & 0x3f)); + freq1low = gbMemory[NR13]; + freq1high = gbMemory[NR14] & 7; + sound2ATLreload = 172 * (64 - (gbMemory[NR21] & 0x3f)); + freq2low = gbMemory[NR23]; + freq2high = gbMemory[NR24] & 7; + sound3ATLreload = 172 * (256 - gbMemory[NR31]); + freq3low = gbMemory[NR33]; + freq3high = gbMemory[NR34] & 7; + sound4ATLreload = 172 * (64 - (gbMemory[NR41] & 0x3f)); + freq4 = soundFreqRatio[gbMemory[NR43] & 7]; + } + else + { + sound1ATLreload = utilReadInt(gzFile); + freq1low = utilReadInt(gzFile); + freq1high = utilReadInt(gzFile); + sound2ATLreload = utilReadInt(gzFile); + freq2low = utilReadInt(gzFile); + freq2high = utilReadInt(gzFile); + sound3ATLreload = utilReadInt(gzFile); + freq3low = utilReadInt(gzFile); + freq3high = utilReadInt(gzFile); + sound4ATLreload = utilReadInt(gzFile); + freq4 = utilReadInt(gzFile); + } + soundBufferIndex = soundIndex * 2; utilGzRead(gzFile, soundBuffer, 4*735); diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/Makefile.in ./src/gtk/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/gtk/Makefile.in 2004-05-14 06:44:28 +0900 +++ ./src/gtk/Makefile.in 2004-09-30 07:23:40 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/images/Makefile.in ./src/gtk/images/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/gtk/images/Makefile.in 2004-05-14 06:40:58 +0900 +++ ./src/gtk/images/Makefile.in 2004-09-30 07:23:39 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/main.cpp ./src/gtk/main.cpp --- ../VisualBoyAdvance-1.7.2/src/gtk/main.cpp 2004-05-22 01:02:35 +0900 +++ ./src/gtk/main.cpp 2004-09-30 05:34:18 +0900 @@ -22,10 +22,10 @@ #include -#include #include #include #include +#include #include "images/vba-wm-pixbufs.h" diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/system.cpp ./src/gtk/system.cpp --- ../VisualBoyAdvance-1.7.2/src/gtk/system.cpp 2004-05-06 17:26:00 +0900 +++ ./src/gtk/system.cpp 2006-09-04 06:52:25 +0900 @@ -338,6 +338,10 @@ { } +void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, int size, int t) +{ +} + void (*dbgMain)() = debuggerMain; void (*dbgSignal)(int, int) = debuggerSignal; void (*dbgOutput)(char *, u32) = debuggerOutput; diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/window.cpp ./src/gtk/window.cpp --- ../VisualBoyAdvance-1.7.2/src/gtk/window.cpp 2004-05-21 22:27:07 +0900 +++ ./src/gtk/window.cpp 2004-09-16 07:12:53 +0900 @@ -909,15 +909,9 @@ for (int i = 0; i < 0x10000; i++) { -#if G_BYTE_ORDER == G_LITTLE_ENDIAN systemColorMap32[i] = (((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift)); -#else - systemColorMap32[i] = (((i & 0x1f) << systemRedShift) - | (((i & 0x3e0) >> 5) << systemGreenShift) - | (((i & 0x7c00) >> 10) << systemBlueShift)); -#endif } gbFrameSkip = 0; diff -urN ../VisualBoyAdvance-1.7.2/src/gtk/window.h ./src/gtk/window.h --- ../VisualBoyAdvance-1.7.2/src/gtk/window.h 2004-05-21 22:25:41 +0900 +++ ./src/gtk/window.h 2004-09-30 05:34:18 +0900 @@ -23,8 +23,8 @@ #include #include -#include #include +#include #ifndef GTKMM20 # include "sigccompat.h" diff -urN ../VisualBoyAdvance-1.7.2/src/hq2x.cpp ./src/hq2x.cpp --- ../VisualBoyAdvance-1.7.2/src/hq2x.cpp 2004-01-21 07:02:03 +0900 +++ ./src/hq2x.cpp 2004-12-19 08:09:56 +0900 @@ -559,7 +559,7 @@ while(count) { dst0 += dstPitch; dst1 += dstPitch; - hq2x_16_def(dst0, dst1, src0, src1, src2, width); + lq2x_16_def(dst0, dst1, src0, src1, src2, width); src0 = src1; src1 = src2; src2 += srcPitch >> 1; @@ -587,7 +587,7 @@ while(count) { dst0 += dstPitch >> 1; dst1 += dstPitch >> 1; - hq2x_32_def(dst0, dst1, src0, src1, src2, width); + lq2x_32_def(dst0, dst1, src0, src1, src2, width); src0 = src1; src1 = src2; src2 += srcPitch >> 2; diff -urN ../VisualBoyAdvance-1.7.2/src/i386/2xSaImmx.asm ./src/i386/2xSaImmx.asm --- ../VisualBoyAdvance-1.7.2/src/i386/2xSaImmx.asm 2003-11-04 23:08:22 +0900 +++ ./src/i386/2xSaImmx.asm 2006-06-20 20:35:21 +0900 @@ -1,40 +1,38 @@ ;/*---------------------------------------------------------------------* ; * The following (piece of) code, (part of) the 2xSaI engine, * -; * copyright (c) 1999 - 2001 by Derek Liauw Kie Fa. * -; * Non-Commercial use of this software is allowed and is encouraged, * -; * provided that appropriate credit be given. * +; * copyright (c) 2001 by Derek Liauw Kie Fa. * +; * Non-Commercial use of the engine is allowed and is encouraged, * +; * provided that appropriate credit be given and that this copyright * +; * notice will not be removed under any circumstance. * ; * You may freely modify this code, but I request * ; * that any improvements to the engine be submitted to me, so * ; * that I can implement these improvements in newer versions of * -; * the software. * +; * the engine. * ; * If you need more information, have any comments or suggestions, * -; * you can e-mail me. My e-mail: derek-liauw@usa.net. * +; * you can e-mail me. My e-mail: DerekL666@yahoo.com * ; *---------------------------------------------------------------------*/ +; modified by Spacy to compile with yasm [2006-06-20] ;---------------------- -; 2xSaI version 0.59 WIP, soon to become version 0.60 +; 2xSaI, Super2xSaI, SuperEagle .. FINAL. no versioning anymore.. ;---------------------- -;%define FAR_POINTER - - - - BITS 32 + BITS 32 %ifdef __DJGPP__ GLOBAL __2xSaILine GLOBAL __2xSaISuperEagleLine - GLOBAL __2xSaISuper2xSaILine + GLOBAL __2xSaISuper2xSaILine GLOBAL _Init_2xSaIMMX %else GLOBAL _2xSaILine GLOBAL _2xSaISuperEagleLine - GLOBAL _2xSaISuper2xSaILine + GLOBAL _2xSaISuper2xSaILine GLOBAL Init_2xSaIMMX %endif - SECTION .text ALIGN = 32 + SECTION .text ALIGN = 32 -%ifdef FAR_POINTER -;EXTERN_C void _2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width, +%ifdef __DJGPP__ +;EXTERN_C void __2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width, ; uint8 *dstPtr, uint32 dstPitch, uint16 dstSegment); %else ;EXTERN_C void _2xSaILine (uint8 *srcPtr, uint32 srcPitch, uint32 width, @@ -50,8 +48,6 @@ dstSegment equ 32 - - colorB0 equ -2 colorB1 equ 0 colorB2 equ 2 @@ -79,18 +75,23 @@ + + + + + %ifdef __DJGPP__ __2xSaISuper2xSaILine: %else -_2xSaISuper2xSaILine: +NEWSYM _2xSaISuper2xSaILine %endif ; Store some stuff - push ebp - mov ebp, esp + push ebp + mov ebp, esp pushad ; Prepare the destination -%ifdef FAR_POINTER +%ifdef __DJGPP__ ; Set the selector mov eax, [ebp+dstSegment] mov fs, ax @@ -98,11 +99,11 @@ mov edx, [ebp+dstOffset] ; edx points to the screen ; Prepare the source ; eax points to colorA - mov eax, [ebp+srcPtr] ;eax points to colorA - mov ebx, [ebp+srcPitch] ;ebx contains the source pitch - mov ecx, [ebp+width] ;ecx contains the number of pixels to process + mov eax, [ebp+srcPtr] ;eax points to colorA + mov ebx, [ebp+srcPitch] ;ebx contains the source pitch + mov ecx, [ebp+width] ;ecx contains the number of pixels to process ; eax now points to colorB1 - sub eax, ebx ;eax points to B1 which is the base + sub eax, ebx ;eax points to B1 which is the base ; Main Loop .Loop: push ecx @@ -111,7 +112,7 @@ mov ecx, [ebp+deltaPtr] - ;load source img + ;load source img movq mm0, [eax+colorB0] movq mm1, [eax+colorB3] movq mm2, [eax+ebx+color4] @@ -124,7 +125,7 @@ movq mm7, [eax+ebx+ebx+colorA3] pop eax - ;compare to delta + ;compare to delta pcmpeqw mm0, [ecx+2+colorB0] pcmpeqw mm1, [ecx+2+colorB3] pcmpeqw mm2, [ecx+ebx+2+color4] @@ -137,7 +138,7 @@ sub ecx, ebx - ;compose results + ;compose results pand mm0, mm1 pand mm2, mm3 pand mm4, mm5 @@ -147,14 +148,14 @@ pxor mm7, mm7 pand mm0, mm4 movq mm6, [eax+colorB0] - pcmpeqw mm7, mm0 ;did any compare give us a zero ? + pcmpeqw mm7, mm0 ;did any compare give us a zero ? movq [ecx+2+colorB0], mm6 packsswb mm7, mm7 movd ecx, mm7 - test ecx, ecx - jz near .SKIP_PROCESS ;no, so we can skip + test ecx, ecx + jz near .SKIP_PROCESS ;no, so we can skip ;End Delta @@ -432,15 +433,15 @@ pcmpgtw mm0, mm1 por mm7, [Mask35] - por mm0, [Mask26] + por mm0, [Mask26] movq [Mask35], mm7 movq [Mask26], mm0 .SKIP_GUESS: - ;Start the ASSEMBLY !!! eh... compose all the results together to form the final image... + ;Start the ASSEMBLY !!! eh... compose all the results together to form the final image... - + movq mm0, [eax+ebx+color5] movq mm1, [eax+ebx+ebx+color2] movq mm2, mm0 @@ -459,7 +460,7 @@ pand mm3, mm2 paddw mm0, mm3 ;mm0 contains the interpolated values - ;--------------------------- + ;--------------------------- @@ -484,102 +485,102 @@ %endif - movq mm7, [Mask26] - movq mm6, [eax+colorB2] - movq mm5, [eax+ebx+ebx+color2] - movq mm4, [eax+ebx+ebx+color1] - pcmpeqw mm4, mm5 - pcmpeqw mm6, mm5 - pxor mm5, mm5 - pand mm7, mm4 - pcmpeqw mm6, mm5 - pand mm7, mm6 - - - - movq mm6, [eax+ebx+ebx+color3] - movq mm5, [eax+ebx+ebx+color2] - movq mm4, [eax+ebx+ebx+color1] - movq mm2, [eax+ebx+color5] - movq mm1, [eax+ebx+color4] - movq mm3, [eax+colorB0] - - pcmpeqw mm2, mm4 - pcmpeqw mm6, mm5 - pcmpeqw mm1, mm5 - pcmpeqw mm3, mm5 - pxor mm5, mm5 - pcmpeqw mm2, mm5 - pcmpeqw mm3, mm5 - pand mm6, mm1 - pand mm2, mm3 - pand mm6, mm2 - por mm7, mm6 - - - movq mm6, mm7 - pcmpeqw mm6, mm5 - pand mm7, mm0 - - movq mm1, [eax+ebx+color5] - pand mm6, mm1 - por mm7, mm6 - movq [final1a], mm7 ;finished 1a - - - - ;-------------------------------- - - movq mm7, [Mask35] - push eax - add eax, ebx - movq mm6, [eax+ebx+ebx+colorA2] - pop eax - movq mm5, [eax+ebx+color5] - movq mm4, [eax+ebx+color4] - pcmpeqw mm4, mm5 - pcmpeqw mm6, mm5 - pxor mm5, mm5 - pand mm7, mm4 - pcmpeqw mm6, mm5 - pand mm7, mm6 - - - - movq mm6, [eax+ebx+color6] - movq mm5, [eax+ebx+color5] - movq mm4, [eax+ebx+color4] - movq mm2, [eax+ebx+ebx+color2] - movq mm1, [eax+ebx+ebx+color1] - push eax - add eax, ebx - movq mm3, [eax+ebx+ebx+colorA0] - pop eax - - pcmpeqw mm2, mm4 - pcmpeqw mm6, mm5 - pcmpeqw mm1, mm5 - pcmpeqw mm3, mm5 - pxor mm5, mm5 - pcmpeqw mm2, mm5 - pcmpeqw mm3, mm5 - pand mm6, mm1 - pand mm2, mm3 - pand mm6, mm2 - por mm7, mm6 - - - movq mm6, mm7 - pcmpeqw mm6, mm5 - pand mm7, mm0 - - movq mm1, [eax+ebx+ebx+color2] - pand mm6, mm1 - por mm7, mm6 - movq [final2a], mm7 ;finished 2a + movq mm7, [Mask26] + movq mm6, [eax+colorB2] + movq mm5, [eax+ebx+ebx+color2] + movq mm4, [eax+ebx+ebx+color1] + pcmpeqw mm4, mm5 + pcmpeqw mm6, mm5 + pxor mm5, mm5 + pand mm7, mm4 + pcmpeqw mm6, mm5 + pand mm7, mm6 + + + + movq mm6, [eax+ebx+ebx+color3] + movq mm5, [eax+ebx+ebx+color2] + movq mm4, [eax+ebx+ebx+color1] + movq mm2, [eax+ebx+color5] + movq mm1, [eax+ebx+color4] + movq mm3, [eax+colorB0] + + pcmpeqw mm2, mm4 + pcmpeqw mm6, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm3, mm5 + pxor mm5, mm5 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm6, mm1 + pand mm2, mm3 + pand mm6, mm2 + por mm7, mm6 + + + movq mm6, mm7 + pcmpeqw mm6, mm5 + pand mm7, mm0 + + movq mm1, [eax+ebx+color5] + pand mm6, mm1 + por mm7, mm6 + movq [final1a], mm7 ;finished 1a + + + + ;-------------------------------- + + movq mm7, [Mask35] + push eax + add eax, ebx + movq mm6, [eax+ebx+ebx+colorA2] + pop eax + movq mm5, [eax+ebx+color5] + movq mm4, [eax+ebx+color4] + pcmpeqw mm4, mm5 + pcmpeqw mm6, mm5 + pxor mm5, mm5 + pand mm7, mm4 + pcmpeqw mm6, mm5 + pand mm7, mm6 + + + + movq mm6, [eax+ebx+color6] + movq mm5, [eax+ebx+color5] + movq mm4, [eax+ebx+color4] + movq mm2, [eax+ebx+ebx+color2] + movq mm1, [eax+ebx+ebx+color1] + push eax + add eax, ebx + movq mm3, [eax+ebx+ebx+colorA0] + pop eax + + pcmpeqw mm2, mm4 + pcmpeqw mm6, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm3, mm5 + pxor mm5, mm5 + pcmpeqw mm2, mm5 + pcmpeqw mm3, mm5 + pand mm6, mm1 + pand mm2, mm3 + pand mm6, mm2 + por mm7, mm6 + + + movq mm6, mm7 + pcmpeqw mm6, mm5 + pand mm7, mm0 + + movq mm1, [eax+ebx+ebx+color2] + pand mm6, mm1 + por mm7, mm6 + movq [final2a], mm7 ;finished 2a - ;-------------------------------------------- + ;-------------------------------------------- %ifdef dfhsdfhsdahdsfhdsfh @@ -600,168 +601,133 @@ product1b = INTERPOLATE (color5, color6); %endif - push eax - add eax, ebx - pxor mm7, mm7 - movq mm0, [eax+ebx+ebx+colorA0] - movq mm1, [eax+ebx+ebx+colorA1] - movq mm2, [eax+ebx+ebx+colorA2] - movq mm3, [eax+ebx+ebx+colorA3] - pop eax - movq mm4, [eax+ebx+ebx+color2] - movq mm5, [eax+ebx+ebx+color3] - movq mm6, [eax+ebx+color6] - - pcmpeqw mm6, mm5 - pcmpeqw mm1, mm5 - pcmpeqw mm4, mm2 - pcmpeqw mm0, mm5 - pcmpeqw mm4, mm7 - pcmpeqw mm0, mm7 - pand mm0, mm4 - pand mm6, mm1 - pand mm0, mm6 - - - push eax - add eax, ebx - movq mm1, [eax+ebx+ebx+colorA1] - pop eax - movq mm4, [eax+ebx+ebx+color2] - movq mm5, [eax+ebx+color5] - movq mm6, [eax+ebx+ebx+color3] - - pcmpeqw mm5, mm4 - pcmpeqw mm2, mm4 - pcmpeqw mm1, mm6 - pcmpeqw mm3, mm4 - pcmpeqw mm1, mm7 - pcmpeqw mm3, mm7 - pand mm2, mm5 - pand mm1, mm3 - pand mm1, mm2 - - - movq mm7, mm0 - por mm7, mm1 - - movq mm4, [Mask35] - movq mm3, [Mask26] - - movq mm6, mm4 - pand mm6, mm7 - pxor mm4, mm6 - - movq mm6, mm3 - pand mm6, mm7 - pxor mm3, mm6 - - movq mm2, mm0 - movq mm7, [I2333Pixel] - movq mm6, [I2223Pixel] - movq mm5, [I23Pixel] - - - por mm2, mm4 - pand mm4, [eax+ebx+ebx+color3] - por mm2, mm3 - pand mm3, [eax+ebx+ebx+color2] - por mm2, mm1 - pand mm0, mm7 - pand mm1, mm6 - pxor mm7, mm7 - pcmpeqw mm2, mm7 - por mm0, mm1 - por mm3, mm4 - pand mm2, mm5 - por mm0, mm3 - por mm0, mm2 - movq [final2b], mm0 - - ;----------------------------------- - - - pxor mm7, mm7 - movq mm0, [eax+colorB0] - movq mm1, [eax+colorB1] - movq mm2, [eax+colorB2] - movq mm3, [eax+colorB3] - movq mm4, [eax+ebx+color5] - movq mm5, [eax+ebx+color6] - movq mm6, [eax+ebx+ebx+color3] - - pcmpeqw mm6, mm5 - pcmpeqw mm1, mm5 - pcmpeqw mm4, mm2 - pcmpeqw mm0, mm5 - pcmpeqw mm4, mm7 - pcmpeqw mm0, mm7 - pand mm0, mm4 - pand mm6, mm1 - pand mm0, mm6 - - movq mm1, [eax+colorB1] - movq mm4, [eax+ebx+color5] - movq mm5, [eax+ebx+ebx+color2] - movq mm6, [eax+ebx+color6] - - pcmpeqw mm5, mm4 - pcmpeqw mm2, mm4 - pcmpeqw mm1, mm6 - pcmpeqw mm3, mm4 - pcmpeqw mm1, mm7 - pcmpeqw mm3, mm7 - pand mm2, mm5 - pand mm1, mm3 - pand mm1, mm2 - - - movq mm7, mm0 - por mm7, mm1 - - movq mm4, [Mask35] - movq mm3, [Mask26] - - movq mm6, mm4 - pand mm6, mm7 - pxor mm4, mm6 - - movq mm6, mm3 - pand mm6, mm7 - pxor mm3, mm6 - - movq mm2, mm0 - movq mm7, [I5666Pixel] - movq mm6, [I5556Pixel] - movq mm5, [I56Pixel] - - - por mm2, mm4 - pand mm4, [eax+ebx+color5] - por mm2, mm3 - pand mm3, [eax+ebx+color6] - por mm2, mm1 - pand mm0, mm7 - pand mm1, mm6 - pxor mm7, mm7 - pcmpeqw mm2, mm7 - por mm0, mm1 - por mm3, mm4 - pand mm2, mm5 - por mm0, mm3 - por mm0, mm2 - movq [final1b], mm0 - - ;--------- - - movq mm0, [final1a] - movq mm4, [final2a] - movq mm2, [final1b] - movq mm6, [final2b] - + push eax + add eax, ebx + pxor mm7, mm7 + movq mm0, [eax+ebx+ebx+colorA0] + movq mm1, [eax+ebx+ebx+colorA1] + movq mm2, [eax+ebx+ebx+colorA2] + movq mm3, [eax+ebx+ebx+colorA3] + pop eax + movq mm4, [eax+ebx+ebx+color2] + movq mm5, [eax+ebx+ebx+color3] + movq mm6, [eax+ebx+color6] + + pcmpeqw mm6, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm4, mm2 + pcmpeqw mm0, mm5 + pcmpeqw mm4, mm7 + pcmpeqw mm0, mm7 + pand mm0, mm4 + pand mm6, mm1 + pand mm0, mm6 + + movq mm4, [eax+ebx+color2] + movq mm5, [eax+ebx+ebx+color5] + movq mm6, [eax+ebx+ebx+color3] + + pcmpeqw mm5, mm4 + pcmpeqw mm2, mm4 + pcmpeqw mm1, mm6 + pcmpeqw mm3, mm4 + pcmpeqw mm1, mm7 + pcmpeqw mm3, mm7 + pand mm2, mm5 + pand mm1, mm3 + pand mm1, mm2 + + movq mm2, mm0 + movq mm7, [I2333Pixel] + movq mm6, [I2223Pixel] + movq mm5, [I23Pixel] + movq mm4, [Mask35] + movq mm3, [Mask26] + + por mm2, mm4 + pand mm4, [eax+ebx+ebx+color3] + por mm2, mm3 + pand mm3, [eax+ebx+ebx+color2] + por mm2, mm1 + pand mm0, mm7 + pand mm1, mm6 + pxor mm7, mm7 + pcmpeqw mm2, mm7 + por mm0, mm1 + por mm3, mm4 + pand mm2, mm5 + por mm0, mm3 + por mm0, mm2 + movq [final2b], mm0 + + ;----------------------------------- + + + pxor mm7, mm7 + movq mm0, [eax+colorB0] + movq mm1, [eax+colorB1] + movq mm2, [eax+colorB2] + movq mm3, [eax+colorB3] + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+color6] + movq mm6, [eax+ebx+ebx+color3] + + pcmpeqw mm6, mm5 + pcmpeqw mm1, mm5 + pcmpeqw mm4, mm2 + pcmpeqw mm0, mm5 + pcmpeqw mm4, mm7 + pcmpeqw mm0, mm7 + pand mm0, mm4 + pand mm6, mm1 + pand mm0, mm6 + + movq mm4, [eax+ebx+color5] + movq mm5, [eax+ebx+ebx+color2] + movq mm6, [eax+ebx+color6] + + pcmpeqw mm5, mm4 + pcmpeqw mm2, mm4 + pcmpeqw mm1, mm6 + pcmpeqw mm3, mm4 + pcmpeqw mm1, mm7 + pcmpeqw mm3, mm7 + pand mm2, mm5 + pand mm1, mm3 + pand mm1, mm2 + + movq mm2, mm0 + movq mm7, [I5666Pixel] + movq mm6, [I5556Pixel] + movq mm5, [I56Pixel] + movq mm4, [Mask35] + movq mm3, [Mask26] + + por mm2, mm4 + pand mm4, [eax+ebx+color5] + por mm2, mm3 + pand mm3, [eax+ebx+color6] + por mm2, mm1 + pand mm0, mm7 + pand mm1, mm6 + pxor mm7, mm7 + pcmpeqw mm2, mm7 + por mm0, mm1 + por mm3, mm4 + pand mm2, mm5 + por mm0, mm3 + por mm0, mm2 + movq [final1b], mm0 + + ;--------- + + movq mm0, [final1a] + movq mm4, [final2a] + movq mm2, [final1b] + movq mm6, [final2b] - movq mm1, mm0 - movq mm5, mm4 + movq mm1, mm0 + movq mm5, mm4 punpcklwd mm0, mm2 @@ -780,12 +746,12 @@ movq [fs:edx+8], mm5 pop edx %else - movq [edx], mm0 - movq [edx+8], mm1 + movq [es:edx], mm0 + movq [es:edx+8], mm1 push edx add edx, [ebp+dstPitch] - movq [edx], mm4 - movq [edx+8], mm5 + movq [es:edx], mm4 + movq [es:edx+8], mm5 pop edx %endif .SKIP_PROCESS: @@ -818,18 +784,22 @@ + + + + %ifdef __DJGPP__ __2xSaISuperEagleLine: %else -_2xSaISuperEagleLine: +NEWSYM _2xSaISuperEagleLine %endif ; Store some stuff - push ebp - mov ebp, esp + push ebp + mov ebp, esp pushad ; Prepare the destination -%ifdef FAR_POINTER +%ifdef __DJGPP__ ; Set the selector mov eax, [ebp+dstSegment] mov fs, ax @@ -1217,9 +1187,9 @@ pcmpgtw mm0, mm1 por mm7, [Mask35] - por mm0, [Mask26] + por mm1, [Mask26] movq [Mask35], mm7 - movq [Mask26], mm0 + movq [Mask26], mm1 .SKIP_GUESS: ;Start the ASSEMBLY !!! @@ -1331,7 +1301,7 @@ -%ifdef FAR_POINTER +%ifdef __DJGPP__ movq [fs:edx], mm0 movq [fs:edx+8], mm1 push edx @@ -1340,12 +1310,12 @@ movq [fs:edx+8], mm5 pop edx %else - movq [edx], mm0 - movq [edx+8], mm1 + movq [es:edx], mm0 + movq [es:edx+8], mm1 push edx add edx, [ebp+dstPitch] - movq [edx], mm4 - movq [edx+8], mm5 + movq [es:edx], mm4 + movq [es:edx+8], mm5 pop edx %endif .SKIP_PROCESS: @@ -1377,7 +1347,7 @@ ;------------------------------------------------------------------------- -;This is version 0.50 +;This is 2xSaI colorI equ -2 colorE equ 0 colorF equ 2 @@ -1401,15 +1371,15 @@ %ifdef __DJGPP__ __2xSaILine: %else -_2xSaILine: +NEWSYM _2xSaILine %endif ; Store some stuff - push ebp - mov ebp, esp + push ebp + mov ebp, esp pushad ; Prepare the destination -%ifdef FAR_POINTER +%ifdef __DJGPP__ ; Set the selector mov eax, [ebp+dstSegment] mov fs, ax @@ -1599,12 +1569,12 @@ punpcklwd mm5, mm0 punpckhwd mm6, mm0 -%ifdef FAR_POINTER +%ifdef __DJGPP__ movq [fs:edx], mm5 movq [fs:edx+8], mm6 %else - movq [edx], mm5 - movq [edx+8], mm6 + movq [es:edx], mm5 + movq [es:edx+8], mm6 %endif ;------------------------------------------------ @@ -1766,7 +1736,6 @@ movd ecx, mm7 test ecx, ecx jz near .SKIP_GUESS - ;--------------------------------------------- ; Map of the pixels: I|E F|J ; G|A B|K @@ -1887,9 +1856,9 @@ pcmpgtw mm0, mm1 por mm7, [Mask1] - por mm0, [Mask2] + por mm1, [Mask2] movq [Mask1], mm7 - movq [Mask2], mm0 + movq [Mask2], mm1 .SKIP_GUESS: ;---------------------------- @@ -1953,12 +1922,12 @@ push edx add edx, [ebp+dstPitch] -%ifdef FAR_POINTER +%ifdef __DJGPP__ movq [fs:edx], mm0 movq [fs:edx+8], mm1 %else - movq [edx], mm0 - movq [edx+8], mm1 + movq [es:edx], mm0 + movq [es:edx+8], mm1 %endif pop edx @@ -1992,28 +1961,28 @@ %ifdef __DJGPP__ _Init_2xSaIMMX: %else -Init_2xSaIMMX: +NEWSYM Init_2xSaIMMX %endif ; Store some stuff - push ebp - mov ebp, esp + push ebp + mov ebp, esp push edx ;Damn thing doesn't work -; mov eax,1 -; cpuid -; test edx, 0x00800000 ;test bit 23 -; jz end2 ;bit not set => no MMX detected - - mov eax, [ebp+8] ;PixelFormat - cmp eax, 555 - jz Bits555 - cmp eax, 565 - jz Bits565 +; mov eax,1 +; cpuid +; test edx, 0x00800000 ;test bit 23 +; jz end2 ;bit not set => no MMX detected + + mov eax, [ebp+8] ;PixelFormat + cmp eax, 555 + jz Bits555 + cmp eax, 565 + jz Bits565 end2: - mov eax, 1 - jmp end3 + mov eax, 1 + jmp end Bits555: mov edx, 0x7BDE7BDE mov eax, colorMask @@ -2032,7 +2001,7 @@ mov [eax], edx mov [eax+4], edx mov eax, 0 - jmp end3 + jmp end Bits565: mov edx, 0xF7DEF7DE mov eax, colorMask @@ -2051,12 +2020,12 @@ mov [eax], edx mov [eax+4], edx mov eax, 0 - jmp end3 -end3: + jmp end +end: pop edx - mov esp, ebp - pop ebp - ret + mov esp, ebp + pop ebp + ret ;------------------------------------------------------------------------- @@ -2067,21 +2036,17 @@ ;------------------------------------------------------------------------- ;------------------------------------------------------------------------- - SECTION .data ALIGN = 32 + SECTION .data ALIGN = 32 ;Some constants -colorMask dd 0xF7DEF7DE,0xF7DEF7DE -lowPixelMask dd 0x08210821,0x08210821 +colorMask dd 0xF7DEF7DE, 0xF7DEF7DE +lowPixelMask dd 0x08210821, 0x08210821 -qcolorMask dd 0xE79CE79C,0xE79CE79C -qlowpixelMask dd 0x18631863,0x18631863 +qcolorMask dd 0xE79CE79C, 0xE79CE79C +qlowpixelMask dd 0x18631863, 0x18631863 -darkenMask dd 0xC718C718,0xC718C718 -GreenMask dd 0x07E007E0,0x07E007E0 -RedBlueMask dd 0xF81FF81F,0xF81FF81F - -FALSE dd 0x00000000,0x00000000 -TRUE dd 0xffffffff,0xffffffff -ONE dd 0x00010001,0x00010001 +FALSE dd 0x00000000, 0x00000000 +TRUE dd 0xffffffff, 0xffffffff +ONE dd 0x00010001, 0x00010001 SECTION .bss ALIGN = 32 diff -urN ../VisualBoyAdvance-1.7.2/src/i386/Makefile.in ./src/i386/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/i386/Makefile.in 2004-05-14 06:40:00 +0900 +++ ./src/i386/Makefile.in 2004-09-30 07:23:30 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/interframe.cpp ./src/interframe.cpp --- ../VisualBoyAdvance-1.7.2/src/interframe.cpp 2004-05-13 23:33:32 +0900 +++ ./src/interframe.cpp 2006-08-24 11:13:39 +0900 @@ -579,42 +579,3 @@ pos++; } } - -static int count = 0; - -void InterlaceIB(u8 *srcPtr, u32 srcPitch, int width, int height) -{ - if(frm1 == NULL) { - Init(); - } - - u16 colorMask = ~RGB_LOW_BITS_MASK; - - u16 *src0 = (u16 *)srcPtr; - u16 *src1 = (u16 *)frm1; - - int sPitch = srcPitch >> 1; - - int pos = 0; - for (int j = 0; j < height; j++) { - bool render = count ? (j & 1) != 0 : (j & 1) == 0; - if(render) { - for (int i = 0; i < sPitch; i++) { - u16 color = src0[pos]; - src0[pos] = - (((color & colorMask) >> 1) + ((((src1[pos] & colorMask) >> 1) & colorMask) >> 1)); - src1[pos] = color; - pos++; - } - } else { - for (int i = 0; i < sPitch; i++) { - u16 color = src0[pos]; - src0[pos] = - (((((color & colorMask) >> 1) & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)); - src1[pos] = color; - pos++; - } - } - } - count = count ^ 1; -} diff -urN ../VisualBoyAdvance-1.7.2/src/memgzio.c ./src/memgzio.c --- ../VisualBoyAdvance-1.7.2/src/memgzio.c 2004-01-18 08:07:32 +0900 +++ ./src/memgzio.c 2006-06-07 06:04:20 +0900 @@ -9,7 +9,7 @@ * Adapted from original gzio.c from zlib library by Forgotten */ -/* @(#) $Id: memgzio.c,v 1.3 2004/01/17 23:07:32 kxu Exp $ */ +/* @(#) $Id: memgzio.c,v 1.5 2006/06/06 21:04:20 spacy51 Exp $ */ #include #include @@ -125,7 +125,7 @@ total = file->available; } memcpy(file->next, buffer, total); - file->available -= total; + file->available -= (int)total; file->next += total; return total; } @@ -147,7 +147,7 @@ total = file->available; } memcpy(buffer, file->next, total); - file->available -= total; + file->available -= (int)total; file->next += total; return total; } @@ -170,7 +170,7 @@ local long memTell(MEMFILE *f) { - return (f->next - f->memory) - 8; + return (long)(f->next - f->memory) - 8; } local int memError(MEMFILE *f) @@ -197,7 +197,7 @@ len = vsprintf(buffer, format, list); va_end(list); - return memWrite(buffer, 1, len, f); + return (int)memWrite(buffer, 1, len, f); } /* =========================================================================== @@ -331,7 +331,7 @@ if (s->z_eof) return EOF; if (s->stream.avail_in == 0) { errno = 0; - s->stream.avail_in = memRead(s->inbuf, 1, Z_BUFSIZE, s->file); + s->stream.avail_in = (uInt)memRead(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (memError(s->file)) s->z_err = Z_ERRNO; @@ -476,8 +476,7 @@ s->stream.avail_in -= n; } if (s->stream.avail_out > 0) { - s->stream.avail_out -= memRead(next_out, 1, s->stream.avail_out, - s->file); + s->stream.avail_out -= (uInt)memRead(next_out, 1, s->stream.avail_out, s->file); } len -= s->stream.avail_out; s->stream.total_in += (uLong)len; @@ -488,7 +487,7 @@ if (s->stream.avail_in == 0 && !s->z_eof) { errno = 0; - s->stream.avail_in = memRead(s->inbuf, 1, Z_BUFSIZE, s->file); + s->stream.avail_in = (uInt)memRead(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (memError(s->file)) { diff -urN ../VisualBoyAdvance-1.7.2/src/memgzio.h ./src/memgzio.h --- ../VisualBoyAdvance-1.7.2/src/memgzio.h 2003-07-24 22:21:52 +0900 +++ ./src/memgzio.h 2006-09-04 06:52:25 +0900 @@ -8,10 +8,11 @@ /* memgzio.c - IO on .gz files in memory * Adapted from original gzio.c from zlib library by Forgotten */ -#ifndef HAVE_ZUTIL_H -#include "../win32/include/zlib/zutil.h" + +#if defined(HAVE_ZUTIL_H) || defined(_WIN32) +# include #else -#include +# include "../win32/dependencies/zlib/zutil.h" #endif gzFile ZEXPORT memgzopen(char *memory, int, const char *); diff -urN ../VisualBoyAdvance-1.7.2/src/prof/Makefile.in ./src/prof/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/prof/Makefile.in 2004-05-14 06:39:54 +0900 +++ ./src/prof/Makefile.in 2004-09-30 07:23:30 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/prof/prof.cpp ./src/prof/prof.cpp --- ../VisualBoyAdvance-1.7.2/src/prof/prof.cpp 2004-05-13 23:31:58 +0900 +++ ./src/prof/prof.cpp 2006-08-25 23:13:38 +0900 @@ -57,20 +57,14 @@ #include "../GBA.h" #include "../NLS.h" +#include "prof.h" /* for struct profile_segment */ + /* * froms is actually a bunch of unsigned shorts indexing tos */ static int profiling = 3; -static unsigned short *froms; -static struct tostruct *tos = 0; -static long tolimit = 0; -static u32 s_lowpc = 0; -static u32 s_highpc = 0; -static unsigned long s_textsize = 0; - -static int ssiz; -static char *sbuf; -static int s_scale; + +static profile_segment *first_segment = NULL; static int hz = 0; static int hist_num_bins = 0; @@ -127,13 +121,13 @@ if (mode) { /* start */ #ifdef PROFILING - cpuProfil(sbuf, ssiz, (u32)s_lowpc, s_scale); + cpuProfil(first_segment); #endif profiling = 0; } else { /* stop */ #ifdef PROFILING - cpuProfil(NULL, 0, 0, 0); + cpuProfil(NULL); #endif profiling = 3; } @@ -147,57 +141,65 @@ int monsize; char *buffer; int o; + profile_segment *newseg = (profile_segment*)calloc(1,sizeof(profile_segment)); + if (newseg) { + newseg->next = first_segment; + first_segment = newseg; + } else { + systemMessage(0, MSG); + return; + } /* * round lowpc and highpc to multiples of the density we're using * so the rest of the scaling (here and in gprof) stays in ints. */ lowpc = ROUNDDOWN(lowpc, HISTFRACTION*sizeof(HISTCOUNTER)); - s_lowpc = lowpc; + newseg->s_lowpc = lowpc; highpc = ROUNDUP(highpc, HISTFRACTION*sizeof(HISTCOUNTER)); - s_highpc = highpc; - s_textsize = highpc - lowpc; - monsize = (s_textsize / HISTFRACTION); + newseg->s_highpc = highpc; + newseg->s_textsize = highpc - lowpc; + monsize = (newseg->s_textsize / HISTFRACTION); buffer = (char *)calloc(1, 2*monsize ); if ( buffer == NULL ) { systemMessage(0, MSG); return; } - froms = (unsigned short *) calloc(1, 4*s_textsize / HASHFRACTION ); - if ( froms == NULL ) { + newseg->froms = (unsigned short *) calloc(1, 4*newseg->s_textsize / HASHFRACTION ); + if ( newseg->froms == NULL ) { systemMessage(0, MSG); free(buffer); buffer = NULL; return; } - tolimit = s_textsize * ARCDENSITY / 100; - if ( tolimit < MINARCS ) { - tolimit = MINARCS; - } else if ( tolimit > 65534 ) { - tolimit = 65534; + newseg->tolimit = newseg->s_textsize * ARCDENSITY / 100; + if ( newseg->tolimit < MINARCS ) { + newseg->tolimit = MINARCS; + } else if ( newseg->tolimit > 65534 ) { + newseg->tolimit = 65534; } - tos = (struct tostruct *) calloc(1, tolimit * sizeof( struct tostruct ) ); - if ( tos == NULL ) { + newseg->tos = (struct tostruct *) calloc(1, newseg->tolimit * sizeof( struct tostruct ) ); + if ( newseg->tos == NULL ) { systemMessage(0, MSG); free(buffer); buffer = NULL; - free(froms); - froms = NULL; + free(newseg->froms); + newseg->froms = NULL; return; } - tos[0].link = 0; - sbuf = buffer; - ssiz = monsize; + newseg->tos[0].link = 0; + newseg->sbuf = buffer; + newseg->ssiz = monsize; if ( monsize <= 0 ) return; o = highpc - lowpc; if( monsize < o ) - s_scale = (int)(( (float) monsize / o ) * SCALE_1_TO_1); + newseg->s_scale = (int)(( (float) monsize / o ) * SCALE_1_TO_1); else - s_scale = SCALE_1_TO_1; + newseg->s_scale = SCALE_1_TO_1; profControl(1); } @@ -209,6 +211,7 @@ u32 frompc; int toindex; struct gmon_hdr ghdr; + profile_segment *seg = first_segment; profControl(0); fd = fopen( "gmon.out" , "wb" ); @@ -229,11 +232,13 @@ if(hz == 0) hz = 100; - hist_num_bins = ssiz; + while(seg) { + + hist_num_bins = seg->ssiz; if(profWrite8(fd, GMON_TAG_TIME_HIST) || - profWrite32(fd, (u32)s_lowpc) || - profWrite32(fd, (u32)s_highpc) || + profWrite32(fd, (u32)seg->s_lowpc) || + profWrite32(fd, (u32)seg->s_highpc) || profWrite32(fd, hist_num_bins) || profWrite32(fd, hz) || profWrite(fd, hist_dimension, 15) || @@ -242,7 +247,7 @@ fclose(fd); return; } - u16 *hist_sample = (u16 *)sbuf; + u16 *hist_sample = (u16 *)seg->sbuf; u16 count; int i; @@ -257,23 +262,25 @@ } } - endfrom = s_textsize / (HASHFRACTION * sizeof(*froms)); + endfrom = seg->s_textsize / (HASHFRACTION * sizeof(*seg->froms)); for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) { - if ( froms[fromindex] == 0 ) { + if ( seg->froms[fromindex] == 0 ) { continue; } - frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms)); - for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link) { + frompc = seg->s_lowpc + (fromindex * HASHFRACTION * sizeof(*seg->froms)); + for (toindex=seg->froms[fromindex]; toindex!=0; toindex=seg->tos[toindex].link) { if(profWrite8(fd, GMON_TAG_CG_ARC) || profWrite32(fd, (u32)frompc) || - profWrite32(fd, (u32)tos[toindex].selfpc) || - profWrite32(fd, tos[toindex].count)) { + profWrite32(fd, (u32)seg->tos[toindex].selfpc) || + profWrite32(fd, seg->tos[toindex].count)) { systemMessage(0, "mcount: arc"); fclose(fd); return; } } } + seg = seg->next; + } fclose(fd); } @@ -284,6 +291,7 @@ register struct tostruct *top; register struct tostruct *prevtop; register long toindex; + profile_segment *seg = first_segment; /* * find the return address for mcount, @@ -309,29 +317,36 @@ * for example: signal catchers get called from the stack, * not from text space. too bad. */ - frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc); - if ((unsigned long) frompcindex > s_textsize) { + while(seg) { + u32 index = (long)frompcindex - (long)seg->s_lowpc; + if (index <= seg->s_textsize) { + frompcindex = (unsigned short *) index; + break; + } + seg = seg->next; + } + if ((unsigned long) frompcindex > seg->s_textsize) { goto done; } frompcindex = - &froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))]; + &(seg->froms[((long) frompcindex) / (HASHFRACTION * sizeof(*seg->froms))]); toindex = *frompcindex; if (toindex == 0) { /* * first time traversing this arc */ - toindex = ++tos[0].link; - if (toindex >= tolimit) { + toindex = ++seg->tos[0].link; + if (toindex >= seg->tolimit) { goto overflow; } *frompcindex = (unsigned short)toindex; - top = &tos[toindex]; + top = &seg->tos[toindex]; top->selfpc = selfpc; top->count = 1; top->link = 0; goto done; } - top = &tos[toindex]; + top = &seg->tos[toindex]; if (top->selfpc == selfpc) { /* * arc at front of chain; usual case. @@ -353,11 +368,11 @@ * so we allocate a new tostruct * and link it to the head of the chain. */ - toindex = ++tos[0].link; - if (toindex >= tolimit) { + toindex = ++seg->tos[0].link; + if (toindex >= seg->tolimit) { goto overflow; } - top = &tos[toindex]; + top = &seg->tos[toindex]; top->selfpc = selfpc; top->count = 1; top->link = *frompcindex; @@ -368,7 +383,7 @@ * otherwise, check the next arc on the chain. */ prevtop = top; - top = &tos[top->link]; + top = &seg->tos[top->link]; if (top->selfpc == selfpc) { /* * there it is. diff -urN ../VisualBoyAdvance-1.7.2/src/prof/prof.h ./src/prof/prof.h --- ../VisualBoyAdvance-1.7.2/src/prof/prof.h 2004-05-13 22:49:00 +0900 +++ ./src/prof/prof.h 2006-08-25 23:13:38 +0900 @@ -24,6 +24,24 @@ profiling is what mcount checks to see if all the data structures are ready. */ + +typedef struct profile_segment { + unsigned short *froms; + struct tostruct *tos; + long tolimit; + + u32 s_lowpc; + u32 s_highpc; + unsigned long s_textsize; + + int ssiz; + char *sbuf; + int s_scale; + + struct profile_segment *next; + +} profile_segment; + extern void profControl(int mode); extern void profStartup(u32 lowpc, u32 highpc); extern void profCleanup(); diff -urN ../VisualBoyAdvance-1.7.2/src/remote.cpp ./src/remote.cpp --- ../VisualBoyAdvance-1.7.2/src/remote.cpp 2004-05-21 02:24:47 +0900 +++ ./src/remote.cpp 2006-09-04 06:52:25 +0900 @@ -20,7 +20,7 @@ #include #include -#ifndef WIN32 +#ifndef _WIN32 # include # include # include @@ -32,14 +32,15 @@ # else // ! HAVE_ARPA_INET_H # define socklen_t int # endif // ! HAVE_ARPA_INET_H -#else // WIN32 +# define SOCKET int +#else // _WIN32 # include # include # define socklen_t int # define close closesocket # define read _read # define write _write -#endif // WIN32 +#endif // _WIN32 #include "GBA.h" @@ -54,8 +55,8 @@ int remotePort = 55555; int remoteSignal = 5; -int remoteSocket = -1; -int remoteListenSocket = -1; +SOCKET remoteSocket = -1; +SOCKET remoteListenSocket = -1; bool remoteConnected = false; bool remoteResumed = false; @@ -85,11 +86,11 @@ bool remoteTcpInit() { if(remoteSocket == -1) { -#ifdef WIN32 +#ifdef _WIN32 WSADATA wsaData; int error = WSAStartup(MAKEWORD(1,1),&wsaData); -#endif // WIN32 - int s = socket(PF_INET, SOCK_STREAM, 0); +#endif // _WIN32 + SOCKET s = socket(PF_INET, SOCK_STREAM, 0); remoteListenSocket = s; @@ -131,19 +132,19 @@ } socklen_t len = sizeof(addr); -#ifdef WIN32 +#ifdef _WIN32 int flag = 0; ioctlsocket(s, FIONBIO, (unsigned long *)&flag); -#endif // WIN32 - int s2 = accept(s, (sockaddr *)&addr, &len); +#endif // _WIN32 + SOCKET s2 = accept(s, (sockaddr *)&addr, &len); if(s2 > 0) { fprintf(stderr, "Got a connection from %s %d\n", inet_ntoa((in_addr)addr.sin_addr), ntohs(addr.sin_port)); } else { -#ifdef WIN32 +#ifdef _WIN32 int error = WSAGetLastError(); -#endif // WIN32 +#endif // _WIN32 } char dummy; recv(s2, &dummy, 1, 0); @@ -230,14 +231,14 @@ char *hex = "0123456789abcdef"; char buffer[1024]; - int count = strlen(packet); + size_t count = strlen(packet); unsigned char csum = 0; char *p = buffer; *p++ = '$'; - for(int i = 0 ;i < count; i++) { + for(size_t i = 0 ;i < count; i++) { csum += packet[i]; *p++ = packet[i]; } @@ -246,7 +247,7 @@ *p++ = hex[csum & 15]; *p++ = 0; // printf("Sending %s\n", buffer); - remoteSendFnc(buffer, count + 4); + remoteSendFnc(buffer, (int)count + 4); char c = 0; remoteRecvFnc(&c, 1); diff -urN ../VisualBoyAdvance-1.7.2/src/sdl/Makefile.in ./src/sdl/Makefile.in --- ../VisualBoyAdvance-1.7.2/src/sdl/Makefile.in 2004-05-21 03:30:10 +0900 +++ ./src/sdl/Makefile.in 2004-09-30 07:23:39 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/src/sdl/SDL.cpp ./src/sdl/SDL.cpp --- ../VisualBoyAdvance-1.7.2/src/sdl/SDL.cpp 2004-05-22 05:16:58 +0900 +++ ./src/sdl/SDL.cpp 2006-08-25 23:06:01 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -23,34 +23,34 @@ #include #include -#include "AutoBuild.h" +#include "../AutoBuild.h" #include "SDL.h" -#include "GBA.h" -#include "agbprint.h" -#include "Flash.h" -#include "Port.h" +#include "../GBA.h" +#include "../agbprint.h" +#include "../Flash.h" +#include "../Port.h" #include "debugger.h" -#include "RTC.h" -#include "Sound.h" -#include "Text.h" -#include "unzip.h" -#include "Util.h" -#include "gb/GB.h" -#include "gb/gbGlobals.h" +#include "../RTC.h" +#include "../Sound.h" +#include "../Text.h" +#include "../unzip.h" +#include "../Util.h" +#include "../gb/GB.h" +#include "../gb/gbGlobals.h" -#ifndef WIN32 +#ifndef _WIN32 # include # define GETCWD getcwd -#else // WIN32 +#else // _WIN32 # include # define GETCWD _getcwd -#endif // WIN32 +#endif // _WIN32 #ifndef __GNUC__ # define HAVE_DECL_GETOPT 0 # define __STDC__ 1 -# include "getopt.h" +# include "../getopt.h" #else // ! __GNUC__ # define HAVE_DECL_GETOPT 1 # include "getopt.h" @@ -109,6 +109,7 @@ extern void debuggerOutput(char *, u32); extern void CPUUpdateRenderBuffers(bool); +extern int gbHardware; struct EmulatedSystem emulator = { NULL, @@ -186,6 +187,7 @@ static int rewindTimer = 0; #define REWIND_SIZE 400000 +#define SYSMSG_BUFFER_SIZE 1024 #define _stricmp strcasecmp @@ -231,6 +233,7 @@ int sdlAutoIPS = 1; int sdlRtcEnable = 0; int sdlAgbPrint = 0; +int sdlMirroringEnable = 0; int sdlDefaultJoypad = 0; @@ -248,8 +251,10 @@ char screenMessageBuffer[21]; u32 screenMessageTime = 0; -SDL_cond *cond = NULL; -SDL_mutex *mutex = NULL; +// Patch #1382692 by deathpudding. +SDL_sem *sdlBufferLock = NULL; +SDL_sem *sdlBufferFull = NULL; +SDL_sem *sdlBufferEmpty = NULL; u8 sdlBuffer[4096]; int sdlSoundLen = 0; @@ -862,15 +867,15 @@ char buffer[4096]; char path[2048]; -#ifdef WIN32 +#ifdef _WIN32 #define PATH_SEP ";" #define FILE_SEP '\\' #define EXE_NAME "VisualBoyAdvance-SDL.exe" -#else // ! WIN32 +#else // ! _WIN32 #define PATH_SEP ":" #define FILE_SEP '/' #define EXE_NAME "VisualBoyAdvance" -#endif // ! WIN32 +#endif // ! _WIN32 fprintf(stderr, "Searching for file %s\n", name); @@ -893,7 +898,7 @@ return f; } -#ifdef WIN32 +#ifdef _WIN32 home = getenv("USERPROFILE"); if(home != NULL) { fprintf(stderr, "Searching user profile directory: %s\n", home); @@ -902,13 +907,13 @@ if(f != NULL) return f; } -#else // ! WIN32 +#else // ! _WIN32 fprintf(stderr, "Searching system config directory: %s\n", SYSCONFDIR); sprintf(path, "%s%c%s", SYSCONFDIR, FILE_SEP, name); f = fopen(path, "r"); if(f != NULL) return f; -#endif // ! WIN32 +#endif // ! _WIN32 if(!strchr(arg0, '/') && !strchr(arg0, '\\')) { @@ -1204,8 +1209,6 @@ if(rewindTimer < 0 || rewindTimer > 600) rewindTimer = 0; rewindTimer *= 6; // convert value to 10 frames multiple - } else if(!strcmp(key, "enhancedDetection")) { - cpuEnhancedDetection = sdlFromHex(value) ? true : false; } else { fprintf(stderr, "Unknown configuration key %s\n", key); } @@ -1306,6 +1309,8 @@ int save = atoi(value); if(save >= 0 && save <= 5) cpuSaveType = save; + } else if(!strcmp(token, "mirroringEnabled")) { + mirroringEnable = (atoi(value) == 0 ? false : true); } } } @@ -1353,10 +1358,14 @@ num+1); else sprintf(stateName,"%s%d.sgm", filename, num+1); + if(emulator.emuWriteState) emulator.emuWriteState(stateName); + sprintf(stateName, "Wrote state %d", num+1); systemScreenMessage(stateName); + + systemDrawScreen(); } void sdlReadState(int num) @@ -1374,6 +1383,8 @@ sprintf(stateName, "Loaded state %d", num+1); systemScreenMessage(stateName); + + systemDrawScreen(); } void sdlWriteBattery() @@ -1720,7 +1731,7 @@ (event.key.keysym.mod & KMOD_CTRL)) { if(emulating && emulator.emuReadMemState && rewindMemory && rewindCount) { - rewindPos = --rewindPos & 7; + rewindPos = (rewindPos - 1) & 7; emulator.emuReadMemState(&rewindMemory[REWIND_SIZE*rewindPos], REWIND_SIZE); rewindCount--; @@ -2182,6 +2193,12 @@ if(optind < argc) { char *szFile = argv[optind]; + u32 len = strlen(szFile); + if (len > SYSMSG_BUFFER_SIZE) + { + fprintf(stderr,"%s :%s: File name too long\n",argv[0],szFile); + exit(-1); + } utilGetBaseName(szFile, filename); char *p = strrchr(filename, '.'); @@ -2205,7 +2222,23 @@ if(type == IMAGE_GB) { failed = !gbLoadRom(szFile); if(!failed) { - cartridgeType = 1; + gbGetHardwareType(); + + // used for the handling of the gb Boot Rom + if (gbHardware & 5) + { + char tempName[0x800]; + strcpy(tempName, arg0); + char *p = strrchr(tempName, '\\'); + if(p) { *p = 0x00; } + strcat(tempName, "\\DMG_ROM.bin"); + fprintf(stderr, "%s\n", tempName); + gbCPUInit(tempName, useBios); + } + else useBios = false; + + gbReset(); + cartridgeType = IMAGE_GB; emulator = GBSystem; if(sdlAutoIPS) { int size = gbRomSize; @@ -2221,11 +2254,9 @@ int size = CPULoadRom(szFile); failed = (size == 0); if(!failed) { - // if(cpuEnhancedDetection && cpuSaveType == 0) { - // utilGBAFindSave(rom, size); - // } - sdlApplyPerImagePreferences(); + + doMirroring(mirroringEnable); cartridgeType = 0; emulator = GBASystem; @@ -2262,7 +2293,7 @@ paletteRAM = (u8 *)calloc(1,0x400); vram = (u8 *)calloc(1, 0x20000); oam = (u8 *)calloc(1, 0x400); - pix = (u8 *)calloc(1, 4 * 240 * 160); + pix = (u8 *)calloc(1, 4 * 241 * 162); ioMem = (u8 *)calloc(1, 0x400); emulator = GBASystem; @@ -2376,43 +2407,22 @@ if(systemColorDepth == 16) { if(sdlCalculateMaskWidth(surface->format->Gmask) == 6) { Init_2xSaI(565); - RGB_LOW_BITS_MASK = 0x821; } else { Init_2xSaI(555); - RGB_LOW_BITS_MASK = 0x421; - } - if(cartridgeType == 2) { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = (((i >> 1) & 0x1f) << systemBlueShift) | - (((i & 0x7c0) >> 6) << systemGreenShift) | - (((i & 0xf800) >> 11) << systemRedShift); - } - } else { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } } srcPitch = srcWidth * 2+4; } else { if(systemColorDepth != 32) filterFunction = NULL; - RGB_LOW_BITS_MASK = 0x010101; - if(systemColorDepth == 32) { - Init_2xSaI(32); - } - for(int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } + Init_2xSaI(32); if(systemColorDepth == 32) srcPitch = srcWidth*4 + 4; else srcPitch = srcWidth*3; } + utilUpdateSystemColorMaps(); + if(systemColorDepth != 32) { switch(filter) { case 0: @@ -2568,9 +2578,9 @@ if(emulator.emuWriteMemState && emulator.emuWriteMemState(&rewindMemory[rewindPos*REWIND_SIZE], REWIND_SIZE)) { - rewindPos = ++rewindPos & 7; + rewindPos = (rewindPos + 1) & 7; if(rewindCount == 8) - rewindTopPos = ++rewindTopPos & 7; + rewindTopPos = (rewindTopPos + 1) & 7; } } @@ -2608,7 +2618,7 @@ void systemMessage(int num, const char *msg, ...) { - char buffer[2048]; + char buffer[SYSMSG_BUFFER_SIZE*2]; va_list valist; va_start(valist, msg); @@ -2914,67 +2924,69 @@ void soundCallback(void *,u8 *stream,int len) { - if(!emulating) + if (!emulating) return; - SDL_mutexP(mutex); - // printf("Locked mutex\n"); - if(!speedup && !throttle) { - while(sdlSoundLen < 2048*2) { - if(emulating) - SDL_CondWait(cond, mutex); - else - break; - } - } - if(emulating) { - // printf("Copying data\n"); - memcpy(stream, sdlBuffer, len); - } + + // Patch #1382692 by deathpudding. + /* since this is running in a different thread, speedup and + * throttle can change at any time; save the value so locks + * stay in sync */ + bool lock = (!speedup && !throttle) ? true : false; + + if (lock) + SDL_SemWait (sdlBufferFull); + + SDL_SemWait (sdlBufferLock); + memcpy (stream, sdlBuffer, len); sdlSoundLen = 0; - if(mutex) - SDL_mutexV(mutex); + SDL_SemPost (sdlBufferLock); + + if (lock) + SDL_SemPost (sdlBufferEmpty); } void systemWriteDataToSoundBuffer() { - if(SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) - SDL_PauseAudio(0); - bool cont = true; - while(cont && !speedup && !throttle) { - SDL_mutexP(mutex); - // printf("Waiting for len < 2048 (speed up %d)\n", speedup); - if(sdlSoundLen < 2048*2) - cont = false; - SDL_mutexV(mutex); - } - - int len = soundBufferLen; - int copied = 0; - if((sdlSoundLen+len) >= 2048*2) { - // printf("Case 1\n"); - memcpy(&sdlBuffer[sdlSoundLen],soundFinalWave, 2048*2-sdlSoundLen); - copied = 2048*2 - sdlSoundLen; + // Patch #1382692 by deathpudding. + if (SDL_GetAudioStatus () != SDL_AUDIO_PLAYING) + SDL_PauseAudio (0); + + if ((sdlSoundLen + soundBufferLen) >= 2048*2) { + bool lock = (!speedup && !throttle) ? true : false; + + if (lock) + SDL_SemWait (sdlBufferEmpty); + + SDL_SemWait (sdlBufferLock); + int copied = 2048*2 - sdlSoundLen; + memcpy (sdlBuffer + sdlSoundLen, soundFinalWave, copied); sdlSoundLen = 2048*2; - SDL_CondSignal(cond); - cont = true; - if(!speedup && !throttle) { - while(cont) { - SDL_mutexP(mutex); - if(sdlSoundLen < 2048*2) - cont = false; - SDL_mutexV(mutex); - } - memcpy(&sdlBuffer[0],&(((u8 *)soundFinalWave)[copied]), - soundBufferLen-copied); - sdlSoundLen = soundBufferLen-copied; - } else { - memcpy(&sdlBuffer[0], &(((u8 *)soundFinalWave)[copied]), -soundBufferLen); - } - } else { - // printf("case 2\n"); - memcpy(&sdlBuffer[sdlSoundLen], soundFinalWave, soundBufferLen); - sdlSoundLen += soundBufferLen; + SDL_SemPost (sdlBufferLock); + + if (lock) { + SDL_SemPost (sdlBufferFull); + + /* wait for buffer to be dumped by soundCallback() */ + SDL_SemWait (sdlBufferEmpty); + SDL_SemPost (sdlBufferEmpty); + + SDL_SemWait (sdlBufferLock); + memcpy (sdlBuffer, ((u8 *)soundFinalWave) + copied, + soundBufferLen - copied); + sdlSoundLen = soundBufferLen - copied; + SDL_SemPost (sdlBufferLock); + } + else { + SDL_SemWait (sdlBufferLock); + memcpy (sdlBuffer, ((u8 *) soundFinalWave) + copied, soundBufferLen); + SDL_SemPost (sdlBufferLock); + } + } + else { + SDL_SemWait (sdlBufferLock); + memcpy (sdlBuffer + sdlSoundLen, soundFinalWave, soundBufferLen); + sdlSoundLen += soundBufferLen; + SDL_SemPost (sdlBufferLock); } } @@ -3006,8 +3018,10 @@ return false; } soundBufferTotalLen = soundBufferLen*10; - cond = SDL_CreateCond(); - mutex = SDL_CreateMutex(); + // Patch #1382692 by deathpudding. + sdlBufferLock = SDL_CreateSemaphore (1); + sdlBufferFull = SDL_CreateSemaphore (0); + sdlBufferEmpty = SDL_CreateSemaphore (1); sdlSoundLen = 0; systemSoundOn = true; return true; @@ -3015,14 +3029,14 @@ void systemSoundShutdown() { - SDL_mutexP(mutex); - SDL_CondSignal(cond); - SDL_mutexV(mutex); - SDL_DestroyCond(cond); - cond = NULL; - SDL_DestroyMutex(mutex); - mutex = NULL; - SDL_CloseAudio(); + // Patch #1382692 by deathpudding. + SDL_CloseAudio (); //TODO: fix freeze + SDL_DestroySemaphore (sdlBufferLock); + SDL_DestroySemaphore (sdlBufferFull); + SDL_DestroySemaphore (sdlBufferEmpty); + sdlBufferLock = NULL; + sdlBufferFull = NULL; + sdlBufferEmpty = NULL; } void systemSoundPause() diff -urN ../VisualBoyAdvance-1.7.2/src/sdl/TestEmu.cpp ./src/sdl/TestEmu.cpp --- ../VisualBoyAdvance-1.7.2/src/sdl/TestEmu.cpp 2004-05-21 03:13:15 +0900 +++ ./src/sdl/TestEmu.cpp 2006-08-25 22:09:04 +0900 @@ -23,17 +23,18 @@ #include #include -#include "AutoBuild.h" +#include "../AutoBuild.h" -#include "GBA.h" +#include "../GBA.h" #include "debugger.h" -#include "Sound.h" -#include "unzip.h" -#include "Util.h" -#include "gb/GB.h" -#include "gb/gbGlobals.h" +#include "../Sound.h" +#include "../unzip.h" +#include "../Util.h" +#include "../gb/GB.h" +#include "../gb/gbGlobals.h" +#include "../getopt.h" -#ifndef WIN32 +#ifndef _WIN32 # include # define GETCWD getcwd #else // WIN32 @@ -255,7 +256,7 @@ paletteRAM = (u8 *)calloc(1,0x400); vram = (u8 *)calloc(1, 0x20000); oam = (u8 *)calloc(1, 0x400); - pix = (u8 *)calloc(1, 4 * 240 * 160); + pix = (u8 *)calloc(1, 4 * 241 * 162); ioMem = (u8 *)calloc(1, 0x400); emulator = GBASystem; @@ -352,6 +353,38 @@ { } +void sdlWriteState(int num) +{ + char stateName[2048]; + + if(saveDir[0]) + sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename), + num+1); + else + sprintf(stateName,"%s%d.sgm", filename, num+1); + if(emulator.emuWriteState) + emulator.emuWriteState(stateName); + sprintf(stateName, "Wrote state %d", num+1); + systemScreenMessage(stateName); +} + +void sdlReadState(int num) +{ + char stateName[2048]; + + if(saveDir[0]) + sprintf(stateName, "%s/%s%d.sgm", saveDir, sdlGetFilename(filename), + num+1); + else + sprintf(stateName,"%s%d.sgm", filename, num+1); + + if(emulator.emuReadState) + emulator.emuReadState(stateName); + + sprintf(stateName, "Loaded state %d", num+1); + systemScreenMessage(stateName); +} + void systemScreenCapture(int a) { char buffer[2048]; diff -urN ../VisualBoyAdvance-1.7.2/src/sdl/debugger.cpp ./src/sdl/debugger.cpp --- ../VisualBoyAdvance-1.7.2/src/sdl/debugger.cpp 2004-05-13 23:13:14 +0900 +++ ./src/sdl/debugger.cpp 2006-08-25 23:00:49 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -16,18 +16,23 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Parts adapted from VBA-H (VBA for Hackers) by LabMaster + #include #include #include +#include -#include "GBA.h" -#include "Port.h" -#include "armdis.h" -#include "elf.h" -#include "exprNode.h" +#include "../GBA.h" +#include "../Port.h" +#include "../armdis.h" +#include "../elf.h" +#include "../exprNode.h" extern bool debugger; extern int emulating; +extern void sdlWriteState(int num); +extern void sdlReadState(int num); extern struct EmulatedSystem emulator; @@ -53,6 +58,13 @@ u32 address; u32 value; int size; + + u32 cond_address; + char cond_rel; + u32 cond_value; + int cond_size; + bool ia1; + bool ia2; }; struct DebuggerCommand { @@ -62,73 +74,116 @@ char *syntax; }; -void debuggerContinueAfterBreakpoint(); - -void debuggerHelp(int,char **); -void debuggerNext(int,char **); -void debuggerContinue(int, char **); -void debuggerRegisters(int, char **); -void debuggerBreak(int, char **); -void debuggerBreakDelete(int, char **); -void debuggerBreakList(int, char **); -void debuggerBreakArm(int, char **); -void debuggerBreakWriteClear(int, char **); -void debuggerBreakThumb(int, char **); -void debuggerBreakWrite(int, char **); -void debuggerDebug(int, char **); -void debuggerDisassemble(int, char **); -void debuggerDisassembleArm(int, char **); -void debuggerDisassembleThumb(int, char **); -void debuggerEditByte(int, char **); -void debuggerEditHalfWord(int, char **); -void debuggerEdit(int, char **); -void debuggerIo(int, char **); -void debuggerLocals(int, char **); -void debuggerMemoryByte(int, char **); -void debuggerMemoryHalfWord(int, char **); -void debuggerMemory(int, char **); -void debuggerPrint(int, char **); -void debuggerQuit(int, char **); -void debuggerSetRadix(int, char **); -void debuggerSymbols(int, char **); -void debuggerVerbose(int, char **); -void debuggerWhere(int, char **); - -DebuggerCommand debuggerCommands[] = { - { "?", debuggerHelp, "Shows this help information. Type ? for command help", "[]" }, - { "ba", debuggerBreakArm, "Adds an ARM breakpoint", "
" }, - { "bd", debuggerBreakDelete,"Deletes a breakpoint", "" }, - { "bl", debuggerBreakList, "Lists breakpoints" }, +unsigned int SearchStart = 0xFFFFFFFF; +unsigned int SearchMaxMatches = 5; +u8 SearchData [64]; // It doesn't make much sense to search for more than 64 bytes +unsigned int SearchLength = 0; +unsigned int SearchResults; + +static void debuggerContinueAfterBreakpoint(); +void debuggerDoSearch(); +unsigned int AddressToGBA(u8* mem); + +static void debuggerHelp(int,char **); +static void debuggerNext(int,char **); +static void debuggerContinue(int, char **); +static void debuggerRegisters(int, char **); +static void debuggerBreak(int, char **); +static void debuggerBreakDelete(int, char **); +static void debuggerBreakList(int, char **); +static void debuggerBreakArm(int, char **); +static void debuggerBreakThumb(int, char **); +static void debuggerBreakChange(int, char **); +static void debuggerBreakChangeClear(int, char **); +static void debuggerBreakWriteClear(int, char **); +static void debuggerBreakWrite(int, char **); +static void debuggerDebug(int, char **); +static void debuggerDisassemble(int, char **); +static void debuggerDisassembleArm(int, char **); +static void debuggerDisassembleThumb(int, char **); +static void debuggerEditByte(int, char **); +static void debuggerEditHalfWord(int, char **); +static void debuggerEditRegister(int, char **); +static void debuggerEdit(int, char **); +static void debuggerFileDisassemble(int, char **); +static void debuggerFileDisassembleArm(int, char **); +static void debuggerFileDisassembleThumb(int, char **); +static void debuggerFindText(int, char **); +static void debuggerFindHex(int, char **); +static void debuggerFindResume(int, char **); +static void debuggerIo(int, char **); +static void debuggerLast(int, char **); +static void debuggerLocals(int, char **); +static void debuggerMemoryByte(int, char **); +static void debuggerMemoryHalfWord(int, char **); +static void debuggerMemory(int, char **); +static void debuggerPrint(int, char **); +static void debuggerQuit(int, char **); +static void debuggerSetRadix(int, char **); +static void debuggerSymbols(int, char **); +static void debuggerVerbose(int, char **); +static void debuggerWhere(int, char **); + +static void debuggerReadState(int, char **); +static void debuggerWriteState(int, char **); +static void debuggerDumpLoad(int, char**); +static void debuggerDumpSave(int, char**); +static void debuggerCondValidate(int n, char **args, int start); +static bool debuggerCondEvaluate(int num); +static void debuggerCondBreakThumb(int, char **); +static void debuggerCondBreakArm(int, char **); + +static DebuggerCommand debuggerCommands[] = { + { "?", debuggerHelp, "Show this help information. Type ? for command help", "[]" }, + { "ba", debuggerBreakArm, "Add an ARM breakpoint", "
" }, + { "bd", debuggerBreakDelete,"Delete a breakpoint", "" }, + { "bl", debuggerBreakList, "List breakpoints" }, + { "bpc", debuggerBreakChange, "Break on change", "
" }, + { "bpcc", debuggerBreakChangeClear, "Clear break on change", "[
]" }, { "bpw", debuggerBreakWrite, "Break on write", "
" }, - { "bpwc", debuggerBreakWriteClear, "Clear break on write", NULL }, - { "break", debuggerBreak, "Adds a breakpoint on the given function", "||" }, - { "bt", debuggerBreakThumb, "Adds a THUMB breakpoint", "
" }, - { "c", debuggerContinue, "Continues execution" , NULL }, - { "d", debuggerDisassemble, "Disassembles instructions", "[
[]]" }, - { "da", debuggerDisassembleArm, "Disassembles ARM instructions", "[
[]]" }, - { "dt", debuggerDisassembleThumb, "Disassembles THUMB instructions", "[
[]]" }, + { "bpwc", debuggerBreakWriteClear, "Clear break on write", "[
]" }, + { "break", debuggerBreak, "Add a breakpoint on the given function", "||" }, + { "bt", debuggerBreakThumb, "Add a THUMB breakpoint", "
" }, + { "c", debuggerContinue, "Continue execution" , NULL }, + { "cba", debuggerCondBreakArm, "Add a conditional ARM breakpoint", "
$
|R []\n either ==, !=, <, >, <=, >=\n either b, h, w" }, + { "cbt", debuggerCondBreakThumb, "Add a conditional THUMB breakpoint", "
$
|R []\n either ==, !=, <, >, <=, >=\n either b, h, w" }, + { "d", debuggerDisassemble, "Disassemble instructions", "[
[]]" }, + { "da", debuggerDisassembleArm, "Disassemble ARM instructions", "[
[]]" }, + { "dload",debuggerDumpLoad, "Load raw data dump from file","
"}, + { "dsave",debuggerDumpSave, "Dump raw data to file","
"}, + { "dt", debuggerDisassembleThumb, "Disassemble THUMB instructions", "[
[]]" }, { "eb", debuggerEditByte, "Modify memory location (byte)", "
" }, { "eh", debuggerEditHalfWord,"Modify memory location (half-word)","
" }, - { "ew", debuggerEdit, "Modify memory location (word)", "
for command help", "[]" }, + { "er", debuggerEditRegister, "Modify register", " " }, + { "ew", debuggerEdit, "Modify memory location (word)", "
" }, + { "fd", debuggerFileDisassemble, "Disassemble instructions to file", " [
[]]" }, + { "fda", debuggerFileDisassembleArm, "Disassemble ARM instructions to file", " [
[]]" }, + { "fdt", debuggerFileDisassembleThumb, "Disassemble THUMB instructions to file", " [
[]]" }, + { "ft", debuggerFindText, "Search memory for ASCII-string.", " [] " }, + { "fh", debuggerFindHex, "Search memory for hex-string.", " [] " }, + { "fr", debuggerFindResume, "Resume current search.", "[]" }, + { "h", debuggerHelp, "Show this help information. Type h for command help", "[]" }, { "io", debuggerIo, "Show I/O registers status", "[video|video2|dma|timer|misc]" }, - { "locals", debuggerLocals, "Shows local variables", NULL }, - { "mb", debuggerMemoryByte, "Shows memory contents (bytes)", "
" }, - { "mh", debuggerMemoryHalfWord, "Shows memory contents (half-words)", "
"}, - { "mw", debuggerMemory, "Shows memory contents (words)", "
" }, - { "n", debuggerNext, "Executes the next instruction", "[]" }, + { "last", debuggerLast, "Trigger the display of the last registers states", NULL }, + { "load", debuggerReadState, "Load a savegame", "" }, + { "locals", debuggerLocals, "Show local variables", NULL }, + { "mb", debuggerMemoryByte, "Show memory contents (bytes)", "
" }, + { "mh", debuggerMemoryHalfWord, "Show memory contents (half-words)", "
"}, + { "mw", debuggerMemory, "Show memory contents (words)", "
" }, + { "n", debuggerNext, "Execute the next instruction", "[]" }, { "print", debuggerPrint, "Print the value of a expression (if known)", "[/x|/o|/d] " }, - { "q", debuggerQuit, "Quits the emulator", NULL }, - { "r", debuggerRegisters, "Shows ARM registers", NULL }, - { "radix", debuggerSetRadix, "Sets the print radix", "" }, + { "q", debuggerQuit, "Quit the emulator", NULL }, + { "r", debuggerRegisters, "Show ARM registers", NULL }, + { "radix", debuggerSetRadix, "Set the print radix", "" }, + { "save", debuggerWriteState, "Create a savegame", "" }, { "symbols", debuggerSymbols, "List symbols", "[]" }, #ifndef FINAL_VERSION - { "trace", debuggerDebug, "Sets the trace level", "" }, + { "trace", debuggerDebug, "Set the trace level", "" }, #endif #ifdef DEV_VERSION { "verbose", debuggerVerbose, "Change verbose setting", "" }, #endif - { "where", debuggerWhere, "Shows call chain", NULL }, + { "where", debuggerWhere, "Show the call chain (if available)", NULL }, { NULL, NULL, NULL, NULL} // end marker }; @@ -139,7 +194,30 @@ int debuggerBreakpointNumber = 0; int debuggerRadix = 0; -void debuggerApplyBreakpoint(u32 address, int num, int size) +extern u32 cpuPrefetch[2]; + +#define ARM_PREFETCH \ + {\ + cpuPrefetch[0] = debuggerReadMemory(armNextPC);\ + cpuPrefetch[1] = debuggerReadMemory(armNextPC+4);\ + } + +#define THUMB_PREFETCH \ + {\ + cpuPrefetch[0] = debuggerReadHalfWord(armNextPC);\ + cpuPrefetch[1] = debuggerReadHalfWord(armNextPC+2);\ + } + +static void debuggerPrefetch() +{ + if(armState) { + ARM_PREFETCH; + } else { + THUMB_PREFETCH; + } +} + +static void debuggerApplyBreakpoint(u32 address, int num, int size) { if(size) debuggerWriteMemory(address, (u32)(0xe1200070 | @@ -150,7 +228,7 @@ (u16)(0xbe00 | num)); } -void debuggerDisableBreakpoints() +static void debuggerDisableBreakpoints() { for(int i = 0; i < debuggerNumOfBreakpoints; i++) { if(debuggerBreakpointList[i].size) @@ -162,7 +240,7 @@ } } -void debuggerEnableBreakpoints(bool skipPC) +static void debuggerEnableBreakpoints(bool skipPC) { for(int i = 0; i < debuggerNumOfBreakpoints; i++) { if(debuggerBreakpointList[i].address == armNextPC && skipPC) @@ -174,12 +252,12 @@ } } -void debuggerUsage(char *cmd) +static void debuggerUsage(char *cmd) { for(int i = 0; ; i++) { if(debuggerCommands[i].name) { if(!strcmp(debuggerCommands[i].name, cmd)) { - printf("%s %s\t%s\n", + printf("%s %s\n\n%s\n", debuggerCommands[i].name, debuggerCommands[i].syntax ? debuggerCommands[i].syntax : "", debuggerCommands[i].help); @@ -192,9 +270,9 @@ } } -void debuggerPrintBaseType(Type *t, u32 value, u32 location, - LocationType type, - int bitSize, int bitOffset) +static void debuggerPrintBaseType(Type *t, u32 value, u32 location, + LocationType type, + int bitSize, int bitOffset) { if(bitSize) { if(bitOffset) @@ -287,7 +365,7 @@ } } -char *debuggerPrintType(Type *t) +static char *debuggerPrintType(Type *t) { char buffer[1024]; static char buffer2[1024]; @@ -307,12 +385,12 @@ return t->name; } -void debuggerPrintValueInternal(Function *, Type *, ELFBlock *, int, int, u32); -void debuggerPrintValueInternal(Function *f, Type *t, - int bitSize, int bitOffset, - u32 objLocation, LocationType type); +static void debuggerPrintValueInternal(Function *, Type *, ELFBlock *, int, int, u32); +static void debuggerPrintValueInternal(Function *f, Type *t, + int bitSize, int bitOffset, + u32 objLocation, LocationType type); -u32 debuggerGetValue(u32 location, LocationType type) +static u32 debuggerGetValue(u32 location, LocationType type) { switch(type) { case LOCATION_memory: @@ -325,31 +403,31 @@ return 0; } -void debuggerPrintPointer(Type *t, u32 value) +static void debuggerPrintPointer(Type *t, u32 value) { printf("(%s)0x%08x", debuggerPrintType(t), value); } -void debuggerPrintReference(Type *t, u32 value) +static void debuggerPrintReference(Type *t, u32 value) { printf("(%s)0x%08x", debuggerPrintType(t), value); } -void debuggerPrintFunction(Type *t, u32 value) +static void debuggerPrintFunction(Type *t, u32 value) { printf("(%s)0x%08x", debuggerPrintType(t), value); } -void debuggerPrintArray(Type *t, u32 value) +static void debuggerPrintArray(Type *t, u32 value) { // todo printf("(%s[])0x%08x", debuggerPrintType(t->array->type), value); } -void debuggerPrintMember(Function *f, - Member *m, - u32 objLocation, - u32 location) +static void debuggerPrintMember(Function *f, + Member *m, + u32 objLocation, + u32 location) { int bitSize = m->bitSize; if(bitSize) { @@ -392,7 +470,7 @@ } } -void debuggerPrintStructure(Function *f, Type *t, u32 objLocation) +static void debuggerPrintStructure(Function *f, Type *t, u32 objLocation) { printf("{"); int count = t->structure->memberCount; @@ -410,7 +488,7 @@ printf("}"); } -void debuggerPrintUnion(Function *f, Type *t, u32 objLocation) +static void debuggerPrintUnion(Function *f, Type *t, u32 objLocation) { // todo printf("{"); @@ -427,7 +505,7 @@ printf("}"); } -void debuggerPrintEnum(Type *t, u32 value) +static void debuggerPrintEnum(Type *t, u32 value) { int i; for(i = 0; i < t->enumeration->count; i++) { @@ -440,9 +518,9 @@ printf("(UNKNOWN VALUE) %d", value); } -void debuggerPrintValueInternal(Function *f, Type *t, - int bitSize, int bitOffset, - u32 objLocation, LocationType type) +static void debuggerPrintValueInternal(Function *f, Type *t, + int bitSize, int bitOffset, + u32 objLocation, LocationType type) { u32 value = debuggerGetValue(objLocation, type); if(!t) { @@ -480,8 +558,9 @@ } } -void debuggerPrintValueInternal(Function *f, Type *t, ELFBlock *loc, - int bitSize, int bitOffset, u32 objLocation) +static void debuggerPrintValueInternal(Function *f, Type *t, ELFBlock *loc, + int bitSize, int bitOffset, + u32 objLocation) { LocationType type; u32 location; @@ -498,14 +577,14 @@ debuggerPrintValueInternal(f, t, bitSize, bitOffset, location, type); } -void debuggerPrintValue(Function *f, Object *o) +static void debuggerPrintValue(Function *f, Object *o) { debuggerPrintValueInternal(f, o->type, o->location, 0, 0, 0); printf("\n"); } -void debuggerSymbols(int argc, char **argv) +static void debuggerSymbols(int argc, char **argv) { int i = 0; u32 value; @@ -550,7 +629,7 @@ } } -void debuggerSetRadix(int argc, char **argv) +static void debuggerSetRadix(int argc, char **argv) { if(argc != 2) debuggerUsage(argv[0]); @@ -578,7 +657,7 @@ } } -void debuggerPrint(int argc, char **argv) +static void debuggerPrint(int argc, char **argv) { if(argc != 2 && argc != 3) { debuggerUsage(argv[0]); @@ -647,7 +726,7 @@ } } -void debuggerHelp(int n, char **args) +static void debuggerHelp(int n, char **args) { if(n == 2) { debuggerUsage(args[1]); @@ -661,7 +740,7 @@ } } -void debuggerDebug(int n, char **args) +static void debuggerDebug(int n, char **args) { if(n == 2) { int v = 0; @@ -672,7 +751,7 @@ debuggerUsage("trace"); } -void debuggerVerbose(int n, char **args) +static void debuggerVerbose(int n, char **args) { if(n == 2) { int v = 0; @@ -683,13 +762,13 @@ debuggerUsage("verbose"); } -void debuggerWhere(int n, char **args) +static void debuggerWhere(int n, char **args) { void elfPrintCallChain(u32); elfPrintCallChain(armNextPC); } -void debuggerLocals(int n, char **args) +static void debuggerLocals(int n, char **args) { Function *f = NULL; CompileUnit *u = NULL; @@ -719,7 +798,7 @@ } } -void debuggerNext(int n, char **args) +static void debuggerNext(int n, char **args) { int count = 1; if(n == 2) { @@ -729,8 +808,10 @@ if(debuggerAtBreakpoint) { debuggerContinueAfterBreakpoint(); debuggerEnableBreakpoints(false); - } else + } else { + debuggerPrefetch(); emulator.emuMain(1); + } } debuggerDisableBreakpoints(); Function *f = NULL; @@ -746,15 +827,16 @@ debuggerRegisters(0, NULL); } -void debuggerContinue(int n, char **args) +static void debuggerContinue(int n, char **args) { if(debuggerAtBreakpoint) debuggerContinueAfterBreakpoint(); debuggerEnableBreakpoints(false); debugger = false; + debuggerPrefetch(); } -void debuggerSignal(int sig,int number) +/*extern*/ void debuggerSignal(int sig,int number) { switch(sig) { case 4: @@ -765,12 +847,21 @@ break; case 5: { - printf("Breakpoint %d reached\n", number); - debugger = true; + bool cond = debuggerCondEvaluate(number & 255); + if(cond) { + printf("Breakpoint %d reached\n", number); + debugger = true; + } else { + debuggerDisableBreakpoints(); + debuggerPrefetch(); + emulator.emuMain(1); + debuggerEnableBreakpoints(false); + return; + } debuggerAtBreakpoint = true; debuggerBreakpointNumber = number; debuggerDisableBreakpoints(); - + Function *f = NULL; CompileUnit *u = NULL; @@ -788,7 +879,7 @@ } } -void debuggerBreakList(int, char **) +static void debuggerBreakList(int, char **) { printf("Num Address Type Symbol\n"); printf("--- -------- ----- ------\n"); @@ -799,13 +890,13 @@ } } -void debuggerBreakDelete(int n, char **args) +static void debuggerBreakDelete(int n, char **args) { if(n == 2) { int n = 0; sscanf(args[1], "%d", &n); - printf("Deleting breakpoint %d (%d)\n", n, debuggerNumOfBreakpoints); if(n >= 0 && n < debuggerNumOfBreakpoints) { + printf("Deleting breakpoint %d (%d)\n", n, debuggerNumOfBreakpoints); n++; if(n < debuggerNumOfBreakpoints) { for(int i = n; i < debuggerNumOfBreakpoints; i++) { @@ -819,11 +910,13 @@ } debuggerNumOfBreakpoints--; } + else + printf("No breakpoints are set\n"); } else debuggerUsage("bd"); } -void debuggerBreak(int n, char **args) +static void debuggerBreak(int n, char **args) { if(n == 2) { u32 address = 0; @@ -914,7 +1007,7 @@ debuggerUsage("break"); } -void debuggerBreakThumb(int n, char **args) +static void debuggerBreakThumb(int n, char **args) { if(n == 2) { u32 address = 0; @@ -930,7 +1023,7 @@ debuggerUsage("bt"); } -void debuggerBreakArm(int n, char **args) +static void debuggerBreakArm(int n, char **args) { if(n == 2) { u32 address = 0; @@ -946,34 +1039,130 @@ debuggerUsage("ba"); } -void debuggerBreakOnWrite(u32 *mem, u32 oldvalue, u32 value, int size) +/*extern*/ void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, + int size, int t) { - u32 address = 0; - if(mem >= (u32*)&workRAM[0] && mem <= (u32*)&workRAM[0x3ffff]) - address = 0x2000000 + ((u32)mem - (u32)&workRAM[0]); - else - address = 0x3000000 + ((u32)mem - (u32)&internalRAM[0]); + const char *type = "write"; + if(t == 2) + type = "change"; if(size == 2) - printf("Breakpoint (on write) address %08x old:%08x new:%08x\n", - address, oldvalue, value); + printf("Breakpoint (on %s) address %08x old:%08x new:%08x\n", + type, address, oldvalue, value); else if(size == 1) - printf("Breakpoint (on write) address %08x old:%04x new:%04x\n", - address, (u16)oldvalue,(u16)value); + printf("Breakpoint (on %s) address %08x old:%04x new:%04x\n", + type, address, (u16)oldvalue,(u16)value); else - printf("Breakpoint (on write) address %08x old:%02x new:%02x\n", - address, (u8)oldvalue, (u8)value); + printf("Breakpoint (on %s) address %08x old:%02x new:%02x\n", + type, address, (u8)oldvalue, (u8)value); debugger = true; } -void debuggerBreakWriteClear(int n, char **args) +static void debuggerBreakWriteClear(int n, char **args) { - memset(freezeWorkRAM, false, 0x40000); - memset(freezeInternalRAM, false, 0x8000); - printf("Cleared all break on write\n"); + if(n == 3) { + u32 address = 0; + sscanf(args[1], "%x", &address); + int n = 0; + sscanf(args[2], "%d", &n); + + if (! ((address >= 0x02000000 && address < 0x02040000) || + (address >= 0x03000000 && address < 0x03008000) || + (address >= 0x05000000 && address < 0x05000400) || + (address >= 0x06000000 && address < 0x06018000) || + (address >= 0x07000000 && address < 0x07000400))) { + printf("Invalid address: %08x\n", address); + return; + } + + u32 final = address + n; + switch(address >> 24) { + case 2: + { + address &= 0x3ffff; + final &= 0x3ffff; + for(u32 i = address; i < final; i++) + if(freezeWorkRAM[i] == 1) + freezeWorkRAM[i] = 0; + printf("Cleared break on write from %08x to %08x\n", + 0x2000000+address, 0x2000000+final); + } + break; + case 3: + { + address &= 0x7fff; + final &= 0x7fff; + for(u32 i = address; i < final; i++) + if(freezeInternalRAM[i] == 1) + freezeInternalRAM[i] = 0; + printf("Cleared break on write from %08x to %08x\n", + 0x3000000+address, 0x3000000+final); + } + break; + case 5: + { + address &= 0x3ff; + final &= 0x3ff; + for(u32 i = address; i < final; i++) + if(freezePRAM[i] == 1) + freezePRAM[i] = 0; + printf("Cleared break on write from %08x to %08x\n", + 0x5000000+address, 0x5000000+final); + } + break; + case 6: + { + if (address > 0x6010000) { + address &= 0x17fff; + final &= 0x17fff; + } else { + address &= 0xffff; + final &= 0xffff; + } + + for (u32 i = address; i < final; i++) + if(freezeVRAM[i] == 1) + freezeVRAM[i] = 0; + printf("Cleared break on write from %08x to %08x\n", + 0x06000000+address, 0x06000000+final); + } + break; + case 7: + { + address &= 0x3ff; + final &= 0x3ff; + for(u32 i = address; i < final; i++) + if(freezeOAM[i] == 1) + freezeOAM[i] = 0; + printf("Cleared break on write from %08x to %08x\n", + 0x7000000+address, 0x7000000+final); + } + break; + } + } else if(n == 1) { + int i; + for(i = 0; i < 0x40000; i++) + if(freezeWorkRAM[i] == 1) + freezeWorkRAM[i] = 0; + for(i = 0; i < 0x8000; i++) + if(freezeInternalRAM[i] == 1) + freezeInternalRAM[i] = 0; + for(i = 0; i < 0x400; i++) + if(freezePRAM[i] == 1) + freezePRAM[i] = 0; + for(i = 0; i< 0x18000; i++) + if(freezeVRAM[i] == 1) + freezeVRAM[i] = 0; + for(i = 0; i < 0x400; i++) + if(freezeOAM[i] == 1) + freezeOAM[i] = 0; + + printf("Cleared all break on write\n"); + } else + debuggerUsage("bpwc"); } -void debuggerBreakWrite(int n, char **args) +static void debuggerBreakWrite(int n, char **args) { if(n == 3) { if(cheatsNumber != 0) { @@ -985,15 +1174,187 @@ int n = 0; sscanf(args[2], "%d", &n); - if(address < 0x2000000 || address > 0x3007fff) { - printf("Invalid address: %08x\n", address); + if (! ((address >= 0x02000000 && address < 0x02040000) || + (address >= 0x03000000 && address < 0x03008000) || + (address >= 0x05000000 && address < 0x05000400) || + (address >= 0x06000000 && address < 0x06018000) || + (address >= 0x07000000 && address < 0x07000400))) { + printf("Invalid address: %08x\n", address); + return; + } + + u32 final = address + n; + + if(address < 0x2040000 && final > 0x2040000) { + printf("Invalid byte count: %d\n", n); + return; + } else if(address < 0x3008000 && final > 0x3008000) { + printf("Invalid byte count: %d\n", n); return; + } else if(address < 0x05000400 && final > 0x05000400) { + printf("Invalid byte count: %d\n", n); + return; + } else if(address < 0x06018000 && final > 0x06018000) { + printf("Invalid byte count: %d\n", n); + return; + } else if(address < 0x07000400 && final > 0x07000400) { + printf("Invalid byte count: %d\n", n); + return; + } + + printf("Added break on write at %08x for %d bytes\n", address, n); + + switch(address >> 24) { + case 2: + for (int i = 0; i < n; i++) + freezeWorkRAM[(address + i) & 0x3ffff] = 1; + break; + case 3: + for (int i = 0; i < n; i++) + freezeInternalRAM[(address + i) & 0x7fff] = 1; + break; + case 5: + for (int i = 0; i < n; i++) + freezePRAM[(address + i) & 0x3ff] = 1; + break; + case 6: + // address/range must be valid, so we can use a lazy mask + for (int i = 0; i < n; i++) + freezeVRAM[(address + i) & 0x1ffff] = 1; + break; + case 7: + for (int i = 0; i < n; i++) + freezeOAM[(address + i) & 0x3ff] = 1; + break; + } + + } else + debuggerUsage("bpw"); +} + +static void debuggerBreakChangeClear(int n, char **args) +{ + if(n == 3) { + u32 address = 0; + sscanf(args[1], "%x", &address); + int n = 0; + sscanf(args[2], "%d", &n); + + if (! ((address >= 0x02000000 && address < 0x02040000) || + (address >= 0x03000000 && address < 0x03008000) || + (address >= 0x05000000 && address < 0x05000400) || + (address >= 0x06000000 && address < 0x06018000) || + (address >= 0x07000000 && address < 0x07000400))) { + printf("Invalid address: %08x\n", address); + return; + } + + u32 final = address + n; + switch(address >> 24) { + case 2: + { + address &= 0x3ffff; + final &= 0x3ffff; + for(u32 i = address; i < final; i++) + if(freezeWorkRAM[i] == 2) + freezeWorkRAM[i] = 0; + printf("Cleared break on change from %08x to %08x\n", + 0x2000000+address, 0x2000000+final); + } + break; + case 3: + { + address &= 0x7fff; + final &= 0x7fff; + for(u32 i = address; i < final; i++) + if(freezeInternalRAM[i] == 2) + freezeInternalRAM[i] = 0; + printf("Cleared break on change from %08x to %08x\n", + 0x3000000+address, 0x3000000+final); + } + break; + case 5: + { + address &= 0x3ff; + final &= 0x3ff; + for(u32 i = address; i < final; i++) + if(freezePRAM[i] == 2) + freezePRAM[i] = 0; + printf("Cleared break on change from %08x to %08x\n", + 0x5000000+address, 0x5000000+final); + } + break; + case 6: + { + if (address > 0x6010000) { + address &= 0x17fff; + final &= 0x17fff; + } else { + address &= 0xffff; + final &= 0xffff; + } + for(u32 i = address; i < final; i++) + if(freezeVRAM[i] == 2) + freezeVRAM[i] = 0; + printf("Cleared break on change from %08x to %08x\n", + 0x3000000+address, 0x3000000+final); + } + break; + case 7: + { + address &= 0x3ff; + final &= 0x3ff; + for(u32 i = address; i < final; i++) + if(freezeOAM[i] == 2) + freezeOAM[i] = 0; + printf("Cleared break on change from %08x to %08x\n", + 0x7000000+address, 0x7000000+final); + } + break; } + } else if(n == 1) { + int i; + for(i = 0; i < 0x40000; i++) + if(freezeWorkRAM[i] == 2) + freezeWorkRAM[i] = 0; + for(i = 0; i < 0x8000; i++) + if(freezeInternalRAM[i] == 2) + freezeInternalRAM[i] = 0; + for(i = 0; i < 0x400; i++) + if(freezePRAM[i] == 2) + freezePRAM[i] = 0; + for(i = 0; i < 0x18000; i++) + if(freezeVRAM[i] == 2) + freezeVRAM[i] = 0; + for(i = 0; i < 0x400; i++) + if(freezeOAM[i] == 2) + freezeOAM[i] = 0; - if(address > 0x203ffff && address < 0x3000000) { - printf("Invalid address: %08x\n", address); + printf("Cleared all break on change\n"); + } else + debuggerUsage("bpcc"); +} + +static void debuggerBreakChange(int n, char **args) +{ + if(n == 3) { + if(cheatsNumber != 0) { + printf("Cheats are enabled. Cannot continue.\n"); return; } + u32 address = 0; + sscanf(args[1], "%x", &address); + int n = 0; + sscanf(args[2], "%d", &n); + + if (! ((address >= 0x02000000 && address < 0x02040000) || + (address >= 0x03000000 && address < 0x03008000) || + (address >= 0x05000000 && address < 0x05000400) || + (address >= 0x06000000 && address < 0x06018000) || + (address >= 0x07000000 && address < 0x07000400))) { + printf("Invalid address: %08x\n", address); + return; + } u32 final = address + n; @@ -1003,22 +1364,84 @@ } else if(address < 0x3008000 && final > 0x3008000) { printf("Invalid byte count: %d\n", n); return; + } else if(address < 0x6018000 && final > 0x6018000) { + printf("Invalid byte count: %d\n", n); + return; + } else if(address < 0x7000400 && final > 0x7000400) { + printf("Invalid byte count: %d\n", n); + return; } - printf("Added break on write at %08x for %d bytes\n", address, n); - for(int i = 0; i < n; i++) { - if((address >> 24) == 2) - freezeWorkRAM[address & 0x3ffff] = true; - else - freezeInternalRAM[address & 0x7fff] = true; - address++; + printf("Added break on change at %08x for %d bytes\n", address, n); + + switch(address >> 24) { + case 2: + for (int i = 0; i < n; i++) + freezeWorkRAM[(address + i) & 0x3ffff] = 2; + break; + case 3: + for (int i = 0; i < n; i++) + freezeInternalRAM[(address + i) & 0x7fff] = 2; + break; + case 5: + for (int i = 0; i < n; i++) + freezePRAM[(address + i) & 0x3ff] = 2; + break; + case 6: + // address/range must be valid, so we can use a lazy mask + for (int i = 0; i < n; i++) + freezeVRAM[(address + i) & 0x1ffff] = 2; + break; + case 7: + for (int i = 0; i < n; i++) + freezeOAM[(address + i) & 0x3ff] = 2; + break; } + } else - debuggerUsage("bpw"); + debuggerUsage("bpc"); +} + +static void debuggerDisassembleArm(FILE *f, u32 pc, int count) +{ + char buffer[80]; + int i = 0; + u32 len = 0; + char format[30]; + for(i = 0; i < count; i++) { + size_t l = strlen(elfGetAddressSymbol(pc+4*i)); + if(l > len) + len = l; + } + sprintf(format, "%%08x %%-%ds %%s\n", len); + for(i = 0; i < count; i++) { + u32 addr = pc; + pc += disArm(pc, buffer, 2); + fprintf(f, format, addr, elfGetAddressSymbol(addr), buffer); + } } -void debuggerDisassembleArm(int n, char **args) +static void debuggerDisassembleThumb(FILE *f, u32 pc, int count) { char buffer[80]; + int i = 0; + u32 len = 0; + char format[30]; + for(i = 0; i < count; i++) { + size_t l = strlen(elfGetAddressSymbol(pc+2*i)); + if(l > len) + len = l; + } + sprintf(format, "%%08x %%-%ds %%s\n", len); + + for(i = 0; i < count; i++) { + u32 addr = pc; + pc += disThumb(pc, buffer, 2); + fprintf(f, format, addr, elfGetAddressSymbol(addr), buffer); + } +} + +static void debuggerDisassembleArm(int n, char **args) +{ u32 pc = reg[15].I; pc -= 4; int count = 20; @@ -1032,25 +1455,11 @@ if(n >= 3) { sscanf(args[2], "%d", &count); } - int i = 0; - int len = 0; - char format[30]; - for(i = 0; i < count; i++) { - int l = strlen(elfGetAddressSymbol(pc+4*i)); - if(l > len) - len = l; - } - sprintf(format, "%%08x %%-%ds %%s\n", len); - for(i = 0; i < count; i++) { - u32 addr = pc; - pc += disArm(pc, buffer, 2); - printf(format, addr, elfGetAddressSymbol(addr), buffer); - } + debuggerDisassembleArm(stdout, pc, count); } -void debuggerDisassembleThumb(int n, char **args) +static void debuggerDisassembleThumb(int n, char **args) { - char buffer[80]; u32 pc = reg[15].I; pc -= 2; int count = 20; @@ -1064,25 +1473,10 @@ if(n >= 3) { sscanf(args[2], "%d", &count); } - - int i = 0; - int len = 0; - char format[30]; - for(i = 0; i < count; i++) { - int l = strlen(elfGetAddressSymbol(pc+2*i)); - if(l > len) - len = l; - } - sprintf(format, "%%08x %%-%ds %%s\n", len); - - for(i = 0; i < count; i++) { - u32 addr = pc; - pc += disThumb(pc, buffer, 2); - printf(format, addr, elfGetAddressSymbol(addr), buffer); - } + debuggerDisassembleThumb(stdout, pc, count); } -void debuggerDisassemble(int n, char **args) +static void debuggerDisassemble(int n, char **args) { if(armState) debuggerDisassembleArm(n, args); @@ -1090,19 +1484,306 @@ debuggerDisassembleThumb(n, args); } -void debuggerContinueAfterBreakpoint() +static void debuggerFileDisassembleArm(int n, char **args) +{ + u32 pc = reg[15].I; + pc -= 4; + int count = 20; + if(n < 2) { + debuggerUsage("fda"); + return; + } + FILE *f = fopen(args[1], "w+"); + if(!f) { + printf("Error: cannot open file %s\n", args[1]); + return; + } + if(n >= 3) { + sscanf(args[2], "%x", &pc); + } + if(pc & 3) { + printf("Misaligned address %08x\n", pc); + pc &= 0xfffffffc; + } + if(n >= 4) { + sscanf(args[3], "%d", &count); + } + debuggerDisassembleArm(f, pc, count); + fclose(f); +} + +static void debuggerFileDisassembleThumb(int n, char **args) +{ + u32 pc = reg[15].I; + pc -= 2; + int count = 20; + if(n < 2) { + debuggerUsage("fdt"); + return; + } + FILE *f = fopen(args[1], "w+"); + if(!f) { + printf("Error: cannot open file %s\n", args[1]); + return; + } + + if(n >= 3) { + sscanf(args[2], "%x", &pc); + } + if(pc & 1) { + printf("Misaligned address %08x\n", pc); + pc &= 0xfffffffe; + } + if(n >= 4) { + sscanf(args[3], "%d", &count); + } + debuggerDisassembleThumb(f, pc, count); + fclose(f); +} + +void debuggerFindText(int n, char **args) +{ + if ((n == 4) || (n == 3)) + { + SearchResults = 0; + sscanf(args[1], "%x", &SearchStart); + + if (n == 4) + { + sscanf(args[2], "%u", &SearchMaxMatches); + strncpy((char*) SearchData, args[3], 64); + SearchLength = strlen(args[3]); + } + else if (n == 3) + { + strncpy((char*) SearchData, args[2], 64); + SearchLength = strlen(args[2]); + }; + + if (SearchLength > 64) + { + printf ("Entered string (length: %d) is longer than 64 bytes and was cut.\n", SearchLength); + SearchLength = 64; + }; + + debuggerDoSearch (); + + } else + debuggerUsage("ft"); +}; + +void debuggerFindHex(int n, char **args) +{ + if ((n == 4) || (n == 3)) + { + SearchResults = 0; + sscanf(args[1], "%x", &SearchStart); + + char SearchHex [128]; + if (n == 4) + { + sscanf(args[2], "%u", &SearchMaxMatches); + strncpy(SearchHex, args[3], 128); + SearchLength = strlen(args[3]); + } + else if (n == 3) + { + strncpy(SearchHex, args[2], 128); + SearchLength = strlen(args[2]); + }; + + if (SearchLength & 1) + printf ("Unaligned bytecount: %d,5. Last digit (%c) cut.\n", SearchLength / 2, SearchHex [SearchLength - 1]); + + SearchLength /= 2; + + if (SearchLength > 64) + { + printf ("Entered string (length: %d) is longer than 64 bytes and was cut.\n", SearchLength); + SearchLength = 64; + }; + + for (unsigned int i = 0; i < SearchLength; i++) + { + unsigned int cbuf = 0; + sscanf (&SearchHex [i << 1], "%02x", &cbuf); + SearchData [i] = cbuf; + }; + + debuggerDoSearch (); + + } else + debuggerUsage("fh"); +}; + +void debuggerFindResume(int n, char **args) +{ + if ((n == 1) || (n == 2)) + { + if (SearchLength == 0) + { + printf("Error: No search in progress. Start a search with ft or fh.\n"); + debuggerUsage("fr"); + return; + }; + + if (n == 2) + sscanf(args[1], "%u", &SearchMaxMatches); + + debuggerDoSearch(); + + } else + debuggerUsage("fr"); +}; + +void debuggerDoSearch() +{ + int count = 0; + + while (true) + { + unsigned int final = SearchStart + SearchLength - 1; + u8* end; + u8* start; + + switch (SearchStart >> 24) + { + case 0: + if (final > 0x00003FFF) { SearchStart = 0x02000000; continue; } + else { start = bios + (SearchStart & 0x3FFF); end = bios + 0x3FFF; break; }; + case 2: + if (final > 0x0203FFFF) { SearchStart = 0x03000000; continue; } + else { start = workRAM + (SearchStart & 0x3FFFF); end = workRAM + 0x3FFFF; break; }; + case 3: + if (final > 0x03007FFF) { SearchStart = 0x04000000; continue; } + else { start = internalRAM + (SearchStart & 0x7FFF); end = internalRAM + 0x7FFF; break; }; + case 4: + if (final > 0x040003FF) { SearchStart = 0x05000000; continue; } + else { start = ioMem + (SearchStart & 0x3FF); end = ioMem + 0x3FF; break; }; + case 5: + if (final > 0x050003FF) { SearchStart = 0x06000000; continue; } + else { start = paletteRAM + (SearchStart & 0x3FF); end = paletteRAM + 0x3FF; break; }; + case 6: + if (final > 0x0601FFFF) { SearchStart = 0x07000000; continue; } + else { start = vram + (SearchStart & 0x1FFFF); end = vram + 0x1FFFF; break; }; + case 7: + if (final > 0x070003FF) { SearchStart = 0x08000000; continue; } + else { start = oam + (SearchStart & 0x3FF); end = oam + 0x3FF; break; }; + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + if (final <= 0x09FFFFFF) + { start = rom + (SearchStart & 0x01FFFFFF); end = rom + 0x01FFFFFF; break; }; + default: + printf ("Search completed.\n"); + SearchLength = 0; + return; + }; + + end -= SearchLength - 1; + u8 firstbyte = SearchData [0]; + while (start <= end) + { + while ((start <= end) && (*start != firstbyte)) + start++; + + if (start > end) + break; + + unsigned int p = 1; + while ((start [p] == SearchData [p]) && (p < SearchLength)) + p++; + + if (p == SearchLength) + { + printf ("Search result (%d): %08x\n", count + SearchResults, AddressToGBA (start)); + count++; + if (count == SearchMaxMatches) + { + SearchStart = AddressToGBA (start + p); + SearchResults += count; + return; + }; + + start += p; // assume areas don't overlap; alternative: start++; + } else + start++; + }; + + SearchStart = AddressToGBA (end + SearchLength - 1) + 1; + }; +}; + +unsigned int AddressToGBA(u8* mem) +{ + if(mem >= &bios[0] && mem <= &bios[0x3fff]) + return 0x00000000 + (mem - &bios[0]); + else if(mem >= &workRAM[0] && mem <= &workRAM[0x3ffff]) + return 0x02000000 + (mem - &workRAM[0]); + else if(mem >= &internalRAM[0] && mem <= &internalRAM[0x7fff]) + return 0x03000000 + (mem - &internalRAM[0]); + else if(mem >= &ioMem[0] && mem <= &ioMem[0x3ff]) + return 0x04000000 + (mem - &ioMem[0]); + else if(mem >= &paletteRAM[0] && mem <= &paletteRAM[0x3ff]) + return 0x05000000 + (mem - &paletteRAM[0]); + else if(mem >= &vram[0] && mem <= &vram[0x1ffff]) + return 0x06000000 + (mem - &vram[0]); + else if(mem >= &oam[0] && mem <= &oam[0x3ff]) + return 0x07000000 + (mem - &oam[0]); + else if(mem >= &rom[0] && mem <= &rom[0x1ffffff]) + return 0x08000000 + (mem - &rom[0]); + else + return 0xFFFFFFFF; +}; + +static void debuggerFileDisassemble(int n, char **args) +{ + if(n < 2) { + debuggerUsage("fd"); + } else { + if(armState) + debuggerFileDisassembleArm(n, args); + else + debuggerFileDisassembleThumb(n, args); + } +} + +static void debuggerContinueAfterBreakpoint() { printf("Continuing after breakpoint\n"); debuggerEnableBreakpoints(true); + debuggerPrefetch(); emulator.emuMain(1); debuggerAtBreakpoint = false; } -void debuggerRegisters(int, char **) +static void debuggerRegisters(int, char **) { char *command[3]; char buffer[10]; +#ifdef BKPT_SUPPORT + if (debugger_last) + { + printf("R00=%08x R04=%08x R08=%08x R12=%08x\n", + oldreg[0], oldreg[4], oldreg[8], oldreg[12]); + printf("R01=%08x R05=%08x R09=%08x R13=%08x\n", + oldreg[1], oldreg[5], oldreg[9], oldreg[13]); + printf("R02=%08x R06=%08x R10=%08x R14=%08x\n", + oldreg[2], oldreg[6], oldreg[10], oldreg[14]); + printf("R03=%08x R07=%08x R11=%08x R15=%08x\n", + oldreg[3], oldreg[7], oldreg[11], oldreg[15]); + command[0]="m"; + command[1]=oldbuffer; + command[2]="1"; + debuggerDisassemble(3, command); + printf("\n"); + } +#endif + printf("R00=%08x R04=%08x R08=%08x R12=%08x\n", reg[0].I, reg[4].I, reg[8].I, reg[12].I); printf("R01=%08x R05=%08x R09=%08x R13=%08x\n", @@ -1128,7 +1809,7 @@ debuggerDisassemble(3, command); } -void debuggerIoVideo() +static void debuggerIoVideo() { printf("DISPCNT = %04x\n", DISPCNT); printf("DISPSTAT = %04x\n", DISPSTAT); @@ -1149,7 +1830,7 @@ printf("COLY = %04x\n", COLY); } -void debuggerIoVideo2() +static void debuggerIoVideo2() { printf("BG0HOFS = %04x\n", BG0HOFS); printf("BG0VOFS = %04x\n", BG0VOFS); @@ -1173,7 +1854,7 @@ printf("BG3Y = %08x\n", (BG3Y_H<<16)|BG3Y_L); } -void debuggerIoDMA() +static void debuggerIoDMA() { printf("DM0SAD = %08x\n", (DM0SAD_H<<16)|DM0SAD_L); printf("DM0DAD = %08x\n", (DM0DAD_H<<16)|DM0DAD_L); @@ -1189,7 +1870,7 @@ printf("DM3CNT = %08x\n", (DM3CNT_H<<16)|DM3CNT_L); } -void debuggerIoTimer() +static void debuggerIoTimer() { printf("TM0D = %04x\n", TM0D); printf("TM0CNT = %04x\n", TM0CNT); @@ -1201,7 +1882,7 @@ printf("TM3CNT = %04x\n", TM3CNT); } -void debuggerIoMisc() +static void debuggerIoMisc() { printf("P1 = %04x\n", P1); printf("IE = %04x\n", IE); @@ -1209,7 +1890,7 @@ printf("IME = %04x\n", IME); } -void debuggerIo(int n, char **args) +static void debuggerIo(int n, char **args) { if(n == 1) { debuggerIoVideo(); @@ -1228,11 +1909,11 @@ else printf("Unrecognized option %s\n", args[1]); } -void debuggerEditByte(int n, char **args) +static void debuggerEditByte(int n, char **args) { if(n == 3) { - u32 address; - u32 byte; + u32 address = 0x10000; + u32 byte = 0; sscanf(args[1], "%x", &address); sscanf(args[2], "%x", &byte); debuggerWriteByte(address, (u8)byte); @@ -1240,23 +1921,41 @@ debuggerUsage("eb"); } -void debuggerEditHalfWord(int n, char **args) +static void debuggerEditHalfWord(int n, char **args) { if(n == 3) { - u32 address; - u32 byte; + u32 address = 0x10000; + u32 HalfWord = 0; sscanf(args[1], "%x", &address); if(address & 1) { printf("Error: address must be half-word aligned\n"); return; } - sscanf(args[2], "%x", &byte); - debuggerWriteHalfWord(address, (u16)byte); + sscanf(args[2], "%x", &HalfWord); + debuggerWriteHalfWord(address, (u16)HalfWord); } else debuggerUsage("eh"); } -void debuggerEdit(int n, char **args) +static void debuggerEditRegister(int n, char **args) +{ + if(n == 3) { + int r = 15; + u32 val; + sscanf(args[1], "%d", &r); + if(r > 16 || r == 15) { + // don't allow PC to change + printf("Error: Register must be valid (0-14,16)\n"); + return; + } + sscanf(args[2], "%x", &val); + reg[r].I=val; + printf("Register changed.\n"); + } else + debuggerUsage("er"); +} + +static void debuggerEdit(int n, char **args) { if(n == 3) { u32 address; @@ -1275,12 +1974,12 @@ #define ASCII(c) (c) < 32 ? '.' : (c) > 127 ? '.' : (c) -void debuggerMemoryByte(int n, char **args) +static void debuggerMemoryByte(int n, char **args) { if(n == 2) { u32 addr = 0; sscanf(args[1], "%x", &addr); - for(int i = 0; i < 16; i++) { + for(int _i = 0; _i < 16; _i++) { int a = debuggerReadByte(addr); int b = debuggerReadByte(addr+1); int c = debuggerReadByte(addr+2); @@ -1310,13 +2009,13 @@ debuggerUsage("mb"); } -void debuggerMemoryHalfWord(int n, char **args) +static void debuggerMemoryHalfWord(int n, char **args) { if(n == 2) { u32 addr = 0; sscanf(args[1], "%x", &addr); addr = addr & 0xfffffffe; - for(int i = 0; i < 16; i++) { + for(int _i = 0; _i < 16; _i++) { int a = debuggerReadByte(addr); int b = debuggerReadByte(addr+1); int c = debuggerReadByte(addr+2); @@ -1346,13 +2045,13 @@ debuggerUsage("mh"); } -void debuggerMemory(int n, char **args) +static void debuggerMemory(int n, char **args) { if(n == 2) { u32 addr = 0; sscanf(args[1], "%x", &addr); addr = addr & 0xfffffffc; - for(int i = 0; i < 16; i++) { + for(int _i = 0; _i < 16; _i++) { int a = debuggerReadByte(addr); int b = debuggerReadByte(addr+1); int c = debuggerReadByte(addr+2); @@ -1385,7 +2084,7 @@ debuggerUsage("mw"); } -void debuggerQuit(int, char **) +static void debuggerQuit(int, char **) { char buffer[10]; printf("Are you sure you want to quit (y/n)? "); @@ -1397,7 +2096,450 @@ } } -void debuggerOutput(char *s, u32 addr) +static void debuggerWriteState(int n, char **args) +{ + int num = 12; + + if(n == 2) { + sscanf(args[1],"%d",&num); + if(num > 0 && num < 11) + sdlWriteState(num-1); + else + printf("Savestate number must be in the 1-10 range"); + } + else + debuggerUsage("save"); +} + +static void debuggerReadState(int n, char **args) +{ + int num = 12; + + if(n == 2) { + sscanf(args[1],"%d",&num); + if(num > 0 && num < 11) + sdlReadState(num-1); + else + printf("Savestate number must be in the 1-10 range"); + } + else + debuggerUsage("load"); +} + +static void debuggerDumpLoad(int n, char** args) +{ + u32 address = 0; + char *file; + FILE *f; + int c; + + if(n==3) { + file=args[1]; + + sscanf(args[2],"%x",&address); + + f=fopen(file,"rb"); + if(!f) { + printf("Error opening file.\n"); + return; + } + + fseek(f,0,SEEK_END); + int size=ftell(f); + fseek(f,0,SEEK_SET); + + for(int i=0;i 4) { //conditional args handled separately + int i = debuggerNumOfBreakpoints; + + u32 address = 0; + sscanf(args[1],"%x", &address); + + debuggerBreakpointList[i].address = address; + debuggerBreakpointList[i].value = debuggerReadHalfWord(address); + debuggerBreakpointList[i].size = 0; + + debuggerCondValidate(n, args,2); + } else + debuggerUsage("cbt"); + +} + +static void debuggerCondBreakArm(int n, char **args) +{ + if(n > 4) { //conditional args handled separately + + int i = debuggerNumOfBreakpoints; + u32 address = 0; + + sscanf(args[1],"%x", &address); + debuggerBreakpointList[i].address = address; + debuggerBreakpointList[i].value = debuggerReadMemory(address); + debuggerBreakpointList[i].size = 1; + debuggerCondValidate(n, args,2); + } else + debuggerUsage("cba"); +} + +static void debuggerCondValidate(int n,char **args,int start) +{ + /* + 0: address/register + 1: op + 2: value + 3: size + */ + + int i=debuggerNumOfBreakpoints; + + char *address=args[start]; + char *op=args[start+1]; + char *value=args[start+2]; + char *tsize,*taddress,*tvalue; + + int rel=0; + + u32 value1=0; + u32 value2=0; + + char size=0; + int j=1; + + if(n==6) { + size = args[start+3][0]; + if(size != 'b' && size != 'h' && size != 'w') { + printf("Invalid size.\n"); + return; + } + + switch(size) { + case 'b': + debuggerBreakpointList[i].cond_size=1; + tsize="byte"; + break; + case 'h': + debuggerBreakpointList[i].cond_size=2; + tsize="halfword"; + break; + case 'w': + debuggerBreakpointList[i].cond_size=4; + tsize="word"; + break; + } + } + + switch(toupper(address[0])) { + case '$': //is address + while (address[j]) { + address[j-1]=address[j]; + j++; + } + address[j-1]=0; + + sscanf(address,"%x",&value1); + switch(size) { + case 'h': + if(value1 & 1) { + printf("Misaligned Conditional Address.\n"); + return; + } + break; + case 'w': + if(value1 & 3) { + printf("Misaligned Conditional Address.\n"); + return; + } + case 'b': + break; + default: + printf("Erroneous Condition\n"); + debuggerUsage((char *)((toupper(args[0][2])=='T') ? "cbt" : "cba")); + return; + } + debuggerBreakpointList[i].ia1=true; + taddress="$"; + break; + case 'R': //is register + while(address[j]) { + address[j-1]=address[j]; + j++; + } + address[j-1]=0; + sscanf(address,"%d",&value1); + + if(value1 > 16) { + printf("Invalid Register.\n"); + return; + } + if(size) + size=0; + debuggerBreakpointList[i].ia1=true; + taddress="r"; + break; + default: //immediate; + printf("First Comparison Parameter should not be Immediate\n"); + return; + } + + debuggerBreakpointList[i].cond_address = value1; + + // Check op + switch(op[0]) { + case '=': // 1 + if (op[1] == '=' && op[2]==0) + rel=1; + else + goto error; + break; + case '!': //2 + if (op[1]=='=' && op[2]==0) + rel=2; + else + goto error; + break; + case '<': //3 + if(op[1]=='=') + rel=5; + else if (op[1]==0) + rel=3; + else + goto error; + break; + case '>': //4 + if (op[1]=='=') + rel=6; + else if (op[1]==0) + rel=4; + else + goto error; + break; + default: + error: + printf("Invalid comparison operator.\n"); + return; + } + + if(op==0) { + printf("Invalid comparison operator.\n"); + return; + } + debuggerBreakpointList[i].cond_rel=rel; + + switch(toupper(value[0])) { + case '$': //is address + while(value[j]) { + value[j-1]=value[j]; + j++; + } + value[j-1]=0; + + sscanf(value,"%x",&value2); + debuggerBreakpointList[i].ia2=true; + tvalue="$"; + switch(size) { + case 'h': + if(value2 & 1) { + printf("Misaligned Conditional Address.\n"); + return; + } + break; + case 'w': + if(value2 & 3) { + printf("Misaligned Conditional Address.\n"); + return; + } + case 'b': + break; + default: + printf("Erroneous Condition\n"); + debuggerUsage((char *)((toupper(args[0][2])=='T') ? "cbt" : "cba")); + return; + } + break; + case 'R': //is register + while(value[j]) { + value[j-1]=value[j]; + j++; + } + value[j-1]=0; + sscanf(value,"%d",&value2); + + if(value2 > 16) { + printf("Invalid Register.\n"); + return; + } + debuggerBreakpointList[i].ia2=true; + tvalue="r"; + break; + default: //immediate; + sscanf(value, "%x",&value2); + debuggerBreakpointList[i].ia2=false; + tvalue="0x"; + + switch(size) { + case 'b': + value2 &=0xFF; + break; + case 'h': + value2 &=0xFFFF; + break; + default: + case 'w': + value2 &=0xFFFFFFFF; + break; + } + break; + } + + debuggerBreakpointList[i].cond_value = value2; + debuggerNumOfBreakpoints++; + + // At here, everything's set. Display message. + switch(size) { + case 0: + printf("Added breakpoint on %08X if R%02d %s %08X\n", + debuggerBreakpointList[i].address, + debuggerBreakpointList[i].cond_address, + op, + debuggerBreakpointList[i].cond_value); + break; + case 'b': + printf("Added breakpoint on %08X if %s%08X %s %s%02X\n", + debuggerBreakpointList[i].address, + taddress, + debuggerBreakpointList[i].cond_address, + op,tvalue, + debuggerBreakpointList[i].cond_value); + break; + case 'h': + printf("Added breakpoint on %08X if %s%08X %s %s%04X\n", + debuggerBreakpointList[i].address, + taddress, + debuggerBreakpointList[i].cond_address, + op, + tvalue, + debuggerBreakpointList[i].cond_value); + break; + case 'w': + printf("Added breakpoint on %08X if %s%08X %s %s%08X\n", + debuggerBreakpointList[i].address, + taddress, + debuggerBreakpointList[i].cond_address, + op,tvalue, + debuggerBreakpointList[i].cond_value); + break; + } +} + +static bool debuggerCondEvaluate(int num) +{ + // check if there is a condition + if(debuggerBreakpointList[num].cond_rel == 0) + return true; + + u32 address=debuggerBreakpointList[num].cond_address; + char size=debuggerBreakpointList[num].cond_size; + u32 value=debuggerBreakpointList[num].cond_value; + u32 value1=0; + u32 value2=0; + + if(address<17) + value1=reg[address].I; + else { + switch(size) { + case 1: + value1=debuggerReadByte(address); + break; + case 2: + value1=debuggerReadHalfWord(address); + break; + default: + value1=debuggerReadMemory(address); + break; + } + } + + //value2 + if(debuggerBreakpointList[num].ia2) { //is address or register + if(value<17) + value2=reg[address].I; + else { + switch(size) { + case 'b': + value2=debuggerReadByte(value); + break; + case 'h': + value2=debuggerReadHalfWord(value); + break; + default: + value2=debuggerReadMemory(value); + break; + } + } + } else + value2=value; + + switch(debuggerBreakpointList[num].cond_rel) { + case 1: // == + return (value1 == value2); + case 2: // != + return (value1 != value2); + case 3: // < + return (value1 < value2); + case 4: // > + return (value1 > value2); + case 5: // <= + return (value1 <= value2); + case 6: // >= + return (value1 >= value2); + default: + return false; //should never happen + } +} + +/*extern*/ void debuggerOutput(char *s, u32 addr) { if(s) printf(s); @@ -1414,7 +2556,65 @@ } } -void debuggerMain() +char* strqtok (char* string, const char* ctrl) +{ // quoted tokens + static char* nexttoken = NULL; + char* str; + + if (string != NULL) + str = string; + else { + if (nexttoken == NULL) + return NULL; + str = nexttoken; + }; + + char deli [32]; + memset (deli, 0, 32 * sizeof (char)); + while (*ctrl) + { + deli [*ctrl >> 3] |= (1 << (*ctrl & 7)); + ctrl++; + }; + // can't allow to be set + deli ['"' >> 3] &= ~(1 << ('"' & 7)); + + // jump over leading delimiters + while ((deli [*str >> 3] & (1 << (*str & 7))) && *str) + str++; + + if (*str == '"') + { + string = ++str; + + // only break if another quote or end of string is found + while ((*str != '"') && *str) + str++; + } else { + string = str; + + // break on delimiter + while (!(deli [*str >> 3] & (1 << (*str & 7))) && *str) + str++; + }; + + if (string == str) + { + nexttoken = NULL; + return NULL; + } else { + if (*str) + { + *str = 0; + nexttoken = str + 1; + } else + nexttoken = NULL; + + return string; + }; +}; + +/*extern*/ void debuggerMain() { char buffer[1024]; char *commands[10]; @@ -1426,15 +2626,16 @@ while(debugger) { systemSoundPause(); + debuggerDisableBreakpoints(); printf("debugger> "); commandCount = 0; char *s = fgets(buffer, 1024, stdin); - commands[0] = strtok(s, " \t\n"); + commands[0] = strqtok(s, " \t\n"); if(commands[0] == NULL) continue; commandCount++; - while((s = strtok(NULL, " \t\n"))) { + while((s = strqtok(NULL, " \t\n"))) { commands[commandCount++] = s; if(commandCount == 10) break; @@ -1452,3 +2653,12 @@ } } } + +void debuggerLast(int n, char **args) +{ +debugger_last =!debugger_last; +if (debugger_last == true) +printf ("Last registers will be shown\n"); +else +printf ("Last registers wont be shown\n"); +} diff -urN ../VisualBoyAdvance-1.7.2/src/thumb.h ./src/thumb.h --- ../VisualBoyAdvance-1.7.2/src/thumb.h 2004-05-13 22:50:06 +0900 +++ ./src/thumb.h 2006-06-25 05:21:47 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,6 +17,17 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// The following define updates oldreg when debugger_last is activated + +#define UPDATE_OLD_REG \ + if (debugger_last) { \ + sprintf(oldbuffer,"%08x", armState ? reg[15].I - 4 : reg[15].I - 4); \ + for (xxx=0; xxx<18; xxx++){ \ + oldreg[xxx]=reg[xxx].I; \ + } \ + } + + #ifdef C_CORE #define NEG(i) ((i) >> 31) #define POS(i) ((~(i)) >> 31) @@ -763,16 +774,29 @@ #endif #endif -u32 opcode = CPUReadHalfWordQuick(armNextPC); -clockTicks = thumbCycles[opcode >> 8] + memoryWaitFetch[(armNextPC >> 24) & 15]; + +#ifdef BKPT_SUPPORT +u8 xxx; +#endif + +u32 opcode = cpuPrefetch[0]; +cpuPrefetch[0] = cpuPrefetch[1]; + +busPrefetch = false; + if (busPrefetchCount & 0xFFFFFF00) + busPrefetchCount = 0x100 | (busPrefetchCount & 0xFF); + +clockTicks = 0; +u32 oldArmNextPC = armNextPC; #ifndef FINAL_VERSION if(armNextPC == stop) { - armNextPC = armNextPC++; + armNextPC++; } #endif armNextPC = reg[15].I; reg[15].I += 2; +THUMB_PREFETCH_NEXT; switch(opcode >> 8) { case 0x00: @@ -901,54 +925,22 @@ } break; case 0x20: - // MOV R0, #Offset8 - reg[0].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[0].I ? false : true); - break; case 0x21: - // MOV R1, #Offset8 - reg[1].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[1].I ? false : true); - break; case 0x22: - // MOV R2, #Offset8 - reg[2].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[2].I ? false : true); - break; case 0x23: - // MOV R3, #Offset8 - reg[3].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[3].I ? false : true); - break; case 0x24: - // MOV R4, #Offset8 - reg[4].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[4].I ? false : true); - break; case 0x25: - // MOV R5, #Offset8 - reg[5].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[5].I ? false : true); - break; case 0x26: - // MOV R6, #Offset8 - reg[6].I = opcode & 255; - N_FLAG = false; - Z_FLAG = (reg[6].I ? false : true); - break; case 0x27: - // MOV R7, #Offset8 - reg[7].I = opcode & 255; + { + u8 regist = (opcode >> 8) & 7; + // MOV R0~R7, #Offset8 + reg[regist].I = opcode & 255; N_FLAG = false; - Z_FLAG = (reg[7].I ? false : true); + Z_FLAG = (reg[regist].I ? false : true); + } break; - case 0x28: +case 0x28: // CMP R0, #Offset8 CMP_RN_O8(0); break; @@ -1044,6 +1036,7 @@ // SUB R7,#Offset8 SUB_RN_O8(7); break; + case 0x40: switch((opcode >> 6) & 3) { case 0x00: @@ -1093,7 +1086,7 @@ } N_FLAG = reg[dest].I & 0x80000000 ? true : false; Z_FLAG = reg[dest].I ? false : true; - clockTicks++; + clockTicks = codeTicksAccess16(armNextPC)+2; } break; case 0x03: @@ -1115,7 +1108,7 @@ } N_FLAG = reg[dest].I & 0x80000000 ? true : false; Z_FLAG = reg[dest].I ? false : true; - clockTicks++; + clockTicks = codeTicksAccess16(armNextPC)+2; } break; } @@ -1144,7 +1137,7 @@ } N_FLAG = reg[dest].I & 0x80000000 ? true : false; Z_FLAG = reg[dest].I ? false : true; - clockTicks++; + clockTicks = codeTicksAccess16(armNextPC)+2; } break; case 0x01: @@ -1181,7 +1174,7 @@ reg[dest].I = value; } } - clockTicks++; + clockTicks = codeTicksAccess16(armNextPC)+2; N_FLAG = reg[dest].I & 0x80000000 ? true : false; Z_FLAG = reg[dest].I ? false : true; } @@ -1239,19 +1232,22 @@ case 0x01: { // MUL Rd, Rs + clockTicks = 1; int dest = opcode & 7; - u32 rm = reg[(opcode >> 3) & 7].I; - reg[dest].I = reg[dest].I * rm; + u32 rm = reg[dest].I; + reg[dest].I = reg[(opcode >> 3) & 7].I * rm; if (((s32)rm) < 0) rm = ~rm; if ((rm & 0xFFFFFF00) == 0) - clockTicks += 1; + clockTicks += 0; else if ((rm & 0xFFFF0000) == 0) - clockTicks += 2; + clockTicks += 1; else if ((rm & 0xFF000000) == 0) - clockTicks += 3; + clockTicks += 2; else - clockTicks += 4; + clockTicks += 3; + busPrefetchCount = (busPrefetchCount<>(8-clockTicks)); + clockTicks += codeTicksAccess16(armNextPC) + 1; Z_FLAG = reg[dest].I ? false : true; N_FLAG = reg[dest].I & 0x80000000 ? true : false; } @@ -1294,7 +1290,9 @@ reg[15].I &= 0xFFFFFFFE; armNextPC = reg[15].I; reg[15].I += 2; - clockTicks++; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC)+1; + clockTicks += clockTicks+codeTicksAccess16(armNextPC)+1; } break; case 3: @@ -1304,7 +1302,9 @@ reg[15].I &= 0xFFFFFFFE; armNextPC = reg[15].I; reg[15].I += 2; - clockTicks++; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC)+1; + clockTicks += clockTicks+codeTicksAccess16(armNextPC)+1; } break; } @@ -1359,20 +1359,33 @@ // MOV Hd, Rs reg[dest+8].I = reg[base].I; if(dest == 7) { +#ifdef BKPT_SUPPORT + UPDATE_OLD_REG +#endif + reg[15].I &= 0xFFFFFFFE; armNextPC = reg[15].I; reg[15].I += 2; - clockTicks++; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC)+1; + clockTicks += clockTicks+codeTicksAccess16(armNextPC)+1; } break; case 3: // MOV Hd, Hs reg[dest+8].I = reg[base+8].I; if(dest == 7) { + +#ifdef BKPT_SUPPORT + UPDATE_OLD_REG +#endif + reg[15].I &= 0xFFFFFFFE; armNextPC = reg[15].I; reg[15].I += 2; - clockTicks++; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC)+1; + clockTicks += clockTicks+codeTicksAccess16(armNextPC)+1; } break; } @@ -1381,33 +1394,54 @@ case 0x47: { int base = (opcode >> 3) & 7; + busPrefetchCount=0; switch((opcode >>6) & 3) { case 0: // BX Rs +#ifdef BKPT_SUPPORT + UPDATE_OLD_REG +#endif reg[15].I = (reg[base].I) & 0xFFFFFFFE; if(reg[base].I & 1) { armState = false; armNextPC = reg[15].I; reg[15].I += 2; + THUMB_PREFETCH; + clockTicks = codeTicksAccessSeq16(armNextPC) + + codeTicksAccessSeq16(armNextPC) + codeTicksAccess16(armNextPC) + 3; } else { armState = true; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks = codeTicksAccessSeq32(armNextPC) + + codeTicksAccessSeq32(armNextPC) + codeTicksAccess32(armNextPC) + 3; } break; case 1: // BX Hs + +#ifdef BKPT_SUPPORT + UPDATE_OLD_REG +#endif + reg[15].I = (reg[8+base].I) & 0xFFFFFFFE; if(reg[8+base].I & 1) { armState = false; armNextPC = reg[15].I; reg[15].I += 2; + THUMB_PREFETCH; + clockTicks = dataTicksAccess16(armNextPC) + dataTicksAccess16(armNextPC) + + codeTicksAccess16(armNextPC) + 3; } else { armState = true; reg[15].I &= 0xFFFFFFFC; armNextPC = reg[15].I; reg[15].I += 4; + ARM_PREFETCH; + clockTicks = dataTicksAccess32(armNextPC) + dataTicksAccess32(armNextPC) + + codeTicksAccess32(armNextPC) + 3; } break; default: @@ -1416,143 +1450,119 @@ } break; case 0x48: - // LDR R0,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[0].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x49: - // LDR R1,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[1].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4a: - // LDR R2,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[2].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4b: - // LDR R3,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[3].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4c: - // LDR R4,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[4].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4d: - // LDR R5,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[5].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4e: - // LDR R6,[PC, #Imm] - { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[6].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x4f: - // LDR R7,[PC, #Imm] + // LDR R0~R7,[PC, #Imm] { - u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); - reg[7].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); + u8 regist = (opcode >> 8) & 7; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; + u32 address = (reg[15].I & 0xFFFFFFFC) + ((opcode & 0xFF) << 2); + reg[regist].I = CPUReadMemoryQuick(address); + busPrefetchCount=0; + clockTicks = 3 + dataTicksAccess32(address) + + codeTicksAccess16(armNextPC); } break; case 0x50: case 0x51: // STR Rd, [Rs, Rn] { - u32 - address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; + u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; CPUWriteMemory(address, reg[opcode & 7].I); - clockTicks += CPUUpdateTicksAccess32(address); + clockTicks = dataTicksAccess32(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x52: case 0x53: // STRH Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; CPUWriteHalfWord(address, reg[opcode&7].W.W0); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = dataTicksAccess16(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x54: case 0x55: // STRB Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode >>6)&7].I; CPUWriteByte(address, reg[opcode & 7].B.B0); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = dataTicksAccess16(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x56: case 0x57: // LDSB Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; reg[opcode&7].I = (s8)CPUReadByte(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess16(address) + + codeTicksAccess16(armNextPC); } break; case 0x58: case 0x59: // LDR Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; reg[opcode&7].I = CPUReadMemory(address); - clockTicks += CPUUpdateTicksAccess32(address); + clockTicks = 3 + dataTicksAccess32(address) + + codeTicksAccess16(armNextPC); } break; case 0x5a: case 0x5b: // LDRH Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; reg[opcode&7].I = CPUReadHalfWord(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess32(address) + + codeTicksAccess16(armNextPC); } break; case 0x5c: case 0x5d: // LDRB Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; reg[opcode&7].I = CPUReadByte(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess16(address) + + codeTicksAccess16(armNextPC); } break; case 0x5e: case 0x5f: // LDSH Rd, [Rs, Rn] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + reg[(opcode>>6)&7].I; reg[opcode&7].I = (s16)CPUReadHalfWordSigned(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess16(address) + + codeTicksAccess16(armNextPC); } break; case 0x60: @@ -1565,10 +1575,12 @@ case 0x67: // STR Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)<<2); CPUWriteMemory(address, reg[opcode&7].I); - clockTicks += CPUUpdateTicksAccess32(address); + clockTicks = dataTicksAccess32(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x68: @@ -1581,9 +1593,12 @@ case 0x6f: // LDR Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)<<2); reg[opcode&7].I = CPUReadMemory(address); - clockTicks += CPUUpdateTicksAccess32(address); + clockTicks = 3 + dataTicksAccess32(address) + + codeTicksAccess16(armNextPC); } break; case 0x70: @@ -1596,10 +1611,12 @@ case 0x77: // STRB Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)); CPUWriteByte(address, reg[opcode&7].B.B0); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = dataTicksAccess16(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x78: @@ -1612,9 +1629,12 @@ case 0x7f: // LDRB Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)); reg[opcode&7].I = CPUReadByte(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess16(address) + + codeTicksAccess16(armNextPC); } break; case 0x80: @@ -1627,10 +1647,12 @@ case 0x87: // STRH Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)<<1); CPUWriteHalfWord(address, reg[opcode&7].W.W0); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = dataTicksAccess16(address) + codeTicksAccess16(armNextPC) + 2; } break; case 0x88: @@ -1643,203 +1665,79 @@ case 0x8f: // LDRH Rd, [Rs, #Imm] { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[(opcode>>3)&7].I + (((opcode>>6)&31)<<1); reg[opcode&7].I = CPUReadHalfWord(address); - clockTicks += CPUUpdateTicksAccess16(address); + clockTicks = 3 + dataTicksAccess16(address) + + codeTicksAccess16(armNextPC); } break; case 0x90: - // STR R0, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[0].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x91: - // STR R1, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[1].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x92: - // STR R2, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[2].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x93: - // STR R3, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[3].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x94: - // STR R4, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[4].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x95: - // STR R5, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[5].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x96: - // STR R6, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[6].I); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x97: - // STR R7, [SP, #Imm] + // STR R0~R7, [SP, #Imm] { - u32 address = reg[13].I + ((opcode&255)<<2); - CPUWriteMemory(address, reg[7].I); - clockTicks += CPUUpdateTicksAccess32(address); + u8 regist = (opcode >> 8) & 7; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; + u32 address = reg[13].I + ((opcode&255)<<2); + CPUWriteMemory(address, reg[regist].I); + clockTicks = dataTicksAccess32(address) + codeTicksAccess16(armNextPC) + 2; } - break; + break; case 0x98: - // LDR R0, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[0].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x99: - // LDR R1, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[1].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9a: - // LDR R2, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[2].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9b: - // LDR R3, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[3].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9c: - // LDR R4, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[4].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9d: - // LDR R5, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[5].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9e: - // LDR R6, [SP, #Imm] - { - u32 address = reg[13].I + ((opcode&255)<<2); - reg[6].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); - } - break; case 0x9f: - // LDR R7, [SP, #Imm] + // LDR R0~R7, [SP, #Imm] { + u8 regist = (opcode >> 8) & 7; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; u32 address = reg[13].I + ((opcode&255)<<2); - reg[7].I = CPUReadMemoryQuick(address); - clockTicks += CPUUpdateTicksAccess32(address); + reg[regist].I = CPUReadMemoryQuick(address); + clockTicks = 3 + dataTicksAccess32(address) + + codeTicksAccess16(armNextPC); } break; case 0xa0: - // ADD R0, PC, Imm - reg[0].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa1: - // ADD R1, PC, Imm - reg[1].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa2: - // ADD R2, PC, Imm - reg[2].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa3: - // ADD R3, PC, Imm - reg[3].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa4: - // ADD R4, PC, Imm - reg[4].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa5: - // ADD R5, PC, Imm - reg[5].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa6: - // ADD R6, PC, Imm - reg[6].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); - break; case 0xa7: - // ADD R7, PC, Imm - reg[7].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); + { + // ADD R0~R7, PC, Imm + u8 regist = (opcode >> 8) & 7; + reg[regist].I = (reg[15].I & 0xFFFFFFFC) + ((opcode&255)<<2); + } break; case 0xa8: - // ADD R0, SP, Imm - reg[0].I = reg[13].I + ((opcode&255)<<2); - break; case 0xa9: - // ADD R1, SP, Imm - reg[1].I = reg[13].I + ((opcode&255)<<2); - break; case 0xaa: - // ADD R2, SP, Imm - reg[2].I = reg[13].I + ((opcode&255)<<2); - break; case 0xab: - // ADD R3, SP, Imm - reg[3].I = reg[13].I + ((opcode&255)<<2); - break; case 0xac: - // ADD R4, SP, Imm - reg[4].I = reg[13].I + ((opcode&255)<<2); - break; case 0xad: - // ADD R5, SP, Imm - reg[5].I = reg[13].I + ((opcode&255)<<2); - break; case 0xae: - // ADD R6, SP, Imm - reg[6].I = reg[13].I + ((opcode&255)<<2); - break; case 0xaf: - // ADD R7, SP, Imm - reg[7].I = reg[13].I + ((opcode&255)<<2); - break; + { + // ADD R0~R7, SP, Imm + u8 regist = (opcode >> 8) & 7; + reg[regist].I = reg[13].I + ((opcode&255)<<2); + } + break; case 0xb0: { // ADD SP, Imm @@ -1853,15 +1751,17 @@ if(opcode & (val)) {\ CPUWriteMemory(address, reg[(r)].I);\ if(offset)\ - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ else\ - clockTicks += 1 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ address += 4;\ } case 0xb4: // PUSH {Rlist} { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = 0; u32 temp = reg[13].I - 4 * cpuBitsSet[opcode & 0xff]; u32 address = temp & 0xFFFFFFFC; @@ -1873,12 +1773,15 @@ PUSH_REG(32, 5); PUSH_REG(64, 6); PUSH_REG(128, 7); + clockTicks += codeTicksAccess16(armNextPC)+1; reg[13].I = temp; } break; case 0xb5: // PUSH {Rlist, LR} { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = 0; u32 temp = reg[13].I - 4 - 4 * cpuBitsSet[opcode & 0xff]; u32 address = temp & 0xFFFFFFFC; @@ -1891,6 +1794,7 @@ PUSH_REG(64, 6); PUSH_REG(128, 7); PUSH_REG(256, 14); + clockTicks += codeTicksAccess16(armNextPC)+1; reg[13].I = temp; } break; @@ -1898,18 +1802,21 @@ if(opcode & (val)) {\ reg[(r)].I = CPUReadMemory(address);\ if(offset)\ - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ else\ - clockTicks += 2 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ address += 4;\ } case 0xbc: // POP {Rlist} { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = 0; u32 address = reg[13].I & 0xFFFFFFFC; u32 temp = reg[13].I + 4*cpuBitsSet[opcode & 0xFF]; + clockTicks = 0; POP_REG(1, 0); POP_REG(2, 1); POP_REG(4, 2); @@ -1919,14 +1826,18 @@ POP_REG(64, 6); POP_REG(128, 7); reg[13].I = temp; + clockTicks += codeTicksAccess16(armNextPC)+2; } break; case 0xbd: // POP {Rlist, PC} { + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; int offset = 0; u32 address = reg[13].I & 0xFFFFFFFC; u32 temp = reg[13].I + 4 + 4*cpuBitsSet[opcode & 0xFF]; + clockTicks = 0; POP_REG(1, 0); POP_REG(2, 1); POP_REG(4, 2); @@ -1937,12 +1848,15 @@ POP_REG(128, 7); reg[15].I = (CPUReadMemory(address) & 0xFFFFFFFE); if(offset) - clockTicks += CPUUpdateTicksAccessSeq32(address); + clockTicks += 1 + dataTicksAccessSeq32(address); else - clockTicks += CPUUpdateTicksAccess32(address); + clockTicks += 1 + dataTicksAccess32(address); armNextPC = reg[15].I; reg[15].I += 2; reg[13].I = temp; + THUMB_PREFETCH; + busPrefetchCount=0; + clockTicks += codeTicksAccess16(armNextPC) + codeTicksAccess16(armNextPC) + 3; } break; #define THUMB_STM_REG(val,r,b) \ @@ -1950,297 +1864,67 @@ CPUWriteMemory(address, reg[(r)].I);\ if(!offset) {\ reg[(b)].I = temp;\ - clockTicks += 1 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccess32(address);\ } else \ - clockTicks += 1 + CPUUpdateTicksAccessSeq32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ offset = 1;\ address += 4;\ } case 0xc0: - { - // STM R0!, {Rlist} - u32 address = reg[0].I & 0xFFFFFFFC; - u32 temp = reg[0].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 0); - THUMB_STM_REG(2, 1, 0); - THUMB_STM_REG(4, 2, 0); - THUMB_STM_REG(8, 3, 0); - THUMB_STM_REG(16, 4, 0); - THUMB_STM_REG(32, 5, 0); - THUMB_STM_REG(64, 6, 0); - THUMB_STM_REG(128, 7, 0); - } - break; case 0xc1: - { - // STM R1!, {Rlist} - u32 address = reg[1].I & 0xFFFFFFFC; - u32 temp = reg[1].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 1); - THUMB_STM_REG(2, 1, 1); - THUMB_STM_REG(4, 2, 1); - THUMB_STM_REG(8, 3, 1); - THUMB_STM_REG(16, 4, 1); - THUMB_STM_REG(32, 5, 1); - THUMB_STM_REG(64, 6, 1); - THUMB_STM_REG(128, 7, 1); - } - break; case 0xc2: - { - // STM R2!, {Rlist} - u32 address = reg[2].I & 0xFFFFFFFC; - u32 temp = reg[2].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 2); - THUMB_STM_REG(2, 1, 2); - THUMB_STM_REG(4, 2, 2); - THUMB_STM_REG(8, 3, 2); - THUMB_STM_REG(16, 4, 2); - THUMB_STM_REG(32, 5, 2); - THUMB_STM_REG(64, 6, 2); - THUMB_STM_REG(128, 7, 2); - } - break; case 0xc3: - { - // STM R3!, {Rlist} - u32 address = reg[3].I & 0xFFFFFFFC; - u32 temp = reg[3].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 3); - THUMB_STM_REG(2, 1, 3); - THUMB_STM_REG(4, 2, 3); - THUMB_STM_REG(8, 3, 3); - THUMB_STM_REG(16, 4, 3); - THUMB_STM_REG(32, 5, 3); - THUMB_STM_REG(64, 6, 3); - THUMB_STM_REG(128, 7, 3); - } - break; case 0xc4: - { - // STM R4!, {Rlist} - u32 address = reg[4].I & 0xFFFFFFFC; - u32 temp = reg[4].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 4); - THUMB_STM_REG(2, 1, 4); - THUMB_STM_REG(4, 2, 4); - THUMB_STM_REG(8, 3, 4); - THUMB_STM_REG(16, 4, 4); - THUMB_STM_REG(32, 5, 4); - THUMB_STM_REG(64, 6, 4); - THUMB_STM_REG(128, 7, 4); - } - break; case 0xc5: - { - // STM R5!, {Rlist} - u32 address = reg[5].I & 0xFFFFFFFC; - u32 temp = reg[5].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 5); - THUMB_STM_REG(2, 1, 5); - THUMB_STM_REG(4, 2, 5); - THUMB_STM_REG(8, 3, 5); - THUMB_STM_REG(16, 4, 5); - THUMB_STM_REG(32, 5, 5); - THUMB_STM_REG(64, 6, 5); - THUMB_STM_REG(128, 7, 5); - } - break; case 0xc6: - { - // STM R6!, {Rlist} - u32 address = reg[6].I & 0xFFFFFFFC; - u32 temp = reg[6].I + 4*cpuBitsSet[opcode & 0xff]; - int offset = 0; - // store - THUMB_STM_REG(1, 0, 6); - THUMB_STM_REG(2, 1, 6); - THUMB_STM_REG(4, 2, 6); - THUMB_STM_REG(8, 3, 6); - THUMB_STM_REG(16, 4, 6); - THUMB_STM_REG(32, 5, 6); - THUMB_STM_REG(64, 6, 6); - THUMB_STM_REG(128, 7, 6); - } - break; case 0xc7: { - // STM R7!, {Rlist} - u32 address = reg[7].I & 0xFFFFFFFC; - u32 temp = reg[7].I + 4*cpuBitsSet[opcode & 0xff]; + // STM R0~7!, {Rlist} + u8 regist = (opcode >> 8) & 7; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; + u32 address = reg[regist].I & 0xFFFFFFFC; + u32 temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xff]; int offset = 0; // store - THUMB_STM_REG(1, 0, 7); - THUMB_STM_REG(2, 1, 7); - THUMB_STM_REG(4, 2, 7); - THUMB_STM_REG(8, 3, 7); - THUMB_STM_REG(16, 4, 7); - THUMB_STM_REG(32, 5, 7); - THUMB_STM_REG(64, 6, 7); - THUMB_STM_REG(128, 7, 7); + THUMB_STM_REG(1, 0, regist); + THUMB_STM_REG(2, 1, regist); + THUMB_STM_REG(4, 2, regist); + THUMB_STM_REG(8, 3, regist); + THUMB_STM_REG(16, 4, regist); + THUMB_STM_REG(32, 5, regist); + THUMB_STM_REG(64, 6, regist); + THUMB_STM_REG(128, 7, regist); + clockTicks = codeTicksAccess16(armNextPC)+1; } - break; + break; #define THUMB_LDM_REG(val,r) \ if(opcode & (val)) {\ reg[(r)].I = CPUReadMemory(address);\ if(offset)\ - clockTicks += 2 + CPUUpdateTicksAccessSeq32(address);\ - else\ - clockTicks += 2 + CPUUpdateTicksAccess32(address);\ + clockTicks += 1 + dataTicksAccessSeq32(address);\ + else \ + clockTicks += 1 + dataTicksAccess32(address);\ offset = 1;\ address += 4;\ } case 0xc8: - { - // LDM R0!, {Rlist} - u32 address = reg[0].I & 0xFFFFFFFC; - u32 temp = reg[0].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 1)) - reg[0].I = temp; - } - break; case 0xc9: - { - // LDM R1!, {Rlist} - u32 address = reg[1].I & 0xFFFFFFFC; - u32 temp = reg[1].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 2)) - reg[1].I = temp; - } - break; case 0xca: - { - // LDM R2!, {Rlist} - u32 address = reg[2].I & 0xFFFFFFFC; - u32 temp = reg[2].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 4)) - reg[2].I = temp; - } - break; case 0xcb: - { - // LDM R3!, {Rlist} - u32 address = reg[3].I & 0xFFFFFFFC; - u32 temp = reg[3].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 8)) - reg[3].I = temp; - } - break; case 0xcc: - { - // LDM R4!, {Rlist} - u32 address = reg[4].I & 0xFFFFFFFC; - u32 temp = reg[4].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 16)) - reg[4].I = temp; - } - break; case 0xcd: - { - // LDM R5!, {Rlist} - u32 address = reg[5].I & 0xFFFFFFFC; - u32 temp = reg[5].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 32)) - reg[5].I = temp; - } - break; case 0xce: - { - // LDM R6!, {Rlist} - u32 address = reg[6].I & 0xFFFFFFFC; - u32 temp = reg[6].I + 4*cpuBitsSet[opcode & 0xFF]; - int offset = 0; - // load - THUMB_LDM_REG(1, 0); - THUMB_LDM_REG(2, 1); - THUMB_LDM_REG(4, 2); - THUMB_LDM_REG(8, 3); - THUMB_LDM_REG(16, 4); - THUMB_LDM_REG(32, 5); - THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 64)) - reg[6].I = temp; - } - break; case 0xcf: { - // LDM R7!, {Rlist} - u32 address = reg[7].I & 0xFFFFFFFC; - u32 temp = reg[7].I + 4*cpuBitsSet[opcode & 0xFF]; + // LDM R0~R7!, {Rlist} + u8 regist = (opcode >> 8) & 7; + if (!busPrefetchCount) + busPrefetch = busPrefetchEnable; + u32 address = reg[regist].I & 0xFFFFFFFC; + u32 temp = reg[regist].I + 4*cpuBitsSet[opcode & 0xFF]; int offset = 0; + clockTicks = 0; // load THUMB_LDM_REG(1, 0); THUMB_LDM_REG(2, 1); @@ -2249,141 +1933,232 @@ THUMB_LDM_REG(16, 4); THUMB_LDM_REG(32, 5); THUMB_LDM_REG(64, 6); - THUMB_LDM_REG(128, 7); - if(!(opcode & 128)) - reg[7].I = temp; + THUMB_LDM_REG(128, 7); + clockTicks += codeTicksAccess16(armNextPC)+2; + if(!(opcode & (1<GetString(szBuffer); index = m_currents.AddString(szBuffer); // and a pointer to the accel object. - m_currents.SetItemData(index, (DWORD)pAccel); + m_currents.SetItemData(index, (DWORD_PTR)pAccel); } } // Init the key editor @@ -185,7 +185,8 @@ return; // no valid key, abort int count = m_commands.GetCount(); - for (int index = 0; index < count; index++) { + int index; + for (index = 0; index < count; index++) { wIDCommand = LOWORD(m_commands.GetItemData(index)); mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel); @@ -234,7 +235,7 @@ pAccel->GetString(szBuffer); index = m_currents.AddString(szBuffer); - m_currents.SetItemData(index, (DWORD)pAccel); + m_currents.SetItemData(index, (DWORD_PTR)pAccel); // Reset the key editor. m_key.ResetKey(); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/AcceleratorManager.cpp ./src/win32/AcceleratorManager.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/AcceleratorManager.cpp 2003-11-04 23:09:51 +0900 +++ ./src/win32/AcceleratorManager.cpp 2006-06-07 06:04:20 +0900 @@ -247,7 +247,7 @@ } } - int nAccel = arrayACCEL.GetSize(); + INT_PTR nAccel = arrayACCEL.GetSize(); LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, nAccel * sizeof(ACCEL)); if (!lpAccel) { for (iLoop = 0; iLoop < nAccel; iLoop++) @@ -268,7 +268,7 @@ } arrayACCEL.RemoveAll(); - HACCEL hNewTable = CreateAcceleratorTable(lpAccel, nAccel); + HACCEL hNewTable = CreateAcceleratorTable(lpAccel, (int)nAccel); if (!hNewTable) { ::LocalFree(lpAccel); return false; @@ -709,14 +709,14 @@ } // AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount)); - int count = AccelsDatasArray.GetSize(); + INT_PTR count = AccelsDatasArray.GetSize(); DWORD *data = (DWORD *)malloc(count * sizeof(DWORD)); ASSERT(data != NULL); for(int index = 0; index < count; index++) data[index] = AccelsDatasArray[index]; - regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD)); + regSetBinaryValue("keyboard", (char *)data, (int)(count*sizeof(DWORD))); AccelsDatasArray.RemoveAll(); CmdDatasArray.RemoveAll(); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/BitmapControl.h ./src/win32/BitmapControl.h --- ../VisualBoyAdvance-1.7.2/src/win32/BitmapControl.h 2004-05-13 22:47:15 +0900 +++ ./src/win32/BitmapControl.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_BITMAPCONTROL_H__2434AADB_B6A5_4E43_AA16_7B65B6F7FA26__INCLUDED_) #define AFX_BITMAPCONTROL_H__2434AADB_B6A5_4E43_AA16_7B65B6F7FA26__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/BugReport.cpp ./src/win32/BugReport.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/BugReport.cpp 2004-05-13 23:29:11 +0900 +++ ./src/win32/BugReport.cpp 2006-08-02 04:21:16 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -216,7 +216,6 @@ AppendFormat(report, "Using BIOS : %d\r\n", theApp.useBiosFile); AppendFormat(report, "Skip BIOS : %d\r\n", theApp.skipBiosFile); AppendFormat(report, "Disable SFX : %d\r\n", cpuDisableSfx); - AppendFormat(report, "Skip intro : %d\r\n", theApp.removeIntros); AppendFormat(report, "Throttle : %d\r\n", theApp.throttle); AppendFormat(report, "Rewind : %d\r\n", theApp.rewindTimer); AppendFormat(report, "Auto frame : %d\r\n", theApp.autoFrameSkip); @@ -227,6 +226,7 @@ AppendFormat(report, "Green shift : %08x\r\n", systemGreenShift); AppendFormat(report, "Blue shift : %08x\r\n", systemBlueShift); AppendFormat(report, "Layer setting: %04X\r\n", layerSettings); + AppendFormat(report, "Mirroring : %d\r\n", mirroringEnable); AppendFormat(report, "Save type : %d (%d)\r\n", theApp.winSaveType, cpuSaveType); AppendFormat(report, "Flash size : %08X (%08x)\r\n", diff -urN ../VisualBoyAdvance-1.7.2/src/win32/CmdAccelOb.cpp ./src/win32/CmdAccelOb.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/CmdAccelOb.cpp 2003-11-04 23:09:52 +0900 +++ ./src/win32/CmdAccelOb.cpp 2006-05-14 01:32:16 +0900 @@ -264,7 +264,8 @@ return; // modifiers part - for (int i = 0; i < sizetable(mapVirtSysKeys); i++) { + int i; + for (i = 0; i < sizetable(mapVirtSysKeys); i++) { if (m_cVirt & mapVirtSysKeys[i].wKey) { szBuffer += mapVirtSysKeys[i].szKey; szBuffer += "+"; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ColorButton.h ./src/win32/ColorButton.h --- ../VisualBoyAdvance-1.7.2/src/win32/ColorButton.h 2004-05-13 22:46:40 +0900 +++ ./src/win32/ColorButton.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_COLORBUTTON_H__DF02109B_B91C_49FD_954F_74A48B83C314__INCLUDED_) #define AFX_COLORBUTTON_H__DF02109B_B91C_49FD_954F_74A48B83C314__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ColorControl.h ./src/win32/ColorControl.h --- ../VisualBoyAdvance-1.7.2/src/win32/ColorControl.h 2004-05-13 22:46:30 +0900 +++ ./src/win32/ColorControl.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_COLORCONTROL_H__747E1E47_DDFA_4D67_B337_A473F2BACB86__INCLUDED_) #define AFX_COLORCONTROL_H__747E1E47_DDFA_4D67_B337_A473F2BACB86__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Commands.cpp ./src/win32/Commands.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Commands.cpp 2004-05-13 23:28:36 +0900 +++ ./src/win32/Commands.cpp 2006-08-04 00:20:17 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -129,13 +129,13 @@ { "OptionsEmulatorDirectories", ID_OPTIONS_EMULATOR_DIRECTORIES }, { "OptionsEmulatorSelectBIOS", ID_OPTIONS_EMULATOR_SELECTBIOSFILE }, { "OptionsEmulatorUseBIOS", ID_OPTIONS_EMULATOR_USEBIOSFILE }, + { "OptionsEmulatorGameOverrides", ID_OPTIONS_EMULATOR_GAMEOVERRIDES }, { "OptionsEmulatorSkipBIOS", ID_OPTIONS_EMULATOR_SKIPBIOS }, { "OptionsEmulatorShowSpeedNone", ID_OPTIONS_EMULATOR_SHOWSPEED_NONE }, { "OptionsEmulatorShowSpeedPercentage", ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE }, { "OptionsEmulatorShowSpeedDetailed", ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED }, { "OptionsEmulatorShowSpeedTransparent", ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT }, { "OptionsEmulatorSpeedupToggle", ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE }, - { "OptionsEmulatorRemoveIntros", ID_OPTIONS_EMULATOR_REMOVEINTROSGBA }, { "OptionsEmulatorAutoHideMenu", ID_OPTIONS_EMULATOR_AUTOHIDEMENU }, { "OptionsEmulatorSaveAuto", ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC }, { "OptionsEmulatorSaveEEPROM", ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM }, @@ -147,6 +147,7 @@ { "OptionsEmulatorAutoIPSPatch", ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH }, { "OptionsEmulatorAGBPrint", ID_OPTIONS_EMULATOR_AGBPRINT }, { "OptionsEmulatorRTC", ID_OPTIONS_EMULATOR_REALTIMECLOCK }, + { "OptionsEmulatorGenericflashcard", ID_OPTIONS_EMULATOR_GENERICFLASHCARD }, { "OptionsEmulatorRewindInterval", ID_OPTIONS_EMULATOR_REWINDINTERVAL }, { "OptionsSoundOff", ID_OPTIONS_SOUND_OFF }, { "OptionsSoundMute", ID_OPTIONS_SOUND_MUTE }, diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Direct3D.cpp ./src/win32/Direct3D.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Direct3D.cpp 2004-05-13 23:28:26 +0900 +++ ./src/win32/Direct3D.cpp 2006-08-11 19:58:39 +0900 @@ -1,6 +1,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,11 +18,8 @@ // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -#include "vba.h" -#define DIRECT3D_VERSION 0x0800 -#include -#include +#include "Display.h" #include "MainWnd.h" @@ -29,10 +27,17 @@ #include "../GBA.h" #include "../Globals.h" #include "../Text.h" +#include "../Util.h" #include "../gb/gbGlobals.h" -#include "Reg.h" -#include "resource.h" +// Direct3D +#define DIRECT3D_VERSION 0x0900 +#include // main include file +#include // required for font rednering +#include // contains debug functions + +extern int Init_2xSaI(u32); // initializes all pixel filters +extern int systemSpeed; #ifdef _DEBUG #define new DEBUG_NEW @@ -42,720 +47,588 @@ #ifdef MMX extern "C" bool cpu_mmx; - extern bool detectMMX(); #endif -extern int Init_2xSaI(u32); -extern void winlog(const char *,...); -extern int systemSpeed; - -typedef struct _D3DTLVERTEX { - float sx; /* Screen coordinates */ - float sy; - float sz; - float rhw; /* Reciprocal of homogeneous w */ - D3DCOLOR color; /* Vertex color */ - float tu; /* Texture coordinates */ - float tv; - _D3DTLVERTEX() { } - _D3DTLVERTEX(const D3DVECTOR& v, float _rhw, - D3DCOLOR _color, - float _tu, float _tv) - { sx = v.x; sy = v.y; sz = v.z; rhw = _rhw; - color = _color; - tu = _tu; tv = _tv; - } -} D3DTLVERTEX, *LPD3DTLVERTEX; - -#define D3DFVF_TLVERTEX D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1 class Direct3DDisplay : public IDisplay { private: - HINSTANCE d3dDLL; - LPDIRECT3D8 pD3D; - LPDIRECT3DDEVICE8 pDevice; - LPDIRECT3DTEXTURE8 pTexture; - D3DSURFACE_DESC dsdBackBuffer; - D3DPRESENT_PARAMETERS dpp; - D3DFORMAT screenFormat; - int width; - int height; - bool filterDisabled; - ID3DXFont *pFont; - bool failed; - - void restoreDeviceObjects(); - void invalidateDeviceObjects(); - bool initializeOffscreen(int w, int h); - void updateFiltering(int); -public: - Direct3DDisplay(); - virtual ~Direct3DDisplay(); + LPDIRECT3D9 pD3D; + LPDIRECT3DDEVICE9 pDevice; + D3DPRESENT_PARAMETERS dpp; + D3DFORMAT screenFormat; + LPDIRECT3DSURFACE9 emulatedImage; + D3DTEXTUREFILTERTYPE filter; + int width; + int height; + RECT destRect; + bool failed; + ID3DXFont *pFont; + + void createFont(); + void destroyFont(); + void createSurface(); + void destroySurface(); + void calculateDestRect(); + bool resetDevice(); - virtual bool initialize(); - virtual void cleanup(); - virtual void render(); - virtual void checkFullScreen(); - virtual void renderMenu(); - virtual void clear(); - virtual bool changeRenderSize(int w, int h); - virtual void resize(int w, int h); - virtual DISPLAY_TYPE getType() { return DIRECT_3D; }; - virtual void setOption(const char *, int); - virtual int selectFullScreenMode(GUID **); +public: + Direct3DDisplay(); + virtual ~Direct3DDisplay(); + virtual DISPLAY_TYPE getType() { return DIRECT_3D; }; + + virtual bool initialize(); + virtual void cleanup(); + virtual void clear(); + virtual void render(); + + virtual void renderMenu(); + virtual bool changeRenderSize( int w, int h ); + virtual void resize( int w, int h ); + virtual void setOption( const char *option, int value ); + virtual int selectFullScreenMode( GUID ** ); }; + Direct3DDisplay::Direct3DDisplay() { - d3dDLL = NULL; - pD3D = NULL; - pDevice = NULL; - pTexture = NULL; - pFont = NULL; - screenFormat = D3DFMT_R5G6B5; - width = 0; - height = 0; - filterDisabled = false; - failed = false; + pD3D = NULL; + pDevice = NULL; + screenFormat = D3DFMT_X8R8G8B8; + width = 0; + height = 0; + failed = false; + pFont = NULL; + emulatedImage = NULL; + filter = D3DTEXF_POINT; } + Direct3DDisplay::~Direct3DDisplay() { - cleanup(); + cleanup(); } + void Direct3DDisplay::cleanup() { - if(pD3D != NULL) { - if(pFont) { - pFont->Release(); - pFont = NULL; - } - - if(pTexture) { - pTexture->Release(); - pTexture = NULL; - } - - if(pDevice) { - pDevice->Release(); - pDevice = NULL; - } - - pD3D->Release(); - pD3D = NULL; - - if(d3dDLL != NULL) { - FreeLibrary(d3dDLL); - d3dDLL = NULL; - } - } + destroyFont(); + destroySurface(); + + if( pDevice ) { + pDevice->Release(); + pDevice = NULL; + } + + if( pD3D ) { + pD3D->Release(); + pD3D = NULL; + } } + bool Direct3DDisplay::initialize() { - theApp.sizeX = 240; - theApp.sizeY = 160; + switch(theApp.cartridgeType) + { + case IMAGE_GBA: + theApp.sizeX = 240; + theApp.sizeY = 160; + break; + case IMAGE_GB: + if (gbBorderOn) + { + theApp.sizeX = 256; + theApp.sizeY = 224; + } + else + { + theApp.sizeX = 160; + theApp.sizeY = 144; + } + break; + } + + + switch(theApp.videoOption) + { + case VIDEO_1X: + theApp.surfaceSizeX = theApp.sizeX; + theApp.surfaceSizeY = theApp.sizeY; + break; + case VIDEO_2X: + theApp.surfaceSizeX = theApp.sizeX * 2; + theApp.surfaceSizeY = theApp.sizeY * 2; + break; + case VIDEO_3X: + theApp.surfaceSizeX = theApp.sizeX * 3; + theApp.surfaceSizeY = theApp.sizeY * 3; + break; + case VIDEO_4X: + theApp.surfaceSizeX = theApp.sizeX * 4; + theApp.surfaceSizeY = theApp.sizeY * 4; + break; + case VIDEO_320x240: + case VIDEO_640x480: + case VIDEO_800x600: + case VIDEO_OTHER: + float scaleX = ((float)theApp.fsWidth / theApp.sizeX); + float scaleY = ((float)theApp.fsHeight / theApp.sizeY); + float min = (scaleX < scaleY) ? scaleX : scaleY; + if(theApp.fullScreenStretch) { + theApp.surfaceSizeX = theApp.fsWidth; + theApp.surfaceSizeY = theApp.fsHeight; + } else { + theApp.surfaceSizeX = (int)(theApp.sizeX * min); + theApp.surfaceSizeY = (int)(theApp.sizeY * min); + } + break; + } + + theApp.rect.left = 0; + theApp.rect.top = 0; + theApp.rect.right = theApp.sizeX; + theApp.rect.bottom = theApp.sizeY; + + theApp.dest.left = 0; + theApp.dest.top = 0; + theApp.dest.right = theApp.surfaceSizeX; + theApp.dest.bottom = theApp.surfaceSizeY; + + + DWORD style = WS_POPUP | WS_VISIBLE; + DWORD styleEx = 0; + + if(theApp.videoOption <= VIDEO_4X) { + style |= WS_OVERLAPPEDWINDOW; + } else { + styleEx = 0; + } + + if(theApp.videoOption <= VIDEO_4X) { + AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx); + } else { + AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx); + } + + int winSizeX = theApp.dest.right-theApp.dest.left; + int winSizeY = theApp.dest.bottom-theApp.dest.top; + + if(theApp.videoOption > VIDEO_4X) { + winSizeX = theApp.fsWidth; + winSizeY = theApp.fsHeight; + } + + int x = 0, y = 0; + + if(theApp.videoOption <= VIDEO_4X) { + x = theApp.windowPositionX; + y = theApp.windowPositionY; + } + + + // Create a window + MainWnd *pWnd = new MainWnd; + theApp.m_pMainWnd = pWnd; + + pWnd->CreateEx(styleEx, + theApp.wndClass, + _T("VisualBoyAdvance"), + style, + x,y,winSizeX,winSizeY, + NULL, + 0); + + if (!(HWND)*pWnd) { + DXTRACE_ERR_MSGBOX( _T("Error creating window"), 0 ); + return FALSE; + } + pWnd->DragAcceptFiles(TRUE); + theApp.updateMenuBar(); + theApp.adjustDestRect(); + + + // load Direct3D v9 + pD3D = Direct3DCreate9( D3D_SDK_VERSION ); + + if(pD3D == NULL) { + DXTRACE_ERR_MSGBOX( _T("Error creating Direct3D object"), 0 ); + return FALSE; + } + + theApp.mode320Available = FALSE; + theApp.mode640Available = FALSE; + theApp.mode800Available = FALSE; + + D3DDISPLAYMODE mode; + pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); + screenFormat = mode.Format; - switch(theApp.videoOption) { - case VIDEO_1X: - theApp.surfaceSizeX = theApp.sizeX; - theApp.surfaceSizeY = theApp.sizeY; - break; - case VIDEO_2X: - theApp.surfaceSizeX = theApp.sizeX * 2; - theApp.surfaceSizeY = theApp.sizeY * 2; - break; - case VIDEO_3X: - theApp.surfaceSizeX = theApp.sizeX * 3; - theApp.surfaceSizeY = theApp.sizeY * 3; - break; - case VIDEO_4X: - theApp.surfaceSizeX = theApp.sizeX * 4; - theApp.surfaceSizeY = theApp.sizeY * 4; - break; - case VIDEO_320x240: - case VIDEO_640x480: - case VIDEO_800x600: - case VIDEO_OTHER: - { - RECT r; - ::GetWindowRect(GetDesktopWindow(), &r); - theApp.fsWidth = r.right - r.left; - theApp.fsHeight = r.bottom - r.top; - - /* Need to fix this code later. For now, Fullscreen takes the whole - screen. - int scaleX = (fsWidth / sizeX); - int scaleY = (fsHeight / sizeY); - int min = scaleX < scaleY ? scaleX : scaleY; - surfaceSizeX = sizeX * min; - surfaceSizeY = sizeY * min; - if(fullScreenStretch) { - */ - theApp.surfaceSizeX = theApp.fsWidth; - theApp.surfaceSizeY = theApp.fsHeight; - // } - } - break; - } - - theApp.rect.left = 0; - theApp.rect.top = 0; - theApp.rect.right = theApp.sizeX; - theApp.rect.bottom = theApp.sizeY; - - theApp.dest.left = 0; - theApp.dest.top = 0; - theApp.dest.right = theApp.surfaceSizeX; - theApp.dest.bottom = theApp.surfaceSizeY; - - DWORD style = WS_POPUP | WS_VISIBLE; - DWORD styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) - style |= WS_OVERLAPPEDWINDOW; - else - styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) - AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx); - else - AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx); - - int winSizeX = theApp.dest.right-theApp.dest.left; - int winSizeY = theApp.dest.bottom-theApp.dest.top; - - if(theApp.videoOption > VIDEO_4X) { - winSizeX = theApp.fsWidth; - winSizeY = theApp.fsHeight; - } - - int x = 0; - int y = 0; - - if(theApp.videoOption <= VIDEO_4X) { - x = theApp.windowPositionX; - y = theApp.windowPositionY; - } - - // Create a window - MainWnd *pWnd = new MainWnd; - theApp.m_pMainWnd = pWnd; - - pWnd->CreateEx(styleEx, - theApp.wndClass, - "VisualBoyAdvance", - style, - x,y,winSizeX,winSizeY, - NULL, - 0); - - if (!(HWND)*pWnd) { - winlog("Error creating Window %08x\n", GetLastError()); - return FALSE; - } - - theApp.updateMenuBar(); - - theApp.adjustDestRect(); - - d3dDLL = LoadLibrary("D3D8.DLL"); - LPDIRECT3D8 (WINAPI *D3DCreate)(UINT); - if(d3dDLL != NULL) { - D3DCreate = (LPDIRECT3D8 (WINAPI *)(UINT)) - GetProcAddress(d3dDLL, "Direct3DCreate8"); - - if(D3DCreate == NULL) { - theApp.directXMessage("Direct3DCreate8"); - return FALSE; - } - } else { - theApp.directXMessage("D3D8.DLL"); - return FALSE; - } - - pD3D = D3DCreate(120); - - if(pD3D == NULL) { - winlog("Error creating Direct3D object\n"); - return FALSE; - } - - theApp.mode320Available = FALSE; - theApp.mode640Available = FALSE; - theApp.mode800Available = FALSE; - - D3DDISPLAYMODE mode; - pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); - - switch(mode.Format) { + switch(mode.Format) { case D3DFMT_R8G8B8: - systemColorDepth = 24; - systemRedShift = 19; - systemGreenShift = 11; - systemBlueShift = 3; - break; + systemColorDepth = 24; + systemRedShift = 19; + systemGreenShift = 11; + systemBlueShift = 3; + break; case D3DFMT_X8R8G8B8: - systemColorDepth = 32; - systemRedShift = 19; - systemGreenShift = 11; - systemBlueShift = 3; - Init_2xSaI(32); - break; + systemColorDepth = 32; + systemRedShift = 19; + systemGreenShift = 11; + systemBlueShift = 3; + Init_2xSaI(32); + break; case D3DFMT_R5G6B5: - systemColorDepth = 16; - systemRedShift = 11; - systemGreenShift = 6; - systemBlueShift = 0; - Init_2xSaI(565); - break; + systemColorDepth = 16; + systemRedShift = 11; + systemGreenShift = 6; + systemBlueShift = 0; + Init_2xSaI(565); + break; case D3DFMT_X1R5G5B5: - systemColorDepth = 16; - systemRedShift = 10; - systemGreenShift = 5; - systemBlueShift = 0; - Init_2xSaI(555); - break; + systemColorDepth = 16; + systemRedShift = 10; + systemGreenShift = 5; + systemBlueShift = 0; + Init_2xSaI(555); + break; default: - systemMessage(0,"Unsupport D3D format %d", mode.Format); - return false; - } - theApp.fsColorDepth = systemColorDepth; + DXTRACE_ERR_MSGBOX( _T("Unsupport D3D format"), 0 ); + return false; + } + theApp.fsColorDepth = systemColorDepth; + utilUpdateSystemColorMaps(); + #ifdef MMX - if(!theApp.disableMMX) - cpu_mmx = theApp.detectMMX(); - else - cpu_mmx = 0; + if(!theApp.disableMMX) { + cpu_mmx = theApp.detectMMX(); + } else { + cpu_mmx = 0; + } #endif - - screenFormat = mode.Format; - - // check for available fullscreen modes - ZeroMemory(&dpp, sizeof(dpp)); - dpp.Windowed = TRUE; - dpp.BackBufferFormat = mode.Format; - dpp.BackBufferCount = 1; - dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - dpp.BackBufferWidth = theApp.surfaceSizeX; - dpp.BackBufferHeight = theApp.surfaceSizeY; - - HRESULT hret = pD3D->CreateDevice(D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - pWnd->GetSafeHwnd(), - D3DCREATE_SOFTWARE_VERTEXPROCESSING, - &dpp, - &pDevice); - if(!SUCCEEDED(hret)) { - winlog("Error creating Direct3DDevice %08x\n", hret); - return false; - } - - restoreDeviceObjects(); - - switch(systemColorDepth) { - case 16: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - case 24: - case 32: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - } - - theApp.updateFilter(); - theApp.updateIFB(); - - if(failed) - return false; - - pWnd->DragAcceptFiles(TRUE); - - return TRUE; -} - -bool Direct3DDisplay::initializeOffscreen(int w, int h) -{ - int size = 256; - if(w > 256 || h > 256) - size = 512; - - UINT ww = size; - UINT hh = size; - D3DFORMAT format = screenFormat; - - if(SUCCEEDED(D3DXCheckTextureRequirements(pDevice, - &ww, - &hh, - NULL, - 0, - &format, - D3DPOOL_MANAGED))) { - if((int)ww < w || (int)hh < h) { - if(theApp.filterFunction) { - filterDisabled = true; - theApp.filterFunction = NULL; - systemMessage(0, "3D card cannot support needed texture size for filter function. Disabling it"); - } - } else - filterDisabled = false; - if(SUCCEEDED(D3DXCreateTexture(pDevice, - ww, - hh, - 0, - 0, - format, - D3DPOOL_MANAGED, - &pTexture))) { - width = w; - height = h; - return true; - } - } - return false; -} - -void Direct3DDisplay::updateFiltering(int filter) -{ - switch(filter) { - default: - case 0: - // point filtering - pDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_POINT ); - pDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_POINT ); - pDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT ); - break; - case 1: - // bilinear - pDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ); - pDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); - pDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT ); - break; - } -} - -void Direct3DDisplay::restoreDeviceObjects() -{ - // Store render target surface desc - LPDIRECT3DSURFACE8 pBackBuffer; - HRESULT hr; - if(SUCCEEDED(hr = pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ))) { - pBackBuffer->GetDesc( &dsdBackBuffer ); - pBackBuffer->Release(); - } else - systemMessage(0, "Failed GetBackBuffer %08x", hr); - - // Set up the texture - pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); - pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - - int filter = regQueryDwordValue("d3dFilter", 0); - if(filter < 0 || filter > 3) - filter = 0; - updateFiltering(filter); - - // Set miscellaneous render states - pDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE ); - pDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); - - // Set the projection matrix - D3DXMATRIX matProj; - FLOAT fAspect = ((FLOAT)dsdBackBuffer.Width) / dsdBackBuffer.Height; - D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); - pDevice->SetTransform( D3DTS_PROJECTION, &matProj ); - - // turn off lighting - pDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); - - if(pFont) { - pFont->Release(); - pFont = NULL; - } - // Create a D3D font using D3DX - HFONT hFont = CreateFont( 14, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - ANTIALIASED_QUALITY, FF_DONTCARE, "Arial" ); - D3DXCreateFont( pDevice, hFont, &pFont ); -} - -void Direct3DDisplay::clear() -{ -} - -void Direct3DDisplay::renderMenu() -{ - checkFullScreen(); - if(theApp.m_pMainWnd) - theApp.m_pMainWnd->DrawMenuBar(); -} -void Direct3DDisplay::checkFullScreen() -{ - // if(tripleBuffering) - // pDirect3D->FlipToGDISurface(); -} -static void BlitRect(LPDIRECT3DDEVICE8 lpDevice, - LPDIRECT3DTEXTURE8 lpSrc, - float left, float top, - float right, float bottom, - D3DCOLOR col,float z) -{ - // calculate rhw + theApp.updateFilter(); + theApp.updateIFB(); - float rhw=1.0f/(z*990.0f+10.0f); - // set up rectangle + // create device + ZeroMemory(&dpp, sizeof(dpp)); + dpp.Windowed = TRUE; + dpp.BackBufferFormat = mode.Format; + dpp.BackBufferCount = theApp.tripleBuffering ? 2 : 1; + dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + dpp.BackBufferWidth = 0; // use width of hDeviceWindow + dpp.BackBufferHeight = 0; // use height of hDeviceWindow + dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; + dpp.PresentationInterval = theApp.vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + + HRESULT hret = pD3D->CreateDevice( + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + pWnd->GetSafeHwnd(), + D3DCREATE_SOFTWARE_VERTEXPROCESSING, + &dpp, + &pDevice); + if( FAILED( hret ) ) { + DXTRACE_ERR_MSGBOX( _T("Error creating Direct3D device"), hret ); + return false; + } + + createFont(); + createSurface(); + calculateDestRect(); - D3DTLVERTEX verts[4]; - verts[0]=D3DTLVERTEX(D3DXVECTOR3(left-0.5f, top-0.5f, z),rhw,col,0.0f,0.0f); - verts[1]=D3DTLVERTEX(D3DXVECTOR3(right-0.5f, top-0.5f, z),rhw,col,1.0f,0.0f); - verts[2]=D3DTLVERTEX(D3DXVECTOR3(right-0.5f, bottom-0.5f, z),rhw,col,1.0f,1.0f); - verts[3]=D3DTLVERTEX(D3DXVECTOR3(left-0.5f, bottom-0.5f, z),rhw,col,0.0f,1.0f); + setOption( _T("d3dFilter"), theApp.d3dFilter ); - // set the texture + if(failed) return false; - lpDevice->SetTexture(0,lpSrc); + return TRUE; +} - // configure shader for vertex type - lpDevice->SetVertexShader(D3DFVF_TLVERTEX); +void Direct3DDisplay::renderMenu() +{ + checkFullScreen(); + if(theApp.m_pMainWnd) { + theApp.m_pMainWnd->DrawMenuBar(); + } +} - // draw the rectangle - lpDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,verts,sizeof(D3DTLVERTEX)); +void Direct3DDisplay::clear() +{ + if( pDevice ) { + pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0x00,0x00,0x00), 0.0f, 0 ); + } } + void Direct3DDisplay::render() { - if(!pDevice) - return; - - // Test the cooperative level to see if it's okay to render - if( FAILED( pDevice->TestCooperativeLevel() ) ) - { - return; - } - pDevice->Clear( 0L, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0L ); - - if(SUCCEEDED(pDevice->BeginScene())) { - D3DLOCKED_RECT locked; - if(pTexture && SUCCEEDED(pTexture->LockRect(0, &locked, NULL, 0))) { - if(theApp.filterFunction) { - if(systemColorDepth == 16) - theApp.filterFunction(pix+theApp.filterWidth*2+4, - theApp.filterWidth*2+4, - (u8*)theApp.delta, - (u8*)locked.pBits, - locked.Pitch, - theApp.filterWidth, - theApp.filterHeight); - else - theApp.filterFunction(pix+theApp.filterWidth*4+4, - theApp.filterWidth*4+4, - (u8*)theApp.delta, - (u8*)locked.pBits, - locked.Pitch, - theApp.filterWidth, - theApp.filterHeight); - } else { - int copyX = 240; - int copyY = 160; - - if(theApp.cartridgeType == 1) { - if(gbBorderOn) { - copyX = 256; - copyY = 224; - } else { - copyX = 160; - copyY = 144; - } - } - // MMX doesn't seem to be faster to copy the data - __asm { - mov eax, copyX; - mov ebx, copyY; - - mov esi, pix; - mov edi, locked.pBits; - mov edx, locked.Pitch; - cmp systemColorDepth, 16; - jnz gbaOtherColor; - sub edx, eax; - sub edx, eax; - lea esi,[esi+2*eax+4]; - shr eax, 1; - gbaLoop16bit: - mov ecx, eax; - repz movsd; - inc esi; - inc esi; - inc esi; - inc esi; - add edi, edx; - dec ebx; - jnz gbaLoop16bit; - jmp gbaLoopEnd; - gbaOtherColor: - cmp systemColorDepth, 32; - jnz gbaOtherColor2; - - sub edx, eax; - sub edx, eax; - sub edx, eax; - sub edx, eax; - lea esi, [esi+4*eax+4]; - gbaLoop32bit: - mov ecx, eax; - repz movsd; - add esi, 4; - add edi, edx; - dec ebx; - jnz gbaLoop32bit; - jmp gbaLoopEnd; - gbaOtherColor2: - lea eax, [eax+2*eax]; - sub edx, eax; - gbaLoop24bit: - mov ecx, eax; - shr ecx, 2; - repz movsd; - add edi, edx; - dec ebx; - jnz gbaLoop24bit; - gbaLoopEnd: - } - } - - if(theApp.videoOption > VIDEO_4X && theApp.showSpeed) { - char buffer[30]; - if(theApp.showSpeed == 1) - sprintf(buffer, "%3d%%", systemSpeed); - else - sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed, - systemFrameSkip, - theApp.showRenderedFrames); - if(theApp.showSpeedTransparent) - drawTextTransp((u8*)locked.pBits, - locked.Pitch, - theApp.rect.left+10, - theApp.rect.bottom-10, - buffer); - else - drawText((u8*)locked.pBits, - locked.Pitch, - theApp.rect.left+10, - theApp.rect.bottom-10, - buffer); - } - - pTexture->UnlockRect(0); - - float scaleX = (float)theApp.surfaceSizeX / theApp.sizeX; - float scaleY = (float)theApp.surfaceSizeY / theApp.sizeY; - BlitRect(pDevice, pTexture, 0, 0, scaleX*256, scaleY*256, 0xffffff, 0.1f); - } - - if(theApp.screenMessage) { - if(((GetTickCount() - theApp.screenMessageTime) < 3000) && - !theApp.disableStatusMessage && pFont) { - D3DCOLOR color = D3DCOLOR_ARGB(255, 255, 0, 0); - pFont->Begin(); - RECT r; - r.left = 10; - r.top = dpp.BackBufferHeight - 20; - r.right = dpp.BackBufferWidth - 10; - r.bottom = r.top + 20; - - pFont->DrawText(theApp.screenMessageBuffer, -1, &r, 0, color); - pFont->End(); - } else { - theApp.screenMessage = false; - } - } - - pDevice->EndScene(); - - pDevice->Present( NULL, NULL, NULL, NULL ); - } -} - -void Direct3DDisplay::invalidateDeviceObjects() -{ - if(pFont) - pFont->Release(); - pFont = NULL; -} - -void Direct3DDisplay::resize(int w, int h) -{ - if(pDevice) { - dpp.BackBufferWidth = w; - dpp.BackBufferHeight = h; - HRESULT hr; - invalidateDeviceObjects(); - if(SUCCEEDED(hr = pDevice->Reset(&dpp))) { - restoreDeviceObjects(); - } else - systemMessage(0, "Failed device reset %08x", hr); - } -} - -bool Direct3DDisplay::changeRenderSize(int w, int h) -{ - if(w != width || h != height) { - if(pTexture) { - pTexture->Release(); - pTexture = NULL; - } - if(!initializeOffscreen(w, h)) { - failed = true; - return false; - } - } - if(filterDisabled && theApp.filterFunction) - theApp.filterFunction = NULL; - - return true; -} - -void Direct3DDisplay::setOption(const char *option, int value) -{ - if(!strcmp(option, "d3dFilter")) - updateFiltering(value); -} - -int Direct3DDisplay::selectFullScreenMode(GUID **) -{ - HWND wnd = GetDesktopWindow(); - RECT r; - GetWindowRect(wnd, &r); - int w = (r.right - r.left) & 4095; - int h = (r.bottom - r.top) & 4095; - HDC dc = GetDC(wnd); - int c = GetDeviceCaps(dc, BITSPIXEL); - ReleaseDC(wnd, dc); - - return (c << 24) | (w << 12) | h; + if( failed ) return; + if(!pDevice) return; + if( FAILED( pDevice->TestCooperativeLevel() ) ) return; + + clear(); + + pDevice->BeginScene(); + + // copy pix to emulatedImage and apply pixel filter if selected + HRESULT hr; + D3DLOCKED_RECT lr; + if( FAILED( hr = emulatedImage->LockRect( &lr, NULL, D3DLOCK_DISCARD ) ) ) { + DXTRACE_ERR_MSGBOX( _T("Can not lock back buffer"), hr ); + return; + } else { + if( !theApp.filterFunction ) { + copyImage( pix, lr.pBits, theApp.sizeX, theApp.sizeY, lr.Pitch, systemColorDepth ); + } else { + u32 pitch = theApp.filterWidth * (systemColorDepth>>3) + 4; + theApp.filterFunction( pix + pitch, + pitch, + (u8*)theApp.delta, + (u8*)lr.pBits, + lr.Pitch, + theApp.filterWidth, + theApp.filterHeight); + } + emulatedImage->UnlockRect(); + } + + // copy emulatedImage to pBackBuffer and scale with or without aspect ratio + LPDIRECT3DSURFACE9 pBackBuffer; + pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); + if( theApp.fullScreenStretch ) { + pDevice->StretchRect( emulatedImage, NULL, pBackBuffer, NULL, filter ); + } else { + pDevice->StretchRect( emulatedImage, NULL, pBackBuffer, &destRect, filter ); + } + pBackBuffer->Release(); + pBackBuffer = NULL; + + D3DCOLOR color; + RECT r; + r.left = 4; + r.right = dpp.BackBufferWidth - 4; + + if( theApp.screenMessage ) { + color = theApp.showSpeedTransparent ? D3DCOLOR_ARGB(0x7F, 0xFF, 0x00, 0x00) : D3DCOLOR_ARGB(0xFF, 0xFF, 0x00, 0x00); + if( ( ( GetTickCount() - theApp.screenMessageTime ) < 3000 ) && !theApp.disableStatusMessage && pFont ) { + r.top = dpp.BackBufferHeight - 20; + r.bottom = dpp.BackBufferHeight - 4; + pFont->DrawText( NULL, theApp.screenMessageBuffer, -1, &r, 0, color ); + } else { + theApp.screenMessage = false; + } + } + + if( theApp.showSpeed && ( theApp.videoOption > VIDEO_4X ) ) { + color = theApp.showSpeedTransparent ? D3DCOLOR_ARGB(0x7F, 0x00, 0x00, 0xFF) : D3DCOLOR_ARGB(0xFF, 0x00, 0x00, 0xFF); + char buffer[30]; + if( theApp.showSpeed == 1 ) { + sprintf( buffer, "%3d%%", systemSpeed ); + } else { + sprintf( buffer, "%3d%%(%d, %d fps)", systemSpeed, systemFrameSkip, theApp.showRenderedFrames ); + } + + r.top = 4; + r.bottom = 20; + pFont->DrawText( NULL, buffer, -1, &r, 0, color ); + } + + pDevice->EndScene(); + + pDevice->Present( NULL, NULL, NULL, NULL ); + + return; +} + + +bool Direct3DDisplay::changeRenderSize( int w, int h ) +{ + if( (w != width) || (h != height) ) { + width = w; height = h; + if( pDevice ) { + destroySurface(); + createSurface(); + calculateDestRect(); + } + } + return true; +} + + +void Direct3DDisplay::resize( int w, int h ) +{ + if( (w != dpp.BackBufferWidth) || (h != dpp.BackBufferHeight) ) { + dpp.BackBufferWidth = (UINT)w; + dpp.BackBufferHeight = (UINT)h; + resetDevice(); + calculateDestRect(); + } +} + + +int Direct3DDisplay::selectFullScreenMode( GUID ** ) +{ + HRESULT hr; + D3DDISPLAYMODE dm; + if( FAILED( hr = pDevice->GetDisplayMode( 0, &dm ) ) ) { + DXTRACE_ERR_MSGBOX( _T("pDevice->GetDisplayMode failed"), hr ); + return false; + } + + UINT bitsPerPixel; + switch( dm.Format ) + { + case D3DFMT_A2R10G10B10: + case D3DFMT_X8R8G8B8: + bitsPerPixel = 32; + break; + case D3DFMT_X1R5G5B5: + case D3DFMT_R5G6B5: + bitsPerPixel = 16; + break; + } + + return (bitsPerPixel << 24) | (dm.Width << 12) | dm.Height; +} + + +void Direct3DDisplay::createFont() +{ + if( !pFont ) { + HRESULT hr = D3DXCreateFont( + pDevice, + 14, + 0, + FW_BOLD, + 1, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + DEFAULT_QUALITY, + DEFAULT_PITCH || FF_DONTCARE, + _T("Arial"), + &pFont ); + if( FAILED( hr ) ) { + DXTRACE_ERR_MSGBOX( _T("createFont failed"), hr ); + } + } +} + + +void Direct3DDisplay::destroyFont() +{ + if( pFont ) { + pFont->Release(); + pFont = NULL; + } +} + + +void Direct3DDisplay::createSurface() +{ + if( !emulatedImage ) { + HRESULT hr = pDevice->CreateOffscreenPlainSurface( + width, height, + dpp.BackBufferFormat, + D3DPOOL_DEFAULT, + &emulatedImage, + NULL ); + if( FAILED( hr ) ) { + DXTRACE_ERR_MSGBOX( _T("createSurface failed"), hr ); + } + } +} + + +void Direct3DDisplay::destroySurface() +{ + if( emulatedImage ) { + emulatedImage->Release(); + emulatedImage = NULL; + } +} + + +void Direct3DDisplay::calculateDestRect() +{ + float scaleX = (float)dpp.BackBufferWidth / (float)width; + float scaleY = (float)dpp.BackBufferHeight / (float)height; + float min = (scaleX < scaleY) ? scaleX : scaleY; + if( theApp.fsMaxScale && (min > theApp.fsMaxScale) ) { + min = (float)theApp.fsMaxScale; + } + destRect.left = 0; + destRect.top = 0; + destRect.right = (LONG)(width * min); + destRect.bottom = (LONG)(height * min); + if( destRect.right != dpp.BackBufferWidth ) { + LONG diff = (dpp.BackBufferWidth - destRect.right) / 2; + destRect.left += diff; + destRect.right += diff; + } + if( destRect.bottom != dpp.BackBufferHeight ) { + LONG diff = (dpp.BackBufferHeight - destRect.bottom) / 2; + destRect.top += diff; + destRect.bottom += diff; + } +} + + +void Direct3DDisplay::setOption( const char *option, int value ) +{ + if( !_tcscmp( option, _T("vsync") ) ) { + dpp.PresentationInterval = value ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + resetDevice(); + } + + if( !_tcscmp( option, _T("tripleBuffering") ) ) { + dpp.BackBufferCount = value ? 2 : 1; + resetDevice(); + } + + if( !_tcscmp( option, _T("d3dFilter") ) ) { + switch( value ) + { + case 0: //point + filter = D3DTEXF_POINT; + break; + case 1: //linear + filter = D3DTEXF_LINEAR; + break; + } + } + + if( !_tcscmp( option, _T("maxScale") ) ) { + calculateDestRect(); + } +} + + +bool Direct3DDisplay::resetDevice() +{ + if( !pDevice ) return false; + + HRESULT hr; + destroyFont(); + destroySurface(); + if( FAILED( hr = pDevice->Reset( &dpp ) ) ) { + //DXTRACE_ERR_MSGBOX( _T("pDevice->Reset failed"), hr ); + failed = true; + return false; + } + createFont(); + createSurface(); + failed = false; + return true; } + IDisplay *newDirect3DDisplay() { - return new Direct3DDisplay(); + return new Direct3DDisplay(); } - diff -urN ../VisualBoyAdvance-1.7.2/src/win32/DirectDraw.cpp ./src/win32/DirectDraw.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/DirectDraw.cpp 2004-05-13 23:28:16 +0900 +++ ./src/win32/DirectDraw.cpp 2006-06-07 06:04:21 +0900 @@ -26,12 +26,15 @@ #include "../GBA.h" #include "../Globals.h" #include "../Text.h" +#include "../Util.h" #include "VBA.h" #include "MainWnd.h" #include "Reg.h" #include "resource.h" +#include "Display.h" + #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE @@ -39,7 +42,6 @@ #endif extern int Init_2xSaI(u32); -extern int RGB_LOW_BITS_MASK; extern void winlog(const char *,...); extern int systemSpeed; extern int winVideoModeSelect(CWnd *, GUID **); @@ -153,7 +155,11 @@ } if(ddrawDLL != NULL) { - AfxFreeLibrary(ddrawDLL); +#ifdef _AFXDLL + AfxFreeLibrary( ddrawDLL ); +#else + FreeLibrary( ddrawDLL ); +#endif ddrawDLL = NULL; } width = 0; @@ -265,7 +271,12 @@ if(theApp.pVideoDriverGUID) guid = theApp.pVideoDriverGUID; - ddrawDLL = AfxLoadLibrary("DDRAW.DLL"); +#ifdef _AFXDLL + ddrawDLL = AfxLoadLibrary("ddraw.dll"); +#else + ddrawDLL = LoadLibrary( _T("ddraw.dll") ); +#endif + HRESULT (WINAPI *DDrawCreateEx)(GUID *,LPVOID *,REFIID,IUnknown *); if(ddrawDLL != NULL) { DDrawCreateEx = (HRESULT (WINAPI *)(GUID *,LPVOID *,REFIID,IUnknown *)) @@ -551,26 +562,22 @@ px.dwBBitMask == 0x001F) { systemGreenShift++; Init_2xSaI(565); - RGB_LOW_BITS_MASK=0x821; } else if((px.dwFlags&DDPF_RGB) != 0 && px.dwRBitMask == 0x7C00 && px.dwGBitMask == 0x03E0 && px.dwBBitMask == 0x001F) { Init_2xSaI(555); - RGB_LOW_BITS_MASK=0x421; } else if((px.dwFlags&DDPF_RGB) != 0 && px.dwRBitMask == 0x001F && px.dwGBitMask == 0x07E0 && px.dwBBitMask == 0xF800) { systemGreenShift++; Init_2xSaI(565); - RGB_LOW_BITS_MASK=0x821; } else if((px.dwFlags&DDPF_RGB) != 0 && px.dwRBitMask == 0x001F && px.dwGBitMask == 0x03E0 && px.dwBBitMask == 0x7C00) { Init_2xSaI(555); - RGB_LOW_BITS_MASK=0x421; } else { // 32-bit or 24-bit if(systemColorDepth == 32 || systemColorDepth == 24) { @@ -588,27 +595,7 @@ winlog("B shift: %d\n", systemBlueShift); } - switch(systemColorDepth) { - case 16: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - case 24: - case 32: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - } + utilUpdateSystemColorMaps(); width = w; height = h; return true; @@ -646,16 +633,13 @@ void DirectDrawDisplay::render() { HRESULT hret; + unsigned int nBytesPerPixel = systemColorDepth>>3; if(pDirectDraw == NULL || ddsOffscreen == NULL || ddsPrimary == NULL) return; - if(theApp.vsync && !speedup) { - hret = pDirectDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0); - } - DDSURFACEDESC2 ddsDesc; ZeroMemory(&ddsDesc, sizeof(ddsDesc)); @@ -722,60 +706,7 @@ copyY = 144; } } - // MMX doesn't seem to be faster to copy the data - __asm { - mov eax, copyX; - mov ebx, copyY; - - mov esi, pix; - mov edi, ddsDesc.lpSurface; - mov edx, ddsDesc.lPitch; - cmp systemColorDepth, 16; - jnz gbaOtherColor; - sub edx, eax; - sub edx, eax; - lea esi,[esi+2*eax+4]; - shr eax, 1; - gbaLoop16bit: - mov ecx, eax; - repz movsd; - inc esi; - inc esi; - inc esi; - inc esi; - add edi, edx; - dec ebx; - jnz gbaLoop16bit; - jmp gbaLoopEnd; - gbaOtherColor: - cmp systemColorDepth, 32; - jnz gbaOtherColor2; - - sub edx, eax; - sub edx, eax; - sub edx, eax; - sub edx, eax; - lea esi, [esi+4*eax+4]; - gbaLoop32bit: - mov ecx, eax; - repz movsd; - add esi, 4; - add edi, edx; - dec ebx; - jnz gbaLoop32bit; - jmp gbaLoopEnd; - gbaOtherColor2: - lea eax, [eax+2*eax]; - sub edx, eax; - gbaLoop24bit: - mov ecx, eax; - shr ecx, 2; - repz movsd; - add edi, edx; - dec ebx; - jnz gbaLoop24bit; - gbaLoopEnd: - } + copyImage( pix, ddsDesc.lpSurface, copyX, copyY, ddsDesc.lPitch, systemColorDepth ); } if(theApp.showSpeed && (theApp.videoOption > VIDEO_4X || theApp.skin != NULL)) { char buffer[30]; @@ -804,6 +735,9 @@ hret = ddsOffscreen->Unlock(NULL); if(hret == DD_OK) { + if(theApp.vsync && !(theApp.tripleBuffering && theApp.videoOption > VIDEO_4X) && !speedup) { // isn't the Flip() call synced unless a certain flag is passed to it? + hret = pDirectDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0); + } ddsOffscreen->PageLock(0); if(theApp.tripleBuffering && theApp.videoOption > VIDEO_4X) { hret = ddsFlip->Blt(&theApp.dest, ddsOffscreen, NULL, DDBLT_WAIT, NULL); @@ -844,7 +778,7 @@ SetTextColor(hdc, RGB(255,0,0)); SetBkMode(hdc,TRANSPARENT); TextOut(hdc, theApp.dest.left+10, theApp.dest.bottom - 20, theApp.screenMessageBuffer, - strlen(theApp.screenMessageBuffer)); + (int)_tcslen(theApp.screenMessageBuffer)); ddsPrimary->ReleaseDC(hdc); } else { theApp.screenMessage = false; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/DirectInput.cpp ./src/win32/DirectInput.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/DirectInput.cpp 2004-05-13 23:28:05 +0900 +++ ./src/win32/DirectInput.cpp 2006-08-24 11:08:26 +0900 @@ -1,27 +1,36 @@ -// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. -// Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team - -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or(at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/* + VisualBoyAdvance S - GB & GBA emulator + Copyright (C) 2006 Spacy + + Original VBA Credits: + Copyright (C) 1999-2003 Forgotten + Copyright (C) 2004-2006 VBA development team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ #include "stdafx.h" +#include "VBA.h" +#include "Input.h" #include "Reg.h" #include "WinResUtil.h" -#define DIRECTINPUT_VERSION 0x0500 -#include +#define DIRECTINPUT_VERSION 0x0800 +#include +#pragma comment(lib, "Dinput8") + #ifdef _DEBUG #define new DEBUG_NEW @@ -38,1020 +47,979 @@ #define POV_LEFT 8 class DirectInput : public Input { -private: - HINSTANCE dinputDLL; - public: - virtual void checkDevices(); - DirectInput(); - virtual ~DirectInput(); - - virtual bool initialize(); - virtual bool readDevices(); - virtual u32 readDevice(int which); - virtual CString getKeyName(int key); - virtual void checkKeys(); - virtual void checkMotionKeys(); - virtual void activate(); - virtual void loadSettings(); - virtual void saveSettings(); + virtual void checkDevices(); + DirectInput(); + virtual ~DirectInput(); + + virtual bool initialize(); + virtual bool readDevices(); + virtual u32 readDevice(int which); + virtual CString getKeyName(LONG_PTR key); + virtual void checkKeys(); + virtual void checkMotionKeys(); + virtual void activate(); + virtual void loadSettings(); + virtual void saveSettings(); }; struct deviceInfo { - LPDIRECTINPUTDEVICE device; - BOOL isPolled; - int nButtons; - int nAxes; - int nPovs; - BOOL first; - struct { - DWORD offset; - LONG center; - LONG negative; - LONG positive; - } axis[8]; - int needed; - union { - UCHAR data[256]; - DIJOYSTATE state; - }; + LPDIRECTINPUTDEVICE8 device; + BOOL isPolled; + int nButtons; + int nAxes; + int nPovs; + BOOL first; + struct { + DWORD offset; + LONG center; + LONG negative; + LONG positive; + } axis[8]; + int needed; + union { + UCHAR data[256]; + DIJOYSTATE state; + }; }; static deviceInfo *currentDevice = NULL; static int numDevices = 1; static deviceInfo *pDevices = NULL; -static LPDIRECTINPUT pDirectInput = NULL; -static int joyDebug = 0; +static LPDIRECTINPUT8 pDirectInput = NULL; static int axisNumber = 0; -USHORT joypad[4][13] = { - { - DIK_LEFT, DIK_RIGHT, - DIK_UP, DIK_DOWN, - DIK_Z, DIK_X, - DIK_RETURN,DIK_BACK, - DIK_A, DIK_S, - DIK_SPACE, DIK_F12, - DIK_C - }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } -}; - -USHORT motion[4] = { - DIK_NUMPAD4, DIK_NUMPAD6, DIK_NUMPAD8, DIK_NUMPAD2 -}; +LONG_PTR joypad[4][13] = { + { + DIK_LEFT, DIK_RIGHT, + DIK_UP, DIK_DOWN, + DIK_Z, DIK_X, + DIK_RETURN,DIK_BACK, + DIK_A, DIK_S, + DIK_SPACE, DIK_F12, + DIK_C + }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }; + +LONG_PTR motion[4] = { + DIK_NUMPAD4, DIK_NUMPAD6, DIK_NUMPAD8, DIK_NUMPAD2 + }; static int winReadKey(char *name, int num) { - char buffer[80]; + char buffer[80]; - sprintf(buffer, "Joy%d_%s", num, name); + sprintf(buffer, "Joy%d_%s", num, name); - return regQueryDwordValue(buffer, (DWORD)-1); + return regQueryDwordValue(buffer, (DWORD)-1); } void winReadKeys() { - int key = -1; + int key = -1; - for(int i = 0; i < 4; i++) { - key = winReadKey("Left", i); - if(key != -1) - joypad[i][KEY_LEFT] = key; - key = winReadKey("Right", i); - if(key != -1) - joypad[i][KEY_RIGHT] = key; - key = winReadKey("Up", i); - if(key != -1) - joypad[i][KEY_UP] = key; - key = winReadKey("Down", i); - if(key != -1) - joypad[i][KEY_DOWN] = key; - key = winReadKey("A", i); - if(key != -1) - joypad[i][KEY_BUTTON_A] = key; - key = winReadKey("B", i); - if(key != -1) - joypad[i][KEY_BUTTON_B] = key; - key = winReadKey("L", i); - if(key != -1) - joypad[i][KEY_BUTTON_L] = key; - key = winReadKey("R", i); - if(key != -1) - joypad[i][KEY_BUTTON_R] = key; - key = winReadKey("Start", i); - if(key != -1) - joypad[i][KEY_BUTTON_START] = key; - key = winReadKey("Select", i); - if(key != -1) - joypad[i][KEY_BUTTON_SELECT] = key; - key = winReadKey("Speed", i); - if(key != -1) - joypad[i][KEY_BUTTON_SPEED] = key; - key = winReadKey("Capture", i); - if(key != -1) - joypad[i][KEY_BUTTON_CAPTURE] = key; - key = winReadKey("GS", i); - if(key != -1) - joypad[i][KEY_BUTTON_GS] = key; - } - key = regQueryDwordValue("Motion_Left", (DWORD)-1); - if(key != -1) - motion[KEY_LEFT] = key; - key = regQueryDwordValue("Motion_Right", (DWORD)-1); - if(key != -1) - motion[KEY_RIGHT] = key; - key = regQueryDwordValue("Motion_Up", (DWORD)-1); - if(key != -1) - motion[KEY_UP] = key; - key = regQueryDwordValue("Motion_Down", (DWORD)-1); - if(key != -1) - motion[KEY_DOWN] = key; + for (int i = 0; i < 4; i++) { + key = winReadKey("Left", i); + if (key != -1) + joypad[i][KEY_LEFT] = key; + key = winReadKey("Right", i); + if (key != -1) + joypad[i][KEY_RIGHT] = key; + key = winReadKey("Up", i); + if (key != -1) + joypad[i][KEY_UP] = key; + key = winReadKey("Down", i); + if (key != -1) + joypad[i][KEY_DOWN] = key; + key = winReadKey("A", i); + if (key != -1) + joypad[i][KEY_BUTTON_A] = key; + key = winReadKey("B", i); + if (key != -1) + joypad[i][KEY_BUTTON_B] = key; + key = winReadKey("L", i); + if (key != -1) + joypad[i][KEY_BUTTON_L] = key; + key = winReadKey("R", i); + if (key != -1) + joypad[i][KEY_BUTTON_R] = key; + key = winReadKey("Start", i); + if (key != -1) + joypad[i][KEY_BUTTON_START] = key; + key = winReadKey("Select", i); + if (key != -1) + joypad[i][KEY_BUTTON_SELECT] = key; + key = winReadKey("Speed", i); + if (key != -1) + joypad[i][KEY_BUTTON_SPEED] = key; + key = winReadKey("Capture", i); + if (key != -1) + joypad[i][KEY_BUTTON_CAPTURE] = key; + key = winReadKey("GS", i); + if (key != -1) + joypad[i][KEY_BUTTON_GS] = key; + } + key = regQueryDwordValue("Motion_Left", (DWORD)-1); + if (key != -1) + motion[KEY_LEFT] = key; + key = regQueryDwordValue("Motion_Right", (DWORD)-1); + if (key != -1) + motion[KEY_RIGHT] = key; + key = regQueryDwordValue("Motion_Up", (DWORD)-1); + if (key != -1) + motion[KEY_UP] = key; + key = regQueryDwordValue("Motion_Down", (DWORD)-1); + if (key != -1) + motion[KEY_DOWN] = key; } -static void winSaveKey(char *name, int num, USHORT value) +static void winSaveKey(char *name, int num, LONG_PTR value) { - char buffer[80]; + char buffer[80]; - sprintf(buffer, "Joy%d_%s", num, name); + sprintf(buffer, "Joy%d_%s", num, name); - regSetDwordValue(buffer, value); + regSetDwordValue(buffer, (DWORD)value); } void winSaveKeys() { - for(int i = 0; i < 4; i++) { - winSaveKey("Left", i, joypad[i][KEY_LEFT]); - winSaveKey("Right", i, joypad[i][KEY_RIGHT]); - winSaveKey("Up", i, joypad[i][KEY_UP]); - winSaveKey("Speed", i, joypad[i][KEY_BUTTON_SPEED]); - winSaveKey("Capture", i, joypad[i][KEY_BUTTON_CAPTURE]); - winSaveKey("GS", i, joypad[i][KEY_BUTTON_GS]); - winSaveKey("Down", i, joypad[i][KEY_DOWN]); - winSaveKey("A", i, joypad[i][KEY_BUTTON_A]); - winSaveKey("B", i, joypad[i][KEY_BUTTON_B]); - winSaveKey("L", i, joypad[i][KEY_BUTTON_L]); - winSaveKey("R", i, joypad[i][KEY_BUTTON_R]); - winSaveKey("Start", i, joypad[i][KEY_BUTTON_START]); - winSaveKey("Select", i, joypad[i][KEY_BUTTON_SELECT]); - } - regSetDwordValue("joyVersion", 1); - - regSetDwordValue("Motion_Left", - motion[KEY_LEFT]); - regSetDwordValue("Motion_Right", - motion[KEY_RIGHT]); - regSetDwordValue("Motion_Up", - motion[KEY_UP]); - regSetDwordValue("Motion_Down", - motion[KEY_DOWN]); + for (int i = 0; i < 4; i++) { + winSaveKey("Left", i, joypad[i][KEY_LEFT]); + winSaveKey("Right", i, joypad[i][KEY_RIGHT]); + winSaveKey("Up", i, joypad[i][KEY_UP]); + winSaveKey("Speed", i, joypad[i][KEY_BUTTON_SPEED]); + winSaveKey("Capture", i, joypad[i][KEY_BUTTON_CAPTURE]); + winSaveKey("GS", i, joypad[i][KEY_BUTTON_GS]); + winSaveKey("Down", i, joypad[i][KEY_DOWN]); + winSaveKey("A", i, joypad[i][KEY_BUTTON_A]); + winSaveKey("B", i, joypad[i][KEY_BUTTON_B]); + winSaveKey("L", i, joypad[i][KEY_BUTTON_L]); + winSaveKey("R", i, joypad[i][KEY_BUTTON_R]); + winSaveKey("Start", i, joypad[i][KEY_BUTTON_START]); + winSaveKey("Select", i, joypad[i][KEY_BUTTON_SELECT]); + } + regSetDwordValue("joyVersion", 1); + + regSetDwordValue("Motion_Left", (DWORD)motion[KEY_LEFT]); + regSetDwordValue("Motion_Right", (DWORD)motion[KEY_RIGHT]); + regSetDwordValue("Motion_Up", (DWORD)motion[KEY_UP]); + regSetDwordValue("Motion_Down", (DWORD)motion[KEY_DOWN]); } static BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext ) { - DIPROPRANGE diprg; - diprg.diph.dwSize = sizeof(DIPROPRANGE); - diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); - diprg.diph.dwHow = DIPH_BYOFFSET; - diprg.diph.dwObj = pdidoi->dwOfs; // Specify the enumerated axis - - diprg.lMin = -32768; - diprg.lMax = 32767; - // try to set the range - if(FAILED(currentDevice->device->SetProperty(DIPROP_RANGE, &diprg.diph))) { - // Get the range for the axis - if( FAILED(currentDevice->device-> - GetProperty( DIPROP_RANGE, &diprg.diph ) ) ) { - return DIENUM_STOP; - } - } - - DIPROPDWORD didz; - - didz.diph.dwSize = sizeof(didz); - didz.diph.dwHeaderSize = sizeof(DIPROPHEADER); - didz.diph.dwHow = DIPH_BYOFFSET; - didz.diph.dwObj = pdidoi->dwOfs; - - didz.dwData = 5000; - - currentDevice->device->SetProperty(DIPROP_DEADZONE, &didz.diph); - - LONG center = (diprg.lMin + diprg.lMax)/2; - LONG threshold = (diprg.lMax - center)/2; - - // only 8 axis supported - if(axisNumber < 8) { - currentDevice->axis[axisNumber].center = center; - currentDevice->axis[axisNumber].negative = center - threshold; - currentDevice->axis[axisNumber].positive = center + threshold; - currentDevice->axis[axisNumber].offset = pdidoi->dwOfs; - } - axisNumber++; - return DIENUM_CONTINUE; + DIPROPRANGE diprg; + diprg.diph.dwSize = sizeof(DIPROPRANGE); + diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.diph.dwObj = pdidoi->dwOfs; // Specify the enumerated axis + + diprg.lMin = -32768; + diprg.lMax = 32767; + // try to set the range + if (FAILED(currentDevice->device->SetProperty(DIPROP_RANGE, &diprg.diph))) { + // Get the range for the axis + if ( FAILED(currentDevice->device-> + GetProperty( DIPROP_RANGE, &diprg.diph ) ) ) { + return DIENUM_STOP; + } + } + + DIPROPDWORD didz; + + didz.diph.dwSize = sizeof(didz); + didz.diph.dwHeaderSize = sizeof(DIPROPHEADER); + didz.diph.dwHow = DIPH_BYOFFSET; + didz.diph.dwObj = pdidoi->dwOfs; + + didz.dwData = 5000; + + currentDevice->device->SetProperty(DIPROP_DEADZONE, &didz.diph); + + LONG center = (diprg.lMin + diprg.lMax)/2; + LONG threshold = (diprg.lMax - center)/2; + + // only 8 axis supported + if (axisNumber < 8) { + currentDevice->axis[axisNumber].center = center; + currentDevice->axis[axisNumber].negative = center - threshold; + currentDevice->axis[axisNumber].positive = center + threshold; + currentDevice->axis[axisNumber].offset = pdidoi->dwOfs; + } + axisNumber++; + return DIENUM_CONTINUE; } static BOOL CALLBACK EnumPovsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext ) { - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } static BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE pInst, - LPVOID lpvContext) + LPVOID lpvContext) { - ZeroMemory(&pDevices[numDevices],sizeof(deviceInfo)); - - HRESULT hRet = pDirectInput->CreateDevice(pInst->guidInstance, - &pDevices[numDevices].device, - NULL); - - if(hRet != DI_OK) - return DIENUM_STOP; - - DIDEVCAPS caps; - caps.dwSize=sizeof(DIDEVCAPS); - - hRet = pDevices[numDevices].device->GetCapabilities(&caps); - - if(hRet == DI_OK) { - if(caps.dwFlags & DIDC_POLLEDDATAFORMAT || - caps.dwFlags & DIDC_POLLEDDEVICE) - pDevices[numDevices].isPolled = TRUE; - - pDevices[numDevices].nButtons = caps.dwButtons; - pDevices[numDevices].nAxes = caps.dwAxes; - pDevices[numDevices].nPovs = caps.dwPOVs; - - for(int i = 0; i < 6; i++) { - pDevices[numDevices].axis[i].center = 0x8000; - pDevices[numDevices].axis[i].negative = 0x4000; - pDevices[numDevices].axis[i].positive = 0xc000; - } - } else if(joyDebug) - winlog("Failed to get device capabilities %08x\n", hRet); - - if(joyDebug) { - // don't translate. debug only - winlog("******************************\n"); - winlog("Joystick %2d name : %s\n", numDevices, pInst->tszProductName); - } - - numDevices++; + ZeroMemory(&pDevices[numDevices],sizeof(deviceInfo)); + + HRESULT hRet = pDirectInput->CreateDevice(pInst->guidInstance, + &pDevices[numDevices].device, + NULL); + + if (hRet != DI_OK) + return DIENUM_STOP; + + DIDEVCAPS caps; + caps.dwSize=sizeof(DIDEVCAPS); + + hRet = pDevices[numDevices].device->GetCapabilities(&caps); + + if (hRet == DI_OK) { + if (caps.dwFlags & DIDC_POLLEDDATAFORMAT || + caps.dwFlags & DIDC_POLLEDDEVICE) + pDevices[numDevices].isPolled = TRUE; + + pDevices[numDevices].nButtons = caps.dwButtons; + pDevices[numDevices].nAxes = caps.dwAxes; + pDevices[numDevices].nPovs = caps.dwPOVs; + + for (int i = 0; i < 6; i++) { + pDevices[numDevices].axis[i].center = 0x8000; + pDevices[numDevices].axis[i].negative = 0x4000; + pDevices[numDevices].axis[i].positive = 0xc000; + } + } + + + numDevices++; + - - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } BOOL CALLBACK DIEnumDevicesCallback2(LPCDIDEVICEINSTANCE pInst, LPVOID lpvContext) { - numDevices++; - - return DIENUM_CONTINUE; + numDevices++; + + return DIENUM_CONTINUE; } static int getPovState(DWORD value) { - int state = 0; - if(LOWORD(value) != 0xFFFF) { - if(value < 9000 || value > 27000) - state |= POV_UP; - if(value > 0 && value < 18000) - state |= POV_RIGHT; - if(value > 9000 && value < 27000) - state |= POV_DOWN; - if(value > 18000) - state |= POV_LEFT; - } - return state; + int state = 0; + if (LOWORD(value) != 0xFFFF) { + if (value < 9000 || value > 27000) + state |= POV_UP; + if (value > 0 && value < 18000) + state |= POV_RIGHT; + if (value > 9000 && value < 27000) + state |= POV_DOWN; + if (value > 18000) + state |= POV_LEFT; + } + return state; } static void checkKeys() { - int dev = 0; - int i; + LONG_PTR dev = 0; + int i; - for(i = 0; i < numDevices; i++) - pDevices[i].needed = 0; + for (i = 0; i < numDevices; i++) + pDevices[i].needed = 0; - for(i = 0; i < 4; i++) { - dev = joypad[i][KEY_LEFT] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_LEFT] = DIK_LEFT; - - dev = joypad[i][KEY_RIGHT] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_RIGHT] = DIK_RIGHT; - - dev = joypad[i][KEY_UP] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_UP] = DIK_UP; - - dev = joypad[i][KEY_DOWN] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_DOWN] = DIK_DOWN; - - dev = joypad[i][KEY_BUTTON_A] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_BUTTON_A] = DIK_Z; - - dev = joypad[i][KEY_BUTTON_B] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_BUTTON_B] = DIK_X; - - dev = joypad[i][KEY_BUTTON_L] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_BUTTON_L] = DIK_A; - - dev = joypad[i][KEY_BUTTON_R] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_BUTTON_R] = DIK_S; - - dev = joypad[i][KEY_BUTTON_START] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - joypad[i][KEY_BUTTON_START] = DIK_RETURN; - - dev = joypad[i][KEY_BUTTON_SELECT] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; + for (i = 0; i < 4; i++) { + dev = joypad[i][KEY_LEFT] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_LEFT] = DIK_LEFT; + + dev = joypad[i][KEY_RIGHT] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_RIGHT] = DIK_RIGHT; + + dev = joypad[i][KEY_UP] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_UP] = DIK_UP; + + dev = joypad[i][KEY_DOWN] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_DOWN] = DIK_DOWN; + + dev = joypad[i][KEY_BUTTON_A] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_A] = DIK_Z; + + dev = joypad[i][KEY_BUTTON_B] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_B] = DIK_X; + + dev = joypad[i][KEY_BUTTON_L] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_L] = DIK_A; + + dev = joypad[i][KEY_BUTTON_R] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_R] = DIK_S; + + dev = joypad[i][KEY_BUTTON_START] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_START] = DIK_RETURN; + + dev = joypad[i][KEY_BUTTON_SELECT] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_SELECT] = DIK_BACK; + + dev = joypad[i][KEY_BUTTON_SPEED] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_SPEED] = DIK_SPACE; + + dev = joypad[i][KEY_BUTTON_CAPTURE] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_CAPTURE] = DIK_F12; + + dev = joypad[i][KEY_BUTTON_GS] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; + else + joypad[i][KEY_BUTTON_GS] = DIK_C; + } + + dev = motion[KEY_UP] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; else - joypad[i][KEY_BUTTON_SELECT] = DIK_BACK; - - dev = joypad[i][KEY_BUTTON_SPEED] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; + motion[KEY_UP] = DIK_NUMPAD8; + + dev = motion[KEY_DOWN] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; else - joypad[i][KEY_BUTTON_SPEED] = DIK_SPACE; - - dev = joypad[i][KEY_BUTTON_CAPTURE] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; + motion[KEY_DOWN] = DIK_NUMPAD2; + + dev = motion[KEY_LEFT] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; else - joypad[i][KEY_BUTTON_CAPTURE] = DIK_F12; - - dev = joypad[i][KEY_BUTTON_GS] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; + motion[KEY_LEFT] = DIK_NUMPAD4; + + dev = motion[KEY_RIGHT] >> 8; + if (dev < numDevices && dev >= 0) + pDevices[dev].needed = 1; else - joypad[i][KEY_BUTTON_GS] = DIK_C; - } - - dev = motion[KEY_UP] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - motion[KEY_UP] = DIK_NUMPAD8; - - dev = motion[KEY_DOWN] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - motion[KEY_DOWN] = DIK_NUMPAD2; - - dev = motion[KEY_LEFT] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - motion[KEY_LEFT] = DIK_NUMPAD4; - - dev = motion[KEY_RIGHT] >> 8; - if(dev < numDevices && dev >= 0) - pDevices[dev].needed = 1; - else - motion[KEY_RIGHT] = DIK_NUMPAD6; + motion[KEY_RIGHT] = DIK_NUMPAD6; } #define KEYDOWN(buffer,key) (buffer[key] & 0x80) static bool readKeyboard() { - if(pDevices[0].needed) { - HRESULT hret = pDevices[0].device-> - GetDeviceState(256, - (LPVOID)pDevices[0].data); - - if(hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { - hret = pDevices[0].device->Acquire(); - if(hret != DI_OK) - return false; - hret = pDevices[0].device->GetDeviceState(256,(LPVOID)pDevices[0].data); + if (pDevices[0].needed) { + HRESULT hret = pDevices[0].device-> + GetDeviceState(256, + (LPVOID)pDevices[0].data); + + if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { + hret = pDevices[0].device->Acquire(); + if (hret != DI_OK) + return false; + hret = pDevices[0].device->GetDeviceState(256,(LPVOID)pDevices[0].data); + } + + return hret == DI_OK; } - - return hret == DI_OK; - } - return true; + return true; } static bool readJoystick(int joy) { - if(pDevices[joy].needed) { - if(pDevices[joy].isPolled) - ((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll(); - - HRESULT hret = pDevices[joy].device-> - GetDeviceState(sizeof(DIJOYSTATE), - (LPVOID)&pDevices[joy].state); - - if(hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { - hret = pDevices[joy].device->Acquire(); - - if(hret == DI_OK) { - - if(pDevices[joy].isPolled) - ((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll(); - - hret = pDevices[joy].device-> - GetDeviceState(sizeof(DIJOYSTATE), - (LPVOID)&pDevices[joy].state); - } - } + if (pDevices[joy].needed) { + if (pDevices[joy].isPolled) + ((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll(); + + HRESULT hret = pDevices[joy].device-> + GetDeviceState(sizeof(DIJOYSTATE), + (LPVOID)&pDevices[joy].state); + + if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { + hret = pDevices[joy].device->Acquire(); + + if (hret == DI_OK) { + + if (pDevices[joy].isPolled) + ((LPDIRECTINPUTDEVICE2)pDevices[joy].device)->Poll(); + + hret = pDevices[joy].device-> + GetDeviceState(sizeof(DIJOYSTATE), + (LPVOID)&pDevices[joy].state); + } + } - return hret == DI_OK; - } + return hret == DI_OK; + } - return true; + return true; } static void checkKeyboard() { - HRESULT hret = pDevices[0].device->Acquire(); - hret = pDevices[0].device-> - GetDeviceState(256, - (LPVOID)pDevices[0].data); - - if(hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { - return; - } - - if(hret == DI_OK) { - for(int i = 0; i < 256; i++) { - if(KEYDOWN(pDevices[0].data, i)) { - SendMessage(GetFocus(), JOYCONFIG_MESSAGE,0,i); - break; - } + // mham fix. Patch #1378104 + UCHAR keystate[256]; + HRESULT hret = pDevices[0].device->Acquire(); + + if (pDevices[0].first) { + pDevices[0].device->GetDeviceState(256, (LPVOID)pDevices[0].data); + pDevices[0].first = FALSE; + return; + } + + hret = pDevices[0].device-> + GetDeviceState(256, (LPVOID)keystate); + + if (hret == DIERR_INPUTLOST || hret == DIERR_NOTACQUIRED) { + return; } - } + + if (hret == DI_OK) { + for (int i = 0; i < 256; i++) { + if (keystate[i] == pDevices[0].data[i]) continue; + if (KEYDOWN(keystate, i)) { + SendMessage(GetFocus(), JOYCONFIG_MESSAGE,0,i); + break; + } + } + } + memcpy(pDevices[0].data, keystate, sizeof(UCHAR) * 256); } static void checkJoypads() { - DIDEVICEOBJECTINSTANCE di; + DIDEVICEOBJECTINSTANCE di; - ZeroMemory(&di,sizeof(DIDEVICEOBJECTINSTANCE)); + ZeroMemory(&di,sizeof(DIDEVICEOBJECTINSTANCE)); - di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); + di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); - int i =0; + int i =0; - DIJOYSTATE joystick; - - for(i = 1; i < numDevices; i++) { - HRESULT hret = pDevices[i].device->Acquire(); - - - if(pDevices[i].isPolled) - ((LPDIRECTINPUTDEVICE2)pDevices[i].device)->Poll(); - - hret = pDevices[i].device->GetDeviceState(sizeof(joystick), &joystick); - - int j; - - if(pDevices[i].first) { - memcpy(&pDevices[i].state, &joystick, sizeof(joystick)); - pDevices[i].first = FALSE; - continue; - } - - for(j = 0; j < pDevices[i].nButtons; j++) { - if(((pDevices[i].state.rgbButtons[j] ^ joystick.rgbButtons[j]) - & joystick.rgbButtons[j]) & 0x80) { - HWND focus = GetFocus(); - - SendMessage(focus, JOYCONFIG_MESSAGE, i,j+128); - } - } - - for(j = 0; j < pDevices[i].nAxes && j < 8; j++) { - LONG value = pDevices[i].axis[j].center; - LONG old = 0; - switch(pDevices[i].axis[j].offset) { - case DIJOFS_X: - value = joystick.lX; - old = pDevices[i].state.lX; - break; - case DIJOFS_Y: - value = joystick.lY; - old = pDevices[i].state.lY; - break; - case DIJOFS_Z: - value = joystick.lZ; - old = pDevices[i].state.lZ; - break; - case DIJOFS_RX: - value = joystick.lRx; - old = pDevices[i].state.lRx; - break; - case DIJOFS_RY: - value = joystick.lRy; - old = pDevices[i].state.lRy; - break; - case DIJOFS_RZ: - value = joystick.lRz; - old = pDevices[i].state.lRz; - break; - case DIJOFS_SLIDER(0): - value = joystick.rglSlider[0]; - old = pDevices[i].state.rglSlider[0]; - break; - case DIJOFS_SLIDER(1): - value = joystick.rglSlider[1]; - old = pDevices[i].state.rglSlider[1]; - break; - } - if(value != old) { - if(value < pDevices[i].axis[j].negative) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)); - else if (value > pDevices[i].axis[j].positive) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)+1); - } - } - - for(j = 0;j < 4 && j < pDevices[i].nPovs; j++) { - if(LOWORD(pDevices[i].state.rgdwPOV[j]) != LOWORD(joystick.rgdwPOV[j])) { - int state = getPovState(joystick.rgdwPOV[j]); - - if(state & POV_UP) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x20); - else if(state & POV_DOWN) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x21); - else if(state & POV_RIGHT) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x22); - else if(state & POV_LEFT) - SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x23); - } - } - - memcpy(&pDevices[i].state, &joystick, sizeof(joystick)); - } -} - -BOOL checkKey(int key) -{ - int dev = (key >> 8); - - int k = (key & 255); - - if(dev == 0) { - return KEYDOWN(pDevices[0].data,k); - } else { - if(k < 16) { - int axis = k >> 1; - LONG value = pDevices[dev].axis[axis].center; - switch(pDevices[dev].axis[axis].offset) { - case DIJOFS_X: - value = pDevices[dev].state.lX; - break; - case DIJOFS_Y: - value = pDevices[dev].state.lY; - break; - case DIJOFS_Z: - value = pDevices[dev].state.lZ; - break; - case DIJOFS_RX: - value = pDevices[dev].state.lRx; - break; - case DIJOFS_RY: - value = pDevices[dev].state.lRy; - break; - case DIJOFS_RZ: - value = pDevices[dev].state.lRz; - break; - case DIJOFS_SLIDER(0): - value = pDevices[dev].state.rglSlider[0]; - break; - case DIJOFS_SLIDER(1): - value = pDevices[dev].state.rglSlider[1]; - break; - } - - if(k & 1) - return value > pDevices[dev].axis[axis].positive; - return value < pDevices[dev].axis[axis].negative; - } else if(k < 48) { - int hat = (k >> 2) & 3; - int state = getPovState(pDevices[dev].state.rgdwPOV[hat]); - BOOL res = FALSE; - switch(k & 3) { - case 0: - res = state & POV_UP; - break; - case 1: - res = state & POV_DOWN; - break; - case 2: - res = state & POV_RIGHT; - break; - case 3: - res = state & POV_LEFT; - break; - } - return res; - } else if(k >= 128) { - return pDevices[dev].state.rgbButtons[k-128] & 0x80; - } - } + DIJOYSTATE joystick; - return FALSE; + for (i = 1; i < numDevices; i++) { + HRESULT hret = pDevices[i].device->Acquire(); + + + if (pDevices[i].isPolled) + ((LPDIRECTINPUTDEVICE2)pDevices[i].device)->Poll(); + + hret = pDevices[i].device->GetDeviceState(sizeof(joystick), &joystick); + + int j; + + if (pDevices[i].first) { + memcpy(&pDevices[i].state, &joystick, sizeof(joystick)); + pDevices[i].first = FALSE; + continue; + } + + for (j = 0; j < pDevices[i].nButtons; j++) { + if (((pDevices[i].state.rgbButtons[j] ^ joystick.rgbButtons[j]) + & joystick.rgbButtons[j]) & 0x80) { + HWND focus = GetFocus(); + + SendMessage(focus, JOYCONFIG_MESSAGE, i,j+128); + } + } + + for (j = 0; j < pDevices[i].nAxes && j < 8; j++) { + LONG value = pDevices[i].axis[j].center; + LONG old = 0; + switch (pDevices[i].axis[j].offset) { + case DIJOFS_X: + value = joystick.lX; + old = pDevices[i].state.lX; + break; + case DIJOFS_Y: + value = joystick.lY; + old = pDevices[i].state.lY; + break; + case DIJOFS_Z: + value = joystick.lZ; + old = pDevices[i].state.lZ; + break; + case DIJOFS_RX: + value = joystick.lRx; + old = pDevices[i].state.lRx; + break; + case DIJOFS_RY: + value = joystick.lRy; + old = pDevices[i].state.lRy; + break; + case DIJOFS_RZ: + value = joystick.lRz; + old = pDevices[i].state.lRz; + break; + case DIJOFS_SLIDER(0): + value = joystick.rglSlider[0]; + old = pDevices[i].state.rglSlider[0]; + break; + case DIJOFS_SLIDER(1): + value = joystick.rglSlider[1]; + old = pDevices[i].state.rglSlider[1]; + break; + } + if (value != old) { + if (value < pDevices[i].axis[j].negative) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)); + else if (value > pDevices[i].axis[j].positive) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)+1); + } + } + + for (j = 0;j < 4 && j < pDevices[i].nPovs; j++) { + if (LOWORD(pDevices[i].state.rgdwPOV[j]) != LOWORD(joystick.rgdwPOV[j])) { + int state = getPovState(joystick.rgdwPOV[j]); + + if (state & POV_UP) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x20); + else if (state & POV_DOWN) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x21); + else if (state & POV_RIGHT) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x22); + else if (state & POV_LEFT) + SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x23); + } + } + + memcpy(&pDevices[i].state, &joystick, sizeof(joystick)); + } } -DirectInput::DirectInput() +BOOL checkKey(LONG_PTR key) { - dinputDLL = NULL; + LONG_PTR dev = (key >> 8); + + LONG_PTR k = (key & 255); + + if (dev == 0) { + return KEYDOWN(pDevices[0].data,k); + } else { + if (k < 16) { + LONG_PTR axis = k >> 1; + LONG value = pDevices[dev].axis[axis].center; + switch (pDevices[dev].axis[axis].offset) { + case DIJOFS_X: + value = pDevices[dev].state.lX; + break; + case DIJOFS_Y: + value = pDevices[dev].state.lY; + break; + case DIJOFS_Z: + value = pDevices[dev].state.lZ; + break; + case DIJOFS_RX: + value = pDevices[dev].state.lRx; + break; + case DIJOFS_RY: + value = pDevices[dev].state.lRy; + break; + case DIJOFS_RZ: + value = pDevices[dev].state.lRz; + break; + case DIJOFS_SLIDER(0): + value = pDevices[dev].state.rglSlider[0]; + break; + case DIJOFS_SLIDER(1): + value = pDevices[dev].state.rglSlider[1]; + break; + } + + if (k & 1) + return value > pDevices[dev].axis[axis].positive; + return value < pDevices[dev].axis[axis].negative; + } else if (k < 48) { + LONG_PTR hat = (k >> 2) & 3; + int state = getPovState(pDevices[dev].state.rgdwPOV[hat]); + BOOL res = FALSE; + switch (k & 3) { + case 0: + res = state & POV_UP; + break; + case 1: + res = state & POV_DOWN; + break; + case 2: + res = state & POV_RIGHT; + break; + case 3: + res = state & POV_LEFT; + break; + } + return res; + } else if (k >= 128) { + return pDevices[dev].state.rgbButtons[k-128] & 0x80; + } + } + + return FALSE; } +DirectInput::DirectInput() +{} + DirectInput::~DirectInput() { - saveSettings(); - if(pDirectInput != NULL) { - if(pDevices) { - for(int i = 0; i < numDevices ; i++) { - if(pDevices[i].device) { - pDevices[i].device->Unacquire(); - pDevices[i].device->Release(); - pDevices[i].device = NULL; + saveSettings(); + if (pDirectInput != NULL) { + if (pDevices) { + for (int i = 0; i < numDevices ; i++) { + if (pDevices[i].device) { + pDevices[i].device->Unacquire(); + pDevices[i].device->Release(); + pDevices[i].device = NULL; + } + } + free(pDevices); + pDevices = NULL; } - } - free(pDevices); - pDevices = NULL; - } - - pDirectInput->Release(); - pDirectInput = NULL; - } - - if(dinputDLL) { - AfxFreeLibrary(dinputDLL); - dinputDLL = NULL; - } + + pDirectInput->Release(); + pDirectInput = NULL; + } } + bool DirectInput::initialize() { - joyDebug = GetPrivateProfileInt("config", - "joyDebug", - 0, - "VBA.ini"); - dinputDLL = AfxLoadLibrary("DINPUT.DLL"); - HRESULT (WINAPI *DInputCreate)(HINSTANCE,DWORD,LPDIRECTINPUT *,IUnknown *); - if(dinputDLL != NULL) { - DInputCreate = (HRESULT (WINAPI *)(HINSTANCE,DWORD,LPDIRECTINPUT *,IUnknown *)) - GetProcAddress(dinputDLL, "DirectInputCreateA"); - - if(DInputCreate == NULL) { - directXMessage("DirectInputCreateA"); - return false; - } - } else { - directXMessage("DINPUT.DLL"); - return false; - } - - HRESULT hret = DInputCreate(AfxGetInstanceHandle(), - DIRECTINPUT_VERSION, - &pDirectInput, - NULL); - if(hret != DI_OK) { - // errorMessage(myLoadString(IDS_ERROR_DISP_CREATE), hret); - return false; - } - hret = pDirectInput->EnumDevices(DIDEVTYPE_JOYSTICK, + HRESULT hr; + + hr = DirectInput8Create( + AfxGetInstanceHandle(), + DIRECTINPUT_VERSION, + IID_IDirectInput8, + (LPVOID*)&pDirectInput, + NULL ); + + if ( hr != DI_OK ) { + return false; + } + + + + + hr = pDirectInput->EnumDevices(DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback2, NULL, DIEDFL_ATTACHEDONLY); - - - pDevices = (deviceInfo *)calloc(numDevices, sizeof(deviceInfo)); - - hret = pDirectInput->CreateDevice(GUID_SysKeyboard,&pDevices[0].device,NULL); - pDevices[0].isPolled = false; - pDevices[0].needed = true; - - if(hret != DI_OK) { - // errorMessage(myLoadString(IDS_ERROR_DISP_CREATEDEVICE), hret); - return false; - } - - numDevices = 1; - hret = pDirectInput->EnumDevices(DIDEVTYPE_JOYSTICK, + pDevices = (deviceInfo *)calloc(numDevices, sizeof(deviceInfo)); + + hr = pDirectInput->CreateDevice(GUID_SysKeyboard,&pDevices[0].device,NULL); + pDevices[0].isPolled = false; + pDevices[0].needed = true; + pDevices[0].first = true; + + if (hr != DI_OK) { + return false; + } + + + numDevices = 1; + + hr = pDirectInput->EnumDevices(DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, NULL, - DIEDFL_ATTACHEDONLY); + DIEDFL_ATTACHEDONLY); + + + if (hr != DI_OK) { + return false; + } + + hr = pDevices[0].device->SetDataFormat(&c_dfDIKeyboard); + + if (hr != DI_OK) { + return false; + } + + int i; + for (i = 1; i < numDevices; i++) { + pDevices[i].device->SetDataFormat(&c_dfDIJoystick); + pDevices[i].needed = false; + pDevices[i].first = true; + currentDevice = &pDevices[i]; + axisNumber = 0; + currentDevice->device->EnumObjects(EnumAxesCallback, NULL, DIDFT_AXIS); + currentDevice->device->EnumObjects(EnumPovsCallback, NULL, DIDFT_POV); + + + currentDevice = NULL; + } - // hret = pDevices[0].device->SetCooperativeLevel(hWindow, - // DISCL_FOREGROUND| - // DISCL_NONEXCLUSIVE); - - if(hret != DI_OK) { - // errorMessage(myLoadString(IDS_ERROR_DISP_LEVEL), hret); - return false; - } - - hret = pDevices[0].device->SetDataFormat(&c_dfDIKeyboard); - - if(hret != DI_OK) { - // errorMessage(myLoadString(IDS_ERROR_DISP_DATAFORMAT), hret); - return false; - } - - for(int i = 1; i < numDevices; i++) { - pDevices[i].device->SetDataFormat(&c_dfDIJoystick); - pDevices[i].needed = false; - currentDevice = &pDevices[i]; - axisNumber = 0; - currentDevice->device->EnumObjects(EnumAxesCallback, NULL, DIDFT_AXIS); - currentDevice->device->EnumObjects(EnumPovsCallback, NULL, DIDFT_POV); - if(joyDebug) { - // don't translate. debug only - winlog("Joystick %2d polled : %d\n", i, currentDevice->isPolled); - winlog("Joystick %2d buttons : %d\n", i, currentDevice->nButtons); - winlog("Joystick %2d povs : %d\n", i, currentDevice->nPovs); - winlog("Joystick %2d axes : %d\n", i, currentDevice->nAxes); - for(int j = 0; j < currentDevice->nAxes; j++) { - winlog("Axis %2d offset : %08lx\n", j, currentDevice->axis[j]. - offset); - winlog("Axis %2d center : %08lx\n", j, currentDevice->axis[j]. - center); - winlog("Axis %2d negative : %08lx\n", j, currentDevice->axis[j]. - negative); - winlog("Axis %2d positive : %08lx\n", j, currentDevice->axis[j]. - positive); - } - } - - currentDevice = NULL; - } - - for(i = 0; i < numDevices; i++) - pDevices[i].device->Acquire(); - - return true; + for (i = 0; i < numDevices; i++) + pDevices[i].device->Acquire(); + + return true; } bool DirectInput::readDevices() { - bool ok = true; - for(int i = 0; i < numDevices; i++) { - if(pDevices[i].needed) { - if(i) { - ok = readJoystick(i); - } else - ok = readKeyboard(); + bool ok = true; + for (int i = 0; i < numDevices; i++) { + if (pDevices[i].needed) { + if (i) { + ok = readJoystick(i); + } else + ok = readKeyboard(); + } } - } - return ok; + return ok; } u32 DirectInput::readDevice(int which) { - u32 res = 0; - int i = theApp.joypadDefault; - if(which >= 0 && which <= 3) - i = which; - - if(checkKey(joypad[i][KEY_BUTTON_A])) - res |= 1; - if(checkKey(joypad[i][KEY_BUTTON_B])) - res |= 2; - if(checkKey(joypad[i][KEY_BUTTON_SELECT])) - res |= 4; - if(checkKey(joypad[i][KEY_BUTTON_START])) - res |= 8; - if(checkKey(joypad[i][KEY_RIGHT])) - res |= 16; - if(checkKey(joypad[i][KEY_LEFT])) - res |= 32; - if(checkKey(joypad[i][KEY_UP])) - res |= 64; - if(checkKey(joypad[i][KEY_DOWN])) - res |= 128; - if(checkKey(joypad[i][KEY_BUTTON_R])) - res |= 256; - if(checkKey(joypad[i][KEY_BUTTON_L])) - res |= 512; - - if(checkKey(joypad[i][KEY_BUTTON_GS])) - res |= 4096; - - res |= theApp.skinButtons; - if(theApp.autoFire) { - res &= (~theApp.autoFire); - if(theApp.autoFireToggle) - res |= theApp.autoFire; - theApp.autoFireToggle = !theApp.autoFireToggle; - } - - // disallow L+R or U+D of being pressed at the same time - if((res & 48) == 48) - res &= ~16; - if((res & 192) == 192) - res &= ~128; - - if(theApp.movieRecording) { - if(i == theApp.joypadDefault) { - if(res != theApp.movieLastJoypad) { - fwrite(&theApp.movieFrame, 1, sizeof(theApp.movieFrame), theApp.movieFile); - fwrite(&res, 1, sizeof(res), theApp.movieFile); - theApp.movieLastJoypad = res; - } - } - } - if(theApp.moviePlaying) { - if(theApp.movieFrame == theApp.moviePlayFrame) { - theApp.movieLastJoypad = theApp.movieNextJoypad; - theApp.movieReadNext(); - } - res = theApp.movieLastJoypad; - } - // we don't record speed up or screen capture buttons - if(checkKey(joypad[i][KEY_BUTTON_SPEED]) || theApp.speedupToggle) - res |= 1024; - if(checkKey(joypad[i][KEY_BUTTON_CAPTURE])) - res |= 2048; - - return res; -} - -CString DirectInput::getKeyName(int key) -{ - int d = (key >> 8); - int k = key & 255; - - DIDEVICEOBJECTINSTANCE di; - - ZeroMemory(&di,sizeof(DIDEVICEOBJECTINSTANCE)); - - di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); - - CString winBuffer = winResLoadString(IDS_ERROR); - - if(d == 0) { - pDevices[0].device->GetObjectInfo(&di,key,DIPH_BYOFFSET); - winBuffer = di.tszName; - } else { - if(k < 16) { - if(k < 4) { - switch(k) { - case 0: - winBuffer.Format(winResLoadString(IDS_JOY_LEFT), d); - break; - case 1: - winBuffer.Format(winResLoadString(IDS_JOY_RIGHT), d); - break; - case 2: - winBuffer.Format(winResLoadString(IDS_JOY_UP), d); - break; - case 3: - winBuffer.Format(winResLoadString(IDS_JOY_DOWN), d); - break; + u32 res = 0; + int i = theApp.joypadDefault; + if (which >= 0 && which <= 3) + i = which; + + if (checkKey(joypad[i][KEY_BUTTON_A])) + res |= 1; + if (checkKey(joypad[i][KEY_BUTTON_B])) + res |= 2; + if (checkKey(joypad[i][KEY_BUTTON_SELECT])) + res |= 4; + if (checkKey(joypad[i][KEY_BUTTON_START])) + res |= 8; + if (checkKey(joypad[i][KEY_RIGHT])) + res |= 16; + if (checkKey(joypad[i][KEY_LEFT])) + res |= 32; + if (checkKey(joypad[i][KEY_UP])) + res |= 64; + if (checkKey(joypad[i][KEY_DOWN])) + res |= 128; + if (checkKey(joypad[i][KEY_BUTTON_R])) + res |= 256; + if (checkKey(joypad[i][KEY_BUTTON_L])) + res |= 512; + + if (checkKey(joypad[i][KEY_BUTTON_GS])) + res |= 4096; + + if (theApp.autoFire) { + res &= (~theApp.autoFire); + if (theApp.autoFireToggle) + res |= theApp.autoFire; + theApp.autoFireToggle = !theApp.autoFireToggle; + } + + // disallow L+R or U+D of being pressed at the same time + if ((res & 48) == 48) + res &= ~16; + if ((res & 192) == 192) + res &= ~128; + + if (theApp.movieRecording) { + if (i == theApp.joypadDefault) { + if (res != theApp.movieLastJoypad) { + fwrite(&theApp.movieFrame, 1, sizeof(theApp.movieFrame), theApp.movieFile); + fwrite(&res, 1, sizeof(res), theApp.movieFile); + theApp.movieLastJoypad = res; + } } - } else { - pDevices[d].device->GetObjectInfo(&di, - pDevices[d].axis[k>>1].offset, - DIPH_BYOFFSET); - if(k & 1) - winBuffer.Format("Joy %d %s +", d, di.tszName); - else - winBuffer.Format("Joy %d %s -", d, di.tszName); - } - } else if(k < 48) { - int hat = (k >> 2) & 3; - pDevices[d].device->GetObjectInfo(&di, - DIJOFS_POV(hat), - DIPH_BYOFFSET); - char *dir = "up"; - int dd = k & 3; - if(dd == 1) - dir = "down"; - else if(dd == 2) - dir = "right"; - else if(dd == 3) - dir = "left"; - winBuffer.Format("Joy %d %s %s", d, di.tszName, dir); + } + if (theApp.moviePlaying) { + if (theApp.movieFrame == theApp.moviePlayFrame) { + theApp.movieLastJoypad = theApp.movieNextJoypad; + theApp.movieReadNext(); + } + res = theApp.movieLastJoypad; + } + // we don't record speed up or screen capture buttons + if (checkKey(joypad[i][KEY_BUTTON_SPEED]) || theApp.speedupToggle) + res |= 1024; + if (checkKey(joypad[i][KEY_BUTTON_CAPTURE])) + res |= 2048; + + return res; +} + +CString DirectInput::getKeyName(LONG_PTR key) +{ + LONG_PTR d = (key >> 8); + LONG_PTR k = key & 255; + + DIDEVICEOBJECTINSTANCE di; + + ZeroMemory(&di,sizeof(DIDEVICEOBJECTINSTANCE)); + + di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); + + CString winBuffer = winResLoadString(IDS_ERROR); + + if (d == 0) { + pDevices[0].device->GetObjectInfo( &di, (DWORD)key, DIPH_BYOFFSET ); + winBuffer = di.tszName; } else { - pDevices[d].device->GetObjectInfo(&di, - DIJOFS_BUTTON(k-128), - DIPH_BYOFFSET); - winBuffer.Format(winResLoadString(IDS_JOY_BUTTON),d,di.tszName); + if (k < 16) { + if (k < 4) { + switch (k) { + case 0: + winBuffer.Format(winResLoadString(IDS_JOY_LEFT), d); + break; + case 1: + winBuffer.Format(winResLoadString(IDS_JOY_RIGHT), d); + break; + case 2: + winBuffer.Format(winResLoadString(IDS_JOY_UP), d); + break; + case 3: + winBuffer.Format(winResLoadString(IDS_JOY_DOWN), d); + break; + } + } else { + pDevices[d].device->GetObjectInfo(&di, + pDevices[d].axis[k>>1].offset, + DIPH_BYOFFSET); + if (k & 1) + winBuffer.Format("Joy %d %s +", d, di.tszName); + else + winBuffer.Format("Joy %d %s -", d, di.tszName); + } + } else if (k < 48) { + LONG_PTR hat = (k >> 2) & 3; + pDevices[d].device->GetObjectInfo(&di, + (DWORD)DIJOFS_POV(hat), + DIPH_BYOFFSET); + char *dir = "up"; + LONG_PTR dd = k & 3; + if (dd == 1) + dir = "down"; + else if (dd == 2) + dir = "right"; + else if (dd == 3) + dir = "left"; + winBuffer.Format("Joy %d %s %s", d, di.tszName, dir); + } else { + pDevices[d].device->GetObjectInfo(&di, + (DWORD)DIJOFS_BUTTON(k-128), + DIPH_BYOFFSET); + winBuffer.Format(winResLoadString(IDS_JOY_BUTTON),d,di.tszName); + } } - } - return winBuffer; + return winBuffer; } void DirectInput::checkKeys() { - ::checkKeys(); + ::checkKeys(); } void DirectInput::checkMotionKeys() { - if(checkKey(motion[KEY_LEFT])) { - theApp.sensorX += 3; - if(theApp.sensorX > 2197) - theApp.sensorX = 2197; - if(theApp.sensorX < 2047) - theApp.sensorX = 2057; - } else if(checkKey(motion[KEY_RIGHT])) { - theApp.sensorX -= 3; - if(theApp.sensorX < 1897) - theApp.sensorX = 1897; - if(theApp.sensorX > 2047) - theApp.sensorX = 2037; - } else if(theApp.sensorX > 2047) { - theApp.sensorX -= 2; - if(theApp.sensorX < 2047) - theApp.sensorX = 2047; - } else { - theApp.sensorX += 2; - if(theApp.sensorX > 2047) - theApp.sensorX = 2047; - } - - if(checkKey(motion[KEY_UP])) { - theApp.sensorY += 3; - if(theApp.sensorY > 2197) - theApp.sensorY = 2197; - if(theApp.sensorY < 2047) - theApp.sensorY = 2057; - } else if(checkKey(motion[KEY_DOWN])) { - theApp.sensorY -= 3; - if(theApp.sensorY < 1897) - theApp.sensorY = 1897; - if(theApp.sensorY > 2047) - theApp.sensorY = 2037; - } else if(theApp.sensorY > 2047) { - theApp.sensorY -= 2; - if(theApp.sensorY < 2047) - theApp.sensorY = 2047; - } else { - theApp.sensorY += 2; - if(theApp.sensorY > 2047) - theApp.sensorY = 2047; - } + if (checkKey(motion[KEY_LEFT])) { + theApp.sensorX += 3; + if (theApp.sensorX > 2197) + theApp.sensorX = 2197; + if (theApp.sensorX < 2047) + theApp.sensorX = 2057; + } else if (checkKey(motion[KEY_RIGHT])) { + theApp.sensorX -= 3; + if (theApp.sensorX < 1897) + theApp.sensorX = 1897; + if (theApp.sensorX > 2047) + theApp.sensorX = 2037; + } else if (theApp.sensorX > 2047) { + theApp.sensorX -= 2; + if (theApp.sensorX < 2047) + theApp.sensorX = 2047; + } else { + theApp.sensorX += 2; + if (theApp.sensorX > 2047) + theApp.sensorX = 2047; + } + + if (checkKey(motion[KEY_UP])) { + theApp.sensorY += 3; + if (theApp.sensorY > 2197) + theApp.sensorY = 2197; + if (theApp.sensorY < 2047) + theApp.sensorY = 2057; + } else if (checkKey(motion[KEY_DOWN])) { + theApp.sensorY -= 3; + if (theApp.sensorY < 1897) + theApp.sensorY = 1897; + if (theApp.sensorY > 2047) + theApp.sensorY = 2037; + } else if (theApp.sensorY > 2047) { + theApp.sensorY -= 2; + if (theApp.sensorY < 2047) + theApp.sensorY = 2047; + } else { + theApp.sensorY += 2; + if (theApp.sensorY > 2047) + theApp.sensorY = 2047; + } } Input *newDirectInput() { - return new DirectInput; + return new DirectInput; } void DirectInput::checkDevices() { - checkJoypads(); - checkKeyboard(); + checkJoypads(); + checkKeyboard(); } void DirectInput::activate() { - for(int i = 0; i < numDevices; i++) { - if(pDevices != NULL && pDevices[i].device != NULL) - pDevices[i].device->Acquire(); - } + for (int i = 0; i < numDevices; i++) { + if (pDevices != NULL && pDevices[i].device != NULL) + pDevices[i].device->Acquire(); + } } void DirectInput::loadSettings() { - winReadKeys(); + winReadKeys(); } void DirectInput::saveSettings() { - winSaveKeys(); + winSaveKeys(); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/DirectSound.cpp ./src/win32/DirectSound.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/DirectSound.cpp 2004-05-13 23:27:55 +0900 +++ ./src/win32/DirectSound.cpp 2006-08-26 01:11:43 +0900 @@ -1,6 +1,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -16,358 +17,357 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// MFC #include "stdafx.h" -#include "VBA.h" + +// Tools #include "AVIWrite.h" -#include "Sound.h" #include "WavWriter.h" +// Internals #include "../System.h" #include "../GBA.h" #include "../Globals.h" #include "../Sound.h" -#include -#include +// DirectSound8 +#include +#pragma comment( lib, "Dsound" ) +#pragma comment( lib, "Dxguid" ) + class DirectSound : public ISound { private: - HINSTANCE dsoundDLL; - LPDIRECTSOUND pDirectSound; - LPDIRECTSOUNDBUFFER dsbPrimary; - LPDIRECTSOUNDBUFFER dsbSecondary; - LPDIRECTSOUNDNOTIFY dsbNotify; - HANDLE dsbEvent; - WAVEFORMATEX wfx; + LPDIRECTSOUND8 pDirectSound; // DirectSound interface + LPDIRECTSOUNDBUFFER dsbPrimary; // Primary DirectSound buffer + LPDIRECTSOUNDBUFFER dsbSecondary; // Secondary DirectSound buffer + LPDIRECTSOUNDNOTIFY8 dsbNotify; + HANDLE dsbEvent; + WAVEFORMATEX wfx; // Primary buffer wave format public: - DirectSound(); - virtual ~DirectSound(); + DirectSound(); + virtual ~DirectSound(); - bool init(); - void pause(); - void reset(); - void resume(); - void write(); + bool init(); // initialize the primary and secondary sound buffer + void pause(); // pause the secondary sound buffer + void reset(); // stop and reset the secondary sound buffer + void resume(); // resume the secondary sound buffer + void write(); // write the emulated sound to the secondary sound buffer }; + DirectSound::DirectSound() { - dsoundDLL = NULL; - pDirectSound = NULL; - dsbPrimary = NULL; - dsbSecondary = NULL; - dsbNotify = NULL; - dsbEvent = NULL; + CoInitialize( NULL ); + + pDirectSound = NULL; + dsbPrimary = NULL; + dsbSecondary = NULL; + dsbNotify = NULL; + dsbEvent = NULL; } + DirectSound::~DirectSound() { - if(theApp.aviRecorder != NULL) { - delete theApp.aviRecorder; - theApp.aviRecorder = NULL; - theApp.aviFrameNumber = 0; - } - - if(theApp.soundRecording) { - if(theApp.soundRecorder != NULL) { - delete theApp.soundRecorder; - theApp.soundRecorder = NULL; - } - theApp.soundRecording = false; - } - - if(dsbNotify != NULL) { - dsbNotify->Release(); - dsbNotify = NULL; - } - - if(dsbEvent != NULL) { - CloseHandle(dsbEvent); - dsbEvent = NULL; - } - - if(pDirectSound != NULL) { - if(dsbPrimary != NULL) { - dsbPrimary->Release(); - dsbPrimary = NULL; - } - - if(dsbSecondary != NULL) { - dsbSecondary->Release(); - dsbSecondary = NULL; - } - - pDirectSound->Release(); - pDirectSound = NULL; - } - - if(dsoundDLL != NULL) { - FreeLibrary(dsoundDLL); - dsoundDLL = NULL; - } + if(theApp.aviRecorder) { + delete theApp.aviRecorder; + theApp.aviRecorder = NULL; + theApp.aviFrameNumber = 0; + } + + if(theApp.soundRecording) { + if(theApp.soundRecorder) { + delete theApp.soundRecorder; + theApp.soundRecorder = NULL; + } + theApp.soundRecording = false; + } + + if(dsbNotify) { + dsbNotify->Release(); + dsbNotify = NULL; + } + + if(dsbEvent) { + CloseHandle(dsbEvent); + dsbEvent = NULL; + } + + if(pDirectSound) { + if(dsbPrimary) { + dsbPrimary->Release(); + dsbPrimary = NULL; + } + + if(dsbSecondary) { + dsbSecondary->Release(); + dsbSecondary = NULL; + } + + pDirectSound->Release(); + pDirectSound = NULL; + } + + CoUninitialize(); } + bool DirectSound::init() { - HRESULT hr; - - dsoundDLL = LoadLibrary("DSOUND.DLL"); - HRESULT (WINAPI *DSoundCreate)(LPCGUID,LPDIRECTSOUND *,IUnknown *); - if(dsoundDLL != NULL) { - DSoundCreate = (HRESULT (WINAPI *)(LPCGUID,LPDIRECTSOUND *,IUnknown *)) - GetProcAddress(dsoundDLL, "DirectSoundCreate"); - - if(DSoundCreate == NULL) { - theApp.directXMessage("DirectSoundCreate"); - return false; - } - } else { - theApp.directXMessage("DSOUND.DLL"); - return false; - } - - if((hr = DSoundCreate(NULL,&pDirectSound,NULL) != DS_OK)) { - // errorMessage(myLoadString(IDS_ERROR_SOUND_CREATE), hr); - systemMessage(IDS_CANNOT_CREATE_DIRECTSOUND, - "Cannot create DirectSound %08x", hr); - pDirectSound = NULL; - dsbSecondary = NULL; - return false; - } - - if((hr=pDirectSound->SetCooperativeLevel((HWND)*theApp.m_pMainWnd, - DSSCL_EXCLUSIVE)) != DS_OK) { - // errorMessage(myLoadString(IDS_ERROR_SOUND_LEVEL), hr); - systemMessage(IDS_CANNOT_SETCOOPERATIVELEVEL, - "Cannot SetCooperativeLevel %08x", hr); - return false; - } - - DSBUFFERDESC dsbdesc; - ZeroMemory(&dsbdesc,sizeof(DSBUFFERDESC)); - dsbdesc.dwSize=sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; - - if((hr=pDirectSound->CreateSoundBuffer(&dsbdesc, - &dsbPrimary, - NULL) != DS_OK)) { - // errorMessage(myLoadString(IDS_ERROR_SOUND_BUFFER),hr); - systemMessage(IDS_CANNOT_CREATESOUNDBUFFER, - "Cannot CreateSoundBuffer %08x", hr); - return false; - } - - // Set primary buffer format - - memset(&wfx, 0, sizeof(WAVEFORMATEX)); - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nChannels = 2; - switch(soundQuality) { - case 2: - wfx.nSamplesPerSec = 22050; - soundBufferLen = 736*2; - soundBufferTotalLen = 7360*2; - break; - case 4: - wfx.nSamplesPerSec = 11025; - soundBufferLen = 368*2; - soundBufferTotalLen = 3680*2; - break; - default: - soundQuality = 1; - wfx.nSamplesPerSec = 44100; - soundBufferLen = 1470*2; - soundBufferTotalLen = 14700*2; - } - wfx.wBitsPerSample = 16; - wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels; - wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; - - if((hr = dsbPrimary->SetFormat(&wfx)) != DS_OK) { - // errorMessage(myLoadString(IDS_ERROR_SOUND_PRIMARY),hr); - systemMessage(IDS_CANNOT_SETFORMAT_PRIMARY, - "Cannot SetFormat for primary %08x", hr); - return false; - } - - ZeroMemory(&dsbdesc,sizeof(DSBUFFERDESC)); - dsbdesc.dwSize = sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY; - dsbdesc.dwBufferBytes = soundBufferTotalLen; - dsbdesc.lpwfxFormat = &wfx; - - if((hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL)) - != DS_OK) { - dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2; - if((hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL)) - != DS_OK) { - systemMessage(IDS_CANNOT_CREATESOUNDBUFFER_SEC, - "Cannot CreateSoundBuffer secondary %08x", hr); - return false; - } - } - - dsbSecondary->SetCurrentPosition(0); - - if(!theApp.useOldSync) { - hr = dsbSecondary->QueryInterface(IID_IDirectSoundNotify, - (void **)&dsbNotify); - if(!FAILED(hr)) { - dsbEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - - DSBPOSITIONNOTIFY notify[10]; - - for(int i = 0; i < 10; i++) { - notify[i].dwOffset = i*soundBufferLen; - notify[i].hEventNotify = dsbEvent; - } - if(FAILED(dsbNotify->SetNotificationPositions(10, notify))) { - dsbNotify->Release(); - dsbNotify = NULL; - CloseHandle(dsbEvent); - dsbEvent = NULL; - } - } - } - - hr = dsbPrimary->Play(0,0,DSBPLAY_LOOPING); - - if(hr != DS_OK) { - // errorMessage(myLoadString(IDS_ERROR_SOUND_PLAYPRIM), hr); - systemMessage(IDS_CANNOT_PLAY_PRIMARY, "Cannot Play primary %08x", hr); - return false; - } - - systemSoundOn = true; - - return true; + HRESULT hr; + DWORD freq; + DSBUFFERDESC dsbdesc; + int i; + + + // Initialize DirectSound + if( FAILED( hr = DirectSoundCreate8( &DSDEVID_DefaultPlayback, &pDirectSound, NULL ) ) ) { + systemMessage( IDS_CANNOT_CREATE_DIRECTSOUND, _T("Cannot create DirectSound %08x"), hr ); + pDirectSound = NULL; + return false; + } + + + if( FAILED( hr = pDirectSound->SetCooperativeLevel( theApp.m_pMainWnd->GetSafeHwnd(), DSSCL_EXCLUSIVE ) ) ) { + systemMessage( IDS_CANNOT_SETCOOPERATIVELEVEL, _T("Cannot SetCooperativeLevel %08x"), hr ); + return false; + } + + + // Create primary sound buffer + ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) ); + dsbdesc.dwSize = sizeof(DSBUFFERDESC); + dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + if( theApp.dsoundDisableHardwareAcceleration ) { + dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE; + } + + if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbPrimary, NULL ) ) ) { + systemMessage(IDS_CANNOT_CREATESOUNDBUFFER, _T("Cannot CreateSoundBuffer %08x"), hr); + return false; + } + + switch(soundQuality) + { + case 4: + freq = 11025; + break; + case 2: + freq = 22050; + break; + default: + soundQuality = 1; + case 1: + freq = 44100; + break; + } + soundBufferLen = freq*2/30; + soundBufferTotalLen = soundBufferLen * 10; + + ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nChannels = 2; + wfx.nSamplesPerSec = freq; + wfx.wBitsPerSample = 16; + wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8; + wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; + + if( FAILED( hr = dsbPrimary->SetFormat( &wfx ) ) ) { + systemMessage( IDS_CANNOT_SETFORMAT_PRIMARY, _T("CreateSoundBuffer(primary) failed %08x"), hr ); + return false; + } + + + // Create secondary sound buffer + ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) ); + dsbdesc.dwSize = sizeof(DSBUFFERDESC); + dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GLOBALFOCUS; + if( theApp.dsoundDisableHardwareAcceleration ) { + dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE; + } + dsbdesc.dwBufferBytes = soundBufferTotalLen; + dsbdesc.lpwfxFormat = &wfx; + + if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbSecondary, NULL ) ) ) { + systemMessage( IDS_CANNOT_CREATESOUNDBUFFER, _T("CreateSoundBuffer(secondary) failed %08x"), hr ); + return false; + } + + if( FAILED( hr = dsbSecondary->SetCurrentPosition( 0 ) ) ) { + systemMessage( 0, _T("dsbSecondary->SetCurrentPosition failed %08x"), hr ); + return false; + } + + + if( !theApp.useOldSync ) { + if( FAILED( hr = dsbSecondary->QueryInterface( IID_IDirectSoundNotify8, (LPVOID*)&dsbNotify ) ) ) { + dsbEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + DSBPOSITIONNOTIFY notify[10]; + for( i = 0; i < 10; i++ ) { + notify[i].dwOffset = i * soundBufferLen; + notify[i].hEventNotify = dsbEvent; + } + + if( FAILED( dsbNotify->SetNotificationPositions( 10, notify ) ) ) { + dsbNotify->Release(); + dsbNotify = NULL; + CloseHandle(dsbEvent); + dsbEvent = NULL; + } + } + } + + + // Play primary buffer + if( FAILED( hr = dsbPrimary->Play( 0, 0, DSBPLAY_LOOPING ) ) ) { + systemMessage( IDS_CANNOT_PLAY_PRIMARY, _T("Cannot Play primary %08x"), hr ); + return false; + } + + systemSoundOn = true; + + return true; } + void DirectSound::pause() { - if(dsbSecondary != NULL) { - DWORD status = 0; - dsbSecondary->GetStatus(&status); - - if(status & DSBSTATUS_PLAYING) { - dsbSecondary->Stop(); - } - } + if( dsbSecondary == NULL ) return; + + DWORD status; + + dsbSecondary->GetStatus( &status ); + + if( status & DSBSTATUS_PLAYING ) dsbSecondary->Stop(); } + void DirectSound::reset() { - if(dsbSecondary) { - dsbSecondary->Stop(); - dsbSecondary->SetCurrentPosition(0); - } + if( dsbSecondary == NULL ) return; + + dsbSecondary->Stop(); + + dsbSecondary->SetCurrentPosition( 0 ); } + void DirectSound::resume() { - if(dsbSecondary != NULL) { - dsbSecondary->Play(0,0,DSBPLAY_LOOPING); - } + if( dsbSecondary == NULL ) return; + + dsbSecondary->Play( 0, 0, DSBPLAY_LOOPING ); } + void DirectSound::write() { - int len = soundBufferLen; - LPVOID lpvPtr1; - DWORD dwBytes1; - LPVOID lpvPtr2; - DWORD dwBytes2; - - if(!pDirectSound) - return; - - if(theApp.soundRecording) { - if(dsbSecondary) { - if(theApp.soundRecorder == NULL) { - theApp.soundRecorder = new WavWriter; - WAVEFORMATEX format; - dsbSecondary->GetFormat(&format, sizeof(format), NULL); - if(theApp.soundRecorder->Open(theApp.soundRecordName)) - theApp.soundRecorder->SetFormat(&format); - } - } - - if(theApp.soundRecorder) { - theApp.soundRecorder->AddSound((u8 *)soundFinalWave, len); - } - } - - if(theApp.aviRecording) { - if(theApp.aviRecorder) { - if(dsbSecondary) { - if(!theApp.aviRecorder->IsSoundAdded()) { - WAVEFORMATEX format; - dsbSecondary->GetFormat(&format, sizeof(format), NULL); - theApp.aviRecorder->SetSoundFormat(&format); - } - } - - theApp.aviRecorder->AddSound((const char *)soundFinalWave, len); - } - } - - HRESULT hr; - - if(!speedup && synchronize && !theApp.throttle) { - DWORD status=0; - hr = dsbSecondary->GetStatus(&status); - if(status && DSBSTATUS_PLAYING) { - if(!soundPaused) { - DWORD play; - while(true) { - dsbSecondary->GetCurrentPosition(&play, NULL); - - if(play < soundNextPosition || - play > soundNextPosition+soundBufferLen) { - break; - } - - if(dsbEvent) { - WaitForSingleObject(dsbEvent, 50); - } - } - } - } else { - soundPaused = 1; - } - } - // Obtain memory address of write block. This will be in two parts - // if the block wraps around. - hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen, &lpvPtr1, - &dwBytes1, &lpvPtr2, &dwBytes2, - 0); - - // If DSERR_BUFFERLOST is returned, restore and retry lock. - if (DSERR_BUFFERLOST == hr) { - dsbSecondary->Restore(); - hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen,&lpvPtr1, - &dwBytes1, &lpvPtr2, &dwBytes2, - 0); - } - - soundNextPosition += soundBufferLen; - soundNextPosition = soundNextPosition % soundBufferTotalLen; - - if SUCCEEDED(hr) { - // Write to pointers. - CopyMemory(lpvPtr1, soundFinalWave, dwBytes1); - if (NULL != lpvPtr2) { - CopyMemory(lpvPtr2, soundFinalWave+dwBytes1, dwBytes2); - } - // Release the data back to DirectSound. - hr = dsbSecondary->Unlock(lpvPtr1, dwBytes1, lpvPtr2, - dwBytes2); - } + if(!pDirectSound) return; + + + HRESULT hr; + DWORD status = 0; + DWORD play = 0; + WAVEFORMATEX format; + LPVOID lpvPtr1; + DWORD dwBytes1 = 0; + LPVOID lpvPtr2; + DWORD dwBytes2 = 0; + + + if( theApp.soundRecording ) { + if( dsbSecondary ) { + if( theApp.soundRecorder ) { + theApp.soundRecorder->AddSound( (u8 *)soundFinalWave, soundBufferLen ); + } else { + theApp.soundRecorder = new WavWriter; + dsbSecondary->GetFormat( &format, sizeof(format), NULL ); + if( theApp.soundRecorder->Open( theApp.soundRecordName ) ) { + theApp.soundRecorder->SetFormat( &format ); + } + } + } + } + + + if( theApp.aviRecording ) { + if( theApp.aviRecorder ) { + if( dsbSecondary ) { + if( !theApp.aviRecorder->IsSoundAdded() ) { + dsbSecondary->GetFormat( &format, sizeof(format), NULL ); + theApp.aviRecorder->SetSoundFormat( &format ); + } + } + theApp.aviRecorder->AddSound( (const char *)soundFinalWave, soundBufferLen ); + } + } + + + if( !speedup && synchronize && !theApp.throttle ) { + hr = dsbSecondary->GetStatus(&status); + if( status & DSBSTATUS_PLAYING ) { + if( !soundPaused ) { + while( true ) { + dsbSecondary->GetCurrentPosition(&play, NULL); + if( ( play < soundNextPosition ) || ( play > (soundNextPosition + soundBufferLen) ) ) { + break; + } + if( dsbEvent ) { + WaitForSingleObject(dsbEvent, 50); + } + } + } + } else { + soundPaused = 1; + } + } + + + // Obtain memory address of write block. + // This will be in two parts if the block wraps around. + if( DSERR_BUFFERLOST == ( hr = dsbSecondary->Lock( + soundNextPosition, + soundBufferLen, + &lpvPtr1, + &dwBytes1, + &lpvPtr2, + &dwBytes2, + 0 ) ) ) { + // If DSERR_BUFFERLOST is returned, restore and retry lock. + dsbSecondary->Restore(); + hr = dsbSecondary->Lock( + soundNextPosition, + soundBufferLen, + &lpvPtr1, + &dwBytes1, + &lpvPtr2, + &dwBytes2, + 0 ); + } + + soundNextPosition += soundBufferLen; + soundNextPosition = soundNextPosition % soundBufferTotalLen; + + if( SUCCEEDED( hr ) ) { + // Write to pointers. + CopyMemory( lpvPtr1, soundFinalWave, dwBytes1 ); + if ( lpvPtr2 ) { + CopyMemory( lpvPtr2, soundFinalWave + dwBytes1, dwBytes2 ); + } + + // Release the data back to DirectSound. + hr = dsbSecondary->Unlock( lpvPtr1, dwBytes1, lpvPtr2, dwBytes2 ); + } else { + systemMessage( 0, _T("dsbSecondary->Lock() failed: %08x"), hr ); + return; + } } + ISound *newDirectSound() { - return new DirectSound(); + return new DirectSound(); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Directories.cpp ./src/win32/Directories.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Directories.cpp 2004-05-13 23:27:43 +0900 +++ ./src/win32/Directories.cpp 2006-08-04 20:24:24 +0900 @@ -26,6 +26,7 @@ #include "WinResUtil.h" #include +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -54,27 +55,21 @@ Directories::Directories(CWnd* pParent /*=NULL*/) : CDialog(Directories::IDD, pParent) { - //{{AFX_DATA_INIT(Directories) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT } void Directories::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(Directories) DDX_Control(pDX, IDC_SAVE_PATH, m_savePath); DDX_Control(pDX, IDC_ROM_PATH, m_romPath); DDX_Control(pDX, IDC_GBROM_PATH, m_gbromPath); DDX_Control(pDX, IDC_CAPTURE_PATH, m_capturePath); DDX_Control(pDX, IDC_BATTERY_PATH, m_batteryPath); - //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(Directories, CDialog) - //{{AFX_MSG_MAP(Directories) ON_BN_CLICKED(IDC_BATTERY_DIR, OnBatteryDir) ON_BN_CLICKED(IDC_BATTERY_DIR_RESET, OnBatteryDirReset) ON_BN_CLICKED(IDC_CAPTURE_DIR, OnCaptureDir) @@ -85,8 +80,7 @@ ON_BN_CLICKED(IDC_ROM_DIR_RESET, OnRomDirReset) ON_BN_CLICKED(IDC_SAVE_DIR, OnSaveDir) ON_BN_CLICKED(IDC_SAVE_DIR_RESET, OnSaveDirReset) - //}}AFX_MSG_MAP - END_MESSAGE_MAP() +END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Directories message handlers @@ -206,23 +200,76 @@ void Directories::OnOK() { - CString buffer; - m_romPath.GetWindowText(buffer); - if(!buffer.IsEmpty()) - regSetStringValue("romdir", buffer); - m_gbromPath.GetWindowText(buffer); - if(!buffer.IsEmpty()) - regSetStringValue("gbromdir", buffer); - m_batteryPath.GetWindowText(buffer); - if(!buffer.IsEmpty()) - regSetStringValue("batteryDir", buffer); - m_savePath.GetWindowText(buffer); - if(!buffer.IsEmpty()) - regSetStringValue("saveDir", buffer); - m_capturePath.GetWindowText(buffer); - if(!buffer.IsEmpty()) - regSetStringValue("captureDir", buffer); - EndDialog(TRUE); + char baseDir[MAX_PATH+1]; + char temp[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + + + CString buffer; + + m_romPath.GetWindowText(buffer); + if( !buffer.IsEmpty() ) + regSetStringValue( "romdir", buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); + + m_gbromPath.GetWindowText(buffer); + if( !buffer.IsEmpty() ) + regSetStringValue( "gbromdir", buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); + + m_batteryPath.GetWindowText(buffer); + if( !buffer.IsEmpty() ) + regSetStringValue( "batteryDir", buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); + + m_savePath.GetWindowText(buffer); + if( !buffer.IsEmpty() ) + regSetStringValue( "saveDir", buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); + + m_capturePath.GetWindowText(buffer); + if( !buffer.IsEmpty() ) + regSetStringValue( "captureDir", buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); + + EndDialog(TRUE); } CString Directories::browseForDir(CString title) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Directories.h ./src/win32/Directories.h --- ../VisualBoyAdvance-1.7.2/src/win32/Directories.h 2004-05-13 22:46:19 +0900 +++ ./src/win32/Directories.h 2006-08-04 20:24:24 +0900 @@ -75,7 +75,24 @@ virtual void OnOK(); //}}AFX_MSG DECLARE_MESSAGE_MAP() - }; +private: + + bool directoryDoesExist(const char *directory) + { // returns true if the directory does exist + HANDLE hDir; + hDir = CreateFile( + directory, + GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL ); + bool retval = (hDir == INVALID_HANDLE_VALUE) ? false : true; + CloseHandle( hDir ); + return retval; + } +}; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Disassemble.cpp ./src/win32/Disassemble.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Disassemble.cpp 2004-05-13 23:27:30 +0900 +++ ./src/win32/Disassemble.cpp 2005-06-25 15:23:31 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -118,6 +118,7 @@ void Disassemble::OnArm() { mode = 1; + address&=0xfffffffC; refresh(); } @@ -133,21 +134,30 @@ CString buffer; m_address.GetWindowText(buffer); sscanf(buffer, "%x", &address); + if (mode==1) + address&=0xfffffffc; + else if (mode==2) + address&=0xfffffffe; refresh(); } void Disassemble::OnGopc() { + if(rom != NULL) + { if(armState) address = armNextPC - 16; else address = armNextPC - 8; refresh(); + } } void Disassemble::OnNext() { + if(rom != NULL) + { CPULoop(1); if(armState) { u32 total = address+count*4; @@ -163,6 +173,7 @@ } } refresh(); + } } void Disassemble::OnRefresh() @@ -173,6 +184,7 @@ void Disassemble::OnThumb() { mode = 2; + address&=0xfffffffe; refresh(); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Display.h ./src/win32/Display.h --- ../VisualBoyAdvance-1.7.2/src/win32/Display.h 2004-05-13 22:45:59 +0900 +++ ./src/win32/Display.h 2006-08-06 02:29:31 +0900 @@ -17,6 +17,8 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#pragma once + enum DISPLAY_TYPE { GDI = 0, DIRECT_DRAW = 1, @@ -32,13 +34,15 @@ virtual bool initialize() = 0; virtual void cleanup() = 0; virtual void render() = 0; - virtual void checkFullScreen() { }; - virtual void renderMenu() { }; - virtual void clear()=0; + virtual void checkFullScreen() {}; + virtual void renderMenu() {}; + virtual void clear() = 0; virtual bool changeRenderSize(int w, int h) { return true; }; virtual void resize(int w, int h) {}; - virtual void setOption(const char *option, int value) = 0; + virtual void setOption(const char *option, int value) {}; virtual DISPLAY_TYPE getType() = 0; virtual bool isSkinSupported() { return false; } virtual int selectFullScreenMode(GUID **) = 0; }; + +void copyImage( void *source, void *destination, unsigned int width, unsigned int height, unsigned int destinationPitch, unsigned int colorDepth ); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/FileDlg.cpp ./src/win32/FileDlg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/FileDlg.cpp 2004-05-13 23:27:04 +0900 +++ ./src/win32/FileDlg.cpp 2006-05-27 23:47:33 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ // FileDlg.cpp: implementation of the FileDlg class. // -////////////////////////////////////////////////////////////////////// + #include "stdafx.h" #include #include @@ -159,20 +159,23 @@ ASSERT(typeControl != NULL); - int sel = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); + LRESULT sel = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); ASSERT(sel != -1); LPCTSTR typeName = extensions[sel]; if(filename.GetLength() == 0) { - filename.Format("*%s", typeName); + if(strlen(typeName) != 0) + filename.Format("*%s", typeName); } else { - int index = filename.Find('.'); - if (index == -1) { - filename = filename + typeName; - } else { - filename = filename.Left(index) + typeName; + if(strlen(typeName) != 0) { + int index = filename.Find('.'); + if (index == -1) { + filename = filename + typeName; + } else { + filename = filename.Left(index) + typeName; + } } } SetWindowText(fileNameControl, filename); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBACheats.cpp ./src/win32/GBACheats.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBACheats.cpp 2004-05-13 23:26:53 +0900 +++ ./src/win32/GBACheats.cpp 2006-05-27 23:47:33 +0900 @@ -684,7 +684,7 @@ break; } - cheatsAdd(code, buffer,address, value,-1, sizeType); + cheatsAdd(code, buffer, address ,address, value,-1, sizeType); return true; } ///////////////////////////////////////////////////////////////////////////// @@ -765,16 +765,16 @@ if(mark != -1) { LVITEM item; for(int i = 0; i < count; i++) { - memset(&item,0, sizeof(item)); + memset(&item, 0, sizeof(item)); item.mask = LVIF_PARAM|LVIF_STATE; item.stateMask = LVIS_SELECTED; item.iItem = i; if(m_list.GetItem(&item)) { if(item.state & LVIS_SELECTED) { if(cheatsList[item.lParam].enabled) - cheatsDisable(item.lParam); + cheatsDisable((int)(item.lParam & 0xFFFFFFFF)); else - cheatsEnable(item.lParam); + cheatsEnable((int)(item.lParam & 0xFFFFFFFF)); } } } @@ -796,7 +796,7 @@ item.stateMask = LVIS_SELECTED; if(m_list.GetItem(&item)) { if(item.state & LVIS_SELECTED) { - cheatsDelete(item.lParam, restoreValues); + cheatsDelete((int)(item.lParam & 0xFFFFFFFF), restoreValues); } } } @@ -838,9 +838,9 @@ if(((l->uOldState & LVIS_STATEIMAGEMASK)>>12) != (((l->uNewState & LVIS_STATEIMAGEMASK)>>12))) { if(m_list.GetCheck(l->iItem)) - cheatsEnable(l->lParam); + cheatsEnable((int)(l->lParam & 0xFFFFFFFF)); else - cheatsDisable(l->lParam); + cheatsDisable((int)(l->lParam & 0xFFFFFFFF)); refresh(); } } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBACheats.h ./src/win32/GBACheats.h --- ../VisualBoyAdvance-1.7.2/src/win32/GBACheats.h 2004-05-13 22:45:27 +0900 +++ ./src/win32/GBACheats.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_GBACHEATS_H__FC31D47D_52C8_42B2_95C7_7C3FD09316A4__INCLUDED_) #define AFX_GBACHEATS_H__FC31D47D_52C8_42B2_95C7_7C3FD09316A4__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBCheatsDlg.cpp ./src/win32/GBCheatsDlg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBCheatsDlg.cpp 2004-05-13 23:26:36 +0900 +++ ./src/win32/GBCheatsDlg.cpp 2006-06-07 06:04:21 +0900 @@ -637,7 +637,7 @@ m_desc.GetWindowText(buffer); - int bank = (address >> 16); + LONG_PTR bank = (address >> 16); address &= 0xFFFF; if(address >= 0xd000) @@ -689,9 +689,7 @@ buffer.Format("%02x:%08x", (address>>16), address&0xFFFF); m_address.SetWindowText(buffer); m_address.EnableWindow(FALSE); - ::SetWindowLong(m_address, - GWL_USERDATA, - address); + ::SetWindowLongPtr( m_address.GetSafeHwnd(), GWLP_USERDATA, address); numberType = regQueryDwordValue("gbCheatsNumberType", 2); if(numberType < 0 || numberType > 2) @@ -826,9 +824,9 @@ item.iItem = mark; if(m_list.GetItem(&item)) { if(gbCheatList[item.lParam].enabled) - gbCheatDisable(item.lParam); + gbCheatDisable((int)item.lParam); else - gbCheatEnable(item.lParam); + gbCheatEnable((int)item.lParam); refresh(); } } @@ -844,7 +842,7 @@ item.mask = LVIF_PARAM; item.iItem = mark; if(m_list.GetItem(&item)) { - gbCheatRemove(item.lParam); + gbCheatRemove((int)item.lParam); refresh(); } } @@ -872,9 +870,9 @@ if(((l->uOldState & LVIS_STATEIMAGEMASK)>>12) != (((l->uNewState & LVIS_STATEIMAGEMASK)>>12))) { if(m_list.GetCheck(l->iItem)) - gbCheatEnable(l->lParam); + gbCheatEnable((int)l->lParam); else - gbCheatDisable(l->lParam); + gbCheatDisable((int)l->lParam); refresh(); } } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBCheatsDlg.h ./src/win32/GBCheatsDlg.h --- ../VisualBoyAdvance-1.7.2/src/win32/GBCheatsDlg.h 2004-05-13 22:45:12 +0900 +++ ./src/win32/GBCheatsDlg.h 2006-06-07 06:04:21 +0900 @@ -121,7 +121,7 @@ // Implementation protected: - u32 address; + LONG_PTR address; // Generated message map functions //{{AFX_MSG(AddGBCheat) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBColorDlg.cpp ./src/win32/GBColorDlg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBColorDlg.cpp 2004-05-13 23:26:06 +0900 +++ ./src/win32/GBColorDlg.cpp 2006-05-27 23:47:33 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -32,28 +32,31 @@ static u16 defaultPalettes[][24] = { { - 0x7FFF, 0x56B5, 0x318C, 0x0000, 0x7FFF, 0x56B5, 0x318C, 0x0000, + 0x7FFF, 0x56B5, 0x318C, 0x0000, 0x7FFF, 0x56B5, 0x318C, 0x0000, }, { - 0x6200, 0x7E10, 0x7C10, 0x5000, 0x6200, 0x7E10, 0x7C10, 0x5000, + 0x6200, 0x7E10, 0x7C10, 0x5000, 0x6200, 0x7E10, 0x7C10, 0x5000, }, { - 0x4008, 0x4000, 0x2000, 0x2008, 0x4008, 0x4000, 0x2000, 0x2008, + 0x4008, 0x4000, 0x2000, 0x2008, 0x4008, 0x4000, 0x2000, 0x2008, }, { - 0x43F0, 0x03E0, 0x4200, 0x2200, 0x43F0, 0x03E0, 0x4200, 0x2200, + 0x43F0, 0x03E0, 0x4200, 0x2200, 0x43F0, 0x03E0, 0x4200, 0x2200, }, { - 0x43FF, 0x03FF, 0x221F, 0x021F, 0x43FF, 0x03FF, 0x221F, 0x021F, + 0x43FF, 0x03FF, 0x221F, 0x021F, 0x43FF, 0x03FF, 0x221F, 0x021F, }, { - 0x621F, 0x7E1F, 0x7C1F, 0x2010, 0x621F, 0x7E1F, 0x7C1F, 0x2010, + 0x621F, 0x7E1F, 0x7C1F, 0x2010, 0x621F, 0x7E1F, 0x7C1F, 0x2010, }, { - 0x621F, 0x401F, 0x001F, 0x2010, 0x621F, 0x401F, 0x001F, 0x2010, + 0x621F, 0x401F, 0x001F, 0x2010, 0x621F, 0x401F, 0x001F, 0x2010, }, { - 0x421F, 0x03E0, 0x7C00, 0x401F, 0x021F, 0x2200, 0x4008, 0x2010, + 0x1B8E, 0x02C0, 0x0DA0, 0x1140, 0x1B8E, 0x02C0, 0x0DA0, 0x1140, + }, + { + 0x7BDE, /*0x23F0*/ 0x5778, /*0x5DC0*/ 0x5640, 0x0000, 0x7BDE, /*0x3678*/ 0x529C, /*0x0980*/ 0x2990, 0x0000, } }; @@ -70,20 +73,15 @@ GBColorDlg::GBColorDlg(CWnd* pParent /*=NULL*/) : CDialog(GBColorDlg::IDD, pParent) { - //{{AFX_DATA_INIT(GBColorDlg) - which = -1; - //}}AFX_DATA_INIT which = gbPaletteOption; } void GBColorDlg::DoDataExchange(CDataExchange* pDX) { - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(GBColorDlg) + CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_PREDEFINED, m_predefined); - DDX_Radio(pDX, IDC_DEFAULT, which); - //}}AFX_DATA_MAP + DDX_Radio(pDX, IDC_DEFAULT, which); } @@ -95,8 +93,8 @@ ON_BN_CLICKED(IDC_USER2, OnUser2) ON_BN_CLICKED(ID_OK, OnOk) ON_BN_CLICKED(ID_CANCEL, OnCancel) - ON_CBN_SELCHANGE(IDC_PREDEFINED, OnSelchangePredefined) - //}}AFX_MSG_MAP + ON_CBN_SELCHANGE(IDC_PREDEFINED, OnSelchangePredefined) + //}}AFX_MSG_MAP ON_CONTROL_RANGE(BN_CLICKED, IDC_COLOR_BG0, IDC_COLOR_OB3, OnColorClicked) END_MESSAGE_MAP() @@ -167,10 +165,12 @@ "Green Forest", "Hot Desert", "Pink Dreams", - "Weird Colors" + "Weird Colors", + "Real GB Colors", + "Real 'GB on GBASP' Colors" }; - for(int j = 0; j < 7; j++) { + for(int j = 0; j < 9; j++) { int index = m_predefined.AddString(names[j]); m_predefined.SetItemData(index, j); } @@ -222,15 +222,20 @@ { id -= IDC_COLOR_BG0; - u16 color = colors[id]; + u16 color = colors[which*8+id]; + + COLORREF colorInit = + RGB((color & 0x1f) << 3, ((color >> 5) & 0x1f) << 3, ((color >> 10) & 0x1f) << 3); - CColorDialog dlg(RGB(color & 0x1f, (color >> 5) & 0x1f, (color >> 10) & 0x1f), + CColorDialog dlg(colorInit, CC_FULLOPEN | CC_ANYCOLOR, this); - if(dlg.DoModal()) { + + if(IDOK == dlg.DoModal()) + { COLORREF c = dlg.GetColor(); - colors[which*8+id] = (u16)((c >> 3) & 0x1f | ((c >> 11) & 0x1f) << 5 | - ((c >> 19) & 0x1f) << 10); + colors[which*8+id] = (u16)((c >> 3) & 0x1f | ((c >> 11) & 0x1f) << 5 | ((c >> 19) & 0x1f) << 10); + colorControls[id].setColor(colors[which*8+id]); } } @@ -246,7 +251,7 @@ int sel = m_predefined.GetCurSel(); if(sel != -1) { - int data = m_predefined.GetItemData(sel); + DWORD_PTR data = m_predefined.GetItemData(sel); for(int i = 0; i < 8; i++) { colorControls[i].setColor(defaultPalettes[data][i]); colors[which*8+i] = defaultPalettes[data][i]; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBColorDlg.h ./src/win32/GBColorDlg.h --- ../VisualBoyAdvance-1.7.2/src/win32/GBColorDlg.h 2004-05-13 22:45:01 +0900 +++ ./src/win32/GBColorDlg.h 2006-05-27 23:47:33 +0900 @@ -21,7 +21,7 @@ #define AFX_GBCOLORDLG_H__8D6126EF_06BB_48CF_ABB3_2CC4B1B60358__INCLUDED_ #include "ColorButton.h" // Added by ClassView -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBDisassemble.cpp ./src/win32/GBDisassemble.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBDisassemble.cpp 2004-05-13 23:25:55 +0900 +++ ./src/win32/GBDisassemble.cpp 2006-01-05 00:10:33 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -39,6 +39,7 @@ extern gbRegister HL; extern gbRegister SP; extern gbRegister PC; +extern u8 register_LY; extern u16 IFF; extern int gbDis(char *, u16); @@ -114,8 +115,9 @@ void GBDisassemble::OnGo() { CString buffer; + m_address.GetWindowText(buffer); - sscanf(buffer, "%x", &address); + sscanf(buffer, "%hx", &address); refresh(); } @@ -242,6 +244,8 @@ GetDlgItem(IDC_R5)->SetWindowText(buffer); sprintf(buffer, "%04x", IFF); GetDlgItem(IDC_R6)->SetWindowText(buffer); + sprintf(buffer, "%04x", register_LY); + GetDlgItem(IDC_LY)->SetWindowText(buffer); m_z = (AF.B.B0 & 0x80) != 0; m_n = (AF.B.B0 & 0x40) != 0; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBDisassemble.h ./src/win32/GBDisassemble.h --- ../VisualBoyAdvance-1.7.2/src/win32/GBDisassemble.h 2004-05-13 22:44:47 +0900 +++ ./src/win32/GBDisassemble.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_GBDISASSEMBLE_H__3EFD5B47_6DBF_4F63_8F91_A9511EC590EB__INCLUDED_) #define AFX_GBDISASSEMBLE_H__3EFD5B47_6DBF_4F63_8F91_A9511EC590EB__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBMapView.cpp ./src/win32/GBMapView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBMapView.cpp 2004-05-13 23:25:45 +0900 +++ ./src/win32/GBMapView.cpp 2006-06-07 06:04:21 +0900 @@ -499,8 +499,8 @@ u8 *colors = (u8 *)lParam; mapViewZoom.setColors(colors); - int x = wParam & 0xffff; - int y = (wParam >> 16); + int x = (int)(wParam & 0xffff); + int y = (int)(wParam >> 16); CString buffer; buffer.Format("(%d,%d)", x, y); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBMapView.h ./src/win32/GBMapView.h --- ../VisualBoyAdvance-1.7.2/src/win32/GBMapView.h 2004-05-13 22:44:36 +0900 +++ ./src/win32/GBMapView.h 2006-05-27 23:47:33 +0900 @@ -31,7 +31,7 @@ #include "ZoomControl.h" #include "ResizeDlg.h" #include "IUpdate.h" -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView ///////////////////////////////////////////////////////////////////////////// // GBMapView dialog diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBPaletteView.cpp ./src/win32/GBPaletteView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBPaletteView.cpp 2004-05-13 23:25:08 +0900 +++ ./src/win32/GBPaletteView.cpp 2004-11-01 03:26:01 +0900 @@ -136,6 +136,8 @@ return; } + captureBuffer = dlg.GetPathName(); + PaletteViewControl *p = NULL; if(which == 0) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GBTileView.cpp ./src/win32/GBTileView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GBTileView.cpp 2004-05-13 23:24:44 +0900 +++ ./src/win32/GBTileView.cpp 2006-05-27 23:47:33 +0900 @@ -460,8 +460,8 @@ u8 *colors = (u8 *)lParam; zoom.setColors(colors); - int x = (wParam & 0xFFFF)/8; - int y = ((wParam >> 16) & 0xFFFF)/8; + int x = (int)((wParam & 0xffff)/8); + int y = (int)(((wParam >> 16) & 0xFFFF)/8); int tiles = 0x0000; if(charBase) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GDIDisplay.cpp ./src/win32/GDIDisplay.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GDIDisplay.cpp 2004-05-13 23:24:10 +0900 +++ ./src/win32/GDIDisplay.cpp 2006-06-22 01:58:15 +0900 @@ -1,6 +1,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,12 +18,14 @@ // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -#include + +#include "Display.h" #include "../System.h" #include "../GBA.h" #include "../Globals.h" #include "../Text.h" +#include "../Util.h" #include "VBA.h" #include "MainWnd.h" @@ -36,7 +39,6 @@ #endif extern void winlog(const char *,...); -extern int RGB_LOW_BITS_MASK; extern int Init_2xSaI(u32); extern int systemSpeed; @@ -216,10 +218,8 @@ if(systemColorDepth == 16) { if(systemGreenShift == 6) { Init_2xSaI(565); - RGB_LOW_BITS_MASK=0x821; } else { Init_2xSaI(555); - RGB_LOW_BITS_MASK=0x421; } } else if(systemColorDepth == 32) Init_2xSaI(32); @@ -241,27 +241,7 @@ cpu_mmx = 0; #endif - switch(systemColorDepth) { - case 16: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - case 24: - case 32: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - } + utilUpdateSystemColorMaps(); theApp.updateFilter(); theApp.updateIFB(); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GameOverrides.cpp ./src/win32/GameOverrides.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/GameOverrides.cpp 1970-01-01 09:00:00 +0900 +++ ./src/win32/GameOverrides.cpp 2006-08-02 04:21:16 +0900 @@ -0,0 +1,291 @@ +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 1999-2003 Forgotten +// Copyright (C) 2005-2006 Forgotten and the VBA development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// GameOverrides.cpp : implementation file +// + +#include "stdafx.h" +#include "vba.h" +#include "GameOverrides.h" +#include "../GBA.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// GameOverrides dialog + + +GameOverrides::GameOverrides(CWnd* pParent /*=NULL*/) + : CDialog(GameOverrides::IDD, pParent) +{ + //{{AFX_DATA_INIT(GameOverrides) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT +} + + +void GameOverrides::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(GameOverrides) + DDX_Control(pDX, IDC_NAME, m_name); + DDX_Control(pDX, IDC_MIRRORING, m_mirroring); + DDX_Control(pDX, IDC_FLASH_SIZE, m_flashSize); + DDX_Control(pDX, IDC_SAVE_TYPE, m_saveType); + DDX_Control(pDX, IDC_RTC, m_rtc); + DDX_Control(pDX, IDC_COMMENT, m_comment); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(GameOverrides, CDialog) + //{{AFX_MSG_MAP(GameOverrides) + ON_BN_CLICKED(IDC_DEFAULTS, OnDefaults) + //}}AFX_MSG_MAP + END_MESSAGE_MAP() + + ///////////////////////////////////////////////////////////////////////////// +// GameOverrides message handlers + +void GameOverrides::OnOK() +{ + char tempName[2048]; + + GetModuleFileName(NULL, tempName, 2048); + + char *p = strrchr(tempName, '\\'); + if(p) + *p = 0; + + char buffer[5]; + strncpy(buffer, (const char *)&rom[0xac], 4); + buffer[4] = 0; + + strcat(tempName, "\\vba-over.ini"); + + char comment[0xFF]; + m_comment.GetWindowText(comment, 0xFF); + WritePrivateProfileString(buffer, "comment", !strncmp(comment, "", 0xFF) ? NULL : comment, tempName); + + int rtc = m_rtc.GetCurSel(); + int flash = m_flashSize.GetCurSel(); + int save = m_saveType.GetCurSel(); + int mirroring = m_mirroring.GetCurSel(); + if(rtc == 0 && flash == 0 && save == 0 && mirroring == 0) + WritePrivateProfileString(buffer, NULL, NULL, tempName); + else { + char *value = NULL; + switch(rtc) { + case 1: + value = "0"; + break; + case 2: + value = "1"; + break; + } + WritePrivateProfileString(buffer, "rtcEnabled", value, tempName); + value = NULL; + switch(flash) { + case 1: + value = "0x10000"; + break; + case 2: + value = "0x20000"; + break; + } + WritePrivateProfileString(buffer, "flashSize", value, tempName); + value = NULL; + switch(save) { + case 1: + value = "0"; + break; + case 2: + value = "1"; + break; + case 3: + value = "2"; + break; + case 4: + value = "3"; + break; + case 5: + value = "4"; + break; + case 6: + value = "5"; + break; + } + WritePrivateProfileString(buffer, "saveType", value, tempName); + value = NULL; + switch(mirroring) { + case 1: + value = "0"; + break; + case 2: + value = "1"; + break; + } + WritePrivateProfileString(buffer, "mirroringEnabled", value, tempName); + } + CDialog::OnOK(); +} + +void GameOverrides::OnDefaults() +{ + m_rtc.SetCurSel(0); + m_flashSize.SetCurSel(0); + m_saveType.SetCurSel(0); + m_mirroring.SetCurSel(0); +} + +void GameOverrides::OnCancel() +{ + CDialog::OnCancel(); +} + +BOOL GameOverrides::OnInitDialog() +{ + CDialog::OnInitDialog(); + + char tempName[2048]; + + const char *rtcValues[] = { + "Default", + "Disabled", + "Enabled" + }; + const char *flashValues[] = { + "Default", + "64K", + "128K" + }; + const char *saveValues[] = { + "Default", + "Automatic", + "EEPROM", + "SRAM", + "Flash", + "EEPROM+Sensor", + "None" + }; + const char *mirroringValues[] = { + "Default", + "Disabled", + "Enabled" + }; + + int i; + + for(i = 0; i < 3; i++) { + m_rtc.AddString(rtcValues[i]); + } + for(i = 0; i < 3; i++) { + m_flashSize.AddString(flashValues[i]); + } + for(i = 0; i < 7; i++) { + m_saveType.AddString(saveValues[i]); + } + for(i = 0; i < 3; i++) { + m_mirroring.AddString(mirroringValues[i]); + } + + GetModuleFileName(NULL, tempName, 2048); + + char *p = strrchr(tempName, '\\'); + if(p) + *p = 0; + + char buffer[5]; + strncpy(buffer, (const char *)&rom[0xac], 4); + buffer[4] = 0; + + strcat(tempName, "\\vba-over.ini"); + + m_name.SetWindowText(buffer); + + char comment[0xFF]; + GetPrivateProfileString(buffer, + "comment", + "", + comment, + 0xFF, + tempName); + m_comment.SetWindowText(comment); + + UINT v = GetPrivateProfileInt(buffer, + "rtcEnabled", + -1, + tempName); + switch(v) { + case 0: + m_rtc.SetCurSel(1); + break; + case 1: + m_rtc.SetCurSel(2); + break; + default: + m_rtc.SetCurSel(0); + } + v = GetPrivateProfileInt(buffer, + "flashSize", + -1, + tempName); + switch(v) { + case 0x10000: + m_flashSize.SetCurSel(1); + break; + case 0x20000: + m_flashSize.SetCurSel(2); + break; + default: + m_flashSize.SetCurSel(0); + } + + v = GetPrivateProfileInt(buffer, + "saveType", + -1, + tempName); + if(v != (UINT)-1 && (v > 5)) + v = (UINT)-1; + if(v != (UINT)-1) + m_saveType.SetCurSel(v+1); + else + m_saveType.SetCurSel(0); + + v = GetPrivateProfileInt(buffer, + "mirroringEnabled", + -1, + tempName); + switch(v) { + case 0: + m_mirroring.SetCurSel(1); + break; + case 1: + m_mirroring.SetCurSel(2); + break; + default: + m_mirroring.SetCurSel(0); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} diff -urN ../VisualBoyAdvance-1.7.2/src/win32/GameOverrides.h ./src/win32/GameOverrides.h --- ../VisualBoyAdvance-1.7.2/src/win32/GameOverrides.h 1970-01-01 09:00:00 +0900 +++ ./src/win32/GameOverrides.h 2006-08-02 04:21:16 +0900 @@ -0,0 +1,74 @@ +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 1999-2003 Forgotten +// Copyright (C) 2005 Forgotten and the VBA development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "afxwin.h" +#if !defined(AFX_GAMEOVERRIDES_H__EEEFE37F_F477_455D_8682_705FB2DBCC0C__INCLUDED_) +#define AFX_GAMEOVERRIDES_H__EEEFE37F_F477_455D_8682_705FB2DBCC0C__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// GameOverrides.h : header file +// + +///////////////////////////////////////////////////////////////////////////// +// GameOverrides dialog + +class GameOverrides : public CDialog +{ +// Construction +public: + GameOverrides(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(GameOverrides) + enum { IDD = IDD_GAME_OVERRIDES }; + CEdit m_name; + CComboBox m_mirroring; + CComboBox m_flashSize; + CComboBox m_saveType; + CComboBox m_rtc; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(GameOverrides) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(GameOverrides) + virtual void OnOK(); + afx_msg void OnDefaults(); + virtual void OnCancel(); + virtual BOOL OnInitDialog(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +public: + CEdit m_comment; +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_GAMEOVERRIDES_H__EEEFE37F_F477_455D_8682_705FB2DBCC0C__INCLUDED_) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/IOViewer.cpp ./src/win32/IOViewer.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/IOViewer.cpp 2004-05-13 23:23:37 +0900 +++ ./src/win32/IOViewer.cpp 2005-06-25 15:23:31 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -67,6 +67,22 @@ ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate) ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses) ON_BN_CLICKED(IDC_APPLY, OnApply) + ON_BN_CLICKED(IDC_BIT_0, bitChange) + ON_BN_CLICKED(IDC_BIT_1, bitChange) + ON_BN_CLICKED(IDC_BIT_2, bitChange) + ON_BN_CLICKED(IDC_BIT_3, bitChange) + ON_BN_CLICKED(IDC_BIT_4, bitChange) + ON_BN_CLICKED(IDC_BIT_5, bitChange) + ON_BN_CLICKED(IDC_BIT_6, bitChange) + ON_BN_CLICKED(IDC_BIT_7, bitChange) + ON_BN_CLICKED(IDC_BIT_8, bitChange) + ON_BN_CLICKED(IDC_BIT_9, bitChange) + ON_BN_CLICKED(IDC_BIT_10, bitChange) + ON_BN_CLICKED(IDC_BIT_11, bitChange) + ON_BN_CLICKED(IDC_BIT_12, bitChange) + ON_BN_CLICKED(IDC_BIT_13, bitChange) + ON_BN_CLICKED(IDC_BIT_14, bitChange) + ON_BN_CLICKED(IDC_BIT_15, bitChange) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -80,10 +96,29 @@ DestroyWindow(); } +void IOViewer::bitChange() +{ + CString buffer; + u16 data = 0; + + for(int i = 0; i < 16; i++) { + CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i); + + if(pWnd) { + if(pWnd->GetCheck()) + data |= (1 << i); + } + } + + buffer.Format("%04X", data); + m_value.SetWindowText(buffer); +} + void IOViewer::OnRefresh() { // TODO: Add your control notification handler code here - + + update(); } void IOViewer::OnAutoUpdate() @@ -186,6 +221,8 @@ void IOViewer::OnApply() { + if(rom != NULL) + { const IOData *sel = &ioViewRegisters[selected]; u16 res = 0; for(int i = 0; i < 16; i++) { @@ -198,4 +235,5 @@ } CPUWriteHalfWord(0x4000000+sel->offset, res); update(); + } } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/IOViewer.h ./src/win32/IOViewer.h --- ../VisualBoyAdvance-1.7.2/src/win32/IOViewer.h 2004-05-13 22:42:26 +0900 +++ ./src/win32/IOViewer.h 2005-06-25 15:23:31 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ // Construction public: void update(); + void bitChange(); bool autoUpdate; int selected; IOViewer(CWnd* pParent = NULL); // standard constructor diff -urN ../VisualBoyAdvance-1.7.2/src/win32/IOViewerRegs.h ./src/win32/IOViewerRegs.h --- ../VisualBoyAdvance-1.7.2/src/win32/IOViewerRegs.h 2004-05-13 22:42:00 +0900 +++ ./src/win32/IOViewerRegs.h 2005-06-25 15:23:31 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -258,7 +258,7 @@ } }, { - &BG2HOFS, 0x18, "0x4000018-BG8HOFS", 0x01FF, + &BG2HOFS, 0x18, "0x4000018-BG2HOFS", 0x01FF, { "", "", @@ -1119,7 +1119,7 @@ } }, { - NULL, 0x82, "0x4000082-SGCNT0_H", 0xFF1F, + NULL, 0x82, "0x4000082-SGCNT0_H", 0xFF0F, { "", "Sound 1-4 Volume (2 bits)", diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Input.h ./src/win32/Input.h --- ../VisualBoyAdvance-1.7.2/src/win32/Input.h 2004-05-13 22:41:34 +0900 +++ ./src/win32/Input.h 2006-06-07 06:04:21 +0900 @@ -43,7 +43,7 @@ virtual bool readDevices() = 0; virtual u32 readDevice(int which) = 0; - virtual CString getKeyName(int key) = 0; + virtual CString getKeyName(LONG_PTR key) = 0; virtual void checkKeys() = 0; virtual void checkMotionKeys() = 0; virtual void checkDevices() = 0; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Joypad.cpp ./src/win32/Joypad.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Joypad.cpp 2004-05-13 23:23:26 +0900 +++ ./src/win32/Joypad.cpp 2006-06-07 06:04:21 +0900 @@ -30,8 +30,8 @@ static char THIS_FILE[] = __FILE__; #endif -extern USHORT joypad[4][13]; -extern USHORT motion[4]; +extern LONG_PTR joypad[4][13]; +extern LONG_PTR motion[4]; ///////////////////////////////////////////////////////////////////////////// // JoypadEditControl @@ -46,27 +46,21 @@ BEGIN_MESSAGE_MAP(JoypadEditControl, CEdit) - //{{AFX_MSG_MAP(JoypadEditControl) - ON_WM_CHAR() - //}}AFX_MSG_MAP ON_MESSAGE(JOYCONFIG_MESSAGE, OnJoyConfig) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // JoypadEditControl message handlers -void JoypadEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) -{ -} - LRESULT JoypadEditControl::OnJoyConfig(WPARAM wParam, LPARAM lParam) { - SetWindowLong(GetSafeHwnd(), GWL_USERDATA,((wParam<<8)|lParam)); - SetWindowText(theApp.input->getKeyName((wParam<<8)|lParam)); - GetParent()->GetNextDlgTabItem(this, FALSE)->SetFocus(); - return TRUE; + SetWindowLongPtr( this->GetSafeHwnd(), GWLP_USERDATA, (wParam<<8) | lParam ); + this->SetWindowText( theApp.input->getKeyName( (int)((wParam<<8)|lParam) ) ); + GetParent()->GetNextDlgTabItem(this, FALSE)->SetFocus(); + return TRUE; } + BOOL JoypadEditControl::PreTranslateMessage(MSG *pMsg) { if(pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN)) @@ -112,14 +106,11 @@ BEGIN_MESSAGE_MAP(JoypadConfig, CDialog) - //{{AFX_MSG_MAP(JoypadConfig) ON_BN_CLICKED(ID_CANCEL, OnCancel) ON_BN_CLICKED(ID_OK, OnOk) - ON_WM_CHAR() ON_WM_DESTROY() ON_WM_TIMER() ON_WM_KEYDOWN() - //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -137,10 +128,6 @@ EndDialog(TRUE); } -void JoypadConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) -{ -} - void JoypadConfig::OnDestroy() { CDialog::OnDestroy(); @@ -148,7 +135,7 @@ KillTimer(timerId); } -void JoypadConfig::OnTimer(UINT nIDEvent) +void JoypadConfig::OnTimer(UINT_PTR nIDEvent) { theApp.input->checkDevices(); @@ -163,45 +150,45 @@ { CDialog::OnInitDialog(); - timerId = SetTimer(0,200,NULL); + timerId = SetTimer(0,50,NULL); - SetWindowLong(up, GWL_USERDATA,joypad[which][KEY_UP]); + SetWindowLongPtr(up, GWLP_USERDATA,joypad[which][KEY_UP]); up.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_UP])); - SetWindowLong(down, GWL_USERDATA,joypad[which][KEY_DOWN]); + SetWindowLongPtr(down, GWLP_USERDATA,joypad[which][KEY_DOWN]); down.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_DOWN])); - SetWindowLong(left, GWL_USERDATA,joypad[which][KEY_LEFT]); + SetWindowLongPtr(left, GWLP_USERDATA,joypad[which][KEY_LEFT]); left.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_LEFT])); - SetWindowLong(right, GWL_USERDATA,joypad[which][KEY_RIGHT]); + SetWindowLongPtr(right, GWLP_USERDATA,joypad[which][KEY_RIGHT]); right.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_RIGHT])); - SetWindowLong(buttonA, GWL_USERDATA,joypad[which][KEY_BUTTON_A]); + SetWindowLongPtr(buttonA, GWLP_USERDATA,joypad[which][KEY_BUTTON_A]); buttonA.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_A])); - SetWindowLong(buttonB, GWL_USERDATA,joypad[which][KEY_BUTTON_B]); + SetWindowLongPtr(buttonB, GWLP_USERDATA,joypad[which][KEY_BUTTON_B]); buttonB.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_B])); - SetWindowLong(buttonL, GWL_USERDATA,joypad[which][KEY_BUTTON_L]); + SetWindowLongPtr(buttonL, GWLP_USERDATA,joypad[which][KEY_BUTTON_L]); buttonL.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_L])); - SetWindowLong(buttonR, GWL_USERDATA,joypad[which][KEY_BUTTON_R]); + SetWindowLongPtr(buttonR, GWLP_USERDATA,joypad[which][KEY_BUTTON_R]); buttonR.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_R])); - SetWindowLong(buttonSelect, GWL_USERDATA,joypad[which][KEY_BUTTON_SELECT]); + SetWindowLongPtr(buttonSelect, GWLP_USERDATA,joypad[which][KEY_BUTTON_SELECT]); buttonSelect.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SELECT])); - SetWindowLong(buttonStart, GWL_USERDATA,joypad[which][KEY_BUTTON_START]); + SetWindowLongPtr(buttonStart, GWLP_USERDATA,joypad[which][KEY_BUTTON_START]); buttonStart.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_START])); - SetWindowLong(speed, GWL_USERDATA,joypad[which][KEY_BUTTON_SPEED]); + SetWindowLongPtr(speed, GWLP_USERDATA,joypad[which][KEY_BUTTON_SPEED]); speed.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SPEED])); - SetWindowLong(capture, GWL_USERDATA,joypad[which][KEY_BUTTON_CAPTURE]); + SetWindowLongPtr(capture, GWLP_USERDATA,joypad[which][KEY_BUTTON_CAPTURE]); capture.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_CAPTURE])); - SetWindowLong(buttonGS, GWL_USERDATA,joypad[which][KEY_BUTTON_GS]); + SetWindowLongPtr(buttonGS, GWLP_USERDATA,joypad[which][KEY_BUTTON_GS]); buttonGS.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_GS])); CenterWindow(); @@ -210,7 +197,7 @@ // EXCEPTION: OCX Property Pages should return FALSE } -void JoypadConfig::assignKey(int id, int key) +void JoypadConfig::assignKey(int id, LONG_PTR key) { switch(id) { case IDC_EDIT_LEFT: @@ -260,43 +247,43 @@ int id; id = IDC_EDIT_UP; - assignKey(id, GetWindowLong(up, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(up, GWLP_USERDATA)); id = IDC_EDIT_DOWN; - assignKey(id, GetWindowLong(down, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(down, GWLP_USERDATA)); id = IDC_EDIT_LEFT; - assignKey(id, GetWindowLong(left, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(left, GWLP_USERDATA)); id = IDC_EDIT_RIGHT; - assignKey(id, GetWindowLong(right, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(right, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_A; - assignKey(id, GetWindowLong(buttonA, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonA, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_B; - assignKey(id, GetWindowLong(buttonB, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonB, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_L; - assignKey(id, GetWindowLong(buttonL, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonL, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_R; - assignKey(id, GetWindowLong(buttonR, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonR, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_SELECT; - assignKey(id, GetWindowLong(buttonSelect, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonSelect, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_START; - assignKey(id, GetWindowLong(buttonStart, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonStart, GWLP_USERDATA)); id = IDC_EDIT_SPEED; - assignKey(id, GetWindowLong(speed, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(speed, GWLP_USERDATA)); id = IDC_EDIT_CAPTURE; - assignKey(id, GetWindowLong(capture, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(capture, GWLP_USERDATA)); id = IDC_EDIT_BUTTON_GS; - assignKey(id, GetWindowLong(buttonGS, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(buttonGS, GWLP_USERDATA)); // winSaveKeys(); } @@ -328,14 +315,11 @@ BEGIN_MESSAGE_MAP(MotionConfig, CDialog) - //{{AFX_MSG_MAP(MotionConfig) ON_BN_CLICKED(ID_CANCEL, OnCancel) ON_BN_CLICKED(ID_OK, OnOk) - ON_WM_CHAR() ON_WM_DESTROY() ON_WM_KEYDOWN() ON_WM_TIMER() - //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -353,10 +337,6 @@ EndDialog( TRUE); } -void MotionConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) -{ -} - void MotionConfig::OnDestroy() { CDialog::OnDestroy(); @@ -370,16 +350,16 @@ timerId = SetTimer(0,200,NULL); - SetWindowLong(up, GWL_USERDATA,motion[KEY_UP]); + SetWindowLongPtr(up, GWLP_USERDATA,motion[KEY_UP]); up.SetWindowText(theApp.input->getKeyName(motion[KEY_UP])); - SetWindowLong(down, GWL_USERDATA,motion[KEY_DOWN]); + SetWindowLongPtr(down, GWLP_USERDATA,motion[KEY_DOWN]); down.SetWindowText(theApp.input->getKeyName(motion[KEY_DOWN])); - SetWindowLong(left, GWL_USERDATA,motion[KEY_LEFT]); + SetWindowLongPtr(left, GWLP_USERDATA,motion[KEY_LEFT]); left.SetWindowText(theApp.input->getKeyName(motion[KEY_LEFT])); - SetWindowLong(right, GWL_USERDATA,motion[KEY_RIGHT]); + SetWindowLongPtr(right, GWLP_USERDATA,motion[KEY_RIGHT]); right.SetWindowText(theApp.input->getKeyName(motion[KEY_RIGHT])); CenterWindow(); @@ -392,14 +372,14 @@ { } -void MotionConfig::OnTimer(UINT nIDEvent) +void MotionConfig::OnTimer(UINT_PTR nIDEvent) { theApp.input->checkDevices(); CDialog::OnTimer(nIDEvent); } -void MotionConfig::assignKey(int id, int key) +void MotionConfig::assignKey(int id, LONG_PTR key) { switch(id) { case IDC_EDIT_LEFT: @@ -422,14 +402,14 @@ int id; id = IDC_EDIT_UP; - assignKey(id, GetWindowLong(up, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(up, GWLP_USERDATA)); id = IDC_EDIT_DOWN; - assignKey(id, GetWindowLong(down, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(down, GWLP_USERDATA)); id = IDC_EDIT_LEFT; - assignKey(id, GetWindowLong(left, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(left, GWLP_USERDATA)); id = IDC_EDIT_RIGHT; - assignKey(id, GetWindowLong(right, GWL_USERDATA)); + assignKey(id, GetWindowLongPtr(right, GWLP_USERDATA)); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Joypad.h ./src/win32/Joypad.h --- ../VisualBoyAdvance-1.7.2/src/win32/Joypad.h 2004-05-13 22:40:44 +0900 +++ ./src/win32/Joypad.h 2006-06-07 06:04:21 +0900 @@ -41,23 +41,12 @@ // Operations public: - // Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(JoypadEditControl) - //}}AFX_VIRTUAL - // Implementation public: virtual BOOL PreTranslateMessage(MSG *pMsg); afx_msg LRESULT OnJoyConfig(WPARAM wParam, LPARAM lParam); virtual ~JoypadEditControl(); - // Generated message map functions - protected: - //{{AFX_MSG(JoypadEditControl) - afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() }; @@ -71,7 +60,7 @@ // Construction public: void assignKeys(); - void assignKey(int id, int key); + void assignKey(int id, LONG_PTR key); JoypadConfig(int w, CWnd* pParent = NULL); // standard constructor // Dialog Data @@ -102,16 +91,15 @@ // Implementation protected: - UINT timerId; + UINT_PTR timerId; int which; // Generated message map functions //{{AFX_MSG(JoypadConfig) afx_msg void OnCancel(); afx_msg void OnOk(); - afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnDestroy(); - afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); virtual BOOL OnInitDialog(); //}}AFX_MSG @@ -125,7 +113,7 @@ // Construction public: void assignKeys(); - void assignKey(int id, int key); + void assignKey(int id, LONG_PTR key); MotionConfig(CWnd* pParent = NULL); // standard constructor // Dialog Data @@ -149,18 +137,15 @@ protected: // Generated message map functions - //{{AFX_MSG(MotionConfig) afx_msg void OnCancel(); afx_msg void OnOk(); - afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnDestroy(); virtual BOOL OnInitDialog(); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg void OnTimer(UINT nIDEvent); - //}}AFX_MSG + afx_msg void OnTimer(UINT_PTR nIDEvent); DECLARE_MESSAGE_MAP() private: - UINT timerId; + UINT_PTR timerId; }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Logging.cpp ./src/win32/Logging.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Logging.cpp 2004-05-13 23:23:01 +0900 +++ ./src/win32/Logging.cpp 2006-06-07 06:04:21 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -225,7 +225,7 @@ m_dma2 = (systemVerbose & 64) != 0; m_dma3 = (systemVerbose & 128) != 0; m_undefined = (systemVerbose & 256) != 0; - m_agbprint = (systemVerbose & 256) != 0; + m_agbprint = (systemVerbose & 512) != 0; UpdateData(FALSE); m_log.LimitText(-1); @@ -237,7 +237,7 @@ void Logging::log(const char *s) { - int size = ::SendMessage(m_log, WM_GETTEXTLENGTH, 0, 0); + DWORD size = (DWORD)::SendMessage(m_log, WM_GETTEXTLENGTH, 0, 0); m_log.SetSel(size, size); m_log.ReplaceSel(s); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWnd.cpp ./src/win32/MainWnd.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MainWnd.cpp 2004-05-13 23:22:47 +0900 +++ ./src/win32/MainWnd.cpp 2006-08-06 21:40:35 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "MainWnd.h" #include +#include #include "FileDlg.h" #include "Reg.h" @@ -52,6 +53,7 @@ #define VBA_CONFIRM_MODE WM_APP + 100 extern void remoteCleanUp(); +extern int gbHardware; ///////////////////////////////////////////////////////////////////////////// // MainWnd @@ -192,14 +194,14 @@ ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE, OnUpdateOptionsEmulatorPausewheninactive) ON_COMMAND(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnOptionsEmulatorSpeeduptoggle) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnUpdateOptionsEmulatorSpeeduptoggle) - ON_COMMAND(ID_OPTIONS_EMULATOR_REMOVEINTROSGBA, OnOptionsEmulatorRemoveintrosgba) - ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_REMOVEINTROSGBA, OnUpdateOptionsEmulatorRemoveintrosgba) ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnOptionsEmulatorAutomaticallyipspatch) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnUpdateOptionsEmulatorAutomaticallyipspatch) ON_COMMAND(ID_OPTIONS_EMULATOR_AGBPRINT, OnOptionsEmulatorAgbprint) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AGBPRINT, OnUpdateOptionsEmulatorAgbprint) ON_COMMAND(ID_OPTIONS_EMULATOR_REALTIMECLOCK, OnOptionsEmulatorRealtimeclock) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_REALTIMECLOCK, OnUpdateOptionsEmulatorRealtimeclock) + ON_COMMAND(ID_OPTIONS_EMULATOR_GENERICFLASHCARD, OnOptionsEmulatorGenericflashcard) + ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_GENERICFLASHCARD, OnUpdateOptionsEmulatorGenericflashcard) ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOHIDEMENU, OnOptionsEmulatorAutohidemenu) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOHIDEMENU, OnUpdateOptionsEmulatorAutohidemenu) ON_COMMAND(ID_OPTIONS_EMULATOR_REWINDINTERVAL, OnOptionsEmulatorRewindinterval) @@ -376,6 +378,9 @@ ON_COMMAND(ID_CHEATS_DISABLECHEATS, OnCheatsDisablecheats) ON_UPDATE_COMMAND_UI(ID_CHEATS_DISABLECHEATS, OnUpdateCheatsDisablecheats) ON_COMMAND(ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE, OnOptionsVideoFullscreenmaxscale) + ON_COMMAND(ID_OPTIONS_EMULATOR_GAMEOVERRIDES, OnOptionsEmulatorGameoverrides) + ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_GAMEOVERRIDES, OnUpdateOptionsEmulatorGameoverrides) + ON_COMMAND(ID_HELP_GNUPUBLICLICENSE, OnHelpGnupubliclicense) //}}AFX_MSG_MAP ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile) ON_COMMAND_EX_RANGE(ID_FILE_LOADGAME_SLOT1, ID_FILE_LOADGAME_SLOT10, OnFileLoadSlot) @@ -414,6 +419,8 @@ ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_JOYPAD_AUTOFIRE_A, ID_OPTIONS_JOYPAD_AUTOFIRE_R, OnUpdateOptionsJoypadAutofire) ON_MESSAGE(VBA_CONFIRM_MODE, OnConfirmMode) ON_MESSAGE(WM_SYSCOMMAND, OnMySysCommand) + ON_COMMAND(ID_OPTIONS_SOUND_HARDWAREACCELERATION, &MainWnd::OnOptionsSoundHardwareacceleration) + ON_UPDATE_COMMAND_UI(ID_OPTIONS_SOUND_HARDWAREACCELERATION, &MainWnd::OnUpdateOptionsSoundHardwareacceleration) END_MESSAGE_MAP() @@ -422,6 +429,7 @@ void MainWnd::OnClose() { + emulating = false; CWnd::OnClose(); delete this; @@ -469,13 +477,40 @@ return false; } systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; - theApp.cartridgeType = (int)type; + theApp.cartridgeType = type; if(type == IMAGE_GB) { + genericflashcardEnable = theApp.winGenericflashcardEnable; + + if(!gbLoadRom(theApp.szFile)) return false; + + gbGetHardwareType(); + + // used for the handling of the gb Boot Rom + if (gbHardware & 5) + { + char tempName[2048]; + GetModuleFileName(NULL, tempName, 2048); + + char *p = strrchr(tempName, '\\'); + if(p) + *p = 0; + + strcat(tempName, "\\DMG_ROM.bin"); + + skipBios = theApp.skipBiosFile ? true : false; + gbCPUInit(tempName, theApp.useBiosFile ? true : false); + } + + + + gbReset(); theApp.emulator = GBSystem; gbBorderOn = theApp.winGbBorderOn; theApp.romSize = gbRomSize; + + if(theApp.autoIPS) { int size = gbRomSize; utilApplyIPS(ipsname, &gbRom, &size); @@ -492,14 +527,11 @@ return false; theApp.romSize = size; - + flashSetSize(theApp.winFlashSize); rtcEnable(theApp.winRtcEnable); cpuSaveType = theApp.winSaveType; - // if(cpuEnhancedDetection && winSaveType == 0) { - // utilGBAFindSave(rom, size); - // } GetModuleFileName(NULL, tempName, 2048); char *p = strrchr(tempName, '\\'); @@ -532,6 +564,12 @@ tempName); if(i != (UINT)-1 && (i <= 5)) cpuSaveType = (int)i; + i = GetPrivateProfileInt(buffer, + "mirroringEnabled", + -1, + tempName); + if(i != (UINT)-1) + doMirroring (i == 0 ? false : true); theApp.emulator = GBASystem; /* disabled due to problems @@ -565,7 +603,7 @@ CPUInit((char *)(LPCTSTR)theApp.biosFileName, theApp.useBiosFile ? true : false); CPUReset(); } - + readBatteryFile(); if(theApp.autoSaveLoadCheatList) @@ -730,6 +768,16 @@ else name = theApp.filename; CString dir = regQueryStringValue("saveDir", NULL); + if( dir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, dir ); + dir = baseDir; + } if(!dir.GetLength()) dir = getDirFromFile(filename); @@ -762,6 +810,16 @@ else name = theApp.filename; CString dir = regQueryStringValue("saveDir", NULL); + if( dir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, dir ); + dir = baseDir; + } if(!dir.GetLength()) dir = getDirFromFile(filename); @@ -824,6 +882,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -851,6 +919,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -915,7 +993,7 @@ info.cch = 256; if(!GetMenuItemInfo(theApp.menu, i, MF_BYPOSITION, &info)) { } - if(!AppendMenu(theApp.popup, MF_POPUP|MF_STRING, (UINT)info.hSubMenu, buffer)) { + if(!AppendMenu(theApp.popup, MF_POPUP|MF_STRING, (UINT_PTR)info.hSubMenu, buffer)) { } } } else { @@ -929,7 +1007,7 @@ info.cch = 256; if(!GetMenuItemInfoW(theApp.menu, i, MF_BYPOSITION, &info)) { } - if(!AppendMenuW(theApp.popup, MF_POPUP|MF_STRING, (UINT)info.hSubMenu, buffer)) { + if(!AppendMenuW(theApp.popup, MF_POPUP|MF_STRING, (UINT_PTR)info.hSubMenu, buffer)) { } } } @@ -951,37 +1029,71 @@ ShowWindow(SW_SHOWMINIMIZED); } -bool MainWnd::fileOpenSelect() + +bool MainWnd::fileOpenSelect( bool gb ) { - theApp.dir = ""; - CString initialDir = regQueryStringValue("romdir","."); - if(!initialDir.IsEmpty()) - theApp.dir = initialDir; - - int selectedFilter = regQueryDwordValue("selectedFilter", 0); - if(selectedFilter < 0 || selectedFilter > 2) - selectedFilter = 0; - - theApp.szFile = ""; - - LPCTSTR exts[] = { "" }; - CString filter = winLoadFilter(IDS_FILTER_ROM); - CString title = winResLoadString(IDS_SELECT_ROM); - - FileDlg dlg(this, "", filter, selectedFilter, "", exts, theApp.dir, title, false); - - if(dlg.DoModal() == IDOK) { - regSetDwordValue("selectedFilter", dlg.m_ofn.nFilterIndex); - theApp.szFile = dlg.GetPathName(); - theApp.dir = theApp.szFile.Left(dlg.m_ofn.nFileOffset); - if(theApp.dir.GetLength() > 3 && theApp.dir[theApp.dir.GetLength()-1] == '\\') - theApp.dir = theApp.dir.Left(theApp.dir.GetLength()-1); - regSetStringValue("romdir", theApp.dir); - return true; - } - return false; + theApp.dir = _T(""); + CString initialDir; + if( gb ) { + initialDir = regQueryStringValue( _T("gbromdir"), _T(".") ); + } else { + initialDir = regQueryStringValue( _T("romdir"), _T(".") ); + } + + if( initialDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, initialDir ); + initialDir = baseDir; + } + + if( !initialDir.IsEmpty() ) { + theApp.dir = initialDir; + } + + int selectedFilter = 0; + if( !gb ) { + selectedFilter = regQueryDwordValue( _T("selectedFilter"), 0); + if( (selectedFilter < 0) || (selectedFilter > 2) ) { + selectedFilter = 0; + } + } + + theApp.szFile = _T(""); + + LPCTSTR exts[] = { _T(""), _T(""), _T(""), _T("") }; + CString filter; + CString title; + if( gb ) { + filter = winLoadFilter( IDS_FILTER_GBROM ); + title = winResLoadString( IDS_SELECT_ROM ); + } else { + filter = winLoadFilter( IDS_FILTER_ROM ); + title = winResLoadString( IDS_SELECT_ROM ); + } + + FileDlg dlg( this, _T(""), filter, selectedFilter, _T(""), exts, theApp.dir, title, false); + + if( dlg.DoModal() == IDOK ) { + if( !gb ) { + regSetDwordValue( _T("selectedFilter"), dlg.m_ofn.nFilterIndex ); + } + theApp.szFile = dlg.GetPathName(); + theApp.dir = theApp.szFile.Left( dlg.m_ofn.nFileOffset ); + if( (theApp.dir.GetLength() > 3) && (theApp.dir[theApp.dir.GetLength()-1] == _T('\\')) ) { + theApp.dir = theApp.dir.Left( theApp.dir.GetLength() - 1 ); + } + SetCurrentDirectory( theApp.dir ); + return true; + } + return false; } + void MainWnd::OnPaint() { CPaintDC dc(this); // device context for painting @@ -1011,6 +1123,16 @@ CString buffer; CString captureDir = regQueryStringValue("captureDir", ""); + if( captureDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, captureDir ); + captureDir = baseDir; + } int index = theApp.filename.ReverseFind('\\'); CString name; @@ -1039,6 +1161,15 @@ captureNumber, ext); + // check if file exists + DWORD dwAttr = GetFileAttributes( buffer ); + if( dwAttr != INVALID_FILE_ATTRIBUTES ) { + // screenshot file already exists + screenCapture(++captureNumber); + // this will recursively use the first non-existent screenshot number + return; + } + if(theApp.captureFormat == 0) theApp.emulator.emuWritePNG(buffer); else @@ -1098,7 +1229,12 @@ } if(theApp.paused && emulating) + { + theApp.painting = true; systemDrawScreen(); + theApp.painting = false; + theApp.renderedFrames--; + } } #if _MSC_VER <= 1200 @@ -1145,3 +1281,4 @@ } return Default(); } + diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWnd.h ./src/win32/MainWnd.h --- ../VisualBoyAdvance-1.7.2/src/win32/MainWnd.h 2004-05-13 22:39:34 +0900 +++ ./src/win32/MainWnd.h 2006-08-06 21:40:35 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -55,7 +55,7 @@ void winMouseOn(); void screenCapture(int captureNumber); HACCEL m_hAccelTable; - bool fileOpenSelect(); + bool fileOpenSelect( bool gb = false ); afx_msg LRESULT OnConfirmMode(WPARAM, LPARAM); afx_msg LRESULT OnMySysCommand(WPARAM, LPARAM); afx_msg void OnUpdateFileLoadGameSlot(CCmdUI *pCmdUI); @@ -221,14 +221,14 @@ afx_msg void OnUpdateOptionsEmulatorPausewheninactive(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorSpeeduptoggle(); afx_msg void OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI* pCmdUI); - afx_msg void OnOptionsEmulatorRemoveintrosgba(); - afx_msg void OnUpdateOptionsEmulatorRemoveintrosgba(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorAutomaticallyipspatch(); afx_msg void OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorAgbprint(); afx_msg void OnUpdateOptionsEmulatorAgbprint(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorRealtimeclock(); afx_msg void OnUpdateOptionsEmulatorRealtimeclock(CCmdUI* pCmdUI); + afx_msg void OnOptionsEmulatorGenericflashcard(); + afx_msg void OnUpdateOptionsEmulatorGenericflashcard(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorAutohidemenu(); afx_msg void OnUpdateOptionsEmulatorAutohidemenu(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorRewindinterval(); @@ -408,13 +408,20 @@ afx_msg void OnUpdateOptionsSoundVolume5x(CCmdUI* pCmdUI); afx_msg void OnCheatsDisablecheats(); afx_msg void OnUpdateCheatsDisablecheats(CCmdUI* pCmdUI); - afx_msg void OnOptionsVideoFullscreenmaxscale(); + afx_msg void OnOptionsVideoFullscreenmaxscale(); + afx_msg void OnOptionsEmulatorGameoverrides(); + afx_msg void OnUpdateOptionsEmulatorGameoverrides(CCmdUI* pCmdUI); + afx_msg void OnHelpGnupubliclicense(); //}}AFX_MSG DECLARE_MESSAGE_MAP() - + afx_msg BOOL OnFileRecentFile(UINT nID); afx_msg BOOL OnFileLoadSlot(UINT nID); afx_msg BOOL OnFileSaveSlot(UINT nID); +public: + afx_msg void OnOptionsSoundHardwareacceleration(); +public: + afx_msg void OnUpdateOptionsSoundHardwareacceleration(CCmdUI *pCmdUI); }; ///////////////////////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWndFile.cpp ./src/win32/MainWndFile.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MainWndFile.cpp 2004-05-13 23:22:25 +0900 +++ ./src/win32/MainWndFile.cpp 2006-08-06 02:29:02 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ #include "stdafx.h" #include "MainWnd.h" +#include + #include "ExportGSASnapshot.h" #include "FileDlg.h" #include "GSACodeSelect.h" @@ -37,15 +39,18 @@ extern int emulating; extern void remoteCleanUp(); +extern void InterframeCleanup(); + void MainWnd::OnFileOpen() { - theApp.winCheckFullscreen(); - if(fileOpenSelect()) { - FileRun(); - } + theApp.winCheckFullscreen(); + if( fileOpenSelect( false ) ) { + FileRun(); + } } + void MainWnd::OnFilePause() { theApp.paused = !theApp.paused; @@ -158,32 +163,16 @@ pCmdUI->Enable(emulating); } + void MainWnd::OnFileOpengameboy() { - theApp.winCheckFullscreen(); - theApp.dir = ""; - CString initialDir = regQueryStringValue("gbromdir","."); - if(!initialDir.IsEmpty()) - theApp.dir = initialDir; - - theApp.szFile = ""; - - LPCTSTR exts[] = { "" }; - CString filter = winLoadFilter(IDS_FILTER_GBROM); - CString title = winResLoadString(IDS_SELECT_ROM); - - FileDlg dlg(this, "", filter, 0, "", exts, initialDir, title, false); - - if(dlg.DoModal() == IDOK) { - theApp.szFile = dlg.GetPathName(); - theApp.dir = theApp.szFile.Left(dlg.m_ofn.nFileOffset); - if(theApp.dir.GetLength() > 3 && theApp.dir[theApp.dir.GetLength()-1] == '\\') - theApp.dir = theApp.dir.Left(theApp.dir.GetLength()-1); - regSetStringValue("gbromdir", theApp.dir); - FileRun(); - } + theApp.winCheckFullscreen(); + if( fileOpenSelect( true ) ) { + FileRun(); + } } + void MainWnd::OnFileLoad() { theApp.winCheckFullscreen(); @@ -198,6 +187,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -245,6 +244,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -254,17 +263,22 @@ else filename.Format("%s\\%s%d.sgm", saveDir, buffer, nID); - bool res = loadSaveGame(filename); - - theApp.rewindCount = 0; - theApp.rewindCounter = 0; - theApp.rewindSaveNeeded = false; - CString format = winResLoadString(IDS_LOADED_STATE_N); buffer.Format(format, nID); - + + bool res = loadSaveGame(filename); + + if (theApp.paused) + InterframeCleanup(); + systemScreenMessage(buffer); - + + systemDrawScreen(); + + //theApp.rewindCount = 0; + //theApp.rewindCounter = 0; + //theApp.rewindSaveNeeded = false; + return res; } @@ -282,6 +296,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -324,6 +348,16 @@ buffer = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -339,6 +373,8 @@ buffer.Format(format, nID); systemScreenMessage(buffer); + + systemDrawScreen(); return res; } @@ -351,6 +387,16 @@ CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -375,7 +421,8 @@ if(!res) systemMessage(MSG_CANNOT_OPEN_FILE, "Cannot open file %s", dlg.GetPathName()); else { - theApp.emulator.emuReset(); + //Removed the reset to allow loading a battery file 'within' a save state. + //theApp.emulator.emuReset(); } } @@ -421,7 +468,7 @@ void MainWnd::OnFileImportGamesharksnapshot() { theApp.winCheckFullscreen(); - LPCTSTR exts[] = { "" }; + LPCTSTR exts[] = { ".gbs" }; CString filter = theApp.cartridgeType == 1 ? winLoadFilter(IDS_FILTER_GBS) : winLoadFilter(IDS_FILTER_SPS); CString title = winResLoadString(IDS_SELECT_SNAPSHOT_FILE); @@ -467,6 +514,16 @@ CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -564,8 +621,18 @@ name = theApp.filename; CString capdir = regQueryStringValue("captureDir", ""); + if( capdir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, capdir ); + capdir = baseDir; + } if(capdir.IsEmpty()) - capdir = getDirFromFile(name); + capdir = getDirFromFile(theApp.filename); CString ext = "png"; @@ -645,6 +712,8 @@ } theApp.adjustDestRect(); + if(theApp.display) + theApp.display->resize(theApp.dest.right-theApp.dest.left, theApp.dest.bottom-theApp.dest.top); } void MainWnd::OnUpdateFileTogglemenu(CCmdUI* pCmdUI) @@ -680,7 +749,7 @@ } fseek(f, 0x1e, SEEK_SET); fread(&len, 1, 4, f); - int game = 0; + INT_PTR game = 0; if(len > 1) { GSACodeSelect dlg(f); game = dlg.DoModal(); @@ -697,7 +766,7 @@ } if(game != -1) { - return cheatsImportGSACodeFile(fileName, game, v3); + return cheatsImportGSACodeFile(fileName, (int)game, v3); } return true; @@ -718,6 +787,16 @@ filename = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -728,7 +807,7 @@ CString name; CFileStatus status; CString str; - time_t time = -1; + time_t time = (time_t)-1; int found = 0; for(int i = 0; i < 10; i++) { @@ -762,6 +841,16 @@ filename = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -804,6 +893,16 @@ filename = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -821,7 +920,7 @@ name.Format("%s%s%d.sgm", saveDir, filename, i+1); if(emulating && CFile::GetStatus(name, status)) { - if(status.m_mtime.GetTime() > time) { +if(status.m_mtime.GetTime() < time) { time = status.m_mtime.GetTime(); found = i; } @@ -848,6 +947,16 @@ filename = theApp.filename; CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWndHelp.cpp ./src/win32/MainWndHelp.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MainWndHelp.cpp 2004-05-13 23:22:12 +0900 +++ ./src/win32/MainWndHelp.cpp 2004-12-19 08:11:08 +0900 @@ -44,3 +44,9 @@ dlg.DoModal(); } + +void MainWnd::OnHelpGnupubliclicense() +{ + ::ShellExecute(0, _T("open"), "http://www.gnu.org/licenses/gpl.html", + 0, 0, SW_SHOWNORMAL); +} diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWndOptions.cpp ./src/win32/MainWndOptions.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MainWndOptions.cpp 2004-05-13 23:22:01 +0900 +++ ./src/win32/MainWndOptions.cpp 2006-08-11 19:58:39 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ #include "Associate.h" #include "Directories.h" #include "FileDlg.h" +#include "GameOverrides.h" #include "GBColorDlg.h" #include "Joypad.h" #include "MaxScale.h" @@ -41,6 +42,8 @@ #include "../gb/gbGlobals.h" #include "../gb/gbPrinter.h" +#include + extern int emulating; #define VBA_CONFIRM_MODE WM_APP + 100 @@ -50,6 +53,7 @@ void MainWnd::OnOptionsFrameskipThrottleNothrottle() { theApp.throttle = 0; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottleNothrottle(CCmdUI* pCmdUI) @@ -60,6 +64,7 @@ void MainWnd::OnOptionsFrameskipThrottle25() { theApp.throttle = 25; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottle25(CCmdUI* pCmdUI) @@ -70,6 +75,7 @@ void MainWnd::OnOptionsFrameskipThrottle50() { theApp.throttle = 50; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottle50(CCmdUI* pCmdUI) @@ -80,6 +86,7 @@ void MainWnd::OnOptionsFrameskipThrottle100() { theApp.throttle = 100; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottle100(CCmdUI* pCmdUI) @@ -90,6 +97,7 @@ void MainWnd::OnOptionsFrameskipThrottle150() { theApp.throttle = 150; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottle150(CCmdUI* pCmdUI) @@ -100,6 +108,7 @@ void MainWnd::OnOptionsFrameskipThrottle200() { theApp.throttle = 200; + theApp.autoFrameSkip = false; } void MainWnd::OnUpdateOptionsFrameskipThrottle200(CCmdUI* pCmdUI) @@ -107,14 +116,19 @@ pCmdUI->SetCheck(theApp.throttle == 200); } + void MainWnd::OnOptionsFrameskipThrottleOther() { - Throttle dlg; - int v = dlg.DoModal(); - if(v) - theApp.throttle = v; + Throttle dlg; + int v = (int)dlg.DoModal(); + + if( v ) { + theApp.throttle = v; + theApp.autoFrameSkip = false; + } } + void MainWnd::OnUpdateOptionsFrameskipThrottleOther(CCmdUI* pCmdUI) { int throttle = theApp.throttle; @@ -127,7 +141,13 @@ { theApp.autoFrameSkip = !theApp.autoFrameSkip; if(!theApp.autoFrameSkip && emulating) - theApp.updateFrameSkip(); + theApp.updateFrameSkip(); + else + { + theApp.throttle = false; + frameSkip = 0; + systemFrameSkip = 0; + } } void MainWnd::OnUpdateOptionsFrameskipAutomatic(CCmdUI* pCmdUI) @@ -144,26 +164,28 @@ case ID_OPTIONS_VIDEO_FRAMESKIP_3: case ID_OPTIONS_VIDEO_FRAMESKIP_4: case ID_OPTIONS_VIDEO_FRAMESKIP_5: - if(theApp.cartridgeType == 0) { + if(theApp.cartridgeType == IMAGE_GBA) { frameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0; } else { gbFrameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0; } if(emulating) theApp.updateFrameSkip(); + theApp.autoFrameSkip = false; return TRUE; break; case ID_OPTIONS_VIDEO_FRAMESKIP_6: case ID_OPTIONS_VIDEO_FRAMESKIP_7: case ID_OPTIONS_VIDEO_FRAMESKIP_8: case ID_OPTIONS_VIDEO_FRAMESKIP_9: - if(theApp.cartridgeType == 0) { + if(theApp.cartridgeType == IMAGE_GBA) { frameSkip = 6 + nID - ID_OPTIONS_VIDEO_FRAMESKIP_6; } else { gbFrameSkip = 6 + nID - ID_OPTIONS_VIDEO_FRAMESKIP_6; } if(emulating) theApp.updateFrameSkip(); + theApp.autoFrameSkip = false; return TRUE; break; } @@ -172,59 +194,64 @@ void MainWnd::OnUpdateOptionsVideoFrameskip0(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 0 : gbFrameSkip == 0); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 0 : gbFrameSkip == 0); } void MainWnd::OnUpdateOptionsVideoFrameskip1(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 1 : gbFrameSkip == 1); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 1 : gbFrameSkip == 1); } void MainWnd::OnUpdateOptionsVideoFrameskip2(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 2 : gbFrameSkip == 2); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 2 : gbFrameSkip == 2); } void MainWnd::OnUpdateOptionsVideoFrameskip3(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 3 : gbFrameSkip == 3); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 3 : gbFrameSkip == 3); } void MainWnd::OnUpdateOptionsVideoFrameskip4(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 4 : gbFrameSkip == 4); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 4 : gbFrameSkip == 4); } void MainWnd::OnUpdateOptionsVideoFrameskip5(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 5 : gbFrameSkip == 5); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 5 : gbFrameSkip == 5); } void MainWnd::OnUpdateOptionsVideoFrameskip6(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 6 : gbFrameSkip == 6); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 6 : gbFrameSkip == 6); } void MainWnd::OnUpdateOptionsVideoFrameskip7(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 7 : gbFrameSkip == 7); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 7 : gbFrameSkip == 7); } void MainWnd::OnUpdateOptionsVideoFrameskip8(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 8 : gbFrameSkip == 8); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 8 : gbFrameSkip == 8); } void MainWnd::OnUpdateOptionsVideoFrameskip9(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 9 : gbFrameSkip == 9); + pCmdUI->SetCheck(theApp.cartridgeType == IMAGE_GBA ? frameSkip == 9 : gbFrameSkip == 9); } + void MainWnd::OnOptionsVideoVsync() { - theApp.vsync = !theApp.vsync; + theApp.vsync = !theApp.vsync; + if( theApp.display ) { + theApp.display->setOption( _T("vsync"), theApp.vsync ); + } } + void MainWnd::OnUpdateOptionsVideoVsync(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.vsync); @@ -268,13 +295,15 @@ pCmdUI->SetCheck(theApp.videoOption == VIDEO_800x600); } + BOOL MainWnd::OnOptionVideoSize(UINT nID) { - theApp.updateVideoSize(nID); - theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE); - return TRUE; + theApp.updateVideoSize(nID); + theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE); + return TRUE; } + void MainWnd::OnOptionsVideoFullscreen320x240() { OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN320X240); @@ -290,6 +319,7 @@ OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN800X600); } + void MainWnd::OnOptionsVideoFullscreen() { theApp.winCheckFullscreen(); @@ -324,6 +354,7 @@ theApp.winAccelMgr.UpdateMenu(theApp.menu); } + void MainWnd::OnUpdateOptionsVideoFullscreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.videoOption == VIDEO_OTHER); @@ -332,7 +363,7 @@ void MainWnd::OnOptionsVideoDisablesfx() { cpuDisableSfx = !cpuDisableSfx; - if(emulating && theApp.cartridgeType == 0) + if(emulating && theApp.cartridgeType == IMAGE_GBA) CPUUpdateRender(); } @@ -341,14 +372,20 @@ pCmdUI->SetCheck(cpuDisableSfx); } + void MainWnd::OnOptionsVideoFullscreenstretchtofit() { - theApp.fullScreenStretch = !theApp.fullScreenStretch; - theApp.updateWindowSize(theApp.videoOption); - if(theApp.display) - theApp.display->clear(); + theApp.fullScreenStretch = !theApp.fullScreenStretch; + theApp.updateWindowSize( theApp.videoOption ); + if( theApp.display ) { + if( emulating ) { + theApp.display->clear( ); + } + theApp.display->setOption( _T("fullScreenStretch"), theApp.fullScreenStretch ); + } } + void MainWnd::OnUpdateOptionsVideoFullscreenstretchtofit(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.fullScreenStretch); @@ -425,31 +462,45 @@ pCmdUI->SetCheck(theApp.renderMethod == OPENGL); } + void MainWnd::OnOptionsVideoTriplebuffering() { - theApp.tripleBuffering = !theApp.tripleBuffering; + theApp.tripleBuffering = !theApp.tripleBuffering; + if( theApp.display ) { + theApp.display->setOption( _T("tripleBuffering"), theApp.tripleBuffering ); + } } + void MainWnd::OnUpdateOptionsVideoTriplebuffering(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.tripleBuffering); + pCmdUI->SetCheck(theApp.tripleBuffering); } void MainWnd::OnOptionsVideoDdrawemulationonly() { - theApp.ddrawEmulationOnly = !theApp.ddrawEmulationOnly; + theApp.ddrawEmulationOnly = !theApp.ddrawEmulationOnly; + if( theApp.display ) { + theApp.display->setOption( _T("ddrawEmulationOnly"), theApp.ddrawEmulationOnly ); + } } + void MainWnd::OnUpdateOptionsVideoDdrawemulationonly(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.ddrawEmulationOnly); } + void MainWnd::OnOptionsVideoDdrawusevideomemory() { - theApp.ddrawUseVideoMemory = !theApp.ddrawUseVideoMemory; + theApp.ddrawUseVideoMemory = !theApp.ddrawUseVideoMemory; + if( theApp.display ) { + theApp.display->setOption( _T("ddrawUseVideoMemory"), theApp.ddrawUseVideoMemory ); + } } + void MainWnd::OnUpdateOptionsVideoDdrawusevideomemory(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.ddrawUseVideoMemory); @@ -457,9 +508,10 @@ void MainWnd::OnOptionsVideoRenderoptionsD3dnofilter() { - theApp.d3dFilter = 0; - if(theApp.display) - theApp.display->setOption("d3dFilter", 0); + theApp.d3dFilter = 0; + if( theApp.display ) { + theApp.display->setOption( _T("d3dFilter"), theApp.d3dFilter ); + } } void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dnofilter(CCmdUI* pCmdUI) @@ -467,61 +519,76 @@ pCmdUI->SetCheck(theApp.d3dFilter == 0); } + void MainWnd::OnOptionsVideoRenderoptionsD3dbilinear() { - theApp.d3dFilter = 1; - if(theApp.display) - theApp.display->setOption("d3dFilter", 1); + theApp.d3dFilter = 1; + if( theApp.display ) { + theApp.display->setOption( _T("d3dFilter"), theApp.d3dFilter ); + } } + void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dbilinear(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.d3dFilter == 1); } + void MainWnd::OnOptionsVideoRenderoptionsGlnearest() { - theApp.glFilter = 0; - if(theApp.display) - theApp.display->setOption("glFilter", 0); + theApp.glFilter = 0; + if( theApp.display ) { + theApp.display->setOption( _T("glFilter"), theApp.glFilter ); + } } + void MainWnd::OnUpdateOptionsVideoRenderoptionsGlnearest(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.glFilter == 0); } + void MainWnd::OnOptionsVideoRenderoptionsGlbilinear() { - theApp.glFilter = 1; - if(theApp.display) - theApp.display->setOption("glFilter", 1); + theApp.glFilter = 1; + if( theApp.display ) { + theApp.display->setOption( _T("glFilter"), theApp.glFilter ); + } } + void MainWnd::OnUpdateOptionsVideoRenderoptionsGlbilinear(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.glFilter == 1); } + void MainWnd::OnOptionsVideoRenderoptionsGltriangle() { - theApp.glType = 0; - if(theApp.display) - theApp.display->setOption("glType", 0); + theApp.glType = 0; + if( theApp.display ) { + theApp.display->setOption( _T("glType"), theApp.glType ); + } } + void MainWnd::OnUpdateOptionsVideoRenderoptionsGltriangle(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.glType == 0); } + void MainWnd::OnOptionsVideoRenderoptionsGlquads() { - theApp.glType = 1; - if(theApp.display) - theApp.display->setOption("glType", 1); + theApp.glType = 1; + if( theApp.display ) { + theApp.display->setOption( _T("glType"), theApp.glType ); + } } + void MainWnd::OnUpdateOptionsVideoRenderoptionsGlquads(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.glType == 1); @@ -529,6 +596,7 @@ void MainWnd::OnOptionsVideoRenderoptionsSelectskin() { +#ifndef NOSKINS LPCTSTR exts[] = {".ini" }; CString filter = winLoadFilter(IDS_FILTER_INI); CString title = winResLoadString(IDS_SELECT_SKIN_FILE); @@ -562,6 +630,9 @@ theApp.winUpdateSkin(); theApp.winAccelMgr.UpdateMenu(theApp.menu); +#else + systemMessage( 0, _T("This build of VBA does not support skins!") ); +#endif } void MainWnd::OnUpdateOptionsVideoRenderoptionsSelectskin(CCmdUI* pCmdUI) @@ -572,9 +643,13 @@ void MainWnd::OnOptionsVideoRenderoptionsSkin() { +#ifndef NOSKINS theApp.skinEnabled = !theApp.skinEnabled; theApp.updateRenderMethod(true); theApp.winAccelMgr.UpdateMenu(theApp.menu); +#else + systemMessage( 0, _T("This build of VBA does not support skins!") ); +#endif } void MainWnd::OnUpdateOptionsVideoRenderoptionsSkin(CCmdUI* pCmdUI) @@ -610,6 +685,8 @@ void MainWnd::OnOptionsEmulatorSynchronize() { synchronize = !synchronize; + if (synchronize) + theApp.throttle = false; } void MainWnd::OnUpdateOptionsEmulatorSynchronize(CCmdUI* pCmdUI) @@ -637,17 +714,6 @@ pCmdUI->SetCheck(theApp.speedupToggle); } -void MainWnd::OnOptionsEmulatorRemoveintrosgba() -{ - // theApp.removeIntros = !theApp.removeIntros; -} - -void MainWnd::OnUpdateOptionsEmulatorRemoveintrosgba(CCmdUI* pCmdUI) -{ - pCmdUI->Enable(false); - // pCmdUI->SetCheck(theApp.removeIntros); -} - void MainWnd::OnOptionsEmulatorAutomaticallyipspatch() { theApp.autoIPS = !theApp.autoIPS; @@ -683,33 +749,53 @@ theApp.autoHideMenu = !theApp.autoHideMenu; } +void MainWnd::OnOptionsEmulatorGenericflashcard() +{ + if(emulating && theApp.cartridgeType == IMAGE_GB) + theApp.winGenericflashcardEnable = !theApp.winGenericflashcardEnable; +} + +void MainWnd::OnUpdateOptionsEmulatorGenericflashcard(CCmdUI* pCmdUI) +{ + if(emulating && theApp.cartridgeType == IMAGE_GB) + pCmdUI->SetCheck(theApp.winGenericflashcardEnable); + else + pCmdUI->SetCheck(false); + + pCmdUI->Enable(emulating && theApp.cartridgeType == IMAGE_GB); +} + void MainWnd::OnUpdateOptionsEmulatorAutohidemenu(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.autoHideMenu); } + void MainWnd::OnOptionsEmulatorRewindinterval() { - RewindInterval dlg(theApp.rewindTimer/6); - int v = dlg.DoModal(); - - if(v >= 0) { - theApp.rewindTimer = v*6; // convert to a multiple of 10 frames - regSetDwordValue("rewindTimer", v); - if(v == 0) { - if(theApp.rewindMemory) - free(theApp.rewindMemory); - theApp.rewindMemory = NULL; - theApp.rewindCount = 0; - theApp.rewindCounter = 0; - theApp.rewindSaveNeeded = false; - } else { - if(theApp.rewindMemory == NULL) - theApp.rewindMemory = (char *)malloc(8*REWIND_SIZE); - } - } + RewindInterval dlg(theApp.rewindTimer/6); + int v = (int)dlg.DoModal(); + + if( v >= 0 ) { + theApp.rewindTimer = v*6; // convert to a multiple of 10 frames + regSetDwordValue("rewindTimer", v); + if(v == 0) { + if(theApp.rewindMemory) { + free(theApp.rewindMemory); + theApp.rewindMemory = NULL; + } + theApp.rewindCount = 0; + theApp.rewindCounter = 0; + theApp.rewindSaveNeeded = false; + } else { + if(theApp.rewindMemory == NULL) { + theApp.rewindMemory = (char *)malloc(8*REWIND_SIZE); + } + } + } } + BOOL MainWnd::OnOptionsEmulatorShowSpeed(UINT nID) { switch(nID) { @@ -818,7 +904,9 @@ void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash512k(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.winFlashSize == 0x10000); + // changed theApp.winFlashSize to flashSize to reflect the actual + // flashsize value used by the emu (it can change upon battery loading) + pCmdUI->SetCheck(flashSize == 0x10000); } void MainWnd::OnOptionsEmulatorSavetypeFlash1m() @@ -829,7 +917,9 @@ void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.winFlashSize == 0x20000); + // changed theApp.winFlashSize to flashSize to reflect the actual + // flashsize value used by the emu (it can change upon battery loading) + pCmdUI->SetCheck(flashSize == 0x20000); } void MainWnd::OnOptionsEmulatorUsebiosfile() @@ -900,6 +990,7 @@ { soundOffFlag = true; soundShutdown(); + theApp.soundInitialized = false; } void MainWnd::OnUpdateOptionsSoundOff(CCmdUI* pCmdUI) @@ -1456,11 +1547,13 @@ void MainWnd::OnOptionsFilterDisablemmx() { +#ifdef MMX theApp.disableMMX = !theApp.disableMMX; if(!theApp.disableMMX) cpu_mmx = theApp.detectMMX(); else cpu_mmx = 0; +#endif } void MainWnd::OnUpdateOptionsFilterDisablemmx(CCmdUI* pCmdUI) @@ -1650,15 +1743,15 @@ void MainWnd::winConfirmMode() { - if(theApp.renderMethod == DIRECT_DRAW && theApp.videoOption > VIDEO_4X) { - theApp.winCheckFullscreen(); - ModeConfirm dlg(theApp.m_pMainWnd); - - if(!dlg.DoModal()) { - theApp.updateVideoSize(ID_OPTIONS_VIDEO_X2); - } - } - theApp.winAccelMgr.UpdateMenu(theApp.menu); + if( theApp.videoOption > VIDEO_4X ) { + theApp.winCheckFullscreen(); + ModeConfirm dlg(theApp.m_pMainWnd); + + if(!dlg.DoModal()) { + theApp.updateVideoSize(ID_OPTIONS_VIDEO_X2); + } + } + theApp.winAccelMgr.UpdateMenu(theApp.menu); } void MainWnd::OnOptionsVideoFullscreenmaxscale() @@ -1668,4 +1761,34 @@ theApp.winCheckFullscreen(); dlg.DoModal(); + + if( theApp.display ) { + theApp.display->setOption( _T("maxScale"), theApp.fsMaxScale ); + } +} + + +void MainWnd::OnOptionsEmulatorGameoverrides() +{ + if(emulating && theApp.cartridgeType == 0) { + GameOverrides dlg(this); + dlg.DoModal(); + } +} + +void MainWnd::OnUpdateOptionsEmulatorGameoverrides(CCmdUI* pCmdUI) +{ + pCmdUI->Enable(emulating && (theApp.cartridgeType == 0)); +} + +void MainWnd::OnOptionsSoundHardwareacceleration() +{ + theApp.dsoundDisableHardwareAcceleration = !theApp.dsoundDisableHardwareAcceleration; + systemSoundShutdown(); + systemSoundInit(); +} + +void MainWnd::OnUpdateOptionsSoundHardwareacceleration(CCmdUI *pCmdUI) +{ + pCmdUI->SetCheck(!theApp.dsoundDisableHardwareAcceleration); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MainWndTools.cpp ./src/win32/MainWndTools.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MainWndTools.cpp 2004-05-13 23:21:49 +0900 +++ ./src/win32/MainWndTools.cpp 2006-08-25 22:09:04 +0900 @@ -51,7 +51,7 @@ extern bool debugger; extern int emulating; -extern int remoteSocket; +extern SOCKET remoteSocket; extern void remoteCleanUp(); extern void remoteSetSockets(SOCKET, SOCKET); @@ -205,7 +205,7 @@ remoteSetSockets(wait.getListenSocket(), wait.getSocket()); debugger = true; emulating = 1; - theApp.cartridgeType = 0; + theApp.cartridgeType = IMAGE_GBA; theApp.filename = "\\gnu_stub"; rom = (u8 *)malloc(0x2000000); workRAM = (u8 *)calloc(1, 0x40000); @@ -214,7 +214,7 @@ paletteRAM = (u8 *)calloc(1,0x400); vram = (u8 *)calloc(1, 0x20000); oam = (u8 *)calloc(1, 0x400); - pix = (u8 *)calloc(1, 4 * 240 * 160); + pix = (u8 *)calloc(1, 4 * 241 * 162); ioMem = (u8 *)calloc(1, 0x400); theApp.emulator = GBASystem; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MapView.cpp ./src/win32/MapView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MapView.cpp 2004-05-13 23:21:38 +0900 +++ ./src/win32/MapView.cpp 2006-06-07 06:04:21 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -465,6 +465,7 @@ bg = 2; } + void MapView::OnRefresh() { paint(); @@ -511,6 +512,12 @@ case 5: renderMode5(); break; + case 6: + renderMode5(); + break; + case 7: + renderMode5(); + break; } enableButtons(mode); SIZE s; @@ -759,7 +766,7 @@ u32 base = ((control >> 8) & 0x1f) * 0x800 + 0x6000000; // all text bgs (16 bits) - if(mode == 0 ||(mode < 3 && bg < 2)) { + if(mode == 0 ||(mode < 3 && bg < 2) || mode == 6 || mode == 7) { return GetTextClickAddress(base, x, y); } // rot bgs (8 bits) @@ -779,8 +786,8 @@ u8 *colors = (u8 *)lParam; mapViewZoom.setColors(colors); - int x = wParam & 0xffff; - int y = (wParam >> 16); + int x = (int)(wParam & 0xffff); + int y = (int)(wParam >> 16); CString buffer; buffer.Format("(%d,%d)", x, y); @@ -791,7 +798,7 @@ GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer); int mode = DISPCNT & 7; - if(mode >= 3) { + if(mode >= 3 && mode <=5) { // bitmap modes GetDlgItem(IDC_TILE_NUM)->SetWindowText("---"); GetDlgItem(IDC_FLIP)->SetWindowText("--"); @@ -991,36 +998,39 @@ fclose(fp); } -void MapView::OnSave() +void MapView::OnSave() { - CString filename; + if(rom != NULL) + { + CString filename; + + if(theApp.captureFormat == 0) + filename = "map.png"; + else + filename = "map.bmp"; + + LPCTSTR exts[] = {".png", ".bmp" }; + + CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); + CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); + + FileDlg dlg(this, + filename, + filter, + theApp.captureFormat ? 2 : 1, + theApp.captureFormat ? "BMP" : "PNG", + exts, + "", + title, + true); - if(theApp.captureFormat == 0) - filename = "map.png"; - else - filename = "map.bmp"; - - LPCTSTR exts[] = {".png", ".bmp" }; - - CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); - CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); - - FileDlg dlg(this, - filename, - filter, - theApp.captureFormat ? 2 : 1, - theApp.captureFormat ? "BMP" : "PNG", - exts, - "", - title, - true); + if(dlg.DoModal() == IDCANCEL) { + return; + } - if(dlg.DoModal() == IDCANCEL) { - return; + if(dlg.getFilterIndex() == 2) + saveBMP(dlg.GetPathName()); + else + savePNG(dlg.GetPathName()); } - - if(dlg.getFilterIndex() == 2) - saveBMP(dlg.GetPathName()); - else - savePNG(dlg.GetPathName()); } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MapView.h ./src/win32/MapView.h --- ../VisualBoyAdvance-1.7.2/src/win32/MapView.h 2004-05-13 22:38:49 +0900 +++ ./src/win32/MapView.h 2006-05-27 23:47:33 +0900 @@ -31,7 +31,7 @@ #include "ZoomControl.h" #include "ResizeDlg.h" #include "IUpdate.h" -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView ///////////////////////////////////////////////////////////////////////////// // MapView dialog diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewer.cpp ./src/win32/MemoryViewer.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewer.cpp 2004-05-13 23:21:13 +0900 +++ ./src/win32/MemoryViewer.cpp 2006-05-27 23:47:33 +0900 @@ -535,8 +535,8 @@ } LRESULT MemoryViewer::OnWMChar(WPARAM wParam, LPARAM LPARAM) -{ - if(OnEditInput(wParam)) +{ // The WM_CHAR message uses Unicode Transformation Format (UTF)-16. + if(OnEditInput((UINT)(wParam & 0xFFFF))) return 0; return 1; } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewer.h ./src/win32/MemoryViewer.h --- ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewer.h 2004-05-13 22:38:21 +0900 +++ ./src/win32/MemoryViewer.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_MEMORYVIEWER_H__52C50474_5399_4D0B_A3E4_4C52C4E0EAA0__INCLUDED_) #define AFX_MEMORYVIEWER_H__52C50474_5399_4D0B_A3E4_4C52C4E0EAA0__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewerAddressSize.h ./src/win32/MemoryViewerAddressSize.h --- ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewerAddressSize.h 2004-05-13 22:38:09 +0900 +++ ./src/win32/MemoryViewerAddressSize.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_MEMORYVIEWERADDRESSSIZE_H__04605262_2B1D_4EED_A467_B6C56AC2CACD__INCLUDED_) #define AFX_MEMORYVIEWERADDRESSSIZE_H__04605262_2B1D_4EED_A467_B6C56AC2CACD__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewerDlg.cpp ./src/win32/MemoryViewerDlg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/MemoryViewerDlg.cpp 2004-05-13 23:20:50 +0900 +++ ./src/win32/MemoryViewerDlg.cpp 2005-09-03 21:29:23 +0900 @@ -320,14 +320,59 @@ void MemoryViewerDlg::OnSave() { - MemoryViewerAddressSize dlg; - CString buffer; + if(rom != NULL) + { + MemoryViewerAddressSize dlg; + CString buffer; - dlg.setAddress(m_viewer.getCurrentAddress()); + dlg.setAddress(m_viewer.getCurrentAddress()); - LPCTSTR exts[] = { ".dmp" }; + LPCTSTR exts[] = { ".dmp" }; - if(dlg.DoModal() == IDOK) { + if(dlg.DoModal() == IDOK) { + CString filter = theApp.winLoadFilter(IDS_FILTER_DUMP); + CString title = winResLoadString(IDS_SELECT_DUMP_FILE); + + FileDlg file(this, + buffer, + filter, + 0, + "DMP", + exts, + "", + title, + true); + if(file.DoModal() == IDOK) { + buffer = file.GetPathName(); + + FILE *f = fopen(buffer, "wb"); + + if(f == NULL) { + systemMessage(IDS_ERROR_CREATING_FILE, buffer); + return; + } + + int size = dlg.getSize(); + u32 addr = dlg.getAddress(); + + for(int i = 0; i < size; i++) { + fputc(CPUReadByteQuick(addr), f); + addr++; + } + + fclose(f); + } + } + } +} + +void MemoryViewerDlg::OnLoad() +{ + if(rom != NULL) + { + CString buffer; + LPCTSTR exts[] = { ".dmp" }; + CString filter = theApp.winLoadFilter(IDS_FILTER_DUMP); CString title = winResLoadString(IDS_SELECT_DUMP_FILE); @@ -338,84 +383,45 @@ "DMP", exts, "", - title, - true); + title, + false); + if(file.DoModal() == IDOK) { buffer = file.GetPathName(); - - FILE *f = fopen(buffer, "wb"); - + FILE *f = fopen(buffer, "rb"); if(f == NULL) { - systemMessage(IDS_ERROR_CREATING_FILE, buffer); + systemMessage(IDS_CANNOT_OPEN_FILE, + "Cannot open file %s", + buffer); return; } - - int size = dlg.getSize(); - u32 addr = dlg.getAddress(); - - for(int i = 0; i < size; i++) { - fputc(CPUReadByteQuick(addr), f); - addr++; - } - - fclose(f); - } - } -} - -void MemoryViewerDlg::OnLoad() -{ - CString buffer; - LPCTSTR exts[] = { ".dmp" }; - - CString filter = theApp.winLoadFilter(IDS_FILTER_DUMP); - CString title = winResLoadString(IDS_SELECT_DUMP_FILE); - - FileDlg file(this, - buffer, - filter, - 0, - "DMP", - exts, - "", - title, - false); - - if(file.DoModal() == IDOK) { - buffer = file.GetPathName(); - FILE *f = fopen(buffer, "rb"); - if(f == NULL) { - systemMessage(IDS_CANNOT_OPEN_FILE, - "Cannot open file %s", - buffer); - return; - } - MemoryViewerAddressSize dlg; + MemoryViewerAddressSize dlg; - fseek(f, 0, SEEK_END); - int size = ftell(f); + fseek(f, 0, SEEK_END); + int size = ftell(f); - fseek(f, 0, SEEK_SET); + fseek(f, 0, SEEK_SET); - dlg.setAddress(m_viewer.getCurrentAddress()); - dlg.setSize(size); + dlg.setAddress(m_viewer.getCurrentAddress()); + dlg.setSize(size); - if(dlg.DoModal() == IDOK) { - int size = dlg.getSize(); - u32 addr = dlg.getAddress(); - - for(int i = 0; i < size; i++) { - int c = fgetc(f); - if(c == -1) - break; - CPUWriteByteQuick(addr, c); - addr++; + if(dlg.DoModal() == IDOK) { + int size = dlg.getSize(); + u32 addr = dlg.getAddress(); + + for(int i = 0; i < size; i++) { + int c = fgetc(f); + if(c == -1) + break; + CPUWriteByteQuick(addr, c); + addr++; + } + OnRefresh(); } - OnRefresh(); + fclose(f); } - fclose(f); - } + } } void MemoryViewerDlg::PostNcDestroy() diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ModeConfirm.cpp ./src/win32/ModeConfirm.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/ModeConfirm.cpp 2004-05-13 23:20:38 +0900 +++ ./src/win32/ModeConfirm.cpp 2006-06-07 06:04:21 +0900 @@ -100,7 +100,7 @@ // EXCEPTION: OCX Property Pages should return FALSE } -void ModeConfirm::OnTimer(UINT nIDEvent) +void ModeConfirm::OnTimer(UINT_PTR nIDEvent) { CString buffer; count--; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ModeConfirm.h ./src/win32/ModeConfirm.h --- ../VisualBoyAdvance-1.7.2/src/win32/ModeConfirm.h 2004-05-13 22:37:41 +0900 +++ ./src/win32/ModeConfirm.h 2006-06-07 06:04:21 +0900 @@ -34,7 +34,7 @@ // Construction public: int count; - UINT timer; + UINT_PTR timer; ModeConfirm(CWnd* pParent); // standard constructor // Dialog Data @@ -60,7 +60,7 @@ afx_msg void OnOk(); afx_msg void OnDestroy(); virtual BOOL OnInitDialog(); - afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnTimer(UINT_PTR nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/OamView.cpp ./src/win32/OamView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/OamView.cpp 2004-05-13 23:20:26 +0900 +++ ./src/win32/OamView.cpp 2005-09-03 21:29:23 +0900 @@ -463,37 +463,40 @@ void OamView::OnSave() { - CString captureBuffer; - - if(theApp.captureFormat == 0) - captureBuffer = "oam.png"; - else - captureBuffer = "oam.bmp"; - - LPCTSTR exts[] = {".png", ".bmp" }; - - CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); - CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); - - FileDlg dlg(this, - captureBuffer, - filter, - theApp.captureFormat ? 2 : 1, - theApp.captureFormat ? "BMP" : "PNG", - exts, - "", - title, - true); - - if(dlg.DoModal() == IDCANCEL) { - return; + if(rom != NULL) + { + CString captureBuffer; + + if(theApp.captureFormat == 0) + captureBuffer = "oam.png"; + else + captureBuffer = "oam.bmp"; + + LPCTSTR exts[] = {".png", ".bmp" }; + + CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); + CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); + + FileDlg dlg(this, + captureBuffer, + filter, + theApp.captureFormat ? 2 : 1, + theApp.captureFormat ? "BMP" : "PNG", + exts, + "", + title, + true); + + if(dlg.DoModal() == IDCANCEL) { + return; + } + captureBuffer = dlg.GetPathName(); + + if(dlg.getFilterIndex() == 2) + saveBMP(captureBuffer); + else + savePNG(captureBuffer); } - captureBuffer = dlg.GetPathName(); - - if(dlg.getFilterIndex() == 2) - saveBMP(captureBuffer); - else - savePNG(captureBuffer); } BOOL OamView::OnInitDialog() diff -urN ../VisualBoyAdvance-1.7.2/src/win32/OpenGL.cpp ./src/win32/OpenGL.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/OpenGL.cpp 2004-05-13 23:20:15 +0900 +++ ./src/win32/OpenGL.cpp 2006-08-11 19:58:39 +0900 @@ -1,6 +1,7 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005-2006 VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,16 +18,25 @@ // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" + #include "MainWnd.h" -#include #include "../System.h" #include "../GBA.h" #include "../Globals.h" #include "../Text.h" +#include "../Util.h" +#include "../gb/gbGlobals.h" + +#include -#include "Reg.h" -#include "resource.h" +// OpenGL +#include // main include file +typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int ); + +extern int Init_2xSaI(u32); +extern void winlog(const char *,...); +extern int systemSpeed; #ifdef _DEBUG #define new DEBUG_NEW @@ -36,530 +46,624 @@ #ifdef MMX extern "C" bool cpu_mmx; - extern bool detectMMX(); #endif -extern int Init_2xSaI(u32); -extern void winlog(const char *,...); -extern int systemSpeed; class OpenGLDisplay : public IDisplay { private: - HDC hDC; - HGLRC hglrc; - GLuint texture; - int width; - int height; - float size; - u8 *filterData; - bool failed; - - bool initializeTexture(int w, int h); - void updateFiltering(int); -public: - OpenGLDisplay(); - virtual ~OpenGLDisplay(); + HDC hDC; + HGLRC hglrc; + GLuint texture; + int width; + int height; + float size; + u8 *filterData; + RECT destRect; + bool failed; + + void initializeMatrices( int w, int h ); + bool initializeTexture( int w, int h ); + void updateFiltering( int value ); + void setVSync( int interval = 1 ); + void calculateDestRect( int w, int h ); - virtual bool initialize(); - virtual void cleanup(); - virtual void render(); - virtual void checkFullScreen(); - virtual void renderMenu(); - virtual void clear(); - virtual bool changeRenderSize(int w, int h); - virtual void resize(int w, int h); - virtual DISPLAY_TYPE getType() { return OPENGL; }; - virtual void setOption(const char *, int); - virtual int selectFullScreenMode(GUID **); +public: + OpenGLDisplay(); + virtual ~OpenGLDisplay(); + virtual DISPLAY_TYPE getType() { return OPENGL; }; + + virtual bool initialize(); + virtual void cleanup(); + virtual void render(); + virtual void renderMenu(); + virtual void clear(); + virtual bool changeRenderSize( int w, int h ); + virtual void resize( int w, int h ); + virtual void setOption( const char *, int ); + virtual int selectFullScreenMode( GUID ** ); }; + OpenGLDisplay::OpenGLDisplay() { - hDC = NULL; - hglrc = NULL; - texture = 0; - width = 0; - height = 0; - size = 0.0f; - filterData = (u8 *)malloc(4*4*256*240); - failed = false; + hDC = NULL; + hglrc = NULL; + texture = 0; + width = 0; + height = 0; + size = 0.0f; + filterData = (u8 *)malloc(4*4*256*240); + failed = false; } + OpenGLDisplay::~OpenGLDisplay() { - cleanup(); + cleanup(); } + void OpenGLDisplay::cleanup() { - if(texture != 0) { - glDeleteTextures(1, &texture); - texture = 0; - } - if(hglrc != NULL) { - wglDeleteContext(hglrc); - wglMakeCurrent(NULL, NULL); - hglrc = NULL; - } - if(hDC != NULL) { - ReleaseDC(*theApp.m_pMainWnd, hDC); - hDC = NULL; - } - if(filterData) { - free(filterData); - filterData = NULL; - } - width = 0; - height = 0; - size = 0.0f; + if(texture != 0) { + glDeleteTextures(1, &texture); + texture = 0; + } + + if(hglrc != NULL) { + wglDeleteContext(hglrc); + wglMakeCurrent(NULL, NULL); + hglrc = NULL; + } + + if(hDC != NULL) { + ReleaseDC(*theApp.m_pMainWnd, hDC); + hDC = NULL; + } + + if(filterData) { + free(filterData); + filterData = NULL; + } + + width = 0; + height = 0; + size = 0.0f; } + bool OpenGLDisplay::initialize() { - theApp.sizeX = 240; - theApp.sizeY = 160; + switch( theApp.cartridgeType ) + { + case IMAGE_GBA: + theApp.sizeX = 240; + theApp.sizeY = 160; + break; + case IMAGE_GB: + if ( gbBorderOn ) + { + theApp.sizeX = 256; + theApp.sizeY = 224; + } + else + { + theApp.sizeX = 160; + theApp.sizeY = 144; + } + break; + } + + + switch(theApp.videoOption) + { + case VIDEO_1X: + theApp.surfaceSizeX = theApp.sizeX; + theApp.surfaceSizeY = theApp.sizeY; + break; + case VIDEO_2X: + theApp.surfaceSizeX = theApp.sizeX * 2; + theApp.surfaceSizeY = theApp.sizeY * 2; + break; + case VIDEO_3X: + theApp.surfaceSizeX = theApp.sizeX * 3; + theApp.surfaceSizeY = theApp.sizeY * 3; + break; + case VIDEO_4X: + theApp.surfaceSizeX = theApp.sizeX * 4; + theApp.surfaceSizeY = theApp.sizeY * 4; + break; + case VIDEO_320x240: + case VIDEO_640x480: + case VIDEO_800x600: + case VIDEO_OTHER: + { + if( theApp.fullScreenStretch ) { + theApp.surfaceSizeX = theApp.fsWidth; + theApp.surfaceSizeY = theApp.fsHeight; + } else { + float scaleX = (float)theApp.fsWidth / (float)theApp.sizeX; + float scaleY = (float)theApp.fsHeight / (float)theApp.sizeY; + float min = ( scaleX < scaleY ) ? scaleX : scaleY; + if( theApp.fsMaxScale ) + min = ( min > (float)theApp.fsMaxScale ) ? (float)theApp.fsMaxScale : min; + theApp.surfaceSizeX = (int)((float)theApp.sizeX * min); + theApp.surfaceSizeY = (int)((float)theApp.sizeY * min); + } + } + break; + } + + theApp.rect.left = 0; + theApp.rect.top = 0; + theApp.rect.right = theApp.sizeX; + theApp.rect.bottom = theApp.sizeY; + + theApp.dest.left = 0; + theApp.dest.top = 0; + theApp.dest.right = theApp.surfaceSizeX; + theApp.dest.bottom = theApp.surfaceSizeY; + + DWORD style = WS_POPUP | WS_VISIBLE; + DWORD styleEx = 0; + + if( theApp.videoOption <= VIDEO_4X ) + style |= WS_OVERLAPPEDWINDOW; + else + styleEx = 0; + + if( theApp.videoOption <= VIDEO_4X ) + AdjustWindowRectEx( &theApp.dest, style, TRUE, styleEx ); + else + AdjustWindowRectEx( &theApp.dest, style, FALSE, styleEx ); + + int winSizeX = theApp.dest.right - theApp.dest.left; + int winSizeY = theApp.dest.bottom - theApp.dest.top; + int x = 0, y = 0; + + if( theApp.videoOption <= VIDEO_4X ) { + x = theApp.windowPositionX; + y = theApp.windowPositionY; + } else { + winSizeX = theApp.fsWidth; + winSizeY = theApp.fsHeight; + } + + // Create a window + MainWnd *pWnd = new MainWnd; + theApp.m_pMainWnd = pWnd; + + pWnd->CreateEx( + styleEx, + theApp.wndClass, + "VisualBoyAdvance", + style, + x,y,winSizeX,winSizeY, + NULL, + 0 ); + + if (!(HWND)*pWnd) { + winlog("Error creating Window %08x\n", GetLastError()); + return FALSE; + } + + theApp.updateMenuBar(); + + theApp.adjustDestRect(); + + theApp.mode320Available = FALSE; + theApp.mode640Available = FALSE; + theApp.mode800Available = FALSE; + + CDC *dc = pWnd->GetDC(); + HDC hDC = dc->GetSafeHdc(); + + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), + 1, // version number + PFD_DRAW_TO_WINDOW | // support window + PFD_SUPPORT_OPENGL | // support OpenGL + PFD_DOUBLEBUFFER, // double buffered + PFD_TYPE_RGBA, // RGBA type + 24, // 24-bit color depth + 0, 0, 0, 0, 0, 0, // color bits ignored + 0, // no alpha buffer + 0, // shift bit ignored + 0, // no accumulation buffer + 0, 0, 0, 0, // accum bits ignored + 32, // 32-bit z-buffer + 0, // no stencil buffer + 0, // no auxiliary buffer + PFD_MAIN_PLANE, // main layer + 0, // reserved + 0, 0, 0 // layer masks ignored + }; + + int iPixelFormat; + if( !(iPixelFormat = ChoosePixelFormat( hDC, &pfd )) ) { + winlog( "Failed ChoosePixelFormat\n" ); + return false; + } + + // obtain detailed information about + // the device context's first pixel format + if( !( DescribePixelFormat( + hDC, + iPixelFormat, + sizeof(PIXELFORMATDESCRIPTOR), + &pfd ) ) ) + { + winlog( "Failed DescribePixelFormat\n" ); + return false; + } + + if( !SetPixelFormat( hDC, iPixelFormat, &pfd ) ) { + winlog( "Failed SetPixelFormat\n" ); + return false; + } + + if( !( hglrc = wglCreateContext( hDC ) ) ) { + winlog( "Failed wglCreateContext\n" ); + return false; + } + + if( !wglMakeCurrent(hDC, hglrc) ) { + winlog( "Failed wglMakeCurrent\n" ); + return false; + } + + pWnd->ReleaseDC( dc ); + + // setup 2D gl environment + glPushAttrib( GL_ENABLE_BIT ); + glDisable( GL_DEPTH_TEST ); + glDisable( GL_CULL_FACE ); + glEnable( GL_TEXTURE_2D ); + + initializeMatrices( theApp.surfaceSizeX, theApp.surfaceSizeY ); + + setVSync( theApp.vsync ); - switch(theApp.videoOption) { - case VIDEO_1X: - theApp.surfaceSizeX = theApp.sizeX; - theApp.surfaceSizeY = theApp.sizeY; - break; - case VIDEO_2X: - theApp.surfaceSizeX = theApp.sizeX * 2; - theApp.surfaceSizeY = theApp.sizeY * 2; - break; - case VIDEO_3X: - theApp.surfaceSizeX = theApp.sizeX * 3; - theApp.surfaceSizeY = theApp.sizeY * 3; - break; - case VIDEO_4X: - theApp.surfaceSizeX = theApp.sizeX * 4; - theApp.surfaceSizeY = theApp.sizeY * 4; - break; - case VIDEO_320x240: - case VIDEO_640x480: - case VIDEO_800x600: - case VIDEO_OTHER: - { - RECT r; - ::GetWindowRect(GetDesktopWindow(), &r); - theApp.fsWidth = r.right - r.left; - theApp.fsHeight = r.bottom - r.top; - - /* Need to fix this code later. For now, Fullscreen takes the whole - screen. - int scaleX = (fsWidth / sizeX); - int scaleY = (fsHeight / sizeY); - int min = scaleX < scaleY ? scaleX : scaleY; - surfaceSizeX = sizeX * min; - surfaceSizeY = sizeY * min; - if(fullScreenStretch) { - */ - theApp.surfaceSizeX = theApp.fsWidth; - theApp.surfaceSizeY = theApp.fsHeight; - // } - } - break; - } - - theApp.rect.left = 0; - theApp.rect.top = 0; - theApp.rect.right = theApp.sizeX; - theApp.rect.bottom = theApp.sizeY; - - theApp.dest.left = 0; - theApp.dest.top = 0; - theApp.dest.right = theApp.surfaceSizeX; - theApp.dest.bottom = theApp.surfaceSizeY; - - DWORD style = WS_POPUP | WS_VISIBLE; - DWORD styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) - style |= WS_OVERLAPPEDWINDOW; - else - styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) - AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx); - else - AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx); - - int winSizeX = theApp.dest.right-theApp.dest.left; - int winSizeY = theApp.dest.bottom-theApp.dest.top; - - if(theApp.videoOption > VIDEO_4X) { - winSizeX = theApp.fsWidth; - winSizeY = theApp.fsHeight; - } - - int x = 0; - int y = 0; - - if(theApp.videoOption <= VIDEO_4X) { - x = theApp.windowPositionX; - y = theApp.windowPositionY; - } - - // Create a window - MainWnd *pWnd = new MainWnd; - theApp.m_pMainWnd = pWnd; - - pWnd->CreateEx(styleEx, - theApp.wndClass, - "VisualBoyAdvance", - style, - x,y,winSizeX,winSizeY, - NULL, - 0); - - if (!(HWND)*pWnd) { - winlog("Error creating Window %08x\n", GetLastError()); - return FALSE; - } - - theApp.updateMenuBar(); - - theApp.adjustDestRect(); - - theApp.mode320Available = FALSE; - theApp.mode640Available = FALSE; - theApp.mode800Available = FALSE; - - CDC *dc = pWnd->GetDC(); - HDC hDC = dc->GetSafeHdc(); - - PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd - 1, // version number - PFD_DRAW_TO_WINDOW | // support window - PFD_SUPPORT_OPENGL | // support OpenGL - PFD_DOUBLEBUFFER, // double buffered - PFD_TYPE_RGBA, // RGBA type - 16, // 16-bit color depth - 0, 0, 0, 0, 0, 0, // color bits ignored - 0, // no alpha buffer - 0, // shift bit ignored - 0, // no accumulation buffer - 0, 0, 0, 0, // accum bits ignored - 32, // 32-bit z-buffer - 0, // no stencil buffer - 0, // no auxiliary buffer - PFD_MAIN_PLANE, // main layer - 0, // reserved - 0, 0, 0 // layer masks ignored - }; - int iPixelFormat; - - if(!(iPixelFormat = ChoosePixelFormat(hDC, &pfd))) { - winlog("Failed ChoosePixelFormat\n"); - return false; - } - - // obtain detailed information about - // the device context's first pixel format - if(!(DescribePixelFormat(hDC, iPixelFormat, - sizeof(PIXELFORMATDESCRIPTOR), &pfd))) { - winlog("Failed DescribePixelFormat\n"); - return false; - } - - if(!SetPixelFormat(hDC, iPixelFormat, &pfd)) { - winlog("Failed SetPixelFormat\n"); - return false; - } - - if(!(hglrc = wglCreateContext(hDC))) { - winlog("Failed wglCreateContext\n"); - return false; - } - - if(!wglMakeCurrent(hDC, hglrc)) { - winlog("Failed wglMakeCurrent\n"); - return false; - } - pWnd->ReleaseDC(dc); - - // setup 2D gl environment - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glEnable(GL_TEXTURE_2D); - - glViewport(0, 0, theApp.surfaceSizeX, theApp.surfaceSizeY); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble)(theApp.surfaceSizeX), (GLdouble)(theApp.surfaceSizeY), - 0.0, 0.0,1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - systemRedShift = 3; - systemGreenShift = 11; - systemBlueShift = 19; - systemColorDepth = 32; - theApp.fsColorDepth = 32; - - Init_2xSaI(32); #ifdef MMX - if(!theApp.disableMMX) - cpu_mmx = theApp.detectMMX(); - else - cpu_mmx = 0; + if(!theApp.disableMMX) + cpu_mmx = theApp.detectMMX(); + else + cpu_mmx = 0; #endif - - if(theApp.ddrawDebug) { - winlog("R shift: %d\n", systemRedShift); - winlog("G shift: %d\n", systemGreenShift); - winlog("B shift: %d\n", systemBlueShift); - } - - switch(systemColorDepth) { - case 16: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - case 24: - case 32: - { - for(int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - } - break; - } - theApp.updateFilter(); - theApp.updateIFB(); - - if(failed) - return false; - - pWnd->DragAcceptFiles(TRUE); - - return TRUE; + + systemRedShift = 3; + systemGreenShift = 11; + systemBlueShift = 19; + systemColorDepth = 32; + theApp.fsColorDepth = 32; + + Init_2xSaI(32); + + utilUpdateSystemColorMaps(); + theApp.updateFilter(); + theApp.updateIFB(); + + if(failed) + return false; + + pWnd->DragAcceptFiles(TRUE); + + return TRUE; } + void OpenGLDisplay::clear() { + glClear( GL_COLOR_BUFFER_BIT ); } + void OpenGLDisplay::renderMenu() { - checkFullScreen(); - if(theApp.m_pMainWnd) - theApp.m_pMainWnd->DrawMenuBar(); + checkFullScreen(); + if( theApp.m_pMainWnd ) + theApp.m_pMainWnd->DrawMenuBar(); } -void OpenGLDisplay::checkFullScreen() -{ - // if(tripleBuffering) - // pOpenGL->FlipToGDISurface(); -} void OpenGLDisplay::render() { - int pitch = theApp.filterWidth * 4 + 4; - u8 *data = pix + (theApp.sizeX+1)*4; - - if(theApp.filterFunction) { - data = filterData; - theApp.filterFunction(pix+pitch, - pitch, - (u8*)theApp.delta, - (u8*)filterData, - theApp.filterWidth*4*2, - theApp.filterWidth, - theApp.filterHeight); - } - - if(theApp.videoOption > VIDEO_4X && theApp.showSpeed) { - char buffer[30]; - if(theApp.showSpeed == 1) - sprintf(buffer, "%3d%%", systemSpeed); - else - sprintf(buffer, "%3d%%(%d, %d fps)", systemSpeed, - systemFrameSkip, - theApp.showRenderedFrames); - - if(theApp.filterFunction) { - int p = theApp.filterWidth * 4; - if(systemColorDepth == 24) - p = theApp.filterWidth * 6; - else if(systemColorDepth == 32) - p = theApp.filterWidth * 8; - if(theApp.showSpeedTransparent) - drawTextTransp((u8*)filterData, - p, - 10, - theApp.filterHeight*2-10, - buffer); - else - drawText((u8*)filterData, - p, - 10, - theApp.filterHeight*2-10, - buffer); - } else { - if(theApp.showSpeedTransparent) - drawTextTransp((u8*)pix, - pitch, - 10, - theApp.filterHeight-10, - buffer); - else - drawText((u8*)pix, - pitch, - 10, - theApp.filterHeight-10, - buffer); - } - } - - // Texturemap complete texture to surface so we have free scaling - // and antialiasing - int mult = 1; - if(theApp.filterFunction) { - glPixelStorei(GL_UNPACK_ROW_LENGTH, 2*theApp.sizeX); - mult = 2; - } else { - glPixelStorei(GL_UNPACK_ROW_LENGTH, theApp.sizeX+1); - } - - glTexSubImage2D( GL_TEXTURE_2D,0, - 0,0, mult*theApp.sizeX,mult*theApp.sizeY, - GL_RGBA,GL_UNSIGNED_BYTE,data); - - if(theApp.glType == 0) { - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(0.0, 0.0); glVertex3i(0, 0, 0); - glTexCoord2f(mult*theApp.sizeX/size, 0.0); glVertex3i(theApp.surfaceSizeX, 0, 0); - glTexCoord2f(0.0, mult*theApp.sizeY/size); glVertex3i(0, theApp.surfaceSizeY, 0); - glTexCoord2f(mult*theApp.sizeX/size, mult*theApp.sizeY/size); glVertex3i(theApp.surfaceSizeX, theApp.surfaceSizeY, 0); - glEnd(); - } else { - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); glVertex3i(0, 0, 0); - glTexCoord2f(mult*theApp.sizeX/size, 0.0); glVertex3i(theApp.surfaceSizeX, 0, 0); - glTexCoord2f(mult*theApp.sizeX/size, mult*theApp.sizeY/size); glVertex3i(theApp.surfaceSizeX, theApp.surfaceSizeY, 0); - glTexCoord2f(0.0, mult*theApp.sizeY/size); glVertex3i(0, theApp.surfaceSizeY, 0); - glEnd(); - } - - CDC *dc = theApp.m_pMainWnd->GetDC(); - - if(theApp.screenMessage) { - if(((GetTickCount() - theApp.screenMessageTime) < 3000) && - !theApp.disableStatusMessage) { - dc->SetTextColor(RGB(255,0,0)); - dc->SetBkMode(TRANSPARENT); - dc->TextOut(10, theApp.surfaceSizeY - 20, theApp.screenMessageBuffer); - } else { - theApp.screenMessage = false; - } - } - - SwapBuffers(dc->GetSafeHdc()); - - theApp.m_pMainWnd->ReleaseDC(dc); -} - -void OpenGLDisplay::resize(int w, int h) -{ - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble)(w), (GLdouble)(h), - 0.0, 0.0,1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -void OpenGLDisplay::updateFiltering(int value) -{ - switch(value) { - case 0: - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - break; - case 1: - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - break; - } -} - -bool OpenGLDisplay::initializeTexture(int w, int h) -{ - int mySize = 256; - size = 256.0f; - if(w > 255 || h > 255) { - size = 512.0f; - mySize = 512; - } - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - - int filter = regQueryDwordValue("glFilter", 0); - if(filter < 0 || filter > 1) - filter = 0; - updateFiltering(filter); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mySize, mySize, 0, GL_RGBA, - GL_UNSIGNED_BYTE, NULL ); - width = w; - height = h; - - return true; -} - -bool OpenGLDisplay::changeRenderSize(int w, int h) -{ - if(width != w || height != h) { - if(texture != 0) { - glDeleteTextures(1, &texture); - texture = 0; - } - if(!initializeTexture(w, h)) { - failed = true; - return false; - } - } - return true; -} - -void OpenGLDisplay::setOption(const char *option, int value) -{ - if(!strcmp(option, "glFilter")) - updateFiltering(value); -} - -int OpenGLDisplay::selectFullScreenMode(GUID **) -{ - HWND wnd = GetDesktopWindow(); - RECT r; - GetWindowRect(wnd, &r); - int w = (r.right - r.left) & 4095; - int h = (r.bottom - r.top) & 4095; - HDC dc = GetDC(wnd); - int c = GetDeviceCaps(dc, BITSPIXEL); - ReleaseDC(wnd, dc); + clear(); - return (c << 24) | (w << 12) | h; + int pitch = theApp.filterWidth * 4 + 4; + u8 *data = pix + ( theApp.sizeX + 1 ) * 4; + + // apply pixel filter + if(theApp.filterFunction) { + data = filterData; + theApp.filterFunction( + pix + pitch, + pitch, + (u8*)theApp.delta, + (u8*)filterData, + theApp.filterWidth * 4 * 2, + theApp.filterWidth, + theApp.filterHeight); + } + + // Texturemap complete texture to surface + // so we have free scaling and antialiasing + int mult; + if( theApp.filterFunction ) { + glPixelStorei( GL_UNPACK_ROW_LENGTH, theApp.sizeX << 1 ); + mult = 2; + } else { + glPixelStorei( GL_UNPACK_ROW_LENGTH, theApp.sizeX + 1 ); + mult = 1; + } + + glTexSubImage2D( + GL_TEXTURE_2D, + 0, + 0, + 0, + mult * theApp.sizeX, + mult * theApp.sizeY, + GL_RGBA, + GL_UNSIGNED_BYTE, + data ); + + if( theApp.glType == 0 ) { + glBegin( GL_TRIANGLE_STRIP ); + + glTexCoord2f( 0.0f, 0.0f ); + glVertex3i( 0, 0, 0 ); + + glTexCoord2f( (float)(mult * theApp.sizeX) / size, 0.0f ); + glVertex3i( theApp.surfaceSizeX, 0, 0 ); + + glTexCoord2f( 0.0f, (float)(mult * theApp.sizeY) / size ); + glVertex3i( 0, theApp.surfaceSizeY, 0 ); + + glTexCoord2f( (float)(mult * theApp.sizeX) / size, (float)(mult * theApp.sizeY) / size ); + glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); + + glEnd(); + } else { + glBegin( GL_QUADS ); + + glTexCoord2f( 0.0f, 0.0f ); + glVertex3i( 0, 0, 0 ); + + glTexCoord2f( (float)(mult * theApp.sizeX) / size, 0.0f ); + glVertex3i( theApp.surfaceSizeX, 0, 0 ); + + glTexCoord2f( (float)(mult * theApp.sizeX) / size, (float)(mult * theApp.sizeY) / size ); + glVertex3i( theApp.surfaceSizeX, theApp.surfaceSizeY, 0 ); + + glTexCoord2f( 0.0f, (float)(mult * theApp.sizeY) / size ); + glVertex3i( 0, theApp.surfaceSizeY, 0 ); + + glEnd(); + } + + CDC *dc = theApp.m_pMainWnd->GetDC(); + + SwapBuffers( dc->GetSafeHdc() ); + // since OpenGL draws on the back buffer, + // we have to swap it to the front buffer to see it + + // draw informations with GDI on the front buffer + dc->SetBkMode( theApp.showSpeedTransparent ? TRANSPARENT : OPAQUE ); + if( theApp.showSpeed && ( theApp.videoOption > VIDEO_4X ) ) { + char buffer[30]; + if( theApp.showSpeed == 1 ) { + sprintf( buffer, "%3d%%", systemSpeed ); + } else { + sprintf( buffer, "%3d%%(%d, %d fps)", systemSpeed, systemFrameSkip, theApp.showRenderedFrames ); + } + dc->SetTextColor( RGB(0x00, 0x00, 0xFF) ); + dc->TextOut( 10, 20, buffer ); + } + if( theApp.screenMessage ) { + if( ( ( GetTickCount() - theApp.screenMessageTime ) < 3000 ) && !theApp.disableStatusMessage ) { + dc->SetTextColor( RGB(0xFF, 0x00, 0x00) ); + dc->TextOut( 10, theApp.surfaceSizeY - 20, theApp.screenMessageBuffer ); + } else { + theApp.screenMessage = false; + } + } + + theApp.m_pMainWnd->ReleaseDC( dc ); +} + + +void OpenGLDisplay::resize( int w, int h ) +{ + initializeMatrices( w, h ); +} + + +void OpenGLDisplay::updateFiltering( int value ) +{ + switch( value ) + { + case 0: + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + break; + case 1: + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + break; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); +} + + +void OpenGLDisplay::initializeMatrices( int w, int h ) +{ + if( theApp.fullScreenStretch ) { + glViewport( 0, 0, w, h ); + } else { + calculateDestRect( w, h ); + glViewport( + destRect.left, + destRect.top, + destRect.right - destRect.left, + destRect.bottom - destRect.top ); + } + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( + /* left */ 1.0f, + /* right */ (GLdouble)(w - 1), + /* bottom */ (GLdouble)(h - 1), + /* top */ 1.0f, + 0.0f, + 1.0f ); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +bool OpenGLDisplay::initializeTexture( int w, int h ) +{ + // size = 2^n + // w = 24 > size = 256 = 2^8 + // w = 255 > size = 256 = 2^8 + // w = 256 > size = 512 = 2^9 + // w = 300 > size = 512 = 2^9 + // OpenGL textures have to be square and a power of 2 + + float n1 = log10( (float)w ) / log10( 2.0f ); + float n2 = log10( (float)h ) / log10( 2.0f ); + float n = ( n1 > n2 ) ? n1 : n2; + + if( ((float)((int)n)) != n ) { + // round up + n = ((float)((int)n)) + 1.0f; + } + + size = pow( 2.0f, n ); + + glGenTextures( 1, &texture ); + glBindTexture( GL_TEXTURE_2D, texture ); + updateFiltering( theApp.glFilter ); + + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA, + (GLsizei)size, + (GLsizei)size, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + NULL ); + + width = w; + height = h; + + return ( glGetError() == GL_NO_ERROR) ? true : false; +} + + +void OpenGLDisplay::setVSync( int interval ) +{ + const char *extensions = (const char *)glGetString( GL_EXTENSIONS ); + + if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 ) { + winlog( "Error: WGL_EXT_swap_control extension not supported on your computer.\n" ); + return; + } else { + PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = NULL; + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" ); + if( wglSwapIntervalEXT ) { + wglSwapIntervalEXT( interval ); + } + } +} + + +bool OpenGLDisplay::changeRenderSize( int w, int h ) +{ + if( (width != w) || (height != h) ) { + if( texture != 0 ) { + glDeleteTextures( 1, &texture ); + texture = 0; + } + + if( !initializeTexture( w, h ) ) { + failed = true; + return false; + } + } + + return true; +} + + +void OpenGLDisplay::calculateDestRect( int w, int h ) +{ + float scaleX = (float)w / (float)width; + float scaleY = (float)h / (float)height; + float min = (scaleX < scaleY) ? scaleX : scaleY; + if( theApp.fsMaxScale && (min > theApp.fsMaxScale) ) { + min = (float)theApp.fsMaxScale; + } + destRect.left = 0; + destRect.top = 0; + destRect.right = (LONG)(width * min); + destRect.bottom = (LONG)(height * min); + if( destRect.right != w ) { + LONG diff = (w - destRect.right) / 2; + destRect.left += diff; + destRect.right += diff; + } + if( destRect.bottom != h ) { + LONG diff = (h - destRect.bottom) / 2; + destRect.top += diff; + destRect.bottom += diff; + } +} + + +void OpenGLDisplay::setOption( const char *option, int value ) +{ + if( !_tcscmp( option, _T("vsync") ) ) { + setVSync( value ); + } + + if( !_tcscmp( option, _T("glFilter") ) ) { + updateFiltering( value ); + } + + if( !_tcscmp( option, _T("maxScale") ) ) { + initializeMatrices( theApp.dest.right, theApp.dest.bottom ); + } + + if( !_tcscmp( option, _T("fullScreenStretch") ) ) { + initializeMatrices( theApp.dest.right, theApp.dest.bottom ); + } +} + + +int OpenGLDisplay::selectFullScreenMode( GUID ** ) +{ + HWND wnd = GetDesktopWindow(); + RECT r; + GetWindowRect( wnd, &r ); + int w = ( r.right - r.left ) & 0xFFF; + int h = ( r.bottom - r.top ) & 0xFFF; + HDC dc = GetDC( wnd ); + int c = GetDeviceCaps( dc, BITSPIXEL ); + ReleaseDC( wnd, dc ); + return (c << 24) | (w << 12) | h; } + IDisplay *newOpenGLDisplay() { - return new OpenGLDisplay(); + return new OpenGLDisplay(); } - diff -urN ../VisualBoyAdvance-1.7.2/src/win32/PaletteView.cpp ./src/win32/PaletteView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/PaletteView.cpp 2004-05-13 23:19:05 +0900 +++ ./src/win32/PaletteView.cpp 2005-09-03 21:29:23 +0900 @@ -109,49 +109,54 @@ void PaletteView::save(int which) { - CString captureBuffer; + if(rom != NULL) + { + CString captureBuffer; + + if(which == 0) + captureBuffer = "bg.pal"; + else + captureBuffer = "obj.pal"; - if(which == 0) - captureBuffer = "bg.pal"; - else - captureBuffer = "obj.pal"; - - LPCTSTR exts[] = {".pal", ".pal", ".act" }; + LPCTSTR exts[] = {".pal", ".pal", ".act" }; - CString filter = theApp.winLoadFilter(IDS_FILTER_PAL); - CString title = winResLoadString(IDS_SELECT_PALETTE_NAME); - FileDlg dlg(this, - captureBuffer, - filter, - 1, - "PAL", - exts, - "", - title, - true); - - if(dlg.DoModal() == IDCANCEL) { - return; - } - - PaletteViewControl *p = NULL; - - if(which == 0) - p = &paletteView; - else - p = &paletteViewOBJ; + CString filter = theApp.winLoadFilter(IDS_FILTER_PAL); + CString title = winResLoadString(IDS_SELECT_PALETTE_NAME); + FileDlg dlg(this, + captureBuffer, + filter, + 1, + "PAL", + exts, + "", + title, + true); + + if(dlg.DoModal() == IDCANCEL) { + return; + } + + captureBuffer = dlg.GetPathName(); + + PaletteViewControl *p = NULL; + + if(which == 0) + p = &paletteView; + else + p = &paletteViewOBJ; - switch(dlg.getFilterIndex()) { - case 0: - case 1: - p->saveMSPAL(captureBuffer); - break; - case 2: - p->saveJASCPAL(captureBuffer); - break; - case 3: - p->saveAdobe(captureBuffer); - break; + switch(dlg.getFilterIndex()) { + case 0: + case 1: + p->saveMSPAL(captureBuffer); + break; + case 2: + p->saveJASCPAL(captureBuffer); + break; + case 3: + p->saveAdobe(captureBuffer); + break; + } } } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/Reg.cpp ./src/win32/Reg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/Reg.cpp 2004-05-13 23:18:44 +0900 +++ ./src/win32/Reg.cpp 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ static char buffer[2048]; static HKEY vbKey = NULL; -static CString regVbaPath; +static CString *regVbaPath = NULL; #define VBA_PREF "preferences" @@ -38,7 +38,12 @@ NULL, &vbKey, &disp); - regVbaPath.Format("%s\\vba.ini", path); + if( regVbaPath != NULL ) { + delete regVbaPath; + regVbaPath = NULL; + } + regVbaPath = new CString(); + regVbaPath->Format("%s\\vba.ini", path); } void regShutdown() @@ -48,7 +53,7 @@ const char *regGetINIPath() { - return regVbaPath; + return *regVbaPath; } char *regQueryStringValue(const char * key, char *def) @@ -75,7 +80,7 @@ def, (LPTSTR)buffer, 2048, - regVbaPath); + *regVbaPath); if(res) return buffer; @@ -106,7 +111,7 @@ return GetPrivateProfileInt(VBA_PREF, key, def, - regVbaPath); + *regVbaPath); } BOOL regQueryBinaryValue(const char * key, char *value, int count) @@ -134,14 +139,14 @@ int size = GetPrivateProfileInt(VBA_PREF, k, -1, - regVbaPath); + *regVbaPath); if(size >= 0 && size < count) count = size; return GetPrivateProfileStruct(VBA_PREF, key, value, count, - regVbaPath); + *regVbaPath); } void regSetStringValue(const char * key, const char * value) @@ -152,12 +157,12 @@ NULL, REG_SZ, (const UCHAR *)value, - strlen(value)+1); + lstrlen(value)+1); } else { WritePrivateProfileString(VBA_PREF, key, value, - regVbaPath); + *regVbaPath); } } @@ -175,7 +180,7 @@ WritePrivateProfileString(VBA_PREF, key, buffer, - regVbaPath); + *regVbaPath); } } @@ -196,13 +201,13 @@ WritePrivateProfileString(VBA_PREF, k, buffer, - regVbaPath); + *regVbaPath); WritePrivateProfileStruct(VBA_PREF, key, value, count, - regVbaPath); + *regVbaPath); } } @@ -215,7 +220,7 @@ WritePrivateProfileString(VBA_PREF, key, NULL, - regVbaPath); + *regVbaPath); } } @@ -238,7 +243,7 @@ 0, REG_SZ, (const UCHAR *)type, - strlen(type)+1); + lstrlen(type)+1); RegCloseKey(key); return true; } @@ -264,7 +269,7 @@ 0, REG_SZ, (const UCHAR *)desc, - strlen(desc)+1); + lstrlen(desc)+1); HKEY key2; res = RegCreateKeyEx(key, "Shell\\Open\\Command", @@ -281,7 +286,7 @@ 0, REG_SZ, (const UCHAR *)application, - strlen(application)+1); + lstrlen(application)+1); RegCloseKey(key2); RegCloseKey(key); return true; @@ -318,14 +323,14 @@ WritePrivateProfileString(section, valueName, temp, - regVbaPath); + *regVbaPath); } break; case REG_SZ: WritePrivateProfileString(section, valueName, buffer, - regVbaPath); + *regVbaPath); break; case REG_BINARY: { @@ -337,12 +342,12 @@ WritePrivateProfileString(section, k, temp, - regVbaPath); + *regVbaPath); WritePrivateProfileStruct(section, valueName, buffer, size, - regVbaPath); + *regVbaPath); } break; } diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ResizeDlg.cpp ./src/win32/ResizeDlg.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/ResizeDlg.cpp 2003-11-04 23:09:52 +0900 +++ ./src/win32/ResizeDlg.cpp 2006-06-07 06:04:21 +0900 @@ -89,7 +89,7 @@ MB_ABORTRETRYIGNORE); if(res == IDRETRY) { - __asm int 3; + DebugBreak(); } else if(res == IDABORT) SendMessage(*theApp.m_pMainWnd, WM_QUIT, 0, 0); } @@ -143,7 +143,7 @@ if(nCode == IDABORT) { ::SendMessage(*theApp.m_pMainWnd, WM_QUIT, 0, 0); } else if(nCode == IDRETRY) - __asm int 3; + DebugBreak(); } long FASTCALL RegQueryValueExRecursive( HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ) diff -urN ../VisualBoyAdvance-1.7.2/src/win32/RomInfo.cpp ./src/win32/RomInfo.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/RomInfo.cpp 2004-05-13 23:18:06 +0900 +++ ./src/win32/RomInfo.cpp 2006-06-06 23:33:43 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2004-2006 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -356,6 +356,15 @@ case 0x06: type = "ROM+MBC2+BATT"; break; + case 0x0b: + type = "ROM+MMM01"; + break; + case 0x0c: + type = "ROM+MMM01+RAM"; + break; + case 0x0d: + type = "ROM+MMM01+RAM+BATT"; + break; case 0x0f: type = "ROM+MBC3+TIMER+BATT"; break; @@ -392,6 +401,18 @@ case 0x22: type = "ROM+MBC7+BATT"; break; + case 0x55: + type = "GameGenie"; + break; + case 0x56: + type = "GameShark V3.0"; + break; + case 0xfc: + type = "ROM+POCKET CAMERA"; + break; + case 0xfd: + type = "ROM+BANDAI TAMA5"; + break; case 0xfe: type = "ROM+HuC-3"; break; @@ -533,7 +554,7 @@ BOOL RomInfoGBA::OnInitDialog() { CDialog::OnInitDialog(); - + char buffer[13]; strncpy(buffer, (const char *)&rom[0xa0], 12); @@ -554,6 +575,9 @@ GetDlgItem(IDC_ROM_UNIT_CODE)->SetWindowText(buffer); sprintf(buffer, "%02x", rom[0xb4]); + if( rom[0xb4] & 0x80 ) { + strcat(buffer, " (DACS)"); + } GetDlgItem(IDC_ROM_DEVICE_TYPE)->SetWindowText(buffer); sprintf(buffer, "%02x", rom[0xbc]); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/TileView.cpp ./src/win32/TileView.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/TileView.cpp 2004-05-13 23:16:23 +0900 +++ ./src/win32/TileView.cpp 2006-06-07 06:04:21 +0900 @@ -265,38 +265,41 @@ void TileView::OnSave() { - CString captureBuffer; + if(rom != NULL) + { + CString captureBuffer; + + if(theApp.captureFormat == 0) + captureBuffer = "tiles.png"; + else + captureBuffer = "tiles.bmp"; + + LPCTSTR exts[] = {".png", ".bmp" }; + + CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); + CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); + + FileDlg dlg(this, + captureBuffer, + filter, + theApp.captureFormat ? 2 : 1, + theApp.captureFormat ? "BMP" : "PNG", + exts, + "", + title, + true); - if(theApp.captureFormat == 0) - captureBuffer = "tiles.png"; - else - captureBuffer = "tiles.bmp"; - - LPCTSTR exts[] = {".png", ".bmp" }; - - CString filter = theApp.winLoadFilter(IDS_FILTER_PNG); - CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); - - FileDlg dlg(this, - captureBuffer, - filter, - theApp.captureFormat ? 2 : 1, - theApp.captureFormat ? "BMP" : "PNG", - exts, - "", - title, - true); - - if(dlg.DoModal() == IDCANCEL) { - return; - } + if(dlg.DoModal() == IDCANCEL) { + return; + } - captureBuffer = dlg.GetPathName(); + captureBuffer = dlg.GetPathName(); - if(dlg.getFilterIndex() == 2) - saveBMP(captureBuffer); - else - savePNG(captureBuffer); + if(dlg.getFilterIndex() == 2) + saveBMP(captureBuffer); + else + savePNG(captureBuffer); + } } void TileView::renderTile256(int tile, int x, int y, u8 *charBase, u16 *palette) @@ -526,8 +529,8 @@ u8 *colors = (u8 *)lParam; zoom.setColors(colors); - int x = (wParam & 0xFFFF)/8; - int y = ((wParam >> 16) & 0xFFFF)/8; + int x = (int)((wParam & 0xFFFF) / 8); + int y = (int)(((wParam >> 16) & 0xFFFF) / 8); u32 address = 0x6000000 + 0x4000 * charBase; int tile = 32 * y + x; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/VBA.clw ./src/win32/VBA.clw --- ../VisualBoyAdvance-1.7.2/src/win32/VBA.clw 2004-01-25 22:38:58 +0900 +++ ./src/win32/VBA.clw 2004-12-19 08:11:08 +0900 @@ -2,13 +2,13 @@ [General Info] Version=1 -LastClass=Hyperlink +LastClass=MainWnd LastTemplate=CDialog NewFileInclude1=#include "stdafx.h" NewFileInclude2=#include "vba.h" LastPage=0 -ClassCount=57 +ClassCount=58 Class1=AboutDialog Class2=Associate Class3=ColorButton @@ -39,48 +39,48 @@ Class28=VideoMode Class29=VideoDriverSelect -ResourceCount=44 -Resource1=IDD_MAX_SCALE -Resource2=IDD_GDB_WAITING -Resource3=IDD_GB_CHEAT_LIST -Resource4=IDD_CONFIG -Resource5=IDD_ADD_CHEAT_DLG -Resource6=IDD_GB_OAM_VIEW -Resource7=IDD_GB_ROM_INFO -Resource8=IDD_OPENDLG -Resource9=IDD_MAP_VIEW -Resource10=IDD_ABOUT -Resource11=IDD_CHEAT_LIST -Resource12=IDD_OAM_VIEW -Resource13=IDD_CODE_SELECT -Resource14=IDD_CHEATS -Resource15=IDD_GBA_ROM_INFO -Resource16=IDD_IO_VIEWER -Resource17=IDD_MEM_VIEWER -Resource18=IDD_ADDR_SIZE -Resource19=IDR_MENU -Resource20=IDD_PALETTE_VIEW -Resource21=IDD_ASSOCIATIONS -Resource22=IDD_GB_COLORS -Resource23=IDD_ADD_CHEAT -Resource24=IDD_DISASSEMBLE -Resource25=IDD_MODES -Resource26=IDD_GDB_PORT -Resource27=IDD_LANG_SELECT -Resource28=IDD_LOGGING -Resource29=IDD_DRIVERS -Resource30=IDD_EXPORT_SPS -Resource31=IDD_THROTTLE -Resource32=IDD_MODE_CONFIRM -Resource33=IDD_GB_DISASSEMBLE -Resource34=IDD_GB_PALETTE_VIEW -Resource35=IDD_REWIND_INTERVAL -Resource36=IDD_GB_TILE_VIEWER -Resource37=IDD_ACCEL_EDITOR -Resource38=IDD_GB_MAP_VIEW -Resource39=IDD_BUG_REPORT -Resource40=IDD_MOTION_CONFIG -Resource41=IDD_TILE_VIEWER +ResourceCount=45 +Resource1=IDD_LOGGING +Resource2=IDD_MOTION_CONFIG +Resource3=IDD_OPENDLG +Resource4=IDD_IO_VIEWER +Resource5=IDR_MENU +Resource6=IDD_TILE_VIEWER +Resource7=IDD_BUG_REPORT +Resource8=IDD_DRIVERS +Resource9=IDD_GB_CHEAT_LIST +Resource10=IDD_MODES +Resource11=IDD_MODE_CONFIRM +Resource12=IDD_ASSOCIATIONS +Resource13=IDD_ABOUT +Resource14=IDD_GB_TILE_VIEWER +Resource15=IDD_GAME_OVERRIDES +Resource16=IDD_EXPORT_SPS +Resource17=IDD_CONFIG +Resource18=IDD_MAP_VIEW +Resource19=IDD_GB_OAM_VIEW +Resource20=IDD_ADD_CHEAT +Resource21=IDD_REWIND_INTERVAL +Resource22=IDD_GBA_ROM_INFO +Resource23=IDD_GB_MAP_VIEW +Resource24=IDD_ADD_CHEAT_DLG +Resource25=IDD_PALETTE_VIEW +Resource26=IDD_GB_PRINTER +Resource27=IDD_DIRECTORIES +Resource28=IDD_LANG_SELECT +Resource29=IDD_MEM_VIEWER +Resource30=IDD_CODE_SELECT +Resource31=IDD_OAM_VIEW +Resource32=IDD_DISASSEMBLE +Resource33=IDD_ACCEL_EDITOR +Resource34=IDD_GDB_PORT +Resource35=IDD_ADDR_SIZE +Resource36=IDD_GB_COLORS +Resource37=IDD_CHEAT_LIST +Resource38=IDD_GDB_WAITING +Resource39=IDD_THROTTLE +Resource40=IDD_CHEATS +Resource41=IDD_GB_ROM_INFO Class30=AddGSACode Class31=GBCheatList Class32=Disassemble @@ -107,11 +107,13 @@ Class53=GDBWaitingDlg Class54=AccelEditor Class55=CKeyboardEdit -Resource42=IDD_DIRECTORIES +Resource42=IDD_GB_DISASSEMBLE Class56=MaxScale -Resource43=IDD_GB_PRINTER +Resource43=IDD_MAX_SCALE Class57=BugReport -Resource44=IDR_ACCELERATOR +Resource44=IDD_GB_PALETTE_VIEW +Class58=GameOverrides +Resource45=IDR_ACCELERATOR [CLS:AboutDialog] Type=0 @@ -239,7 +241,7 @@ BaseClass=CWnd HeaderFile=MainWnd.h ImplementationFile=MainWnd.cpp -LastObject=ID_CHEATS_AUTOMATICSAVELOADCHEATS +LastObject=ID_HELP_GNUPUBLICLICENSE Filter=W VirtualFilter=WC @@ -311,7 +313,7 @@ Control5=IDC_URL,static,1342308353 Control6=IDC_STATIC,static,1342308353 Control7=IDC_STATIC,static,1342308353 -Control8=IDC_VERSION,static,1342308353 +Control8=IDC_VERSION,static,1342308481 [DLG:IDD_ASSOCIATIONS] Type=1 @@ -527,7 +529,7 @@ Control3=ID_CANCEL,button,1342242816 Control4=IDC_STATIC,static,1342308352 Control5=IDC_STATIC,static,1342308352 -Control6=IDC_LANG_NAME,static,1342308352 +Control6=IDC_LANG_NAME,static,1342308480 [DLG:IDD_MODE_CONFIRM] Type=1 @@ -536,7 +538,7 @@ Control1=ID_OK,button,1342242817 Control2=ID_CANCEL,button,1342242816 Control3=IDC_STATIC,static,1342308353 -Control4=IDC_TIMER,static,1342308353 +Control4=IDC_TIMER,static,1342308481 [DLG:IDD_REWIND_INTERVAL] Type=1 @@ -559,25 +561,25 @@ Control5=IDC_STATIC,static,1342308352 Control6=IDC_STATIC,static,1342308352 Control7=IDC_STATIC,static,1342308352 -Control8=IDC_ROM_TITLE,static,1342308352 -Control9=IDC_ROM_MAKER_CODE,static,1342308352 -Control10=IDC_ROM_UNIT_CODE,static,1342308352 -Control11=IDC_ROM_DEVICE_TYPE,static,1342308352 -Control12=IDC_ROM_VERSION,static,1342308352 -Control13=IDC_ROM_CRC,static,1342308352 +Control8=IDC_ROM_TITLE,static,1342308480 +Control9=IDC_ROM_MAKER_CODE,static,1342308480 +Control10=IDC_ROM_UNIT_CODE,static,1342308480 +Control11=IDC_ROM_DEVICE_TYPE,static,1342308480 +Control12=IDC_ROM_VERSION,static,1342308480 +Control13=IDC_ROM_CRC,static,1342308480 Control14=IDC_STATIC,static,1342308352 -Control15=IDC_ROM_COLOR,static,1342308352 +Control15=IDC_ROM_COLOR,static,1342308480 Control16=IDC_STATIC,static,1342308352 -Control17=IDC_ROM_SIZE,static,1342308352 +Control17=IDC_ROM_SIZE,static,1342308480 Control18=IDC_STATIC,static,1342308352 -Control19=IDC_ROM_RAM_SIZE,static,1342308352 +Control19=IDC_ROM_RAM_SIZE,static,1342308480 Control20=IDC_STATIC,static,1342308352 -Control21=IDC_ROM_DEST_CODE,static,1342308352 +Control21=IDC_ROM_DEST_CODE,static,1342308480 Control22=IDC_STATIC,static,1342308352 -Control23=IDC_ROM_LIC_CODE,static,1342308352 +Control23=IDC_ROM_LIC_CODE,static,1342308480 Control24=IDC_STATIC,static,1342308352 -Control25=IDC_ROM_CHECKSUM,static,1342308352 -Control26=IDC_ROM_MAKER_NAME2,static,1342308352 +Control25=IDC_ROM_CHECKSUM,static,1342308480 +Control26=IDC_ROM_MAKER_NAME2,static,1342308480 Control27=IDC_STATIC,static,1342308352 [DLG:IDD_GBA_ROM_INFO] @@ -592,15 +594,15 @@ Control6=IDC_STATIC,static,1342308352 Control7=IDC_STATIC,static,1342308352 Control8=IDC_STATIC,static,1342308352 -Control9=IDC_ROM_TITLE,static,1342308352 -Control10=IDC_ROM_GAME_CODE,static,1342308352 -Control11=IDC_ROM_MAKER_CODE,static,1342308352 -Control12=IDC_ROM_UNIT_CODE,static,1342308352 -Control13=IDC_ROM_DEVICE_TYPE,static,1342308352 -Control14=IDC_ROM_VERSION,static,1342308352 -Control15=IDC_ROM_CRC,static,1342308352 -Control16=IDC_ROM_MAKER_NAME,static,1342308352 -Control17=IDC_STATIC,static,1342308352 +Control9=IDC_STATIC,static,1342308352 +Control10=IDC_ROM_TITLE,static,1342308480 +Control11=IDC_ROM_GAME_CODE,static,1342308480 +Control12=IDC_ROM_MAKER_CODE,static,1342308480 +Control13=IDC_ROM_UNIT_CODE,static,1342308480 +Control14=IDC_ROM_DEVICE_TYPE,static,1342308480 +Control15=IDC_ROM_VERSION,static,1342308480 +Control16=IDC_ROM_CRC,static,1342308480 +Control17=IDC_ROM_MAKER_NAME,static,1342308480 [DLG:IDD_THROTTLE] Type=1 @@ -696,44 +698,44 @@ Control4=IDC_BG1,button,1342177289 Control5=IDC_BG2,button,1342177289 Control6=IDC_BG3,button,1342177289 -Control7=IDC_STRETCH,button,1342242819 -Control8=IDC_REFRESH,button,1342373888 -Control9=IDC_SAVE,button,1342373888 -Control10=IDC_CLOSE,button,1342242816 -Control11=IDC_MAP_VIEW,VbaBitmapControl,1342373888 -Control12=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888 -Control13=IDC_COLOR,VbaColorControl,1342242816 -Control14=IDC_R,static,1342308352 -Control15=IDC_G,static,1342308352 -Control16=IDC_B,static,1342308352 -Control17=IDC_STATIC,button,1342177287 +Control7=IDC_STRETCH,button,1342373891 +Control8=IDC_AUTO_UPDATE,button,1342373891 +Control9=IDC_REFRESH,button,1342373888 +Control10=IDC_SAVE,button,1342373888 +Control11=IDC_CLOSE,button,1342242816 +Control12=IDC_MAP_VIEW,VbaBitmapControl,1342373888 +Control13=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888 +Control14=IDC_COLOR,VbaColorControl,1342242816 +Control15=IDC_R,static,1342308480 +Control16=IDC_G,static,1342308480 +Control17=IDC_B,static,1342308480 Control18=IDC_STATIC,button,1342177287 -Control19=IDC_AUTO_UPDATE,button,1342242819 -Control20=IDC_XY,static,1342308352 +Control19=IDC_STATIC,button,1342177287 +Control20=IDC_XY,static,1342308480 Control21=IDC_STATIC,static,1342308352 -Control22=IDC_MODE,static,1342308352 +Control22=IDC_MODE,static,1342308480 Control23=IDC_STATIC,static,1342308352 -Control24=IDC_MAPBASE,static,1342308352 +Control24=IDC_MAPBASE,static,1342308480 Control25=IDC_STATIC,static,1342308352 -Control26=IDC_CHARBASE,static,1342308352 +Control26=IDC_CHARBASE,static,1342308480 Control27=IDC_STATIC,static,1342308352 -Control28=IDC_DIM,static,1342308352 +Control28=IDC_DIM,static,1342308480 Control29=IDC_STATIC,static,1342308352 -Control30=IDC_NUMCOLORS,static,1342308352 +Control30=IDC_NUMCOLORS,static,1342308480 Control31=IDC_STATIC,static,1342308352 -Control32=IDC_PRIORITY,static,1342308352 +Control32=IDC_PRIORITY,static,1342308480 Control33=IDC_STATIC,static,1342308352 -Control34=IDC_MOSAIC,static,1342308352 +Control34=IDC_MOSAIC,static,1342308480 Control35=IDC_STATIC,static,1342308352 -Control36=IDC_OVERFLOW,static,1342308352 +Control36=IDC_OVERFLOW,static,1342308480 Control37=IDC_STATIC,static,1342308352 -Control38=IDC_ADDRESS,static,1342308352 +Control38=IDC_ADDRESS,static,1342308480 Control39=IDC_STATIC,static,1342308352 -Control40=IDC_TILE_NUM,static,1342308352 +Control40=IDC_TILE_NUM,static,1342308480 Control41=IDC_STATIC,static,1342308352 -Control42=IDC_FLIP,static,1342308352 +Control42=IDC_FLIP,static,1342308480 Control43=IDC_STATIC,static,1342308352 -Control44=IDC_PALETTE_NUM,static,1342308352 +Control44=IDC_PALETTE_NUM,static,1342308480 [DLG:IDD_PALETTE_VIEW] Type=1 @@ -743,11 +745,11 @@ Control2=IDC_SAVE_OBJ,button,1342242816 Control3=IDC_REFRESH2,button,1342242816 Control4=IDC_CLOSE,button,1342242816 -Control5=IDC_ADDRESS,static,1342308352 -Control6=IDC_R,static,1342308352 -Control7=IDC_G,static,1342308352 -Control8=IDC_B,static,1342308352 -Control9=IDC_VALUE,static,1342308352 +Control5=IDC_ADDRESS,static,1342308480 +Control6=IDC_R,static,1342308480 +Control7=IDC_G,static,1342308480 +Control8=IDC_B,static,1342308480 +Control9=IDC_VALUE,static,1342308480 Control10=IDC_COLOR,VbaColorControl,1342242816 Control11=IDC_PALETTE_VIEW,VbaPaletteViewControl,1342242816 Control12=IDC_PALETTE_VIEW_OBJ,VbaPaletteViewControl,1342242816 @@ -793,18 +795,18 @@ Control7=IDC_OAM_VIEW,VbaBitmapControl,1342373888 Control8=IDC_OAM_VIEW_ZOOM,VbaZoomControl,1342373888 Control9=IDC_COLOR,VbaColorControl,1342242816 -Control10=IDC_POS,static,1342308352 -Control11=IDC_MODE,static,1342308352 -Control12=IDC_COLORS,static,1342308352 -Control13=IDC_PALETTE,static,1342308352 -Control14=IDC_TILE,static,1342308352 -Control15=IDC_PRIO,static,1342308352 -Control16=IDC_SIZE2,static,1342308352 -Control17=IDC_ROT,static,1342308352 -Control18=IDC_FLAGS,static,1342308352 -Control19=IDC_R,static,1342308352 -Control20=IDC_G,static,1342308352 -Control21=IDC_B,static,1342308352 +Control10=IDC_POS,static,1342308480 +Control11=IDC_MODE,static,1342308480 +Control12=IDC_COLORS,static,1342308480 +Control13=IDC_PALETTE,static,1342308480 +Control14=IDC_TILE,static,1342308480 +Control15=IDC_PRIO,static,1342308480 +Control16=IDC_SIZE2,static,1342308480 +Control17=IDC_ROT,static,1342308480 +Control18=IDC_FLAGS,static,1342308480 +Control19=IDC_R,static,1342308480 +Control20=IDC_G,static,1342308480 +Control21=IDC_B,static,1342308480 Control22=IDC_STATIC,static,1342308352 Control23=IDC_STATIC,static,1342308352 Control24=IDC_STATIC,static,1342308352 @@ -856,15 +858,15 @@ Control15=IDC_STATIC,button,1342177287 Control16=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888 Control17=IDC_COLOR,VbaColorControl,1342242816 -Control18=IDC_R,static,1342308352 -Control19=IDC_G,static,1342308352 -Control20=IDC_B,static,1342308352 +Control18=IDC_R,static,1342308480 +Control19=IDC_G,static,1342308480 +Control20=IDC_B,static,1342308480 Control21=IDC_STATIC,static,1342308352 Control22=IDC_AUTO_UPDATE,button,1342242819 Control23=IDC_STATIC,static,1342308352 Control24=IDC_STATIC,static,1342308352 -Control25=IDC_TILE_NUMBER,static,1342308352 -Control26=IDC_ADDRESS,static,1342308352 +Control25=IDC_TILE_NUMBER,static,1342308480 +Control26=IDC_ADDRESS,static,1342308480 [DLG:IDD_DISASSEMBLE] Type=1 @@ -874,12 +876,12 @@ Control2=IDC_ARM,button,1342177289 Control3=IDC_THUMB,button,1342177289 Control4=IDC_ADDRESS,edit,1350762632 -Control5=IDC_GO,button,1342242816 +Control5=IDC_GO,button,1342242817 Control6=IDC_DISASSEMBLE,listbox,1350631683 Control7=IDC_AUTO_UPDATE,button,1342242819 Control8=IDC_REFRESH,button,1342242816 Control9=IDC_NEXT,button,1342242816 -Control10=IDC_CLOSE,button,1342242817 +Control10=IDC_CLOSE,button,1342242816 Control11=IDC_STATIC,static,1342308352 Control12=IDC_STATIC,static,1342308352 Control13=IDC_STATIC,static,1342308352 @@ -888,22 +890,22 @@ Control16=IDC_STATIC,static,1342308352 Control17=IDC_STATIC,static,1342308352 Control18=IDC_STATIC,static,1342308352 -Control19=IDC_R0,static,1342308352 -Control20=IDC_R1,static,1342308352 -Control21=IDC_R2,static,1342308352 -Control22=IDC_R3,static,1342308352 -Control23=IDC_R4,static,1342308352 -Control24=IDC_R5,static,1342308352 -Control25=IDC_R6,static,1342308352 -Control26=IDC_R7,static,1342308352 -Control27=IDC_R8,static,1342308352 -Control28=IDC_R9,static,1342308352 -Control29=IDC_R10,static,1342308352 -Control30=IDC_R11,static,1342308352 -Control31=IDC_R12,static,1342308352 -Control32=IDC_R13,static,1342308352 -Control33=IDC_R14,static,1342308352 -Control34=IDC_R15,static,1342308352 +Control19=IDC_R0,static,1342308480 +Control20=IDC_R1,static,1342308480 +Control21=IDC_R2,static,1342308480 +Control22=IDC_R3,static,1342308480 +Control23=IDC_R4,static,1342308480 +Control24=IDC_R5,static,1342308480 +Control25=IDC_R6,static,1342308480 +Control26=IDC_R7,static,1342308480 +Control27=IDC_R8,static,1342308480 +Control28=IDC_R9,static,1342308480 +Control29=IDC_R10,static,1342308480 +Control30=IDC_R11,static,1342308480 +Control31=IDC_R12,static,1342308480 +Control32=IDC_R13,static,1342308480 +Control33=IDC_R14,static,1342308480 +Control34=IDC_R15,static,1342308480 Control35=IDC_STATIC,static,1342308352 Control36=IDC_STATIC,static,1342308352 Control37=IDC_STATIC,static,1342308352 @@ -912,7 +914,7 @@ Control40=IDC_STATIC,static,1342308352 Control41=IDC_STATIC,static,1342308352 Control42=IDC_STATIC,static,1342308352 -Control43=IDC_R16,static,1342308352 +Control43=IDC_R16,static,1342308480 Control44=IDC_STATIC,static,1342308352 Control45=IDC_N,button,1476460547 Control46=IDC_Z,button,1476460547 @@ -922,7 +924,7 @@ Control50=IDC_I,button,1476460547 Control51=IDC_T,button,1476460547 Control52=IDC_STATIC,static,1342308352 -Control53=IDC_MODE,static,1342308352 +Control53=IDC_MODE,static,1342308480 Control54=IDC_VSCROLL,scrollbar,1342177281 Control55=IDC_GOPC,button,1342242816 @@ -941,7 +943,7 @@ ControlCount=3 Control1=ID_CANCEL,button,1342242816 Control2=IDC_STATIC,static,1342308352 -Control3=IDC_PORT,static,1342308352 +Control3=IDC_PORT,static,1342308480 [DLG:IDD_LOGGING] Type=1 @@ -979,22 +981,22 @@ Class=GBDisassemble ControlCount=27 Control1=IDC_ADDRESS,edit,1350762632 -Control2=IDC_GO,button,1342242816 +Control2=IDC_GO,button,1342242817 Control3=IDC_DISASSEMBLE,listbox,1350631683 Control4=IDC_AUTO_UPDATE,button,1342242819 Control5=IDC_REFRESH,button,1342242816 Control6=IDC_NEXT,button,1342242816 -Control7=IDC_CLOSE,button,1342242817 +Control7=IDC_CLOSE,button,1342242816 Control8=IDC_STATIC,static,1342308352 Control9=IDC_STATIC,static,1342308352 Control10=IDC_STATIC,static,1342308352 Control11=IDC_STATIC,static,1342308352 Control12=IDC_STATIC,static,1342308352 -Control13=IDC_R0,static,1342308352 -Control14=IDC_R1,static,1342308352 -Control15=IDC_R2,static,1342308352 -Control16=IDC_R3,static,1342308352 -Control17=IDC_R6,static,1342308352 +Control13=IDC_R0,static,1342308480 +Control14=IDC_R1,static,1342308480 +Control15=IDC_R2,static,1342308480 +Control16=IDC_R3,static,1342308480 +Control17=IDC_R6,static,1342308480 Control18=IDC_N,button,1476460547 Control19=IDC_Z,button,1476460547 Control20=IDC_C,button,1476460547 @@ -1002,9 +1004,9 @@ Control22=IDC_VSCROLL,scrollbar,1342177281 Control23=IDC_GOPC,button,1342242816 Control24=IDC_STATIC,static,1342308352 -Control25=IDC_R4,static,1342308352 +Control25=IDC_R4,static,1342308480 Control26=IDC_STATIC,static,1342308352 -Control27=IDC_R5,static,1342308352 +Control27=IDC_R5,static,1342308480 [DLG:IDD_GB_OAM_VIEW] Type=1 @@ -1019,15 +1021,15 @@ Control7=IDC_OAM_VIEW,VbaBitmapControl,1342373888 Control8=IDC_OAM_VIEW_ZOOM,VbaZoomControl,1342373888 Control9=IDC_COLOR,VbaColorControl,1342242816 -Control10=IDC_POS,static,1342308352 -Control11=IDC_PALETTE,static,1342308352 -Control12=IDC_TILE,static,1342308352 -Control13=IDC_PRIO,static,1342308352 -Control14=IDC_OAP,static,1342308352 -Control15=IDC_FLAGS,static,1342308352 -Control16=IDC_R,static,1342308352 -Control17=IDC_G,static,1342308352 -Control18=IDC_B,static,1342308352 +Control10=IDC_POS,static,1342308480 +Control11=IDC_PALETTE,static,1342308480 +Control12=IDC_TILE,static,1342308480 +Control13=IDC_PRIO,static,1342308480 +Control14=IDC_OAP,static,1342308480 +Control15=IDC_FLAGS,static,1342308480 +Control16=IDC_R,static,1342308480 +Control17=IDC_G,static,1342308480 +Control18=IDC_B,static,1342308480 Control19=IDC_STATIC,static,1342308352 Control20=IDC_STATIC,static,1342308352 Control21=IDC_STATIC,static,1342308352 @@ -1036,7 +1038,7 @@ Control24=IDC_STATIC,static,1342308352 Control25=IDC_STATIC,static,1342308352 Control26=IDC_AUTO_UPDATE,button,1342242819 -Control27=IDC_BANK,static,1342308352 +Control27=IDC_BANK,static,1342308480 Control28=IDC_STATIC,static,1342308352 [DLG:IDD_GB_TILE_VIEWER] @@ -1056,15 +1058,15 @@ Control11=IDC_STATIC,button,1342177287 Control12=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888 Control13=IDC_COLOR,VbaColorControl,1342242816 -Control14=IDC_R,static,1342308352 -Control15=IDC_G,static,1342308352 -Control16=IDC_B,static,1342308352 +Control14=IDC_R,static,1342308480 +Control15=IDC_G,static,1342308480 +Control16=IDC_B,static,1342308480 Control17=IDC_STATIC,static,1342308352 Control18=IDC_AUTO_UPDATE,button,1342242819 Control19=IDC_STATIC,static,1342308352 Control20=IDC_STATIC,static,1342308352 -Control21=IDC_TILE_NUMBER,static,1342308352 -Control22=IDC_ADDRESS,static,1342308352 +Control21=IDC_TILE_NUMBER,static,1342308480 +Control22=IDC_ADDRESS,static,1342308480 Control23=IDC_PALETTE_SLIDER,msctls_trackbar32,1342373889 [DLG:IDD_GB_MAP_VIEW] @@ -1082,23 +1084,23 @@ Control9=IDC_MAP_VIEW,VbaBitmapControl,1342373888 Control10=IDC_MAP_VIEW_ZOOM,VbaZoomControl,1342373888 Control11=IDC_COLOR,VbaColorControl,1342242816 -Control12=IDC_R,static,1342308352 -Control13=IDC_G,static,1342308352 -Control14=IDC_B,static,1342308352 +Control12=IDC_R,static,1342308480 +Control13=IDC_G,static,1342308480 +Control14=IDC_B,static,1342308480 Control15=IDC_STATIC,button,1342177287 Control16=IDC_STATIC,button,1342177287 Control17=IDC_AUTO_UPDATE,button,1342242819 -Control18=IDC_XY,static,1342308352 +Control18=IDC_XY,static,1342308480 Control19=IDC_STATIC,static,1342308352 -Control20=IDC_PRIORITY,static,1342308352 +Control20=IDC_PRIORITY,static,1342308480 Control21=IDC_STATIC,static,1342308352 -Control22=IDC_ADDRESS,static,1342308352 +Control22=IDC_ADDRESS,static,1342308480 Control23=IDC_STATIC,static,1342308352 -Control24=IDC_TILE_NUM,static,1342308352 +Control24=IDC_TILE_NUM,static,1342308480 Control25=IDC_STATIC,static,1342308352 -Control26=IDC_FLIP,static,1342308352 +Control26=IDC_FLIP,static,1342308480 Control27=IDC_STATIC,static,1342308352 -Control28=IDC_PALETTE_NUM,static,1342308352 +Control28=IDC_PALETTE_NUM,static,1342308480 [DLG:IDD_GB_PALETTE_VIEW] Type=1 @@ -1108,11 +1110,11 @@ Control2=IDC_SAVE_OBJ,button,1342242816 Control3=IDC_REFRESH2,button,1342242816 Control4=IDC_CLOSE,button,1342242816 -Control5=IDC_ADDRESS,static,1342308352 -Control6=IDC_R,static,1342308352 -Control7=IDC_G,static,1342308352 -Control8=IDC_B,static,1342308352 -Control9=IDC_VALUE,static,1342308352 +Control5=IDC_ADDRESS,static,1342308480 +Control6=IDC_R,static,1342308480 +Control7=IDC_G,static,1342308480 +Control8=IDC_B,static,1342308480 +Control9=IDC_VALUE,static,1342308480 Control10=IDC_COLOR,VbaColorControl,1342242816 Control11=IDC_PALETTE_VIEW,VbaPaletteViewControl,1342242816 Control12=IDC_PALETTE_VIEW_OBJ,VbaPaletteViewControl,1342242816 @@ -1263,129 +1265,131 @@ Command104=ID_OPTIONS_EMULATOR_REALTIMECLOCK Command105=ID_OPTIONS_EMULATOR_AUTOHIDEMENU Command106=ID_OPTIONS_EMULATOR_REWINDINTERVAL -Command107=ID_OPTIONS_EMULATOR_SHOWSPEED_NONE -Command108=ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE -Command109=ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED -Command110=ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT -Command111=ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC -Command112=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM -Command113=ID_OPTIONS_EMULATOR_SAVETYPE_SRAM -Command114=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH -Command115=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR -Command116=ID_OPTIONS_EMULATOR_SAVETYPE_NONE -Command117=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K -Command118=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M -Command119=ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION -Command120=ID_OPTIONS_EMULATOR_USEBIOSFILE -Command121=ID_OPTIONS_EMULATOR_SKIPBIOS -Command122=ID_OPTIONS_EMULATOR_SELECTBIOSFILE -Command123=ID_OPTIONS_EMULATOR_PNGFORMAT -Command124=ID_OPTIONS_EMULATOR_BMPFORMAT -Command125=ID_OPTIONS_SOUND_OFF -Command126=ID_OPTIONS_SOUND_MUTE -Command127=ID_OPTIONS_SOUND_ON -Command128=ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION -Command129=ID_OPTIONS_SOUND_ECHO -Command130=ID_OPTIONS_SOUND_LOWPASSFILTER -Command131=ID_OPTIONS_SOUND_REVERSESTEREO -Command132=ID_OPTIONS_SOUND_CHANNEL1 -Command133=ID_OPTIONS_SOUND_CHANNEL2 -Command134=ID_OPTIONS_SOUND_CHANNEL3 -Command135=ID_OPTIONS_SOUND_CHANNEL4 -Command136=ID_OPTIONS_SOUND_DIRECTSOUNDA -Command137=ID_OPTIONS_SOUND_DIRECTSOUNDB -Command138=ID_OPTIONS_SOUND_11KHZ -Command139=ID_OPTIONS_SOUND_22KHZ -Command140=ID_OPTIONS_SOUND_44KHZ -Command141=ID_OPTIONS_SOUND_VOLUME_25X -Command142=ID_OPTIONS_SOUND_VOLUME_5X -Command143=ID_OPTIONS_SOUND_VOLUME_1X -Command144=ID_OPTIONS_SOUND_VOLUME_2X -Command145=ID_OPTIONS_SOUND_VOLUME_3X -Command146=ID_OPTIONS_SOUND_VOLUME_4X -Command147=ID_OPTIONS_GAMEBOY_BORDER -Command148=ID_OPTIONS_GAMEBOY_PRINTER -Command149=ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC -Command150=ID_OPTIONS_GAMEBOY_AUTOMATIC -Command151=ID_OPTIONS_GAMEBOY_GBA -Command152=ID_OPTIONS_GAMEBOY_CGB -Command153=ID_OPTIONS_GAMEBOY_SGB -Command154=ID_OPTIONS_GAMEBOY_SGB2 -Command155=ID_OPTIONS_GAMEBOY_GB -Command156=ID_OPTIONS_GAMEBOY_REALCOLORS -Command157=ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS -Command158=ID_OPTIONS_GAMEBOY_COLORS -Command159=ID_OPTIONS_PRIORITY_HIGHEST -Command160=ID_OPTIONS_PRIORITY_ABOVENORMAL -Command161=ID_OPTIONS_PRIORITY_NORMAL -Command162=ID_OPTIONS_PRIORITY_BELOWNORMAL -Command163=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE -Command164=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR -Command165=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART -Command166=ID_OPTIONS_FILTER_NORMAL -Command167=ID_OPTIONS_FILTER_TVMODE -Command168=ID_OPTIONS_FILTER_2XSAI -Command169=ID_OPTIONS_FILTER_SUPER2XSAI -Command170=ID_OPTIONS_FILTER_SUPEREAGLE -Command171=ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL -Command172=ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL -Command173=ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X -Command174=ID_OPTIONS_FILTER16BIT_SIMPLE2X -Command175=ID_OPTIONS_FILTER_BILINEAR -Command176=ID_OPTIONS_FILTER_BILINEARPLUS -Command177=ID_OPTIONS_FILTER_SCANLINES -Command178=ID_OPTIONS_FILTER_HQ2X -Command179=ID_OPTIONS_FILTER_LQ2X -Command180=ID_OPTIONS_FILTER_DISABLEMMX -Command181=ID_OPTIONS_JOYPAD_CONFIGURE_1 -Command182=ID_OPTIONS_JOYPAD_CONFIGURE_2 -Command183=ID_OPTIONS_JOYPAD_CONFIGURE_3 -Command184=ID_OPTIONS_JOYPAD_CONFIGURE_4 -Command185=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1 -Command186=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2 -Command187=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3 -Command188=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4 -Command189=ID_OPTIONS_JOYPAD_MOTIONCONFIGURE -Command190=ID_OPTIONS_JOYPAD_AUTOFIRE_A -Command191=ID_OPTIONS_JOYPAD_AUTOFIRE_B -Command192=ID_OPTIONS_JOYPAD_AUTOFIRE_L -Command193=ID_OPTIONS_JOYPAD_AUTOFIRE_R -Command194=ID_OPTIONS_LANGUAGE_SYSTEM -Command195=ID_OPTIONS_LANGUAGE_ENGLISH -Command196=ID_OPTIONS_LANGUAGE_OTHER -Command197=ID_CHEATS_SEARCHFORCHEATS -Command198=ID_CHEATS_CHEATLIST -Command199=ID_CHEATS_AUTOMATICSAVELOADCHEATS -Command200=ID_CHEATS_DISABLECHEATS -Command201=ID_CHEATS_LOADCHEATLIST -Command202=ID_CHEATS_SAVECHEATLIST -Command203=ID_TOOLS_DISASSEMBLE -Command204=ID_TOOLS_LOGGING -Command205=ID_TOOLS_IOVIEWER -Command206=ID_TOOLS_MAPVIEW -Command207=ID_TOOLS_MEMORYVIEWER -Command208=ID_TOOLS_OAMVIEWER -Command209=ID_TOOLS_PALETTEVIEW -Command210=ID_TOOLS_TILEVIEWER -Command211=ID_DEBUG_NEXTFRAME -Command212=ID_TOOLS_DEBUG_GDB -Command213=ID_TOOLS_DEBUG_LOADANDWAIT -Command214=ID_TOOLS_DEBUG_BREAK -Command215=ID_TOOLS_DEBUG_DISCONNECT -Command216=ID_OPTIONS_SOUND_STARTRECORDING -Command217=ID_OPTIONS_SOUND_STOPRECORDING -Command218=ID_TOOLS_RECORD_STARTAVIRECORDING -Command219=ID_TOOLS_RECORD_STOPAVIRECORDING -Command220=ID_TOOLS_RECORD_STARTMOVIERECORDING -Command221=ID_TOOLS_RECORD_STOPMOVIERECORDING -Command222=ID_TOOLS_PLAY_STARTMOVIEPLAYING -Command223=ID_TOOLS_PLAY_STOPMOVIEPLAYING -Command224=ID_TOOLS_REWIND -Command225=ID_TOOLS_CUSTOMIZE -Command226=ID_HELP_BUGREPORT -Command227=ID_HELP_FAQ -Command228=ID_HELP_ABOUT -CommandCount=228 +Command107=ID_OPTIONS_EMULATOR_GAMEOVERRIDES +Command108=ID_OPTIONS_EMULATOR_SHOWSPEED_NONE +Command109=ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE +Command110=ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED +Command111=ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT +Command112=ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC +Command113=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM +Command114=ID_OPTIONS_EMULATOR_SAVETYPE_SRAM +Command115=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH +Command116=ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR +Command117=ID_OPTIONS_EMULATOR_SAVETYPE_NONE +Command118=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K +Command119=ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M +Command120=ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION +Command121=ID_OPTIONS_EMULATOR_USEBIOSFILE +Command122=ID_OPTIONS_EMULATOR_SKIPBIOS +Command123=ID_OPTIONS_EMULATOR_SELECTBIOSFILE +Command124=ID_OPTIONS_EMULATOR_PNGFORMAT +Command125=ID_OPTIONS_EMULATOR_BMPFORMAT +Command126=ID_OPTIONS_SOUND_OFF +Command127=ID_OPTIONS_SOUND_MUTE +Command128=ID_OPTIONS_SOUND_ON +Command129=ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION +Command130=ID_OPTIONS_SOUND_ECHO +Command131=ID_OPTIONS_SOUND_LOWPASSFILTER +Command132=ID_OPTIONS_SOUND_REVERSESTEREO +Command133=ID_OPTIONS_SOUND_CHANNEL1 +Command134=ID_OPTIONS_SOUND_CHANNEL2 +Command135=ID_OPTIONS_SOUND_CHANNEL3 +Command136=ID_OPTIONS_SOUND_CHANNEL4 +Command137=ID_OPTIONS_SOUND_DIRECTSOUNDA +Command138=ID_OPTIONS_SOUND_DIRECTSOUNDB +Command139=ID_OPTIONS_SOUND_11KHZ +Command140=ID_OPTIONS_SOUND_22KHZ +Command141=ID_OPTIONS_SOUND_44KHZ +Command142=ID_OPTIONS_SOUND_VOLUME_25X +Command143=ID_OPTIONS_SOUND_VOLUME_5X +Command144=ID_OPTIONS_SOUND_VOLUME_1X +Command145=ID_OPTIONS_SOUND_VOLUME_2X +Command146=ID_OPTIONS_SOUND_VOLUME_3X +Command147=ID_OPTIONS_SOUND_VOLUME_4X +Command148=ID_OPTIONS_GAMEBOY_BORDER +Command149=ID_OPTIONS_GAMEBOY_PRINTER +Command150=ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC +Command151=ID_OPTIONS_GAMEBOY_AUTOMATIC +Command152=ID_OPTIONS_GAMEBOY_GBA +Command153=ID_OPTIONS_GAMEBOY_CGB +Command154=ID_OPTIONS_GAMEBOY_SGB +Command155=ID_OPTIONS_GAMEBOY_SGB2 +Command156=ID_OPTIONS_GAMEBOY_GB +Command157=ID_OPTIONS_GAMEBOY_REALCOLORS +Command158=ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS +Command159=ID_OPTIONS_GAMEBOY_COLORS +Command160=ID_OPTIONS_PRIORITY_HIGHEST +Command161=ID_OPTIONS_PRIORITY_ABOVENORMAL +Command162=ID_OPTIONS_PRIORITY_NORMAL +Command163=ID_OPTIONS_PRIORITY_BELOWNORMAL +Command164=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE +Command165=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR +Command166=ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART +Command167=ID_OPTIONS_FILTER_NORMAL +Command168=ID_OPTIONS_FILTER_TVMODE +Command169=ID_OPTIONS_FILTER_2XSAI +Command170=ID_OPTIONS_FILTER_SUPER2XSAI +Command171=ID_OPTIONS_FILTER_SUPEREAGLE +Command172=ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL +Command173=ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL +Command174=ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X +Command175=ID_OPTIONS_FILTER16BIT_SIMPLE2X +Command176=ID_OPTIONS_FILTER_BILINEAR +Command177=ID_OPTIONS_FILTER_BILINEARPLUS +Command178=ID_OPTIONS_FILTER_SCANLINES +Command179=ID_OPTIONS_FILTER_HQ2X +Command180=ID_OPTIONS_FILTER_LQ2X +Command181=ID_OPTIONS_FILTER_DISABLEMMX +Command182=ID_OPTIONS_JOYPAD_CONFIGURE_1 +Command183=ID_OPTIONS_JOYPAD_CONFIGURE_2 +Command184=ID_OPTIONS_JOYPAD_CONFIGURE_3 +Command185=ID_OPTIONS_JOYPAD_CONFIGURE_4 +Command186=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1 +Command187=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2 +Command188=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3 +Command189=ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4 +Command190=ID_OPTIONS_JOYPAD_MOTIONCONFIGURE +Command191=ID_OPTIONS_JOYPAD_AUTOFIRE_A +Command192=ID_OPTIONS_JOYPAD_AUTOFIRE_B +Command193=ID_OPTIONS_JOYPAD_AUTOFIRE_L +Command194=ID_OPTIONS_JOYPAD_AUTOFIRE_R +Command195=ID_OPTIONS_LANGUAGE_SYSTEM +Command196=ID_OPTIONS_LANGUAGE_ENGLISH +Command197=ID_OPTIONS_LANGUAGE_OTHER +Command198=ID_CHEATS_SEARCHFORCHEATS +Command199=ID_CHEATS_CHEATLIST +Command200=ID_CHEATS_AUTOMATICSAVELOADCHEATS +Command201=ID_CHEATS_DISABLECHEATS +Command202=ID_CHEATS_LOADCHEATLIST +Command203=ID_CHEATS_SAVECHEATLIST +Command204=ID_TOOLS_DISASSEMBLE +Command205=ID_TOOLS_LOGGING +Command206=ID_TOOLS_IOVIEWER +Command207=ID_TOOLS_MAPVIEW +Command208=ID_TOOLS_MEMORYVIEWER +Command209=ID_TOOLS_OAMVIEWER +Command210=ID_TOOLS_PALETTEVIEW +Command211=ID_TOOLS_TILEVIEWER +Command212=ID_DEBUG_NEXTFRAME +Command213=ID_TOOLS_DEBUG_GDB +Command214=ID_TOOLS_DEBUG_LOADANDWAIT +Command215=ID_TOOLS_DEBUG_BREAK +Command216=ID_TOOLS_DEBUG_DISCONNECT +Command217=ID_OPTIONS_SOUND_STARTRECORDING +Command218=ID_OPTIONS_SOUND_STOPRECORDING +Command219=ID_TOOLS_RECORD_STARTAVIRECORDING +Command220=ID_TOOLS_RECORD_STOPAVIRECORDING +Command221=ID_TOOLS_RECORD_STARTMOVIERECORDING +Command222=ID_TOOLS_RECORD_STOPMOVIERECORDING +Command223=ID_TOOLS_PLAY_STARTMOVIEPLAYING +Command224=ID_TOOLS_PLAY_STOPMOVIEPLAYING +Command225=ID_TOOLS_REWIND +Command226=ID_TOOLS_CUSTOMIZE +Command227=ID_HELP_BUGREPORT +Command228=ID_HELP_FAQ +Command229=ID_HELP_GNUPUBLICLICENSE +Command230=ID_HELP_ABOUT +CommandCount=230 [ACL:IDR_ACCELERATOR] Type=1 @@ -1713,3 +1717,28 @@ VirtualFilter=dWC LastObject=BugReport +[DLG:IDD_GAME_OVERRIDES] +Type=1 +Class=GameOverrides +ControlCount=11 +Control1=IDC_RTC,combobox,1344339971 +Control2=IDC_SAVE_TYPE,combobox,1344339971 +Control3=IDC_FLASH_SIZE,combobox,1344339971 +Control4=IDOK,button,1342242817 +Control5=IDC_DEFAULTS,button,1342242816 +Control6=IDCANCEL,button,1342242816 +Control7=IDC_STATIC,static,1342308352 +Control8=IDC_NAME,edit,1484849280 +Control9=IDC_STATIC,static,1342308352 +Control10=IDC_STATIC,static,1342308352 +Control11=IDC_STATIC,static,1342308352 + +[CLS:GameOverrides] +Type=0 +HeaderFile=GameOverrides.h +ImplementationFile=GameOverrides.cpp +BaseClass=CDialog +Filter=D +LastObject=IDOK +VirtualFilter=dWC + diff -urN ../VisualBoyAdvance-1.7.2/src/win32/VBA.cpp ./src/win32/VBA.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/VBA.cpp 2004-05-13 23:16:07 +0900 +++ ./src/win32/VBA.cpp 2006-08-06 21:40:35 +0900 @@ -1,6 +1,6 @@ // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,13 +19,13 @@ // VBA.cpp : Defines the class behaviors for the application. // #include "stdafx.h" -#include #include "AVIWrite.h" #include "LangSelect.h" #include "MainWnd.h" #include "Reg.h" #include "resource.h" +#include "resource2.h" #include "skin.h" #include "WavWriter.h" #include "WinResUtil.h" @@ -130,6 +130,23 @@ extern "C" bool cpu_mmx; #endif +namespace Sm60FPS +{ + float K_fCpuSpeed = 98.0f; + float K_fTargetFps = 60.0f * K_fCpuSpeed / 100; + float K_fDT = 1000.0f / K_fTargetFps; + + u32 dwTimeElapse; + u32 dwTime0; + u32 dwTime1; + u32 nFrameCnt; + float fWantFPS; + float fCurFPS; + bool bLastSkip; + int nCurSpeed; + int bSaveMoreCPU; +}; + void directXMessage(const char *msg) { systemMessage(IDS_DIRECTX_7_REQUIRED, @@ -163,9 +180,11 @@ filterType = 0; filterWidth = 0; filterHeight = 0; + fsAdapter = 0; fsWidth = 0; fsHeight = 0; fsColorDepth = 0; + fsFrequency = 0; fsForceChange = false; surfaceSizeX = 0; surfaceSizeY = 0; @@ -183,7 +202,7 @@ display = NULL; menu = NULL; popup = NULL; - cartridgeType = 0; + cartridgeType = IMAGE_GBA; soundInitialized = false; useBiosFile = false; skipBiosFile = false; @@ -197,6 +216,7 @@ winGbBorderOn = 0; winFlashSize = 0x10000; winRtcEnable = false; + winGenericflashcardEnable = false; winSaveType = 0; rewindMemory = NULL; rewindPos = 0; @@ -246,6 +266,7 @@ winPauseNextFrame = false; soundRecording = false; soundRecorder = NULL; + dsoundDisableHardwareAcceleration = true; sound = NULL; aviRecording = false; aviRecorder = NULL; @@ -287,6 +308,15 @@ { InterframeCleanup(); + char winBuffer[2048]; + + GetModuleFileName(NULL, winBuffer, 2048); + char *p = strrchr(winBuffer, '\\'); + if(p) + *p = 0; + + regInit(winBuffer); + saveSettings(); if(moviePlaying) { @@ -350,7 +380,6 @@ // The one and only VBA object VBA theApp; -#include ///////////////////////////////////////////////////////////////////////////// // VBA initialization @@ -407,17 +436,13 @@ BOOL VBA::InitInstance() { - AfxEnableControlContainer(); - // Standard initialization - // If you are not using these features and wish to reduce the size - // of your final executable, you should remove from the following - // the specific initialization routines you do not need. - +#if _MSC_VER < 1400 #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif +#endif SetRegistryKey(_T("VBA")); @@ -504,6 +529,7 @@ return TRUE; } + void VBA::adjustDestRect() { POINT point; @@ -570,6 +596,7 @@ } } + void VBA::updateIFB() { if(systemColorDepth == 16) { @@ -810,6 +837,9 @@ } } + if (Sm60FPS_CanSkipFrame()) + return; + if(theApp.aviRecording && !theApp.painting) { int width = 240; int height = 160; @@ -855,16 +885,15 @@ delete bmp; } - if(theApp.ifbFunction) { - if(systemColorDepth == 16) - theApp.ifbFunction(pix+theApp.filterWidth*2+4, theApp.filterWidth*2+4, - theApp.filterWidth, theApp.filterHeight); - else - theApp.ifbFunction(pix+theApp.filterWidth*4+4, theApp.filterWidth*4+4, - theApp.filterWidth, theApp.filterHeight); + if( theApp.ifbFunction ) { + theApp.ifbFunction( pix + (theApp.filterWidth * (systemColorDepth>>3)) + 4, + (theApp.filterWidth * (systemColorDepth>>3)) + 4, + theApp.filterWidth, theApp.filterHeight ); } theApp.display->render(); + + Sm60FPS_Sleep(); } void systemScreenCapture(int captureNumber) @@ -875,7 +904,7 @@ u32 systemGetClock() { - return timeGetTime(); + return GetTickCount(); } void systemMessage(int number, const char *defaultMsg, ...) @@ -932,34 +961,18 @@ void system10Frames(int rate) { u32 time = systemGetClock(); - if(!theApp.wasPaused && theApp.autoFrameSkip && !theApp.throttle) { - u32 diff = time - theApp.autoFrameSkipLastTime; - int speed = 100; - if(diff) - speed = (1000000/rate)/diff; - - if(speed >= 98) { - theApp.frameskipadjust++; + if (theApp.autoFrameSkip) + { + u32 diff = time - theApp.autoFrameSkipLastTime; + Sm60FPS::nCurSpeed = 100; - if(theApp.frameskipadjust >= 3) { - theApp.frameskipadjust=0; - if(systemFrameSkip > 0) - systemFrameSkip--; - } - } else { - if(speed < 80) - theApp.frameskipadjust -= (90 - speed)/5; - else if(systemFrameSkip < 9) - theApp.frameskipadjust--; - - if(theApp.frameskipadjust <= -2) { - theApp.frameskipadjust += 2; - if(systemFrameSkip < 9) - systemFrameSkip++; - } - } + if (diff) + Sm60FPS::nCurSpeed = (1000000/rate)/diff; } + + + if(!theApp.wasPaused && theApp.throttle) { if(!speedup) { u32 diff = time - theApp.throttleLastTime; @@ -1074,7 +1087,7 @@ void systemGbBorderOn() { - if(emulating && theApp.cartridgeType == 1 && gbBorderOn) { + if(emulating && theApp.cartridgeType == IMAGE_GB && gbBorderOn) { theApp.updateWindowSize(theApp.videoOption); } } @@ -1170,9 +1183,9 @@ winSetLanguageOption(languageOption, true); - frameSkip = regQueryDwordValue("frameSkip", 2); + frameSkip = regQueryDwordValue("frameSkip", 0); if(frameSkip < 0 || frameSkip > 9) - frameSkip = 2; + frameSkip = 0; gbFrameSkip = regQueryDwordValue("gbFrameSkip", 0); if(gbFrameSkip < 0 || gbFrameSkip > 9) @@ -1184,8 +1197,7 @@ synchronize = regQueryDwordValue("synchronize", 1) ? true : false; fullScreenStretch = regQueryDwordValue("stretch", 0) ? true : false; - videoOption = regQueryDwordValue("video", 0); - + videoOption = regQueryDwordValue("video", 1); if(videoOption < 0 || videoOption > VIDEO_OTHER) videoOption = 0; @@ -1202,9 +1214,11 @@ else pVideoDriverGUID = &videoDriverGUID; + fsAdapter = regQueryDwordValue("fsAdapter", 0); fsWidth = regQueryDwordValue("fsWidth", 0); fsHeight = regQueryDwordValue("fsHeight", 0); fsColorDepth = regQueryDwordValue("fsColorDepth", 0); + fsFrequency = regQueryDwordValue("fsFrequency", 0); if(videoOption == VIDEO_OTHER) { if(fsWidth < 0 || fsWidth > 4095 || fsHeight < 0 || fsHeight > 4095) @@ -1214,7 +1228,6 @@ } renderMethod = (DISPLAY_TYPE)regQueryDwordValue("renderMethod", DIRECT_DRAW); - if(renderMethod < GDI || renderMethod > OPENGL) renderMethod = DIRECT_DRAW; @@ -1242,7 +1255,7 @@ soundOffFlag = (regQueryDwordValue("soundOff", 0)) ? true : false; - soundQuality = regQueryDwordValue("soundQuality", 2); + soundQuality = regQueryDwordValue("soundQuality", 1); soundEcho = regQueryDwordValue("soundEcho", 0) ? true : false; @@ -1255,15 +1268,17 @@ soundVolume = 0; ddrawEmulationOnly = regQueryDwordValue("ddrawEmulationOnly", false) ? true : false; - ddrawUseVideoMemory = regQueryDwordValue("ddrawUseVideoMemory", false) ? true : false; - tripleBuffering = regQueryDwordValue("tripleBuffering", true) ? true : false; + ddrawUseVideoMemory = regQueryDwordValue("ddrawUseVideoMemory", true) ? true : false; + tripleBuffering = regQueryDwordValue("tripleBuffering", false) ? true : false; - d3dFilter = regQueryDwordValue("d3dFilter", 0); + d3dFilter = regQueryDwordValue("d3dFilter", 1); if(d3dFilter < 0 || d3dFilter > 1) - d3dFilter = 0; - glFilter = regQueryDwordValue("glFilter", 0); + d3dFilter = 1; + + glFilter = regQueryDwordValue("glFilter", 1); if(glFilter < 0 || glFilter > 1) - glFilter = 0; + glFilter = 1; + glType = regQueryDwordValue("glType", 0); if(glType < 0 || glType > 1) glType = 0; @@ -1272,7 +1287,7 @@ if(filterType < 0 || filterType > 13) filterType = 0; - disableMMX = regQueryDwordValue("disableMMX", 0) ? true: false; + disableMMX = regQueryDwordValue("disableMMX", false) ? true: false; disableStatusMessage = regQueryDwordValue("disableStatus", 0) ? true : false; @@ -1310,9 +1325,6 @@ if(winSaveType < 0 || winSaveType > 5) winSaveType = 0; - cpuEnhancedDetection = regQueryDwordValue("enhancedDetection", 1) ? true : - false; - ifbType = regQueryDwordValue("ifbType", 0); if(ifbType < 0 || ifbType > 2) ifbType = 0; @@ -1320,6 +1332,7 @@ winFlashSize = regQueryDwordValue("flashSize", 0x10000); if(winFlashSize != 0x10000 && winFlashSize != 0x20000) winFlashSize = 0x10000; + flashSize = winFlashSize; agbPrintEnable(regQueryDwordValue("agbPrint", 0) ? true : false); @@ -1407,6 +1420,15 @@ throttle = regQueryDwordValue("throttle", 0); if(throttle < 5 || throttle > 1000) throttle = 0; + + if (autoFrameSkip) + { + throttle = 0; + frameSkip = 0; + systemFrameSkip = 0; + } + + Sm60FPS::bSaveMoreCPU = regQueryDwordValue("saveMoreCPU", 0); } void VBA::updateFrameSkip() @@ -1442,28 +1464,25 @@ value = VIDEO_320x240; fsWidth = 320; fsHeight = 240; - fsColorDepth = 16; + fsColorDepth = 32; break; case ID_OPTIONS_VIDEO_FULLSCREEN640X480: value = VIDEO_640x480; fsWidth = 640; fsHeight = 480; - fsColorDepth = 16; + fsColorDepth = 32; break; case ID_OPTIONS_VIDEO_FULLSCREEN800X600: value = VIDEO_800x600; fsWidth = 800; fsHeight = 600; - fsColorDepth = 16; + fsColorDepth = 32; break; case ID_OPTIONS_VIDEO_FULLSCREEN: value = VIDEO_OTHER; break; } - if(videoOption == value && value != VIDEO_OTHER) - return; - updateWindowSize(value); } @@ -1474,15 +1493,18 @@ HINSTANCE hinstDll; DWORD dwVersion = 0; - hinstDll = AfxLoadLibrary("USER32.DLL"); +#ifdef _AFXDLL + hinstDll = AfxLoadLibrary("user32.dll"); +#else + hinstDll = LoadLibrary( _T("user32.dll") ); +#endif if(hinstDll) { - GETMENUBARINFO func = (GETMENUBARINFO)GetProcAddress(hinstDll, - "GetMenuBarInfo"); + GETMENUBARINFO func = (GETMENUBARINFO)GetProcAddress(hinstDll, "GetMenuBarInfo"); if(func) { MENUBARINFO info; - info.cbSize = sizeof(info); + info.cbSize = sizeof(MENUBARINFO); func(AfxGetMainWnd()->GetSafeHwnd(), OBJID_MENU, 0, &info); @@ -1499,7 +1521,11 @@ SWP_NOMOVE | SWP_SHOWWINDOW); } } - AfxFreeLibrary(hinstDll); +#ifdef _AFXDLL + AfxFreeLibrary( hinstDll ); +#else + FreeLibrary( hinstDll ); +#endif } } @@ -1561,7 +1587,7 @@ videoOption = value; - if(cartridgeType == 1) { + if(cartridgeType == IMAGE_GB) { if(gbBorderOn) { sizeX = 256; sizeY = 224; @@ -1660,6 +1686,9 @@ updateIFB(); updateFilter(); + if(display) + display->resize(theApp.dest.right-theApp.dest.left, theApp.dest.bottom-theApp.dest.top); + m_pMainWnd->RedrawWindow(NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN); } @@ -1670,26 +1699,37 @@ bool VBA::updateRenderMethod(bool force) { - bool res = updateRenderMethod0(force); - - while(!res && renderMethod > 0) { - if(renderMethod == OPENGL) - renderMethod = DIRECT_3D; - else if(renderMethod == DIRECT_3D) - renderMethod = DIRECT_DRAW; - else if(renderMethod == DIRECT_DRAW) { - if(videoOption > VIDEO_4X) { - videoOption = VIDEO_2X; - force = true; - } else - renderMethod = GDI; - } - - res = updateRenderMethod(force); - } - return res; + Sm60FPS_Init(); + bool res = updateRenderMethod0(force); + + while(!res && renderMethod > 0) { + if( fsAdapter > 0 ) { + fsAdapter = 0; + } else { + if( videoOption > VIDEO_4X ) { + videoOption = VIDEO_1X; + force = true; + } else { + if(renderMethod == OPENGL) { + renderMethod = DIRECT_3D; + } else { + if(renderMethod == DIRECT_3D) { + renderMethod = DIRECT_DRAW; + } else { + if(renderMethod == DIRECT_DRAW) { + renderMethod = GDI; + } + } + } + } + } + res = updateRenderMethod(force); + } + + return res; } + bool VBA::updateRenderMethod0(bool force) { bool initInput = false; @@ -1721,17 +1761,19 @@ if(display == NULL) { switch(renderMethod) { case GDI: - display = newGDIDisplay(); - break; + display = newGDIDisplay(); + break; case DIRECT_DRAW: - display = newDirectDrawDisplay(); - break; + pVideoDriverGUID = NULL; + ZeroMemory( &videoDriverGUID, sizeof( GUID ) ); + display = newDirectDrawDisplay(); + break; case DIRECT_3D: - display = newDirect3DDisplay(); - break; - case OPENGL: - display = newOpenGLDisplay(); - break; + display = newDirect3DDisplay(); + break; + case OPENGL: + display = newOpenGLDisplay(); + break; } if(display->initialize()) { @@ -1762,14 +1804,17 @@ return true; } + void VBA::winCheckFullscreen() { - if(videoOption > VIDEO_4X && tripleBuffering) { - if(display) - display->checkFullScreen(); - } + if(videoOption > VIDEO_4X && tripleBuffering) { + if(display) { + display->checkFullScreen(); + } + } } + void VBA::shutdownDisplay() { if(display != NULL) { @@ -1788,6 +1833,7 @@ void VBA::winUpdateSkin() { +#ifndef NOSKINS skinButtons = 0; if(skin) { delete skin; @@ -1809,6 +1855,7 @@ adjustDestRect(); updateMenuBar(); } +#endif } void VBA::updatePriority() @@ -1896,7 +1943,11 @@ } AfxSetResourceHandle(l); if(languageModule != NULL) - AfxFreeLibrary(languageModule); +#ifdef _AFXDLL + AfxFreeLibrary( languageModule ); +#else + FreeLibrary( languageModule ); +#endif languageModule = l; } else { systemMessage(IDS_FAILED_TO_GET_LOCINFO, @@ -1907,7 +1958,11 @@ break; case 1: if(languageModule != NULL) - AfxFreeLibrary(languageModule); +#ifdef _AFXDLL + AfxFreeLibrary( languageModule ); +#else + FreeLibrary( languageModule ); +#endif languageModule = NULL; AfxSetResourceHandle(AfxGetInstanceHandle()); break; @@ -1925,7 +1980,13 @@ } AfxSetResourceHandle(l); if(languageModule != NULL) - AfxFreeLibrary(languageModule); + { +#ifdef _AFXDLL + AfxFreeLibrary( languageModule ); +#else + FreeLibrary( languageModule ); +#endif + } languageModule = l; } } else { @@ -1954,9 +2015,13 @@ { CString buffer; - buffer.Format("vba_%s.dll", name); + buffer.Format( _T("vba_%s.dll"), name); - HINSTANCE l = AfxLoadLibrary(buffer); +#ifdef _AFXDLL + HINSTANCE l = AfxLoadLibrary( buffer ); +#else + HMODULE l = LoadLibrary( buffer ); +#endif if(l == NULL) { if(strlen(name) == 3) { @@ -1966,7 +2031,11 @@ buffer2[2] = 0; buffer.Format("vba_%s.dll", buffer2); - return AfxLoadLibrary(buffer); +#ifdef _AFXDLL + return AfxLoadLibrary( buffer ); +#else + return LoadLibrary( buffer ); +#endif } } return l; @@ -2065,9 +2134,11 @@ } + regSetDwordValue("fsAdapter", fsAdapter); regSetDwordValue("fsWidth", fsWidth); regSetDwordValue("fsHeight", fsHeight); regSetDwordValue("fsColorDepth", fsColorDepth); + regSetDwordValue("fsFrequency", fsFrequency); regSetDwordValue("renderMethod", renderMethod); @@ -2131,8 +2202,6 @@ regSetDwordValue("saveType", winSaveType); - regSetDwordValue("enhancedDetection", cpuEnhancedDetection); - regSetDwordValue("ifbType", ifbType); regSetDwordValue("flashSize", winFlashSize); @@ -2174,6 +2243,8 @@ regSetDwordValue("cheatsEnabled", cheatsEnabled); regSetDwordValue("fsMaxScale", fsMaxScale); regSetDwordValue("throttle", throttle); + + regSetDwordValue("saveMoreCPU", Sm60FPS::bSaveMoreCPU); } void winSignal(int, int) @@ -2201,3 +2272,73 @@ toolsLog(str); } } + + +void Sm60FPS_Init() +{ + Sm60FPS::dwTimeElapse = 0; + Sm60FPS::fWantFPS = 60.f; + Sm60FPS::fCurFPS = 0.f; + Sm60FPS::nFrameCnt = 0; + Sm60FPS::bLastSkip = false; + Sm60FPS::nCurSpeed = 100; +} + + +bool Sm60FPS_CanSkipFrame() +{ + if( theApp.autoFrameSkip ) { + if( Sm60FPS::nFrameCnt == 0 ) { + Sm60FPS::nFrameCnt = 0; + Sm60FPS::dwTimeElapse = 0; + Sm60FPS::dwTime0 = timeGetTime(); + } else { + if( Sm60FPS::nFrameCnt >= 10 ) { + Sm60FPS::nFrameCnt = 0; + Sm60FPS::dwTimeElapse = 0; + + if( Sm60FPS::nCurSpeed > Sm60FPS::K_fCpuSpeed ) { + Sm60FPS::fWantFPS += 1; + if( Sm60FPS::fWantFPS > Sm60FPS::K_fTargetFps ){ + Sm60FPS::fWantFPS = Sm60FPS::K_fTargetFps; + } + } else { + if( Sm60FPS::nCurSpeed < (Sm60FPS::K_fCpuSpeed - 5) ) { + Sm60FPS::fWantFPS -= 1; + if( Sm60FPS::fWantFPS < 30.f ) { + Sm60FPS::fWantFPS = 30.f; + } + } + } + } else { // between frame 1-10 + Sm60FPS::dwTime1 = timeGetTime(); + Sm60FPS::dwTimeElapse += (Sm60FPS::dwTime1 - Sm60FPS::dwTime0); + Sm60FPS::dwTime0 = Sm60FPS::dwTime1; + if( !Sm60FPS::bLastSkip && + ( (Sm60FPS::fWantFPS < Sm60FPS::K_fTargetFps) || Sm60FPS::bSaveMoreCPU) ) { + Sm60FPS::fCurFPS = (float)Sm60FPS::nFrameCnt * 1000 / Sm60FPS::dwTimeElapse; + if( (Sm60FPS::fCurFPS < Sm60FPS::K_fTargetFps) || Sm60FPS::bSaveMoreCPU ) { + Sm60FPS::bLastSkip = true; + Sm60FPS::nFrameCnt++; + return true; + } + } + } + } + Sm60FPS::bLastSkip = false; + Sm60FPS::nFrameCnt++; + } + return false; +} + + +void Sm60FPS_Sleep() +{ + if( theApp.autoFrameSkip ) { + u32 dwTimePass = Sm60FPS::dwTimeElapse + (timeGetTime() - Sm60FPS::dwTime0); + u32 dwTimeShould = (u32)(Sm60FPS::nFrameCnt * Sm60FPS::K_fDT); + if( dwTimeShould > dwTimePass ) { + Sleep(dwTimeShould - dwTimePass); + } + } +} diff -urN ../VisualBoyAdvance-1.7.2/src/win32/VBA.h ./src/win32/VBA.h --- ../VisualBoyAdvance-1.7.2/src/win32/VBA.h 2004-05-13 22:32:30 +0900 +++ ./src/win32/VBA.h 2006-08-06 21:40:35 +0900 @@ -1,7 +1,7 @@ // -*- C++ -*- // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten -// Copyright (C) 2004 Forgotten and the VBA development team +// Copyright (C) 2005 Forgotten and the VBA development team // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,26 +20,23 @@ // VBA.h : main header file for the VBA application // -#if !defined(AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_) -#define AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_ - -#if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif -#include +#include "stdafx.h" +#include "resource.h" +//#include #include "AcceleratorManager.h" -#include "resource.h" // main symbols #include "Display.h" #include "Input.h" #include "IUpdate.h" #include "Sound.h" #include "../System.h" +#include "../Util.h" ///////////////////////////////////////////////////////////////////////////// // VBA: @@ -47,8 +44,14 @@ // enum { - VIDEO_1X, VIDEO_2X, VIDEO_3X, VIDEO_4X, - VIDEO_320x240, VIDEO_640x480, VIDEO_800x600, VIDEO_OTHER + VIDEO_1X, + VIDEO_2X, + VIDEO_3X, + VIDEO_4X, + VIDEO_320x240, + VIDEO_640x480, + VIDEO_800x600, + VIDEO_OTHER }; #define REWIND_SIZE 400000 @@ -74,9 +77,11 @@ int filterType; int filterWidth; int filterHeight; + int fsAdapter; int fsWidth; int fsHeight; int fsColorDepth; + int fsFrequency; bool fsForceChange; int sizeX; int sizeY; @@ -94,7 +99,7 @@ u8 *delta[257*244*4]; bool menuToggle; IDisplay *display; - int cartridgeType; + IMAGE_TYPE cartridgeType; bool soundInitialized; bool useBiosFile; bool skipBiosFile; @@ -110,6 +115,7 @@ int winGbBorderOn; int winFlashSize; bool winRtcEnable; + bool winGenericflashcardEnable; int winSaveType; char *rewindMemory; int rewindPos; @@ -150,7 +156,7 @@ bool disableMMX; int languageOption; CString languageName; - HINSTANCE languageModule; + HMODULE languageModule; int renderedFrames; Input *input; int joypadDefault; @@ -160,6 +166,7 @@ bool soundRecording; WavWriter *soundRecorder; CString soundRecordName; + bool dsoundDisableHardwareAcceleration; ISound *sound; bool aviRecording; AVIWrite *aviRecorder; @@ -225,10 +232,10 @@ void saveSettings(); void movieReadNext(); bool initInput(); - HINSTANCE winLoadLanguage(const char *name); + HMODULE winLoadLanguage(const char *name); void winSetLanguageOption(int option, bool force); - bool detectMMX(); #ifdef MMX + bool detectMMX(); #endif void updatePriority(); void winUpdateSkin(); @@ -252,14 +259,8 @@ }; extern VBA theApp; + extern int emulating; #ifdef MMX extern "C" bool cpu_mmx; -#endif - - ///////////////////////////////////////////////////////////////////////////// - - //{{AFX_INSERT_LOCATION}} - // Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_VBA_H__57514A10_49F9_4B83_A928_0D8A4A7306A3__INCLUDED_) +#endif \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/src/win32/VideoMode.cpp ./src/win32/VideoMode.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/VideoMode.cpp 2004-05-13 23:15:52 +0900 +++ ./src/win32/VideoMode.cpp 2006-07-26 22:02:44 +0900 @@ -100,22 +100,31 @@ static HRESULT WINAPI addVideoMode(LPDDSURFACEDESC2 surf, LPVOID lpContext) { - HWND h = (HWND)lpContext; - char buffer[50]; - - switch(surf->ddpfPixelFormat.dwRGBBitCount) { - case 16: - case 24: - case 32: - if(surf->dwWidth >= 640 && surf->dwHeight >= 480) { - sprintf(buffer, "%4dx%4dx%2d", surf->dwWidth, surf->dwHeight, - surf->ddpfPixelFormat.dwRGBBitCount); - int pos = ::SendMessage(h, LB_ADDSTRING, 0, (LPARAM)buffer); - ::SendMessage(h, LB_SETITEMDATA, pos, - (surf->ddpfPixelFormat.dwRGBBitCount << 24) | - ((surf->dwWidth & 4095) << 12) | - (surf->dwHeight & 4095)); - } + HWND h = (HWND)lpContext; + char buffer[50]; + + switch( surf->ddpfPixelFormat.dwRGBBitCount ) + { + case 16: + case 24: + case 32: + sprintf( + buffer, + _T("%4dx%4dx%2d"), + surf->dwWidth, + surf->dwHeight, + surf->ddpfPixelFormat.dwRGBBitCount + ); + WPARAM pos = ::SendMessage( h, LB_ADDSTRING, 0, (LPARAM)buffer ); + ::SendMessage( + h, + LB_SETITEMDATA, + pos, + (surf->ddpfPixelFormat.dwRGBBitCount << 24) | + ((surf->dwWidth & 4095) << 12) | + (surf->dwHeight & 4095) + ); + break; } return DDENUMRET_OK; @@ -123,7 +132,11 @@ int winVideoModeSelect(CWnd *pWnd, GUID **guid) { +#ifdef _AFXDLL HINSTANCE h = AfxLoadLibrary("ddraw.dll"); +#else + HMODULE h = LoadLibrary( _T("ddraw.dll") ); +#endif // If ddraw.dll doesn't exist in the search path, // then DirectX probably isn't installed, so fail. @@ -180,12 +193,14 @@ if(gDriverCnt > 1) { VideoDriverSelect d(pWnd); - selected = d.DoModal(); + INT_PTR selected = d.DoModal(); if(selected == -1) { - // If the library was loaded by calling LoadLibrary(), - // then you must use FreeLibrary() to let go of it. - AfxFreeLibrary(h); +#ifdef _AFXDLL + AfxFreeLibrary( h ); +#else + FreeLibrary( h ); +#endif return -1; } @@ -203,19 +218,27 @@ NULL); if(hret != DD_OK) { systemMessage(0, "Error during DirectDrawCreateEx: %08x", hret); - AfxFreeLibrary(h); +#ifdef _AFXDLL + AfxFreeLibrary( h ); +#else + FreeLibrary( h ); +#endif return -1; } } else { // should not happen.... systemMessage(0, "Error getting DirectDrawCreateEx"); - AfxFreeLibrary(h); +#ifdef _AFXDLL + AfxFreeLibrary( h ); +#else + FreeLibrary( h ); +#endif return -1; } VideoMode dlg(ddraw, pWnd); - int res = dlg.DoModal(); + INT_PTR res = dlg.DoModal(); if(res != -1) { *guid = Drivers[selected].pGUID; @@ -225,9 +248,13 @@ // If the library was loaded by calling LoadLibrary(), // then you must use FreeLibrary() to let go of it. - AfxFreeLibrary(h); +#ifdef _AFXDLL + AfxFreeLibrary( h ); +#else + FreeLibrary( h ); +#endif - return res; + return (int)res; } ///////////////////////////////////////////////////////////////////////////// @@ -278,12 +305,12 @@ void VideoMode::OnOk() { - int cur = m_modes.GetCurSel(); + DWORD_PTR cur = m_modes.GetCurSel(); if(cur != -1) { - cur = m_modes.GetItemData(cur); + cur = m_modes.GetItemData((int)cur); } - EndDialog(cur); + EndDialog((int)cur); } BOOL VideoMode::OnInitDialog() @@ -291,8 +318,11 @@ CDialog::OnInitDialog(); // check for available fullscreen modes - pDirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, m_modes.m_hWnd, - addVideoMode); + pDirectDraw->EnumDisplayModes( + DDEDM_STANDARDVGAMODES, + NULL, + m_modes.m_hWnd, + addVideoMode); GetDlgItem(ID_OK)->EnableWindow(FALSE); CenterWindow(); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/ZoomControl.h ./src/win32/ZoomControl.h --- ../VisualBoyAdvance-1.7.2/src/win32/ZoomControl.h 2004-05-13 22:30:22 +0900 +++ ./src/win32/ZoomControl.h 2006-05-27 23:47:33 +0900 @@ -20,7 +20,7 @@ #if !defined(AFX_ZOOMCONTROL_H__BC193230_D2D6_4240_93AE_28C2EF2C641A__INCLUDED_) #define AFX_ZOOMCONTROL_H__BC193230_D2D6_4240_93AE_28C2EF2C641A__INCLUDED_ -#include "..\System.h" // Added by ClassView +#include "../System.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 diff -urN ../VisualBoyAdvance-1.7.2/src/win32/display.cpp ./src/win32/display.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/display.cpp 1970-01-01 09:00:00 +0900 +++ ./src/win32/display.cpp 2006-08-01 00:51:01 +0900 @@ -0,0 +1,123 @@ +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 1999-2003 Forgotten +// Copyright (C) 2004 Forgotten and the VBA development team + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or(at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "stdafx.h" +#include "Display.h" + +void copyImage( void *source, void *destination, unsigned int width, unsigned int height, unsigned int destinationPitch, unsigned int colorDepth ) +{ +#ifdef ASM + + // Copy the image at [source] to the locked Direct3D texture + __asm + { + mov eax, width ; Initialize + mov ebx, height ; + mov edi, destination ; + mov edx, destinationPitch ; + + cmp colorDepth, 16 ; Check colorDepth==16bit + jnz gbaOtherColor ; + sub edx, eax ; + sub edx, eax ; + mov esi, source ; + lea esi,[esi+2*eax+4] ; + shr eax, 1 ; +gbaLoop16bit: + mov ecx, eax ; + rep movsd ; + add esi, 4 ; + add edi, edx ; + dec ebx ; + jnz gbaLoop16bit ; + jmp gbaLoopEnd ; +gbaOtherColor: + cmp colorDepth, 32 ; Check colorDepth==32bit + jnz gbaOtherColor2 ; + + lea esi, [eax*4] ; + sub edx, esi ; + mov esi, source ; + lea esi, [esi+4*eax+4] ; +gbaLoop32bit: + mov ecx, eax ; + rep movsd ; ECX times: Move DWORD at [ESI] to [EDI] | ESI++ EDI++ + add esi, 4 ; + add edi, edx ; + dec ebx ; + jnz gbaLoop32bit ; + jmp gbaLoopEnd ; +gbaOtherColor2: + lea eax, [eax+2*eax] ; Works like colorDepth==24bit + sub edx, eax ; +gbaLoop24bit: + mov ecx, eax ; + shr ecx, 2 ; + rep movsd ; + add edi, edx ; + dec ebx ; + jnz gbaLoop24bit ; +gbaLoopEnd: + } + +#else // #ifdef ASM + + // optimized C version + register unsigned int lineSize; + register unsigned char *src, *dst; + switch(colorDepth) + { + case 16: + lineSize = width<<1; + src = ((unsigned char*)source) + lineSize + 4; + dst = (unsigned char*)destination; + do { + MoveMemory( dst, src, lineSize ); + src+=lineSize; + dst+=lineSize; + src += 2; + dst += (destinationPitch - lineSize); + } while ( --height); + break; + case 32: + lineSize = width<<2; + src = ((unsigned char*)source) + lineSize + 4; + dst = (unsigned char*)destination; + do { + MoveMemory( dst, src, lineSize ); + src+=lineSize; + dst+=lineSize; + src += 4; + dst += (destinationPitch - lineSize); + } while ( --height); + break; + } + + // very compatible but slow C version + //unsigned int nBytesPerPixel = colorDepth>>3; + //unsigned int i, x, y, srcPitch = (width+1) * nBytesPerPixel; + //unsigned char * src = ((unsigned char*)source)+srcPitch; + //unsigned char * dst = (unsigned char*)destination; + //for (y=0;yGetWindowRect(&r); @@ -168,7 +168,7 @@ pWnd->SetWindowRgn(m_rgnSkin, true); // subclass the window procedure - m_OldWndProc = (WNDPROC)SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG)SkinWndProc); + m_OldWndProc = (WNDPROC)SetWindowLongPtr( m_hWnd, GWLP_WNDPROC, (LONG_PTR)SkinWndProc ); // store a pointer to our class instance inside the window procedure. if (!SetProp(m_hWnd, "skin", (void*)this)) @@ -214,7 +214,7 @@ SetWindowRgn(m_hWnd, NULL, true); // unsubclass the window procedure - OurWnd = (WNDPROC)SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG)m_OldWndProc); + OurWnd = (WNDPROC)SetWindowLongPtr( m_hWnd, GWLP_WNDPROC, (LONG_PTR)m_OldWndProc ); // remove the pointer to our class instance, but if we fail we don't care. RemoveProp(m_hWnd, "skin"); @@ -223,7 +223,7 @@ // we failed to unhook the window. m_bHooked = ( OurWnd ? false : true ); - SetWindowLong(m_hWnd, GWL_STYLE, m_dOldStyle); + SetWindowLongPtr(m_hWnd, GWL_STYLE, m_dOldStyle); RECT r; @@ -533,7 +533,7 @@ { // we will need a pointer to the associated class instance // (it was stored in the window before, remember?) - CSkin *pSkin = (CSkin*)GetProp(hWnd, "skin"); + CSkin *pSkin = (CSkin*)GetProp(hWnd, _T("skin")); // to handle WM_PAINT PAINTSTRUCT ps; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/skin.h ./src/win32/skin.h --- ../VisualBoyAdvance-1.7.2/src/win32/skin.h 2004-05-13 22:31:53 +0900 +++ ./src/win32/skin.h 2006-05-27 23:47:33 +0900 @@ -67,7 +67,7 @@ RECT m_rect; - DWORD m_dOldStyle; + LONG_PTR m_dOldStyle; RECT m_oldRect; int m_nButtons; SkinButton *m_buttons; diff -urN ../VisualBoyAdvance-1.7.2/src/win32/skinButton.cpp ./src/win32/skinButton.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/skinButton.cpp 2004-05-13 23:14:10 +0900 +++ ./src/win32/skinButton.cpp 2006-08-26 00:27:16 +0900 @@ -97,7 +97,7 @@ PAINTSTRUCT ps; HDC hDC = ::BeginPaint(m_hWnd, &ps); HDC memDC = ::CreateCompatibleDC(hDC); - UINT state = ::SendMessage(m_hWnd, BM_GETSTATE, 0, 0); + LRESULT state = ::SendMessage(m_hWnd, BM_GETSTATE, 0, 0); HBITMAP oldBitmap; if(state & BST_PUSHED) oldBitmap = (HBITMAP)SelectObject(memDC, downBmp); @@ -126,6 +126,8 @@ if(region != NULL) inside &= PtInRegion(region, pt.x, pt.y); if(inside) { + ReleaseCapture(); + Invalidate(); HWND hWnd = m_hWnd; if(idCommand != 0) GetParent()->SendMessage(WM_COMMAND, idCommand, 0); diff -urN ../VisualBoyAdvance-1.7.2/src/win32/stdafx.cpp ./src/win32/stdafx.cpp --- ../VisualBoyAdvance-1.7.2/src/win32/stdafx.cpp 2004-05-13 23:13:56 +0900 +++ ./src/win32/stdafx.cpp 2006-05-27 23:47:33 +0900 @@ -16,11 +16,4 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// stdafx.cpp : source file that includes just the standard includes -// DialogSizer.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file +#include "stdafx.h" \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/src/win32/stdafx.h ./src/win32/stdafx.h --- ../VisualBoyAdvance-1.7.2/src/win32/stdafx.h 2004-05-13 22:28:48 +0900 +++ ./src/win32/stdafx.h 2006-05-27 23:47:33 +0900 @@ -33,6 +33,13 @@ // Insert your headers here //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Target for Windows 2000 +#define WINVER 0x0500 +#define _WIN32_WINNT 0x0500 + +#define STRICT + + #include #include #include diff -urN ../VisualBoyAdvance-1.7.2/src/win32/vba.rc ./src/win32/vba.rc --- ../VisualBoyAdvance-1.7.2/src/win32/vba.rc 2004-05-15 20:21:51 +0900 +++ ./src/win32/vba.rc 2006-08-06 21:40:35 +0900 @@ -1,4 +1,4 @@ -//Microsoft Developer Studio generated resource script. +// Microsoft Visual C++ generated resource script. // #include "resource.h" @@ -8,7 +8,7 @@ // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" -#include "vba.rc2" +#include "resource2.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -27,21 +27,20 @@ // TEXTINCLUDE // -1 TEXTINCLUDE DISCARDABLE +1 TEXTINCLUDE BEGIN "resource.h\0" END -2 TEXTINCLUDE DISCARDABLE +2 TEXTINCLUDE BEGIN "#include ""afxres.h""\r\n" - "#include ""vba.rc2""\0" + "#include ""resource2.h""\0" END -3 TEXTINCLUDE DISCARDABLE +3 TEXTINCLUDE BEGIN - "\r\n" - "\0" + "#include ""vba.rc2""\0" END #endif // APSTUDIO_INVOKED @@ -49,94 +48,77 @@ ///////////////////////////////////////////////////////////////////////////// // -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON ICON DISCARDABLE "gbadvance.ico" - -///////////////////////////////////////////////////////////////////////////// -// // Dialog // -IDD_OPENDLG DIALOG DISCARDABLE 36, 24, 202, 117 -STYLE DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | - WS_SYSMENU +IDD_OPENDLG DIALOG 36, 24, 202, 117 +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Open" FONT 8, "MS Shell Dlg" BEGIN LTEXT "File &name:",1090,2,1,81,8 EDITTEXT 1152,0,10,104,12,ES_AUTOHSCROLL | ES_OEMCONVERT - LISTBOX 1120,1,24,104,53,LBS_SORT | LBS_OWNERDRAWFIXED | - LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | - WS_TABSTOP + LISTBOX 1120,1,24,104,53,LBS_SORT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP LTEXT "&Folders:",-1,112,0,53,9 LTEXT "",1088,113,10,86,9,SS_NOPREFIX - LISTBOX 1121,112,24,88,52,LBS_SORT | LBS_OWNERDRAWFIXED | - LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | - WS_TABSTOP + LISTBOX 1121,112,24,88,52,LBS_SORT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP LTEXT "List files of &type:",1089,1,75,81,9 - COMBOBOX 1136,1,87,104,13,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | - WS_VSCROLL | WS_TABSTOP + COMBOBOX 1136,1,87,104,13,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP LTEXT "Dri&ves:",1091,113,76,70,9 - COMBOBOX 1137,112,87,71,68,CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | - CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_VSCROLL | - WS_TABSTOP + COMBOBOX 1137,112,87,71,68,CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP DEFPUSHBUTTON "OK",IDOK,24,102,50,14,WS_GROUP PUSHBUTTON "Cancel",IDCANCEL,90,102,50,14,WS_GROUP END -IDD_ABOUT DIALOG DISCARDABLE 0, 0, 164, 93 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "About VisualBoyAdvance" -FONT 8, "MS Sans Serif" -BEGIN - DEFPUSHBUTTON "OK",IDOK,56,72,50,14 - ICON IDI_ICON,IDC_STATIC,5,12,21,20 - CTEXT "VisualBoyAdvance Emulator",IDC_STATIC,14,7,134,8 - CTEXT "Copyright (c) 2004 Forgotten and the VBA team", - IDC_STATIC,6,35,150,8 - CTEXT "http://vba.ngemu.com",IDC_URL,43,55,76,8 - CTEXT "Contribution by Costis",IDC_STATIC,30,45,102,8 - CTEXT "Version",IDC_STATIC,46,16,70,8 - CTEXT "",IDC_VERSION,60,25,43,8 -END - -IDD_DIRECTORIES DIALOG DISCARDABLE 0, 0, 284, 129 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_ABOUT DIALOGEX 0, 0, 157, 78 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "About" +FONT 8, "MS Sans Serif", 0, 0, 0x0 +BEGIN + ICON 101,IDC_STATIC,6,6,20,20 + CTEXT "VisualBoyAdvance Emulator",IDC_STATIC,30,6,120,8 + CTEXT "Copyright © 2006 VBA development team",IDC_STATIC,6,36,144,8 + CTEXT "http://vba.ngemu.com",IDC_URL,6,66,144,8 + CTEXT "Contribution by Costis",IDC_STATIC,6,48,144,8 + CTEXT "Version",IDC_STATIC,30,18,60,8 + CTEXT "",IDC_VERSION,90,18,60,8,SS_NOPREFIX +END + +IDD_DIRECTORIES DIALOGEX 0, 0, 220, 301 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW CAPTION "Directories" -FONT 8, "MS Sans Serif" +FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN - PUSHBUTTON "Browse...",IDC_ROM_DIR,174,7,50,14 - PUSHBUTTON "Browse...",IDC_GBROM_DIR,174,26,50,14 - PUSHBUTTON "Browse...",IDC_BATTERY_DIR,174,45,50,14 - PUSHBUTTON "Browse...",IDC_SAVE_DIR,174,64,50,14 - PUSHBUTTON "Browse...",IDC_CAPTURE_DIR,174,83,50,14 - DEFPUSHBUTTON "OK",IDOK,88,108,50,14 - PUSHBUTTON "Cancel",IDCANCEL,145,108,50,14 - LTEXT "ROM:",IDC_STATIC,7,9,20,8 - LTEXT "Battery:",IDC_STATIC,7,47,25,8 - LTEXT "Save Game:",IDC_STATIC,7,66,40,8 - LTEXT "Capture:",IDC_STATIC,7,85,28,8 - EDITTEXT IDC_ROM_PATH,49,7,121,14,ES_AUTOHSCROLL | WS_DISABLED - EDITTEXT IDC_BATTERY_PATH,49,45,121,14,ES_AUTOHSCROLL | - WS_DISABLED - EDITTEXT IDC_SAVE_PATH,49,64,121,14,ES_AUTOHSCROLL | WS_DISABLED - EDITTEXT IDC_CAPTURE_PATH,49,83,121,14,ES_AUTOHSCROLL | - WS_DISABLED - LTEXT "GB ROM:",IDC_STATIC,7,28,32,8 - EDITTEXT IDC_GBROM_PATH,49,26,121,14,ES_AUTOHSCROLL | WS_DISABLED - PUSHBUTTON "Reset",IDC_ROM_DIR_RESET,228,6,50,14 - PUSHBUTTON "Reset",IDC_GBROM_DIR_RESET,228,25,50,14 - PUSHBUTTON "Reset",IDC_BATTERY_DIR_RESET,228,45,50,14 - PUSHBUTTON "Reset",IDC_SAVE_DIR_RESET,228,64,50,14 - PUSHBUTTON "Reset",IDC_CAPTURE_DIR_RESET,228,83,50,14 + PUSHBUTTON "Browse...",IDC_ROM_DIR,12,66,90,12 + PUSHBUTTON "Browse...",IDC_GBROM_DIR,12,114,90,12 + PUSHBUTTON "Browse...",IDC_BATTERY_DIR,12,162,90,12 + PUSHBUTTON "Browse...",IDC_SAVE_DIR,12,210,90,12 + PUSHBUTTON "Browse...",IDC_CAPTURE_DIR,12,258,90,12 + DEFPUSHBUTTON "OK",IDOK,120,282,42,12 + PUSHBUTTON "Cancel",IDCANCEL,168,282,42,12 + EDITTEXT IDC_ROM_PATH,12,54,198,12,ES_AUTOHSCROLL + EDITTEXT IDC_BATTERY_PATH,12,150,198,12,ES_AUTOHSCROLL + EDITTEXT IDC_SAVE_PATH,12,198,198,12,ES_AUTOHSCROLL + EDITTEXT IDC_CAPTURE_PATH,12,246,198,12,ES_AUTOHSCROLL + EDITTEXT IDC_GBROM_PATH,12,102,198,12,ES_AUTOHSCROLL + PUSHBUTTON "Reset",IDC_ROM_DIR_RESET,120,66,90,12 + PUSHBUTTON "Reset",IDC_GBROM_DIR_RESET,120,114,84,12 + PUSHBUTTON "Reset",IDC_BATTERY_DIR_RESET,120,162,90,12 + PUSHBUTTON "Reset",IDC_SAVE_DIR_RESET,120,210,90,12 + PUSHBUTTON "Reset",IDC_CAPTURE_DIR_RESET,120,258,90,12 + CONTROL "You can either select or enter absolute paths to directories,\nor you can use relative paths by beginning with a . (point).\nExamples: c:\\emulation\\roms | .\\battery | ..\\snapshots\\gba",IDC_STATIC, + "Static",SS_LEFTNOWORDWRAP | WS_GROUP,6,6,210,30,WS_EX_STATICEDGE + GROUPBOX "Game Boy Advance ROM Images",IDC_STATIC,6,42,210,42 + GROUPBOX "Game Boy / Game Boy Color ROM Images",IDC_STATIC,6,90,210,42 + GROUPBOX "Game Boy Internal Battery Saves",IDC_STATIC,6,138,210,42 + GROUPBOX "Visual Boy Advance Save Games",IDC_STATIC,6,186,210,42 + GROUPBOX "Screenshots",IDC_STATIC,6,234,210,42 END -IDD_CONFIG DIALOG DISCARDABLE 0, 0, 135, 211 -STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_CONFIG DIALOG 0, 0, 135, 211 +STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Joypad configuration" FONT 8, "MS Sans Serif" BEGIN @@ -170,43 +152,27 @@ LTEXT "GS:",IDC_STATIC,5,173,35,10 END -IDD_CHEATS DIALOG DISCARDABLE 0, 0, 276, 253 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_CHEATS DIALOG 0, 0, 276, 253 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Search for cheats" FONT 8, "MS Sans Serif" BEGIN - CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | - LVS_SINGLESEL | WS_BORDER | WS_TABSTOP,3,5,265,111 - CONTROL "Ol&d value",IDC_OLD_VALUE,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,11,129,46,10 - CONTROL "Specifi&c value",IDC_SPECIFIC_VALUE,"Button", - BS_AUTORADIOBUTTON,11,141,61,10 - CONTROL "&8 bits",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,11,167,33,10 - CONTROL "&16 bits",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,11, - 179,37,10 - CONTROL "&32 bits",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,11, - 191,37,10 - CONTROL "&Equal",IDC_EQ,"Button",BS_AUTORADIOBUTTON | WS_GROUP, - 100,128,34,10 - CONTROL "&Not equal",IDC_NE,"Button",BS_AUTORADIOBUTTON,100,140, - 47,10 - CONTROL "&Less than",IDC_LT,"Button",BS_AUTORADIOBUTTON,100,152, - 47,10 - CONTROL "Le&ss or equal",IDC_LE,"Button",BS_AUTORADIOBUTTON,100, - 164,58,10 - CONTROL "&Greather than",IDC_GT,"Button",BS_AUTORADIOBUTTON,100, - 176,59,10 - CONTROL "G&reater or equal",IDC_GE,"Button",BS_AUTORADIOBUTTON, - 100,188,67,10 - CONTROL "S&igned",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,202,130,38,10 - CONTROL "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,202, - 142,46,10 - CONTROL "&Hexadecimal",IDC_HEXADECIMAL,"Button", - BS_AUTORADIOBUTTON,202,154,57,10 - CONTROL "U&pdate values",IDC_UPDATE,"Button",BS_AUTOCHECKBOX | - WS_GROUP | WS_TABSTOP,192,192,62,10 + CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | WS_BORDER | WS_TABSTOP,3,5,265,111 + CONTROL "Ol&d value",IDC_OLD_VALUE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,129,46,10 + CONTROL "Specifi&c value",IDC_SPECIFIC_VALUE,"Button",BS_AUTORADIOBUTTON,11,141,61,10 + CONTROL "&8 bits",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,167,33,10 + CONTROL "&16 bits",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,11,179,37,10 + CONTROL "&32 bits",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,11,191,37,10 + CONTROL "&Equal",IDC_EQ,"Button",BS_AUTORADIOBUTTON | WS_GROUP,100,128,34,10 + CONTROL "&Not equal",IDC_NE,"Button",BS_AUTORADIOBUTTON,100,140,47,10 + CONTROL "&Less than",IDC_LT,"Button",BS_AUTORADIOBUTTON,100,152,47,10 + CONTROL "Le&ss or equal",IDC_LE,"Button",BS_AUTORADIOBUTTON,100,164,58,10 + CONTROL "&Greather than",IDC_GT,"Button",BS_AUTORADIOBUTTON,100,176,59,10 + CONTROL "G&reater or equal",IDC_GE,"Button",BS_AUTORADIOBUTTON,100,188,67,10 + CONTROL "S&igned",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP,202,130,38,10 + CONTROL "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,202,142,46,10 + CONTROL "&Hexadecimal",IDC_HEXADECIMAL,"Button",BS_AUTORADIOBUTTON,202,154,57,10 + CONTROL "U&pdate values",IDC_UPDATE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,192,192,62,10 EDITTEXT IDC_VALUE,95,211,172,14,ES_AUTOHSCROLL PUSHBUTTON "&Start",IDC_START,15,237,50,14,WS_GROUP PUSHBUTTON "S&earch",IDC_SEARCH,80,236,50,14 @@ -219,26 +185,20 @@ LTEXT "Enter &value:",IDC_STATIC,3,214,69,8 END -IDD_ADD_CHEAT DIALOG DISCARDABLE 0, 0, 186, 137 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_ADD_CHEAT DIALOG 0, 0, 186, 137 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Add cheat" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_ADDRESS,60,6,123,14,ES_AUTOHSCROLL EDITTEXT IDC_VALUE,60,24,123,14,ES_AUTOHSCROLL EDITTEXT IDC_DESC,60,42,123,14,ES_AUTOHSCROLL - CONTROL "8-bit",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,11,70,29,10 - CONTROL "16-bit",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,62,70, - 33,10 - CONTROL "32-bit",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,117,70, - 33,10 - CONTROL "&Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,11,97,38,10 - CONTROL "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,62, - 98,46,10 - CONTROL "&Hexadecimal",IDC_HEXADECIMAL,"Button", - BS_AUTORADIOBUTTON,117,98,57,10 + CONTROL "8-bit",IDC_SIZE_8,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,11,70,29,10 + CONTROL "16-bit",IDC_SIZE_16,"Button",BS_AUTORADIOBUTTON,62,70,33,10 + CONTROL "32-bit",IDC_SIZE_32,"Button",BS_AUTORADIOBUTTON,117,70,33,10 + CONTROL "&Signed",IDC_SIGNED,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,11,97,38,10 + CONTROL "&Unsigned",IDC_UNSIGNED,"Button",BS_AUTORADIOBUTTON,62,98,46,10 + CONTROL "&Hexadecimal",IDC_HEXADECIMAL,"Button",BS_AUTORADIOBUTTON,117,98,57,10 DEFPUSHBUTTON "&OK",ID_OK,36,116,50,14,WS_GROUP PUSHBUTTON "&Cancel",ID_CANCEL,99,116,50,14 LTEXT "&Value:",IDC_STATIC,3,27,54,8 @@ -248,13 +208,12 @@ LTEXT "&Description:",IDC_STATIC,3,45,55,8 END -IDD_CHEAT_LIST DIALOG DISCARDABLE 0, 0, 280, 250 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_CHEAT_LIST DIALOG 0, 0, 280, 250 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Cheat list" FONT 8, "MS Sans Serif" BEGIN - CONTROL "Restore &previous values",IDC_RESTORE,"Button", - BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,5,183,92,10 + CONTROL "Restore &previous values",IDC_RESTORE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,5,183,92,10 PUSHBUTTON "&Code...",IDC_ADD_CODE,9,208,64,14,WS_GROUP PUSHBUTTON "C&heat...",IDC_ADD_CHEAT,75,208,64,14 PUSHBUTTON "&Gameshark...",IDC_ADD_GAMESHARK,141,208,64,14 @@ -263,41 +222,33 @@ PUSHBUTTON "Remove A&ll",IDC_REMOVE_ALL,75,230,64,14 PUSHBUTTON "&Enable/Dis.",IDC_ENABLE,141,230,64,14 DEFPUSHBUTTON "&OK",ID_OK,206,230,64,14,WS_GROUP - CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | - WS_GROUP | WS_TABSTOP,5,15,269,156 + CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | WS_GROUP | WS_TABSTOP,5,15,269,156 LTEXT "Status legend:",IDC_STATIC,6,3,46,8 LTEXT "E: Enabled",IDC_STATIC,188,3,36,8 LTEXT "D: Disabled",IDC_STATIC,234,3,38,8 GROUPBOX "Add",IDC_STATIC,5,199,268,27 END -IDD_ASSOCIATIONS DIALOG DISCARDABLE 0, 0, 116, 95 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_ASSOCIATIONS DIALOG 0, 0, 116, 95 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Associations" FONT 8, "MS Sans Serif" BEGIN - CONTROL ".gb",IDC_GB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,15, - 26,10 - CONTROL ".sgb",IDC_SGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15, - 29,29,10 - CONTROL ".cgb",IDC_CGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15, - 43,30,10 - CONTROL ".gbc",IDC_GBC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15, - 57,30,10 - CONTROL ".gba",IDC_GBA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75, - 13,30,10 - CONTROL ".agb",IDC_AGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75, - 27,30,10 - CONTROL ".bin",IDC_BIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75, - 41,27,10 + CONTROL ".gb",IDC_GB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,15,26,10 + CONTROL ".sgb",IDC_SGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,29,29,10 + CONTROL ".cgb",IDC_CGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,43,30,10 + CONTROL ".gbc",IDC_GBC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,57,30,10 + CONTROL ".gba",IDC_GBA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,13,30,10 + CONTROL ".agb",IDC_AGB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,27,30,10 + CONTROL ".bin",IDC_BIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,41,27,10 DEFPUSHBUTTON "OK",ID_OK,3,78,50,14 PUSHBUTTON "Cancel",ID_CANCEL,63,78,50,14 GROUPBOX "GBA Types",IDC_STATIC,63,3,50,51 GROUPBOX "GB Types",IDC_STATIC,3,3,50,69 END -IDD_GBA_ROM_INFO DIALOG DISCARDABLE 0, 0, 220, 142 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GBA_ROM_INFO DIALOG 0, 0, 220, 142 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Rom information" FONT 8, "MS Sans Serif" BEGIN @@ -309,19 +260,19 @@ LTEXT "Device type:",IDC_STATIC,7,80,60,8 LTEXT "ROM version:",IDC_STATIC,7,94,60,8 LTEXT "CRC:",IDC_STATIC,7,108,60,8 - LTEXT "",IDC_ROM_TITLE,80,10,133,8 - LTEXT "",IDC_ROM_GAME_CODE,80,24,133,8 - LTEXT "",IDC_ROM_MAKER_CODE,80,38,133,8 - LTEXT "",IDC_ROM_UNIT_CODE,80,66,133,8 - LTEXT "",IDC_ROM_DEVICE_TYPE,80,80,133,8 - LTEXT "",IDC_ROM_VERSION,80,94,133,8 - LTEXT "",IDC_ROM_CRC,80,108,133,8 - LTEXT "",IDC_ROM_MAKER_NAME,80,52,133,8 LTEXT "Maker name:",IDC_STATIC,7,52,60,8 + LTEXT "",IDC_ROM_TITLE,80,10,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_GAME_CODE,80,24,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_MAKER_CODE,80,38,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_UNIT_CODE,80,66,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_DEVICE_TYPE,80,80,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_VERSION,80,94,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_CRC,80,108,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_MAKER_NAME,80,52,133,8,SS_NOPREFIX END -IDD_GB_ROM_INFO DIALOG DISCARDABLE 0, 0, 220, 225 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GB_ROM_INFO DIALOG 0, 0, 220, 225 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Rom information" FONT 8, "MS Sans Serif" BEGIN @@ -332,39 +283,36 @@ LTEXT "Cartridge type:",IDC_STATIC,7,82,60,8 LTEXT "ROM version:",IDC_STATIC,7,152,60,8 LTEXT "CRC:",IDC_STATIC,7,166,60,8 - LTEXT "",IDC_ROM_TITLE,80,10,133,8 - LTEXT "",IDC_ROM_MAKER_CODE,80,38,133,8 - LTEXT "",IDC_ROM_UNIT_CODE,80,68,133,8 - LTEXT "",IDC_ROM_DEVICE_TYPE,80,82,133,8 - LTEXT "",IDC_ROM_VERSION,80,152,133,8 - LTEXT "",IDC_ROM_CRC,80,166,133,8 + LTEXT "",IDC_ROM_TITLE,80,10,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_MAKER_CODE,80,38,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_UNIT_CODE,80,68,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_DEVICE_TYPE,80,82,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_VERSION,80,152,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_CRC,80,166,133,8,SS_NOPREFIX LTEXT "Color:",IDC_STATIC,7,24,60,8 - LTEXT "",IDC_ROM_COLOR,80,24,133,8 + LTEXT "",IDC_ROM_COLOR,80,24,133,8,SS_NOPREFIX LTEXT "ROM size:",IDC_STATIC,7,96,60,8 - LTEXT "",IDC_ROM_SIZE,80,96,133,8 + LTEXT "",IDC_ROM_SIZE,80,96,133,8,SS_NOPREFIX LTEXT "RAM size:",IDC_STATIC,7,110,60,8 - LTEXT "",IDC_ROM_RAM_SIZE,80,110,133,8 + LTEXT "",IDC_ROM_RAM_SIZE,80,110,133,8,SS_NOPREFIX LTEXT "Dest. code:",IDC_STATIC,7,124,60,8 - LTEXT "",IDC_ROM_DEST_CODE,80,124,133,8 + LTEXT "",IDC_ROM_DEST_CODE,80,124,133,8,SS_NOPREFIX LTEXT "License code:",IDC_STATIC,7,138,60,8 - LTEXT "",IDC_ROM_LIC_CODE,80,138,133,8 + LTEXT "",IDC_ROM_LIC_CODE,80,138,133,8,SS_NOPREFIX LTEXT "Checksum:",IDC_STATIC,7,180,60,8 - LTEXT "",IDC_ROM_CHECKSUM,80,180,133,8 - LTEXT "",IDC_ROM_MAKER_NAME2,80,52,133,8 + LTEXT "",IDC_ROM_CHECKSUM,80,180,133,8,SS_NOPREFIX + LTEXT "",IDC_ROM_MAKER_NAME2,80,52,133,8,SS_NOPREFIX LTEXT "Maker name:",IDC_STATIC,7,52,60,8 END -IDD_GB_CHEAT_LIST DIALOG DISCARDABLE 0, 0, 286, 221 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GB_CHEAT_LIST DIALOG 0, 0, 286, 221 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Gameboy Cheat List" FONT 8, "MS Sans Serif" BEGIN - CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | - WS_GROUP | WS_TABSTOP,9,20,269,156 - PUSHBUTTON "Add &GameGenie...",IDC_ADD_GG_CHEAT,9,183,80,14, - WS_GROUP - PUSHBUTTON "&Add GameShark...",IDC_ADD_GS_CHEAT,103,183,80,14, - WS_GROUP + CONTROL "",IDC_CHEAT_LIST,"SysListView32",LVS_REPORT | WS_BORDER | WS_GROUP | WS_TABSTOP,9,20,269,156 + PUSHBUTTON "Add &GameGenie...",IDC_ADD_GG_CHEAT,9,183,80,14,WS_GROUP + PUSHBUTTON "&Add GameShark...",IDC_ADD_GS_CHEAT,103,183,80,14,WS_GROUP PUSHBUTTON "&Remove",IDC_REMOVE,197,183,80,14 PUSHBUTTON "Remove A&ll",IDC_REMOVE_ALL,9,202,80,14 PUSHBUTTON "&Enable/Dis.",IDC_ENABLE,103,202,80,14 @@ -374,40 +322,37 @@ LTEXT "D: Disabled",IDC_STATIC,241,9,38,8 END -IDD_ADD_CHEAT_DLG DIALOG DISCARDABLE 0, 0, 182, 107 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_ADD_CHEAT_DLG DIALOG 0, 0, 182, 107 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Title" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_DESC,60,7,120,14,ES_AUTOHSCROLL - EDITTEXT IDC_CODE,60,23,120,58,ES_MULTILINE | ES_UPPERCASE | - ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN + EDITTEXT IDC_CODE,60,23,120,58,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN DEFPUSHBUTTON "OK",ID_OK,33,86,50,14 PUSHBUTTON "Cancel",ID_CANCEL,99,86,50,14 LTEXT "&Description:",IDC_STATIC,3,10,54,8 LTEXT "&Code:",IDC_STATIC,3,29,54,8 END -IDD_GB_PRINTER DIALOG DISCARDABLE 0, 0, 178, 209 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GB_PRINTER DIALOG 0, 0, 178, 209 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "GB Printer" FONT 8, "MS Sans Serif" BEGIN - CONTROL "&1x",IDC_1X,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13, - 166,22,10 + CONTROL "&1x",IDC_1X,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,166,22,10 CONTROL "&2x",IDC_2X,"Button",BS_AUTORADIOBUTTON,55,166,23,10 CONTROL "&3x",IDC_3X,"Button",BS_AUTORADIOBUTTON,98,166,23,10 CONTROL "&4x",IDC_4X,"Button",BS_AUTORADIOBUTTON,141,166,23,10 DEFPUSHBUTTON "&Print...",ID_PRINT,7,190,50,14,WS_GROUP PUSHBUTTON "&Save...",ID_SAVE,64,190,50,14 PUSHBUTTON "&Close",ID_OK,121,190,50,14 - CONTROL "",IDC_GB_PRINTER,"Static",SS_BLACKFRAME | WS_GROUP,7,6, - 162,146 + CONTROL "",IDC_GB_PRINTER,"Static",SS_BLACKFRAME | WS_GROUP,7,6,162,146 GROUPBOX "Print Size",IDC_STATIC,7,156,162,25 END -IDD_MOTION_CONFIG DIALOG DISCARDABLE 0, 0, 135, 78 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_MOTION_CONFIG DIALOG 0, 0, 135, 78 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Motion Sensor" FONT 8, "MS Sans Serif" BEGIN @@ -423,8 +368,8 @@ LTEXT "Right:",IDC_STATIC,5,44,35,10 END -IDD_LANG_SELECT DIALOG DISCARDABLE 0, 0, 186, 68 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_LANG_SELECT DIALOG 0, 0, 186, 68 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Language selection" FONT 8, "MS Sans Serif" BEGIN @@ -433,82 +378,72 @@ PUSHBUTTON "Cancel",ID_CANCEL,104,49,50,14 LTEXT "Current system language is:",IDC_STATIC,6,9,123,8 LTEXT "Enter language name (3 letter):",IDC_STATIC,6,30,127,8 - LTEXT "",IDC_LANG_NAME,140,9,40,8 + LTEXT "",IDC_LANG_NAME,140,9,40,8,SS_NOPREFIX END -IDD_CODE_SELECT DIALOG DISCARDABLE 0, 0, 316, 235 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_CODE_SELECT DIALOG 0, 0, 316, 235 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Select codes to import" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",ID_OK,91,214,50,14 PUSHBUTTON "Cancel",ID_CANCEL,174,214,50,14 - LISTBOX IDC_GAME_LIST,7,7,302,205,LBS_SORT | - LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | - WS_TABSTOP + LISTBOX IDC_GAME_LIST,7,7,302,205,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP END -IDD_MAP_VIEW DIALOG DISCARDABLE 0, 0, 322, 238 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_MAP_VIEW DIALOG 0, 0, 322, 238 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Map view" FONT 8, "MS Sans Serif" BEGIN - CONTROL "Frame 0",IDC_FRAME_0,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,13,22,41,10 - CONTROL "Frame 1",IDC_FRAME_1,"Button",BS_AUTORADIOBUTTON,13,36, - 41,10 - CONTROL "BG0",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13, - 63,30,10 + CONTROL "Frame 0",IDC_FRAME_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,22,41,10 + CONTROL "Frame 1",IDC_FRAME_1,"Button",BS_AUTORADIOBUTTON,13,36,41,10 + CONTROL "BG0",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,63,30,10 CONTROL "BG1",IDC_BG1,"Button",BS_AUTORADIOBUTTON,13,77,30,10 CONTROL "BG2",IDC_BG2,"Button",BS_AUTORADIOBUTTON,13,91,30,10 CONTROL "BG3",IDC_BG3,"Button",BS_AUTORADIOBUTTON,13,105,30,10 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_GROUP | WS_TABSTOP,7,122,68,10 - CONTROL "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | - WS_GROUP | WS_TABSTOP,7,134,55,10 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,122,68,10 + CONTROL "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,134,55,10 PUSHBUTTON "&Refresh",IDC_REFRESH,25,217,50,14,WS_GROUP PUSHBUTTON "&Save...",IDC_SAVE,88,217,50,14,WS_GROUP PUSHBUTTON "&Close",IDC_CLOSE,155,217,50,14 - CONTROL "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,187,15,128,128 - CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,7,148,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164, - 48,47 - LTEXT "",IDC_R,245,173,50,8 - LTEXT "",IDC_G,245,185,50,8 - LTEXT "",IDC_B,245,197,50,8 + CONTROL "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,187,15,128,128 + CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,148,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164,48,47 + LTEXT "",IDC_R,245,173,50,8,SS_NOPREFIX + LTEXT "",IDC_G,245,185,50,8,SS_NOPREFIX + LTEXT "",IDC_B,245,197,50,8,SS_NOPREFIX GROUPBOX "Frame",IDC_STATIC,7,11,63,37 GROUPBOX "Background",IDC_STATIC,7,52,63,67 - LTEXT "",IDC_XY,129,95,53,8 + LTEXT "",IDC_XY,129,95,53,8,SS_NOPREFIX LTEXT "Mode:",IDC_STATIC,80,15,34,8 - LTEXT "",IDC_MODE,130,15,53,8 + LTEXT "",IDC_MODE,130,15,53,8,SS_NOPREFIX LTEXT "Map Base:",IDC_STATIC,80,25,35,8 - LTEXT "",IDC_MAPBASE,130,25,53,8 + LTEXT "",IDC_MAPBASE,130,25,53,8,SS_NOPREFIX LTEXT "Char Base:",IDC_STATIC,80,35,36,8 - LTEXT "",IDC_CHARBASE,130,35,53,8 + LTEXT "",IDC_CHARBASE,130,35,53,8,SS_NOPREFIX LTEXT "Size:",IDC_STATIC,80,45,37,8 - LTEXT "",IDC_DIM,130,45,53,8 + LTEXT "",IDC_DIM,130,45,53,8,SS_NOPREFIX LTEXT "Colors:",IDC_STATIC,80,55,37,8 - LTEXT "",IDC_NUMCOLORS,130,55,53,8 + LTEXT "",IDC_NUMCOLORS,130,55,53,8,SS_NOPREFIX LTEXT "Priority:",IDC_STATIC,80,65,37,8 - LTEXT "",IDC_PRIORITY,130,65,53,8 + LTEXT "",IDC_PRIORITY,130,65,53,8,SS_NOPREFIX LTEXT "Mosaic:",IDC_STATIC,80,75,37,8 - LTEXT "",IDC_MOSAIC,130,75,53,8 + LTEXT "",IDC_MOSAIC,130,75,53,8,SS_NOPREFIX LTEXT "Overflow:",IDC_STATIC,80,85,37,8 - LTEXT "",IDC_OVERFLOW,130,85,53,8 + LTEXT "",IDC_OVERFLOW,130,85,53,8,SS_NOPREFIX LTEXT "Address:",IDC_STATIC,80,105,37,8 - LTEXT "",IDC_ADDRESS,130,105,53,8 + LTEXT "",IDC_ADDRESS,130,105,53,8,SS_NOPREFIX LTEXT "Tile:",IDC_STATIC,80,115,37,8 - LTEXT "",IDC_TILE_NUM,130,115,53,8 + LTEXT "",IDC_TILE_NUM,130,115,53,8,SS_NOPREFIX LTEXT "Flip:",IDC_STATIC,80,125,37,8 - LTEXT "",IDC_FLIP,130,125,53,8 + LTEXT "",IDC_FLIP,130,125,53,8,SS_NOPREFIX LTEXT "Palette:",IDC_STATIC,80,135,37,8 - LTEXT "",IDC_PALETTE_NUM,130,135,53,8 + LTEXT "",IDC_PALETTE_NUM,130,135,53,8,SS_NOPREFIX END -IDD_PALETTE_VIEW DIALOG DISCARDABLE 0, 0, 316, 266 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_PALETTE_VIEW DIALOG 0, 0, 316, 266 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Palette View" FONT 8, "MS Sans Serif" BEGIN @@ -516,15 +451,13 @@ PUSHBUTTON "Save OBJ...",IDC_SAVE_OBJ,98,245,50,14 PUSHBUTTON "&Refresh",IDC_REFRESH2,166,245,50,14 PUSHBUTTON "&Close",IDC_CLOSE,234,245,50,14 - LTEXT "",IDC_ADDRESS,53,168,50,8 - LTEXT "",IDC_R,53,180,50,8 - LTEXT "",IDC_G,53,192,50,8 - LTEXT "",IDC_B,53,204,50,8 - LTEXT "",IDC_VALUE,53,216,50,8 - CONTROL "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,161,168, - 50,50 - CONTROL "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl", - WS_TABSTOP,12,30,128,128 + LTEXT "",IDC_ADDRESS,53,168,50,8,SS_NOPREFIX + LTEXT "",IDC_R,53,180,50,8,SS_NOPREFIX + LTEXT "",IDC_G,53,192,50,8,SS_NOPREFIX + LTEXT "",IDC_B,53,204,50,8,SS_NOPREFIX + LTEXT "",IDC_VALUE,53,216,50,8,SS_NOPREFIX + CONTROL "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,161,168,50,50 + CONTROL "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl",WS_TABSTOP,12,30,128,128 CONTROL "PaletteViewBG",IDC_PALETTE_VIEW_OBJ, "VbaPaletteViewControl",WS_TABSTOP,166,30,128,128 GROUPBOX "Background",IDC_STATIC,7,20,137,143 @@ -534,73 +467,57 @@ LTEXT "G:",IDC_STATIC,7,192,43,8 LTEXT "B:",IDC_STATIC,7,204,38,8 LTEXT "Value:",IDC_STATIC,7,216,38,8 - LTEXT "Click on a color for more information",IDC_STATIC,7,7, - 302,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,229,71,10 + LTEXT "Click on a color for more information",IDC_STATIC,7,7,302,8 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,229,71,10 END -IDD_MEM_VIEWER DIALOG DISCARDABLE 0, 0, 380, 178 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_MEM_VIEWER DIALOG 0, 0, 380, 178 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Memory viewer" FONT 8, "MS Sans Serif" BEGIN - COMBOBOX IDC_ADDRESSES,7,7,109,30,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - CONTROL "8-bit",IDC_8_BIT,"Button",BS_AUTORADIOBUTTON | WS_GROUP, - 120,9,29,10 - CONTROL "16-bit",IDC_16_BIT,"Button",BS_AUTORADIOBUTTON,154,9,33, - 10 - CONTROL "32-bit",IDC_32_BIT,"Button",BS_AUTORADIOBUTTON,192,9,33, - 10 - EDITTEXT IDC_ADDRESS,238,7,82,14,ES_UPPERCASE | ES_AUTOHSCROLL | - ES_WANTRETURN | WS_GROUP + COMBOBOX IDC_ADDRESSES,7,7,109,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "8-bit",IDC_8_BIT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,120,9,29,10 + CONTROL "16-bit",IDC_16_BIT,"Button",BS_AUTORADIOBUTTON,154,9,33,10 + CONTROL "32-bit",IDC_32_BIT,"Button",BS_AUTORADIOBUTTON,192,9,33,10 + EDITTEXT IDC_ADDRESS,238,7,82,14,ES_UPPERCASE | ES_AUTOHSCROLL | ES_WANTRETURN | WS_GROUP DEFPUSHBUTTON "&Go",IDC_GO,323,7,50,14,WS_GROUP - CONTROL "Viewer",IDC_VIEWER,"VbaMemoryViewer",WS_TABSTOP,7,22, - 366,112 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,139,71,10 + CONTROL "Viewer",IDC_VIEWER,"VbaMemoryViewer",WS_TABSTOP,7,22,366,112 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,139,71,10 PUSHBUTTON "&Refresh",IDC_REFRESH,67,157,50,14 PUSHBUTTON "&Load...",IDC_LOAD,132,157,50,14 PUSHBUTTON "&Save...",IDC_SAVE,197,157,50,14 PUSHBUTTON "&Close",IDC_CLOSE,262,157,50,14 - LTEXT "Current address:",IDC_CURRENT_ADDRESS_LABEL,210,142,77, - 8 - EDITTEXT IDC_CURRENT_ADDRESS,291,139,82,14,ES_RIGHT | - ES_AUTOHSCROLL | WS_DISABLED + LTEXT "Current address:",IDC_CURRENT_ADDRESS_LABEL,210,142,77,8 + EDITTEXT IDC_CURRENT_ADDRESS,291,139,82,14,ES_RIGHT | ES_AUTOHSCROLL | WS_DISABLED END -IDD_OAM_VIEW DIALOG DISCARDABLE 0, 0, 234, 185 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_OAM_VIEW DIALOG 0, 0, 234, 185 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Oam Viewer" FONT 8, "MS Sans Serif" BEGIN - EDITTEXT IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | - ES_NUMBER + EDITTEXT IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER SCROLLBAR IDC_SCROLLBAR,7,33,76,11 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,138,79,10 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,138,79,10 PUSHBUTTON "&Refresh",IDC_REFRESH,7,164,50,14,WS_GROUP PUSHBUTTON "&Save...",IDC_SAVE,91,164,50,14,WS_GROUP PUSHBUTTON "&Close",IDC_CLOSE,177,164,50,14 - CONTROL "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,87,7,64,64 - CONTROL "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,163,7,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48, - 47 - LTEXT "",IDC_POS,31,47,50,8 - LTEXT "",IDC_MODE,31,57,50,8 - LTEXT "",IDC_COLORS,31,67,50,8 - LTEXT "",IDC_PALETTE,31,77,50,8 - LTEXT "",IDC_TILE,31,87,50,8 - LTEXT "",IDC_PRIO,31,97,50,8 - LTEXT "",IDC_SIZE2,31,107,50,8 - LTEXT "",IDC_ROT,31,117,50,8 - LTEXT "",IDC_FLAGS,31,127,50,8 - LTEXT "",IDC_R,145,88,50,8 - LTEXT "",IDC_G,145,100,50,8 - LTEXT "",IDC_B,145,112,50,8 + CONTROL "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,87,7,64,64 + CONTROL "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,163,7,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48,47 + LTEXT "",IDC_POS,31,47,50,8,SS_NOPREFIX + LTEXT "",IDC_MODE,31,57,50,8,SS_NOPREFIX + LTEXT "",IDC_COLORS,31,67,50,8,SS_NOPREFIX + LTEXT "",IDC_PALETTE,31,77,50,8,SS_NOPREFIX + LTEXT "",IDC_TILE,31,87,50,8,SS_NOPREFIX + LTEXT "",IDC_PRIO,31,97,50,8,SS_NOPREFIX + LTEXT "",IDC_SIZE2,31,107,50,8,SS_NOPREFIX + LTEXT "",IDC_ROT,31,117,50,8,SS_NOPREFIX + LTEXT "",IDC_FLAGS,31,127,50,8,SS_NOPREFIX + LTEXT "",IDC_R,145,88,50,8,SS_NOPREFIX + LTEXT "",IDC_G,145,100,50,8,SS_NOPREFIX + LTEXT "",IDC_B,145,112,50,8,SS_NOPREFIX LTEXT "Pos:",IDC_STATIC,7,47,24,8 LTEXT "Mode:",IDC_STATIC,7,57,24,8 LTEXT "Colors:",IDC_STATIC,7,67,24,8 @@ -611,21 +528,18 @@ LTEXT "Sprite:",IDC_STATIC,7,7,50,8 LTEXT "Rot.:",IDC_STATIC,7,117,24,8 LTEXT "Flags:",IDC_STATIC,7,127,24,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10 END -IDD_ACCEL_EDITOR DIALOG DISCARDABLE 0, 0, 280, 121 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_ACCEL_EDITOR DIALOG 0, 0, 280, 121 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Accelerator editor" FONT 8, "MS Sans Serif" BEGIN LTEXT "&Commands:",IDC_STATIC,9,9,38,8 - LISTBOX IDC_COMMANDS,9,18,100,67,LBS_SORT | LBS_NOINTEGRALHEIGHT | - LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_COMMANDS,9,18,100,67,LBS_SORT | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP LTEXT "Current &Keys:",IDC_STATIC1,113,9,43,8 - LISTBOX IDC_CURRENTS,113,18,100,67,LBS_SORT | - LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_CURRENTS,113,18,100,67,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP DEFPUSHBUTTON "OK",ID_OK,223,9,50,14 PUSHBUTTON "Cancel",ID_CANCEL,223,25,50,14 LTEXT "Select &New Shortcut Key:",IDC_STATIC3,113,90,82,8 @@ -633,70 +547,52 @@ PUSHBUTTON "&Assign",IDC_ASSIGN,223,70,50,14 PUSHBUTTON "&Remove",IDC_REMOVE,223,86,50,14 PUSHBUTTON "Re&set All",IDC_RESET,223,102,50,14 - LTEXT "Static",IDC_ALREADY_AFFECTED,9,102,100,12, - SS_CENTERIMAGE + LTEXT "Static",IDC_ALREADY_AFFECTED,9,102,100,12,SS_CENTERIMAGE LTEXT "Currently assigned to :",IDC_STATIC2,9,90,73,10 END -IDD_TILE_VIEWER DIALOG DISCARDABLE 0, 0, 326, 266 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_TILE_VIEWER DIALOG 0, 0, 326, 266 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Tile Viewer" FONT 8, "MS Sans Serif" BEGIN - CONTROL "16",IDC_16_COLORS,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,13,20,24,10 - CONTROL "256",IDC_256_COLORS,"Button",BS_AUTORADIOBUTTON,13,30, - 28,10 - CONTROL "0x6000000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,13,57,51,10 - CONTROL "0x6004000",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON, - 13,67,51,10 - CONTROL "0x6008000",IDC_CHARBASE_2,"Button",BS_AUTORADIOBUTTON, - 13,77,51,10 - CONTROL "0x600C000",IDC_CHARBASE_3,"Button",BS_AUTORADIOBUTTON, - 13,87,52,10 - CONTROL "0x6010000",IDC_CHARBASE_4,"Button",BS_AUTORADIOBUTTON, - 13,97,49,10 - CONTROL "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32", - TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,124,76,22 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,149,79,10 + CONTROL "16",IDC_16_COLORS,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,20,24,10 + CONTROL "256",IDC_256_COLORS,"Button",BS_AUTORADIOBUTTON,13,30,28,10 + CONTROL "0x6000000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,57,51,10 + CONTROL "0x6004000",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON,13,67,51,10 + CONTROL "0x6008000",IDC_CHARBASE_2,"Button",BS_AUTORADIOBUTTON,13,77,51,10 + CONTROL "0x600C000",IDC_CHARBASE_3,"Button",BS_AUTORADIOBUTTON,13,87,52,10 + CONTROL "0x6010000",IDC_CHARBASE_4,"Button",BS_AUTORADIOBUTTON,13,97,49,10 + CONTROL "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,124,76,22 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,149,79,10 PUSHBUTTON "Refresh",IDC_REFRESH,7,245,50,14,WS_GROUP PUSHBUTTON "Save...",IDC_SAVE,138,245,50,14 PUSHBUTTON "Close",IDC_CLOSE,269,245,50,14 - CONTROL "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,191,7,128,128 + CONTROL "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,191,7,128,128 GROUPBOX "Colors",IDC_STATIC,7,7,66,38 GROUPBOX "Char Base",IDC_STATIC,7,46,65,64 - CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,7,174,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,183,48, - 47 - LTEXT "",IDC_R,156,192,50,8 - LTEXT "",IDC_G,156,204,50,8 - LTEXT "",IDC_B,156,216,50,8 + CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,174,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,183,48,47 + LTEXT "",IDC_R,156,192,50,8,SS_NOPREFIX + LTEXT "",IDC_G,156,204,50,8,SS_NOPREFIX + LTEXT "",IDC_B,156,216,50,8,SS_NOPREFIX LTEXT "Palette:",IDC_STATIC,7,113,65,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,160,71,10 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,160,71,10 LTEXT "Tile:",IDC_STATIC,79,14,41,8 LTEXT "Address:",IDC_STATIC,79,26,41,8 - LTEXT "",IDC_TILE_NUMBER,135,14,50,8 - LTEXT "",IDC_ADDRESS,135,26,50,8 + LTEXT "",IDC_TILE_NUMBER,135,14,50,8,SS_NOPREFIX + LTEXT "",IDC_ADDRESS,135,26,50,8,SS_NOPREFIX END -IDD_GB_COLORS DIALOG DISCARDABLE 0, 0, 169, 121 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GB_COLORS DIALOG 0, 0, 169, 121 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Gameboy Mono Colors" FONT 8, "MS Sans Serif" BEGIN - CONTROL "Default",IDC_DEFAULT,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,7,7,39,10 - CONTROL "User 1",IDC_USER1,"Button",BS_AUTORADIOBUTTON,67,7,37, - 10 - CONTROL "User 2",IDC_USER2,"Button",BS_AUTORADIOBUTTON,125,7,37, - 10 - COMBOBOX IDC_PREDEFINED,7,21,155,30,CBS_DROPDOWNLIST | CBS_SORT | - WS_VSCROLL | WS_TABSTOP + CONTROL "Default",IDC_DEFAULT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,7,7,39,10 + CONTROL "User 1",IDC_USER1,"Button",BS_AUTORADIOBUTTON,67,7,37,10 + CONTROL "User 2",IDC_USER2,"Button",BS_AUTORADIOBUTTON,125,7,37,10 + COMBOBOX IDC_PREDEFINED,7,21,155,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "",IDC_COLOR_BG0,15,47,28,14,WS_GROUP PUSHBUTTON "",IDC_COLOR_BG1,52,47,28,14 PUSHBUTTON "",IDC_COLOR_BG2,89,47,28,14 @@ -712,23 +608,18 @@ GROUPBOX "Sprite",IDC_STATIC,8,67,154,30 END -IDD_DISASSEMBLE DIALOG DISCARDABLE 0, 0, 402, 225 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_DISASSEMBLE DIALOG 0, 0, 402, 225 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Disassemble" FONT 8, "MS Sans Serif" BEGIN - CONTROL "Automatic",IDC_AUTOMATIC,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,7,9,47,10 + CONTROL "Automatic",IDC_AUTOMATIC,"Button",BS_AUTORADIOBUTTON | WS_GROUP,7,9,47,10 CONTROL "ARM",IDC_ARM,"Button",BS_AUTORADIOBUTTON,62,9,32,10 - CONTROL "THUMB",IDC_THUMB,"Button",BS_AUTORADIOBUTTON,103,9,42, - 10 - EDITTEXT IDC_ADDRESS,158,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | - WS_GROUP + CONTROL "THUMB",IDC_THUMB,"Button",BS_AUTORADIOBUTTON,103,9,42,10 + EDITTEXT IDC_ADDRESS,158,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_GROUP DEFPUSHBUTTON "Go",IDC_GO,232,7,50,14 - LISTBOX IDC_DISASSEMBLE,7,25,276,161,LBS_SORT | - LBS_NOINTEGRALHEIGHT | WS_TABSTOP - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10 + LISTBOX IDC_DISASSEMBLE,7,25,276,161,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_TABSTOP + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10 PUSHBUTTON "Refresh",IDC_REFRESH,120,204,50,14 PUSHBUTTON "Next",IDC_NEXT,233,204,50,14 PUSHBUTTON "Close",IDC_CLOSE,346,204,50,14 @@ -740,22 +631,22 @@ LTEXT "R5:",IDC_STATIC,309,47,18,8 LTEXT "R6:",IDC_STATIC,309,55,18,8 LTEXT "R7:",IDC_STATIC,309,63,18,8 - LTEXT "",IDC_R0,344,7,52,8 - LTEXT "",IDC_R1,344,15,52,8 - LTEXT "",IDC_R2,344,23,52,8 - LTEXT "",IDC_R3,344,31,52,8 - LTEXT "",IDC_R4,344,39,52,8 - LTEXT "",IDC_R5,344,47,52,8 - LTEXT "",IDC_R6,344,55,52,8 - LTEXT "",IDC_R7,344,63,52,8 - LTEXT "",IDC_R8,344,71,52,8 - LTEXT "",IDC_R9,344,79,52,8 - LTEXT "",IDC_R10,344,87,52,8 - LTEXT "",IDC_R11,344,95,52,8 - LTEXT "",IDC_R12,344,103,52,8 - LTEXT "",IDC_R13,344,111,52,8 - LTEXT "",IDC_R14,344,119,52,8 - LTEXT "",IDC_R15,344,127,52,8 + LTEXT "",IDC_R0,344,7,52,8,SS_NOPREFIX + LTEXT "",IDC_R1,344,15,52,8,SS_NOPREFIX + LTEXT "",IDC_R2,344,23,52,8,SS_NOPREFIX + LTEXT "",IDC_R3,344,31,52,8,SS_NOPREFIX + LTEXT "",IDC_R4,344,39,52,8,SS_NOPREFIX + LTEXT "",IDC_R5,344,47,52,8,SS_NOPREFIX + LTEXT "",IDC_R6,344,55,52,8,SS_NOPREFIX + LTEXT "",IDC_R7,344,63,52,8,SS_NOPREFIX + LTEXT "",IDC_R8,344,71,52,8,SS_NOPREFIX + LTEXT "",IDC_R9,344,79,52,8,SS_NOPREFIX + LTEXT "",IDC_R10,344,87,52,8,SS_NOPREFIX + LTEXT "",IDC_R11,344,95,52,8,SS_NOPREFIX + LTEXT "",IDC_R12,344,103,52,8,SS_NOPREFIX + LTEXT "",IDC_R13,344,111,52,8,SS_NOPREFIX + LTEXT "",IDC_R14,344,119,52,8,SS_NOPREFIX + LTEXT "",IDC_R15,344,127,52,8,SS_NOPREFIX LTEXT "R8:",IDC_STATIC,309,71,18,8 LTEXT "R9:",IDC_STATIC,309,79,18,8 LTEXT "R10:",IDC_STATIC,309,87,18,8 @@ -764,30 +655,23 @@ LTEXT "R13:",IDC_STATIC,309,111,18,8 LTEXT "R14:",IDC_STATIC,309,119,18,8 LTEXT "R15:",IDC_STATIC,309,127,18,8 - LTEXT "",IDC_R16,344,135,52,8 + LTEXT "",IDC_R16,344,135,52,8,SS_NOPREFIX LTEXT "R16:",IDC_STATIC,309,135,20,8 - CONTROL "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,309,146,21,10 - CONTROL "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,309,156,21,10 - CONTROL "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,309,166,21,10 - CONTROL "V",IDC_V,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,309,176,21,10 - CONTROL "F",IDC_F,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,342,156,20,10 - CONTROL "I",IDC_I,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,342,146,18,10 - CONTROL "T",IDC_T,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,342,166,21,10 + CONTROL "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,146,21,10 + CONTROL "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,156,21,10 + CONTROL "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,166,21,10 + CONTROL "V",IDC_V,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,309,176,21,10 + CONTROL "F",IDC_F,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,156,20,10 + CONTROL "I",IDC_I,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,146,18,10 + CONTROL "T",IDC_T,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,342,166,21,10 LTEXT "Mode:",IDC_STATIC,341,176,21,8 - LTEXT "",IDC_MODE,376,176,20,8 + LTEXT "",IDC_MODE,376,176,20,8,SS_NOPREFIX SCROLLBAR IDC_VSCROLL,283,25,10,161,SBS_VERT PUSHBUTTON "Goto R15",IDC_GOPC,7,204,50,14 END -IDD_GDB_PORT DIALOG DISCARDABLE 0, 0, 186, 51 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GDB_PORT DIALOG 0, 0, 186, 51 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "GDB connection" FONT 8, "MS Sans Serif" BEGIN @@ -797,58 +681,46 @@ EDITTEXT IDC_PORT,125,7,54,14,ES_RIGHT | ES_AUTOHSCROLL END -IDD_GDB_WAITING DIALOG DISCARDABLE 0, 0, 186, 44 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_GDB_WAITING DIALOG 0, 0, 186, 44 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Waiting..." FONT 8, "MS Sans Serif" BEGIN PUSHBUTTON "Cancel",ID_CANCEL,67,23,50,14 LTEXT "Waiting for connection on port:",IDC_STATIC,7,7,117,8 - LTEXT "",IDC_PORT,143,7,36,8 + LTEXT "",IDC_PORT,143,7,36,8,SS_NOPREFIX END -IDD_LOGGING DIALOG DISCARDABLE 0, 0, 366, 218 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_LOGGING DIALOG 0, 0, 366, 218 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Logging" FONT 8, "MS Sans Serif" BEGIN - CONTROL "SWI",IDC_VERBOSE_SWI,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,17,87,10 - CONTROL "Unaligned memory",IDC_VERBOSE_UNALIGNED_ACCESS,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,10,30,87,10 - CONTROL "Illegal write",IDC_VERBOSE_ILLEGAL_WRITE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,10,43,87,10 - CONTROL "Illegal read",IDC_VERBOSE_ILLEGAL_READ,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,10,56,87,10 - CONTROL "DMA 0",IDC_VERBOSE_DMA0,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,69,87,10 - CONTROL "DMA 1",IDC_VERBOSE_DMA1,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,82,87,10 - CONTROL "DMA 2",IDC_VERBOSE_DMA2,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,95,87,10 - CONTROL "DMA 3",IDC_VERBOSE_DMA3,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,108,87,10 - CONTROL "Undefined instruction",IDC_VERBOSE_UNDEFINED,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,10,121,87,10 - CONTROL "AGBPrint",IDC_VERBOSE_AGBPRINT,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,134,87,10 - EDITTEXT IDC_LOG,107,7,252,183,ES_MULTILINE | ES_AUTOVSCROLL | - ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL + CONTROL "SWI",IDC_VERBOSE_SWI,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,17,87,10 + CONTROL "Unaligned memory",IDC_VERBOSE_UNALIGNED_ACCESS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,30,87,10 + CONTROL "Illegal write",IDC_VERBOSE_ILLEGAL_WRITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,43,87,10 + CONTROL "Illegal read",IDC_VERBOSE_ILLEGAL_READ,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,56,87,10 + CONTROL "DMA 0",IDC_VERBOSE_DMA0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,69,87,10 + CONTROL "DMA 1",IDC_VERBOSE_DMA1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,82,87,10 + CONTROL "DMA 2",IDC_VERBOSE_DMA2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,95,87,10 + CONTROL "DMA 3",IDC_VERBOSE_DMA3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,108,87,10 + CONTROL "Undefined instruction",IDC_VERBOSE_UNDEFINED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,121,87,10 + CONTROL "AGBPrint",IDC_VERBOSE_AGBPRINT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,134,87,10 + EDITTEXT IDC_LOG,107,7,252,183,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL PUSHBUTTON "Save...",IDC_SAVE,75,197,50,14 PUSHBUTTON "Clear",IDC_CLEAR,137,197,50,14 DEFPUSHBUTTON "OK",ID_OK,197,197,50,14 GROUPBOX "Verbose",IDC_STATIC,7,7,93,142 END -IDD_EXPORT_SPS DIALOG DISCARDABLE 0, 0, 248, 148 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_EXPORT_SPS DIALOG 0, 0, 248, 148 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Export Gameshark Snapshot" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_TITLE,84,7,157,14,ES_AUTOHSCROLL EDITTEXT IDC_DESC,84,27,157,14,ES_AUTOHSCROLL - EDITTEXT IDC_NOTES,84,47,157,73,ES_MULTILINE | ES_AUTOHSCROLL | - ES_WANTRETURN + EDITTEXT IDC_NOTES,84,47,157,73,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN DEFPUSHBUTTON "OK",ID_OK,67,127,50,14 PUSHBUTTON "Cancel",ID_CANCEL,130,127,50,14 LTEXT "Title:",IDC_STATIC,7,8,62,8 @@ -856,8 +728,8 @@ LTEXT "Notes:",IDC_STATIC,7,48,60,8 END -IDD_ADDR_SIZE DIALOG DISCARDABLE 0, 0, 186, 67 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_ADDR_SIZE DIALOG 0, 0, 186, 67 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Enter address and size" FONT 8, "MS Sans Serif" BEGIN @@ -869,54 +741,48 @@ LTEXT "Size:",IDC_STATIC,7,29,65,8 END -IDD_MODES DIALOG DISCARDABLE 0, 0, 208, 129 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_MODES DIALOG 0, 0, 208, 129 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Select video mode" FONT 8, "MS Sans Serif" BEGIN - LISTBOX IDC_MODES,7,18,194,80,LBS_SORT | LBS_NOINTEGRALHEIGHT | - WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_MODES,7,18,194,80,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP DEFPUSHBUTTON "OK",ID_OK,45,108,50,14 PUSHBUTTON "Cancel",ID_CANCEL,112,108,50,14 LTEXT "Available video modes:",IDC_STATIC,7,7,194,8 END -IDD_DRIVERS DIALOG DISCARDABLE 0, 0, 208, 121 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_DRIVERS DIALOG 0, 0, 208, 121 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Select video driver" FONT 8, "MS Sans Serif" BEGIN - LISTBOX IDC_DRIVERS,7,17,194,80,LBS_NOINTEGRALHEIGHT | - WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_DRIVERS,7,17,194,80,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP DEFPUSHBUTTON "OK",ID_OK,45,104,50,14 PUSHBUTTON "Cancel",ID_CANCEL,112,104,50,14 LTEXT "Available drivers:",IDC_STATIC,7,7,194,8 END -IDD_THROTTLE DIALOG DISCARDABLE 0, 0, 186, 63 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_THROTTLE DIALOG 0, 0, 186, 63 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Throttle" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_THROTTLE,7,20,172,14,ES_AUTOHSCROLL DEFPUSHBUTTON "OK",ID_OK,37,42,50,14 PUSHBUTTON "Cancel",ID_CANCEL,99,42,50,14 - LTEXT "Enter desired throttle (5%...1000%):",IDC_STATIC,7,7, - 172,8 + LTEXT "Enter desired throttle (5%...1000%):",IDC_STATIC,7,7,172,8 END -IDD_GB_DISASSEMBLE DIALOG DISCARDABLE 0, 0, 344, 225 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_GB_DISASSEMBLE DIALOG 0, 0, 344, 225 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "GB Disassemble" FONT 8, "MS Sans Serif" BEGIN - EDITTEXT IDC_ADDRESS,7,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | - WS_GROUP + EDITTEXT IDC_ADDRESS,7,7,65,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_GROUP DEFPUSHBUTTON "Go",IDC_GO,81,7,50,14 - LISTBOX IDC_DISASSEMBLE,7,25,222,161,LBS_SORT | - LBS_NOINTEGRALHEIGHT | WS_TABSTOP - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10 + LISTBOX IDC_DISASSEMBLE,7,25,222,161,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_TABSTOP + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,191,71,10 PUSHBUTTON "Refresh",IDC_REFRESH,100,204,50,14 PUSHBUTTON "Next",IDC_NEXT,193,204,50,14 PUSHBUTTON "Close",IDC_CLOSE,287,204,50,14 @@ -925,55 +791,48 @@ LTEXT "DE:",IDC_STATIC,250,45,18,8 LTEXT "HL:",IDC_STATIC,250,55,18,8 LTEXT "IFF:",IDC_STATIC,250,85,18,8 - LTEXT "",IDC_R0,285,25,52,8 - LTEXT "",IDC_R1,285,35,52,8 - LTEXT "",IDC_R2,285,45,52,8 - LTEXT "",IDC_R3,285,55,52,8 - LTEXT "",IDC_R6,285,85,52,8 - CONTROL "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,250,109,21,10 - CONTROL "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,250,97,21,10 - CONTROL "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,250,133,21,10 - CONTROL "H",IDC_H,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,250,121,21,10 + LTEXT "LY:",IDC_STATIC,272,95,18,8 + LTEXT "",IDC_R0,285,25,52,8,SS_NOPREFIX + LTEXT "",IDC_R1,285,35,52,8,SS_NOPREFIX + LTEXT "",IDC_R2,285,45,52,8,SS_NOPREFIX + LTEXT "",IDC_R3,285,55,52,8,SS_NOPREFIX + LTEXT "",IDC_R6,285,85,52,8,SS_NOPREFIX + LTEXT "",IDC_LY,285,95,52,8,SS_NOPREFIX + CONTROL "N",IDC_N,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,109,21,10 + CONTROL "Z",IDC_Z,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,97,21,10 + CONTROL "C",IDC_C,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,133,21,10 + CONTROL "H",IDC_H,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,250,121,21,10 SCROLLBAR IDC_VSCROLL,229,25,10,161,SBS_VERT PUSHBUTTON "Goto PC",IDC_GOPC,7,204,50,14 LTEXT "SP:",IDC_STATIC,250,65,18,8 - LTEXT "",IDC_R4,285,65,52,8 + LTEXT "",IDC_R4,285,65,52,8,SS_NOPREFIX LTEXT "PC:",IDC_STATIC,250,75,18,8 - LTEXT "",IDC_R5,285,75,52,8 + LTEXT "",IDC_R5,285,75,52,8,SS_NOPREFIX END -IDD_GB_OAM_VIEW DIALOG DISCARDABLE 0, 0, 234, 185 -STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +IDD_GB_OAM_VIEW DIALOG 0, 0, 234, 185 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "GB Oam Viewer" FONT 8, "MS Sans Serif" BEGIN - EDITTEXT IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | - ES_NUMBER + EDITTEXT IDC_SPRITE,7,19,76,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER SCROLLBAR IDC_SCROLLBAR,7,33,76,11 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,138,79,10 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,138,79,10 PUSHBUTTON "&Refresh",IDC_REFRESH,7,164,50,14,WS_GROUP PUSHBUTTON "&Save...",IDC_SAVE,91,164,50,14,WS_GROUP PUSHBUTTON "&Close",IDC_CLOSE,177,164,50,14 - CONTROL "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,87,7,64,64 - CONTROL "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,163,7,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48, - 47 - LTEXT "",IDC_POS,31,47,50,8 - LTEXT "",IDC_PALETTE,31,87,50,8 - LTEXT "",IDC_TILE,31,57,50,8 - LTEXT "",IDC_PRIO,31,67,50,8 - LTEXT "",IDC_OAP,31,77,50,8 - LTEXT "",IDC_FLAGS,31,97,50,8 - LTEXT "",IDC_R,145,88,50,8 - LTEXT "",IDC_G,145,100,50,8 - LTEXT "",IDC_B,145,112,50,8 + CONTROL "MapView",IDC_OAM_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,87,7,64,64 + CONTROL "Zoom",IDC_OAM_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,163,7,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,87,79,48,47 + LTEXT "",IDC_POS,31,47,50,8,SS_NOPREFIX + LTEXT "",IDC_PALETTE,31,87,50,8,SS_NOPREFIX + LTEXT "",IDC_TILE,31,57,50,8,SS_NOPREFIX + LTEXT "",IDC_PRIO,31,67,50,8,SS_NOPREFIX + LTEXT "",IDC_OAP,31,77,50,8,SS_NOPREFIX + LTEXT "",IDC_FLAGS,31,97,50,8,SS_NOPREFIX + LTEXT "",IDC_R,145,88,50,8,SS_NOPREFIX + LTEXT "",IDC_G,145,100,50,8,SS_NOPREFIX + LTEXT "",IDC_B,145,112,50,8,SS_NOPREFIX LTEXT "Pos:",IDC_STATIC,7,47,24,8 LTEXT "Pal:",IDC_STATIC,7,87,24,8 LTEXT "Tile:",IDC_STATIC,7,57,24,8 @@ -981,96 +840,78 @@ LTEXT "OAP:",IDC_STATIC,7,77,24,8 LTEXT "Sprite:",IDC_STATIC,7,7,50,8 LTEXT "Flags:",IDC_STATIC,7,97,24,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10 - LTEXT "",IDC_BANK,31,107,50,8 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,150,71,10 + LTEXT "",IDC_BANK,31,107,50,8,SS_NOPREFIX LTEXT "Bank:",IDC_STATIC,7,107,24,8 END -IDD_GB_TILE_VIEWER DIALOG DISCARDABLE 0, 0, 326, 238 -STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +IDD_GB_TILE_VIEWER DIALOG 0, 0, 326, 238 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "GB Tile Viewer" FONT 8, "MS Sans Serif" BEGIN - CONTROL "0",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13, - 20,20,10 + CONTROL "0",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,20,20,10 CONTROL "1",IDC_BANK_1,"Button",BS_AUTORADIOBUTTON,13,30,20,10 - CONTROL "0x8000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,13,57,39,10 - CONTROL "0x8800",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON,13, - 67,39,10 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,122,79,10 + CONTROL "0x8000",IDC_CHARBASE_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,57,39,10 + CONTROL "0x8800",IDC_CHARBASE_1,"Button",BS_AUTORADIOBUTTON,13,67,39,10 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,122,79,10 PUSHBUTTON "Refresh",IDC_REFRESH,7,217,50,14,WS_GROUP PUSHBUTTON "Save...",IDC_SAVE,138,217,50,14 PUSHBUTTON "Close",IDC_CLOSE,269,217,50,14 - CONTROL "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,191,7,128,128 + CONTROL "Custom1",IDC_TILE_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,191,7,128,128 GROUPBOX "VRAM Bank",IDC_STATIC,7,7,66,38 GROUPBOX "Char Base",IDC_STATIC,7,46,65,35 - CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,7,147,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,156,48, - 47 - LTEXT "",IDC_R,156,164,50,8 - LTEXT "",IDC_G,156,176,50,8 - LTEXT "",IDC_B,156,188,50,8 + CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,147,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,98,156,48,47 + LTEXT "",IDC_R,156,164,50,8,SS_NOPREFIX + LTEXT "",IDC_G,156,176,50,8,SS_NOPREFIX + LTEXT "",IDC_B,156,188,50,8,SS_NOPREFIX LTEXT "Palette:",IDC_STATIC,7,86,65,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,133,71,10 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,133,71,10 LTEXT "Tile:",IDC_STATIC,79,14,41,8 LTEXT "Address:",IDC_STATIC,79,26,41,8 - LTEXT "",IDC_TILE_NUMBER,135,14,50,8 - LTEXT "",IDC_ADDRESS,135,26,50,8 - CONTROL "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32", - TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,98,76,22 + LTEXT "",IDC_TILE_NUMBER,135,14,50,8,SS_NOPREFIX + LTEXT "",IDC_ADDRESS,135,26,50,8,SS_NOPREFIX + CONTROL "Slider1",IDC_PALETTE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_GROUP | WS_TABSTOP,1,98,76,22 END -IDD_GB_MAP_VIEW DIALOG DISCARDABLE 0, 0, 322, 238 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +IDD_GB_MAP_VIEW DIALOG 0, 0, 322, 238 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "GB Map Viewer" FONT 8, "MS Sans Serif" BEGIN - CONTROL "0x8000",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | - WS_GROUP,13,22,39,10 - CONTROL "0x8800",IDC_BANK_1,"Button",BS_AUTORADIOBUTTON,13,36,39, - 10 - CONTROL "0x9800",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP, - 13,63,39,10 + CONTROL "0x8000",IDC_BANK_0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,22,39,10 + CONTROL "0x8800",IDC_BANK_1,"Button",BS_AUTORADIOBUTTON,13,36,39,10 + CONTROL "0x9800",IDC_BG0,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,63,39,10 CONTROL "0x9C00",IDC_BG1,"Button",BS_AUTORADIOBUTTON,13,77,40,10 - CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,122,68,10 + CONTROL "Stretch to fit",IDC_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,122,68,10 PUSHBUTTON "&Refresh",IDC_REFRESH,25,217,50,14,WS_GROUP PUSHBUTTON "&Save...",IDC_SAVE,88,217,50,14,WS_GROUP PUSHBUTTON "&Close",IDC_CLOSE,155,217,50,14 - CONTROL "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | - WS_TABSTOP,187,15,128,128 - CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | - WS_TABSTOP,7,148,64,64 - CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164, - 48,47 - LTEXT "",IDC_R,245,173,50,8 - LTEXT "",IDC_G,245,185,50,8 - LTEXT "",IDC_B,245,197,50,8 + CONTROL "MapView",IDC_MAP_VIEW,"VbaBitmapControl",WS_GROUP | WS_TABSTOP,187,15,128,128 + CONTROL "Zoom",IDC_MAP_VIEW_ZOOM,"VbaZoomControl",WS_GROUP | WS_TABSTOP,7,148,64,64 + CONTROL "Color",IDC_COLOR,"VbaColorControl",WS_TABSTOP,187,164,48,47 + LTEXT "",IDC_R,245,173,50,8,SS_NOPREFIX + LTEXT "",IDC_G,245,185,50,8,SS_NOPREFIX + LTEXT "",IDC_B,245,197,50,8,SS_NOPREFIX GROUPBOX "Char Base",IDC_STATIC,7,11,63,37 GROUPBOX "Map Base",IDC_STATIC,7,52,63,41 - CONTROL "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,7,134,55,10 - LTEXT "",IDC_XY,129,18,53,8 + CONTROL "Auto update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134,55,10 + LTEXT "",IDC_XY,129,18,53,8,SS_NOPREFIX LTEXT "Priority:",IDC_STATIC,80,68,37,8 - LTEXT "",IDC_PRIORITY,130,68,53,8 + LTEXT "",IDC_PRIORITY,130,68,53,8,SS_NOPREFIX LTEXT "Address:",IDC_STATIC,80,28,37,8 - LTEXT "",IDC_ADDRESS,130,28,53,8 + LTEXT "",IDC_ADDRESS,130,28,53,8,SS_NOPREFIX LTEXT "Tile:",IDC_STATIC,80,38,37,8 - LTEXT "",IDC_TILE_NUM,130,38,53,8 + LTEXT "",IDC_TILE_NUM,130,38,53,8,SS_NOPREFIX LTEXT "Flip:",IDC_STATIC,80,48,37,8 - LTEXT "",IDC_FLIP,130,48,53,8 + LTEXT "",IDC_FLIP,130,48,53,8,SS_NOPREFIX LTEXT "Palette:",IDC_STATIC,80,58,37,8 - LTEXT "",IDC_PALETTE_NUM,130,58,53,8 + LTEXT "",IDC_PALETTE_NUM,130,58,53,8,SS_NOPREFIX END -IDD_GB_PALETTE_VIEW DIALOG DISCARDABLE 0, 0, 196, 234 -STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +IDD_GB_PALETTE_VIEW DIALOG 0, 0, 196, 234 +STYLE DS_SETFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "GB Palette Viewer" FONT 8, "MS Sans Serif" BEGIN @@ -1078,15 +919,13 @@ PUSHBUTTON "Save OBJ...",IDC_SAVE_OBJ,73,191,50,14 PUSHBUTTON "&Refresh",IDC_REFRESH2,139,191,50,14 PUSHBUTTON "&Close",IDC_CLOSE,73,213,50,14 - LTEXT "",IDC_ADDRESS,53,117,50,8 - LTEXT "",IDC_R,53,129,50,8 - LTEXT "",IDC_G,53,141,50,8 - LTEXT "",IDC_B,53,153,50,8 - LTEXT "",IDC_VALUE,53,165,50,8 - CONTROL "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,119,117, - 50,50 - CONTROL "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl", - WS_TABSTOP,11,30,64,64 + LTEXT "",IDC_ADDRESS,53,117,50,8,SS_NOPREFIX + LTEXT "",IDC_R,53,129,50,8,SS_NOPREFIX + LTEXT "",IDC_G,53,141,50,8,SS_NOPREFIX + LTEXT "",IDC_B,53,153,50,8,SS_NOPREFIX + LTEXT "",IDC_VALUE,53,165,50,8,SS_NOPREFIX + CONTROL "Custom1",IDC_COLOR,"VbaColorControl",WS_TABSTOP,119,117,50,50 + CONTROL "PaletteViewBG",IDC_PALETTE_VIEW,"VbaPaletteViewControl",WS_TABSTOP,11,30,64,64 CONTROL "PaletteViewBG",IDC_PALETTE_VIEW_OBJ, "VbaPaletteViewControl",WS_TABSTOP,120,30,64,64 GROUPBOX "BG",IDC_STATIC,6,20,74,81 @@ -1096,111 +935,108 @@ LTEXT "G:",IDC_STATIC,7,141,43,8 LTEXT "B:",IDC_STATIC,7,153,38,8 LTEXT "Value:",IDC_STATIC,7,165,38,8 - LTEXT "Click on a color for more information",IDC_STATIC,7,7, - 182,8 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,178,71,10 + LTEXT "Click on a color for more information",IDC_STATIC,7,7,182,8 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,178,71,10 END -IDD_MODE_CONFIRM DIALOG DISCARDABLE 0, 0, 186, 57 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_MODE_CONFIRM DIALOG 0, 0, 186, 57 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Confirm mode" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",ID_OK,31,36,50,14 PUSHBUTTON "Cancel",ID_CANCEL,103,36,50,14 - CTEXT "Do you want to keep the current mode?",IDC_STATIC,7,7, - 172,8 - CTEXT "",IDC_TIMER,7,19,172,8 + CTEXT "Do you want to keep the current mode?",IDC_STATIC,7,7,172,8 + CTEXT "",IDC_TIMER,7,19,172,8,SS_NOPREFIX,WS_EX_TOOLWINDOW END -IDD_REWIND_INTERVAL DIALOG DISCARDABLE 0, 0, 186, 68 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_REWIND_INTERVAL DIALOG 0, 0, 186, 68 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Select rewind interval" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_INTERVAL,7,28,172,14,ES_AUTOHSCROLL DEFPUSHBUTTON "OK",ID_OK,37,47,50,14 PUSHBUTTON "Cancel",ID_CANCEL,99,47,50,14 - LTEXT "Enter rewind interval (0...600) seconds:",IDC_STATIC,7, - 7,172,8 + LTEXT "Enter rewind interval (0...600) seconds:",IDC_STATIC,7,7,172,8 LTEXT "Enter 0 to disable rewind.",IDC_STATIC,7,17,172,8 END -IDD_IO_VIEWER DIALOG DISCARDABLE 0, 0, 269, 238 -STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +IDD_IO_VIEWER DIALOG 0, 0, 269, 238 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "I/O Viewer" FONT 8, "MS Sans Serif" BEGIN - COMBOBOX IDC_ADDRESSES,7,7,255,30,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP + COMBOBOX IDC_ADDRESSES,7,7,255,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP RTEXT "",IDC_VALUE,103,23,159,8 - CONTROL "",IDC_BIT_15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,34, - 255,10 - CONTROL "",IDC_BIT_14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,44, - 255,10 - CONTROL "",IDC_BIT_13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,54, - 255,8 - CONTROL "",IDC_BIT_12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,64, - 255,10 - CONTROL "",IDC_BIT_11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,74, - 255,10 - CONTROL "",IDC_BIT_10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,84, - 255,10 - CONTROL "",IDC_BIT_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,94, - 255,10 - CONTROL "",IDC_BIT_8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,104, - 255,10 - CONTROL "",IDC_BIT_7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,114, - 255,10 - CONTROL "",IDC_BIT_6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124, - 255,10 - CONTROL "",IDC_BIT_5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134, - 255,10 - CONTROL "",IDC_BIT_4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,144, - 255,10 - CONTROL "",IDC_BIT_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,154, - 255,10 - CONTROL "",IDC_BIT_2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,164, - 255,10 - CONTROL "",IDC_BIT_1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,174, - 255,10 - CONTROL "",IDC_BIT_0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,184, - 255,10 - CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,201,71,10 + CONTROL "",IDC_BIT_15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,34,255,10 + CONTROL "",IDC_BIT_14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,44,255,10 + CONTROL "",IDC_BIT_13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,54,255,8 + CONTROL "",IDC_BIT_12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,64,255,10 + CONTROL "",IDC_BIT_11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,74,255,10 + CONTROL "",IDC_BIT_10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,84,255,10 + CONTROL "",IDC_BIT_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,94,255,10 + CONTROL "",IDC_BIT_8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,104,255,10 + CONTROL "",IDC_BIT_7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,114,255,10 + CONTROL "",IDC_BIT_6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124,255,10 + CONTROL "",IDC_BIT_5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134,255,10 + CONTROL "",IDC_BIT_4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,144,255,10 + CONTROL "",IDC_BIT_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,154,255,10 + CONTROL "",IDC_BIT_2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,164,255,10 + CONTROL "",IDC_BIT_1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,174,255,10 + CONTROL "",IDC_BIT_0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,184,255,10 + CONTROL "Automatic update",IDC_AUTO_UPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,201,71,10 DEFPUSHBUTTON "&Refresh",IDC_REFRESH,54,221,50,14 DEFPUSHBUTTON "&Apply",IDC_APPLY,110,221,50,14 PUSHBUTTON "&Close",IDC_CLOSE,166,221,50,14 LTEXT "Value:",IDC_STATIC,7,23,72,8 END -IDD_MAX_SCALE DIALOG DISCARDABLE 0, 0, 186, 68 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_MAX_SCALE DIALOG 0, 0, 186, 68 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Fullscreen scale" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_VALUE,7,28,172,14,ES_AUTOHSCROLL DEFPUSHBUTTON "OK",ID_OK,37,47,50,14 PUSHBUTTON "Cancel",ID_CANCEL,99,47,50,14 - LTEXT "Enter the maxium fullscreen scale:",IDC_STATIC,7,7,172, - 8 + LTEXT "Enter the maxium fullscreen scale:",IDC_STATIC,7,7,172,8 LTEXT "Enter 0 to use maximum scale.",IDC_STATIC,7,17,172,8 END -IDD_BUG_REPORT DIALOG DISCARDABLE 0, 0, 296, 186 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +IDD_BUG_REPORT DIALOG 0, 0, 296, 186 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Bug Report" FONT 8, "MS Sans Serif" BEGIN PUSHBUTTON "&OK",ID_OK,157,165,50,14 - EDITTEXT IDC_BUG_REPORT,11,22,278,131,ES_MULTILINE | - ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | - WS_VSCROLL + EDITTEXT IDC_BUG_REPORT,11,22,278,131,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL LTEXT "Bug report data:",IDC_STATIC,7,7,282,8 DEFPUSHBUTTON "&Copy",IDC_COPY,87,164,50,14 END +IDD_GAME_OVERRIDES DIALOGEX 0, 0, 268, 132 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Game overrides" +FONT 8, "MS Sans Serif", 0, 0, 0x0 +BEGIN + COMBOBOX IDC_RTC,84,42,180,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SAVE_TYPE,84,60,180,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_FLASH_SIZE,84,78,180,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_MIRRORING,84,96,180,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + DEFPUSHBUTTON "OK",IDOK,6,114,72,12 + PUSHBUTTON "Defaults",IDC_DEFAULTS,108,114,54,12 + PUSHBUTTON "Cancel",IDCANCEL,192,114,72,12 + LTEXT "Game Code",IDC_STATIC,6,6,72,12 + EDITTEXT IDC_NAME,84,6,180,12,ES_AUTOHSCROLL | WS_DISABLED + LTEXT "Real Time Clock:",IDC_STATIC,6,42,72,12 + LTEXT "Save Type:",IDC_STATIC,6,60,72,12 + LTEXT "Flash Size:",IDC_STATIC,6,78,72,12 + LTEXT "Mirroring:",IDC_STATIC,6,96,72,12 + LTEXT "Comment",IDC_STATIC,6,24,72,12 + EDITTEXT IDC_COMMENT,84,24,180,12,ES_AUTOHSCROLL +END + ///////////////////////////////////////////////////////////////////////////// // @@ -1208,7 +1044,7 @@ // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE +GUIDELINES DESIGNINFO BEGIN IDD_OPENDLG, DIALOG BEGIN @@ -1218,17 +1054,17 @@ IDD_ABOUT, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 157 + RIGHTMARGIN, 150 TOPMARGIN, 7 - BOTTOMMARGIN, 86 + BOTTOMMARGIN, 71 END IDD_DIRECTORIES, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 277 + RIGHTMARGIN, 213 TOPMARGIN, 7 - BOTTOMMARGIN, 122 + BOTTOMMARGIN, 294 END IDD_CONFIG, DIALOG @@ -1542,6 +1378,14 @@ TOPMARGIN, 7 BOTTOMMARGIN, 179 END + + IDD_GAME_OVERRIDES, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 261 + TOPMARGIN, 7 + BOTTOMMARGIN, 105 + END END #endif // APSTUDIO_INVOKED @@ -1551,21 +1395,19 @@ // Menu // -IDR_MENU MENU DISCARDABLE +IDR_MENU MENU BEGIN POPUP "&File" BEGIN - MENUITEM "&Open...", ID_FILE_OPEN + MENUITEM "Open...", ID_FILE_OPEN MENUITEM "Open Gameboy...", ID_FILE_OPENGAMEBOY MENUITEM SEPARATOR - MENUITEM "&Load...", ID_FILE_LOAD - MENUITEM "&Save...", ID_FILE_SAVE - POPUP "Loa&d Game" + MENUITEM "Load...", ID_FILE_LOAD + MENUITEM "Save...", ID_FILE_SAVE + POPUP "Load Game" BEGIN MENUITEM "Most recent", ID_FILE_LOADGAME_MOSTRECENT - MENUITEM "Auto load most recent", ID_FILE_LOADGAME_AUTOLOADMOSTRECENT - MENUITEM SEPARATOR MENUITEM "Slot #1", ID_FILE_LOADGAME_SLOT1 MENUITEM "Slot #2", ID_FILE_LOADGAME_SLOT2 @@ -1578,10 +1420,9 @@ MENUITEM "Slot #9", ID_FILE_LOADGAME_SLOT9 MENUITEM "Slot #10", ID_FILE_LOADGAME_SLOT10 END - POPUP "S&ave Game" + POPUP "Save Game" BEGIN MENUITEM "Oldest slot", ID_FILE_SAVEGAME_OLDESTSLOT - MENUITEM SEPARATOR MENUITEM "Slot #1", ID_FILE_SAVEGAME_SLOT1 MENUITEM "Slot #2", ID_FILE_SAVEGAME_SLOT2 @@ -1595,40 +1436,35 @@ MENUITEM "Slot #10", ID_FILE_SAVEGAME_SLOT10 END MENUITEM SEPARATOR - MENUITEM "&Pause", ID_FILE_PAUSE - MENUITEM "&Reset", ID_FILE_RESET + MENUITEM "Pause", ID_FILE_PAUSE + MENUITEM "Reset", ID_FILE_RESET MENUITEM SEPARATOR - POPUP "Re¢" + POPUP "Recent" BEGIN MENUITEM "&Reset", ID_FILE_RECENT_RESET MENUITEM "&Freeze", ID_FILE_RECENT_FREEZE MENUITEM SEPARATOR END MENUITEM SEPARATOR - POPUP "&Import" + POPUP "Import" BEGIN MENUITEM "&Battery file...", ID_FILE_IMPORT_BATTERYFILE - MENUITEM "Gameshark &code file...", ID_FILE_IMPORT_GAMESHARKCODEFILE - MENUITEM "&Gameshark Snapshot...", ID_FILE_IMPORT_GAMESHARKSNAPSHOT - END - POPUP "E&xport" + POPUP "Export" BEGIN MENUITEM "&Battery file...", ID_FILE_EXPORT_BATTERYFILE - MENUITEM "&Gameshark Snapshot...", ID_FILE_EXPORT_GAMESHARKSNAPSHOT - END MENUITEM SEPARATOR - MENUITEM "S&creen capture...", ID_FILE_SCREENCAPTURE - MENUITEM "Ro&m information...", ID_FILE_ROMINFORMATION - MENUITEM "&Toggle menu", ID_FILE_TOGGLEMENU + MENUITEM "Screen capture...", ID_FILE_SCREENCAPTURE + MENUITEM "Rom information...", ID_FILE_ROMINFORMATION + MENUITEM "Toggle menu", ID_FILE_TOGGLEMENU MENUITEM SEPARATOR - MENUITEM "&Close", ID_FILE_CLOSE + MENUITEM "Close", ID_FILE_CLOSE MENUITEM SEPARATOR - MENUITEM "&Exit", ID_FILE_EXIT + MENUITEM "Exit", ID_FILE_EXIT END POPUP "&Options" BEGIN @@ -1637,43 +1473,25 @@ POPUP "Throttle" BEGIN MENUITEM "No throttle", ID_OPTIONS_FRAMESKIP_THROTTLE_NOTHROTTLE - MENUITEM "25%", ID_OPTIONS_FRAMESKIP_THROTTLE_25 - MENUITEM "50%", ID_OPTIONS_FRAMESKIP_THROTTLE_50 - MENUITEM "100%", ID_OPTIONS_FRAMESKIP_THROTTLE_100 - MENUITEM "150%", ID_OPTIONS_FRAMESKIP_THROTTLE_150 - MENUITEM "200%", ID_OPTIONS_FRAMESKIP_THROTTLE_200 - MENUITEM "Other...", ID_OPTIONS_FRAMESKIP_THROTTLE_OTHER - END MENUITEM "&Automatic", ID_OPTIONS_FRAMESKIP_AUTOMATIC - MENUITEM SEPARATOR MENUITEM "&0", ID_OPTIONS_VIDEO_FRAMESKIP_0 - MENUITEM "&1", ID_OPTIONS_VIDEO_FRAMESKIP_1 - MENUITEM "&2", ID_OPTIONS_VIDEO_FRAMESKIP_2 - MENUITEM "&3", ID_OPTIONS_VIDEO_FRAMESKIP_3 - MENUITEM "&4", ID_OPTIONS_VIDEO_FRAMESKIP_4 - MENUITEM "&5", ID_OPTIONS_VIDEO_FRAMESKIP_5 - MENUITEM "&6", ID_OPTIONS_VIDEO_FRAMESKIP_6 - MENUITEM "&7", ID_OPTIONS_VIDEO_FRAMESKIP_7 - MENUITEM "&8", ID_OPTIONS_VIDEO_FRAMESKIP_8 - MENUITEM "&9", ID_OPTIONS_VIDEO_FRAMESKIP_9 - END POPUP "&Video" BEGIN @@ -1681,39 +1499,24 @@ POPUP "Render Method" BEGIN MENUITEM "GDI", ID_OPTIONS_VIDEO_RENDERMETHOD_GDI - MENUITEM "DirectDraw", ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECTDRAW - MENUITEM "Direct3D", ID_OPTIONS_VIDEO_RENDERMETHOD_DIRECT3D - MENUITEM "OpenGL", ID_OPTIONS_VIDEO_RENDERMETHOD_OPENGL - MENUITEM SEPARATOR MENUITEM "DDraw &Emulation Only", ID_OPTIONS_VIDEO_DDRAWEMULATIONONLY - MENUITEM "DDraw Use &Video Memory", ID_OPTIONS_VIDEO_DDRAWUSEVIDEOMEMORY - MENUITEM "DDraw Triple Buffering", ID_OPTIONS_VIDEO_TRIPLEBUFFERING - MENUITEM SEPARATOR MENUITEM "D3D Nearest", ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DNOFILTER - MENUITEM "D3D Bilinear", ID_OPTIONS_VIDEO_RENDEROPTIONS_D3DBILINEAR - MENUITEM SEPARATOR MENUITEM "GL Nearest", ID_OPTIONS_VIDEO_RENDEROPTIONS_GLNEAREST - MENUITEM "GL Bilinear", ID_OPTIONS_VIDEO_RENDEROPTIONS_GLBILINEAR - MENUITEM "GL Triangle", ID_OPTIONS_VIDEO_RENDEROPTIONS_GLTRIANGLE - MENUITEM "GL Quads", ID_OPTIONS_VIDEO_RENDEROPTIONS_GLQUADS - MENUITEM SEPARATOR MENUITEM "Select skin...", ID_OPTIONS_VIDEO_RENDEROPTIONS_SELECTSKIN - MENUITEM "Skin", ID_OPTIONS_VIDEO_RENDEROPTIONS_SKIN - END MENUITEM SEPARATOR MENUITEM "x&1", ID_OPTIONS_VIDEO_X1 @@ -1721,114 +1524,68 @@ MENUITEM "x&3", ID_OPTIONS_VIDEO_X3 MENUITEM "x&4", ID_OPTIONS_VIDEO_X4 MENUITEM "Full Screen (320x240)", ID_OPTIONS_VIDEO_FULLSCREEN320X240 - MENUITEM "Full Screen (640x480)", ID_OPTIONS_VIDEO_FULLSCREEN640X480 - MENUITEM "Full Screen (800x600)", ID_OPTIONS_VIDEO_FULLSCREEN800X600 - MENUITEM "&Other Full Screen...", ID_OPTIONS_VIDEO_FULLSCREEN - MENUITEM "Full screen max scale...", ID_OPTIONS_VIDEO_FULLSCREENMAXSCALE - MENUITEM SEPARATOR MENUITEM "&Disable SFX", ID_OPTIONS_VIDEO_DISABLESFX - MENUITEM "Fullscreen stretch to &fit", ID_OPTIONS_VIDEO_FULLSCREENSTRETCHTOFIT - MENUITEM SEPARATOR POPUP "&Layers" BEGIN MENUITEM "BG 0", ID_OPTIONS_VIDEO_LAYERS_BG0 - MENUITEM "BG 1", ID_OPTIONS_VIDEO_LAYERS_BG1 - MENUITEM "BG 2", ID_OPTIONS_VIDEO_LAYERS_BG2 - MENUITEM "BG 3", ID_OPTIONS_VIDEO_LAYERS_BG3 - MENUITEM "OBJ", ID_OPTIONS_VIDEO_LAYERS_OBJ - MENUITEM "WIN 0", ID_OPTIONS_VIDEO_LAYERS_WIN0 - MENUITEM "WIN 1", ID_OPTIONS_VIDEO_LAYERS_WIN1 - MENUITEM "OBJ WIN", ID_OPTIONS_VIDEO_LAYERS_OBJWIN - END END POPUP "&Emulator" BEGIN MENUITEM "&Associate...", ID_OPTIONS_EMULATOR_ASSOCIATE - MENUITEM "&Directories...", ID_OPTIONS_EMULATOR_DIRECTORIES - MENUITEM "D&isable status messages", ID_OPTIONS_EMULATOR_DISABLESTATUSMESSAGES - MENUITEM "&Synchronize", ID_OPTIONS_EMULATOR_SYNCHRONIZE - MENUITEM "Pause when inactive window", ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE - MENUITEM "Speed up toggle", ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE - - MENUITEM "Remove intros (GBA)", ID_OPTIONS_EMULATOR_REMOVEINTROSGBA - MENUITEM "Automatic IPS patching", ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH - MENUITEM "AGB Print", ID_OPTIONS_EMULATOR_AGBPRINT - MENUITEM "Real Time Clock", ID_OPTIONS_EMULATOR_REALTIMECLOCK - MENUITEM "Auto hide menu", ID_OPTIONS_EMULATOR_AUTOHIDEMENU - MENUITEM "Rewind interval...", ID_OPTIONS_EMULATOR_REWINDINTERVAL - + MENUITEM "Generic Flashcard (GB/GBC)", ID_OPTIONS_EMULATOR_GENERICFLASHCARD + MENUITEM "&Game Overrides...", ID_OPTIONS_EMULATOR_GAMEOVERRIDES POPUP "Show speed" BEGIN MENUITEM "None", ID_OPTIONS_EMULATOR_SHOWSPEED_NONE - MENUITEM "Percentage", ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE - MENUITEM "Detailed", ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED - MENUITEM SEPARATOR MENUITEM "Transparent", ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT - END POPUP "Save Type" BEGIN MENUITEM "&Automatic", ID_OPTIONS_EMULATOR_SAVETYPE_AUTOMATIC - MENUITEM "EEPROM", ID_OPTIONS_EMULATOR_SAVETYPE_EEPROM - MENUITEM "SRAM", ID_OPTIONS_EMULATOR_SAVETYPE_SRAM - MENUITEM "Flash", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH - MENUITEM "EEPROM+Sensor", ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR - MENUITEM "None", ID_OPTIONS_EMULATOR_SAVETYPE_NONE - MENUITEM SEPARATOR - MENUITEM "Flash 64K", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K - - MENUITEM "Flash 128K", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M - - MENUITEM SEPARATOR - MENUITEM "Enhanced detection", ID_OPTIONS_EMULATOR_SAVETYPE_ENHANCEDDETECTION - + MENUITEM "Flash 64 KB", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K + MENUITEM "Flash 128 KB", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M END MENUITEM SEPARATOR MENUITEM "&Use BIOS file", ID_OPTIONS_EMULATOR_USEBIOSFILE - MENUITEM "Skip BIOS", ID_OPTIONS_EMULATOR_SKIPBIOS - MENUITEM "S&elect BIOS file...", ID_OPTIONS_EMULATOR_SELECTBIOSFILE - MENUITEM SEPARATOR MENUITEM "PNG format", ID_OPTIONS_EMULATOR_PNGFORMAT - MENUITEM "BMP format", ID_OPTIONS_EMULATOR_BMPFORMAT - END POPUP "&Sound" BEGIN @@ -1837,26 +1594,17 @@ MENUITEM "&On", ID_OPTIONS_SOUND_ON MENUITEM SEPARATOR MENUITEM "Use old synchronization", ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION - MENUITEM SEPARATOR MENUITEM "Echo", ID_OPTIONS_SOUND_ECHO MENUITEM "Low pass filter", ID_OPTIONS_SOUND_LOWPASSFILTER - MENUITEM "Reverse Stereo", ID_OPTIONS_SOUND_REVERSESTEREO - MENUITEM SEPARATOR - MENUITEM "Channel &1", ID_OPTIONS_SOUND_CHANNEL1 - , CHECKED - MENUITEM "Channel &2", ID_OPTIONS_SOUND_CHANNEL2 - , CHECKED - MENUITEM "Channel &3", ID_OPTIONS_SOUND_CHANNEL3 - , CHECKED - MENUITEM "Channel &4", ID_OPTIONS_SOUND_CHANNEL4 - , CHECKED - MENUITEM "Direct Sound &A", ID_OPTIONS_SOUND_DIRECTSOUNDA - , CHECKED - MENUITEM "Direct Sound &B", ID_OPTIONS_SOUND_DIRECTSOUNDB - , CHECKED + MENUITEM "Channel &1", ID_OPTIONS_SOUND_CHANNEL1, CHECKED + MENUITEM "Channel &2", ID_OPTIONS_SOUND_CHANNEL2, CHECKED + MENUITEM "Channel &3", ID_OPTIONS_SOUND_CHANNEL3, CHECKED + MENUITEM "Channel &4", ID_OPTIONS_SOUND_CHANNEL4, CHECKED + MENUITEM "Direct Sound &A", ID_OPTIONS_SOUND_DIRECTSOUNDA, CHECKED + MENUITEM "Direct Sound &B", ID_OPTIONS_SOUND_DIRECTSOUNDB, CHECKED MENUITEM SEPARATOR MENUITEM "11 &Khz", ID_OPTIONS_SOUND_11KHZ MENUITEM "22 K&hz", ID_OPTIONS_SOUND_22KHZ @@ -1865,30 +1613,21 @@ POPUP "&Volume" BEGIN MENUITEM ".25X", ID_OPTIONS_SOUND_VOLUME_25X - MENUITEM ".5X", ID_OPTIONS_SOUND_VOLUME_5X - MENUITEM "&1x", ID_OPTIONS_SOUND_VOLUME_1X - MENUITEM "&2x", ID_OPTIONS_SOUND_VOLUME_2X - MENUITEM "&3x", ID_OPTIONS_SOUND_VOLUME_3X - MENUITEM "&4x", ID_OPTIONS_SOUND_VOLUME_4X - END + MENUITEM "Hardware Acceleration", ID_OPTIONS_SOUND_HARDWAREACCELERATION END POPUP "&Gameboy" BEGIN MENUITEM "&Border", ID_OPTIONS_GAMEBOY_BORDER - MENUITEM "&Printer", ID_OPTIONS_GAMEBOY_PRINTER - MENUITEM "Border Automatic", ID_OPTIONS_GAMEBOY_BORDERAUTOMATIC - MENUITEM SEPARATOR MENUITEM "&Automatic", ID_OPTIONS_GAMEBOY_AUTOMATIC - MENUITEM "&GBA", ID_OPTIONS_GAMEBOY_GBA MENUITEM "&CGB/GBC", ID_OPTIONS_GAMEBOY_CGB MENUITEM "&SGB", ID_OPTIONS_GAMEBOY_SGB @@ -1896,110 +1635,74 @@ MENUITEM "G&B", ID_OPTIONS_GAMEBOY_GB MENUITEM SEPARATOR MENUITEM "&Real Colors", ID_OPTIONS_GAMEBOY_REALCOLORS - MENUITEM "G&ameboy Colors", ID_OPTIONS_GAMEBOY_GAMEBOYCOLORS - MENUITEM SEPARATOR MENUITEM "Colors...", ID_OPTIONS_GAMEBOY_COLORS - END POPUP "&Priority" BEGIN MENUITEM "&Highest", ID_OPTIONS_PRIORITY_HIGHEST - MENUITEM "&Above Normal", ID_OPTIONS_PRIORITY_ABOVENORMAL - MENUITEM "&Normal", ID_OPTIONS_PRIORITY_NORMAL - MENUITEM "&Below Normal", ID_OPTIONS_PRIORITY_BELOWNORMAL - END POPUP "F&ilter" BEGIN POPUP "Interframe Blending" BEGIN MENUITEM "None", ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE - MENUITEM "Motion Blur", ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR - MENUITEM "Smart", ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART - END MENUITEM SEPARATOR MENUITEM "&Normal", ID_OPTIONS_FILTER_NORMAL MENUITEM "&TV Mode", ID_OPTIONS_FILTER_TVMODE MENUITEM "&2xSaI", ID_OPTIONS_FILTER_2XSAI MENUITEM "&Super 2xSaI", ID_OPTIONS_FILTER_SUPER2XSAI - MENUITEM "Super &Eagle", ID_OPTIONS_FILTER_SUPEREAGLE - MENUITEM "Pixelate", ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL - MENUITEM "Motion Blur", ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL - MENUITEM "AdvanceMAME Scale2x", ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X - MENUITEM "Simple 2x", ID_OPTIONS_FILTER16BIT_SIMPLE2X - MENUITEM "Bilinear", ID_OPTIONS_FILTER_BILINEAR - MENUITEM "Bilinear Plus", ID_OPTIONS_FILTER_BILINEARPLUS - MENUITEM "Scanlines", ID_OPTIONS_FILTER_SCANLINES - MENUITEM "hq2x", ID_OPTIONS_FILTER_HQ2X MENUITEM "lq2x", ID_OPTIONS_FILTER_LQ2X MENUITEM SEPARATOR MENUITEM "&Disable MMX", ID_OPTIONS_FILTER_DISABLEMMX - END POPUP "&Joypad" BEGIN POPUP "&Configure" BEGIN MENUITEM "&1...", ID_OPTIONS_JOYPAD_CONFIGURE_1 - MENUITEM "&2...", ID_OPTIONS_JOYPAD_CONFIGURE_2 - MENUITEM "&3...", ID_OPTIONS_JOYPAD_CONFIGURE_3 - MENUITEM "&4...", ID_OPTIONS_JOYPAD_CONFIGURE_4 - END POPUP "Default Joypad" BEGIN MENUITEM "1", ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1 - MENUITEM "2", ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_2 - MENUITEM "3", ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_3 - MENUITEM "4", ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_4 - END MENUITEM "Motion Configure...", ID_OPTIONS_JOYPAD_MOTIONCONFIGURE - MENUITEM SEPARATOR POPUP "&Autofire" BEGIN MENUITEM "&A", ID_OPTIONS_JOYPAD_AUTOFIRE_A - MENUITEM "&B", ID_OPTIONS_JOYPAD_AUTOFIRE_B - MENUITEM "&L", ID_OPTIONS_JOYPAD_AUTOFIRE_L - MENUITEM "&R", ID_OPTIONS_JOYPAD_AUTOFIRE_R - END END POPUP "&Language" BEGIN MENUITEM "&System", ID_OPTIONS_LANGUAGE_SYSTEM - MENUITEM "&English", ID_OPTIONS_LANGUAGE_ENGLISH - MENUITEM "&Other...", ID_OPTIONS_LANGUAGE_OTHER - END END POPUP "&Cheats" @@ -2008,7 +1711,6 @@ MENUITEM "&Cheat list...", ID_CHEATS_CHEATLIST MENUITEM SEPARATOR MENUITEM "&Automatic save/load cheats", ID_CHEATS_AUTOMATICSAVELOADCHEATS - MENUITEM "Disable cheats", ID_CHEATS_DISABLECHEATS MENUITEM "&Load cheat list...", ID_CHEATS_LOADCHEATLIST MENUITEM "Sa&ve cheat list...", ID_CHEATS_SAVECHEATLIST @@ -2029,33 +1731,23 @@ BEGIN MENUITEM "Wait for connection...", ID_TOOLS_DEBUG_GDB MENUITEM "Load and wait...", ID_TOOLS_DEBUG_LOADANDWAIT - MENUITEM "Break into GDB", ID_TOOLS_DEBUG_BREAK MENUITEM "Disconnect", ID_TOOLS_DEBUG_DISCONNECT - END MENUITEM SEPARATOR POPUP "Record" BEGIN MENUITEM "Start sound recording...", ID_OPTIONS_SOUND_STARTRECORDING - MENUITEM "Stop sound recording", ID_OPTIONS_SOUND_STOPRECORDING - MENUITEM "Start AVI recording...", ID_TOOLS_RECORD_STARTAVIRECORDING - MENUITEM "Stop AVI recording", ID_TOOLS_RECORD_STOPAVIRECORDING - MENUITEM "Start movie recording...", ID_TOOLS_RECORD_STARTMOVIERECORDING - MENUITEM "Stop movie recording", ID_TOOLS_RECORD_STOPMOVIERECORDING - END POPUP "Play" BEGIN MENUITEM "Start playing movie...", ID_TOOLS_PLAY_STARTMOVIEPLAYING - MENUITEM "Stop playing movie", ID_TOOLS_PLAY_STOPMOVIEPLAYING - END MENUITEM SEPARATOR MENUITEM "Rewind", ID_TOOLS_REWIND @@ -2065,6 +1757,7 @@ BEGIN MENUITEM "Bug Report", ID_HELP_BUGREPORT MENUITEM "FAQ (website)", ID_HELP_FAQ + MENUITEM "License...", ID_HELP_GNUPUBLICLICENSE MENUITEM SEPARATOR MENUITEM "&About...", ID_HELP_ABOUT END @@ -2076,7 +1769,7 @@ // Accelerator // -IDR_ACCELERATOR ACCELERATORS DISCARDABLE +IDR_ACCELERATOR ACCELERATORS BEGIN "1", ID_OPTIONS_VIDEO_LAYERS_BG0, VIRTKEY, CONTROL, NOINVERT "1", ID_OPTIONS_JOYPAD_AUTOFIRE_A, VIRTKEY, ALT, NOINVERT @@ -2089,8 +1782,7 @@ "5", ID_OPTIONS_VIDEO_LAYERS_OBJ, VIRTKEY, CONTROL, NOINVERT "6", ID_OPTIONS_VIDEO_LAYERS_WIN0, VIRTKEY, CONTROL, NOINVERT "7", ID_OPTIONS_VIDEO_LAYERS_WIN1, VIRTKEY, CONTROL, NOINVERT - "8", ID_OPTIONS_VIDEO_LAYERS_OBJWIN, VIRTKEY, CONTROL, - NOINVERT + "8", ID_OPTIONS_VIDEO_LAYERS_OBJWIN, VIRTKEY, CONTROL, NOINVERT "B", ID_TOOLS_REWIND, VIRTKEY, CONTROL, NOINVERT "C", ID_CHEATS_SEARCHFORCHEATS, VIRTKEY, CONTROL, NOINVERT "L", ID_FILE_LOAD, VIRTKEY, CONTROL, NOINVERT @@ -2136,17 +1828,10 @@ ///////////////////////////////////////////////////////////////////////////// // -// 24 -// - -1 24 MOVEABLE PURE "VisualBoyAdvance.exe.manifest" - -///////////////////////////////////////////////////////////////////////////// -// // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_UNSUPPORTED_VBA_SGM "Unsupported VisualBoyAdvance save game version %d" IDS_CANNOT_LOAD_SGM "Cannot load save game for %s" @@ -2166,10 +1851,10 @@ IDS_UNKNOWN_THUMB_OPCODE "Unknown opcode %04x from %08x" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_ERROR_CREATING_FILE "Error creating file %s" - IDS_FAILED_TO_READ_SGM "Failed to read complete save game %s (%d)" + IDS_FAILED_TO_READ_SGM "Battery file's size incompatible with the rom settings %s (%d).\nWarning : save of the battery file is now disabled !" IDS_FAILED_TO_READ_RTC "Failed to read RTC from save game %s (continuing)" IDS_UNSUPPORTED_VB_SGM "Unsupported VisualBoy save game version %d" IDS_CANNOT_LOAD_SGM_FOR "Cannot load save game for %s. Playing %s" @@ -2186,7 +1871,7 @@ IDS_UNSUPPORTED_CHEAT_LIST_VERSION "Unsupported cheat list version %d" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN 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" IDS_DISABLING_VIDEO_MEMORY "Disabling Use Video Memory setting" @@ -2208,7 +1893,7 @@ IDS_INVALID_ADDRESS "Invalid address: %08x" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_MISALIGNED_HALFWORD "Misaligned half-word address: %08x" IDS_MISALIGNED_WORD "Misaligned word address: %08x" @@ -2228,7 +1913,7 @@ IDS_SELECT_BATTERY_DIR "Select Battery directory:" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_SELECT_SAVE_DIR "Select Save Directory:" IDS_SELECT_CAPTURE_DIR "Select Capture directory:" @@ -2248,7 +1933,7 @@ IDS_LOADED_STATE_N "Loaded state %d" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_WROTE_STATE "Wrote state" IDS_WROTE_STATE_N "Wrote state %d" @@ -2268,7 +1953,7 @@ IDS_UNKNOWN "Unknown" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_NONE "None" IDS_FAILED_TO_LOAD_LIBRARY "Failed to load library %s" @@ -2288,7 +1973,7 @@ IDS_SELECT_BATTERY_FILE "Select battery file" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_UNSUPPORTED_CHEAT_LIST_TYPE "Unsupported cheat list type %d" IDS_INVALID_GSA_CODE "Invalid GSA code. Format is XXXXXXXXYYYYYYYY." @@ -2303,12 +1988,12 @@ IDS_OUT_OF_MEMORY "Failed to allocate memory for %s" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_FILTER_GBS "Gameboy Snapshot_*.GBS__" IDS_FILTER_GCF "Gameshark Code File_*.GCF__" IDS_SELECT_CODE_FILE "Select code file" - IDS_SAVE_WILL_BE_LOST "Importing a snapshot file will erase any saved games and reset the emulator. Do you want to continue?" + IDS_SAVE_WILL_BE_LOST "Importing a snapshot file will erase any saved games. Do you want to continue?" IDS_CONFIRM_ACTION "Please confirm action" IDS_CODES_WILL_BE_LOST "Importing a code file will erase any entered codes. Do you want to continue?" IDS_FILTER_SPC "Gameshark Code File_*.SPC;*.XPC__" @@ -2323,7 +2008,7 @@ IDS_ERROR_LISTENING "Error listening on socket." END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_ERROR_CREATING_SOCKET "Error creating socket." IDS_ACK_NOT_RECEIVED "ACK not received from GDB." @@ -2344,7 +2029,7 @@ IDS_END_OF_MOVIE "end of movie" END -STRINGTABLE DISCARDABLE +STRINGTABLE BEGIN IDS_INVALID_INTERVAL_VALUE "Invalid rewind interval value. Please enter a number between 0 and 600 seconds." @@ -2362,8 +2047,7 @@ // // Generated from the TEXTINCLUDE 3 resource. // - - +#include "vba.rc2" ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED diff -urN ../VisualBoyAdvance-1.7.2/src/win32/vba.rc2 ./src/win32/vba.rc2 --- ../VisualBoyAdvance-1.7.2/src/win32/vba.rc2 2004-05-15 20:26:54 +0900 +++ ./src/win32/vba.rc2 2006-05-26 23:37:41 +0900 @@ -1,5 +1,16 @@ #ifndef _MAC #include "../AutoBuild.h" + +#if _MSC_VER >= 1400 +// use modern icon +IDI_ICON ICON DISCARDABLE "vbavista.ico" +#else +// use traditional icon +IDI_ICON ICON DISCARDABLE "gbadvance.ico" +#endif + + + ///////////////////////////////////////////////////////////////////////////// // // Version @@ -23,11 +34,11 @@ BLOCK "040904b0" BEGIN VALUE "Comments", "VisualBoyAdvance comes with NO WARRANTY. Use it at your own risk.\0" - VALUE "CompanyName", "None\0" + VALUE "CompanyName", "http://vba.ngemu.com/\0" VALUE "FileDescription", "VisualBoyAdvance emulator\0" VALUE "FileVersion", STRFILEVER VALUE "InternalName", "VisualBoyAdvance\0" - VALUE "LegalCopyright", "Copyright © 2004 Forgotten and the VBA team\0" + VALUE "LegalCopyright", "Copyright © 2006 VBA development team\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "VisualBoyAdvance.exe\0" VALUE "PrivateBuild", "0\0" Binary files ../VisualBoyAdvance-1.7.2/src/win32/vbavista.ico and ./src/win32/vbavista.ico differ diff -urN ../VisualBoyAdvance-1.7.2/win32/GBA.dsp ./win32/GBA.dsp --- ../VisualBoyAdvance-1.7.2/win32/GBA.dsp 2004-02-29 22:07:01 +0900 +++ ./win32/GBA.dsp 2004-11-05 09:51:52 +0900 @@ -494,36 +494,36 @@ !IF "$(CFG)" == "GBA - Win32 Release" # Begin Custom Build -OutDir=.\Release +IntDir=.\Release InputPath=..\src\i386\2xSaImmx.asm InputName=2xSaImmx -"$(OutDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o $(OutDir)\$(InputName).obj $(InputPath) +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o "$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build !ELSEIF "$(CFG)" == "GBA - Win32 Debug" # Begin Custom Build -OutDir=.\Debug +IntDir=.\Debug InputPath=..\src\i386\2xSaImmx.asm InputName=2xSaImmx -"$(OutDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o $(OutDir)\$(InputName).obj $(InputPath) +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o "$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build !ELSEIF "$(CFG)" == "GBA - Win32 ReleaseNoDev" # Begin Custom Build -OutDir=.\ReleaseNoDev +IntDir=.\ReleaseNoDev InputPath=..\src\i386\2xSaImmx.asm InputName=2xSaImmx -"$(OutDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o $(OutDir)\$(InputName).obj $(InputPath) +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + "c:\Program Files\Nasm\nasmw.exe" -D__DJGPP__ -f win32 -o "$(IntDir)\$(InputName).obj" "$(InputPath)" # End Custom Build @@ -560,6 +560,10 @@ # End Source File # Begin Source File +SOURCE=..\src\win32\GameOverrides.cpp +# End Source File +# Begin Source File + SOURCE=..\src\win32\GDIDisplay.cpp # End Source File # Begin Source File @@ -736,6 +740,10 @@ # End Source File # Begin Source File +SOURCE=..\src\win32\GameOverrides.h +# End Source File +# Begin Source File + SOURCE=..\src\gb\GB.h # End Source File # Begin Source File diff -urN ../VisualBoyAdvance-1.7.2/win32/Makefile.in ./win32/Makefile.in --- ../VisualBoyAdvance-1.7.2/win32/Makefile.in 2004-05-14 06:41:19 +0900 +++ ./win32/Makefile.in 2004-09-30 07:23:40 +0900 @@ -77,6 +77,8 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBOBJS = @LIBOBJS@ +LIBPNG_CFLAGS = @LIBPNG_CFLAGS@ +LIBPNG_LIBS = @LIBPNG_LIBS@ LIBS = @LIBS@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL.h ./win32/SDL-1.2.2/include/SDL.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL.h 1970-01-01 09:00:00 +0900 @@ -1,97 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Main include header for the SDL library */ - -#ifndef _SDL_H -#define _SDL_H - -#include "SDL_main.h" -#include "SDL_types.h" -#include "SDL_getenv.h" -#include "SDL_error.h" -#include "SDL_rwops.h" -#include "SDL_timer.h" -#include "SDL_audio.h" -#include "SDL_cdrom.h" -#include "SDL_joystick.h" -#include "SDL_events.h" -#include "SDL_video.h" -#include "SDL_byteorder.h" -#include "SDL_version.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* As of version 0.5, SDL is loaded dynamically into the application */ - -/* These are the flags which may be passed to SDL_Init() -- you should - specify the subsystems which you will be using in your application. -*/ -#define SDL_INIT_TIMER 0x00000001 -#define SDL_INIT_AUDIO 0x00000010 -#define SDL_INIT_VIDEO 0x00000020 -#define SDL_INIT_CDROM 0x00000100 -#define SDL_INIT_JOYSTICK 0x00000200 -#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */ -#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */ -#define SDL_INIT_EVERYTHING 0x0000FFFF - -/* This function loads the SDL dynamically linked library and initializes - * the subsystems specified by 'flags' (and those satisfying dependencies) - * Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup - * signal handlers for some commonly ignored fatal signals (like SIGSEGV) - */ -extern DECLSPEC int SDL_Init(Uint32 flags); - -/* This function initializes specific SDL subsystems */ -extern DECLSPEC int SDL_InitSubSystem(Uint32 flags); - -/* This function cleans up specific SDL subsystems */ -extern DECLSPEC void SDL_QuitSubSystem(Uint32 flags); - -/* This function returns mask of the specified subsystems which have - been initialized. - If 'flags' is 0, it returns a mask of all initialized subsystems. -*/ -extern DECLSPEC Uint32 SDL_WasInit(Uint32 flags); - -/* This function cleans up all initialized subsystems and unloads the - * dynamically linked library. You should call it upon all exit conditions. - */ -extern DECLSPEC void SDL_Quit(void); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_active.h ./win32/SDL-1.2.2/include/SDL_active.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_active.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_active.h 1970-01-01 09:00:00 +0900 @@ -1,60 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_active.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL application focus event handling */ - -#ifndef _SDL_active_h -#define _SDL_active_h - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* The available application states */ -#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */ -#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */ -#define SDL_APPACTIVE 0x04 /* The application is active */ - -/* Function prototypes */ -/* - * This function returns the current state of the application, which is a - * bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and - * SDL_APPACTIVE. If SDL_APPACTIVE is set, then the user is able to - * see your application, otherwise it has been iconified or disabled. - */ -extern DECLSPEC Uint8 SDL_GetAppState(void); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_active_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_audio.h ./win32/SDL-1.2.2/include/SDL_audio.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_audio.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_audio.h 1970-01-01 09:00:00 +0900 @@ -1,260 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_audio.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Access to the raw audio mixing buffer for the SDL library */ - -#ifndef _SDL_audio_h -#define _SDL_audio_h - -#include - -#include "SDL_main.h" -#include "SDL_types.h" -#include "SDL_error.h" -#include "SDL_rwops.h" -#include "SDL_byteorder.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* The calculated values in this structure are calculated by SDL_OpenAudio() */ -typedef struct { - int freq; /* DSP frequency -- samples per second */ - Uint16 format; /* Audio data format */ - Uint8 channels; /* Number of channels: 1 mono, 2 stereo */ - Uint8 silence; /* Audio buffer silence value (calculated) */ - Uint16 samples; /* Audio buffer size in samples */ - Uint16 padding; /* Necessary for some compile environments */ - Uint32 size; /* Audio buffer size in bytes (calculated) */ - /* This function is called when the audio device needs more data. - 'stream' is a pointer to the audio data buffer - 'len' is the length of that buffer in bytes. - Once the callback returns, the buffer will no longer be valid. - Stereo samples are stored in a LRLRLR ordering. - */ - void (*callback)(void *userdata, Uint8 *stream, int len); - void *userdata; -} SDL_AudioSpec; - -/* Audio format flags (defaults to LSB byte order) */ -#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */ -#define AUDIO_S8 0x8008 /* Signed 8-bit samples */ -#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */ -#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */ -#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */ -#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */ -#define AUDIO_U16 AUDIO_U16LSB -#define AUDIO_S16 AUDIO_S16LSB - -/* Native audio byte ordering */ -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -#define AUDIO_U16SYS AUDIO_U16LSB -#define AUDIO_S16SYS AUDIO_S16LSB -#else -#define AUDIO_U16SYS AUDIO_U16MSB -#define AUDIO_S16SYS AUDIO_S16MSB -#endif - - -/* A structure to hold a set of audio conversion filters and buffers */ -typedef struct SDL_AudioCVT { - int needed; /* Set to 1 if conversion possible */ - Uint16 src_format; /* Source audio format */ - Uint16 dst_format; /* Target audio format */ - double rate_incr; /* Rate conversion increment */ - Uint8 *buf; /* Buffer to hold entire audio data */ - int len; /* Length of original audio buffer */ - int len_cvt; /* Length of converted audio buffer */ - int len_mult; /* buffer must be len*len_mult big */ - double len_ratio; /* Given len, final size is len*len_ratio */ - void (*filters[10])(struct SDL_AudioCVT *cvt, Uint16 format); - int filter_index; /* Current audio conversion function */ -} SDL_AudioCVT; - - -/* Function prototypes */ - -/* These functions are used internally, and should not be used unless you - * have a specific need to specify the audio driver you want to use. - * You should normally use SDL_Init() or SDL_InitSubSystem(). - */ -extern DECLSPEC int SDL_AudioInit(const char *driver_name); -extern DECLSPEC void SDL_AudioQuit(void); - -/* This function fills the given character buffer with the name of the - * current audio driver, and returns a pointer to it if the audio driver has - * been initialized. It returns NULL if no driver has been initialized. - */ -extern DECLSPEC char *SDL_AudioDriverName(char *namebuf, int maxlen); - -/* - * This function opens the audio device with the desired parameters, and - * returns 0 if successful, placing the actual hardware parameters in the - * structure pointed to by 'obtained'. If 'obtained' is NULL, the audio - * data passed to the callback function will be guaranteed to be in the - * requested format, and will be automatically converted to the hardware - * audio format if necessary. This function returns -1 if it failed - * to open the audio device, or couldn't set up the audio thread. - * - * When filling in the desired audio spec structure, - * 'desired->freq' should be the desired audio frequency in samples-per-second. - * 'desired->format' should be the desired audio format. - * 'desired->samples' is the desired size of the audio buffer, in samples. - * This number should be a power of two, and may be adjusted by the audio - * driver to a value more suitable for the hardware. Good values seem to - * range between 512 and 8096 inclusive, depending on the application and - * CPU speed. Smaller values yield faster response time, but can lead - * to underflow if the application is doing heavy processing and cannot - * fill the audio buffer in time. A stereo sample consists of both right - * and left channels in LR ordering. - * Note that the number of samples is directly related to time by the - * following formula: ms = (samples*1000)/freq - * 'desired->size' is the size in bytes of the audio buffer, and is - * calculated by SDL_OpenAudio(). - * 'desired->silence' is the value used to set the buffer to silence, - * and is calculated by SDL_OpenAudio(). - * 'desired->callback' should be set to a function that will be called - * when the audio device is ready for more data. It is passed a pointer - * to the audio buffer, and the length in bytes of the audio buffer. - * This function usually runs in a separate thread, and so you should - * protect data structures that it accesses by calling SDL_LockAudio() - * and SDL_UnlockAudio() in your code. - * 'desired->userdata' is passed as the first parameter to your callback - * function. - * - * The audio device starts out playing silence when it's opened, and should - * be enabled for playing by calling SDL_PauseAudio(0) when you are ready - * for your audio callback function to be called. Since the audio driver - * may modify the requested size of the audio buffer, you should allocate - * any local mixing buffers after you open the audio device. - */ -extern DECLSPEC int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained); - -/* - * Get the current audio state: - */ -typedef enum { - SDL_AUDIO_STOPPED = 0, - SDL_AUDIO_PLAYING, - SDL_AUDIO_PAUSED -} SDL_audiostatus; -extern DECLSPEC SDL_audiostatus SDL_GetAudioStatus(void); - -/* - * This function pauses and unpauses the audio callback processing. - * It should be called with a parameter of 0 after opening the audio - * device to start playing sound. This is so you can safely initialize - * data for your callback function after opening the audio device. - * Silence will be written to the audio device during the pause. - */ -extern DECLSPEC void SDL_PauseAudio(int pause_on); - -/* - * This function loads a WAVE from the data source, automatically freeing - * that source if 'freesrc' is non-zero. For example, to load a WAVE file, - * you could do: - * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); - * - * If this function succeeds, it returns the given SDL_AudioSpec, - * filled with the audio data format of the wave data, and sets - * 'audio_buf' to a malloc()'d buffer containing the audio data, - * and sets 'audio_len' to the length of that audio buffer, in bytes. - * You need to free the audio buffer with SDL_FreeWAV() when you are - * done with it. - * - * This function returns NULL and sets the SDL error message if the - * wave file cannot be opened, uses an unknown data format, or is - * corrupt. Currently raw and MS-ADPCM WAVE files are supported. - */ -extern DECLSPEC SDL_AudioSpec *SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, - SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len); - -/* Compatibility convenience function -- loads a WAV from a file */ -#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \ - SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len) - -/* - * This function frees data previously allocated with SDL_LoadWAV_RW() - */ -extern DECLSPEC void SDL_FreeWAV(Uint8 *audio_buf); - -/* - * This function takes a source format and rate and a destination format - * and rate, and initializes the 'cvt' structure with information needed - * by SDL_ConvertAudio() to convert a buffer of audio data from one format - * to the other. - * This function returns 0, or -1 if there was an error. - */ -extern DECLSPEC int SDL_BuildAudioCVT(SDL_AudioCVT *cvt, - Uint16 src_format, Uint8 src_channels, int src_rate, - Uint16 dst_format, Uint8 dst_channels, int dst_rate); - -/* Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(), - * created an audio buffer cvt->buf, and filled it with cvt->len bytes of - * audio data in the source format, this function will convert it in-place - * to the desired format. - * The data conversion may expand the size of the audio data, so the buffer - * cvt->buf should be allocated after the cvt structure is initialized by - * SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long. - */ -extern DECLSPEC int SDL_ConvertAudio(SDL_AudioCVT *cvt); - -/* - * This takes two audio buffers of the playing audio format and mixes - * them, performing addition, volume adjustment, and overflow clipping. - * The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME - * for full audio volume. Note this does not change hardware volume. - * This is provided for convenience -- you can mix your own audio data. - */ -#define SDL_MIX_MAXVOLUME 128 -extern DECLSPEC void SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume); - -/* - * The lock manipulated by these functions protects the callback function. - * During a LockAudio/UnlockAudio pair, you can be guaranteed that the - * callback function is not running. Do not call these from the callback - * function or you will cause deadlock. - */ -extern DECLSPEC void SDL_LockAudio(void); -extern DECLSPEC void SDL_UnlockAudio(void); - -/* - * This function shuts down audio processing and closes the audio device. - */ -extern DECLSPEC void SDL_CloseAudio(void); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_audio_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_byteorder.h ./win32/SDL-1.2.2/include/SDL_byteorder.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_byteorder.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_byteorder.h 1970-01-01 09:00:00 +0900 @@ -1,52 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_byteorder.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Macros for determining the byte-order of this platform */ - -#ifndef _SDL_byteorder_h -#define _SDL_byteorder_h - -/* The two types of endianness */ -#define SDL_LIL_ENDIAN 1234 -#define SDL_BIG_ENDIAN 4321 - -/* Pardon the mess, I'm trying to determine the endianness of this host. - I'm doing it by preprocessor defines rather than some sort of configure - script so that application code can use this too. The "right" way would - be to dynamically generate this file on install, but that's a lot of work. - */ -#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ - (defined(__alpha__) || defined(__alpha)) || \ - defined(__arm__) || \ - (defined(__mips__) && defined(__MIPSEL__)) || \ - defined(__LITTLE_ENDIAN__) -#define SDL_BYTEORDER SDL_LIL_ENDIAN -#else -#define SDL_BYTEORDER SDL_BIG_ENDIAN -#endif - -#endif /* _SDL_byteorder_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_cdrom.h ./win32/SDL-1.2.2/include/SDL_cdrom.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_cdrom.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_cdrom.h 1970-01-01 09:00:00 +0900 @@ -1,175 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_cdrom.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* This is the CD-audio control API for Simple DirectMedia Layer */ - -#ifndef _SDL_cdrom_h -#define _SDL_cdrom_h - -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* In order to use these functions, SDL_Init() must have been called - with the SDL_INIT_CDROM flag. This causes SDL to scan the system - for CD-ROM drives, and load appropriate drivers. -*/ - -/* The maximum number of CD-ROM tracks on a disk */ -#define SDL_MAX_TRACKS 99 - -/* The types of CD-ROM track possible */ -#define SDL_AUDIO_TRACK 0x00 -#define SDL_DATA_TRACK 0x04 - -/* The possible states which a CD-ROM drive can be in. */ -typedef enum { - CD_TRAYEMPTY, - CD_STOPPED, - CD_PLAYING, - CD_PAUSED, - CD_ERROR = -1 -} CDstatus; - -/* Given a status, returns true if there's a disk in the drive */ -#define CD_INDRIVE(status) ((int)status > 0) - -typedef struct { - Uint8 id; /* Track number */ - Uint8 type; /* Data or audio track */ - Uint16 unused; - Uint32 length; /* Length, in frames, of this track */ - Uint32 offset; /* Offset, in frames, from start of disk */ -} SDL_CDtrack; - -/* This structure is only current as of the last call to SDL_CDStatus() */ -typedef struct SDL_CD { - int id; /* Private drive identifier */ - CDstatus status; /* Current drive status */ - - /* The rest of this structure is only valid if there's a CD in drive */ - int numtracks; /* Number of tracks on disk */ - int cur_track; /* Current track position */ - int cur_frame; /* Current frame offset within current track */ - SDL_CDtrack track[SDL_MAX_TRACKS+1]; -} SDL_CD; - -/* Conversion functions from frames to Minute/Second/Frames and vice versa */ -#define CD_FPS 75 -#define FRAMES_TO_MSF(f, M,S,F) { \ - int value = f; \ - *(F) = value%CD_FPS; \ - value /= CD_FPS; \ - *(S) = value%60; \ - value /= 60; \ - *(M) = value; \ -} -#define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F)) - -/* CD-audio API functions: */ - -/* Returns the number of CD-ROM drives on the system, or -1 if - SDL_Init() has not been called with the SDL_INIT_CDROM flag. - */ -extern DECLSPEC int SDL_CDNumDrives(void); - -/* Returns a human-readable, system-dependent identifier for the CD-ROM. - Example: - "/dev/cdrom" - "E:" - "/dev/disk/ide/1/master" -*/ -extern DECLSPEC const char * SDL_CDName(int drive); - -/* Opens a CD-ROM drive for access. It returns a drive handle on success, - or NULL if the drive was invalid or busy. This newly opened CD-ROM - becomes the default CD used when other CD functions are passed a NULL - CD-ROM handle. - Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. -*/ -extern DECLSPEC SDL_CD * SDL_CDOpen(int drive); - -/* This function returns the current status of the given drive. - If the drive has a CD in it, the table of contents of the CD and current - play position of the CD will be stored in the SDL_CD structure. -*/ -extern DECLSPEC CDstatus SDL_CDStatus(SDL_CD *cdrom); - -/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks' - tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play - until the end of the CD. This function will skip data tracks. - This function should only be called after calling SDL_CDStatus() to - get track information about the CD. - For example: - // Play entire CD: - if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) - SDL_CDPlayTracks(cdrom, 0, 0, 0, 0); - // Play last track: - if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { - SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0); - } - // Play first and second track and 10 seconds of third track: - if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) - SDL_CDPlayTracks(cdrom, 0, 0, 2, 10); - - This function returns 0, or -1 if there was an error. -*/ -extern DECLSPEC int SDL_CDPlayTracks(SDL_CD *cdrom, - int start_track, int start_frame, int ntracks, int nframes); - -/* Play the given CD starting at 'start' frame for 'length' frames. - It returns 0, or -1 if there was an error. -*/ -extern DECLSPEC int SDL_CDPlay(SDL_CD *cdrom, int start, int length); - -/* Pause play -- returns 0, or -1 on error */ -extern DECLSPEC int SDL_CDPause(SDL_CD *cdrom); - -/* Resume play -- returns 0, or -1 on error */ -extern DECLSPEC int SDL_CDResume(SDL_CD *cdrom); - -/* Stop play -- returns 0, or -1 on error */ -extern DECLSPEC int SDL_CDStop(SDL_CD *cdrom); - -/* Eject CD-ROM -- returns 0, or -1 on error */ -extern DECLSPEC int SDL_CDEject(SDL_CD *cdrom); - -/* Closes the handle for the CD-ROM drive */ -extern DECLSPEC void SDL_CDClose(SDL_CD *cdrom); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_video_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_copying.h ./win32/SDL-1.2.2/include/SDL_copying.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_copying.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_copying.h 1970-01-01 09:00:00 +0900 @@ -1,27 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_copying.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_endian.h ./win32/SDL-1.2.2/include/SDL_endian.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_endian.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_endian.h 1970-01-01 09:00:00 +0900 @@ -1,149 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_endian.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Functions for reading and writing endian-specific values */ - -#ifndef _SDL_endian_h -#define _SDL_endian_h - -/* These functions read and write data of the specified endianness, - dynamically translating to the host machine endianness. - - e.g.: If you want to read a 16 bit value on big-endian machine from - an open file containing little endian values, you would use: - value = SDL_ReadLE16(rp); - Note that the read/write functions use SDL_RWops pointers - instead of FILE pointers. This allows you to read and write - endian values from large chunks of memory as well as files - and other data sources. -*/ - -#include - -#include "SDL_types.h" -#include "SDL_rwops.h" -#include "SDL_byteorder.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* The macros used to swap values */ -/* Try to use superfast macros on systems that support them */ -#ifdef linux -#include -#ifdef __arch__swab16 -#define SDL_Swap16 __arch__swab16 -#endif -#ifdef __arch__swab32 -#define SDL_Swap32 __arch__swab32 -#endif -#endif /* linux */ -/* Use inline functions for compilers that support them, and static - functions for those that do not. Because these functions become - static for compilers that do not support inline functions, this - header should only be included in files that actually use them. -*/ -#ifndef SDL_Swap16 -static __inline__ Uint16 SDL_Swap16(Uint16 D) { - return((D<<8)|(D>>8)); -} -#endif -#ifndef SDL_Swap32 -static __inline__ Uint32 SDL_Swap32(Uint32 D) { - return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); -} -#endif -#ifdef SDL_HAS_64BIT_TYPE -#ifndef SDL_Swap64 -static __inline__ Uint64 SDL_Swap64(Uint64 val) { - Uint32 hi, lo; - - /* Separate into high and low 32-bit values and swap them */ - lo = (Uint32)(val&0xFFFFFFFF); - val >>= 32; - hi = (Uint32)(val&0xFFFFFFFF); - val = SDL_Swap32(lo); - val <<= 32; - val |= SDL_Swap32(hi); - return(val); -} -#endif -#else -#ifndef SDL_Swap64 -/* This is mainly to keep compilers from complaining in SDL code. - If there is no real 64-bit datatype, then compilers will complain about - the fake 64-bit datatype that SDL provides when it compiles user code. -*/ -#define SDL_Swap64(X) (X) -#endif -#endif /* SDL_HAS_64BIT_TYPE */ - - -/* Byteswap item from the specified endianness to the native endianness */ -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -#define SDL_SwapLE16(X) (X) -#define SDL_SwapLE32(X) (X) -#define SDL_SwapLE64(X) (X) -#define SDL_SwapBE16(X) SDL_Swap16(X) -#define SDL_SwapBE32(X) SDL_Swap32(X) -#define SDL_SwapBE64(X) SDL_Swap64(X) -#else -#define SDL_SwapLE16(X) SDL_Swap16(X) -#define SDL_SwapLE32(X) SDL_Swap32(X) -#define SDL_SwapLE64(X) SDL_Swap64(X) -#define SDL_SwapBE16(X) (X) -#define SDL_SwapBE32(X) (X) -#define SDL_SwapBE64(X) (X) -#endif - -/* Read an item of the specified endianness and return in native format */ -extern DECLSPEC Uint16 SDL_ReadLE16(SDL_RWops *src); -extern DECLSPEC Uint16 SDL_ReadBE16(SDL_RWops *src); -extern DECLSPEC Uint32 SDL_ReadLE32(SDL_RWops *src); -extern DECLSPEC Uint32 SDL_ReadBE32(SDL_RWops *src); -extern DECLSPEC Uint64 SDL_ReadLE64(SDL_RWops *src); -extern DECLSPEC Uint64 SDL_ReadBE64(SDL_RWops *src); - -/* Write an item of native format to the specified endianness */ -extern DECLSPEC int SDL_WriteLE16(SDL_RWops *dst, Uint16 value); -extern DECLSPEC int SDL_WriteBE16(SDL_RWops *dst, Uint16 value); -extern DECLSPEC int SDL_WriteLE32(SDL_RWops *dst, Uint32 value); -extern DECLSPEC int SDL_WriteBE32(SDL_RWops *dst, Uint32 value); -extern DECLSPEC int SDL_WriteLE64(SDL_RWops *dst, Uint64 value); -extern DECLSPEC int SDL_WriteBE64(SDL_RWops *dst, Uint64 value); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_endian_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_error.h ./win32/SDL-1.2.2/include/SDL_error.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_error.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_error.h 1970-01-01 09:00:00 +0900 @@ -1,62 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_error.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Simple error message routines for SDL */ - -#ifndef _SDL_error_h -#define _SDL_error_h - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Public functions */ -extern DECLSPEC void SDL_SetError(const char *fmt, ...); -extern DECLSPEC char * SDL_GetError(void); -extern DECLSPEC void SDL_ClearError(void); - -/* Private error message function - used internally */ -#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM) -typedef enum { - SDL_ENOMEM, - SDL_EFREAD, - SDL_EFWRITE, - SDL_EFSEEK, - SDL_LASTERROR -} SDL_errorcode; -extern void SDL_Error(SDL_errorcode code); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_error_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_events.h ./win32/SDL-1.2.2/include/SDL_events.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_events.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_events.h 1970-01-01 09:00:00 +0900 @@ -1,334 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_events.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL event handling */ - -#ifndef _SDL_events_h -#define _SDL_events_h - -#include "SDL_types.h" -#include "SDL_active.h" -#include "SDL_keyboard.h" -#include "SDL_mouse.h" -#include "SDL_joystick.h" -#include "SDL_quit.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Event enumerations */ -enum { SDL_NOEVENT = 0, /* Unused (do not remove) */ - SDL_ACTIVEEVENT, /* Application loses/gains visibility */ - SDL_KEYDOWN, /* Keys pressed */ - SDL_KEYUP, /* Keys released */ - SDL_MOUSEMOTION, /* Mouse moved */ - SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */ - SDL_MOUSEBUTTONUP, /* Mouse button released */ - SDL_JOYAXISMOTION, /* Joystick axis motion */ - SDL_JOYBALLMOTION, /* Joystick trackball motion */ - SDL_JOYHATMOTION, /* Joystick hat position change */ - SDL_JOYBUTTONDOWN, /* Joystick button pressed */ - SDL_JOYBUTTONUP, /* Joystick button released */ - SDL_QUIT, /* User-requested quit */ - SDL_SYSWMEVENT, /* System specific event */ - SDL_EVENT_RESERVEDA, /* Reserved for future use.. */ - SDL_EVENT_RESERVEDB, /* Reserved for future use.. */ - SDL_VIDEORESIZE, /* User resized video mode */ - SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */ - SDL_EVENT_RESERVED2, /* Reserved for future use.. */ - SDL_EVENT_RESERVED3, /* Reserved for future use.. */ - SDL_EVENT_RESERVED4, /* Reserved for future use.. */ - SDL_EVENT_RESERVED5, /* Reserved for future use.. */ - SDL_EVENT_RESERVED6, /* Reserved for future use.. */ - SDL_EVENT_RESERVED7, /* Reserved for future use.. */ - /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ - SDL_USEREVENT = 24, - /* This last event is only for bounding internal arrays - It is the number of bits in the event mask datatype -- Uint32 - */ - SDL_NUMEVENTS = 32 -}; - -/* Predefined event masks */ -#define SDL_EVENTMASK(X) (1<<(X)) -enum { - SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT), - SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN), - SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP), - SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION), - SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN), - SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP), - SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION)| - SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)| - SDL_EVENTMASK(SDL_MOUSEBUTTONUP), - SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION), - SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION), - SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION), - SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN), - SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP), - SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION)| - SDL_EVENTMASK(SDL_JOYBALLMOTION)| - SDL_EVENTMASK(SDL_JOYHATMOTION)| - SDL_EVENTMASK(SDL_JOYBUTTONDOWN)| - SDL_EVENTMASK(SDL_JOYBUTTONUP), - SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE), - SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE), - SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT), - SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT) -}; -#define SDL_ALLEVENTS 0xFFFFFFFF - -/* Application visibility event structure */ -typedef struct { - Uint8 type; /* SDL_ACTIVEEVENT */ - Uint8 gain; /* Whether given states were gained or lost (1/0) */ - Uint8 state; /* A mask of the focus states */ -} SDL_ActiveEvent; - -/* Keyboard event structure */ -typedef struct { - Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */ - Uint8 which; /* The keyboard device index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ - SDL_keysym keysym; -} SDL_KeyboardEvent; - -/* Mouse motion event structure */ -typedef struct { - Uint8 type; /* SDL_MOUSEMOTION */ - Uint8 which; /* The mouse device index */ - Uint8 state; /* The current button state */ - Uint16 x, y; /* The X/Y coordinates of the mouse */ - Sint16 xrel; /* The relative motion in the X direction */ - Sint16 yrel; /* The relative motion in the Y direction */ -} SDL_MouseMotionEvent; - -/* Mouse button event structure */ -typedef struct { - Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ - Uint8 which; /* The mouse device index */ - Uint8 button; /* The mouse button index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ - Uint16 x, y; /* The X/Y coordinates of the mouse at press time */ -} SDL_MouseButtonEvent; - -/* Joystick axis motion event structure */ -typedef struct { - Uint8 type; /* SDL_JOYAXISMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 axis; /* The joystick axis index */ - Sint16 value; /* The axis value (range: -32768 to 32767) */ -} SDL_JoyAxisEvent; - -/* Joystick trackball motion event structure */ -typedef struct { - Uint8 type; /* SDL_JOYBALLMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 ball; /* The joystick trackball index */ - Sint16 xrel; /* The relative motion in the X direction */ - Sint16 yrel; /* The relative motion in the Y direction */ -} SDL_JoyBallEvent; - -/* Joystick hat position change event structure */ -typedef struct { - Uint8 type; /* SDL_JOYHATMOTION */ - Uint8 which; /* The joystick device index */ - Uint8 hat; /* The joystick hat index */ - Uint8 value; /* The hat position value: - 8 1 2 - 7 0 3 - 6 5 4 - Note that zero means the POV is centered. - */ -} SDL_JoyHatEvent; - -/* Joystick button event structure */ -typedef struct { - Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ - Uint8 which; /* The joystick device index */ - Uint8 button; /* The joystick button index */ - Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ -} SDL_JoyButtonEvent; - -/* The "window resized" event - When you get this event, you are responsible for setting a new video - mode with the new width and height. - */ -typedef struct { - Uint8 type; /* SDL_VIDEORESIZE */ - int w; /* New width */ - int h; /* New height */ -} SDL_ResizeEvent; - -/* The "screen redraw" event */ -typedef struct { - Uint8 type; /* SDL_VIDEOEXPOSE */ -} SDL_ExposeEvent; - -/* The "quit requested" event */ -typedef struct { - Uint8 type; /* SDL_QUIT */ -} SDL_QuitEvent; - -/* A user-defined event type */ -typedef struct { - Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ - int code; /* User defined event code */ - void *data1; /* User defined data pointer */ - void *data2; /* User defined data pointer */ -} SDL_UserEvent; - -/* If you want to use this event, you should include SDL_syswm.h */ -struct SDL_SysWMmsg; -typedef struct SDL_SysWMmsg SDL_SysWMmsg; -typedef struct { - Uint8 type; - SDL_SysWMmsg *msg; -} SDL_SysWMEvent; - -/* General event structure */ -typedef union { - Uint8 type; - SDL_ActiveEvent active; - SDL_KeyboardEvent key; - SDL_MouseMotionEvent motion; - SDL_MouseButtonEvent button; - SDL_JoyAxisEvent jaxis; - SDL_JoyBallEvent jball; - SDL_JoyHatEvent jhat; - SDL_JoyButtonEvent jbutton; - SDL_ResizeEvent resize; - SDL_ExposeEvent expose; - SDL_QuitEvent quit; - SDL_UserEvent user; - SDL_SysWMEvent syswm; -} SDL_Event; - - -/* Function prototypes */ - -/* Pumps the event loop, gathering events from the input devices. - This function updates the event queue and internal input device state. - This should only be run in the thread that sets the video mode. -*/ -extern DECLSPEC void SDL_PumpEvents(void); - -/* Checks the event queue for messages and optionally returns them. - If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to - the back of the event queue. - If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front - of the event queue, matching 'mask', will be returned and will not - be removed from the queue. - If 'action' is SDL_GETEVENT, up to 'numevents' events at the front - of the event queue, matching 'mask', will be returned and will be - removed from the queue. - This function returns the number of events actually stored, or -1 - if there was an error. This function is thread-safe. -*/ -typedef enum { - SDL_ADDEVENT, - SDL_PEEKEVENT, - SDL_GETEVENT -} SDL_eventaction; -/* */ -extern DECLSPEC int SDL_PeepEvents(SDL_Event *events, int numevents, - SDL_eventaction action, Uint32 mask); - -/* Polls for currently pending events, and returns 1 if there are any pending - events, or 0 if there are none available. If 'event' is not NULL, the next - event is removed from the queue and stored in that area. - */ -extern DECLSPEC int SDL_PollEvent(SDL_Event *event); - -/* Waits indefinitely for the next available event, returning 1, or 0 if there - was an error while waiting for events. If 'event' is not NULL, the next - event is removed from the queue and stored in that area. - */ -extern DECLSPEC int SDL_WaitEvent(SDL_Event *event); - -/* Add an event to the event queue. - This function returns 0, or -1 if the event couldn't be added to - the event queue. If the event queue is full, this function fails. - */ -extern DECLSPEC int SDL_PushEvent(SDL_Event *event); - -/* - This function sets up a filter to process all events before they - change internal state and are posted to the internal event queue. - - The filter is protypted as: -*/ -typedef int (*SDL_EventFilter)(const SDL_Event *event); -/* - If the filter returns 1, then the event will be added to the internal queue. - If it returns 0, then the event will be dropped from the queue, but the - internal state will still be updated. This allows selective filtering of - dynamically arriving events. - - WARNING: Be very careful of what you do in the event filter function, as - it may run in a different thread! - - There is one caveat when dealing with the SDL_QUITEVENT event type. The - event filter is only called when the window manager desires to close the - application window. If the event filter returns 1, then the window will - be closed, otherwise the window will remain open if possible. - If the quit event is generated by an interrupt signal, it will bypass the - internal queue and be delivered to the application at the next event poll. -*/ -extern DECLSPEC void SDL_SetEventFilter(SDL_EventFilter filter); - -/* - Return the current event filter - can be used to "chain" filters. - If there is no event filter set, this function returns NULL. -*/ -extern DECLSPEC SDL_EventFilter SDL_GetEventFilter(void); - -/* - This function allows you to set the state of processing certain events. - If 'state' is set to SDL_IGNORE, that event will be automatically dropped - from the event queue and will not event be filtered. - If 'state' is set to SDL_ENABLE, that event will be processed normally. - If 'state' is set to SDL_QUERY, SDL_EventState() will return the - current processing state of the specified event. -*/ -#define SDL_QUERY -1 -#define SDL_IGNORE 0 -#define SDL_DISABLE 0 -#define SDL_ENABLE 1 -extern DECLSPEC Uint8 SDL_EventState(Uint8 type, int state); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_events_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_getenv.h ./win32/SDL-1.2.2/include/SDL_getenv.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_getenv.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_getenv.h 1970-01-01 09:00:00 +0900 @@ -1,30 +0,0 @@ - -/* Not all environments have a working getenv()/putenv() */ - -#if defined(macintosh) || defined(_WIN32_WCE) -#define NEED_SDL_GETENV -#endif - -#ifdef NEED_SDL_GETENV - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Put a variable of the form "name=value" into the environment */ -extern DECLSPEC int SDL_putenv(const char *variable); -#define putenv(X) SDL_putenv(X) - -/* Retrieve a variable named "name" from the environment */ -extern DECLSPEC char *SDL_getenv(const char *name); -#define getenv(X) SDL_getenv(X) - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* NEED_GETENV */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_joystick.h ./win32/SDL-1.2.2/include/SDL_joystick.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_joystick.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_joystick.h 1970-01-01 09:00:00 +0900 @@ -1,171 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_joystick.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL joystick event handling */ - -#ifndef _SDL_joystick_h -#define _SDL_joystick_h - -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* In order to use these functions, SDL_Init() must have been called - with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system - for joysticks, and load appropriate drivers. -*/ - -/* The joystick structure used to identify an SDL joystick */ -struct _SDL_Joystick; -typedef struct _SDL_Joystick SDL_Joystick; - - -/* Function prototypes */ -/* - * Count the number of joysticks attached to the system - */ -extern DECLSPEC int SDL_NumJoysticks(void); - -/* - * Get the implementation dependent name of a joystick. - * This can be called before any joysticks are opened. - * If no name can be found, this function returns NULL. - */ -extern DECLSPEC const char *SDL_JoystickName(int device_index); - -/* - * Open a joystick for use - the index passed as an argument refers to - * the N'th joystick on the system. This index is the value which will - * identify this joystick in future joystick events. - * - * This function returns a joystick identifier, or NULL if an error occurred. - */ -extern DECLSPEC SDL_Joystick *SDL_JoystickOpen(int device_index); - -/* - * Returns 1 if the joystick has been opened, or 0 if it has not. - */ -extern DECLSPEC int SDL_JoystickOpened(int device_index); - -/* - * Get the device index of an opened joystick. - */ -extern DECLSPEC int SDL_JoystickIndex(SDL_Joystick *joystick); - -/* - * Get the number of general axis controls on a joystick - */ -extern DECLSPEC int SDL_JoystickNumAxes(SDL_Joystick *joystick); - -/* - * Get the number of trackballs on a joystick - * Joystick trackballs have only relative motion events associated - * with them and their state cannot be polled. - */ -extern DECLSPEC int SDL_JoystickNumBalls(SDL_Joystick *joystick); - -/* - * Get the number of POV hats on a joystick - */ -extern DECLSPEC int SDL_JoystickNumHats(SDL_Joystick *joystick); - -/* - * Get the number of buttons on a joystick - */ -extern DECLSPEC int SDL_JoystickNumButtons(SDL_Joystick *joystick); - -/* - * Update the current state of the open joysticks. - * This is called automatically by the event loop if any joystick - * events are enabled. - */ -extern DECLSPEC void SDL_JoystickUpdate(void); - -/* - * Enable/disable joystick event polling. - * If joystick events are disabled, you must call SDL_JoystickUpdate() - * yourself and check the state of the joystick when you want joystick - * information. - * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE. - */ -extern DECLSPEC int SDL_JoystickEventState(int state); - -/* - * Get the current state of an axis control on a joystick - * The state is a value ranging from -32768 to 32767. - * The axis indices start at index 0. - */ -extern DECLSPEC Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis); - -/* - * Get the current state of a POV hat on a joystick - * The return value is one of the following positions: - */ -#define SDL_HAT_CENTERED 0x00 -#define SDL_HAT_UP 0x01 -#define SDL_HAT_RIGHT 0x02 -#define SDL_HAT_DOWN 0x04 -#define SDL_HAT_LEFT 0x08 -#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) -#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) -#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) -#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) -/* - * The hat indices start at index 0. - */ -extern DECLSPEC Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat); - -/* - * Get the ball axis change since the last poll - * This returns 0, or -1 if you passed it invalid parameters. - * The ball indices start at index 0. - */ -extern DECLSPEC int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); - -/* - * Get the current state of a button on a joystick - * The button indices start at index 0. - */ -extern DECLSPEC Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button); - -/* - * Close a joystick previously opened with SDL_JoystickOpen() - */ -extern DECLSPEC void SDL_JoystickClose(SDL_Joystick *joystick); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_joystick_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_keyboard.h ./win32/SDL-1.2.2/include/SDL_keyboard.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_keyboard.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_keyboard.h 1970-01-01 09:00:00 +0900 @@ -1,124 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_keyboard.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL keyboard event handling */ - -#ifndef _SDL_keyboard_h -#define _SDL_keyboard_h - -#include "SDL_types.h" -#include "SDL_keysym.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Keysym structure - - The scancode is hardware dependent, and should not be used by general - applications. If no hardware scancode is available, it will be 0. - - - The 'unicode' translated character is only available when character - translation is enabled by the SDL_EnableUNICODE() API. If non-zero, - this is a UNICODE character corresponding to the keypress. If the - high 9 bits of the character are 0, then this maps to the equivalent - ASCII character: - char ch; - if ( (keysym.unicode & 0xFF80) == 0 ) { - ch = keysym.unicode & 0x7F; - } else { - An international character.. - } - */ -typedef struct { - Uint8 scancode; /* hardware specific scancode */ - SDLKey sym; /* SDL virtual keysym */ - SDLMod mod; /* current key modifiers */ - Uint16 unicode; /* translated character */ -} SDL_keysym; - -/* This is the mask which refers to all hotkey bindings */ -#define SDL_ALL_HOTKEYS 0xFFFFFFFF - -/* Function prototypes */ -/* - * Enable/Disable UNICODE translation of keyboard input. - * This translation has some overhead, so translation defaults off. - * If 'enable' is 1, translation is enabled. - * If 'enable' is 0, translation is disabled. - * If 'enable' is -1, the translation state is not changed. - * It returns the previous state of keyboard translation. - */ -extern DECLSPEC int SDL_EnableUNICODE(int enable); - -/* - * Enable/Disable keyboard repeat. Keyboard repeat defaults to off. - * 'delay' is the initial delay in ms between the time when a key is - * pressed, and keyboard repeat begins. - * 'interval' is the time in ms between keyboard repeat events. - */ -#define SDL_DEFAULT_REPEAT_DELAY 500 -#define SDL_DEFAULT_REPEAT_INTERVAL 30 -/* - * If 'delay' is set to 0, keyboard repeat is disabled. - */ -extern DECLSPEC int SDL_EnableKeyRepeat(int delay, int interval); - -/* - * Get a snapshot of the current state of the keyboard. - * Returns an array of keystates, indexed by the SDLK_* syms. - * Used: - * Uint8 *keystate = SDL_GetKeyState(NULL); - * if ( keystate[SDLK_RETURN] ) ... is pressed. - */ -extern DECLSPEC Uint8 * SDL_GetKeyState(int *numkeys); - -/* - * Get the current key modifier state - */ -extern DECLSPEC SDLMod SDL_GetModState(void); - -/* - * Set the current key modifier state - * This does not change the keyboard state, only the key modifier flags. - */ -extern DECLSPEC void SDL_SetModState(SDLMod modstate); - -/* - * Get the name of an SDL virtual keysym - */ -extern DECLSPEC char * SDL_GetKeyName(SDLKey key); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_keyboard_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_keysym.h ./win32/SDL-1.2.2/include/SDL_keysym.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_keysym.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_keysym.h 1970-01-01 09:00:00 +0900 @@ -1,315 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_keysym.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -#ifndef _SDL_keysym_h -#define _SDL_keysym_h - -/* What we really want is a mapping of every raw key on the keyboard. - To support international keyboards, we use the range 0xA1 - 0xFF - as international virtual keycodes. We'll follow in the footsteps of X11... - The names of the keys - */ - -typedef enum { - /* The keyboard syms have been cleverly chosen to map to ASCII */ - SDLK_UNKNOWN = 0, - SDLK_FIRST = 0, - SDLK_BACKSPACE = 8, - SDLK_TAB = 9, - SDLK_CLEAR = 12, - SDLK_RETURN = 13, - SDLK_PAUSE = 19, - SDLK_ESCAPE = 27, - SDLK_SPACE = 32, - SDLK_EXCLAIM = 33, - SDLK_QUOTEDBL = 34, - SDLK_HASH = 35, - SDLK_DOLLAR = 36, - SDLK_AMPERSAND = 38, - SDLK_QUOTE = 39, - SDLK_LEFTPAREN = 40, - SDLK_RIGHTPAREN = 41, - SDLK_ASTERISK = 42, - SDLK_PLUS = 43, - SDLK_COMMA = 44, - SDLK_MINUS = 45, - SDLK_PERIOD = 46, - SDLK_SLASH = 47, - SDLK_0 = 48, - SDLK_1 = 49, - SDLK_2 = 50, - SDLK_3 = 51, - SDLK_4 = 52, - SDLK_5 = 53, - SDLK_6 = 54, - SDLK_7 = 55, - SDLK_8 = 56, - SDLK_9 = 57, - SDLK_COLON = 58, - SDLK_SEMICOLON = 59, - SDLK_LESS = 60, - SDLK_EQUALS = 61, - SDLK_GREATER = 62, - SDLK_QUESTION = 63, - SDLK_AT = 64, - /* - Skip uppercase letters - */ - SDLK_LEFTBRACKET = 91, - SDLK_BACKSLASH = 92, - SDLK_RIGHTBRACKET = 93, - SDLK_CARET = 94, - SDLK_UNDERSCORE = 95, - SDLK_BACKQUOTE = 96, - SDLK_a = 97, - SDLK_b = 98, - SDLK_c = 99, - SDLK_d = 100, - SDLK_e = 101, - SDLK_f = 102, - SDLK_g = 103, - SDLK_h = 104, - SDLK_i = 105, - SDLK_j = 106, - SDLK_k = 107, - SDLK_l = 108, - SDLK_m = 109, - SDLK_n = 110, - SDLK_o = 111, - SDLK_p = 112, - SDLK_q = 113, - SDLK_r = 114, - SDLK_s = 115, - SDLK_t = 116, - SDLK_u = 117, - SDLK_v = 118, - SDLK_w = 119, - SDLK_x = 120, - SDLK_y = 121, - SDLK_z = 122, - SDLK_DELETE = 127, - /* End of ASCII mapped keysyms */ - - /* International keyboard syms */ - SDLK_WORLD_0 = 160, /* 0xA0 */ - SDLK_WORLD_1 = 161, - SDLK_WORLD_2 = 162, - SDLK_WORLD_3 = 163, - SDLK_WORLD_4 = 164, - SDLK_WORLD_5 = 165, - SDLK_WORLD_6 = 166, - SDLK_WORLD_7 = 167, - SDLK_WORLD_8 = 168, - SDLK_WORLD_9 = 169, - SDLK_WORLD_10 = 170, - SDLK_WORLD_11 = 171, - SDLK_WORLD_12 = 172, - SDLK_WORLD_13 = 173, - SDLK_WORLD_14 = 174, - SDLK_WORLD_15 = 175, - SDLK_WORLD_16 = 176, - SDLK_WORLD_17 = 177, - SDLK_WORLD_18 = 178, - SDLK_WORLD_19 = 179, - SDLK_WORLD_20 = 180, - SDLK_WORLD_21 = 181, - SDLK_WORLD_22 = 182, - SDLK_WORLD_23 = 183, - SDLK_WORLD_24 = 184, - SDLK_WORLD_25 = 185, - SDLK_WORLD_26 = 186, - SDLK_WORLD_27 = 187, - SDLK_WORLD_28 = 188, - SDLK_WORLD_29 = 189, - SDLK_WORLD_30 = 190, - SDLK_WORLD_31 = 191, - SDLK_WORLD_32 = 192, - SDLK_WORLD_33 = 193, - SDLK_WORLD_34 = 194, - SDLK_WORLD_35 = 195, - SDLK_WORLD_36 = 196, - SDLK_WORLD_37 = 197, - SDLK_WORLD_38 = 198, - SDLK_WORLD_39 = 199, - SDLK_WORLD_40 = 200, - SDLK_WORLD_41 = 201, - SDLK_WORLD_42 = 202, - SDLK_WORLD_43 = 203, - SDLK_WORLD_44 = 204, - SDLK_WORLD_45 = 205, - SDLK_WORLD_46 = 206, - SDLK_WORLD_47 = 207, - SDLK_WORLD_48 = 208, - SDLK_WORLD_49 = 209, - SDLK_WORLD_50 = 210, - SDLK_WORLD_51 = 211, - SDLK_WORLD_52 = 212, - SDLK_WORLD_53 = 213, - SDLK_WORLD_54 = 214, - SDLK_WORLD_55 = 215, - SDLK_WORLD_56 = 216, - SDLK_WORLD_57 = 217, - SDLK_WORLD_58 = 218, - SDLK_WORLD_59 = 219, - SDLK_WORLD_60 = 220, - SDLK_WORLD_61 = 221, - SDLK_WORLD_62 = 222, - SDLK_WORLD_63 = 223, - SDLK_WORLD_64 = 224, - SDLK_WORLD_65 = 225, - SDLK_WORLD_66 = 226, - SDLK_WORLD_67 = 227, - SDLK_WORLD_68 = 228, - SDLK_WORLD_69 = 229, - SDLK_WORLD_70 = 230, - SDLK_WORLD_71 = 231, - SDLK_WORLD_72 = 232, - SDLK_WORLD_73 = 233, - SDLK_WORLD_74 = 234, - SDLK_WORLD_75 = 235, - SDLK_WORLD_76 = 236, - SDLK_WORLD_77 = 237, - SDLK_WORLD_78 = 238, - SDLK_WORLD_79 = 239, - SDLK_WORLD_80 = 240, - SDLK_WORLD_81 = 241, - SDLK_WORLD_82 = 242, - SDLK_WORLD_83 = 243, - SDLK_WORLD_84 = 244, - SDLK_WORLD_85 = 245, - SDLK_WORLD_86 = 246, - SDLK_WORLD_87 = 247, - SDLK_WORLD_88 = 248, - SDLK_WORLD_89 = 249, - SDLK_WORLD_90 = 250, - SDLK_WORLD_91 = 251, - SDLK_WORLD_92 = 252, - SDLK_WORLD_93 = 253, - SDLK_WORLD_94 = 254, - SDLK_WORLD_95 = 255, /* 0xFF */ - - /* Numeric keypad */ - SDLK_KP0 = 256, - SDLK_KP1 = 257, - SDLK_KP2 = 258, - SDLK_KP3 = 259, - SDLK_KP4 = 260, - SDLK_KP5 = 261, - SDLK_KP6 = 262, - SDLK_KP7 = 263, - SDLK_KP8 = 264, - SDLK_KP9 = 265, - SDLK_KP_PERIOD = 266, - SDLK_KP_DIVIDE = 267, - SDLK_KP_MULTIPLY = 268, - SDLK_KP_MINUS = 269, - SDLK_KP_PLUS = 270, - SDLK_KP_ENTER = 271, - SDLK_KP_EQUALS = 272, - - /* Arrows + Home/End pad */ - SDLK_UP = 273, - SDLK_DOWN = 274, - SDLK_RIGHT = 275, - SDLK_LEFT = 276, - SDLK_INSERT = 277, - SDLK_HOME = 278, - SDLK_END = 279, - SDLK_PAGEUP = 280, - SDLK_PAGEDOWN = 281, - - /* Function keys */ - SDLK_F1 = 282, - SDLK_F2 = 283, - SDLK_F3 = 284, - SDLK_F4 = 285, - SDLK_F5 = 286, - SDLK_F6 = 287, - SDLK_F7 = 288, - SDLK_F8 = 289, - SDLK_F9 = 290, - SDLK_F10 = 291, - SDLK_F11 = 292, - SDLK_F12 = 293, - SDLK_F13 = 294, - SDLK_F14 = 295, - SDLK_F15 = 296, - - /* Key state modifier keys */ - SDLK_NUMLOCK = 300, - SDLK_CAPSLOCK = 301, - SDLK_SCROLLOCK = 302, - SDLK_RSHIFT = 303, - SDLK_LSHIFT = 304, - SDLK_RCTRL = 305, - SDLK_LCTRL = 306, - SDLK_RALT = 307, - SDLK_LALT = 308, - SDLK_RMETA = 309, - SDLK_LMETA = 310, - SDLK_LSUPER = 311, /* Left "Windows" key */ - SDLK_RSUPER = 312, /* Right "Windows" key */ - SDLK_MODE = 313, /* "Alt Gr" key */ - SDLK_COMPOSE = 314, /* Multi-key compose key */ - - /* Miscellaneous function keys */ - SDLK_HELP = 315, - SDLK_PRINT = 316, - SDLK_SYSREQ = 317, - SDLK_BREAK = 318, - SDLK_MENU = 319, - SDLK_POWER = 320, /* Power Macintosh power key */ - SDLK_EURO = 321, /* Some european keyboards */ - - /* Add any other keys here */ - - SDLK_LAST -} SDLKey; - -/* Enumeration of valid key mods (possibly OR'd together) */ -typedef enum { - KMOD_NONE = 0x0000, - KMOD_LSHIFT= 0x0001, - KMOD_RSHIFT= 0x0002, - KMOD_LCTRL = 0x0040, - KMOD_RCTRL = 0x0080, - KMOD_LALT = 0x0100, - KMOD_RALT = 0x0200, - KMOD_LMETA = 0x0400, - KMOD_RMETA = 0x0800, - KMOD_NUM = 0x1000, - KMOD_CAPS = 0x2000, - KMOD_MODE = 0x4000, - KMOD_RESERVED = 0x8000 -} SDLMod; - -#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL) -#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT) -#define KMOD_ALT (KMOD_LALT|KMOD_RALT) -#define KMOD_META (KMOD_LMETA|KMOD_RMETA) - -#endif /* _SDL_keysym_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_main.h ./win32/SDL-1.2.2/include/SDL_main.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_main.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_main.h 1970-01-01 09:00:00 +0900 @@ -1,97 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_main.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -#ifndef _SDL_main_h -#define _SDL_main_h - -/* Redefine main() on Win32 and MacOS so that it is called by winmain.c */ - -#if defined(WIN32) || (defined(__MWERKS__) && !defined(__BEOS__)) || \ - defined(macintosh) || defined(__APPLE__) - -#ifdef __cplusplus -#define C_LINKAGE "C" -#else -#define C_LINKAGE -#endif /* __cplusplus */ - -/* The application's main() function must be called with C linkage, - and should be declared like this: -#ifdef __cplusplus -extern "C" -#endif - int main(int argc, char *argv[]) - { - } - */ -#define main SDL_main - -/* The prototype for the application's main() function */ -extern C_LINKAGE int SDL_main(int argc, char *argv[]); - - -/* From the SDL library code -- needed for registering the app on Win32 */ -#if defined(WIN32) -#include "SDL_types.h" -#include "begin_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* This should be called from your WinMain() function, if any */ -extern DECLSPEC int SDL_RegisterApp(char *name, Uint32 style, void *hInst); - -#ifdef __cplusplus -} -#endif -#include "close_code.h" -#endif - -/* From the SDL library code -- needed for registering QuickDraw on MacOS */ -#if defined(macintosh) -#include "begin_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Forward declaration so we don't need to include QuickDraw.h */ -struct QDGlobals; - -/* This should be called from your main() function, if any */ -extern DECLSPEC void SDL_InitQuickDraw(struct QDGlobals *the_qd); - -#ifdef __cplusplus -} -#endif -#include "close_code.h" -#endif - -#endif /* Need to redefine main()? */ - -#endif /* _SDL_main_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_mouse.h ./win32/SDL-1.2.2/include/SDL_mouse.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_mouse.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_mouse.h 1970-01-01 09:00:00 +0900 @@ -1,136 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_mouse.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL mouse event handling */ - -#ifndef _SDL_mouse_h -#define _SDL_mouse_h - -#include "SDL_types.h" -#include "SDL_video.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct WMcursor WMcursor; /* Implementation dependent */ -typedef struct { - SDL_Rect area; /* The area of the mouse cursor */ - Sint16 hot_x, hot_y; /* The "tip" of the cursor */ - Uint8 *data; /* B/W cursor data */ - Uint8 *mask; /* B/W cursor mask */ - Uint8 *save[2]; /* Place to save cursor area */ - WMcursor *wm_cursor; /* Window-manager cursor */ -} SDL_Cursor; - -/* Function prototypes */ -/* - * Retrieve the current state of the mouse. - * The current button state is returned as a button bitmask, which can - * be tested using the SDL_BUTTON(X) macros, and x and y are set to the - * current mouse cursor position. You can pass NULL for either x or y. - */ -extern DECLSPEC Uint8 SDL_GetMouseState(int *x, int *y); - -/* - * Retrieve the current state of the mouse. - * The current button state is returned as a button bitmask, which can - * be tested using the SDL_BUTTON(X) macros, and x and y are set to the - * mouse deltas since the last call to SDL_GetRelativeMouseState(). - */ -extern DECLSPEC Uint8 SDL_GetRelativeMouseState(int *x, int *y); - -/* - * Set the position of the mouse cursor (generates a mouse motion event) - */ -extern DECLSPEC void SDL_WarpMouse(Uint16 x, Uint16 y); - -/* - * Create a cursor using the specified data and mask (in MSB format). - * The cursor width must be a multiple of 8 bits. - * - * The cursor is created in black and white according to the following: - * data mask resulting pixel on screen - * 0 1 White - * 1 1 Black - * 0 0 Transparent - * 1 0 Inverted color if possible, black if not. - * - * Cursors created with this function must be freed with SDL_FreeCursor(). - */ -extern DECLSPEC SDL_Cursor *SDL_CreateCursor - (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); - -/* - * Set the currently active cursor to the specified one. - * If the cursor is currently visible, the change will be immediately - * represented on the display. - */ -extern DECLSPEC void SDL_SetCursor(SDL_Cursor *cursor); - -/* - * Returns the currently active cursor. - */ -extern DECLSPEC SDL_Cursor * SDL_GetCursor(void); - -/* - * Deallocates a cursor created with SDL_CreateCursor(). - */ -extern DECLSPEC void SDL_FreeCursor(SDL_Cursor *cursor); - -/* - * Toggle whether or not the cursor is shown on the screen. - * The cursor start off displayed, but can be turned off. - * SDL_ShowCursor() returns 1 if the cursor was being displayed - * before the call, or 0 if it was not. You can query the current - * state by passing a 'toggle' value of -1. - */ -extern DECLSPEC int SDL_ShowCursor(int toggle); - -/* Used as a mask when testing buttons in buttonstate - Button 1: Left mouse button - Button 2: Middle mouse button - Button 3: Right mouse button - */ -#define SDL_BUTTON(X) (SDL_PRESSED<<(X-1)) -#define SDL_BUTTON_LEFT 1 -#define SDL_BUTTON_MIDDLE 2 -#define SDL_BUTTON_RIGHT 3 -#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT) -#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE) -#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT) - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_mouse_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_mutex.h ./win32/SDL-1.2.2/include/SDL_mutex.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_mutex.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_mutex.h 1970-01-01 09:00:00 +0900 @@ -1,163 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_mutex.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -#ifndef _SDL_mutex_h -#define _SDL_mutex_h - -/* Functions to provide thread synchronization primitives - - These are independent of the other SDL routines. -*/ - -#include "SDL_main.h" -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Synchronization functions which can time out return this value - if they time out. -*/ -#define SDL_MUTEX_TIMEDOUT 1 - -/* This is the timeout value which corresponds to never time out */ -#define SDL_MUTEX_MAXWAIT (~(Uint32)0) - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Mutex functions */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* The SDL mutex structure, defined in SDL_mutex.c */ -struct SDL_mutex; -typedef struct SDL_mutex SDL_mutex; - -/* Create a mutex, initialized unlocked */ -extern DECLSPEC SDL_mutex * SDL_CreateMutex(void); - -/* Lock the mutex (Returns 0, or -1 on error) */ -#define SDL_LockMutex(m) SDL_mutexP(m) -extern DECLSPEC int SDL_mutexP(SDL_mutex *mutex); - -/* Unlock the mutex (Returns 0, or -1 on error) */ -#define SDL_UnlockMutex(m) SDL_mutexV(m) -extern DECLSPEC int SDL_mutexV(SDL_mutex *mutex); - -/* Destroy a mutex */ -extern DECLSPEC void SDL_DestroyMutex(SDL_mutex *mutex); - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Semaphore functions */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* The SDL semaphore structure, defined in SDL_sem.c */ -struct SDL_semaphore; -typedef struct SDL_semaphore SDL_sem; - -/* Create a semaphore, initialized with value, returns NULL on failure. */ -extern DECLSPEC SDL_sem * SDL_CreateSemaphore(Uint32 initial_value); - -/* Destroy a semaphore */ -extern DECLSPEC void SDL_DestroySemaphore(SDL_sem *sem); - -/* This function suspends the calling thread until the semaphore pointed - * to by sem has a positive count. It then atomically decreases the semaphore - * count. - */ -extern DECLSPEC int SDL_SemWait(SDL_sem *sem); - -/* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds, - SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error. -*/ -extern DECLSPEC int SDL_SemTryWait(SDL_sem *sem); - -/* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if - the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in - the allotted time, and -1 on error. - On some platforms this function is implemented by looping with a delay - of 1 ms, and so should be avoided if possible. -*/ -extern DECLSPEC int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms); - -/* Atomically increases the semaphore's count (not blocking), returns 0, - or -1 on error. - */ -extern DECLSPEC int SDL_SemPost(SDL_sem *sem); - -/* Returns the current count of the semaphore */ -extern DECLSPEC Uint32 SDL_SemValue(SDL_sem *sem); - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Condition variable functions */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* The SDL condition variable structure, defined in SDL_cond.c */ -struct SDL_cond; -typedef struct SDL_cond SDL_cond; - -/* Create a condition variable */ -extern DECLSPEC SDL_cond * SDL_CreateCond(void); - -/* Destroy a condition variable */ -extern DECLSPEC void SDL_DestroyCond(SDL_cond *cond); - -/* Restart one of the threads that are waiting on the condition variable, - returns 0 or -1 on error. - */ -extern DECLSPEC int SDL_CondSignal(SDL_cond *cond); - -/* Restart all threads that are waiting on the condition variable, - returns 0 or -1 on error. - */ -extern DECLSPEC int SDL_CondBroadcast(SDL_cond *cond); - -/* Wait on the condition variable, unlocking the provided mutex. - The mutex must be locked before entering this function! - Returns 0 when it is signaled, or -1 on error. - */ -extern DECLSPEC int SDL_CondWait(SDL_cond *cond, SDL_mutex *mut); - -/* Waits for at most 'ms' milliseconds, and returns 0 if the condition - variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not - signaled in the allotted time, and -1 on error. - On some platforms this function is implemented by looping with a delay - of 1 ms, and so should be avoided if possible. -*/ -extern DECLSPEC int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_mutex_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_quit.h ./win32/SDL-1.2.2/include/SDL_quit.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_quit.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_quit.h 1970-01-01 09:00:00 +0900 @@ -1,52 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_quit.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL quit event handling */ - -#ifndef _SDL_quit_h -#define _SDL_quit_h - -/* - An SDL_QUITEVENT is generated when the user tries to close the application - window. If it is ignored or filtered out, the window will remain open. - If it is not ignored or filtered, it is queued normally and the window - is allowed to close. When the window is closed, screen updates will - complete, but have no effect. - - SDL_Init() installs signal handlers for SIGINT (keyboard interrupt) - and SIGTERM (system termination request), if handlers do not already - exist, that generate SDL_QUITEVENT events as well. There is no way - to determine the cause of an SDL_QUITEVENT, but setting a signal - handler in your application will override the default generation of - quit events for that signal. -*/ - -/* There are no functions directly affecting the quit event */ -#define SDL_QuitRequested() \ - (SDL_PumpEvents(), SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUITMASK)) - -#endif /* _SDL_quit_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_rwops.h ./win32/SDL-1.2.2/include/SDL_rwops.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_rwops.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_rwops.h 1970-01-01 09:00:00 +0900 @@ -1,113 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_rwops.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* This file provides a general interface for SDL to read and write - data sources. It can easily be extended to files, memory, etc. -*/ - -#ifndef _SDL_RWops_h -#define _SDL_RWops_h - -#include - -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* This is the read/write operation structure -- very basic */ - -typedef struct SDL_RWops { - /* Seek to 'offset' relative to whence, one of stdio's whence values: - SEEK_SET, SEEK_CUR, SEEK_END - Returns the final offset in the data source. - */ - int (*seek)(struct SDL_RWops *context, int offset, int whence); - - /* Read up to 'num' objects each of size 'objsize' from the data - source to the area pointed at by 'ptr'. - Returns the number of objects read, or -1 if the read failed. - */ - int (*read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); - - /* Write exactly 'num' objects each of size 'objsize' from the area - pointed at by 'ptr' to data source. - Returns 'num', or -1 if the write failed. - */ - int (*write)(struct SDL_RWops *context, const void *ptr, int size, int num); - - /* Close and free an allocated SDL_FSops structure */ - int (*close)(struct SDL_RWops *context); - - Uint32 type; - union { - struct { - int autoclose; - FILE *fp; - } stdio; - struct { - Uint8 *base; - Uint8 *here; - Uint8 *stop; - } mem; - struct { - void *data1; - } unknown; - } hidden; - -} SDL_RWops; - - -/* Functions to create SDL_RWops structures from various data sources */ - -extern DECLSPEC SDL_RWops * SDL_RWFromFile(const char *file, const char *mode); - -extern DECLSPEC SDL_RWops * SDL_RWFromFP(FILE *fp, int autoclose); - -extern DECLSPEC SDL_RWops * SDL_RWFromMem(void *mem, int size); - -extern DECLSPEC SDL_RWops * SDL_AllocRW(void); -extern DECLSPEC void SDL_FreeRW(SDL_RWops *area); - -/* Macros to easily read and write from an SDL_RWops structure */ -#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence) -#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, SEEK_CUR) -#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n) -#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n) -#define SDL_RWclose(ctx) (ctx)->close(ctx) - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_RWops_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_syswm.h ./win32/SDL-1.2.2/include/SDL_syswm.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_syswm.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_syswm.h 1970-01-01 09:00:00 +0900 @@ -1,165 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_syswm.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Include file for SDL custom system window manager hooks */ - -#ifndef _SDL_syswm_h -#define _SDL_syswm_h - -#include "SDL_version.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Your application has access to a special type of event 'SDL_SYSWMEVENT', - which contains window-manager specific information and arrives whenever - an unhandled window event occurs. This event is ignored by default, but - you can enable it with SDL_EventState() -*/ -#ifdef SDL_PROTOTYPES_ONLY -struct SDL_SysWMinfo; -typedef struct SDL_SysWMinfo SDL_SysWMinfo; -#else - -/* This is the structure for custom window manager events */ -#if (defined(unix) || defined(__unix__) || defined(_AIX) || defined(__OpenBSD__)) && \ - (!defined(DISABLE_X11) && !defined(__CYGWIN32__)) - /* AIX is unix, of course, but the native compiler CSet doesn't define unix */ -#include -#include - -/* These are the various supported subsystems under UNIX */ -typedef enum { - SDL_SYSWM_X11 -} SDL_SYSWM_TYPE; - -/* The UNIX custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - SDL_SYSWM_TYPE subsystem; - union { - XEvent xevent; - } event; -}; - -/* The UNIX custom window manager information structure. - When this structure is returned, it holds information about which - low level system it is using, and will be one of SDL_SYSWM_TYPE. - */ -typedef struct { - SDL_version version; - SDL_SYSWM_TYPE subsystem; - union { - struct { - Display *display; /* The X11 display */ - Window window; /* The X11 display window */ - /* These locking functions should be called around - any X11 functions using the display variable. - They lock the event thread, so should not be - called around event functions or from event filters. - */ - void (*lock_func)(void); - void (*unlock_func)(void); - - /* Introduced in SDL 1.0.2 */ - Window fswindow; /* The X11 fullscreen window */ - Window wmwindow; /* The X11 managed input window */ - } x11; - } info; -} SDL_SysWMinfo; - -#elif defined(ENABLE_NANOX) -#include - -/* The generic custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int data; -}; - -/* The windows custom window manager information structure */ -typedef struct { - SDL_version version ; - GR_WINDOW_ID window ; /* The display window */ -} SDL_SysWMinfo; - -#elif defined(WIN32) -#include - -/* The windows custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - HWND hwnd; /* The window for the message */ - UINT msg; /* The type of message */ - WPARAM wParam; /* WORD message parameter */ - LPARAM lParam; /* LONG message parameter */ -}; - -/* The windows custom window manager information structure */ -typedef struct { - SDL_version version; - HWND window; /* The Win32 display window */ -} SDL_SysWMinfo; - -#else - -/* The generic custom event structure */ -struct SDL_SysWMmsg { - SDL_version version; - int data; -}; - -/* The generic custom window manager information structure */ -typedef struct { - SDL_version version; - int data; -} SDL_SysWMinfo; - -#endif /* OS type */ - -#endif /* SDL_PROTOTYPES_ONLY */ - -/* Function prototypes */ -/* - * This function gives you custom hooks into the window manager information. - * It fills the structure pointed to by 'info' with custom information and - * returns 1 if the function is implemented. If it's not implemented, or - * the version member of the 'info' structure is invalid, it returns 0. - */ -extern DECLSPEC int SDL_GetWMInfo(SDL_SysWMinfo *info); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_syswm_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_thread.h ./win32/SDL-1.2.2/include/SDL_thread.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_thread.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_thread.h 1970-01-01 09:00:00 +0900 @@ -1,79 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_thread.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -#ifndef _SDL_thread_h -#define _SDL_thread_h - -/* Header for the SDL thread management routines - - These are independent of the other SDL routines. -*/ - -#include "SDL_main.h" -#include "SDL_types.h" - -/* Thread synchronization primitives */ -#include "SDL_mutex.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* The SDL thread structure, defined in SDL_thread.c */ -struct SDL_Thread; -typedef struct SDL_Thread SDL_Thread; - -/* Create a thread */ -extern DECLSPEC SDL_Thread * SDL_CreateThread(int (*fn)(void *), void *data); - -/* Get the 32-bit thread identifier for the current thread */ -extern DECLSPEC Uint32 SDL_ThreadID(void); - -/* Get the 32-bit thread identifier for the specified thread, - equivalent to SDL_ThreadID() if the specified thread is NULL. - */ -extern DECLSPEC Uint32 SDL_GetThreadID(SDL_Thread *thread); - -/* Wait for a thread to finish. - The return code for the thread function is placed in the area - pointed to by 'status', if 'status' is not NULL. - */ -extern DECLSPEC void SDL_WaitThread(SDL_Thread *thread, int *status); - -/* Forcefully kill a thread without worrying about its state */ -extern DECLSPEC void SDL_KillThread(SDL_Thread *thread); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_thread_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_timer.h ./win32/SDL-1.2.2/include/SDL_timer.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_timer.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_timer.h 1970-01-01 09:00:00 +0900 @@ -1,118 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_timer.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -#ifndef _SDL_timer_h -#define _SDL_timer_h - -/* Header for the SDL time management routines */ - -#include "SDL_main.h" -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* This is the OS scheduler timeslice, in milliseconds */ -#define SDL_TIMESLICE 10 - -/* This is the maximum resolution of the SDL timer on all platforms */ -#define TIMER_RESOLUTION 10 /* Experimentally determined */ - -/* Get the number of milliseconds since the SDL library initialization. - * Note that this value wraps if the program runs for more than ~49 days. - */ -extern DECLSPEC Uint32 SDL_GetTicks(void); - -/* Wait a specified number of milliseconds before returning */ -extern DECLSPEC void SDL_Delay(Uint32 ms); - -/* Function prototype for the timer callback function */ -typedef Uint32 (*SDL_TimerCallback)(Uint32 interval); - -/* Set a callback to run after the specified number of milliseconds has - * elapsed. The callback function is passed the current timer interval - * and returns the next timer interval. If the returned value is the - * same as the one passed in, the periodic alarm continues, otherwise a - * new alarm is scheduled. If the callback returns 0, the periodic alarm - * is cancelled. - * - * To cancel a currently running timer, call SDL_SetTimer(0, NULL); - * - * The timer callback function may run in a different thread than your - * main code, and so shouldn't call any functions from within itself. - * - * The maximum resolution of this timer is 10 ms, which means that if - * you request a 16 ms timer, your callback will run approximately 20 ms - * later on an unloaded system. If you wanted to set a flag signaling - * a frame update at 30 frames per second (every 33 ms), you might set a - * timer for 30 ms: - * SDL_SetTimer((33/10)*10, flag_update); - * - * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init(). - * - * Under UNIX, you should not use raise or use SIGALRM and this function - * in the same program, as it is implemented using setitimer(). You also - * should not use this function in multi-threaded applications as signals - * to multi-threaded apps have undefined behavior in some implementations. - */ -extern DECLSPEC int SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback); - -/* New timer API, supports multiple timers - * Written by Stephane Peter - */ - -/* Function prototype for the new timer callback function. - * The callback function is passed the current timer interval and returns - * the next timer interval. If the returned value is the same as the one - * passed in, the periodic alarm continues, otherwise a new alarm is - * scheduled. If the callback returns 0, the periodic alarm is cancelled. - */ -typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param); - -/* Definition of the timer ID type */ -typedef struct _SDL_TimerID *SDL_TimerID; - -/* Add a new timer to the pool of timers already running. - Returns a timer ID, or NULL when an error occurs. - */ -extern DECLSPEC SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); - -/* Remove one of the multiple timers knowing its ID. - * Returns a boolean value indicating success. - */ -extern DECLSPEC SDL_bool SDL_RemoveTimer(SDL_TimerID t); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_timer_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_types.h ./win32/SDL-1.2.2/include/SDL_types.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_types.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_types.h 1970-01-01 09:00:00 +0900 @@ -1,87 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_types.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* General data types used by the SDL library */ - -#ifndef _SDL_types_h -#define _SDL_types_h - -/* The number of elements in a table */ -#define SDL_TABLESIZE(table) (sizeof(table)/sizeof(table[0])) - -/* Basic data types */ -typedef enum { - SDL_FALSE = 0, - SDL_TRUE = 1 -} SDL_bool; -typedef unsigned char Uint8; -typedef signed char Sint8; -typedef unsigned short Uint16; -typedef signed short Sint16; -typedef unsigned int Uint32; -typedef signed int Sint32; - -/* Figure out how to support 64-bit datatypes */ -#if !defined(__STRICT_ANSI__) -#if defined(__GNUC__) || defined(__MWERKS__) /* MJS */ -#define SDL_HAS_64BIT_TYPE long long -#elif defined(_MSC_VER) /* VC++ */ -#define SDL_HAS_64BIT_TYPE __int64 -#endif -#endif /* !__STRICT_ANSI__ */ - -/* The 64-bit datatype isn't supported on all platforms */ -#ifdef SDL_HAS_64BIT_TYPE -typedef unsigned SDL_HAS_64BIT_TYPE Uint64; -typedef SDL_HAS_64BIT_TYPE Sint64; -#else -/* This is really just a hack to prevent the compiler from complaining */ -typedef struct { - Uint32 hi; - Uint32 lo; -} Uint64, Sint64; -#endif - -/* Make sure the types really have the right sizes */ -#define SDL_COMPILE_TIME_ASSERT(name, x) \ - typedef int SDL_dummy_ ## name[(x) * 2 - 1] - -SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); -SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); -SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); -SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); -SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); -SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); -SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); -SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); - -#undef SDL_COMPILE_TIME_ASSERT - -/* General keyboard/mouse state definitions */ -enum { SDL_PRESSED = 0x01, SDL_RELEASED = 0x00 }; - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_version.h ./win32/SDL-1.2.2/include/SDL_version.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_version.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_version.h 1970-01-01 09:00:00 +0900 @@ -1,90 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_version.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* This header defines the current SDL version */ - -#ifndef _SDL_version_h -#define _SDL_version_h - -#include "SDL_types.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL -*/ -#define SDL_MAJOR_VERSION 1 -#define SDL_MINOR_VERSION 2 -#define SDL_PATCHLEVEL 2 - -typedef struct { - Uint8 major; - Uint8 minor; - Uint8 patch; -} SDL_version; - -/* This macro can be used to fill a version structure with the compile-time - * version of the SDL library. - */ -#define SDL_VERSION(X) \ -{ \ - (X)->major = SDL_MAJOR_VERSION; \ - (X)->minor = SDL_MINOR_VERSION; \ - (X)->patch = SDL_PATCHLEVEL; \ -} - -/* This macro turns the version numbers into a numeric value: - (1,2,3) -> (1203) - This assumes that there will never be more than 100 patchlevels -*/ -#define SDL_VERSIONNUM(X, Y, Z) \ - (X)*1000 + (Y)*100 + (Z) - -/* This is the version number macro for the current SDL version */ -#define SDL_COMPILEDVERSION \ - SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) - -/* This macro will evaluate to true if compiled with SDL at least X.Y.Z */ -#define SDL_VERSION_ATLEAST(X, Y, Z) \ - (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) - -/* This function gets the version of the dynamically linked SDL library. - it should NOT be used to fill a version structure, instead you should - use the SDL_Version() macro. - */ -extern DECLSPEC const SDL_version * SDL_Linked_Version(void); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_version_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_video.h ./win32/SDL-1.2.2/include/SDL_video.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/SDL_video.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/SDL_video.h 1970-01-01 09:00:00 +0900 @@ -1,891 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) SDL_video.h,v 1.1 2002/10/20 13:03:12 forgotten Exp"; -#endif - -/* Header file for access to the SDL raw framebuffer window */ - -#ifndef _SDL_video_h -#define _SDL_video_h - -#include - -#include "SDL_types.h" -#include "SDL_mutex.h" -#include "SDL_rwops.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Transparency definitions: These define alpha as the opacity of a surface */ -#define SDL_ALPHA_OPAQUE 255 -#define SDL_ALPHA_TRANSPARENT 0 - -/* Useful data types */ -typedef struct { - Sint16 x, y; - Uint16 w, h; -} SDL_Rect; - -typedef struct { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 unused; -} SDL_Color; - -typedef struct { - int ncolors; - SDL_Color *colors; -} SDL_Palette; - -/* Everything in the pixel format structure is read-only */ -typedef struct SDL_PixelFormat { - SDL_Palette *palette; - Uint8 BitsPerPixel; - Uint8 BytesPerPixel; - Uint8 Rloss; - Uint8 Gloss; - Uint8 Bloss; - Uint8 Aloss; - Uint8 Rshift; - Uint8 Gshift; - Uint8 Bshift; - Uint8 Ashift; - Uint32 Rmask; - Uint32 Gmask; - Uint32 Bmask; - Uint32 Amask; - - /* RGB color key information */ - Uint32 colorkey; - /* Alpha value information (per-surface alpha) */ - Uint8 alpha; -} SDL_PixelFormat; - -/* typedef for private surface blitting functions */ -struct SDL_Surface; -typedef int (*SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect, - struct SDL_Surface *dst, SDL_Rect *dstrect); - -/* This structure should be treated as read-only, except for 'pixels', - which, if not NULL, contains the raw pixel data for the surface. -*/ -typedef struct SDL_Surface { - Uint32 flags; /* Read-only */ - SDL_PixelFormat *format; /* Read-only */ - int w, h; /* Read-only */ - Uint16 pitch; /* Read-only */ - void *pixels; /* Read-write */ - int offset; /* Private */ - - /* Hardware-specific surface info */ - struct private_hwdata *hwdata; - - /* clipping information */ - SDL_Rect clip_rect; /* Read-only */ - Uint32 unused1; /* for binary compatibility */ - - /* Allow recursive locks */ - Uint32 locked; /* Private */ - - /* info for fast blit mapping to other surfaces */ - struct SDL_BlitMap *map; /* Private */ - - /* format version, bumped at every change to invalidate blit maps */ - unsigned int format_version; /* Private */ - - /* Reference count -- used when freeing surface */ - int refcount; /* Read-mostly */ -} SDL_Surface; - -/* These are the currently supported flags for the SDL_surface */ -/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */ -#define SDL_SWSURFACE 0x00000000 /* Surface is in system memory */ -#define SDL_HWSURFACE 0x00000001 /* Surface is in video memory */ -#define SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */ -/* Available for SDL_SetVideoMode() */ -#define SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */ -#define SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */ -#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */ -#define SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */ -#define SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */ -#define SDL_OPENGLBLIT 0x0000000A /* Create an OpenGL rendering context and use it for blitting */ -#define SDL_RESIZABLE 0x00000010 /* This video mode may be resized */ -#define SDL_NOFRAME 0x00000020 /* No window caption or edge frame */ -/* Used internally (read-only) */ -#define SDL_HWACCEL 0x00000100 /* Blit uses hardware acceleration */ -#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */ -#define SDL_RLEACCELOK 0x00002000 /* Private flag */ -#define SDL_RLEACCEL 0x00004000 /* Surface is RLE encoded */ -#define SDL_SRCALPHA 0x00010000 /* Blit uses source alpha blending */ -#define SDL_PREALLOC 0x01000000 /* Surface uses preallocated memory */ - -/* Evaluates to true if the surface needs to be locked before access */ -#define SDL_MUSTLOCK(surface) \ - (surface->offset || \ - ((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0)) - - -/* Useful for determining the video hardware capabilities */ -typedef struct { - Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */ - Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */ - Uint32 UnusedBits1 :6; - Uint32 UnusedBits2 :1; - Uint32 blit_hw :1; /* Flag: Accelerated blits HW --> HW */ - Uint32 blit_hw_CC :1; /* Flag: Accelerated blits with Colorkey */ - Uint32 blit_hw_A :1; /* Flag: Accelerated blits with Alpha */ - Uint32 blit_sw :1; /* Flag: Accelerated blits SW --> HW */ - Uint32 blit_sw_CC :1; /* Flag: Accelerated blits with Colorkey */ - Uint32 blit_sw_A :1; /* Flag: Accelerated blits with Alpha */ - Uint32 blit_fill :1; /* Flag: Accelerated color fill */ - Uint32 UnusedBits3 :16; - Uint32 video_mem; /* The total amount of video memory (in K) */ - SDL_PixelFormat *vfmt; /* Value: The format of the video surface */ -} SDL_VideoInfo; - - -/* The most common video overlay formats. - For an explanation of these pixel formats, see: - http://www.webartz.com/fourcc/indexyuv.htm - - For information on the relationship between color spaces, see: - http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html - */ -#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ -#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ -#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ -#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ -#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ - -/* The YUV hardware video overlay */ -typedef struct SDL_Overlay { - Uint32 format; /* Read-only */ - int w, h; /* Read-only */ - int planes; /* Read-only */ - Uint16 *pitches; /* Read-only */ - Uint8 **pixels; /* Read-write */ - - /* Hardware-specific surface info */ - struct private_yuvhwfuncs *hwfuncs; - struct private_yuvhwdata *hwdata; - - /* Special flags */ - Uint32 hw_overlay :1; /* Flag: This overlay hardware accelerated? */ - Uint32 UnusedBits :31; -} SDL_Overlay; - - -/* Public enumeration for setting the OpenGL window attributes. */ -typedef enum { - SDL_GL_RED_SIZE, - SDL_GL_GREEN_SIZE, - SDL_GL_BLUE_SIZE, - SDL_GL_ALPHA_SIZE, - SDL_GL_BUFFER_SIZE, - SDL_GL_DOUBLEBUFFER, - SDL_GL_DEPTH_SIZE, - SDL_GL_STENCIL_SIZE, - SDL_GL_ACCUM_RED_SIZE, - SDL_GL_ACCUM_GREEN_SIZE, - SDL_GL_ACCUM_BLUE_SIZE, - SDL_GL_ACCUM_ALPHA_SIZE -} SDL_GLattr; - -/* flags for SDL_SetPalette() */ -#define SDL_LOGPAL 0x01 -#define SDL_PHYSPAL 0x02 - -/* Function prototypes */ - -/* These functions are used internally, and should not be used unless you - * have a specific need to specify the video driver you want to use. - * You should normally use SDL_Init() or SDL_InitSubSystem(). - * - * SDL_VideoInit() initializes the video subsystem -- sets up a connection - * to the window manager, etc, and determines the current video mode and - * pixel format, but does not initialize a window or graphics mode. - * Note that event handling is activated by this routine. - * - * If you use both sound and video in your application, you need to call - * SDL_Init() before opening the sound device, otherwise under Win32 DirectX, - * you won't be able to set full-screen display modes. - */ -extern DECLSPEC int SDL_VideoInit(const char *driver_name, Uint32 flags); -extern DECLSPEC void SDL_VideoQuit(void); - -/* This function fills the given character buffer with the name of the - * video driver, and returns a pointer to it if the video driver has - * been initialized. It returns NULL if no driver has been initialized. - */ -extern DECLSPEC char *SDL_VideoDriverName(char *namebuf, int maxlen); - -/* - * This function returns a pointer to the current display surface. - * If SDL is doing format conversion on the display surface, this - * function returns the publicly visible surface, not the real video - * surface. - */ -extern DECLSPEC SDL_Surface * SDL_GetVideoSurface(void); - -/* - * This function returns a read-only pointer to information about the - * video hardware. If this is called before SDL_SetVideoMode(), the 'vfmt' - * member of the returned structure will contain the pixel format of the - * "best" video mode. - */ -extern DECLSPEC const SDL_VideoInfo * SDL_GetVideoInfo(void); - -/* - * Check to see if a particular video mode is supported. - * It returns 0 if the requested mode is not supported under any bit depth, - * or returns the bits-per-pixel of the closest available mode with the - * given width and height. If this bits-per-pixel is different from the - * one used when setting the video mode, SDL_SetVideoMode() will succeed, - * but will emulate the requested bits-per-pixel with a shadow surface. - * - * The arguments to SDL_VideoModeOK() are the same ones you would pass to - * SDL_SetVideoMode() - */ -extern DECLSPEC int SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags); - -/* - * Return a pointer to an array of available screen dimensions for the - * given format and video flags, sorted largest to smallest. Returns - * NULL if there are no dimensions available for a particular format, - * or (SDL_Rect **)-1 if any dimension is okay for the given format. - * - * If 'format' is NULL, the mode list will be for the format given - * by SDL_GetVideoInfo()->vfmt - */ -extern DECLSPEC SDL_Rect ** SDL_ListModes(SDL_PixelFormat *format, Uint32 flags); - -/* - * Set up a video mode with the specified width, height and bits-per-pixel. - * - * If 'bpp' is 0, it is treated as the current display bits per pixel. - * - * If SDL_ANYFORMAT is set in 'flags', the SDL library will try to set the - * requested bits-per-pixel, but will return whatever video pixel format is - * available. The default is to emulate the requested pixel format if it - * is not natively available. - * - * If SDL_HWSURFACE is set in 'flags', the video surface will be placed in - * video memory, if possible, and you may have to call SDL_LockSurface() - * in order to access the raw framebuffer. Otherwise, the video surface - * will be created in system memory. - * - * If SDL_ASYNCBLIT is set in 'flags', SDL will try to perform rectangle - * updates asynchronously, but you must always lock before accessing pixels. - * SDL will wait for updates to complete before returning from the lock. - * - * If SDL_HWPALETTE is set in 'flags', the SDL library will guarantee - * that the colors set by SDL_SetColors() will be the colors you get. - * Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all - * of the colors exactly the way they are requested, and you should look - * at the video surface structure to determine the actual palette. - * If SDL cannot guarantee that the colors you request can be set, - * i.e. if the colormap is shared, then the video surface may be created - * under emulation in system memory, overriding the SDL_HWSURFACE flag. - * - * If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set - * a fullscreen video mode. The default is to create a windowed mode - * if the current graphics system has a window manager. - * If the SDL library is able to set a fullscreen video mode, this flag - * will be set in the surface that is returned. - * - * If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up - * two surfaces in video memory and swap between them when you call - * SDL_Flip(). This is usually slower than the normal single-buffering - * scheme, but prevents "tearing" artifacts caused by modifying video - * memory while the monitor is refreshing. It should only be used by - * applications that redraw the entire screen on every update. - * - * If SDL_RESIZABLE is set in 'flags', the SDL library will allow the - * window manager, if any, to resize the window at runtime. When this - * occurs, SDL will send a SDL_VIDEORESIZE event to you application, - * and you must respond to the event by re-calling SDL_SetVideoMode() - * with the requested size (or another size that suits the application). - * - * If SDL_NOFRAME is set in 'flags', the SDL library will create a window - * without any title bar or frame decoration. Fullscreen video modes have - * this flag set automatically. - * - * This function returns the video framebuffer surface, or NULL if it fails. - * - * If you rely on functionality provided by certain video flags, check the - * flags of the returned surface to make sure that functionality is available. - * SDL will fall back to reduced functionality if the exact flags you wanted - * are not available. - */ -extern DECLSPEC SDL_Surface *SDL_SetVideoMode - (int width, int height, int bpp, Uint32 flags); - -/* - * Makes sure the given list of rectangles is updated on the given screen. - * If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire - * screen. - * These functions should not be called while 'screen' is locked. - */ -extern DECLSPEC void SDL_UpdateRects - (SDL_Surface *screen, int numrects, SDL_Rect *rects); -extern DECLSPEC void SDL_UpdateRect - (SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h); - -/* - * On hardware that supports double-buffering, this function sets up a flip - * and returns. The hardware will wait for vertical retrace, and then swap - * video buffers before the next video surface blit or lock will return. - * On hardware that doesn not support double-buffering, this is equivalent - * to calling SDL_UpdateRect(screen, 0, 0, 0, 0); - * The SDL_DOUBLEBUF flag must have been passed to SDL_SetVideoMode() when - * setting the video mode for this function to perform hardware flipping. - * This function returns 0 if successful, or -1 if there was an error. - */ -extern DECLSPEC int SDL_Flip(SDL_Surface *screen); - -/* - * Set the gamma correction for each of the color channels. - * The gamma values range (approximately) between 0.1 and 10.0 - * - * If this function isn't supported directly by the hardware, it will - * be emulated using gamma ramps, if available. If successful, this - * function returns 0, otherwise it returns -1. - */ -extern DECLSPEC int SDL_SetGamma(float red, float green, float blue); - -/* - * Set the gamma translation table for the red, green, and blue channels - * of the video hardware. Each table is an array of 256 16-bit quantities, - * representing a mapping between the input and output for that channel. - * The input is the index into the array, and the output is the 16-bit - * gamma value at that index, scaled to the output color precision. - * - * You may pass NULL for any of the channels to leave it unchanged. - * If the call succeeds, it will return 0. If the display driver or - * hardware does not support gamma translation, or otherwise fails, - * this function will return -1. - */ -extern DECLSPEC int SDL_SetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue); - -/* - * Retrieve the current values of the gamma translation tables. - * - * You must pass in valid pointers to arrays of 256 16-bit quantities. - * Any of the pointers may be NULL to ignore that channel. - * If the call succeeds, it will return 0. If the display driver or - * hardware does not support gamma translation, or otherwise fails, - * this function will return -1. - */ -extern DECLSPEC int SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue); - -/* - * Sets a portion of the colormap for the given 8-bit surface. If 'surface' - * is not a palettized surface, this function does nothing, returning 0. - * If all of the colors were set as passed to SDL_SetColors(), it will - * return 1. If not all the color entries were set exactly as given, - * it will return 0, and you should look at the surface palette to - * determine the actual color palette. - * - * When 'surface' is the surface associated with the current display, the - * display colormap will be updated with the requested colors. If - * SDL_HWPALETTE was set in SDL_SetVideoMode() flags, SDL_SetColors() - * will always return 1, and the palette is guaranteed to be set the way - * you desire, even if the window colormap has to be warped or run under - * emulation. - */ -extern DECLSPEC int SDL_SetColors(SDL_Surface *surface, - SDL_Color *colors, int firstcolor, int ncolors); - -/* - * Sets a portion of the colormap for a given 8-bit surface. - * 'flags' is one or both of: - * SDL_LOGPAL -- set logical palette, which controls how blits are mapped - * to/from the surface, - * SDL_PHYSPAL -- set physical palette, which controls how pixels look on - * the screen - * Only screens have physical palettes. Separate change of physical/logical - * palettes is only possible if the screen has SDL_HWPALETTE set. - * - * The return value is 1 if all colours could be set as requested, and 0 - * otherwise. - * - * SDL_SetColors() is equivalent to calling this function with - * flags = (SDL_LOGPAL|SDL_PHYSPAL). - */ -extern DECLSPEC int SDL_SetPalette(SDL_Surface *surface, int flags, - SDL_Color *colors, int firstcolor, - int ncolors); - -/* - * Maps an RGB triple to an opaque pixel value for a given pixel format - */ -extern DECLSPEC Uint32 SDL_MapRGB - (SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b); - -/* - * Maps an RGBA quadruple to a pixel value for a given pixel format - */ -extern DECLSPEC Uint32 SDL_MapRGBA(SDL_PixelFormat *format, - Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* - * Maps a pixel value into the RGB components for a given pixel format - */ -extern DECLSPEC void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, - Uint8 *r, Uint8 *g, Uint8 *b); - -/* - * Maps a pixel value into the RGBA components for a given pixel format - */ -extern DECLSPEC void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, - Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); - -/* - * Allocate and free an RGB surface (must be called after SDL_SetVideoMode) - * If the depth is 4 or 8 bits, an empty palette is allocated for the surface. - * If the depth is greater than 8 bits, the pixel format is set using the - * flags '[RGB]mask'. - * If the function runs out of memory, it will return NULL. - * - * The 'flags' tell what kind of surface to create. - * SDL_SWSURFACE means that the surface should be created in system memory. - * SDL_HWSURFACE means that the surface should be created in video memory, - * with the same format as the display surface. This is useful for surfaces - * that will not change much, to take advantage of hardware acceleration - * when being blitted to the display surface. - * SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with - * this surface, but you must always lock it before accessing the pixels. - * SDL will wait for current blits to finish before returning from the lock. - * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits. - * If the hardware supports acceleration of colorkey blits between - * two surfaces in video memory, SDL will try to place the surface in - * video memory. If this isn't possible or if there is no hardware - * acceleration available, the surface will be placed in system memory. - * SDL_SRCALPHA means that the surface will be used for alpha blits and - * if the hardware supports hardware acceleration of alpha blits between - * two surfaces in video memory, to place the surface in video memory - * if possible, otherwise it will be placed in system memory. - * If the surface is created in video memory, blits will be _much_ faster, - * but the surface format must be identical to the video surface format, - * and the only way to access the pixels member of the surface is to use - * the SDL_LockSurface() and SDL_UnlockSurface() calls. - * If the requested surface actually resides in video memory, SDL_HWSURFACE - * will be set in the flags member of the returned surface. If for some - * reason the surface could not be placed in video memory, it will not have - * the SDL_HWSURFACE flag set, and will be created in system memory instead. - */ -#define SDL_AllocSurface SDL_CreateRGBSurface -extern DECLSPEC SDL_Surface *SDL_CreateRGBSurface - (Uint32 flags, int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern DECLSPEC SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, - int width, int height, int depth, int pitch, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); -extern DECLSPEC void SDL_FreeSurface(SDL_Surface *surface); - -/* - * SDL_LockSurface() sets up a surface for directly accessing the pixels. - * Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write - * to and read from 'surface->pixels', using the pixel format stored in - * 'surface->format'. Once you are done accessing the surface, you should - * use SDL_UnlockSurface() to release it. - * - * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates - * to 0, then you can read and write to the surface at any time, and the - * pixel format of the surface will not change. In particular, if the - * SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you - * will not need to lock the display surface before accessing it. - * - * No operating system or library calls should be made between lock/unlock - * pairs, as critical system locks may be held during this time. - * - * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked. - */ -extern DECLSPEC int SDL_LockSurface(SDL_Surface *surface); -extern DECLSPEC void SDL_UnlockSurface(SDL_Surface *surface); - -/* - * Load a surface from a seekable SDL data source (memory or file.) - * If 'freesrc' is non-zero, the source will be closed after being read. - * Returns the new surface, or NULL if there was an error. - * The new surface should be freed with SDL_FreeSurface(). - */ -extern DECLSPEC SDL_Surface * SDL_LoadBMP_RW(SDL_RWops *src, int freesrc); - -/* Convenience macro -- load a surface from a file */ -#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1) - -/* - * Save a surface to a seekable SDL data source (memory or file.) - * If 'freedst' is non-zero, the source will be closed after being written. - * Returns 0 if successful or -1 if there was an error. - */ -extern DECLSPEC int SDL_SaveBMP_RW - (SDL_Surface *surface, SDL_RWops *dst, int freedst); - -/* Convenience macro -- save a surface to a file */ -#define SDL_SaveBMP(surface, file) \ - SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1) - -/* - * Sets the color key (transparent pixel) in a blittable surface. - * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), - * 'key' will be the transparent pixel in the source image of a blit. - * SDL_RLEACCEL requests RLE acceleration for the surface if present, - * and removes RLE acceleration if absent. - * If 'flag' is 0, this function clears any current color key. - * This function returns 0, or -1 if there was an error. - */ -extern DECLSPEC int SDL_SetColorKey - (SDL_Surface *surface, Uint32 flag, Uint32 key); - -/* - * This function sets the alpha value for the entire surface, as opposed to - * using the alpha component of each pixel. This value measures the range - * of transparency of the surface, 0 being completely transparent to 255 - * being completely opaque. An 'alpha' value of 255 causes blits to be - * opaque, the source pixels copied to the destination (the default). Note - * that per-surface alpha can be combined with colorkey transparency. - * - * If 'flag' is 0, alpha blending is disabled for the surface. - * If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface. - * OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the - * surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed. - */ -extern DECLSPEC int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha); - -/* - * Sets the clipping rectangle for the destination surface in a blit. - * - * If the clip rectangle is NULL, clipping will be disabled. - * If the clip rectangle doesn't intersect the surface, the function will - * return SDL_FALSE and blits will be completely clipped. Otherwise the - * function returns SDL_TRUE and blits to the surface will be clipped to - * the intersection of the surface area and the clipping rectangle. - * - * Note that blits are automatically clipped to the edges of the source - * and destination surfaces. - */ -extern DECLSPEC SDL_bool SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect); - -/* - * Gets the clipping rectangle for the destination surface in a blit. - * 'rect' must be a pointer to a valid rectangle which will be filled - * with the correct values. - */ -extern DECLSPEC void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect); - -/* - * Creates a new surface of the specified format, and then copies and maps - * the given surface to it so the blit of the converted surface will be as - * fast as possible. If this function fails, it returns NULL. - * - * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those - * semantics. You can also pass SDL_RLEACCEL in the flags parameter and - * SDL will try to RLE accelerate colorkey and alpha blits in the resulting - * surface. - * - * This function is used internally by SDL_DisplayFormat(). - */ -extern DECLSPEC SDL_Surface *SDL_ConvertSurface - (SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags); - -/* - * This performs a fast blit from the source surface to the destination - * surface. It assumes that the source and destination rectangles are - * the same size. If either 'srcrect' or 'dstrect' are NULL, the entire - * surface (src or dst) is copied. The final blit rectangles are saved - * in 'srcrect' and 'dstrect' after all clipping is performed. - * If the blit is successful, it returns 0, otherwise it returns -1. - * - * The blit function should not be called on a locked surface. - * - * The blit semantics for surfaces with and without alpha and colorkey - * are defined as follows: - * - * RGBA->RGB: - * SDL_SRCALPHA set: - * alpha-blend (using alpha-channel). - * SDL_SRCCOLORKEY ignored. - * SDL_SRCALPHA not set: - * copy RGB. - * if SDL_SRCCOLORKEY set, only copy the pixels matching the - * RGB values of the source colour key, ignoring alpha in the - * comparison. - * - * RGB->RGBA: - * SDL_SRCALPHA set: - * alpha-blend (using the source per-surface alpha value); - * set destination alpha to opaque. - * SDL_SRCALPHA not set: - * copy RGB, set destination alpha to opaque. - * both: - * if SDL_SRCCOLORKEY set, only copy the pixels matching the - * source colour key. - * - * RGBA->RGBA: - * SDL_SRCALPHA set: - * alpha-blend (using the source alpha channel) the RGB values; - * leave destination alpha untouched. [Note: is this correct?] - * SDL_SRCCOLORKEY ignored. - * SDL_SRCALPHA not set: - * copy all of RGBA to the destination. - * if SDL_SRCCOLORKEY set, only copy the pixels matching the - * RGB values of the source colour key, ignoring alpha in the - * comparison. - * - * RGB->RGB: - * SDL_SRCALPHA set: - * alpha-blend (using the source per-surface alpha value). - * SDL_SRCALPHA not set: - * copy RGB. - * both: - * if SDL_SRCCOLORKEY set, only copy the pixels matching the - * source colour key. - * - * If either of the surfaces were in video memory, and the blit returns -2, - * the video memory was lost, so it should be reloaded with artwork and - * re-blitted: - while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) { - while ( SDL_LockSurface(image) < 0 ) - Sleep(10); - -- Write image pixels to image->pixels -- - SDL_UnlockSurface(image); - } - * This happens under DirectX 5.0 when the system switches away from your - * fullscreen application. The lock will also fail until you have access - * to the video memory again. - */ -/* You should call SDL_BlitSurface() unless you know exactly how SDL - blitting works internally and how to use the other blit functions. -*/ -#define SDL_BlitSurface SDL_UpperBlit - -/* This is the public blit function, SDL_BlitSurface(), and it performs - rectangle validation and clipping before passing it to SDL_LowerBlit() -*/ -extern DECLSPEC int SDL_UpperBlit - (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); -/* This is a semi-private blit function and it performs low-level surface - blitting only. -*/ -extern DECLSPEC int SDL_LowerBlit - (SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); - -/* - * This function performs a fast fill of the given rectangle with 'color' - * The given rectangle is clipped to the destination surface clip area - * and the final fill rectangle is saved in the passed in pointer. - * If 'dstrect' is NULL, the whole surface will be filled with 'color' - * The color should be a pixel of the format used by the surface, and - * can be generated by the SDL_MapRGB() function. - * This function returns 0 on success, or -1 on error. - */ -extern DECLSPEC int SDL_FillRect - (SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); - -/* - * This function takes a surface and copies it to a new surface of the - * pixel format and colors of the video framebuffer, suitable for fast - * blitting onto the display surface. It calls SDL_ConvertSurface() - * - * If you want to take advantage of hardware colorkey or alpha blit - * acceleration, you should set the colorkey and alpha value before - * calling this function. - * - * If the conversion fails or runs out of memory, it returns NULL - */ -extern DECLSPEC SDL_Surface * SDL_DisplayFormat(SDL_Surface *surface); - -/* - * This function takes a surface and copies it to a new surface of the - * pixel format and colors of the video framebuffer (if possible), - * suitable for fast alpha blitting onto the display surface. - * The new surface will always have an alpha channel. - * - * If you want to take advantage of hardware colorkey or alpha blit - * acceleration, you should set the colorkey and alpha value before - * calling this function. - * - * If the conversion fails or runs out of memory, it returns NULL - */ -extern DECLSPEC SDL_Surface * SDL_DisplayFormatAlpha(SDL_Surface *surface); - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* YUV video surface overlay functions */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* This function creates a video output overlay - Calling the returned surface an overlay is something of a misnomer because - the contents of the display surface underneath the area where the overlay - is shown is undefined - it may be overwritten with the converted YUV data. -*/ -extern DECLSPEC SDL_Overlay *SDL_CreateYUVOverlay(int width, int height, - Uint32 format, SDL_Surface *display); - -/* Lock an overlay for direct access, and unlock it when you are done */ -extern DECLSPEC int SDL_LockYUVOverlay(SDL_Overlay *overlay); -extern DECLSPEC void SDL_UnlockYUVOverlay(SDL_Overlay *overlay); - -/* Blit a video overlay to the display surface. - The contents of the video surface underneath the blit destination are - not defined. - The width and height of the destination rectangle may be different from - that of the overlay, but currently only 2x scaling is supported. -*/ -extern DECLSPEC int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect); - -/* Free a video overlay */ -extern DECLSPEC void SDL_FreeYUVOverlay(SDL_Overlay *overlay); - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* OpenGL support functions. */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* - * Dynamically load a GL driver, if SDL is built with dynamic GL. - * - * SDL links normally with the OpenGL library on your system by default, - * but you can compile it to dynamically load the GL driver at runtime. - * If you do this, you need to retrieve all of the GL functions used in - * your program from the dynamic library using SDL_GL_GetProcAddress(). - * - * This is disabled in default builds of SDL. - */ -extern DECLSPEC int SDL_GL_LoadLibrary(const char *path); - -/* - * Get the address of a GL function (for extension functions) - */ -extern DECLSPEC void *SDL_GL_GetProcAddress(const char* proc); - -/* - * Set an attribute of the OpenGL subsystem before intialization. - */ -extern DECLSPEC int SDL_GL_SetAttribute(SDL_GLattr attr, int value); - -/* - * Get an attribute of the OpenGL subsystem from the windowing - * interface, such as glX. This is of course different from getting - * the values from SDL's internal OpenGL subsystem, which only - * stores the values you request before initialization. - * - * Developers should track the values they pass into SDL_GL_SetAttribute - * themselves if they want to retrieve these values. - */ -extern DECLSPEC int SDL_GL_GetAttribute(SDL_GLattr attr, int* value); - -/* - * Swap the OpenGL buffers, if double-buffering is supported. - */ -extern DECLSPEC void SDL_GL_SwapBuffers(void); - -/* - * Internal functions that should not be called unless you have read - * and understood the source code for these functions. - */ -extern DECLSPEC void SDL_GL_UpdateRects(int numrects, SDL_Rect* rects); -extern DECLSPEC void SDL_GL_Lock(void); -extern DECLSPEC void SDL_GL_Unlock(void); - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* These functions allow interaction with the window manager, if any. */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* - * Sets/Gets the title and icon text of the display window - */ -extern DECLSPEC void SDL_WM_SetCaption(const char *title, const char *icon); -extern DECLSPEC void SDL_WM_GetCaption(char **title, char **icon); - -/* - * Sets the icon for the display window. - * This function must be called before the first call to SDL_SetVideoMode(). - * It takes an icon surface, and a mask in MSB format. - * If 'mask' is NULL, the entire icon surface will be used as the icon. - */ -extern DECLSPEC void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); - -/* - * This function iconifies the window, and returns 1 if it succeeded. - * If the function succeeds, it generates an SDL_APPACTIVE loss event. - * This function is a noop and returns 0 in non-windowed environments. - */ -extern DECLSPEC int SDL_WM_IconifyWindow(void); - -/* - * Toggle fullscreen mode without changing the contents of the screen. - * If the display surface does not require locking before accessing - * the pixel information, then the memory pointers will not change. - * - * If this function was able to toggle fullscreen mode (change from - * running in a window to fullscreen, or vice-versa), it will return 1. - * If it is not implemented, or fails, it returns 0. - * - * The next call to SDL_SetVideoMode() will set the mode fullscreen - * attribute based on the flags parameter - if SDL_FULLSCREEN is not - * set, then the display will be windowed by default where supported. - * - * This is currently only implemented in the X11 video driver. - */ -extern DECLSPEC int SDL_WM_ToggleFullScreen(SDL_Surface *surface); - -/* - * This function allows you to set and query the input grab state of - * the application. It returns the new input grab state. - */ -typedef enum { - SDL_GRAB_QUERY = -1, - SDL_GRAB_OFF = 0, - SDL_GRAB_ON = 1, - SDL_GRAB_FULLSCREEN /* Used internally */ -} SDL_GrabMode; -/* - * Grabbing means that the mouse is confined to the application window, - * and nearly all keyboard input is passed directly to the application, - * and not interpreted by a window manager, if any. - */ -extern DECLSPEC SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode); - -/* Not in public API at the moment - do not use! */ -extern DECLSPEC int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include "close_code.h" - -#endif /* _SDL_video_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/begin_code.h ./win32/SDL-1.2.2/include/begin_code.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/begin_code.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/begin_code.h 1970-01-01 09:00:00 +0900 @@ -1,91 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* This file sets things up for C dynamic library function definitions, - static inlined functions, and structures aligned at 4-byte alignment. - If you don't like ugly C preprocessor code, don't look at this file. :) -*/ - -/* This shouldn't be nested -- included it around code only. */ -#ifdef _begin_code_h -#error Nested inclusion of begin_code.h -#endif -#define _begin_code_h - -/* Some compilers use a special export keyword */ -#ifndef DECLSPEC -# ifdef __BEOS__ -# if defined(__GNUC__) -# define DECLSPEC __declspec(dllexport) -# else -# define DECLSPEC __declspec(export) -# endif -# else -# ifdef WIN32 -# define DECLSPEC __declspec(dllexport) -# else -# define DECLSPEC -# endif -# endif -#endif - -/* Force structure packing at 4 byte alignment. - This is necessary if the header is included in code which has structure - packing set to an alternate value, say for loading structures from disk. - The packing is reset to the previous value in close_code.h - */ -#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__) -#ifdef _MSC_VER -#pragma warning(disable: 4103) -#endif -#ifdef __BORLANDC__ -#pragma nopackwarning -#endif -#pragma pack(push,4) -#endif /* Compiler needs structure packing set */ - -/* Set up compiler-specific options for inlining functions */ -#ifndef SDL_INLINE_OKAY -#ifdef __GNUC__ -#define SDL_INLINE_OKAY -#else -/* Add any special compiler-specific cases here */ -#if defined(_MSC_VER) -#define __inline__ __inline -#define SDL_INLINE_OKAY -#else -#if !defined(__MRC__) && !defined(_SGI_SOURCE) -#define __inline__ inline -#define SDL_INLINE_OKAY -#endif /* Not a funky compiler */ -#endif /* Visual C++ */ -#endif /* GNU C */ -#endif /* SDL_INLINE_OKAY */ - -/* If inlining isn't supported, remove "__inline__", turning static - inlined functions into static functions (resulting in code bloat - in all files which include the offending header files) -*/ -#ifndef SDL_INLINE_OKAY -#define __inline__ -#endif - diff -urN ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/close_code.h ./win32/SDL-1.2.2/include/close_code.h --- ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/include/close_code.h 2002-10-20 22:03:12 +0900 +++ ./win32/SDL-1.2.2/include/close_code.h 1970-01-01 09:00:00 +0900 @@ -1,36 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* This file reverses the effects of begin_code.h and should be included - after you finish any function and structure declarations in your headers -*/ - -#undef _begin_code_h - -/* Reset structure packing at previous byte alignment */ -#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__) -#ifdef __BORLANDC__ -#pragma nopackwarning -#endif -#pragma pack(pop) -#endif /* Compiler needs structure packing set */ - Binary files ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/lib/SDL.dll and ./win32/SDL-1.2.2/lib/SDL.dll differ Binary files ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/lib/SDL.lib and ./win32/SDL-1.2.2/lib/SDL.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/SDL-1.2.2/lib/SDLmain.lib and ./win32/SDL-1.2.2/lib/SDLmain.lib differ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/cximage.vcproj ./win32/dependencies/cximage/cximage.vcproj --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/cximage.vcproj 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/cximage.vcproj 2006-08-24 07:16:02 +0900 @@ -0,0 +1,367 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/license.txt ./win32/dependencies/cximage/license.txt --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/license.txt 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/license.txt 2006-08-24 07:16:02 +0900 @@ -0,0 +1,48 @@ +This copy of the CxImage notices is provided for your convenience. In case of +any discrepancy between this copy and the notices in the file ximage.h that is +included in the CxImage distribution, the latter shall prevail. + +If you modify CxImage you may insert additional notices immediately following +this sentence. + +-------------------------------------------------------------------------------- + +COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + +CxImage version 5.99c 17/Oct/2004 + +CxImage : Copyright (C) 2001 - 2004, Davide Pizzolato + +Original CImage and CImageIterator implementation are: +Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx) + +Covered code is provided under this license on an "as is" basis, without warranty +of any kind, either expressed or implied, including, without limitation, warranties +that the covered code is free of defects, merchantable, fit for a particular purpose +or non-infringing. The entire risk as to the quality and performance of the covered +code is with you. Should any covered code prove defective in any respect, you (not +the initial developer or any other contributor) assume the cost of any necessary +servicing, repair or correction. This disclaimer of warranty constitutes an essential +part of this license. No use of any covered code is authorized hereunder except under +this disclaimer. + +Permission is hereby granted to use, copy, modify, and distribute this +source code, or portions hereof, for any purpose, including commercial applications, +freely and without fee, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not +claim that you wrote the original software. If you use this software +in a product, an acknowledgment in the product documentation would be +appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and must not be +misrepresented as being the original software. + +3. This notice may not be removed or altered from any source distribution. + +-------------------------------------------------------------------------------- + +Other information: about CxImage, and the latest version, can be found at the +CxImage home page: http://www.xdp.it + +-------------------------------------------------------------------------------- diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/tif_xfile.cpp ./win32/dependencies/cximage/tif_xfile.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/tif_xfile.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/tif_xfile.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,208 @@ +/* + * TIFF file IO, using CxFile. + */ + +#ifdef WIN32 + #include +#endif +#include + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_TIF + +#include "../tiff/tiffiop.h" + +#include "xfile.h" + +static tsize_t +_tiffReadProcEx(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((CxFile*)fd)->Read(buf, 1, size); +} + +static tsize_t +_tiffWriteProcEx(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((CxFile*)fd)->Write(buf, 1, size); +} + +static toff_t +_tiffSeekProcEx(thandle_t fd, toff_t off, int whence) +{ + if ( off == 0xFFFFFFFF ) + return 0xFFFFFFFF; + if (!((CxFile*)fd)->Seek(off, whence)) + return 0xFFFFFFFF; + if (whence == SEEK_SET) + return off; + + return (toff_t)((CxFile*)fd)->Tell(); +} + +// Return nonzero if error +static int +_tiffCloseProcEx(thandle_t fd) +{ +// return !((CxFile*)fd)->Close(); // "//" needed for memory files + return 0; +} + +#include + +static toff_t +_tiffSizeProcEx(thandle_t fd) +{ + return ((CxFile*)fd)->Size(); +} + +static int +_tiffMapProcEx(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProcEx(thandle_t fd, tdata_t base, toff_t size) +{ +} + +// Open a TIFF file descriptor for read/writing. +/* +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + FILE* stream = fopen(name, mode); + if (stream == NULL) + { + TIFFError(module, "%s: Cannot open", name); + return NULL; + } + return (TIFFFdOpen((int)stream, name, mode)); +} +*/ + +TIFF* +_TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProcEx, _tiffWriteProcEx, _tiffSeekProcEx, _tiffCloseProcEx, + _tiffSizeProcEx, _tiffMapProcEx, _tiffUnmapProcEx); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +extern "C" TIFF* _TIFFOpenEx(CxFile* stream, const char* mode) +{ + return (_TIFFFdOpen((int)stream, "TIFF IMAGE", mode)); +} + +#ifdef __GNUC__ +extern char* malloc(); +extern char* realloc(); +#else +#include +#endif + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +Win32WarningHandler(const char* module, const char* fmt, va_list ap) +{ +#ifdef _DEBUG +#if (!defined(_CONSOLE) && defined(WIN32)) + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Warning"; + LPCTSTR szDefaultModule = "TIFFLIB"; + szTmp = (module == NULL) ? (LPTSTR)szDefaultModule : (LPTSTR)module; + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (lstrlen(szTmp) + + lstrlen(szTitleText) + lstrlen(fmt) + 128)*sizeof(TCHAR))) == NULL) + return; + wsprintf(szTitle, szTitleText, szTmp); + szTmp = szTitle + (lstrlen(szTitle)+2)*sizeof(TCHAR); + wvsprintf(szTmp, fmt, ap); + MessageBox(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION); + LocalFree(szTitle); + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +#endif +} +TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; + +static void +Win32ErrorHandler(const char* module, const char* fmt, va_list ap) +{ +#ifdef _DEBUG +#if (!defined(_CONSOLE) && defined(WIN32)) + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Error"; + LPCTSTR szDefaultModule = "TIFFLIB"; + szTmp = (module == NULL) ? (LPTSTR)szDefaultModule : (LPTSTR)module; + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (lstrlen(szTmp) + + lstrlen(szTitleText) + lstrlen(fmt) + 128)*sizeof(TCHAR))) == NULL) + return; + wsprintf(szTitle, szTitleText, szTmp); + szTmp = szTitle + (lstrlen(szTitle)+2)*sizeof(TCHAR); + wvsprintf(szTmp, fmt, ap); + MessageBox(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION); + LocalFree(szTitle); + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +#endif +} +TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; + +#endif + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xfile.h ./win32/dependencies/cximage/xfile.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xfile.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/xfile.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,76 @@ +/* + * File: xfile.h + * Purpose: General Purpose File Class + */ +/* + -------------------------------------------------------------------------------- + + COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + + CxFile (c) 11/May/2002 Davide Pizzolato - www.xdp.it + CxFile version 2.00 23/Aug/2002 + + Special thanks to Chris Shearer Cooper for new features, enhancements and bugfixes + + Covered code is provided under this license on an "as is" basis, without warranty + of any kind, either expressed or implied, including, without limitation, warranties + that the covered code is free of defects, merchantable, fit for a particular purpose + or non-infringing. The entire risk as to the quality and performance of the covered + code is with you. Should any covered code prove defective in any respect, you (not + the initial developer or any other contributor) assume the cost of any necessary + servicing, repair or correction. This disclaimer of warranty constitutes an essential + part of this license. No use of any covered code is authorized hereunder except under + this disclaimer. + + Permission is hereby granted to use, copy, modify, and distribute this + source code, or portions hereof, for any purpose, including commercial applications, + freely and without fee, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. + -------------------------------------------------------------------------------- + */ +#if !defined(__xfile_h) +#define __xfile_h + +#ifdef WIN32 + #include +#endif + +#include +#include + +#include "ximadef.h" + +class DLL_EXP CxFile +{ +public: + CxFile(void) { }; + virtual ~CxFile() { }; + + virtual bool Close() = 0; + virtual size_t Read(void *buffer, size_t size, size_t count) = 0; + virtual size_t Write(const void *buffer, size_t size, size_t count) = 0; + virtual bool Seek(long offset, int origin) = 0; + virtual long Tell() = 0; + virtual long Size() = 0; + virtual bool Flush() = 0; + virtual bool Eof() = 0; + virtual long Error() = 0; + virtual bool PutC(unsigned char c) + { + // Default implementation + size_t nWrote = Write(&c, 1, 1); + return (bool)(nWrote == 1); + } + virtual long GetC() = 0; +}; + +#endif //__xfile_h diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximabmp.cpp ./win32/dependencies/cximage/ximabmp.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximabmp.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximabmp.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,361 @@ +/* + * File: ximabmp.cpp + * Purpose: Platform Independent BMP Image Class Loader and Writer + * 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximabmp.h" + +#if CXIMAGE_SUPPORT_BMP + +#include "ximaiter.h" + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageBMP::Encode(CxFile * hFile) +{ + + if (EncodeSafeCheck(hFile)) return false; + + BITMAPFILEHEADER hdr; + + hdr.bfType = 0x4d42; // 'BM' WINDOWS_BITMAP_SIGNATURE + hdr.bfSize = GetSize() + 14 /*sizeof(BITMAPFILEHEADER)*/; + hdr.bfReserved1 = hdr.bfReserved2 = 0; + hdr.bfOffBits = 14 /*sizeof(BITMAPFILEHEADER)*/ + head.biSize + GetPaletteSize(); + + //copy attributes + memcpy(pDib,&head,sizeof(BITMAPINFOHEADER)); + // Write the file header + hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1); + // Write the DIB header and the pixels + hFile->Write(pDib,GetSize(),1); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_DECODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageBMP::Decode(CxFile * hFile) +{ + if (hFile == NULL) return false; + + BITMAPFILEHEADER bf; + DWORD off = hFile->Tell(); // + try { + if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) throw "Not a BMP"; + if (bf.bfType != BFT_BITMAP) { //do we have a RC HEADER? + bf.bfOffBits = 0L; + hFile->Seek(off,SEEK_SET); + } + + BITMAPINFOHEADER bmpHeader; + if (!DibReadBitmapInfo(hFile,&bmpHeader)) throw "Error reading BMP info"; + DWORD dwCompression=bmpHeader.biCompression; + DWORD dwBitCount=bmpHeader.biBitCount; //preserve for BI_BITFIELDS compression + bool bIsOldBmp = bmpHeader.biSize == sizeof(BITMAPCOREHEADER); + + bool bTopDownDib = bmpHeader.biHeight<0; // check if it's a top-down bitmap + if (bTopDownDib) bmpHeader.biHeight=-bmpHeader.biHeight; + + if (info.nEscape == -1) { + // Return output dimensions only + head.biWidth = bmpHeader.biWidth; + head.biHeight = bmpHeader.biHeight; + throw "output dimensions returned"; + } + + if (!Create(bmpHeader.biWidth,bmpHeader.biHeight,bmpHeader.biBitCount,CXIMAGE_FORMAT_BMP)) + throw "Can't allocate memory"; + + head.biXPelsPerMeter = bmpHeader.biXPelsPerMeter; + head.biYPelsPerMeter = bmpHeader.biYPelsPerMeter; + info.xDPI = (long) floor(bmpHeader.biXPelsPerMeter * 254.0 / 10000.0 + 0.5); + info.yDPI = (long) floor(bmpHeader.biYPelsPerMeter * 254.0 / 10000.0 + 0.5); + + if (info.nEscape) throw "Cancelled"; // - cancel decoding + + RGBQUAD *pRgb = GetPalette(); + if (pRgb){ + if (bIsOldBmp){ + // convert a old color table (3 byte entries) to a new + // color table (4 byte entries) + hFile->Read((void*)pRgb,DibNumColors(&bmpHeader) * sizeof(RGBTRIPLE),1); + for (int i=DibNumColors(&head)-1; i>=0; i--){ + pRgb[i].rgbRed = ((RGBTRIPLE *)pRgb)[i].rgbtRed; + pRgb[i].rgbBlue = ((RGBTRIPLE *)pRgb)[i].rgbtBlue; + pRgb[i].rgbGreen = ((RGBTRIPLE *)pRgb)[i].rgbtGreen; + pRgb[i].rgbReserved = (BYTE)0; + } + } else { + hFile->Read((void*)pRgb,DibNumColors(&bmpHeader) * sizeof(RGBQUAD),1); + //force rgbReserved=0, to avoid problems with some WinXp bitmaps + for (unsigned int i=0; i - cancel decoding + + switch (dwBitCount) { + case 32 : + if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); + if (dwCompression == BI_BITFIELDS || dwCompression == BI_RGB){ + long imagesize=4*head.biHeight*head.biWidth; + BYTE* buff32=(BYTE*)malloc(imagesize); + if (buff32){ + hFile->Read(buff32, imagesize,1); // read in the pixels + Bitfield2RGB(buff32,0,0,0,32); + free(buff32); + } else throw "can't allocate memory"; + } else throw "unknown compression"; + break; + case 24 : + if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); + if (dwCompression == BI_RGB){ + hFile->Read(info.pImage, head.biSizeImage,1); // read in the pixels + } else throw "unknown compression"; + break; + case 16 : + { + DWORD bfmask[3]; + if (dwCompression == BI_BITFIELDS) + { + hFile->Read(bfmask, 12, 1); + } else { + bfmask[0]=0x7C00; bfmask[1]=0x3E0; bfmask[2]=0x1F; //RGB555 + } + // bf.bfOffBits required after the bitfield mask + if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); + // read in the pixels + hFile->Read(info.pImage, head.biHeight*((head.biWidth+1)/2)*4,1); + // transform into RGB + Bitfield2RGB(info.pImage,(WORD)bfmask[0],(WORD)bfmask[1],(WORD)bfmask[2],16); + break; + } + case 8 : + case 4 : + case 1 : + if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); + switch (dwCompression) { + case BI_RGB : + hFile->Read(info.pImage, head.biSizeImage,1); // read in the pixels + break; + case BI_RLE4 : + { + BYTE status_byte = 0; + BYTE second_byte = 0; + int scanline = 0; + int bits = 0; + BOOL low_nibble = FALSE; + CImageIterator iter(this); + + for (BOOL bContinue = TRUE; bContinue;) { + hFile->Read(&status_byte, sizeof(BYTE), 1); + switch (status_byte) { + case RLE_COMMAND : + hFile->Read(&status_byte, sizeof(BYTE), 1); + switch (status_byte) { + case RLE_ENDOFLINE : + bits = 0; + scanline++; + low_nibble = FALSE; + break; + case RLE_ENDOFBITMAP : + bContinue=FALSE; + break; + case RLE_DELTA : + { + // read the delta values + BYTE delta_x; + BYTE delta_y; + hFile->Read(&delta_x, sizeof(BYTE), 1); + hFile->Read(&delta_y, sizeof(BYTE), 1); + // apply them + bits += delta_x / 2; + scanline += delta_y; + break; + } + default : + hFile->Read(&second_byte, sizeof(BYTE), 1); + BYTE *sline = iter.GetRow(scanline); + for (int i = 0; i < status_byte; i++) { + if (low_nibble) { + if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ + *(sline + bits) |= (second_byte & 0x0F); + } + if (i != status_byte - 1) + hFile->Read(&second_byte, sizeof(BYTE), 1); + bits++; + } else { + if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ + *(sline + bits) = (BYTE)(second_byte & 0xF0); + } + } + low_nibble = !low_nibble; + } + if ((((status_byte+1) >> 1) & 1 )== 1) + hFile->Read(&second_byte, sizeof(BYTE), 1); + break; + }; + break; + default : + { + BYTE *sline = iter.GetRow(scanline); + hFile->Read(&second_byte, sizeof(BYTE), 1); + for (unsigned i = 0; i < status_byte; i++) { + if (low_nibble) { + if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ + *(sline + bits) |= (second_byte & 0x0F); + } + bits++; + } else { + if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ + *(sline + bits) = (BYTE)(second_byte & 0xF0); + } + } + low_nibble = !low_nibble; + } + } + break; + }; + } + break; + } + case BI_RLE8 : + { + BYTE status_byte = 0; + BYTE second_byte = 0; + int scanline = 0; + int bits = 0; + CImageIterator iter(this); + + for (BOOL bContinue = TRUE; bContinue; ) { + hFile->Read(&status_byte, sizeof(BYTE), 1); + switch (status_byte) { + case RLE_COMMAND : + hFile->Read(&status_byte, sizeof(BYTE), 1); + switch (status_byte) { + case RLE_ENDOFLINE : + bits = 0; + scanline++; + break; + case RLE_ENDOFBITMAP : + bContinue=FALSE; + break; + case RLE_DELTA : + { + // read the delta values + BYTE delta_x; + BYTE delta_y; + hFile->Read(&delta_x, sizeof(BYTE), 1); + hFile->Read(&delta_y, sizeof(BYTE), 1); + // apply them + bits += delta_x; + scanline += delta_y; + break; + } + default : + hFile->Read((void *)(iter.GetRow(scanline) + bits), sizeof(BYTE) * status_byte, 1); + // align run length to even number of bytes + if ((status_byte & 1) == 1) + hFile->Read(&second_byte, sizeof(BYTE), 1); + bits += status_byte; + break; + }; + break; + default : + BYTE *sline = iter.GetRow(scanline); + hFile->Read(&second_byte, sizeof(BYTE), 1); + for (unsigned i = 0; i < status_byte; i++) { + if ((DWORD)bits + + } catch (char *message) { + strncpy(info.szLastError,message,255); + if (info.nEscape==-1) return true; + return false; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/* ReadDibBitmapInfo() + * + * Will read a file in DIB format and return a global HANDLE to its + * BITMAPINFO. This function will work with both "old" and "new" + * bitmap formats, but will always return a "new" BITMAPINFO. + */ +bool CxImageBMP::DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib) +{ + if ((fh==NULL)||(pdib==NULL)) return false; + + if (fh->Read(pdib,sizeof(BITMAPINFOHEADER),1)==0) return false; + + BITMAPCOREHEADER bc; + + switch (pdib->biSize) // what type of bitmap info is this? + { + case sizeof(BITMAPINFOHEADER): + break; + + case 64: //sizeof(OS2_BMP_HEADER): + fh->Seek((long)(64 - sizeof(BITMAPINFOHEADER)),SEEK_CUR); + break; + + case sizeof(BITMAPCOREHEADER): + bc = *(BITMAPCOREHEADER*)pdib; + pdib->biSize = bc.bcSize; + pdib->biWidth = (DWORD)bc.bcWidth; + pdib->biHeight = (DWORD)bc.bcHeight; + pdib->biPlanes = bc.bcPlanes; + pdib->biBitCount = bc.bcBitCount; + pdib->biCompression = BI_RGB; + pdib->biSizeImage = 0; + pdib->biXPelsPerMeter = 0; + pdib->biYPelsPerMeter = 0; + pdib->biClrUsed = 0; + pdib->biClrImportant = 0; + + fh->Seek((long)(sizeof(BITMAPCOREHEADER)-sizeof(BITMAPINFOHEADER)), SEEK_CUR); + + break; + default: + //give a last chance + if (pdib->biSize>(sizeof(BITMAPINFOHEADER))&& + (pdib->biSizeImage==(unsigned long)(pdib->biHeight*((((pdib->biBitCount*pdib->biWidth)+31)/32)*4)))&& + (pdib->biPlanes==1)&&(pdib->biCompression==BI_RGB)&&(pdib->biClrUsed==0)) + { + fh->Seek((long)(pdib->biSize - sizeof(BITMAPINFOHEADER)),SEEK_CUR); + break; + } + return false; + } + + FixBitmapInfo(pdib); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_DECODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_BMP +//////////////////////////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximabmp.h ./win32/dependencies/cximage/ximabmp.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximabmp.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximabmp.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,79 @@ +/* + * File: ximabmp.h + * Purpose: BMP Image Class Loader and Writer + */ +/* ========================================================== + * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * original CImageBMP and CImageIterator implementation are: + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * ========================================================== + */ + +#if !defined(__ximaBMP_h) +#define __ximaBMP_h + +#include "ximage.h" + +const int RLE_COMMAND = 0; +const int RLE_ENDOFLINE = 0; +const int RLE_ENDOFBITMAP = 1; +const int RLE_DELTA = 2; + +#if !defined(BI_RLE8) + #define BI_RLE8 1L +#endif +#if !defined(BI_RLE4) + #define BI_RLE4 2L +#endif + +#if CXIMAGE_SUPPORT_BMP + +class CxImageBMP: public CxImage +{ +public: + CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {}; + + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + +protected: + bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib); +}; + +#define BFT_ICON 0x4349 /* 'IC' */ +#define BFT_BITMAP 0x4d42 /* 'BM' */ +#define BFT_CURSOR 0x5450 /* 'PT' */ + +#ifndef WIDTHBYTES +#define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ +#endif + +#endif + +#define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n)) +#define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount) + +#define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ + ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \ + : (lpbi)->biSizeImage) + +#define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ + ? (int)(1 << (int)(lpbi)->biBitCount) \ + : (int)(lpbi)->biClrUsed) + +#define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ + (lpbi)->biSizeImage = DibSizeImage(lpbi); \ + if ((lpbi)->biClrUsed == 0) \ + (lpbi)->biClrUsed = DibNumColors(lpbi); \ + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximacfg.h ./win32/dependencies/cximage/ximacfg.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximacfg.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximacfg.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,52 @@ +#if !defined(__ximaCFG_h) +#define __ximaCFG_h + +///////////////////////////////////////////////////////////////////////////// +// CxImage supported features +#define CXIMAGE_SUPPORT_ALPHA 1 +#define CXIMAGE_SUPPORT_SELECTION 1 +#define CXIMAGE_SUPPORT_TRANSFORMATION 1 +#define CXIMAGE_SUPPORT_DSP 1 +#define CXIMAGE_SUPPORT_LAYERS 1 +#define CXIMAGE_SUPPORT_INTERPOLATION 1 + +#define CXIMAGE_SUPPORT_DECODE 1 +#define CXIMAGE_SUPPORT_ENCODE 1 // +#define CXIMAGE_SUPPORT_WINDOWS 1 +#define CXIMAGE_SUPPORT_WINCE 0 // + +///////////////////////////////////////////////////////////////////////////// +// CxImage supported formats +#define CXIMAGE_SUPPORT_BMP 1 +#define CXIMAGE_SUPPORT_GIF 1 +#define CXIMAGE_SUPPORT_JPG 0 +#define CXIMAGE_SUPPORT_PNG 0 +#define CXIMAGE_SUPPORT_MNG 0 +#define CXIMAGE_SUPPORT_ICO 1 +#define CXIMAGE_SUPPORT_TIF 0 +#define CXIMAGE_SUPPORT_TGA 1 +#define CXIMAGE_SUPPORT_PCX 1 +#define CXIMAGE_SUPPORT_WBMP 1 +#define CXIMAGE_SUPPORT_WMF 1 +#define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2 +#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm + +#define CXIMAGE_SUPPORT_JP2 0 +#define CXIMAGE_SUPPORT_JPC 0 +#define CXIMAGE_SUPPORT_PGX 0 +#define CXIMAGE_SUPPORT_PNM 0 +#define CXIMAGE_SUPPORT_RAS 0 + + +///////////////////////////////////////////////////////////////////////////// +#define CXIMAGE_MAX_MEMORY 256000000 + +#define CXIMAGE_ERR_NOFILE "null file handler" +#define CXIMAGE_ERR_NOIMAGE "null image!!!" + +///////////////////////////////////////////////////////////////////////////// +//color to grey mapping +//#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000) +#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10) + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximadef.h ./win32/dependencies/cximage/ximadef.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximadef.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximadef.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,197 @@ +#if !defined(__ximadefs_h) +#define __ximadefs_h + +#include "ximacfg.h" + +#if defined(_AFXDLL)||defined(_USRDLL) + #define DLL_EXP __declspec(dllexport) +#elif defined(_MSC_VER)&&(_MSC_VER<1200) + #define DLL_EXP __declspec(dllimport) +#else + #define DLL_EXP +#endif + +#if CXIMAGE_SUPPORT_JP2 || CXIMAGE_SUPPORT_JPC || CXIMAGE_SUPPORT_PGX || CXIMAGE_SUPPORT_PNM || CXIMAGE_SUPPORT_RAS + #define CXIMAGE_SUPPORT_JASPER 1 +#else + #define CXIMAGE_SUPPORT_JASPER 0 +#endif + +#if CXIMAGE_SUPPORT_DSP +#undef CXIMAGE_SUPPORT_TRANSFORMATION + #define CXIMAGE_SUPPORT_TRANSFORMATION 1 +#endif + +#if CXIMAGE_SUPPORT_TRANSFORMATION || CXIMAGE_SUPPORT_TIF || CXIMAGE_SUPPORT_TGA || CXIMAGE_SUPPORT_BMP || CXIMAGE_SUPPORT_WINDOWS + #define CXIMAGE_SUPPORT_BASICTRANSFORMATIONS 1 +#endif + +#if CXIMAGE_SUPPORT_DSP || CXIMAGE_SUPPORT_TRANSFORMATION +#undef CXIMAGE_SUPPORT_INTERPOLATION + #define CXIMAGE_SUPPORT_INTERPOLATION 1 +#endif + +#if CXIMAGE_SUPPORT_WINCE + #undef CXIMAGE_SUPPORT_WMF + #define CXIMAGE_SUPPORT_WMF 0 + #undef CXIMAGE_SUPPORT_WINDOWS + #define CXIMAGE_SUPPORT_WINDOWS 0 +#endif + +#ifndef WIN32 + #undef CXIMAGE_SUPPORT_WINDOWS + #define CXIMAGE_SUPPORT_WINDOWS 0 +#endif + +#ifndef min +#define min(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef max +#define max(a,b) (((a)>(b))?(a):(b)) +#endif + +#ifndef PI + #define PI 3.141592653589793f +#endif + + +#ifdef WIN32 +#include +#include +#endif + +#include +#include + + +#ifdef __BORLANDC__ + +#ifndef _COMPLEX_DEFINED + +typedef struct tagcomplex { + double x,y; +} _complex; + +#endif + +#define _cabs(c) sqrt(c.x*c.x+c.y*c.y) + +#endif + + +#ifndef WIN32 + +#include +#include +#include + +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned long DWORD; +typedef unsigned int UINT; + +typedef DWORD COLORREF; +typedef unsigned int HANDLE; +typedef void* HRGN; + +#ifndef BOOL +#define BOOL bool +#endif + +#ifndef TRUE +#define TRUE true +#endif + +#ifndef FALSE +#define FALSE false +#endif + +#ifndef TCHAR +#define TCHAR char +#define _T +#endif + +typedef struct tagRECT +{ + long left; + long top; + long right; + long bottom; +} RECT; + +typedef struct tagPOINT +{ + long x; + long y; +} POINT; + +typedef struct tagRGBQUAD { + BYTE rgbBlue; + BYTE rgbGreen; + BYTE rgbRed; + BYTE rgbReserved; +} RGBQUAD; + +#pragma pack(1) + +typedef struct tagBITMAPINFOHEADER{ + DWORD biSize; + long biWidth; + long biHeight; + WORD biPlanes; + WORD biBitCount; + DWORD biCompression; + DWORD biSizeImage; + long biXPelsPerMeter; + long biYPelsPerMeter; + DWORD biClrUsed; + DWORD biClrImportant; +} BITMAPINFOHEADER; + +typedef struct tagBITMAPFILEHEADER { + WORD bfType; + DWORD bfSize; + WORD bfReserved1; + WORD bfReserved2; + DWORD bfOffBits; +} BITMAPFILEHEADER; + +typedef struct tagBITMAPCOREHEADER { + DWORD bcSize; + WORD bcWidth; + WORD bcHeight; + WORD bcPlanes; + WORD bcBitCount; +} BITMAPCOREHEADER; + +typedef struct tagRGBTRIPLE { + BYTE rgbtBlue; + BYTE rgbtGreen; + BYTE rgbtRed; +} RGBTRIPLE; + +#pragma pack() + +#define BI_RGB 0L +#define BI_RLE8 1L +#define BI_RLE4 2L +#define BI_BITFIELDS 3L + +#define GetRValue(rgb) ((BYTE)(rgb)) +#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) +#define GetBValue(rgb) ((BYTE)((rgb)>>16)) +#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) + +#ifndef _COMPLEX_DEFINED + +typedef struct tagcomplex { + double x,y; +} _complex; + +#endif + +#define _cabs(c) sqrt(c.x*c.x+c.y*c.y) + +#endif + +#endif //__ximadefs diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximadsp.cpp ./win32/dependencies/cximage/ximadsp.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximadsp.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximadsp.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,2370 @@ +// xImaDsp.cpp : DSP functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#include "ximaiter.h" + +#if CXIMAGE_SUPPORT_DSP + +//////////////////////////////////////////////////////////////////////////////// +/** + * Converts the image to B&W. + * The Mean() function can be used for calculating the optimal threshold. + * \param level: the lightness threshold. + * \return true if everything is ok + */ +bool CxImage::Threshold(BYTE level) +{ + if (!pDib) return false; + if (head.biBitCount == 1) return true; + + GrayScale(); + + CxImage tmp(head.biWidth,head.biHeight,1); + if (!tmp.IsValid()) return false; + + for (long y=0;ylevel) + tmp.SetPixelIndex(x,y,1); + else + tmp.SetPixelIndex(x,y,0); + } + } + tmp.SetPaletteColor(0,0,0,0); + tmp.SetPaletteColor(1,255,255,255); + Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract RGB channels from the image. Each channel is an 8 bit grayscale image. + * \param r,g,b: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitRGB(CxImage* r,CxImage* g,CxImage* b) +{ + if (!pDib) return false; + if (r==NULL && g==NULL && b==NULL) return false; + + CxImage tmpr(head.biWidth,head.biHeight,8); + CxImage tmpg(head.biWidth,head.biHeight,8); + CxImage tmpb(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long y=0; yTransfer(tmpr); + if (g) g->Transfer(tmpg); + if (b) b->Transfer(tmpb); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract CMYK channels from the image. Each channel is an 8 bit grayscale image. + * \param c,m,y,k: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k) +{ + if (!pDib) return false; + if (c==NULL && m==NULL && y==NULL && k==NULL) return false; + + CxImage tmpc(head.biWidth,head.biHeight,8); + CxImage tmpm(head.biWidth,head.biHeight,8); + CxImage tmpy(head.biWidth,head.biHeight,8); + CxImage tmpk(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long yy=0; yyTransfer(tmpc); + if (m) m->Transfer(tmpm); + if (y) y->Transfer(tmpy); + if (k) k->Transfer(tmpk); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract YUV channels from the image. Each channel is an 8 bit grayscale image. + * \param y,u,v: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitYUV(CxImage* y,CxImage* u,CxImage* v) +{ + if (!pDib) return false; + if (y==NULL && u==NULL && v==NULL) return false; + + CxImage tmpy(head.biWidth,head.biHeight,8); + CxImage tmpu(head.biWidth,head.biHeight,8); + CxImage tmpv(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long yy=0; yyTransfer(tmpy); + if (u) u->Transfer(tmpu); + if (v) v->Transfer(tmpv); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract YIQ channels from the image. Each channel is an 8 bit grayscale image. + * \param y,i,q: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitYIQ(CxImage* y,CxImage* i,CxImage* q) +{ + if (!pDib) return false; + if (y==NULL && i==NULL && q==NULL) return false; + + CxImage tmpy(head.biWidth,head.biHeight,8); + CxImage tmpi(head.biWidth,head.biHeight,8); + CxImage tmpq(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long yy=0; yyTransfer(tmpy); + if (i) i->Transfer(tmpi); + if (q) q->Transfer(tmpq); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract XYZ channels from the image. Each channel is an 8 bit grayscale image. + * \param x,y,z: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitXYZ(CxImage* x,CxImage* y,CxImage* z) +{ + if (!pDib) return false; + if (x==NULL && y==NULL && z==NULL) return false; + + CxImage tmpx(head.biWidth,head.biHeight,8); + CxImage tmpy(head.biWidth,head.biHeight,8); + CxImage tmpz(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long yy=0; yyTransfer(tmpx); + if (y) y->Transfer(tmpy); + if (z) z->Transfer(tmpz); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Extract HSL channels from the image. Each channel is an 8 bit grayscale image. + * \param h,s,l: pointers to CxImage objects, to store the splited channels + * \return true if everything is ok + */ +bool CxImage::SplitHSL(CxImage* h,CxImage* s,CxImage* l) +{ + if (!pDib) return false; + if (h==NULL && s==NULL && l==NULL) return false; + + CxImage tmph(head.biWidth,head.biHeight,8); + CxImage tmps(head.biWidth,head.biHeight,8); + CxImage tmpl(head.biWidth,head.biHeight,8); + + RGBQUAD color; + for(long y=0; yTransfer(tmph); + if (s) s->Transfer(tmps); + if (l) l->Transfer(tmpl); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#define HSLMAX 255 /* H,L, and S vary over 0-HSLMAX */ +#define RGBMAX 255 /* R,G, and B vary over 0-RGBMAX */ + /* HSLMAX BEST IF DIVISIBLE BY 6 */ + /* RGBMAX, HSLMAX must each fit in a BYTE. */ +/* Hue is undefined if Saturation is 0 (grey-scale) */ +/* This value determines where the Hue scrollbar is */ +/* initially set for achromatic colors */ +#define HSLUNDEFINED (HSLMAX*2/3) +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::RGBtoHSL(RGBQUAD lRGBColor) +{ + BYTE R,G,B; /* input RGB values */ + BYTE H,L,S; /* output HSL values */ + BYTE cMax,cMin; /* max and min RGB values */ + WORD Rdelta,Gdelta,Bdelta; /* intermediate value: % of spread from max*/ + + R = lRGBColor.rgbRed; /* get R, G, and B out of DWORD */ + G = lRGBColor.rgbGreen; + B = lRGBColor.rgbBlue; + + cMax = max( max(R,G), B); /* calculate lightness */ + cMin = min( min(R,G), B); + L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX)); + + if (cMax==cMin){ /* r=g=b --> achromatic case */ + S = 0; /* saturation */ + H = HSLUNDEFINED; /* hue */ + } else { /* chromatic case */ + if (L <= (HSLMAX/2)) /* saturation */ + S = (BYTE)((((cMax-cMin)*HSLMAX)+((cMax+cMin)/2))/(cMax+cMin)); + else + S = (BYTE)((((cMax-cMin)*HSLMAX)+((2*RGBMAX-cMax-cMin)/2))/(2*RGBMAX-cMax-cMin)); + /* hue */ + Rdelta = (WORD)((((cMax-R)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); + Gdelta = (WORD)((((cMax-G)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); + Bdelta = (WORD)((((cMax-B)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); + + if (R == cMax) + H = (BYTE)(Bdelta - Gdelta); + else if (G == cMax) + H = (BYTE)((HSLMAX/3) + Rdelta - Bdelta); + else /* B == cMax */ + H = (BYTE)(((2*HSLMAX)/3) + Gdelta - Rdelta); + +// if (H < 0) H += HSLMAX; //always false + if (H > HSLMAX) H -= HSLMAX; + } + RGBQUAD hsl={L,S,H,0}; + return hsl; +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::HueToRGB(float n1,float n2, float hue) +{ + // fixed implementation for HSL2RGB routine + float rValue; + + if (hue > 360) + hue = hue - 360; + else if (hue < 0) + hue = hue + 360; + + if (hue < 60) + rValue = n1 + (n2-n1)*hue/60.0f; + else if (hue < 180) + rValue = n2; + else if (hue < 240) + rValue = n1+(n2-n1)*(240-hue)/60; + else + rValue = n1; + + return rValue; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::HSLtoRGB(COLORREF cHSLColor) +{ + return HSLtoRGB(RGBtoRGBQUAD(cHSLColor)); +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::HSLtoRGB(RGBQUAD lHSLColor) +{ + // fixed implementation for HSL2RGB routine + float h,s,l; + float m1,m2; + BYTE r,g,b; + + h = (float)lHSLColor.rgbRed * 360.0f/255.0f; + s = (float)lHSLColor.rgbGreen/255.0f; + l = (float)lHSLColor.rgbBlue/255.0f; + + if (l <= 0.5) m2 = l * (1+s); + else m2 = l + s - l*s; + + m1 = 2 * l - m2; + + if (s == 0) { + r=g=b=(BYTE)(l*255.0f); + } else { + r = (BYTE)(HueToRGB(m1,m2,h+120) * 255.0f); + g = (BYTE)(HueToRGB(m1,m2,h) * 255.0f); + b = (BYTE)(HueToRGB(m1,m2,h-120) * 255.0f); + } + + RGBQUAD rgb = {b,g,r,0}; + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::YUVtoRGB(RGBQUAD lYUVColor) +{ + int U,V,R,G,B; + float Y = lYUVColor.rgbRed; + U = lYUVColor.rgbGreen - 128; + V = lYUVColor.rgbBlue - 128; + +// R = (int)(1.164 * Y + 2.018 * U); +// G = (int)(1.164 * Y - 0.813 * V - 0.391 * U); +// B = (int)(1.164 * Y + 1.596 * V); + R = (int)( Y + 1.403f * V); + G = (int)( Y - 0.344f * U - 0.714f * V); + B = (int)( Y + 1.770f * U); + + R= min(255,max(0,R)); + G= min(255,max(0,G)); + B= min(255,max(0,B)); + RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0}; + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::RGBtoYUV(RGBQUAD lRGBColor) +{ + int Y,U,V,R,G,B; + R = lRGBColor.rgbRed; + G = lRGBColor.rgbGreen; + B = lRGBColor.rgbBlue; + +// Y = (int)( 0.257 * R + 0.504 * G + 0.098 * B); +// U = (int)( 0.439 * R - 0.368 * G - 0.071 * B + 128); +// V = (int)(-0.148 * R - 0.291 * G + 0.439 * B + 128); + Y = (int)(0.299f * R + 0.587f * G + 0.114f * B); + U = (int)((B-Y) * 0.565f + 128); + V = (int)((R-Y) * 0.713f + 128); + + Y= min(255,max(0,Y)); + U= min(255,max(0,U)); + V= min(255,max(0,V)); + RGBQUAD yuv={(BYTE)V,(BYTE)U,(BYTE)Y,0}; + return yuv; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::YIQtoRGB(RGBQUAD lYIQColor) +{ + int I,Q,R,G,B; + float Y = lYIQColor.rgbRed; + I = lYIQColor.rgbGreen - 128; + Q = lYIQColor.rgbBlue - 128; + + R = (int)( Y + 0.956f * I + 0.621f * Q); + G = (int)( Y - 0.273f * I - 0.647f * Q); + B = (int)( Y - 1.104f * I + 1.701f * Q); + + R= min(255,max(0,R)); + G= min(255,max(0,G)); + B= min(255,max(0,B)); + RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0}; + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::RGBtoYIQ(RGBQUAD lRGBColor) +{ + int Y,I,Q,R,G,B; + R = lRGBColor.rgbRed; + G = lRGBColor.rgbGreen; + B = lRGBColor.rgbBlue; + + Y = (int)( 0.2992f * R + 0.5868f * G + 0.1140f * B); + I = (int)( 0.5960f * R - 0.2742f * G - 0.3219f * B + 128); + Q = (int)( 0.2109f * R - 0.5229f * G + 0.3120f * B + 128); + + Y= min(255,max(0,Y)); + I= min(255,max(0,I)); + Q= min(255,max(0,Q)); + RGBQUAD yiq={(BYTE)Q,(BYTE)I,(BYTE)Y,0}; + return yiq; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::XYZtoRGB(RGBQUAD lXYZColor) +{ + int X,Y,Z,R,G,B; + X = lXYZColor.rgbRed; + Y = lXYZColor.rgbGreen; + Z = lXYZColor.rgbBlue; + double k=1.088751; + + R = (int)( 3.240479f * X - 1.537150f * Y - 0.498535f * Z * k); + G = (int)( -0.969256f * X + 1.875992f * Y + 0.041556f * Z * k); + B = (int)( 0.055648f * X - 0.204043f * Y + 1.057311f * Z * k); + + R= min(255,max(0,R)); + G= min(255,max(0,G)); + B= min(255,max(0,B)); + RGBQUAD rgb={(BYTE)B,(BYTE)G,(BYTE)R,0}; + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::RGBtoXYZ(RGBQUAD lRGBColor) +{ + int X,Y,Z,R,G,B; + R = lRGBColor.rgbRed; + G = lRGBColor.rgbGreen; + B = lRGBColor.rgbBlue; + + X = (int)( 0.412453f * R + 0.357580f * G + 0.180423f * B); + Y = (int)( 0.212671f * R + 0.715160f * G + 0.072169f * B); + Z = (int)((0.019334f * R + 0.119193f * G + 0.950227f * B)*0.918483657f); + + //X= min(255,max(0,X)); + //Y= min(255,max(0,Y)); + //Z= min(255,max(0,Z)); + RGBQUAD xyz={(BYTE)Z,(BYTE)Y,(BYTE)X,0}; + return xyz; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Generates a "rainbow" palette with saturated colors + * \param correction: 1 generates a single hue spectrum. 0.75 is nice for scientific applications. + */ +void CxImage::HuePalette(float correction) +{ + if (head.biClrUsed==0) return; + + for(DWORD j=0; j 1.0f) blend = 1.0f; + int a0 = (int)(256*blend); + int a1 = 256 - a0; + + bool bFullBlend = false; + if (blend > 0.999f) bFullBlend = true; + + RGBQUAD color,hsl; + if (head.biClrUsed==0){ + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y>8); + color.rgbBlue = (BYTE)((hsl.rgbBlue * a0 + color.rgbBlue * a1)>>8); + color.rgbGreen = (BYTE)((hsl.rgbGreen * a0 + color.rgbGreen * a1)>>8); + SetPixelColor(x,y,color); + } + } + } + } + } else { + for(DWORD j=0; j + for (int i=0;i<256;i++) { + cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness))); + } + + return Lut(cTable); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return mean lightness of the image. Useful with Threshold() and Light() + */ +float CxImage::Mean() +{ + if (!pDib) return 0; + + CxImage tmp(*this,true); + if (!tmp.IsValid()) return false; + + tmp.GrayScale(); + float sum=0; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + if (xmin==xmax || ymin==ymax) return (float)0.0; + + BYTE *iSrc=tmp.info.pImage; + iSrc += tmp.info.dwEffWidth*ymin; // necessary for selections + + for(long y=ymin; y + for(long x=xmin; x 0 && (y+kmax-1) < head.biHeight && x-k2 > 0 && (x+kmax-1) < head.biWidth) + { + b=0; + iCount = 0; + iY2 = ((y-k2)*info.dwEffWidth); + for(long j=-k2;j r) r=c.rgbRed; + if (c.rgbGreen > g) g=c.rgbGreen; + if (c.rgbBlue > b) b=c.rgbBlue; + } + } + c.rgbRed = r; + c.rgbGreen = g; + c.rgbBlue = b; + tmp.SetPixelColor(x,y,c); + } + } + } + Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Enhance the variations between adjacent pixels. + * Similar results can be achieved using Filter(), + * but the algorithms are different both in Edge() and in Contour(). + * \param Ksize: size of the kernel. + * \return true if everything is ok + */ +bool CxImage::Edge(long Ksize) +{ + if (!pDib) return false; + + long k2 = Ksize/2; + long kmax= Ksize-k2; + BYTE r,g,b,rr,gg,bb; + RGBQUAD c; + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y r) r=c.rgbRed; + if (c.rgbGreen > g) g=c.rgbGreen; + if (c.rgbBlue > b) b=c.rgbBlue; + + if (c.rgbRed < rr) rr=c.rgbRed; + if (c.rgbGreen < gg) gg=c.rgbGreen; + if (c.rgbBlue < bb) bb=c.rgbBlue; + } + } + c.rgbRed = 255-abs(r-rr); + c.rgbGreen = 255-abs(g-gg); + c.rgbBlue = 255-abs(b-bb); + tmp.SetPixelColor(x,y,c); + } + } + } + Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Blends two images + * \param imgsrc2: image to be mixed with this + * \param op: blending method; see ImageOpType + * \param lXOffset, lYOffset: image displacement + * \param bMixAlpha: if true and imgsrc2 has a valid alpha layer, it will be mixed in the destination image. + * \return true if everything is ok + * + * thanks to Mwolski + */ +// +void CxImage::Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset, long lYOffset, bool bMixAlpha) +{ + long lWide = min(GetWidth(),imgsrc2.GetWidth()-lXOffset); + long lHeight = min(GetHeight(),imgsrc2.GetHeight()-lYOffset); + + bool bEditAlpha = imgsrc2.AlphaIsValid() & bMixAlpha; + + if (bEditAlpha && AlphaIsValid()==false){ + AlphaCreate(); + } + + RGBQUAD rgbBackgrnd = GetTransColor(); + RGBQUAD rgb1, rgb2, rgbDest; + + for(long lY=0;lY>8); + } else { + a=255; + } + + if (a==0){ //transparent + rgbDest = rgb1; + } else if (a==255){ //opaque + rgbDest = rgb2; + } else { //blend + a1 = (BYTE)~a; + rgbDest.rgbBlue = (BYTE)((rgb1.rgbBlue*a1+rgb2.rgbBlue*a)>>8); + rgbDest.rgbGreen = (BYTE)((rgb1.rgbGreen*a1+rgb2.rgbGreen*a)>>8); + rgbDest.rgbRed = (BYTE)((rgb1.rgbRed*a1+rgb2.rgbRed*a)>>8); + } + + if (bEditAlpha) rgbDest.rgbReserved = (BYTE)(((1+rgb1.rgbReserved)*a)>>8); + } + break; + case OpSrcBlend: + if(memcmp(&rgb1,&rgbBackgrnd,sizeof(RGBQUAD))==0) + rgbDest = rgb2; + else + { + long lBDiff = abs(rgb1.rgbBlue - rgbBackgrnd.rgbBlue); + long lGDiff = abs(rgb1.rgbGreen - rgbBackgrnd.rgbGreen); + long lRDiff = abs(rgb1.rgbRed - rgbBackgrnd.rgbRed); + + double lAverage = (lBDiff+lGDiff+lRDiff)/3; + double lThresh = 16; + double dLarge = lAverage/lThresh; + double dSmall = (lThresh-lAverage)/lThresh; + double dSmallAmt = dSmall*((double)rgb2.rgbBlue); + + if( lAverage < lThresh+1){ + rgbDest.rgbBlue = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbBlue) + + dSmallAmt))); + rgbDest.rgbGreen = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbGreen) + + dSmallAmt))); + rgbDest.rgbRed = (BYTE)max(0,min(255,(int)(dLarge*((double)rgb1.rgbRed) + + dSmallAmt))); + } + else + rgbDest = rgb1; + } + break; + default: + return; + } + SetPixelColor(lX,lY,rgbDest,bEditAlpha); + } + } + } +} +//////////////////////////////////////////////////////////////////////////////// +// thanks to Kenneth Ballard +void CxImage::MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset) +{ + RGBQUAD rgbBackgrnd = imagesrc2.GetTransColor(); + RGBQUAD rgb1; + + long width = imagesrc2.GetWidth(); + long height = imagesrc2.GetHeight(); + + int x, y; + + for(x = 0; x < width; x++) + { + for(y = 0; y < height; y++) + { + rgb1 = imagesrc2.GetPixelColor(x, y); + if(memcmp(&rgb1, &rgbBackgrnd, sizeof(RGBQUAD)) != 0) + SetPixelColor(x + lXOffset, y + lYOffset, rgb1); + } + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adjusts separately the red, green, and blue values in the image. + * \param r, g, b: can be from -255 to +255. + * \return true if everything is ok + */ +bool CxImage::ShiftRGB(long r, long g, long b) +{ + if (!pDib) return false; + RGBQUAD color; + if (head.biClrUsed==0){ + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y + for (int i=0;i<256;i++) { + cTable[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax))); + } + + return Lut(cTable); +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_WINCE == 0 +/** + * Adjusts the intensity of each pixel to the median intensity of its surrounding pixels. + * \param Ksize: size of the kernel. + * \return true if everything is ok + */ +bool CxImage::Median(long Ksize) +{ + if (!pDib) return false; + + long k2 = Ksize/2; + long kmax= Ksize-k2; + long i,j,k; + + RGBQUAD* kernel = (RGBQUAD*)malloc(Ksize*Ksize*sizeof(RGBQUAD)); + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y + for(long x=xmin; xGetWidth(); + h=srcReal->GetHeight(); + } else { + w=srcImag->GetWidth(); + h=srcImag->GetHeight(); + } + + bool bXpow2 = IsPowerof2(w); + bool bYpow2 = IsPowerof2(h); + //if bForceFFT, width AND height must be powers of 2 + if (bForceFFT && !(bXpow2 && bYpow2)) { + long i; + + i=0; + while((1< copy the image + if (srcReal && dstReal) tmpReal->Copy(*srcReal,true,false,false); + if (srcImag && dstImag) tmpImag->Copy(*srcImag,true,false,false); + + // dst&&src are empty -> create new one, else turn to GrayScale + if (srcReal==0 && dstReal==0){ + tmpReal = new CxImage(w,h,8); + tmpReal->Clear(0); + tmpReal->SetGrayPalette(); + } else { + if (!tmpReal->IsGrayScale()) tmpReal->GrayScale(); + } + if (srcImag==0 && dstImag==0){ + tmpImag = new CxImage(w,h,8); + tmpImag->Clear(0); + tmpImag->SetGrayPalette(); + } else { + if (!tmpImag->IsGrayScale()) tmpImag->GrayScale(); + } + + if (!(tmpReal->IsValid() && tmpImag->IsValid())){ + if (srcReal==0 && dstReal==0) delete tmpReal; + if (srcImag==0 && dstImag==0) delete tmpImag; + return false; + } + + //resample for FFT, if necessary + tmpReal->Resample(w,h,0); + tmpImag->Resample(w,h,0); + + //ok, here we have 2 (w x h), grayscale images ready for a FFT + + double* real; + double* imag; + long j,k,m; + + _complex **grid; + //double mean = tmpReal->Mean(); + /* Allocate memory for the grid */ + grid = (_complex **)malloc(w * sizeof(_complex)); + for (k=0;kGetPixelIndex(k,j)-128; + grid[k][j].y = tmpImag->GetPixelIndex(k,j)-128; + } + } + + //DFT buffers + double *real2,*imag2; + real2 = (double*)malloc(max(w,h) * sizeof(double)); + imag2 = (double*)malloc(max(w,h) * sizeof(double)); + + /* Transform the rows */ + real = (double *)malloc(w * sizeof(double)); + imag = (double *)malloc(w * sizeof(double)); + + m=0; + while((1<SetPixelIndex(k,j,(BYTE)max(0,min(255,(nn*(3+log(_cabs(grid[k][j]))))))); + if (grid[k][j].x==0){ + tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/0.0000000001)*nn))))); + } else { + tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128+(atan(grid[k][j].y/grid[k][j].x)*nn))))); + } + } else { + tmpReal->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].x*nn)))); + tmpImag->SetPixelIndex(k,j,(BYTE)max(0,min(255,(128 + grid[k][j].y*nn)))); + } + } + } + + for (k=0;k> 1; + j = 0; + for (i=0;i>= 1; + } + j += k; + } + + /* Compute the FFT */ + c1 = -1.0; + c2 = 0.0; + l2 = 1; + for (l=0;lGetWidth(); + long h = r->GetHeight(); + + Create(w,h,24); + + g->Resample(w,h); + b->Resample(w,h); + + if (a) { + a->Resample(w,h); +#if CXIMAGE_SUPPORT_ALPHA + AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + } + + RGBQUAD c; + for (long y=0;y + for (long x=0;xGetPixelIndex(x,y); + c.rgbGreen=g->GetPixelIndex(x,y); + c.rgbBlue=b->GetPixelIndex(x,y); + switch (colorspace){ + case 1: + SetPixelColor(x,y,HSLtoRGB(c)); + break; + case 2: + SetPixelColor(x,y,YUVtoRGB(c)); + break; + case 3: + SetPixelColor(x,y,YIQtoRGB(c)); + break; + case 4: + SetPixelColor(x,y,XYZtoRGB(c)); + break; + default: + SetPixelColor(x,y,c); + } +#if CXIMAGE_SUPPORT_ALPHA + if (a) AlphaSet(x,y,a->GetPixelIndex(x,y)); +#endif //CXIMAGE_SUPPORT_ALPHA + } + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Smart blurring to remove small defects, dithering or artifacts. + * \param radius: normally between 0.01 and 0.5 + * \param niterations: should be trimmed with radius, to avoid blurring should be (radius*niterations)<1 + * \param colorspace: 0 = RGB, 1 = HSL, 2 = YUV, 3 = YIQ, 4 = XYZ + * \return true if everything is ok + */ +bool CxImage::Repair(float radius, long niterations, long colorspace) +{ + if (!IsValid()) return false; + + long w = GetWidth(); + long h = GetHeight(); + + CxImage r,g,b; + + r.Create(w,h,8); + g.Create(w,h,8); + b.Create(w,h,8); + + switch (colorspace){ + case 1: + SplitHSL(&r,&g,&b); + break; + case 2: + SplitYUV(&r,&g,&b); + break; + case 3: + SplitYIQ(&r,&g,&b); + break; + case 4: + SplitXYZ(&r,&g,&b); + break; + default: + SplitRGB(&r,&g,&b); + } + + for (int i=0; iGetWidth()-1; + long h = ch->GetHeight()-1; + + double correction,ix,iy,ixx,ixy,iyy,den,num; + int x,y,xy0,xp1,xm1,yp1,ym1; + for(x=1; xGetPixelIndex(x,y); + xm1 = ch->GetPixelIndex(x-1,y); + xp1 = ch->GetPixelIndex(x+1,y); + ym1 = ch->GetPixelIndex(x,y-1); + yp1 = ch->GetPixelIndex(x,y+1); + + ix= (xp1-xm1)/2.0; + iy= (yp1-ym1)/2.0; + ixx= xp1 - 2.0 * xy0 + xm1; + iyy= yp1 - 2.0 * xy0 + ym1; + ixy=(ch->GetPixelIndex(x+1,y+1)+ch->GetPixelIndex(x-1,y-1)- + ch->GetPixelIndex(x-1,y+1)-ch->GetPixelIndex(x+1,y-1))/4.0; + + num= (1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy; + den= 1.0+ix*ix+iy*iy; + correction = num/den; + + tmp.SetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction)))); + } + } + + for (x=0;x<=w;x++){ + tmp.SetPixelIndex(x,0,ch->GetPixelIndex(x,0)); + tmp.SetPixelIndex(x,h,ch->GetPixelIndex(x,h)); + } + for (y=0;y<=h;y++){ + tmp.SetPixelIndex(0,y,ch->GetPixelIndex(0,y)); + tmp.SetPixelIndex(w,y,ch->GetPixelIndex(w,y)); + } + ch->Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Enhance the variations between adjacent pixels. + * Similar results can be achieved using Filter(), + * but the algorithms are different both in Edge() and in Contour(). + * \return true if everything is ok + */ +bool CxImage::Contour() +{ + if (!pDib) return false; + + long Ksize = 3; + long k2 = Ksize/2; + long kmax= Ksize-k2; + long i,j,k; + BYTE maxr,maxg,maxb; + RGBQUAD pix1,pix2; + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; ymaxb) maxb = pix2.rgbBlue; + if ((pix2.rgbGreen-pix1.rgbGreen)>maxg) maxg = pix2.rgbGreen; + if ((pix2.rgbRed-pix1.rgbRed)>maxr) maxr = pix2.rgbRed; + } + } + pix1.rgbBlue=(BYTE)(255-maxb); + pix1.rgbGreen=(BYTE)(255-maxg); + pix1.rgbRed=(BYTE)(255-maxr); + tmp.SetPixelColor(x,y,pix1); + } + } + } + Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adds a random offset to each pixel in the image + * \param radius: maximum pixel displacement + * \return true if everything is ok + */ +bool CxImage::Jitter(long radius) +{ + if (!pDib) return false; + + long nx,ny; + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y y) + { + for (row = 0; row < y ; row++) + { + scale=0; + /* find the scale factor */ + for (j = 0; j < y ; j++) + { + /* if the index is in bounds, add it to the scale counter */ + if ((j + cmatrix_length/2 - row >= 0) && + (j + cmatrix_length/2 - row < cmatrix_length)) + scale += cmatrix[j + cmatrix_length/2 - row]; + } + for (i = 0; i= row - cmatrix_length/2) && + (j <= row + cmatrix_length/2)) + sum += cur_col[j*bytes + i] * cmatrix[j]; + } + dest_col[row*bytes + i] = (BYTE)(0.5f + sum / scale); + } + } + } + else + { + /* for the edge condition, we only use available info and scale to one */ + for (row = 0; row < cmatrix_middle; row++) + { + /* find scale factor */ + scale=0; + for (j = cmatrix_middle - row; j0; j--) + { + sum += *(ctable_p + *cur_col_p1); + cur_col_p1 += bytes; + ctable_p += 256; + } + cur_col_p++; + *(dest_col_p++) = (BYTE)(0.5f + sum); + } + } + + /* for the edge condition , we only use available info, and scale to one */ + for (; row < y; row++) + { + /* find scale factor */ + scale=0; + for (j = 0; j< y-row + cmatrix_middle; j++) + scale += cmatrix[j]; + for (i = 0; i 255) dest_row[u*3+v] = 255; + else dest_row[u*3+v] = value; + } + } + } + + Transfer(tmp); + + return TRUE; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Apply a look up table to the image. + * \param pLut: BYTE[256] look up table + * \return true if everything is ok + */ +bool CxImage::Lut(BYTE* pLut) +{ + if (!pDib || !pLut) return false; + RGBQUAD color; + + double dbScaler; + if (head.biClrUsed==0){ + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + // faster loop for full image + BYTE *iSrc=info.pImage; + for(unsigned long i=0; i < head.biSizeImage ; i++){ + *iSrc++ = pLut[*iSrc]; + } + return true; + } + + dbScaler = 100.0/ymax; + + for(long y=ymin; y + for(long x=xmin; x + if (!pDib) return false; + FloodFill2(x,y,GetPixelColor(x,y),FillColor); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::FloodFill2(int x, int y, RGBQUAD old_color, RGBQUAD new_color) +{ + // Fill in the actual pixels. + // Function steps recursively until it finds borders (color that is not old_color) + if (!IsInside(x,y)) return; + + RGBQUAD r = GetPixelColor(x,y); + COLORREF cr = RGB(r.rgbRed,r.rgbGreen,r.rgbBlue); + + if(cr == RGB(old_color.rgbRed,old_color.rgbGreen,old_color.rgbBlue) + && cr != RGB(new_color.rgbRed,new_color.rgbGreen,new_color.rgbBlue) ) { + + // the above if statement, after && is there to prevent + // stack overflows. The program will continue to find + // colors if you flood-fill an entire region (entire picture) + + SetPixelColor(x,y,new_color); + + FloodFill2((x+1),y,old_color,new_color); + FloodFill2((x-1),y,old_color,new_color); + FloodFill2(x,(y+1),old_color,new_color); + FloodFill2(x,(y-1),old_color,new_color); + } +}*/ +/////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_DSP diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaenc.cpp ./win32/dependencies/cximage/ximaenc.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaenc.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaenc.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,920 @@ +// xImaCodec.cpp : Encode Decode functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_JPG +#include "ximajpg.h" +#endif + +#if CXIMAGE_SUPPORT_GIF +#include "ximagif.h" +#endif + +#if CXIMAGE_SUPPORT_PNG +#include "ximapng.h" +#endif + +#if CXIMAGE_SUPPORT_MNG +#include "ximamng.h" +#endif + +#if CXIMAGE_SUPPORT_BMP +#include "ximabmp.h" +#endif + +#if CXIMAGE_SUPPORT_ICO +#include "ximaico.h" +#endif + +#if CXIMAGE_SUPPORT_TIF +#include "ximatif.h" +#endif + +#if CXIMAGE_SUPPORT_TGA +#include "ximatga.h" +#endif + +#if CXIMAGE_SUPPORT_PCX +#include "ximapcx.h" +#endif + +#if CXIMAGE_SUPPORT_WBMP +#include "ximawbmp.h" +#endif + +#if CXIMAGE_SUPPORT_WMF +#include "ximawmf.h" // - WMF/EMF support +#endif + +#if CXIMAGE_SUPPORT_J2K +#include "ximaj2k.h" +#endif + +#if CXIMAGE_SUPPORT_JBG +#include "ximajbg.h" +#endif + +#if CXIMAGE_SUPPORT_JASPER +#include "ximajas.h" +#endif + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::EncodeSafeCheck(CxFile *hFile) +{ + if (hFile==NULL) { + strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); + return true; + } + + if (pDib==NULL){ + strcpy(info.szLastError,CXIMAGE_ERR_NOIMAGE); + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +//#ifdef WIN32 +//bool CxImage::Save(LPCWSTR filename, DWORD imagetype) +//{ +// FILE* hFile; //file handle to write the image +// if ((hFile=_wfopen(filename,L"wb"))==NULL) return false; +// bool bOK = Encode(hFile,imagetype); +// fclose(hFile); +// return bOK; +//} +//#endif //WIN32 +//////////////////////////////////////////////////////////////////////////////// +// For UNICODE support: char -> TCHAR +/** + * Saves to disk the image in a specific format. + * \param filename: file name + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Save(const TCHAR * filename, DWORD imagetype) +{ + FILE* hFile; //file handle to write the image + +#ifdef WIN32 + if ((hFile=_tfopen(filename,_T("wb")))==NULL) return false; // For UNICODE support +#else + if ((hFile=fopen(filename,"wb"))==NULL) return false; +#endif + + bool bOK = Encode(hFile,imagetype); + fclose(hFile); + return bOK; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Saves to disk the image in a specific format. + * \param hFile: file handle, open and enabled for writing. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Encode(FILE *hFile, DWORD imagetype) +{ + CxIOFile file(hFile); + return Encode(&file,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Saves to memory buffer the image in a specific format. + * \param buffer: output memory buffer pointer. Must be NULL, + * the function allocates and fill the memory, + * the application must free the buffer, see also FreeMemory(). + * \param size: output memory buffer size. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Encode(BYTE * &buffer, long &size, DWORD imagetype) +{ + if (buffer!=NULL){ + strcpy(info.szLastError,"the buffer must be empty"); + return false; + } + CxMemFile file; + file.Open(); + if(Encode(&file,imagetype)){ + buffer=file.GetBuffer(); + size=file.Size(); + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Saves to disk the image in a specific format. + * \param hFile: file handle (implemented using CxMemFile or CxIOFile), + * open and enabled for writing. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + * \sa ENUM_CXIMAGE_FORMATS + */ +bool CxImage::Encode(CxFile *hFile, DWORD imagetype) +{ + +#if CXIMAGE_SUPPORT_BMP + + if (imagetype==CXIMAGE_FORMAT_BMP){ + CxImageBMP newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_ICO + if (imagetype==CXIMAGE_FORMAT_ICO){ + CxImageICO newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_TIF + if (imagetype==CXIMAGE_FORMAT_TIF){ + CxImageTIF newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JPG + if (imagetype==CXIMAGE_FORMAT_JPG){ + CxImageJPG newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_GIF + if (imagetype==CXIMAGE_FORMAT_GIF){ + CxImageGIF newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_PNG + if (imagetype==CXIMAGE_FORMAT_PNG){ + CxImagePNG newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_MNG + if (imagetype==CXIMAGE_FORMAT_MNG){ + CxImageMNG newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_TGA + if (imagetype==CXIMAGE_FORMAT_TGA){ + CxImageTGA newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_PCX + if (imagetype==CXIMAGE_FORMAT_PCX){ + CxImagePCX newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_WBMP + if (imagetype==CXIMAGE_FORMAT_WBMP){ + CxImageWBMP newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // - WMF/EMF support + if (imagetype==CXIMAGE_FORMAT_WMF){ + CxImageWMF newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_J2K + if (imagetype==CXIMAGE_FORMAT_J2K){ + CxImageJ2K newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JBG + if (imagetype==CXIMAGE_FORMAT_JBG){ + CxImageJBG newima; + newima.Ghost(this); + if (newima.Encode(hFile)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JASPER + if ( + #if CXIMAGE_SUPPORT_JP2 + imagetype==CXIMAGE_FORMAT_JP2 || + #endif + #if CXIMAGE_SUPPORT_JPC + imagetype==CXIMAGE_FORMAT_JPC || + #endif + #if CXIMAGE_SUPPORT_PGX + imagetype==CXIMAGE_FORMAT_PGX || + #endif + #if CXIMAGE_SUPPORT_PNM + imagetype==CXIMAGE_FORMAT_PNM || + #endif + #if CXIMAGE_SUPPORT_RAS + imagetype==CXIMAGE_FORMAT_RAS || + #endif + false ){ + CxImageJAS newima; + newima.Ghost(this); + if (newima.Encode(hFile,imagetype)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif + + strcpy(info.szLastError,"Encode: Unknown format"); + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers. + * \param hFile: file handle. + * \param pImages: array of CxImage pointers. + * \param pagecount: number of images. + * \param imagetype: can be CXIMAGE_FORMAT_TIF or CXIMAGE_FORMAT_GIF. + * \return true if everything is ok + */ +bool CxImage::Encode(FILE * hFile, CxImage ** pImages, int pagecount, DWORD imagetype) +{ + CxIOFile file(hFile); + return Encode(&file, pImages, pagecount,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers. + * \param hFile: file handle (implemented using CxMemFile or CxIOFile). + * \param pImages: array of CxImage pointers. + * \param pagecount: number of images. + * \param imagetype: can be CXIMAGE_FORMAT_TIF or CXIMAGE_FORMAT_GIF. + * \return true if everything is ok + */ +bool CxImage::Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype) +{ +#if CXIMAGE_SUPPORT_TIF + if (imagetype==CXIMAGE_FORMAT_TIF){ + CxImageTIF newima; + newima.Ghost(this); + if (newima.Encode(hFile,pImages,pagecount)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_GIF + if (imagetype==CXIMAGE_FORMAT_GIF){ + CxImageGIF newima; + newima.Ghost(this); + if (newima.Encode(hFile,pImages,pagecount)){ + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif + strcpy(info.szLastError,"Multipage Encode, Unsupported operation for this format"); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * exports the image into a RGBA buffer, Useful for OpenGL applications. + * \param buffer: output memory buffer pointer. Must be NULL, + * the function allocates and fill the memory, + * the application must free the buffer, see also FreeMemory(). + * \param size: output memory buffer size. + * \return true if everything is ok + */ +bool CxImage::Encode2RGBA(BYTE * &buffer, long &size) +{ + if (buffer!=NULL){ + strcpy(info.szLastError,"the buffer must be empty"); + return false; + } + CxMemFile file; + file.Open(); + if(Encode2RGBA(&file)){ + buffer=file.GetBuffer(); + size=file.Size(); + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * exports the image into a RGBA buffer, Useful for OpenGL applications. + * \param hFile: file handle (implemented using CxMemFile or CxIOFile). + * \return true if everything is ok + */ +bool CxImage::Encode2RGBA(CxFile *hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + for (DWORD y = 0; yPutC(color.rgbRed); + hFile->PutC(color.rgbGreen); + hFile->PutC(color.rgbBlue); + hFile->PutC(color.rgbReserved); + } + } + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_DECODE +//////////////////////////////////////////////////////////////////////////////// +// For UNICODE support: char -> TCHAR +/** + * Reads from disk the image in a specific format. + * - If decoding fails using the specified image format, + * the function will try the automatic file format recognition. + * + * \param filename: file name + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Load(const TCHAR * filename, DWORD imagetype) +//bool CxImage::Load(const char * filename, DWORD imagetype) +{ + /*FILE* hFile; //file handle to read the image + if ((hFile=fopen(filename,"rb"))==NULL) return false; + bool bOK = Decode(hFile,imagetype); + fclose(hFile);*/ + + /* automatic file type recognition */ + bool bOK = false; + if ( imagetype > 0 && imagetype < CMAX_IMAGE_FORMATS ){ + FILE* hFile; //file handle to read the image + +#ifdef WIN32 + if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support +#else + if ((hFile=fopen(filename,"rb"))==NULL) return false; +#endif + + bOK = Decode(hFile,imagetype); + fclose(hFile); + if (bOK) return bOK; + } + + char szError[256]; + strcpy(szError,info.szLastError); //save the first error + + // if failed, try automatic recognition of the file... + FILE* hFile; + +#ifdef WIN32 + if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support +#else + if ((hFile=fopen(filename,"rb"))==NULL) return false; +#endif + + bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN); + fclose(hFile); + + if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error + + return bOK; +} +//////////////////////////////////////////////////////////////////////////////// +#ifdef WIN32 +//bool CxImage::Load(LPCWSTR filename, DWORD imagetype) +//{ +// /*FILE* hFile; //file handle to read the image +// if ((hFile=_wfopen(filename, L"rb"))==NULL) return false; +// bool bOK = Decode(hFile,imagetype); +// fclose(hFile);*/ +// +// /* automatic file type recognition */ +// bool bOK = false; +// if ( imagetype > 0 && imagetype < CMAX_IMAGE_FORMATS ){ +// FILE* hFile; //file handle to read the image +// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false; +// bOK = Decode(hFile,imagetype); +// fclose(hFile); +// if (bOK) return bOK; +// } +// +// char szError[256]; +// strcpy(szError,info.szLastError); //save the first error +// +// // if failed, try automatic recognition of the file... +// FILE* hFile; //file handle to read the image +// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false; +// bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN); +// fclose(hFile); +// +// if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error +// +// return bOK; +//} +//////////////////////////////////////////////////////////////////////////////// +/** + * Loads an image from the application resources. + * \param hRes: the resource handle returned by FindResource(). + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS. + * \param hModule: NULL for internal resource, or external application/DLL hinstance returned by LoadLibray. + * \return true if everything is ok + */ +bool CxImage::LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule) +{ + DWORD rsize=SizeofResource(hModule,hRes); + HGLOBAL hMem=::LoadResource(hModule,hRes); + if (hMem){ + char* lpVoid=(char*)LockResource(hMem); + if (lpVoid){ + // FILE* fTmp=tmpfile(); doesn't work with network + /*char tmpPath[MAX_PATH] = {0}; + char tmpFile[MAX_PATH] = {0}; + GetTempPath(MAX_PATH,tmpPath); + GetTempFileName(tmpPath,"IMG",0,tmpFile); + FILE* fTmp=fopen(tmpFile,"w+b"); + if (fTmp){ + fwrite(lpVoid,rsize,1,fTmp); + fseek(fTmp,0,SEEK_SET); + bool bOK = Decode(fTmp,imagetype); + fclose(fTmp); + DeleteFile(tmpFile); + return bOK; + }*/ + + CxMemFile fTmp((BYTE*)lpVoid,rsize); + return Decode(&fTmp,imagetype); + } + } else strcpy(info.szLastError,"Unable to load resource!"); + return false; +} +#endif //WIN32 +//////////////////////////////////////////////////////////////////////////////// +/** + * Constructor from file name, see Load() + * \param filename: file name + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + */ +// +// > filename: file name +// > imagetype: specify the image format (CXIMAGE_FORMAT_BMP,...) +// For UNICODE support: char -> TCHAR +CxImage::CxImage(const TCHAR * filename, DWORD imagetype) +//CxImage::CxImage(const char * filename, DWORD imagetype) +{ + Startup(imagetype); + Load(filename,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Constructor from file handle, see Decode() + * \param stream: file handle, with read access. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + */ +CxImage::CxImage(FILE * stream, DWORD imagetype) +{ + Startup(imagetype); + Decode(stream,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Constructor from CxFile object, see Decode() + * \param stream: file handle (implemented using CxMemFile or CxIOFile), with read access. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + */ +CxImage::CxImage(CxFile * stream, DWORD imagetype) +{ + Startup(imagetype); + Decode(stream,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Constructor from memory buffer, see Decode() + * \param buffer: memory buffer + * \param size: size of buffer + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + */ +CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype) +{ + Startup(imagetype); + CxMemFile stream(buffer,size); + Decode(&stream,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Loads an image from memory buffer + * \param buffer: memory buffer + * \param size: size of buffer + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype) +{ + CxMemFile file(buffer,size); + return Decode(&file,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Loads an image from file handle. + * \param hFile: file handle, with read access. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + */ +bool CxImage::Decode(FILE *hFile, DWORD imagetype) +{ + CxIOFile file(hFile); + return Decode(&file,imagetype); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Loads an image from CxFile object + * \param hFile: file handle (implemented using CxMemFile or CxIOFile), with read access. + * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS + * \return true if everything is ok + * \sa ENUM_CXIMAGE_FORMATS + */ +bool CxImage::Decode(CxFile *hFile, DWORD imagetype) +{ + + if (imagetype==CXIMAGE_FORMAT_UNKNOWN){ + DWORD pos = hFile->Tell(); +#if CXIMAGE_SUPPORT_BMP + { CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_JPG + { CxImageJPG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_ICO + { CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_GIF + { CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_PNG + { CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_TIF + { CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_MNG + { CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_TGA + { CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_PCX + { CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_WBMP + { CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS + { CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_J2K + { CxImageJ2K newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_JBG + { CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif +#if CXIMAGE_SUPPORT_JASPER + { CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } +#endif + } + +#if CXIMAGE_SUPPORT_BMP + if (imagetype==CXIMAGE_FORMAT_BMP){ + CxImageBMP newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JPG + if (imagetype==CXIMAGE_FORMAT_JPG){ + CxImageJPG newima; + newima.CopyInfo(*this); // + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_ICO + if (imagetype==CXIMAGE_FORMAT_ICO){ + CxImageICO newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + info.nNumFrames = newima.info.nNumFrames; + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_GIF + if (imagetype==CXIMAGE_FORMAT_GIF){ + CxImageGIF newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + info.nNumFrames = newima.info.nNumFrames; + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_PNG + if (imagetype==CXIMAGE_FORMAT_PNG){ + CxImagePNG newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_TIF + if (imagetype==CXIMAGE_FORMAT_TIF){ + CxImageTIF newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + info.nNumFrames = newima.info.nNumFrames; + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_MNG + if (imagetype==CXIMAGE_FORMAT_MNG){ + CxImageMNG newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + info.nNumFrames = newima.info.nNumFrames; + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_TGA + if (imagetype==CXIMAGE_FORMAT_TGA){ + CxImageTGA newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_PCX + if (imagetype==CXIMAGE_FORMAT_PCX){ + CxImagePCX newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_WBMP + if (imagetype==CXIMAGE_FORMAT_WBMP){ + CxImageWBMP newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support + if (imagetype == CXIMAGE_FORMAT_WMF){ + CxImageWMF newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_J2K + if (imagetype==CXIMAGE_FORMAT_J2K){ + CxImageJ2K newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JBG + if (imagetype==CXIMAGE_FORMAT_JBG){ + CxImageJBG newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif +#if CXIMAGE_SUPPORT_JASPER + if ( + #if CXIMAGE_SUPPORT_JP2 + imagetype==CXIMAGE_FORMAT_JP2 || + #endif + #if CXIMAGE_SUPPORT_JPC + imagetype==CXIMAGE_FORMAT_JPC || + #endif + #if CXIMAGE_SUPPORT_PGX + imagetype==CXIMAGE_FORMAT_PGX || + #endif + #if CXIMAGE_SUPPORT_PNM + imagetype==CXIMAGE_FORMAT_PNM || + #endif + #if CXIMAGE_SUPPORT_RAS + imagetype==CXIMAGE_FORMAT_RAS || + #endif + false ){ + CxImageJAS newima; + newima.CopyInfo(*this); + if (newima.Decode(hFile,imagetype)){ + Transfer(newima); + return true; + } else { + strcpy(info.szLastError,newima.GetLastError()); + return false; + } + } +#endif + + strcpy(info.szLastError,"Decode: Unknown or wrong format"); + return false; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_DECODE +//////////////////////////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaexif.cpp ./win32/dependencies/cximage/ximaexif.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaexif.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaexif.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,873 @@ +/* + * File: ximaexif.cpp + * Purpose: EXIF reader + * 18/Aug/2002 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + * based on jhead-1.8 by Matthias Wandel + */ + +#include "ximajpg.h" + +#if CXIMAGEJPG_SUPPORT_EXIF + +//////////////////////////////////////////////////////////////////////////////// +CxImageJPG::CxExifInfo::CxExifInfo(EXIFINFO* info) +{ + if (info) { + m_exifinfo = info; + freeinfo = false; + } else { + m_exifinfo = new EXIFINFO; + memset(m_exifinfo,0,sizeof(EXIFINFO)); + freeinfo = true; + } + + m_szLastError[0]='\0'; + ExifImageWidth = MotorolaOrder = 0; + SectionsRead=0; + memset(&Sections, 0, MAX_SECTIONS * sizeof(Section_t)); +} +//////////////////////////////////////////////////////////////////////////////// +CxImageJPG::CxExifInfo::~CxExifInfo() +{ + for(int i=0;iGetC(); + + if (a != 0xff || hFile->GetC() != M_SOI){ + return FALSE; + } + + for(;;){ + int itemlen; + int marker = 0; + int ll,lh, got; + BYTE * Data; + + if (SectionsRead >= MAX_SECTIONS){ + strcpy(m_szLastError,"Too many sections in jpg file"); + return false; + } + + for (a=0;a<7;a++){ + marker = hFile->GetC(); + if (marker != 0xff) break; + + if (a >= 6){ + printf("too many padding bytes\n"); + return false; + } + } + + if (marker == 0xff){ + // 0xff is legal padding, but if we get that many, something's wrong. + strcpy(m_szLastError,"too many padding bytes!"); + return false; + } + + Sections[SectionsRead].Type = marker; + + // Read the length of the section. + lh = hFile->GetC(); + ll = hFile->GetC(); + + itemlen = (lh << 8) | ll; + + if (itemlen < 2){ + strcpy(m_szLastError,"invalid marker"); + return false; + } + + Sections[SectionsRead].Size = itemlen; + + Data = (BYTE *)malloc(itemlen); + if (Data == NULL){ + strcpy(m_szLastError,"Could not allocate memory"); + return false; + } + Sections[SectionsRead].Data = Data; + + // Store first two pre-read bytes. + Data[0] = (BYTE)lh; + Data[1] = (BYTE)ll; + + got = hFile->Read(Data+2, 1, itemlen-2); // Read the whole section. + if (got != itemlen-2){ + strcpy(m_szLastError,"Premature end of file?"); + return false; + } + SectionsRead += 1; + + switch(marker){ + + case M_SOS: // stop before hitting compressed data + // If reading entire image is requested, read the rest of the data. + if (nReadMode & EXIF_READ_IMAGE){ + int cp, ep, size; + // Determine how much file is left. + cp = hFile->Tell(); + hFile->Seek(0, SEEK_END); + ep = hFile->Tell(); + hFile->Seek(cp, SEEK_SET); + + size = ep-cp; + Data = (BYTE *)malloc(size); + if (Data == NULL){ + strcpy(m_szLastError,"could not allocate data for entire image"); + return false; + } + + got = hFile->Read(Data, 1, size); + if (got != size){ + strcpy(m_szLastError,"could not read the rest of the image"); + return false; + } + + Sections[SectionsRead].Data = Data; + Sections[SectionsRead].Size = size; + Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; + SectionsRead ++; + } + return true; + + case M_EOI: // in case it's a tables-only JPEG stream + printf("No image in jpeg!\n"); + return FALSE; + + case M_COM: // Comment section + if (HaveCom || ((nReadMode & EXIF_READ_EXIF) == 0)){ + // Discard this section. + free(Sections[--SectionsRead].Data); + Sections[SectionsRead].Data=0; + }else{ + process_COM(Data, itemlen); + HaveCom = TRUE; + } + break; + + case M_JFIF: + // Regular jpegs always have this tag, exif images have the exif + // marker instead, althogh ACDsee will write images with both markers. + // this program will re-create this marker on absence of exif marker. + // hence no need to keep the copy from the file. + free(Sections[--SectionsRead].Data); + Sections[SectionsRead].Data=0; + break; + + case M_EXIF: + // Seen files from some 'U-lead' software with Vivitar scanner + // that uses marker 31 for non exif stuff. Thus make sure + // it says 'Exif' in the section before treating it as exif. + if ((nReadMode & EXIF_READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ + m_exifinfo->IsExif = process_EXIF((BYTE *)Data+2, itemlen); + }else{ + // Discard this section. + free(Sections[--SectionsRead].Data); + Sections[SectionsRead].Data=0; + } + break; + + case M_SOF0: + case M_SOF1: + case M_SOF2: + case M_SOF3: + case M_SOF5: + case M_SOF6: + case M_SOF7: + case M_SOF9: + case M_SOF10: + case M_SOF11: + case M_SOF13: + case M_SOF14: + case M_SOF15: + process_SOFn(Data, marker); + break; + default: + // Skip any other sections. + //if (ShowTags) printf("Jpeg section marker 0x%02x size %d\n",marker, itemlen); + break; + } + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/*-------------------------------------------------------------------------- + Process a EXIF marker + Describes all the drivel that most digital cameras include... +--------------------------------------------------------------------------*/ +bool CxImageJPG::CxExifInfo::process_EXIF(unsigned char * CharBuf, unsigned int length) +{ + m_exifinfo->FlashUsed = 0; + /* If it's from a digicam, and it used flash, it says so. */ + m_exifinfo->Comments[0] = '\0'; /* Initial value - null string */ + + ExifImageWidth = 0; + + { /* Check the EXIF header component */ + static const unsigned char ExifHeader[] = "Exif\0\0"; + if (memcmp(CharBuf+0, ExifHeader,6)){ + strcpy(m_szLastError,"Incorrect Exif header"); + return false; + } + } + + if (memcmp(CharBuf+6,"II",2) == 0){ + MotorolaOrder = 0; + }else{ + if (memcmp(CharBuf+6,"MM",2) == 0){ + MotorolaOrder = 1; + }else{ + strcpy(m_szLastError,"Invalid Exif alignment marker."); + return false; + } + } + + /* Check the next two values for correctness. */ + if (Get16u(CharBuf+8) != 0x2a){ + strcpy(m_szLastError,"Invalid Exif start (1)"); + return false; + } + + int FirstOffset = Get32u(CharBuf+10); + /* + if (FirstOffset < 8 || FirstOffset > 16){ + // I used to ensure this was set to 8 (website I used indicated its 8) + // but PENTAX Optio 230 has it set differently, and uses it as offset. (Sept 11 2002) + strcpy(m_szLastError,"Suspicious offset of first IFD value"); + return false; + }*/ + + unsigned char * LastExifRefd = CharBuf; + + /* First directory starts 16 bytes in. Offsets start at 8 bytes in. */ + if (!ProcessExifDir(CharBuf+14, CharBuf+6, length-6, m_exifinfo, &LastExifRefd)) + return false; + + /* give a chance for a second directory */ + if (FirstOffset > 8) { + if (!ProcessExifDir(CharBuf+14+FirstOffset-8, CharBuf+6, length-6, m_exifinfo, &LastExifRefd)) + return false; + } + + /* This is how far the interesting (non thumbnail) part of the exif went. */ + // int ExifSettingsLength = LastExifRefd - CharBuf; + + /* Compute the CCD width, in milimeters. */ + if (m_exifinfo->FocalplaneXRes != 0){ + m_exifinfo->CCDWidth = (float)(ExifImageWidth * m_exifinfo->FocalplaneUnits / m_exifinfo->FocalplaneXRes); + } + + return true; +} +//-------------------------------------------------------------------------- +// Get 16 bits motorola order (always) for jpeg header stuff. +//-------------------------------------------------------------------------- +int CxImageJPG::CxExifInfo::Get16m(void * Short) +{ + return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1]; +} +//////////////////////////////////////////////////////////////////////////////// +/*-------------------------------------------------------------------------- + Convert a 16 bit unsigned value from file's native byte order +--------------------------------------------------------------------------*/ +int CxImageJPG::CxExifInfo::Get16u(void * Short) +{ + if (MotorolaOrder){ + return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1]; + }else{ + return (((unsigned char *)Short)[1] << 8) | ((unsigned char *)Short)[0]; + } +} +//////////////////////////////////////////////////////////////////////////////// +/*-------------------------------------------------------------------------- + Convert a 32 bit signed value from file's native byte order +--------------------------------------------------------------------------*/ +long CxImageJPG::CxExifInfo::Get32s(void * Long) +{ + if (MotorolaOrder){ + return ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16) + | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 ); + }else{ + return ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16) + | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 ); + } +} +//////////////////////////////////////////////////////////////////////////////// +/*-------------------------------------------------------------------------- + Convert a 32 bit unsigned value from file's native byte order +--------------------------------------------------------------------------*/ +unsigned long CxImageJPG::CxExifInfo::Get32u(void * Long) +{ + return (unsigned long)Get32s(Long) & 0xffffffff; +} +//////////////////////////////////////////////////////////////////////////////// + +/* Describes format descriptor */ +static const int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; +#define NUM_FORMATS 12 + +#define FMT_BYTE 1 +#define FMT_STRING 2 +#define FMT_USHORT 3 +#define FMT_ULONG 4 +#define FMT_URATIONAL 5 +#define FMT_SBYTE 6 +#define FMT_UNDEFINED 7 +#define FMT_SSHORT 8 +#define FMT_SLONG 9 +#define FMT_SRATIONAL 10 +#define FMT_SINGLE 11 +#define FMT_DOUBLE 12 + +/* Describes tag values */ + +#define TAG_EXIF_VERSION 0x9000 +#define TAG_EXIF_OFFSET 0x8769 +#define TAG_INTEROP_OFFSET 0xa005 + +#define TAG_MAKE 0x010F +#define TAG_MODEL 0x0110 + +#define TAG_ORIENTATION 0x0112 +#define TAG_XRESOLUTION 0x011A +#define TAG_YRESOLUTION 0x011B +#define TAG_RESOLUTIONUNIT 0x0128 + +#define TAG_EXPOSURETIME 0x829A +#define TAG_FNUMBER 0x829D + +#define TAG_SHUTTERSPEED 0x9201 +#define TAG_APERTURE 0x9202 +#define TAG_BRIGHTNESS 0x9203 +#define TAG_MAXAPERTURE 0x9205 +#define TAG_FOCALLENGTH 0x920A + +#define TAG_DATETIME_ORIGINAL 0x9003 +#define TAG_USERCOMMENT 0x9286 + +#define TAG_SUBJECT_DISTANCE 0x9206 +#define TAG_FLASH 0x9209 + +#define TAG_FOCALPLANEXRES 0xa20E +#define TAG_FOCALPLANEYRES 0xa20F +#define TAG_FOCALPLANEUNITS 0xa210 +#define TAG_EXIF_IMAGEWIDTH 0xA002 +#define TAG_EXIF_IMAGELENGTH 0xA003 + +/* the following is added 05-jan-2001 vcs */ +#define TAG_EXPOSURE_BIAS 0x9204 +#define TAG_WHITEBALANCE 0x9208 +#define TAG_METERING_MODE 0x9207 +#define TAG_EXPOSURE_PROGRAM 0x8822 +#define TAG_ISO_EQUIVALENT 0x8827 +#define TAG_COMPRESSION_LEVEL 0x9102 + +#define TAG_THUMBNAIL_OFFSET 0x0201 +#define TAG_THUMBNAIL_LENGTH 0x0202 + + +/*-------------------------------------------------------------------------- + Process one of the nested EXIF directories. +--------------------------------------------------------------------------*/ +bool CxImageJPG::CxExifInfo::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, + EXIFINFO * const m_exifinfo, unsigned char ** const LastExifRefdP ) +{ + int de; + int a; + int NumDirEntries; + unsigned ThumbnailOffset = 0; + unsigned ThumbnailSize = 0; + + NumDirEntries = Get16u(DirStart); + + if ((DirStart+2+NumDirEntries*12) > (OffsetBase+ExifLength)){ + strcpy(m_szLastError,"Illegally sized directory"); + return false; + } + + for (de=0;de= NUM_FORMATS) { + /* (-1) catches illegal zero case as unsigned underflows to positive large */ + strcpy(m_szLastError,"Illegal format code in EXIF dir"); + return false; + } + + ByteCount = Components * BytesPerFormat[Format]; + + if (ByteCount > 4){ + unsigned OffsetVal; + OffsetVal = Get32u(DirEntry+8); + /* If its bigger than 4 bytes, the dir entry contains an offset.*/ + if (OffsetVal+ByteCount > ExifLength){ + /* Bogus pointer offset and / or bytecount value */ + strcpy(m_szLastError,"Illegal pointer offset value in EXIF."); + return false; + } + ValuePtr = OffsetBase+OffsetVal; + }else{ + /* 4 bytes or less and value is in the dir entry itself */ + ValuePtr = DirEntry+8; + } + + if (*LastExifRefdP < ValuePtr+ByteCount){ + /* Keep track of last byte in the exif header that was + actually referenced. That way, we know where the + discardable thumbnail data begins. + */ + *LastExifRefdP = ValuePtr+ByteCount; + } + + /* Extract useful components of tag */ + switch(Tag){ + + case TAG_MAKE: + strncpy(m_exifinfo->CameraMake, (char*)ValuePtr, 31); + break; + + case TAG_MODEL: + strncpy(m_exifinfo->CameraModel, (char*)ValuePtr, 39); + break; + + case TAG_EXIF_VERSION: + strncpy(m_exifinfo->Version,(char*)ValuePtr, 4); + break; + + case TAG_DATETIME_ORIGINAL: + strncpy(m_exifinfo->DateTime, (char*)ValuePtr, 19); + break; + + case TAG_USERCOMMENT: + // Olympus has this padded with trailing spaces. Remove these first. + for (a=ByteCount;;){ + a--; + if (((char*)ValuePtr)[a] == ' '){ + ((char*)ValuePtr)[a] = '\0'; + }else{ + break; + } + if (a == 0) break; + } + + /* Copy the comment */ + if (memcmp(ValuePtr, "ASCII",5) == 0){ + for (a=5;a<10;a++){ + char c; + c = ((char*)ValuePtr)[a]; + if (c != '\0' && c != ' '){ + strncpy(m_exifinfo->Comments, (char*)ValuePtr+a, 199); + break; + } + } + + }else{ + strncpy(m_exifinfo->Comments, (char*)ValuePtr, 199); + } + break; + + case TAG_FNUMBER: + /* Simplest way of expressing aperture, so I trust it the most. + (overwrite previously computd value if there is one) + */ + m_exifinfo->ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_APERTURE: + case TAG_MAXAPERTURE: + /* More relevant info always comes earlier, so only + use this field if we don't have appropriate aperture + information yet. + */ + if (m_exifinfo->ApertureFNumber == 0){ + m_exifinfo->ApertureFNumber = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0f)*0.5); + } + break; + + case TAG_BRIGHTNESS: + m_exifinfo->Brightness = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_FOCALLENGTH: + /* Nice digital cameras actually save the focal length + as a function of how farthey are zoomed in. + */ + + m_exifinfo->FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_SUBJECT_DISTANCE: + /* Inidcates the distacne the autofocus camera is focused to. + Tends to be less accurate as distance increases. + */ + m_exifinfo->Distance = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXPOSURETIME: + /* Simplest way of expressing exposure time, so I + trust it most. (overwrite previously computd value + if there is one) + */ + m_exifinfo->ExposureTime = + (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_SHUTTERSPEED: + /* More complicated way of expressing exposure time, + so only use this value if we don't already have it + from somewhere else. + */ + if (m_exifinfo->ExposureTime == 0){ + m_exifinfo->ExposureTime = (float) + (1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0f))); + } + break; + + case TAG_FLASH: + if ((int)ConvertAnyFormat(ValuePtr, Format) & 7){ + m_exifinfo->FlashUsed = 1; + }else{ + m_exifinfo->FlashUsed = 0; + } + break; + + case TAG_ORIENTATION: + m_exifinfo->Orientation = (int)ConvertAnyFormat(ValuePtr, Format); + if (m_exifinfo->Orientation < 1 || m_exifinfo->Orientation > 8){ + strcpy(m_szLastError,"Undefined rotation value"); + m_exifinfo->Orientation = 0; + } + break; + + case TAG_EXIF_IMAGELENGTH: + case TAG_EXIF_IMAGEWIDTH: + /* Use largest of height and width to deal with images + that have been rotated to portrait format. + */ + a = (int)ConvertAnyFormat(ValuePtr, Format); + if (ExifImageWidth < a) ExifImageWidth = a; + break; + + case TAG_FOCALPLANEXRES: + m_exifinfo->FocalplaneXRes = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_FOCALPLANEYRES: + m_exifinfo->FocalplaneYRes = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_RESOLUTIONUNIT: + switch((int)ConvertAnyFormat(ValuePtr, Format)){ + case 1: m_exifinfo->ResolutionUnit = 1.0f; break; /* 1 inch */ + case 2: m_exifinfo->ResolutionUnit = 1.0f; break; + case 3: m_exifinfo->ResolutionUnit = 0.3937007874f; break; /* 1 centimeter*/ + case 4: m_exifinfo->ResolutionUnit = 0.03937007874f; break; /* 1 millimeter*/ + case 5: m_exifinfo->ResolutionUnit = 0.00003937007874f; /* 1 micrometer*/ + } + break; + + case TAG_FOCALPLANEUNITS: + switch((int)ConvertAnyFormat(ValuePtr, Format)){ + case 1: m_exifinfo->FocalplaneUnits = 1.0f; break; /* 1 inch */ + case 2: m_exifinfo->FocalplaneUnits = 1.0f; break; + case 3: m_exifinfo->FocalplaneUnits = 0.3937007874f; break; /* 1 centimeter*/ + case 4: m_exifinfo->FocalplaneUnits = 0.03937007874f; break; /* 1 millimeter*/ + case 5: m_exifinfo->FocalplaneUnits = 0.00003937007874f; /* 1 micrometer*/ + } + break; + + // Remaining cases contributed by: Volker C. Schoech + + case TAG_EXPOSURE_BIAS: + m_exifinfo->ExposureBias = (float) ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_WHITEBALANCE: + m_exifinfo->Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_METERING_MODE: + m_exifinfo->MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXPOSURE_PROGRAM: + m_exifinfo->ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_ISO_EQUIVALENT: + m_exifinfo->ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); + if ( m_exifinfo->ISOequivalent < 50 ) m_exifinfo->ISOequivalent *= 200; + break; + + case TAG_COMPRESSION_LEVEL: + m_exifinfo->CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_XRESOLUTION: + m_exifinfo->Xresolution = (float)ConvertAnyFormat(ValuePtr, Format); + break; + case TAG_YRESOLUTION: + m_exifinfo->Yresolution = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_THUMBNAIL_OFFSET: + ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_THUMBNAIL_LENGTH: + ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); + break; + + } + + if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ + unsigned char * SubdirStart; + unsigned Offset = Get32u(ValuePtr); + if (Offset>8){ + SubdirStart = OffsetBase + Offset; + if (SubdirStart < OffsetBase || + SubdirStart > OffsetBase+ExifLength){ + strcpy(m_szLastError,"Illegal subdirectory link"); + return false; + } + ProcessExifDir(SubdirStart, OffsetBase, ExifLength, m_exifinfo, LastExifRefdP); + } + continue; + } + } + + + { + /* In addition to linking to subdirectories via exif tags, + there's also a potential link to another directory at the end + of each directory. This has got to be the result of a + committee! + */ + unsigned char * SubdirStart; + unsigned Offset; + Offset = Get16u(DirStart+2+12*NumDirEntries); + if (Offset){ + SubdirStart = OffsetBase + Offset; + if (SubdirStart < OffsetBase + || SubdirStart > OffsetBase+ExifLength){ + strcpy(m_szLastError,"Illegal subdirectory link"); + return false; + } + ProcessExifDir(SubdirStart, OffsetBase, ExifLength, m_exifinfo, LastExifRefdP); + } + } + + + if (ThumbnailSize && ThumbnailOffset){ + if (ThumbnailSize + ThumbnailOffset <= ExifLength){ + /* The thumbnail pointer appears to be valid. Store it. */ + m_exifinfo->ThumbnailPointer = OffsetBase + ThumbnailOffset; + m_exifinfo->ThumbnailSize = ThumbnailSize; + } + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/*-------------------------------------------------------------------------- + Evaluate number, be it int, rational, or float from directory. +--------------------------------------------------------------------------*/ +double CxImageJPG::CxExifInfo::ConvertAnyFormat(void * ValuePtr, int Format) +{ + double Value; + Value = 0; + + switch(Format){ + case FMT_SBYTE: Value = *(signed char *)ValuePtr; break; + case FMT_BYTE: Value = *(unsigned char *)ValuePtr; break; + + case FMT_USHORT: Value = Get16u(ValuePtr); break; + case FMT_ULONG: Value = Get32u(ValuePtr); break; + + case FMT_URATIONAL: + case FMT_SRATIONAL: + { + int Num,Den; + Num = Get32s(ValuePtr); + Den = Get32s(4+(char *)ValuePtr); + if (Den == 0){ + Value = 0; + }else{ + Value = (double)Num/Den; + } + break; + } + + case FMT_SSHORT: Value = (signed short)Get16u(ValuePtr); break; + case FMT_SLONG: Value = Get32s(ValuePtr); break; + + /* Not sure if this is correct (never seen float used in Exif format) + */ + case FMT_SINGLE: Value = (double)*(float *)ValuePtr; break; + case FMT_DOUBLE: Value = *(double *)ValuePtr; break; + } + return Value; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageJPG::CxExifInfo::process_COM (const BYTE * Data, int length) +{ + int ch; + char Comment[MAX_COMMENT+1]; + int nch; + int a; + + nch = 0; + + if (length > MAX_COMMENT) length = MAX_COMMENT; // Truncate if it won't fit in our structure. + + for (a=2;aComments,Comment); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageJPG::CxExifInfo::process_SOFn (const BYTE * Data, int marker) +{ + int data_precision, num_components; + + data_precision = Data[2]; + m_exifinfo->Height = Get16m((void*)(Data+3)); + m_exifinfo->Width = Get16m((void*)(Data+5)); + num_components = Data[7]; + + if (num_components == 3){ + m_exifinfo->IsColor = 1; + }else{ + m_exifinfo->IsColor = 0; + } + + m_exifinfo->Process = marker; + + //if (ShowTags) printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", + // ImageInfo.Width, ImageInfo.Height, num_components, data_precision); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * this will work only on a CxImageJPG object, if the image originally has valid EXIF data + \verbatim + CxImageJPG jpg; + CxIOFile in,out; + in.Open("D:\\exif_in.jpg","rb"); + out.Open("D:\\exif_out.jpg","w+b"); + jpg.Decode(&in); + if (jpg.IsValid()){ + jpg.RotateLeft(); + jpg.Encode(&out); + } + \endverbatim +*/ +bool CxImageJPG::CxExifInfo::EncodeExif(CxFile * hFile) +{ + int a; + + if (FindSection(M_SOS)==NULL){ + strcpy(m_szLastError,"Can't write exif : didn't read all"); + return false; + } + + // Initial static jpeg marker. + hFile->PutC(0xff); + hFile->PutC(0xd8); + + if (Sections[0].Type != M_EXIF && Sections[0].Type != M_JFIF){ + // The image must start with an exif or jfif marker. If we threw those away, create one. + static BYTE JfifHead[18] = { + 0xff, M_JFIF, + 0x00, 0x10, 'J' , 'F' , 'I' , 'F' , 0x00, 0x01, + 0x01, 0x01, 0x01, 0x2C, 0x01, 0x2C, 0x00, 0x00 + }; + hFile->Write(JfifHead, 18, 1); + } + + // Write all the misc sections + for (a=0;aPutC(0xff); + hFile->PutC(Sections[a].Type); + hFile->Write(Sections[a].Data, Sections[a].Size, 1); + } + + // Write the remaining image data. + hFile->Write(Sections[a].Data, Sections[a].Size, 1); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageJPG::CxExifInfo::DiscardAllButExif() +{ + Section_t ExifKeeper; + Section_t CommentKeeper; + int a; + + memset(&ExifKeeper, 0, sizeof(ExifKeeper)); + memset(&CommentKeeper, 0, sizeof(ExifKeeper)); + + for (a=0;a Use it before Create() + */ +void CxImage::CopyInfo(const CxImage &src) +{ + if (pDib==NULL) memcpy(&info,&src.info,sizeof(CXIMAGEINFO)); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \sa Copy + */ +CxImage& CxImage::operator = (const CxImage& isrc) +{ + if (this != &isrc) Copy(isrc); + return *this; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Initializes or rebuilds the image. + * \param dwWidth: width + * \param dwHeight: height + * \param wBpp: bit per pixel, can be 1, 4, 8, 24 + * \param imagetype: (optional) set the image format, see ENUM_CXIMAGE_FORMATS + * \return pointer to the internal pDib object; NULL if an error occurs. + */ +void* CxImage::Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype) +{ + // destroy the existing image (if any) + if (!Destroy()) + return NULL; + + // prevent further actions if width or height are not vaild + if ((dwWidth == 0) || (dwHeight == 0)){ + strcpy(info.szLastError,"CxImage::Create : width and height must be greater than zero"); + return NULL; + } + + // Make sure bits per pixel is valid + if (wBpp <= 1) wBpp = 1; + else if (wBpp <= 4) wBpp = 4; + else if (wBpp <= 8) wBpp = 8; + else wBpp = 24; + + // limit memory requirements (and also a check for bad parameters) + if (((dwWidth*dwHeight*wBpp)>>8) > CXIMAGE_MAX_MEMORY){ + strcpy(info.szLastError,"CXIMAGE_MAX_MEMORY exceeded"); + return NULL; + } + + // set the correct bpp value + switch (wBpp){ + case 1: + head.biClrUsed = 2; break; + case 4: + head.biClrUsed = 16; break; + case 8: + head.biClrUsed = 256; break; + default: + head.biClrUsed = 0; + } + + //set the common image informations + info.dwEffWidth = ((((wBpp * dwWidth) + 31) / 32) * 4); + info.dwType = imagetype; + + // initialize BITMAPINFOHEADER + head.biSize = sizeof(BITMAPINFOHEADER); // + head.biWidth = dwWidth; // fill in width from parameter + head.biHeight = dwHeight; // fill in height from parameter + head.biPlanes = 1; // must be 1 + head.biBitCount = (WORD)wBpp; // from parameter + head.biCompression = BI_RGB; + head.biSizeImage = info.dwEffWidth * dwHeight; +// head.biXPelsPerMeter = 0; See SetXDPI +// head.biYPelsPerMeter = 0; See SetYDPI + head.biClrImportant = 0; + + pDib = malloc(GetSize()); // alloc memory block to store our bitmap + if (!pDib){ + strcpy(info.szLastError,"CxImage::Create can't allocate memory"); + return NULL; + } + + //clear the palette + RGBQUAD* pal=GetPalette(); + if (pal) memset(pal,0,GetPaletteSize()); + //Destroy the existing selection +#if CXIMAGE_SUPPORT_SELECTION + if (pSelection) SelectionDelete(); +#endif //CXIMAGE_SUPPORT_SELECTION + //Destroy the existing alpha channel +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha) AlphaDelete(); +#endif //CXIMAGE_SUPPORT_ALPHA + + // use our bitmap info structure to fill in first part of + // our DIB with the BITMAPINFOHEADER + BITMAPINFOHEADER* lpbi; + lpbi = (BITMAPINFOHEADER*)(pDib); + *lpbi = head; + + info.pImage=GetBits(); + + return pDib; //return handle to the DIB +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return pointer to the image pixels. USE CAREFULLY + */ +BYTE* CxImage::GetBits(DWORD row) +{ + if (pDib){ + if (row) { + if (row<(DWORD)head.biHeight){ + return ((BYTE*)pDib + *(DWORD*)pDib + GetPaletteSize() + (info.dwEffWidth * row)); + } else { + return NULL; + } + } else { + return ((BYTE*)pDib + *(DWORD*)pDib + GetPaletteSize()); + } + } + return NULL; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return the size in bytes of the internal pDib object + */ +long CxImage::GetSize() +{ + return head.biSize + head.biSizeImage + GetPaletteSize(); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Checks if the coordinates are inside the image + * \return true if x and y are both inside the image + */ +bool CxImage::IsInside(long x, long y) +{ + return (0<=y && y 0) bval = 255; + } + if (GetBpp() == 4){ + bval = (BYTE)(17*(0x0F & bval)); + } + + memset(info.pImage,bval,head.biSizeImage); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Transfers the image from an existing source image. The source becomes empty. + * \return true if everything is ok + */ +bool CxImage::Transfer(CxImage &from) +{ + if (!Destroy()) + return false; + + memcpy(&head,&from.head,sizeof(BITMAPINFOHEADER)); + memcpy(&info,&from.info,sizeof(CXIMAGEINFO)); + + pDib = from.pDib; + pSelection = from.pSelection; + pAlpha = from.pAlpha; + pLayers = from.pLayers; + + memset(&from.head,0,sizeof(BITMAPINFOHEADER)); + memset(&from.info,0,sizeof(CXIMAGEINFO)); + from.pDib = from.pSelection = from.pAlpha = NULL; + from.pLayers = NULL; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * (this) points to the same pDib owned by (*from), the image remains in (*from) + * but (this) has the access to the pixels. Use carefully !!! + */ +void CxImage::Ghost(CxImage *from) +{ + if (from){ + memcpy(&head,&from->head,sizeof(BITMAPINFOHEADER)); + memcpy(&info,&from->info,sizeof(CXIMAGEINFO)); + pDib = from->pDib; + pSelection = from->pSelection; + pAlpha = from->pAlpha; + pLayers = from->pLayers; + info.pGhost=from; + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * turns a 16 or 32 bit bitfield image into a RGB image + */ +void CxImage::Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp) +{ + switch (bpp){ + case 16: + { + DWORD ns[3]={0,0,0}; + // compute the number of shift for each mask + for (int i=0;i<16;i++){ + if ((redmask>>i)&0x01) ns[0]++; + if ((greenmask>>i)&0x01) ns[1]++; + if ((bluemask>>i)&0x01) ns[2]++; + } + ns[1]+=ns[0]; ns[2]+=ns[1]; ns[0]=8-ns[0]; ns[1]-=8; ns[2]-=8; + // dword aligned width for 16 bit image + long effwidth2=(((head.biWidth + 1) / 2) * 4); + WORD w; + long y2,y3,x2,x3; + BYTE *p=info.pImage; + // scan the buffer in reverse direction to avoid reallocations + for (long y=head.biHeight-1; y>=0; y--){ + y2=effwidth2*y; + y3=info.dwEffWidth*y; + for (long x=head.biWidth-1; x>=0; x--){ + x2 = 2*x+y2; + x3 = 3*x+y3; + w = (WORD)(src[x2]+256*src[1+x2]); + p[ x3]=(BYTE)((w & bluemask)<>ns[1]); + p[2+x3]=(BYTE)((w & redmask)>>ns[2]); + } + } + break; + } + case 32: + { + // dword aligned width for 32 bit image + long effwidth4 = head.biWidth * 4; + long y4,y3,x4,x3; + BYTE *p=info.pImage; + // scan the buffer in reverse direction to avoid reallocations + for (long y=head.biHeight-1; y>=0; y--){ + y4=effwidth4*y; + y3=info.dwEffWidth*y; + for (long x=head.biWidth-1; x>=0; x--){ + x4 = 4*x+y4; + x3 = 3*x+y3; + p[ x3]=src[ x4]; + p[1+x3]=src[1+x4]; + p[2+x3]=src[2+x4]; + } + } + } + + } + return; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Creates an image from a generic buffer + * \param pArray: source memory buffer + * \param dwWidth: image width + * \param dwHeight: image height + * \param dwBitsperpixel: can be 1,4,8,24,32 + * \param dwBytesperline: line alignment, in bytes, for a single row stored in pArray + * \param bFlipImage: tune this parameter if the image is upsidedown + * \return true if everything is ok + */ +bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage) +{ + if (pArray==NULL) return false; + if (!((dwBitsperpixel==1)||(dwBitsperpixel==4)||(dwBitsperpixel==8)|| + (dwBitsperpixel==24)||(dwBitsperpixel==32))) return false; + + if (!Create(dwWidth,dwHeight,dwBitsperpixel)) return false; + + if (dwBitsperpixel<24) SetGrayPalette(); + +#if CXIMAGE_SUPPORT_ALPHA + if (dwBitsperpixel==32) AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + + BYTE *dst,*src; + + for (DWORD y = 0; yrgbRed,c1->rgbGreen,c1->rgbBlue); + int g2 = (int)RGB2GRAY(c2->rgbRed,c2->rgbGreen,c2->rgbBlue); + + return (g1-g2); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * simply calls "if (memblock) free(memblock);". + * Useful when calling Encode for a memory buffer, + * from a DLL compiled with different memory management options. + * CxImage::FreeMemory will use the same memory environment used by Encode. + */ +void CxImage::FreeMemory(void* memblock) +{ + if (memblock) + free(memblock); +} +//////////////////////////////////////////////////////////////////////////////// +//EOF diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximage.h ./win32/dependencies/cximage/ximage.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximage.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximage.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,648 @@ +/* + * File: ximage.h + * Purpose: General Purpose Image Class + */ +/* + -------------------------------------------------------------------------------- + + COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + + CxImage version 5.99c 17/Oct/2004 + + CxImage : Copyright (C) 2001 - 2004, Davide Pizzolato + + Original CImage and CImageIterator implementation are: + Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx) + + Covered code is provided under this license on an "as is" basis, without warranty + of any kind, either expressed or implied, including, without limitation, warranties + that the covered code is free of defects, merchantable, fit for a particular purpose + or non-infringing. The entire risk as to the quality and performance of the covered + code is with you. Should any covered code prove defective in any respect, you (not + the initial developer or any other contributor) assume the cost of any necessary + servicing, repair or correction. This disclaimer of warranty constitutes an essential + part of this license. No use of any covered code is authorized hereunder except under + this disclaimer. + + Permission is hereby granted to use, copy, modify, and distribute this + source code, or portions hereof, for any purpose, including commercial applications, + freely and without fee, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. + + -------------------------------------------------------------------------------- + + Other information: about CxImage, and the latest version, can be found at the + CxImage home page: http://www.xdp.it + + -------------------------------------------------------------------------------- + */ +#if !defined(__CXIMAGE_H) +#define __CXIMAGE_H + +#if _MSC_VER > 1000 +#pragma once +#endif + +///////////////////////////////////////////////////////////////////////////// +#include "xfile.h" +#include "xiofile.h" +#include "xmemfile.h" +#include "ximadef.h" // adjust some #define + +/* see "ximacfg.h" for CxImage configuration options */ + +///////////////////////////////////////////////////////////////////////////// +// CxImage formats enumerator +enum ENUM_CXIMAGE_FORMATS{ +CXIMAGE_FORMAT_UNKNOWN, +#if CXIMAGE_SUPPORT_BMP +CXIMAGE_FORMAT_BMP, +#endif +#if CXIMAGE_SUPPORT_GIF +CXIMAGE_FORMAT_GIF, +#endif +#if CXIMAGE_SUPPORT_JPG +CXIMAGE_FORMAT_JPG, +#endif +#if CXIMAGE_SUPPORT_PNG +CXIMAGE_FORMAT_PNG, +#endif +#if CXIMAGE_SUPPORT_MNG +CXIMAGE_FORMAT_MNG, +#endif +#if CXIMAGE_SUPPORT_ICO +CXIMAGE_FORMAT_ICO, +#endif +#if CXIMAGE_SUPPORT_TIF +CXIMAGE_FORMAT_TIF, +#endif +#if CXIMAGE_SUPPORT_TGA +CXIMAGE_FORMAT_TGA, +#endif +#if CXIMAGE_SUPPORT_PCX +CXIMAGE_FORMAT_PCX, +#endif +#if CXIMAGE_SUPPORT_WBMP +CXIMAGE_FORMAT_WBMP, +#endif +#if CXIMAGE_SUPPORT_WMF +CXIMAGE_FORMAT_WMF, +#endif +#if CXIMAGE_SUPPORT_J2K +CXIMAGE_FORMAT_J2K, +#endif +#if CXIMAGE_SUPPORT_JBG +CXIMAGE_FORMAT_JBG, +#endif +#if CXIMAGE_SUPPORT_JP2 +CXIMAGE_FORMAT_JP2, +#endif +#if CXIMAGE_SUPPORT_JPC +CXIMAGE_FORMAT_JPC, +#endif +#if CXIMAGE_SUPPORT_PGX +CXIMAGE_FORMAT_PGX, +#endif +#if CXIMAGE_SUPPORT_PNM +CXIMAGE_FORMAT_PNM, +#endif +#if CXIMAGE_SUPPORT_RAS +CXIMAGE_FORMAT_RAS, +#endif +CMAX_IMAGE_FORMATS +}; + +///////////////////////////////////////////////////////////////////////////// +// CxImage class +///////////////////////////////////////////////////////////////////////////// +class DLL_EXP CxImage +{ +//extensible information collector +typedef struct tagCxImageInfo { + DWORD dwEffWidth; ///< DWORD aligned scan line width + BYTE* pImage; ///< THE IMAGE BITS + CxImage* pGhost; ///< if this is a ghost, pGhost points to the body + CxImage* pParent; ///< if this is a layer, pParent points to the body + DWORD dwType; ///< original image format + char szLastError[256]; ///< debugging + long nProgress; ///< monitor + long nEscape; ///< escape + long nBkgndIndex; ///< used for GIF, PNG, MNG + RGBQUAD nBkgndColor; ///< used for RGB transparency + BYTE nQuality; ///< used for JPEG + BYTE nJpegScale; ///< used for JPEG [ignacio] + long nFrame; ///< used for TIF, GIF, MNG : actual frame + long nNumFrames; ///< used for TIF, GIF, MNG : total number of frames + DWORD dwFrameDelay; ///< used for GIF, MNG + long xDPI; ///< horizontal resolution + long yDPI; ///< vertical resolution + RECT rSelectionBox; ///< bounding rectangle + BYTE nAlphaMax; ///< max opacity (fade) + bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled. + bool bEnabled; ///< enables the painting functions + long xOffset; + long yOffset; + DWORD dwCodecOpt[CMAX_IMAGE_FORMATS]; ///< for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg + RGBQUAD last_c; ///< for GetNearestIndex optimization + BYTE last_c_index; + bool last_c_isvalid; + long nNumLayers; + DWORD dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags + +} CXIMAGEINFO; + +public: + //public structures +struct rgb_color { BYTE r,g,b; }; + +#if CXIMAGE_SUPPORT_WINDOWS +// text placement data +// members must be initialized with the InitTextInfo(&this) function. +typedef struct tagCxTextInfo +{ + TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M]) + LOGFONT lfont; ///< font and codepage data + COLORREF fcolor; ///< foreground color + long align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text + BYTE opaque; ///< text has background or hasn't. Default is true. + ///< data for background (ignored if .opaque==FALSE) + COLORREF bcolor; ///< background color + float b_opacity; ///< opacity value for background between 0.0-1.0 Default is 0. (opaque) + BYTE b_outline; ///< outline width for background (zero: no outline) + BYTE b_round; ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10. + ///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.) +} CXTEXTINFO; +#endif + +public: +/** \addtogroup Constructors */ //@{ + CxImage(DWORD imagetype = 0); + CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); + CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); + CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR + CxImage(FILE * stream, DWORD imagetype); + CxImage(CxFile * stream, DWORD imagetype); + CxImage(BYTE * buffer, DWORD size, DWORD imagetype); + virtual ~CxImage() { Destroy(); }; + CxImage& operator = (const CxImage&); +//@} + +/** \addtogroup Initialization */ //@{ + void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); + bool Destroy(); + void Clear(BYTE bval=0); + void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); + bool Transfer(CxImage &from); + bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); + bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); + void FreeMemory(void* memblock); +//@} + +/** \addtogroup Attributes */ //@{ + long GetSize(); + BYTE* GetBits(DWORD row = 0); + BYTE GetColorType(); + void* GetDIB() const; + DWORD GetHeight() const; + DWORD GetWidth() const; + DWORD GetEffWidth() const; + DWORD GetNumColors() const; + WORD GetBpp() const; + DWORD GetType() const; + const char* GetLastError(); + const TCHAR* GetVersion(); + const float GetVersionNumber(); + + DWORD GetFrameDelay() const; + void SetFrameDelay(DWORD d); + + void GetOffset(long *x,long *y); + void SetOffset(long x,long y); + + BYTE GetJpegQuality() const; + void SetJpegQuality(BYTE q); + + BYTE GetJpegScale() const; + void SetJpegScale(BYTE q); + + long GetXDPI() const; + long GetYDPI() const; + void SetXDPI(long dpi); + void SetYDPI(long dpi); + + DWORD GetClrImportant() const; + void SetClrImportant(DWORD ncolors = 0); + + long GetProgress() const; + long GetEscape() const; + void SetProgress(long p); + void SetEscape(long i); + + long GetTransIndex() const; + RGBQUAD GetTransColor(); + void SetTransIndex(long idx); + void SetTransColor(RGBQUAD rgb); + bool IsTransparent() const; + + DWORD GetCodecOption(DWORD imagetype = 0); + bool SetCodecOption(DWORD opt, DWORD imagetype = 0); + + DWORD GetFlags() const; + void SetFlags(DWORD flags, bool bLockReservedFlags = true); + + //void* GetUserData() const {return info.pUserData;} + //void SetUserData(void* pUserData) {info.pUserData = pUserData;} +//@} + +/** \addtogroup Palette + * These functions have no effects on RGB images and in this case the returned value is always 0. + * @{ */ + bool IsGrayScale(); + bool IsIndexed() const; + bool IsSamePalette(CxImage &img, bool bCheckAlpha = true); + DWORD GetPaletteSize(); + RGBQUAD* GetPalette() const; + RGBQUAD GetPaletteColor(BYTE idx); + bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b); + BYTE GetNearestIndex(RGBQUAD c); + void BlendPalette(COLORREF cr,long perc); + void SetGrayPalette(); + void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b); + void SetPalette(RGBQUAD* pPal,DWORD nColors=256); + void SetPalette(rgb_color *rgb,DWORD nColors=256); + void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0); + void SetPaletteColor(BYTE idx, RGBQUAD c); + void SetPaletteColor(BYTE idx, COLORREF cr); + void SwapIndex(BYTE idx1, BYTE idx2); + void SetStdPalette(); +//@} + +/** \addtogroup Pixel */ //@{ + bool IsInside(long x, long y); + bool IsTransparent(long x,long y); + RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true); + BYTE GetPixelIndex(long x,long y); + BYTE GetPixelGray(long x, long y); + void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false); + void SetPixelColor(long x,long y,COLORREF cr); + void SetPixelIndex(long x,long y,BYTE i); + void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false); + void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr); + void BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha = false); +//@} + +protected: +/** \addtogroup Protected */ //@{ + BYTE BlindGetPixelIndex(const long x,const long y); + RGBQUAD BlindGetPixelColor(const long x,const long y); + void *BlindGetPixelPointer(const long x,const long y); +//@} + +public: + +#if CXIMAGE_SUPPORT_INTERPOLATION +/** \addtogroup Interpolation */ //@{ + //overflow methods: + enum OverflowMethod { + OM_COLOR=1, + OM_BACKGROUND=2, + OM_TRANSPARENT=3, + OM_WRAP=4, + OM_REPEAT=5, + OM_MIRROR=6 + }; + void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod); + void OverflowCoordinates(long &x, long &y, OverflowMethod const ofMethod); + RGBQUAD GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0); + //interpolation methods: + enum InterpolationMethod { + IM_NEAREST_NEIGHBOUR=1, + IM_BILINEAR =2, + IM_BSPLINE =3, + IM_BICUBIC =4, + IM_BICUBIC2 =5, + IM_LANCZOS =6, + IM_BOX =7, + IM_HERMITE =8, + IM_HAMMING =9, + IM_SINC =10, + IM_BLACKMAN =11, + IM_BESSEL =12, + IM_GAUSSIAN =13, + IM_QUADRATIC =14, + IM_MITCHELL =15, + IM_CATROM =16 + }; + RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0); + RGBQUAD GetAreaColorInterpolated(float const xc, float const yc, float const w, float const h, InterpolationMethod const inMethod, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0); +//@} + +protected: +/** \addtogroup Protected */ //@{ + void AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa); +//@} + +/** \addtogroup Kernels */ //@{ +public: + static float KernelBSpline(const float x); + static float KernelLinear(const float t); + static float KernelCubic(const float t); + static float KernelGeneralizedCubic(const float t, const float a=-1); + static float KernelLanczosSinc(const float t, const float r = 3); + static float KernelBox(const float x); + static float KernelHermite(const float x); + static float KernelHamming(const float x); + static float KernelSinc(const float x); + static float KernelBlackman(const float x); + static float KernelBessel_J1(const float x); + static float KernelBessel_P1(const float x); + static float KernelBessel_Q1(const float x); + static float KernelBessel_Order1(float x); + static float KernelBessel(const float x); + static float KernelGaussian(const float x); + static float KernelQuadratic(const float x); + static float KernelMitchell(const float x); + static float KernelCatrom(const float x); +//@} +#endif //CXIMAGE_SUPPORT_INTERPOLATION + +/** \addtogroup Painting */ //@{ +#if CXIMAGE_SUPPORT_WINCE + long Blt(HDC pDC, long x=0, long y=0); +#endif +#if CXIMAGE_SUPPORT_WINDOWS + HBITMAP MakeBitmap(HDC hdc = NULL); + HANDLE CopyToHandle(); + bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard) + bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource + bool CreateFromHICON(HICON hico); + long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false); + long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false); + long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY); + long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY); + long Tile(HDC hdc, RECT *rc); + long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1); + long Draw2(HDC hdc, const RECT& rect); + //long DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); + long DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); + // extensions + long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false ); + void InitTextInfo( CXTEXTINFO *txt ); +#endif //CXIMAGE_SUPPORT_WINDOWS +//@} + + // file operations +#if CXIMAGE_SUPPORT_DECODE +/** \addtogroup Decode */ //@{ +#ifdef WIN32 + //bool Load(LPCWSTR filename, DWORD imagetype=0); + bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL); +#endif + // For UNICODE support: char -> TCHAR + bool Load(const TCHAR* filename, DWORD imagetype=0); + //bool Load(const char * filename, DWORD imagetype=0); + bool Decode(FILE * hFile, DWORD imagetype); + bool Decode(CxFile * hFile, DWORD imagetype); + bool Decode(BYTE * buffer, DWORD size, DWORD imagetype); +//@} +#endif //CXIMAGE_SUPPORT_DECODE + +#if CXIMAGE_SUPPORT_ENCODE +protected: +/** \addtogroup Protected */ //@{ + bool EncodeSafeCheck(CxFile *hFile); +//@} + +public: +/** \addtogroup Encode */ //@{ +#ifdef WIN32 + //bool Save(LPCWSTR filename, DWORD imagetype=0); +#endif + // For UNICODE support: char -> TCHAR + bool Save(const TCHAR* filename, DWORD imagetype); + //bool Save(const char * filename, DWORD imagetype=0); + bool Encode(FILE * hFile, DWORD imagetype); + bool Encode(CxFile * hFile, DWORD imagetype); + bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype); + bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype); + bool Encode(BYTE * &buffer, long &size, DWORD imagetype); + + bool Encode2RGBA(CxFile *hFile); + bool Encode2RGBA(BYTE * &buffer, long &size); +//@} +#endif //CXIMAGE_SUPPORT_ENCODE + +/** \addtogroup Attributes */ //@{ + //misc. + bool IsValid() const; + bool IsEnabled() const; + void Enable(bool enable=true); + + // frame operations + long GetNumFrames() const; + long GetFrame() const; + void SetFrame(long nFrame); +//@} + +#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS +/** \addtogroup BasicTransformations */ //@{ + bool GrayScale(); + bool Flip(); + bool Mirror(); + bool Negative(); + bool RotateLeft(CxImage* iDst = NULL); + bool RotateRight(CxImage* iDst = NULL); +//@} +#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS + +#if CXIMAGE_SUPPORT_TRANSFORMATION +/** \addtogroup Transformations */ //@{ + // image operations + bool Rotate(float angle, CxImage* iDst = NULL); + bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR, + OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0, + bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false); + bool Rotate180(CxImage* iDst = NULL); + bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL); + bool Resample2(long newx, long newy, InterpolationMethod const inMethod=IM_BICUBIC2, + OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL, + bool const disableAveraging=false); + bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0); + bool IncreaseBpp(DWORD nbit); + bool Dither(long method = 0); + bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL); + bool Crop(const RECT& rect, CxImage* iDst = NULL); + bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL); + bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0, bool bEnableInterpolation = false); + bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0); + bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); + bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); + bool CircleTransform(int type,long rmax=0,float Koeff=1.0f); + bool RedEyeRemove(); + bool QIShrink(long newx, long newy, CxImage* const iDst = NULL); +//@} +#endif //CXIMAGE_SUPPORT_TRANSFORMATION + +#if CXIMAGE_SUPPORT_DSP +/** \addtogroup DSP */ //@{ + bool Contour(); + bool HistogramStretch(long method = 0); + bool HistogramEqualize(); + bool HistogramNormalize(); + bool HistogramRoot(); + bool HistogramLog(); + long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0); + bool Jitter(long radius=2); + bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0); + bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0); + bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true); + bool Noise(long level); + bool Median(long Ksize=3); + bool Gamma(float gamma); + bool ShiftRGB(long r, long g, long b); + bool Threshold(BYTE level); + bool Colorize(BYTE hue, BYTE sat, float blend = 1.0f); + bool Light(long brightness, long contrast = 0); + float Mean(); + bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset); + bool Erode(long Ksize=2); + bool Dilate(long Ksize=2); + bool Edge(long Ksize=2); + void HuePalette(float correction=1); + enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen }; + void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0, bool bMixAlpha = false); + void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset); + bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0); + bool Lut(BYTE* pLut); + bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0); +//@} + +protected: +/** \addtogroup Protected */ //@{ + bool IsPowerof2(long x); + bool FFT(int dir,int m,double *x,double *y); + bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2); + bool RepairChannel(CxImage *ch, float radius); + // + int gen_convolve_matrix (float radius, float **cmatrix_p); + float* gen_lookup_table (float *cmatrix, int cmatrix_length); + void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes); +//@} + +public: +/** \addtogroup ColorSpace */ //@{ + bool SplitRGB(CxImage* r,CxImage* g,CxImage* b); + bool SplitYUV(CxImage* y,CxImage* u,CxImage* v); + bool SplitHSL(CxImage* h,CxImage* s,CxImage* l); + bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q); + bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z); + bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k); + static RGBQUAD HSLtoRGB(COLORREF cHSLColor); + static RGBQUAD RGBtoHSL(RGBQUAD lRGBColor); + static RGBQUAD HSLtoRGB(RGBQUAD lHSLColor); + static RGBQUAD YUVtoRGB(RGBQUAD lYUVColor); + static RGBQUAD RGBtoYUV(RGBQUAD lRGBColor); + static RGBQUAD YIQtoRGB(RGBQUAD lYIQColor); + static RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor); + static RGBQUAD XYZtoRGB(RGBQUAD lXYZColor); + static RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor); +#endif //CXIMAGE_SUPPORT_DSP + static RGBQUAD RGBtoRGBQUAD(COLORREF cr); + static COLORREF RGBQUADtoRGB (RGBQUAD c); +//@} + +#if CXIMAGE_SUPPORT_SELECTION +/** \addtogroup Selection */ //@{ + bool SelectionClear(); + bool SelectionCreate(); + bool SelectionDelete(); + bool SelectionInvert(); + bool SelectionAddRect(RECT r); + bool SelectionAddEllipse(RECT r); + bool SelectionAddPolygon(POINT *points, long npoints); + bool SelectionAddColor(RGBQUAD c); + bool SelectionAddPixel(int x, int y); + bool SelectionCopy(CxImage &from); + bool SelectionIsInside(long x, long y); + bool SelectionIsValid(); + void SelectionGetBox(RECT& r); + bool SelectionToHRGN(HRGN& region); + bool SelectionSplit(CxImage *dest); +//@} +#endif //CXIMAGE_SUPPORT_SELECTION + +#if CXIMAGE_SUPPORT_ALPHA +/** \addtogroup Alpha */ //@{ + void AlphaClear(); + void AlphaCreate(); + void AlphaDelete(); + void AlphaInvert(); + bool AlphaMirror(); + bool AlphaFlip(); + bool AlphaCopy(CxImage &from); + bool AlphaSplit(CxImage *dest); + void AlphaStrip(); + void AlphaSet(BYTE level); + bool AlphaSet(CxImage &from); + void AlphaSet(const long x,const long y,const BYTE level); + BYTE AlphaGet(const long x,const long y); + BYTE AlphaGetMax() const; + void AlphaSetMax(BYTE nAlphaMax); + bool AlphaIsValid(); + BYTE* AlphaGetPointer(const long x = 0,const long y = 0); + + void AlphaPaletteClear(); + void AlphaPaletteEnable(bool enable=true); + bool AlphaPaletteIsEnabled(); + bool AlphaPaletteIsValid(); + bool AlphaPaletteSplit(CxImage *dest); +//@} + +protected: +/** \addtogroup Protected */ //@{ + BYTE BlindAlphaGet(const long x,const long y); +//@} +#endif //CXIMAGE_SUPPORT_ALPHA + +public: +#if CXIMAGE_SUPPORT_LAYERS +/** \addtogroup Layers */ //@{ + bool LayerCreate(long position = -1); + bool LayerDelete(long position = -1); + void LayerDeleteAll(); + CxImage* GetLayer(long position); + CxImage* GetParent() const; + long GetNumLayers() const; +//@} +#endif //CXIMAGE_SUPPORT_LAYERS + +protected: +/** \addtogroup Protected */ //@{ + void Startup(DWORD imagetype = 0); + void CopyInfo(const CxImage &src); + void Ghost(CxImage *src); + void RGBtoBGR(BYTE *buffer, int length); + static float HueToRGB(float n1,float n2, float hue); + void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp); + static int CompareColors(const void *elem1, const void *elem2); + + void* pDib; //contains the header, the palette, the pixels + BITMAPINFOHEADER head; //standard header + CXIMAGEINFO info; //extended information + BYTE* pSelection; //selected region + BYTE* pAlpha; //alpha channel + CxImage** pLayers; //generic layers +//@} +}; + +//////////////////////////////////////////////////////////////////////////// +#endif // !defined(__CXIMAGE_H) diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximagif.cpp ./win32/dependencies/cximage/ximagif.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximagif.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximagif.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,1564 @@ +/* + * File: ximagif.cpp + * Purpose: Platform Independent GIF Image Class Loader and Writer + * 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximagif.h" + +#if CXIMAGE_SUPPORT_GIF + +#include "ximaiter.h" + +#if CXIMAGE_SUPPORT_WINCE + #define assert(s) +#else + #include +#endif + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageGIF::Decode(CxFile *fp) +{ + /* AD - for transparency */ + struct_dscgif dscgif; + struct_image image; + struct_TabCol TabCol; + + if (fp == NULL) return false; + + fp->Read(&dscgif,/*sizeof(dscgif)*/13,1); + //if (strncmp(dscgif.header,"GIF8",3)!=0) { + if (strncmp(dscgif.header,"GIF8",4)!=0) return FALSE; + + if (info.nEscape == -1) { + // Return output dimensions only + head.biWidth = dscgif.scrwidth; + head.biHeight = dscgif.scrheight; + return true; + } + + /* AD - for interlace */ + TabCol.sogct = (short)(1 << ((dscgif.pflds & 0x07)+1)); + TabCol.colres = (short)(((dscgif.pflds & 0x70) >> 3) + 1); + + // assume that the image is a truecolor-gif if + // 1) no global color map found + // 2) (image.w, image.h) of the 1st image != (dscgif.scrwidth, dscgif.scrheight) + long bTrueColor=0; + CxImage* imaRGB=NULL; + + // Global colour map? + if (dscgif.pflds & 0x80) + fp->Read(TabCol.paleta,sizeof(struct rgb_color)*TabCol.sogct,1); + else + bTrueColor++; //first chance for a truecolor gif + + long first_transparent_index; + + int iImage = 0; + info.nNumFrames=get_num_frames(fp,&TabCol,&dscgif); + + if ((info.nFrame<0)||(info.nFrame>=info.nNumFrames)) return false; + + //it cannot be a true color GIF with only one frame + if (info.nNumFrames == 1) + bTrueColor=0; + + char ch; + bool bPreviousWasNull = true; + int prevdispmeth = 0; + + for (BOOL bContinue = TRUE; bContinue; ) + { + if (fp->Read(&ch, sizeof(ch), 1) != 1) {break;} + + if (info.nEscape > 0) return false; // - cancel decoding + if (bPreviousWasNull || ch==0) + { + switch (ch) + { + case '!': // extension + { + bContinue = DecodeExtension(fp); + break; + } + case ',': // image + { + assert(sizeof(image) == 9); + fp->Read(&image,sizeof(image),1); + //avoid byte order problems with Solaris + BYTE *byteData = (BYTE *) & image; + image.l = byteData[0]+byteData[1]*256; + image.t = byteData[2]+byteData[3]*256; + image.w = byteData[4]+byteData[5]*256; + image.h = byteData[6]+byteData[7]*256; + + if (((image.l + image.w) > dscgif.scrwidth)||((image.t + image.h) > dscgif.scrheight)) + break; + + // check if it could be a truecolor gif + if ((iImage==0) && (image.w != dscgif.scrwidth) && (image.h != dscgif.scrheight)) + bTrueColor++; + + // Local colour map? + if (image.pf & 0x80) { + TabCol.sogct = (short)(1 << ((image.pf & 0x07) +1)); + assert(3 == sizeof(struct rgb_color)); + fp->Read(TabCol.paleta,sizeof(struct rgb_color)*TabCol.sogct,1); + //log << "Local colour map" << endl; + } + + int bpp; // select the correct bit per pixel value + if (TabCol.sogct <= 2) bpp = 1; + else if (TabCol.sogct <= 16) bpp = 4; + else bpp = 8; + + CxImageGIF backimage; + backimage.CopyInfo(*this); + if (iImage==0){ + //first frame: build image background + backimage.Create(dscgif.scrwidth, dscgif.scrheight, bpp, CXIMAGE_FORMAT_GIF); + first_transparent_index = info.nBkgndIndex; + backimage.Clear((BYTE)gifgce.transpcolindex); + } else { + //generic frame: handle disposal method from previous one + /*Values : 0 - No disposal specified. The decoder is + not required to take any action. + 1 - Do not dispose. The graphic is to be left + in place. + 2 - Restore to background color. The area used by the + graphic must be restored to the background color. + 3 - Restore to previous. The decoder is required to + restore the area overwritten by the graphic with + what was there prior to rendering the graphic. + */ + backimage.Copy(*this); + if (prevdispmeth==2){ + backimage.Clear((BYTE)first_transparent_index); + } + } + + //active frame + Create(image.w, image.h, bpp, CXIMAGE_FORMAT_GIF); + + if ((image.pf & 0x80) || (dscgif.pflds & 0x80)) { + unsigned char r[256], g[256], b[256]; + int i, has_white = 0; + + for (i=0; i < TabCol.sogct; i++) { + r[i] = TabCol.paleta[i].r; + g[i] = TabCol.paleta[i].g; + b[i] = TabCol.paleta[i].b; + + if (RGB(r[i],g[i],b[i]) == 0xFFFFFF) has_white = 1; + } + + // Force transparency colour white... + //if (0) if (info.nBkgndIndex != -1) + // r[info.nBkgndIndex] = g[info.nBkgndIndex] = b[info.nBkgndIndex] = 255; + // Fill in with white // AD + if (info.nBkgndIndex != -1) { + while (i < 256) { + has_white = 1; + r[i] = g[i] = b[i] = 255; + i++; + } + } + + // Force last colour to white... // AD + //if ((info.nBkgndIndex != -1) && !has_white) { + // r[255] = g[255] = b[255] = 255; + //} + + SetPalette((info.nBkgndIndex != -1 ? 256 : TabCol.sogct), r, g, b); + } + + CImageIterator* iter = new CImageIterator(this); + iter->Upset(); + int badcode=0; + ibf = GIFBUFTAM+1; + + interlaced = image.pf & 0x40; + iheight = image.h; + istep = 8; + iypos = 0; + ipass = 0; + + long pos_start = fp->Tell(); + //if (interlaced) log << "Interlaced" << endl; + decoder(fp, iter, image.w, badcode); + delete iter; + + if (info.nEscape) return false; // - cancel decoding + + if (bTrueColor<2 ){ //standard GIF: mix frame with background + backimage.GifMix(*this,image); + backimage.SetTransIndex(first_transparent_index); + backimage.SetPalette(GetPalette()); + Transfer(backimage); + } else { //it's a truecolor gif! + //force full image decoding + info.nFrame=info.nNumFrames-1; + //build the RGB image + if (imaRGB==NULL) imaRGB = new CxImage(dscgif.scrwidth,dscgif.scrheight,24,CXIMAGE_FORMAT_GIF); + //copy the partial image into the full RGB image + for(long y=0;ySetPixelColor(x+image.l,dscgif.scrheight-1-image.t-y,GetPixelColor(x,image.h-y-1)); + } + } + } + + prevdispmeth = gifgce.dispmeth; + + //restore the correct position in the file for the next image + if (badcode){ + seek_next_image(fp,pos_start); + } else { + fp->Seek(-(ibfmax - ibf - 1), SEEK_CUR); + } + + if (info.nFrame==iImage) bContinue=false; else iImage++; + + break; + } + case ';': //terminator + bContinue=false; + break; + default: + bPreviousWasNull = (ch==0); + break; + } + } + } + + if (bTrueColor>=2 && imaRGB){ + if (gifgce.transpcolflag){ + imaRGB->SetTransColor(GetPaletteColor((BYTE)info.nBkgndIndex)); + imaRGB->SetTransIndex(0); + } + Transfer(*imaRGB); + } + delete imaRGB; + + return true; + +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageGIF::DecodeExtension(CxFile *fp) +{ + bool bContinue; + unsigned char count; + unsigned char fc; + + bContinue = (1 == fp->Read(&fc, sizeof(fc), 1)); + if (bContinue) { + /* AD - for transparency */ + if (fc == 0xF9) { + bContinue = (1 == fp->Read(&count, sizeof(count), 1)); + if (bContinue) { + assert(sizeof(gifgce) == 4); + bContinue = (count == fp->Read(&gifgce, 1, sizeof(gifgce))); + if (bContinue) { + if (gifgce.transpcolflag) info.nBkgndIndex = gifgce.transpcolindex; + info.dwFrameDelay = gifgce.delaytime; + m_dispmeth = gifgce.dispmeth; + } } } + + if (fc == 0xFE) { // Comment block + bContinue = (1 == fp->Read(&count, sizeof(count), 1)); + if (bContinue) { + bContinue = (1 == fp->Read(m_comment, count, 1)); + m_comment[count]='\0'; + } } + + if (fc == 0xFF) { // Application Extension block + bContinue = (1 == fp->Read(&count, sizeof(count), 1)); + if (bContinue) { + bContinue = (count==11); + if (bContinue){ + char AppID[11]; + bContinue = (1 == fp->Read(AppID, count, 1)); + if (bContinue) { + bContinue = (1 == fp->Read(&count, sizeof(count), 1)); + if (bContinue) { + BYTE* dati = (BYTE*)malloc(count); + bContinue = (dati!=NULL); + if (bContinue){ + bContinue = (1 == fp->Read(dati, count, 1)); + if (count>2){ + m_loops = dati[1]+256*dati[2]; + } + } + free(dati); + } } } } } + + while (bContinue && fp->Read(&count, sizeof(count), 1) && count) { + //log << "Skipping " << count << " bytes" << endl; + fp->Seek(count, SEEK_CUR); + } + } + return bContinue; + +} + + +// - This external (machine specific) function is expected to return +// either the next BYTE from the GIF file, or a negative error number. +int CxImageGIF::get_byte(CxFile* file) +{ + if (ibf>=GIFBUFTAM){ + // FW 06/02/98 >>> + ibfmax = file->Read( buf , 1 , GIFBUFTAM) ; + if( ibfmax < GIFBUFTAM ) buf[ ibfmax ] = 255 ; + // FW 06/02/98 <<< + ibf = 0; + } + if (ibf>=ibfmax) return -1; // avoid overflows + return buf[ibf++]; +} +//////////////////////////////////////////////////////////////////////////////// +/* - This function takes a full line of pixels (one BYTE per pixel) and + * displays them (or does whatever your program wants with them...). It + * should return zero, or negative if an error or some other event occurs + * which would require aborting the decode process... Note that the length + * passed will almost always be equal to the line length passed to the + * decoder function, with the sole exception occurring when an ending code + * occurs in an odd place in the GIF file... In any case, linelen will be + * equal to the number of pixels passed... +*/ +int CxImageGIF::out_line(CImageIterator* iter, unsigned char *pixels, int linelen) +{ + // for 1 & 4 bpp images, the pixels are compressed + if (head.biBitCount < 8){ + for(long x=0;x> 3); + if (head.biBitCount==4){ + pos = (BYTE)(4*(1-x%2)); + *iDst &= ~(0x0F<SetY(iheight-iypos-1); + iter->SetRow(pixels, linelen); + + if ((iypos += istep) >= iheight) { + do { + if (ipass++ > 0) istep /= 2; + iypos = istep / 2; + } + while (iypos > iheight); + } + return 0; + } else { + if (iter->ItOK()) { + iter->SetRow(pixels, linelen); + (void)iter->PrevRow(); + return 0; + } else { + // puts("chafeo"); + return -1; + } + } +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +// SaveFile - writes GIF87a gif file +// Randy Spann 6/15/97 +// R.Spann@ConnRiver.net +bool CxImageGIF::Encode(CxFile * fp) +{ + if (EncodeSafeCheck(fp)) return false; + + if(head.biBitCount > 8) { + //strcpy(info.szLastError,"GIF Images must be 8 bit or less"); + //return FALSE; + return EncodeRGB(fp); + } + + EncodeHeader(fp); + + EncodeExtension(fp); + + EncodeComment(fp); + + EncodeBody(fp); + + fp->PutC(';'); // Write the GIF file terminator + + return true; // done! +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageGIF::Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLocalColorMap) +{ + try{ + if (fp==NULL) throw "invalid file pointer"; + if (pImages==NULL || pagecount==0 || pImages[0]==NULL) throw "multipage GIF, no images!"; + + CxImageGIF ghost; + + //write the first image + ghost.Ghost(pImages[0]); + ghost.EncodeHeader(fp); + + if (m_loops!=1){ + ghost.SetLoops(max(0,m_loops-1)); + ghost.EncodeLoopExtension(fp); + } + + ghost.SetDisposalMethod(GetDisposalMethod()); + ghost.EncodeExtension(fp); + + EncodeComment(fp); + + ghost.EncodeBody(fp); + + for (int i=2; i<=pagecount; i++){ + if (pImages[i-1]==NULL) throw "Bad image pointer"; + ghost.Ghost(pImages[i-1]); + + ghost.SetDisposalMethod(GetDisposalMethod()); + ghost.EncodeExtension(fp); + + ghost.EncodeBody(fp,bLocalColorMap); + } + + fp->PutC(';'); // Write the GIF file terminator + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return false; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::EncodeHeader(CxFile *fp) +{ + fp->Write("GIF89a",1,6); //GIF Header + + Putword(head.biWidth,fp); //Logical screen descriptor + Putword(head.biHeight,fp); + + BYTE Flags; + if (head.biClrUsed==0){ + Flags=0x11; + } else { + Flags = 0x80; + Flags |=(head.biBitCount - 1) << 5; + Flags |=(head.biBitCount - 1); + } + + fp->PutC(Flags); //GIF "packed fields" + fp->PutC(0); //GIF "BackGround" + fp->PutC(0); //GIF "pixel aspect ratio" + + if (head.biClrUsed!=0){ + RGBQUAD* pPal = GetPalette(); + for(DWORD i=0; iPutC(pPal[i].rgbRed); + fp->PutC(pPal[i].rgbGreen); + fp->PutC(pPal[i].rgbBlue); + } + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::EncodeExtension(CxFile *fp) +{ + // TRK BEGIN : transparency + fp->PutC('!'); + fp->PutC(TRANSPARENCY_CODE); + + gifgce.transpcolflag = (info.nBkgndIndex != -1) ? 1 : 0; + gifgce.userinputflag = 0; + gifgce.dispmeth = m_dispmeth; + gifgce.res = 0; + gifgce.delaytime = (WORD)info.dwFrameDelay; + gifgce.transpcolindex = (BYTE)info.nBkgndIndex; + fp->PutC(sizeof(gifgce)); + fp->Write(&gifgce, sizeof(gifgce), 1); + fp->PutC(0); + // TRK END +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::EncodeLoopExtension(CxFile *fp) +{ + fp->PutC('!'); //byte 1 : 33 (hex 0x21) GIF Extension code + fp->PutC(255); //byte 2 : 255 (hex 0xFF) Application Extension Label + fp->PutC(11); //byte 3 : 11 (hex (0x0B) Length of Application Block (eleven bytes of data to follow) + fp->Write("NETSCAPE2.0",11,1); + fp->PutC(3); //byte 15 : 3 (hex 0x03) Length of Data Sub-Block (three bytes of data to follow) + fp->PutC(1); //byte 16 : 1 (hex 0x01) + Putword(m_loops,fp); //bytes 17 to 18 : 0 to 65535, an unsigned integer in lo-hi byte format. + //This indicate the number of iterations the loop should be executed. + fp->PutC(0); //bytes 19 : 0 (hex 0x00) a Data Sub-block Terminator. +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::EncodeBody(CxFile *fp, bool bLocalColorMap) +{ + curx = 0; + cury = head.biHeight - 1; //because we read the image bottom to top + CountDown = (long)head.biWidth * (long)head.biHeight; + + fp->PutC(','); + + Putword(info.xOffset,fp); + Putword(info.yOffset,fp); + Putword(head.biWidth,fp); + Putword(head.biHeight,fp); + + BYTE Flags=0x00; //non-interlaced (0x40 = interlaced) (0x80 = LocalColorMap) + if (bLocalColorMap) { Flags|=0x80; Flags|=head.biBitCount-1; } + fp->PutC(Flags); + + if (bLocalColorMap){ + Flags|=0x87; + RGBQUAD* pPal = GetPalette(); + for(DWORD i=0; iPutC(pPal[i].rgbRed); + fp->PutC(pPal[i].rgbGreen); + fp->PutC(pPal[i].rgbBlue); + } + } + + int InitCodeSize = head.biBitCount <=1 ? 2 : head.biBitCount; + // Write out the initial code size + fp->PutC((BYTE)InitCodeSize); + + // Go and actually compress the data + switch (GetCodecOption(CXIMAGE_FORMAT_GIF)) + { + case 1: //uncompressed + compressNONE(InitCodeSize+1, fp); + break; + case 2: //RLE + compressRLE(InitCodeSize+1, fp); + break; + default: //LZW + compressLZW(InitCodeSize+1, fp); + } + + // Write out a Zero-length packet (to end the series) + fp->PutC(0); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::EncodeComment(CxFile *fp) +{ + unsigned long n = (unsigned long) strlen(m_comment); + if (n>255) n=255; + if (n) { + fp->PutC('!'); //extension code: + fp->PutC(254); //comment extension + fp->PutC((BYTE)n); //size of comment + fp->Write(m_comment,n,1); + fp->PutC(0); //block terminator + } +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageGIF::EncodeRGB(CxFile *fp) +{ + EncodeHeader(fp); + +// EncodeLoopExtension(fp); + + EncodeComment(fp); + + unsigned long w,h; + w=h=0; + const long cellw = 17; + const long cellh = 15; + CxImageGIF tmp; + for (long y=0;yPutC(';'); // Write the GIF file terminator + + return true; // done! +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +// Return the next pixel from the image +// fix for 1 & 4 bpp images +int CxImageGIF::GifNextPixel( ) +{ + if( CountDown == 0 ) return EOF; + --CountDown; + int r = GetPixelIndex(curx,cury); + // Bump the current X position + ++curx; + if( curx == head.biWidth ){ + curx = 0; + cury--; //bottom to top + } + return r; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::Putword(int w, CxFile *fp ) +{ + fp->PutC((BYTE)(w & 0xff)); + fp->PutC((BYTE)((w / 256) & 0xff)); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::compressNONE( int init_bits, CxFile* outfile) +{ + register long c; + register long ent; + + // g_init_bits - initial number of bits + // g_outfile - pointer to output file + g_init_bits = init_bits; + g_outfile = outfile; + + // Set up the necessary values + cur_accum = cur_bits = clear_flg = 0; + maxcode = (short)MAXCODE(n_bits = g_init_bits); + code_int maxmaxcode = (code_int)1 << MAXBITSCODES; + + ClearCode = (1 << (init_bits - 1)); + EOFCode = ClearCode + 1; + free_ent = (short)(ClearCode + 2); + + a_count=0; + ent = GifNextPixel( ); + + output( (code_int)ClearCode ); + + while ( ent != EOF ) { + c = GifNextPixel(); + + output ( (code_int) ent ); + ent = c; + if ( free_ent < maxmaxcode ) { + free_ent++; + } else { + free_ent=(short)(ClearCode+2); + clear_flg=1; + output((code_int)ClearCode); + } + } + // Put out the final code. + output( (code_int) EOFCode ); +} +//////////////////////////////////////////////////////////////////////////////// + +/*************************************************************************** + * + * GIFCOMPR.C - LZW GIF Image compression routines + * + ***************************************************************************/ + +void CxImageGIF::compressLZW( int init_bits, CxFile* outfile) +{ + register long fcode; + register long c; + register long ent; + register long hshift; + register long disp; + register long i; + + // g_init_bits - initial number of bits + // g_outfile - pointer to output file + g_init_bits = init_bits; + g_outfile = outfile; + + // Set up the necessary values + cur_accum = cur_bits = clear_flg = 0; + maxcode = (short)MAXCODE(n_bits = g_init_bits); + code_int maxmaxcode = (code_int)1 << MAXBITSCODES; + + ClearCode = (1 << (init_bits - 1)); + EOFCode = ClearCode + 1; + free_ent = (short)(ClearCode + 2); + + a_count=0; + ent = GifNextPixel( ); + + hshift = 0; + for ( fcode = (long) HSIZE; fcode < 65536L; fcode *= 2L ) ++hshift; + hshift = 8 - hshift; /* set hash code range bound */ + cl_hash((long)HSIZE); /* clear hash table */ + output( (code_int)ClearCode ); + + while ( (c = GifNextPixel( )) != EOF ) { + + fcode = (long) (((long) c << MAXBITSCODES) + ent); + i = (((code_int)c << hshift) ^ ent); /* xor hashing */ + + if ( HashTabOf (i) == fcode ) { + ent = CodeTabOf (i); + continue; + } else if ( (long)HashTabOf (i) < 0 ) /* empty slot */ + goto nomatch; + disp = HSIZE - i; /* secondary hash (after G. Knott) */ + if ( i == 0 ) disp = 1; +probe: + if ( (i -= disp) < 0 ) i += HSIZE; + if ( HashTabOf (i) == fcode ) { ent = CodeTabOf (i); continue; } + if ( (long)HashTabOf (i) > 0 ) goto probe; +nomatch: + output ( (code_int) ent ); + ent = c; + if ( free_ent < maxmaxcode ) { + CodeTabOf (i) = free_ent++; /* code -> hashtable */ + HashTabOf (i) = fcode; + } else { + cl_hash((long)HSIZE); + free_ent=(short)(ClearCode+2); + clear_flg=1; + output((code_int)ClearCode); + } + } + // Put out the final code. + output( (code_int)ent ); + output( (code_int) EOFCode ); +} +//////////////////////////////////////////////////////////////////////////////// + +static const unsigned long code_mask[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, + 0x001F, 0x003F, 0x007F, 0x00FF, + 0x01FF, 0x03FF, 0x07FF, 0x0FFF, + 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; + +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::output( code_int code) +{ + cur_accum &= code_mask[ cur_bits ]; + + if( cur_bits > 0 ) + cur_accum |= ((long)code << cur_bits); + else + cur_accum = code; + + cur_bits += n_bits; + + while( cur_bits >= 8 ) { + char_out( (unsigned int)(cur_accum & 0xff) ); + cur_accum >>= 8; + cur_bits -= 8; + } + + /* + * If the next entry is going to be too big for the code size, + * then increase it, if possible. + */ + + if ( free_ent > maxcode || clear_flg ) { + if( clear_flg ) { + maxcode = (short)MAXCODE(n_bits = g_init_bits); + clear_flg = 0; + } else { + ++n_bits; + if ( n_bits == MAXBITSCODES ) + maxcode = (code_int)1 << MAXBITSCODES; /* should NEVER generate this code */ + else + maxcode = (short)MAXCODE(n_bits); + } + } + + if( code == EOFCode ) { + // At EOF, write the rest of the buffer. + while( cur_bits > 0 ) { + char_out( (unsigned int)(cur_accum & 0xff) ); + cur_accum >>= 8; + cur_bits -= 8; + } + + flush_char(); + g_outfile->Flush(); + + if(g_outfile->Error()) strcpy(info.szLastError,"Write Error in GIF file"); + } +} +//////////////////////////////////////////////////////////////////////////////// + +void CxImageGIF::cl_hash(register long hsize) + +{ + register long *htab_p = htab+hsize; + + register long i; + register long m1 = -1L; + + i = hsize - 16; + + do { + *(htab_p-16)=m1; + *(htab_p-15)=m1; + *(htab_p-14)=m1; + *(htab_p-13)=m1; + *(htab_p-12)=m1; + *(htab_p-11)=m1; + *(htab_p-10)=m1; + *(htab_p-9)=m1; + *(htab_p-8)=m1; + *(htab_p-7)=m1; + *(htab_p-6)=m1; + *(htab_p-5)=m1; + *(htab_p-4)=m1; + *(htab_p-3)=m1; + *(htab_p-2)=m1; + *(htab_p-1)=m1; + + htab_p-=16; + } while ((i-=16) >=0); + + for (i+=16;i>0;--i) + *--htab_p=m1; +} + +/******************************************************************************* +* GIF specific +*******************************************************************************/ + +void CxImageGIF::char_out(int c) +{ + accum[a_count++]=(char)c; + if (a_count >=254) + flush_char(); +} + +void CxImageGIF::flush_char() +{ + if (a_count > 0) { + g_outfile->PutC((BYTE)a_count); + g_outfile->Write(accum,1,a_count); + a_count=0; + } +} + +/******************************************************************************* +* GIF decoder +*******************************************************************************/ +/* DECODE.C - An LZW decoder for GIF + * Copyright (C) 1987, by Steven A. Bennett + * Copyright (C) 1994, C++ version by Alejandro Aguilar Sierra +* + * Permission is given by the author to freely redistribute and include + * this code in any program as long as this credit is given where due. + * + * In accordance with the above, I want to credit Steve Wilhite who wrote + * the code which this is heavily inspired by... + * + * GIF and 'Graphics Interchange Format' are trademarks (tm) of + * Compuserve, Incorporated, an H&R Block Company. + * + * Release Notes: This file contains a decoder routine for GIF images + * which is similar, structurally, to the original routine by Steve Wilhite. + * It is, however, somewhat noticably faster in most cases. + * + */ + +//////////////////////////////////////////////////////////////////////////////// + +short CxImageGIF::init_exp(short size) +{ + curr_size = (short)(size + 1); + top_slot = (short)(1 << curr_size); + clear = (short)(1 << size); + ending = (short)(clear + 1); + slot = newcodes = (short)(ending + 1); + navail_bytes = nbits_left = 0; + + memset(stack,0,MAX_CODES + 1); + memset(prefix,0,MAX_CODES + 1); + memset(suffix,0,MAX_CODES + 1); + return(0); +} +//////////////////////////////////////////////////////////////////////////////// + +/* get_next_code() + * - gets the next code from the GIF file. Returns the code, or else + * a negative number in case of file errors... + */ +short CxImageGIF::get_next_code(CxFile* file) +{ + short i, x; + DWORD ret; + + if (nbits_left == 0) { + if (navail_bytes <= 0) { + /* Out of bytes in current block, so read next block */ + pbytes = byte_buff; + if ((navail_bytes = (short)get_byte(file)) < 0) + return(navail_bytes); + else if (navail_bytes) { + for (i = 0; i < navail_bytes; ++i) { + if ((x = (short)get_byte(file)) < 0) return(x); + byte_buff[i] = (BYTE)x; + } + } + } + b1 = *pbytes++; + nbits_left = 8; + --navail_bytes; + } + + if (navail_bytes<0) return ending; // prevent deadlocks (thanks to Mike Melnikov) + + ret = b1 >> (8 - nbits_left); + while (curr_size > nbits_left){ + if (navail_bytes <= 0){ + /* Out of bytes in current block, so read next block*/ + pbytes = byte_buff; + if ((navail_bytes = (short)get_byte(file)) < 0) + return(navail_bytes); + else if (navail_bytes){ + for (i = 0; i < navail_bytes; ++i){ + if ((x = (short)get_byte(file)) < 0) return(x); + byte_buff[i] = (BYTE)x; + } + } + } + b1 = *pbytes++; + ret |= b1 << nbits_left; + nbits_left += 8; + --navail_bytes; + } + nbits_left = (short)(nbits_left-curr_size); + ret &= code_mask[curr_size]; + return((short)(ret)); +} +//////////////////////////////////////////////////////////////////////////////// + +/* short decoder(linewidth) + * short linewidth; * Pixels per line of image * + * + * - This function decodes an LZW image, according to the method used + * in the GIF spec. Every *linewidth* "characters" (ie. pixels) decoded + * will generate a call to out_line(), which is a user specific function + * to display a line of pixels. The function gets it's codes from + * get_next_code() which is responsible for reading blocks of data and + * seperating them into the proper size codes. Finally, get_byte() is + * the global routine to read the next BYTE from the GIF file. + * + * It is generally a good idea to have linewidth correspond to the actual + * width of a line (as specified in the Image header) to make your own + * code a bit simpler, but it isn't absolutely necessary. + * + * Returns: 0 if successful, else negative. (See ERRS.H) + * + */ +/* bad_code_count is incremented each time an out of range code is read. + * When this value is non-zero after a decode, your GIF file is probably + * corrupt in some way... + */ +short CxImageGIF::decoder(CxFile* file, CImageIterator* iter, short linewidth, int &bad_code_count) +{ + register BYTE *sp, *bufptr; + BYTE *buf; + register short code, fc, oc, bufcnt; + short c, size, ret; + + /* Initialize for decoding a new image... */ + bad_code_count = 0; + if ((size = (short)get_byte(file)) < 0) return(size); + if (size < 2 || 9 < size) return(BAD_CODE_SIZE); + // out_line = outline; + init_exp(size); + //printf("L %d %x\n",linewidth,size); + + /* Initialize in case they forgot to put in a clear code. + * (This shouldn't happen, but we'll try and decode it anyway...) + */ + oc = fc = 0; + + /* Allocate space for the decode buffer */ + if ((buf = new BYTE[linewidth + 1]) == NULL) return(OUT_OF_MEMORY); + + /* Set up the stack pointer and decode buffer pointer */ + sp = stack; + bufptr = buf; + bufcnt = linewidth; + + /* This is the main loop. For each code we get we pass through the + * linked list of prefix codes, pushing the corresponding "character" for + * each code onto the stack. When the list reaches a single "character" + * we push that on the stack too, and then start unstacking each + * character for output in the correct order. Special handling is + * included for the clear code, and the whole thing ends when we get + * an ending code. + */ + while ((c = get_next_code(file)) != ending) { + /* If we had a file error, return without completing the decode*/ + if (c < 0){ + delete[] buf; + return(0); + } + /* If the code is a clear code, reinitialize all necessary items.*/ + if (c == clear){ + curr_size = (short)(size + 1); + slot = newcodes; + top_slot = (short)(1 << curr_size); + + /* Continue reading codes until we get a non-clear code + * (Another unlikely, but possible case...) + */ + while ((c = get_next_code(file)) == clear); + + /* If we get an ending code immediately after a clear code + * (Yet another unlikely case), then break out of the loop. + */ + if (c == ending) break; + + /* Finally, if the code is beyond the range of already set codes, + * (This one had better NOT happen... I have no idea what will + * result from this, but I doubt it will look good...) then set it + * to color zero. + */ + if (c >= slot) c = 0; + oc = fc = c; + + /* And let us not forget to put the char into the buffer... And + * if, on the off chance, we were exactly one pixel from the end + * of the line, we have to send the buffer to the out_line() + * routine... + */ + *bufptr++ = (BYTE)c; + if (--bufcnt == 0) { + if ((ret = (short)out_line(iter, buf, linewidth)) < 0) { + delete[] buf; + return(ret); + } + bufptr = buf; + bufcnt = linewidth; + } + } else { + /* In this case, it's not a clear code or an ending code, so + * it must be a code code... So we can now decode the code into + * a stack of character codes. (Clear as mud, right?) + */ + code = c; + + /* Here we go again with one of those off chances... If, on the + * off chance, the code we got is beyond the range of those already + * set up (Another thing which had better NOT happen...) we trick + * the decoder into thinking it actually got the last code read. + * (Hmmn... I'm not sure why this works... But it does...) + */ + if (code >= slot) { + if (code > slot) ++bad_code_count; + code = oc; + *sp++ = (BYTE)fc; + } + + /* Here we scan back along the linked list of prefixes, pushing + * helpless characters (ie. suffixes) onto the stack as we do so. + */ + while (code >= newcodes) { + *sp++ = suffix[code]; + code = prefix[code]; + } + + /* Push the last character on the stack, and set up the new + * prefix and suffix, and if the required slot number is greater + * than that allowed by the current bit size, increase the bit + * size. (NOTE - If we are all full, we *don't* save the new + * suffix and prefix... I'm not certain if this is correct... + * it might be more proper to overwrite the last code... + */ + *sp++ = (BYTE)code; + if (slot < top_slot){ + suffix[slot] = (BYTE)(fc = (BYTE)code); + prefix[slot++] = oc; + oc = c; + } + if (slot >= top_slot){ + if (curr_size < 12) { + top_slot <<= 1; + ++curr_size; + } + } + + /* Now that we've pushed the decoded string (in reverse order) + * onto the stack, lets pop it off and put it into our decode + * buffer... And when the decode buffer is full, write another + * line... + */ + while (sp > stack) { + *bufptr++ = *(--sp); + if (--bufcnt == 0) { + if ((ret = (short)out_line(iter, buf, linewidth)) < 0) { + delete[] buf; + return(ret); + } + bufptr = buf; + bufcnt = linewidth; + } + } + } + } + ret = 0; + if (bufcnt != linewidth) + ret = (short)out_line(iter, buf, (linewidth - bufcnt)); + delete[] buf; + return(ret); +} +//////////////////////////////////////////////////////////////////////////////// +int CxImageGIF::get_num_frames(CxFile *fp,struct_TabCol* TabColSrc,struct_dscgif* dscgif) +{ + struct_image image; + + long pos=fp->Tell(); + int nframes=0; + + struct_TabCol TempTabCol; + memcpy(&TempTabCol,TabColSrc,sizeof(struct_TabCol)); + + char ch; + bool bPreviousWasNull = true; + + for (BOOL bContinue = TRUE; bContinue; ) + { + if (fp->Read(&ch, sizeof(ch), 1) != 1) {break;} + + if (bPreviousWasNull || ch==0) + { + switch (ch) + { + case '!': // extension + { + DecodeExtension(fp); + break; + } + case ',': // image + { + + assert(sizeof(image) == 9); + //log << "Image header" << endl; + fp->Read(&image,sizeof(image),1); + + //avoid byte order problems with Solaris + BYTE *byteData = (BYTE *) & image; + image.l = byteData[0]+byteData[1]*256; + image.t = byteData[2]+byteData[3]*256; + image.w = byteData[4]+byteData[5]*256; + image.h = byteData[6]+byteData[7]*256; + + if (((image.l + image.w) > dscgif->scrwidth)||((image.t + image.h) > dscgif->scrheight)) + break; + + nframes++; + + // Local colour map? + if (image.pf & 0x80) { + TempTabCol.sogct = (short)(1 << ((image.pf & 0x07) +1)); + assert(3 == sizeof(struct rgb_color)); + fp->Read(TempTabCol.paleta,sizeof(struct rgb_color)*TempTabCol.sogct,1); + //log << "Local colour map" << endl; + } + + int bpp; // select the correct bit per pixel value + if (TempTabCol.sogct <= 2) bpp = 1; + else if (TempTabCol.sogct <= 16) bpp = 4; + else bpp = 8; + + Create(image.w, image.h, bpp, CXIMAGE_FORMAT_GIF); + + CImageIterator* iter = new CImageIterator(this); + iter->Upset(); + int badcode=0; + ibf = GIFBUFTAM+1; + + interlaced = image.pf & 0x40; + iheight = image.h; + istep = 8; + iypos = 0; + ipass = 0; + + long pos_start = fp->Tell(); + + //if (interlaced) log << "Interlaced" << endl; + decoder(fp, iter, image.w, badcode); + delete iter; + + if (badcode){ + seek_next_image(fp,pos_start); + } else { + fp->Seek(-(ibfmax - ibf - 1), SEEK_CUR); + } + + break; + } + case ';': //terminator + bContinue=false; + break; + default: + bPreviousWasNull = (ch==0); + break; + } + } + } + + fp->Seek(pos,SEEK_SET); + return nframes; +} +//////////////////////////////////////////////////////////////////////////////// +long CxImageGIF::seek_next_image(CxFile* fp, long position) +{ + fp->Seek(position, SEEK_SET); + char ch1,ch2; + ch1=ch2=0; + while(fp->Read(&ch2,sizeof(char),1)>0){ + if (ch1 == 0 && ch2 == ','){ + fp->Seek(-1,SEEK_CUR); + return fp->Tell(); + } else { + ch1 = ch2; + } + } + return -1; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::SetDisposalMethod(int dm) +{ m_dispmeth=dm; } +//////////////////////////////////////////////////////////////////////////////// +long CxImageGIF::GetDisposalMethod() +{ return m_dispmeth; } +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::SetLoops(int loops) +{ m_loops=loops; } +//////////////////////////////////////////////////////////////////////////////// +long CxImageGIF::GetLoops() +{ return m_loops; } +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::SetComment(const char* sz_comment_in) +{ if (sz_comment_in) strncpy(m_comment,sz_comment_in,255); } +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::GetComment(char* sz_comment_out) +{ if (sz_comment_out) strncpy(sz_comment_out,m_comment,255); } +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::GifMix(CxImage & imgsrc2, struct_image & imgdesc) +{ + long ymin = max(0,(long)(GetHeight()-imgdesc.t - imgdesc.h)); + long ymax = GetHeight()-imgdesc.t; + long xmin = imgdesc.l; + long xmax = min(GetWidth(), (DWORD)(imgdesc.l + imgdesc.w)); + + long ibg2= imgsrc2.GetTransIndex(); + BYTE i2; + + for(long y = ymin; y < ymax; y++){ + for(long x = xmin; x < xmax; x++){ + i2 = imgsrc2.GetPixelIndex(x-xmin,y-ymin); + if(i2!=ibg2) SetPixelIndex(x,y,i2); + } + } +} +//////////////////////////////////////////////////////////////////////////////// +/*----------------------------------------------------------------------- + * + * miGIF Compression - mouse and ivo's GIF-compatible compression + * + * -run length encoding compression routines- + * + * Copyright (C) 1998 Hutchison Avenue Software Corporation + * http://www.hasc.com + * info@hasc.com + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. This software is provided "AS IS." The Hutchison Avenue + * Software Corporation disclaims all warranties, either express or implied, + * including but not limited to implied warranties of merchantability and + * fitness for a particular purpose, with respect to this code and accompanying + * documentation. + * + * The miGIF compression routines do not, strictly speaking, generate files + * conforming to the GIF spec, since the image data is not LZW-compressed + * (this is the point: in order to avoid transgression of the Unisys patent + * on the LZW algorithm.) However, miGIF generates data streams that any + * reasonably sane LZW decompresser will decompress to what we want. + * + * miGIF compression uses run length encoding. It compresses horizontal runs + * of pixels of the same color. This type of compression gives good results + * on images with many runs, for example images with lines, text and solid + * shapes on a solid-colored background. It gives little or no compression + * on images with few runs, for example digital or scanned photos. + * + * der Mouse + * mouse@rodents.montreal.qc.ca + * 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B + * + * ivo@hasc.com + * + * The Graphics Interchange Format(c) is the Copyright property of + * CompuServe Incorporated. GIF(sm) is a Service Mark property of + * CompuServe Incorporated. + * + */ +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_clear(struct_RLE* rle) +{ + rle->out_bits = rle->out_bits_init; + rle->out_bump = rle->out_bump_init; + rle->out_clear = rle->out_clear_init; + rle->out_count = 0; + rle->rl_table_max = 0; + rle->just_cleared = 1; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_flush(struct_RLE* rle) +{ + if (rle->rl_count == 1){ + rle_output_plain(rle->rl_pixel,rle); + rle->rl_count = 0; + return; + } + if (rle->just_cleared){ + rle_flush_fromclear(rle->rl_count,rle); + } else if ((rle->rl_table_max < 2) || (rle->rl_table_pixel != rle->rl_pixel)) { + rle_flush_clearorrep(rle->rl_count,rle); + } else { + rle_flush_withtable(rle->rl_count,rle); + } + rle->rl_count = 0; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_output_plain(int c,struct_RLE* rle) +{ + rle->just_cleared = 0; + rle_output(c,rle); + rle->out_count++; + if (rle->out_count >= rle->out_bump){ + rle->out_bits ++; + rle->out_bump += 1 << (rle->out_bits - 1); + } + if (rle->out_count >= rle->out_clear){ + rle_output(rle->code_clear,rle); + rle_clear(rle); + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_flush_fromclear(int count,struct_RLE* rle) +{ + int n; + + rle->out_clear = rle->max_ocodes; + rle->rl_table_pixel = rle->rl_pixel; + n = 1; + while (count > 0){ + if (n == 1){ + rle->rl_table_max = 1; + rle_output_plain(rle->rl_pixel,rle); + count --; + } else if (count >= n){ + rle->rl_table_max = n; + rle_output_plain(rle->rl_basecode+n-2,rle); + count -= n; + } else if (count == 1){ + rle->rl_table_max ++; + rle_output_plain(rle->rl_pixel,rle); + count = 0; + } else { + rle->rl_table_max ++; + rle_output_plain(rle->rl_basecode+count-2,rle); + count = 0; + } + if (rle->out_count == 0) n = 1; else n ++; + } + rle_reset_out_clear(rle); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_reset_out_clear(struct_RLE* rle) +{ + rle->out_clear = rle->out_clear_init; + if (rle->out_count >= rle->out_clear){ + rle_output(rle->code_clear,rle); + rle_clear(rle); + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_flush_withtable(int count, struct_RLE* rle) +{ + int repmax; + int repleft; + int leftover; + + repmax = count / rle->rl_table_max; + leftover = count % rle->rl_table_max; + repleft = (leftover ? 1 : 0); + if (rle->out_count+repmax+repleft > rle->max_ocodes){ + repmax = rle->max_ocodes - rle->out_count; + leftover = count - (repmax * rle->rl_table_max); + repleft = 1 + rle_compute_triangle_count(leftover,rle->max_ocodes); + } + if (1+rle_compute_triangle_count(count,rle->max_ocodes) < (unsigned int)(repmax+repleft)){ + rle_output(rle->code_clear,rle); + rle_clear(rle); + rle_flush_fromclear(count,rle); + return; + } + rle->out_clear = rle->max_ocodes; + for (;repmax>0;repmax--) rle_output_plain(rle->rl_basecode+rle->rl_table_max-2,rle); + if (leftover){ + if (rle->just_cleared){ + rle_flush_fromclear(leftover,rle); + } else if (leftover == 1){ + rle_output_plain(rle->rl_pixel,rle); + } else { + rle_output_plain(rle->rl_basecode+leftover-2,rle); + } + } + rle_reset_out_clear(rle); +} +//////////////////////////////////////////////////////////////////////////////// +unsigned int CxImageGIF::rle_compute_triangle_count(unsigned int count, unsigned int nrepcodes) +{ + unsigned int perrep; + unsigned int cost; + + cost = 0; + perrep = (nrepcodes * (nrepcodes+1)) / 2; + while (count >= perrep){ + cost += nrepcodes; + count -= perrep; + } + if (count > 0){ + unsigned int n; + n = rle_isqrt(count); + while ((n*(n+1)) >= 2*count) n --; + while ((n*(n+1)) < 2*count) n ++; + cost += n; + } + return(cost); +} +//////////////////////////////////////////////////////////////////////////////// +unsigned int CxImageGIF::rle_isqrt(unsigned int x) +{ + unsigned int r; + unsigned int v; + + if (x < 2) return(x); + for (v=x,r=1;v;v>>=2,r<<=1) ; + while (1){ + v = ((x / r) + r) / 2; + if ((v == r) || (v == r+1)) return(r); + r = v; + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_flush_clearorrep(int count, struct_RLE* rle) +{ + int withclr; + withclr = 1 + rle_compute_triangle_count(count,rle->max_ocodes); + if (withclr < count) { + rle_output(rle->code_clear,rle); + rle_clear(rle); + rle_flush_fromclear(count,rle); + } else { + for (;count>0;count--) rle_output_plain(rle->rl_pixel,rle); + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_write_block(struct_RLE* rle) +{ + g_outfile->PutC((BYTE)rle->oblen); + g_outfile->Write(rle->oblock,1,rle->oblen); + rle->oblen = 0; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_block_out(unsigned char c, struct_RLE* rle) +{ + rle->oblock[rle->oblen++] = c; + if (rle->oblen >= 255) rle_write_block(rle); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_block_flush(struct_RLE* rle) +{ + if (rle->oblen > 0) rle_write_block(rle); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_output(int val, struct_RLE* rle) +{ + rle->obuf |= val << rle->obits; + rle->obits += rle->out_bits; + while (rle->obits >= 8){ + rle_block_out(rle->obuf&0xff,rle); + rle->obuf >>= 8; + rle->obits -= 8; + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::rle_output_flush(struct_RLE* rle) +{ + if (rle->obits > 0) rle_block_out(rle->obuf,rle); + rle_block_flush(rle); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageGIF::compressRLE( int init_bits, CxFile* outfile) +{ + g_init_bits = init_bits; + g_outfile = outfile; + + struct_RLE rle; + rle.code_clear = 1 << (init_bits - 1); + rle.code_eof = rle.code_clear + 1; + rle.rl_basecode = rle.code_eof + 1; + rle.out_bump_init = (1 << (init_bits - 1)) - 1; + rle.out_clear_init = (init_bits <= 3) ? 9 : (rle.out_bump_init-1); + rle.out_bits_init = init_bits; + rle.max_ocodes = (1 << MAXBITSCODES) - ((1 << (rle.out_bits_init - 1)) + 3); + rle.rl_count = 0; + rle_clear(&rle); + rle.obuf = 0; + rle.obits = 0; + rle.oblen = 0; + + rle_output(rle.code_clear,&rle); + + int c; + while (1){ + c = GifNextPixel(); + if ((rle.rl_count > 0) && (c != rle.rl_pixel)) rle_flush(&rle); + if (c == EOF) break; + if (rle.rl_pixel == c){ + rle.rl_count++; + } else { + rle.rl_pixel = c; + rle.rl_count = 1; + } + } + rle_output(rle.code_eof,&rle); + rle_output_flush(&rle); +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_GIF diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximagif.h ./win32/dependencies/cximage/ximagif.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximagif.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximagif.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,248 @@ +/* + * File: ximagif.h + * Purpose: GIF Image Class Loader and Writer + */ +/* ========================================================== + * CxImageGIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * original CImageGIF and CImageIterator implementation are: + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * 6/15/97 Randy Spann: Added GIF87a writing support + * R.Spann@ConnRiver.net + * + * DECODE.C - An LZW decoder for GIF + * Copyright (C) 1987, by Steven A. Bennett + * Copyright (C) 1994, C++ version by Alejandro Aguilar Sierra + * + * In accordance with the above, I want to credit Steve Wilhite who wrote + * the code which this is heavily inspired by... + * + * GIF and 'Graphics Interchange Format' are trademarks (tm) of + * Compuserve, Incorporated, an H&R Block Company. + * + * Release Notes: This file contains a decoder routine for GIF images + * which is similar, structurally, to the original routine by Steve Wilhite. + * It is, however, somewhat noticably faster in most cases. + * + * ========================================================== + */ + +#if !defined(__ximaGIF_h) +#define __ximaGIF_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_GIF + +typedef short int code_int; + +/* Various error codes used by decoder */ +#define OUT_OF_MEMORY -10 +#define BAD_CODE_SIZE -20 +#define READ_ERROR -1 +#define WRITE_ERROR -2 +#define OPEN_ERROR -3 +#define CREATE_ERROR -4 +#define MAX_CODES 4095 +#define GIFBUFTAM 16383 +#define TRANSPARENCY_CODE 0xF9 + +//LZW GIF Image compression +#define MAXBITSCODES 12 +#define HSIZE 5003 /* 80% occupancy */ +#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) +#define HashTabOf(i) htab[i] +#define CodeTabOf(i) codetab[i] + + +class CImageIterator; +class DLL_EXP CxImageGIF: public CxImage +{ +#pragma pack(1) + +typedef struct tag_gifgce{ + BYTE transpcolflag:1; + BYTE userinputflag:1; + BYTE dispmeth:3; + BYTE res:3; + WORD delaytime; + BYTE transpcolindex; +} struct_gifgce; + +typedef struct tag_dscgif{ /* Logic Screen Descriptor */ + char header[6]; /* Firma and version */ + WORD scrwidth; + WORD scrheight; + char pflds; + char bcindx; + char pxasrat; +} struct_dscgif; + +typedef struct tag_image{ /* Image Descriptor */ + WORD l; + WORD t; + WORD w; + WORD h; + BYTE pf; +} struct_image; + +typedef struct tag_TabCol{ /* Tabla de colores */ + short colres; /* color resolution */ + short sogct; /* size of global color table */ + rgb_color paleta[256]; /* paleta */ +} struct_TabCol; + +typedef struct tag_RLE{ + int rl_pixel; + int rl_basecode; + int rl_count; + int rl_table_pixel; + int rl_table_max; + int just_cleared; + int out_bits; + int out_bits_init; + int out_count; + int out_bump; + int out_bump_init; + int out_clear; + int out_clear_init; + int max_ocodes; + int code_clear; + int code_eof; + unsigned int obuf; + int obits; + unsigned char oblock[256]; + int oblen; +} struct_RLE; +#pragma pack() + +public: + CxImageGIF(): CxImage(CXIMAGE_FORMAT_GIF) {m_loops=0; m_dispmeth=0; m_comment[0]='\0';} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_GIF);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_GIF);} + + bool Decode(CxFile * fp); + bool Decode(FILE *fp) { CxIOFile file(fp); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * fp); + bool Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false); + bool Encode(FILE *fp) { CxIOFile file(fp); return Encode(&file); } + bool Encode(FILE *fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false) + { CxIOFile file(fp); return Encode(&file, pImages, pagecount, bLocalColorMap); } +#endif // CXIMAGE_SUPPORT_ENCODE + + void SetLoops(int loops); + long GetLoops(); + void SetComment(const char* sz_comment_in); + void GetComment(char* sz_comment_out); + void SetDisposalMethod(int dm); + long GetDisposalMethod(); + +protected: + bool DecodeExtension(CxFile *fp); + void EncodeHeader(CxFile *fp); + void EncodeLoopExtension(CxFile *fp); + void EncodeExtension(CxFile *fp); + void EncodeBody(CxFile *fp, bool bLocalColorMap = false); + void EncodeComment(CxFile *fp); + bool EncodeRGB(CxFile *fp); + void GifMix(CxImage & imgsrc2, struct_image & imgdesc); + + struct_gifgce gifgce; + + int curx, cury; + long CountDown; + unsigned long cur_accum; + int cur_bits; + int interlaced, iypos, istep, iheight, ipass; + int ibf; + int ibfmax; + BYTE buf[GIFBUFTAM + 1]; +// Implementation + int GifNextPixel (); + void Putword (int w, CxFile* fp ); + void compressNONE (int init_bits, CxFile* outfile); + void compressLZW (int init_bits, CxFile* outfile); + void output (code_int code ); + void cl_hash (long hsize); + void char_out (int c); + void flush_char (); + short init_exp(short size); + short get_next_code(CxFile*); + short decoder(CxFile*, CImageIterator* iter, short linewidth, int &bad_code_count); + int get_byte(CxFile*); + int out_line(CImageIterator* iter, unsigned char *pixels, int linelen); + int get_num_frames(CxFile *f,struct_TabCol* TabColSrc,struct_dscgif* dscgif); + long seek_next_image(CxFile* fp, long position); + + short curr_size; /* The current code size */ + short clear; /* Value for a clear code */ + short ending; /* Value for a ending code */ + short newcodes; /* First available code */ + short top_slot; /* Highest code for current size */ + short slot; /* Last read code */ + + /* The following static variables are used + * for seperating out codes */ + short navail_bytes; /* # bytes left in block */ + short nbits_left; /* # bits left in current BYTE */ + BYTE b1; /* Current BYTE */ + BYTE byte_buff[257]; /* Current block */ + BYTE *pbytes; /* Pointer to next BYTE in block */ + /* The reason we have these seperated like this instead of using + * a structure like the original Wilhite code did, is because this + * stuff generally produces significantly faster code when compiled... + * This code is full of similar speedups... (For a good book on writing + * C for speed or for space optomisation, see Efficient C by Tom Plum, + * published by Plum-Hall Associates...) + */ + BYTE stack[MAX_CODES + 1]; /* Stack for storing pixels */ + BYTE suffix[MAX_CODES + 1]; /* Suffix table */ + WORD prefix[MAX_CODES + 1]; /* Prefix linked list */ + +//LZW GIF Image compression routines + long htab [HSIZE]; + unsigned short codetab [HSIZE]; + int n_bits; /* number of bits/code */ + code_int maxcode; /* maximum code, given n_bits */ + code_int free_ent; /* first unused entry */ + int clear_flg; + int g_init_bits; + CxFile* g_outfile; + int ClearCode; + int EOFCode; + + int a_count; + char accum[256]; + + char m_comment[256]; + int m_loops; + int m_dispmeth; + +//RLE compression routines + void compressRLE( int init_bits, CxFile* outfile); + void rle_clear(struct_RLE* rle); + void rle_flush(struct_RLE* rle); + void rle_flush_withtable(int count, struct_RLE* rle); + void rle_flush_clearorrep(int count, struct_RLE* rle); + void rle_flush_fromclear(int count,struct_RLE* rle); + void rle_output_plain(int c,struct_RLE* rle); + void rle_reset_out_clear(struct_RLE* rle); + unsigned int rle_compute_triangle_count(unsigned int count, unsigned int nrepcodes); + unsigned int rle_isqrt(unsigned int x); + void rle_write_block(struct_RLE* rle); + void rle_block_out(unsigned char c, struct_RLE* rle); + void rle_block_flush(struct_RLE* rle); + void rle_output(int val, struct_RLE* rle); + void rle_output_flush(struct_RLE* rle); +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximahist.cpp ./win32/dependencies/cximage/ximahist.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximahist.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximahist.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,649 @@ +// xImaHist.cpp : histogram functions +/* 28/01/2004 v1.00 - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_DSP + +//////////////////////////////////////////////////////////////////////////////// +long CxImage::Histogram(long* red, long* green, long* blue, long* gray, long colorspace) +{ + if (!pDib) return 0; + RGBQUAD color; + + if (red) memset(red,0,256*sizeof(long)); + if (green) memset(green,0,256*sizeof(long)); + if (blue) memset(blue,0,256*sizeof(long)); + if (gray) memset(gray,0,256*sizeof(long)); + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; yn) n=red[i]; + if (green && green[i]>n) n=green[i]; + if (blue && blue[i]>n) n=blue[i]; + if (gray && gray[i]>n) n=gray[i]; + } + + return n; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * HistogramStretch + * \param method: 0 = luminance (default), 1 = linked channels , 2 = independent channels. + * \return true if everything is ok + * \author [dave] and [nipper] + */ +bool CxImage::HistogramStretch(long method) +{ + if (!pDib) return false; + + if ((head.biBitCount==8) && IsGrayScale()){ + // get min/max info + BYTE minc = 255, maxc = 0; + BYTE gray; + long y; + + double dbScaler = 50.0/head.biHeight; + + for (y=0; y maxc) maxc = gray; + } + } + + if (minc == 0 && maxc == 255) return true; + + // calculate LUT + BYTE lut[256]; + BYTE range = maxc - minc; + if (range != 0){ + for (long x = minc; x <= maxc; x++){ + lut[x] = (BYTE)(255 * (x - minc) / range); + } + } else lut[minc] = minc; + + for (y=0; y + // get min/max info + BYTE minc = 255, maxc = 0; + RGBQUAD color; + long y; + + for (y=0; y maxc) maxc = color.rgbRed; + if (color.rgbBlue > maxc) maxc = color.rgbBlue; + if (color.rgbGreen > maxc) maxc = color.rgbGreen; + } + } + + if (minc == 0 && maxc == 255) + return true; + + // calculate LUT + BYTE lut[256]; + BYTE range = maxc - minc; + + if (range != 0){ + for (long x = minc; x <= maxc; x++){ + lut[x] = (BYTE)(255 * (x - minc) / range); + } + } else lut[minc] = minc; + + // normalize image + double dbScaler = 100.0/head.biHeight; + + for (y=0; y + // get min/max info + BYTE minR = 255, maxR = 0; + BYTE minG = 255, maxG = 0; + BYTE minB = 255, maxB = 0; + RGBQUAD color; + long y; + + for (y=0; y maxR) maxR = color.rgbRed; + if (color.rgbBlue > maxB) maxB = color.rgbBlue; + if (color.rgbGreen > maxG) maxG = color.rgbGreen; + } + } + + if (minR == 0 && maxR == 255 && minG == 0 && maxG == 255 && minB == 0 && maxB == 255) + return true; + + // calculate LUT + BYTE lutR[256]; + BYTE range = maxR - minR; + if (range != 0) { + for (long x = minR; x <= maxR; x++){ + lutR[x] = (BYTE)(255 * (x - minR) / range); + } + } else lutR[minR] = minR; + + BYTE lutG[256]; + range = maxG - minG; + if (range != 0) { + for (long x = minG; x <= maxG; x++){ + lutG[x] = (BYTE)(255 * (x - minG) / range); + } + } else lutG[minG] = minG; + + BYTE lutB[256]; + range = maxB - minB; + if (range != 0) { + for (long x = minB; x <= maxB; x++){ + lutB[x] = (BYTE)(255 * (x - minB) / range); + } + } else lutB[minB] = minB; + + // normalize image + double dbScaler = 100.0/head.biHeight; + + for (y=0; y + // S = ( R - C ) ( B - A / D - C ) + double alimit = 0.0; + double blimit = 255.0; + double lowerc = 255.0; + double upperd = 0.0; + double tmpGray; + + RGBQUAD color; + RGBQUAD yuvClr; + double stretcheds; + + if ( head.biClrUsed == 0 ){ + long x, y, xmin, xmax, ymin, ymax; + xmin = ymin = 0; + xmax = head.biWidth; + ymax = head.biHeight; + + for( y = ymin; y < ymax; y++ ){ + info.nProgress = (long)(50*y/ymax); + if (info.nEscape) break; + for( x = xmin; x < xmax; x++ ){ + color = GetPixelColor( x, y ); + tmpGray = RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if ( tmpGray < lowerc ) lowerc = tmpGray; + if ( tmpGray > upperd ) upperd = tmpGray; + } + } + if (upperd==lowerc) return false; + + for( y = ymin; y < ymax; y++ ){ + info.nProgress = (long)(50+50*y/ymax); + if (info.nEscape) break; + for( x = xmin; x < xmax; x++ ){ + + color = GetPixelColor( x, y ); + yuvClr = RGBtoYUV(color); + + // Stretch Luminance + tmpGray = (double)yuvClr.rgbRed; + stretcheds = (double)(tmpGray - lowerc) * ( (blimit - alimit) / (upperd - lowerc) ); // + alimit; + if ( stretcheds < 0.0 ) stretcheds = 0.0; + else if ( stretcheds > 255.0 ) stretcheds = 255.0; + yuvClr.rgbRed = (BYTE)stretcheds; + + color = YUVtoRGB(yuvClr); + SetPixelColor( x, y, color ); + } + } + } else { + DWORD j; + for( j = 0; j < head.biClrUsed; j++ ){ + color = GetPaletteColor( (BYTE)j ); + tmpGray = RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if ( tmpGray < lowerc ) lowerc = tmpGray; + if ( tmpGray > upperd ) upperd = tmpGray; + } + if (upperd==lowerc) return false; + + for( j = 0; j < head.biClrUsed; j++ ){ + + color = GetPaletteColor( (BYTE)j ); + yuvClr = RGBtoYUV( color ); + + // Stretch Luminance + tmpGray = (double)yuvClr.rgbRed; + stretcheds = (double)(tmpGray - lowerc) * ( (blimit - alimit) / (upperd - lowerc) ); // + alimit; + if ( stretcheds < 0.0 ) stretcheds = 0.0; + else if ( stretcheds > 255.0 ) stretcheds = 255.0; + yuvClr.rgbRed = (BYTE)stretcheds; + + color = YUVtoRGB(yuvClr); + SetPaletteColor( (BYTE)j, color ); + } + } + } + } + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +// HistogramEqualize function by : dave(at)posortho(dot)com +bool CxImage::HistogramEqualize() +{ + if (!pDib) return false; + + int histogram[256]; + int map[256]; + int equalize_map[256]; + int x, y, i, j; + RGBQUAD color; + RGBQUAD yuvClr; + unsigned int YVal, high, low; + + memset( &histogram, 0, sizeof(int) * 256 ); + memset( &map, 0, sizeof(int) * 256 ); + memset( &equalize_map, 0, sizeof(int) * 256 ); + + // form histogram + for(y=0; y < head.biHeight; y++){ + info.nProgress = (long)(50*y/head.biHeight); + if (info.nEscape) break; + for(x=0; x < head.biWidth; x++){ + color = GetPixelColor( x, y ); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + histogram[YVal]++; + } + } + + // integrate the histogram to get the equalization map. + j = 0; + for(i=0; i <= 255; i++){ + j += histogram[i]; + map[i] = j; + } + + // equalize + low = map[0]; + high = map[255]; + if (low == high) return false; + for( i = 0; i <= 255; i++ ){ + equalize_map[i] = (unsigned int)((((double)( map[i] - low ) ) * 255) / ( high - low ) ); + } + + // stretch the histogram + if(head.biClrUsed == 0){ // No Palette + for( y = 0; y < head.biHeight; y++ ){ + info.nProgress = (long)(50+50*y/head.biHeight); + if (info.nEscape) break; + for( x = 0; x < head.biWidth; x++ ){ + + color = GetPixelColor( x, y ); + yuvClr = RGBtoYUV(color); + + yuvClr.rgbRed = (BYTE)equalize_map[yuvClr.rgbRed]; + + color = YUVtoRGB(yuvClr); + SetPixelColor( x, y, color ); + } + } + } else { // Palette + for( i = 0; i < (int)head.biClrUsed; i++ ){ + + color = GetPaletteColor((BYTE)i); + yuvClr = RGBtoYUV(color); + + yuvClr.rgbRed = (BYTE)equalize_map[yuvClr.rgbRed]; + + color = YUVtoRGB(yuvClr); + SetPaletteColor( (BYTE)i, color ); + } + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +// HistogramNormalize function by : dave(at)posortho(dot)com +bool CxImage::HistogramNormalize() +{ + if (!pDib) return false; + + int histogram[256]; + int threshold_intensity, intense; + int x, y, i; + unsigned int normalize_map[256]; + unsigned int high, low, YVal; + + RGBQUAD color; + RGBQUAD yuvClr; + + memset( &histogram, 0, sizeof( int ) * 256 ); + memset( &normalize_map, 0, sizeof( unsigned int ) * 256 ); + + // form histogram + for(y=0; y < head.biHeight; y++){ + info.nProgress = (long)(50*y/head.biHeight); + if (info.nEscape) break; + for(x=0; x < head.biWidth; x++){ + color = GetPixelColor( x, y ); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + histogram[YVal]++; + } + } + + // find histogram boundaries by locating the 1 percent levels + threshold_intensity = ( head.biWidth * head.biHeight) / 100; + + intense = 0; + for( low = 0; low < 255; low++ ){ + intense += histogram[low]; + if( intense > threshold_intensity ) break; + } + + intense = 0; + for( high = 255; high != 0; high--){ + intense += histogram[ high ]; + if( intense > threshold_intensity ) break; + } + + if ( low == high ){ + // Unreasonable contrast; use zero threshold to determine boundaries. + threshold_intensity = 0; + intense = 0; + for( low = 0; low < 255; low++){ + intense += histogram[low]; + if( intense > threshold_intensity ) break; + } + intense = 0; + for( high = 255; high != 0; high-- ){ + intense += histogram [high ]; + if( intense > threshold_intensity ) break; + } + } + if( low == high ) return false; // zero span bound + + // Stretch the histogram to create the normalized image mapping. + for(i = 0; i <= 255; i++){ + if ( i < (int) low ){ + normalize_map[i] = 0; + } else { + if(i > (int) high) + normalize_map[i] = 255; + else + normalize_map[i] = ( 255 - 1) * ( i - low) / ( high - low ); + } + } + + // Normalize + if( head.biClrUsed == 0 ){ + for( y = 0; y < head.biHeight; y++ ){ + info.nProgress = (long)(50+50*y/head.biHeight); + if (info.nEscape) break; + for( x = 0; x < head.biWidth; x++ ){ + + color = GetPixelColor( x, y ); + yuvClr = RGBtoYUV( color ); + + yuvClr.rgbRed = (BYTE)normalize_map[yuvClr.rgbRed]; + + color = YUVtoRGB( yuvClr ); + SetPixelColor( x, y, color ); + } + } + } else { + for(i = 0; i < (int)head.biClrUsed; i++){ + + color = GetPaletteColor( (BYTE)i ); + yuvClr = RGBtoYUV( color ); + + yuvClr.rgbRed = (BYTE)normalize_map[yuvClr.rgbRed]; + + color = YUVtoRGB( yuvClr ); + SetPaletteColor( (BYTE)i, color ); + } + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +// HistogramLog function by : dave(at)posortho(dot)com +bool CxImage::HistogramLog() +{ + if (!pDib) return false; + + //q(i,j) = 255/log(1 + |high|) * log(1 + |p(i,j)|); + int x, y, i; + RGBQUAD color; + RGBQUAD yuvClr; + + unsigned int YVal, high = 1; + + // Find Highest Luminance Value in the Image + if( head.biClrUsed == 0 ){ // No Palette + for(y=0; y < head.biHeight; y++){ + info.nProgress = (long)(50*y/head.biHeight); + if (info.nEscape) break; + for(x=0; x < head.biWidth; x++){ + color = GetPixelColor( x, y ); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if (YVal > high ) high = YVal; + } + } + } else { // Palette + for(i = 0; i < (int)head.biClrUsed; i++){ + color = GetPaletteColor((BYTE)i); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if (YVal > high ) high = YVal; + } + } + + // Logarithm Operator + double k = 255.0 / ::log( 1.0 + (double)high ); + if( head.biClrUsed == 0 ){ + for( y = 0; y < head.biHeight; y++ ){ + info.nProgress = (long)(50+50*y/head.biHeight); + if (info.nEscape) break; + for( x = 0; x < head.biWidth; x++ ){ + + color = GetPixelColor( x, y ); + yuvClr = RGBtoYUV( color ); + + yuvClr.rgbRed = (BYTE)(k * ::log( 1.0 + (double)yuvClr.rgbRed ) ); + + color = YUVtoRGB( yuvClr ); + SetPixelColor( x, y, color ); + } + } + } else { + for(i = 0; i < (int)head.biClrUsed; i++){ + + color = GetPaletteColor( (BYTE)i ); + yuvClr = RGBtoYUV( color ); + + yuvClr.rgbRed = (BYTE)(k * ::log( 1.0 + (double)yuvClr.rgbRed ) ); + + color = YUVtoRGB( yuvClr ); + SetPaletteColor( (BYTE)i, color ); + } + } + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +// HistogramRoot function by : dave(at)posortho(dot)com +bool CxImage::HistogramRoot() +{ + if (!pDib) return false; + //q(i,j) = sqrt(|p(i,j)|); + + int x, y, i; + RGBQUAD color; + RGBQUAD yuvClr; + double dtmp; + unsigned int YVal, high = 1; + + // Find Highest Luminance Value in the Image + if( head.biClrUsed == 0 ){ // No Palette + for(y=0; y < head.biHeight; y++){ + info.nProgress = (long)(50*y/head.biHeight); + if (info.nEscape) break; + for(x=0; x < head.biWidth; x++){ + color = GetPixelColor( x, y ); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if (YVal > high ) high = YVal; + } + } + } else { // Palette + for(i = 0; i < (int)head.biClrUsed; i++){ + color = GetPaletteColor((BYTE)i); + YVal = (unsigned int)RGB2GRAY(color.rgbRed, color.rgbGreen, color.rgbBlue); + if (YVal > high ) high = YVal; + } + } + + // Root Operator + double k = 128.0 / ::log( 1.0 + (double)high ); + if( head.biClrUsed == 0 ){ + for( y = 0; y < head.biHeight; y++ ){ + info.nProgress = (long)(50+50*y/head.biHeight); + if (info.nEscape) break; + for( x = 0; x < head.biWidth; x++ ){ + + color = GetPixelColor( x, y ); + yuvClr = RGBtoYUV( color ); + + dtmp = k * ::sqrt( (double)yuvClr.rgbRed ); + if ( dtmp > 255.0 ) dtmp = 255.0; + if ( dtmp < 0 ) dtmp = 0; + yuvClr.rgbRed = (BYTE)dtmp; + + color = YUVtoRGB( yuvClr ); + SetPixelColor( x, y, color ); + } + } + } else { + for(i = 0; i < (int)head.biClrUsed; i++){ + + color = GetPaletteColor( (BYTE)i ); + yuvClr = RGBtoYUV( color ); + + dtmp = k * ::sqrt( (double)yuvClr.rgbRed ); + if ( dtmp > 255.0 ) dtmp = 255.0; + if ( dtmp < 0 ) dtmp = 0; + yuvClr.rgbRed = (BYTE)dtmp; + + color = YUVtoRGB( yuvClr ); + SetPaletteColor( (BYTE)i, color ); + } + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaico.cpp ./win32/dependencies/cximage/ximaico.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaico.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaico.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,299 @@ +/* + * File: ximaico.cpp + * Purpose: Platform Independent ICON Image Class Loader and Writer (MS version) + * 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximaico.h" + +#if CXIMAGE_SUPPORT_ICO + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageICO::Decode(CxFile *hFile) +{ + if (hFile==NULL) return false; + + DWORD off = hFile->Tell(); // + int page=info.nFrame; //internal icon structure indexes + + // read the first part of the header + ICONHEADER icon_header; + hFile->Read(&icon_header,sizeof(ICONHEADER),1); + // check if it's an icon or a cursor + if ((icon_header.idReserved == 0) && ((icon_header.idType == 1)||(icon_header.idType == 2))) { + + info.nNumFrames = icon_header.idCount; + + // load the icon descriptions + ICONDIRENTRY *icon_list = (ICONDIRENTRY *)malloc(icon_header.idCount * sizeof(ICONDIRENTRY)); + int c; + for (c = 0; c < icon_header.idCount; c++) + hFile->Read(icon_list + c, sizeof(ICONDIRENTRY), 1); + + if ((page>=0)&&(page + BITMAPINFOHEADER bih; + hFile->Seek(off + icon_list[page].dwImageOffset, SEEK_SET); + hFile->Read(&bih,sizeof(BITMAPINFOHEADER),1); + c = bih.biBitCount; + + // allocate memory for one icon + Create(icon_list[page].bWidth,icon_list[page].bHeight, c, CXIMAGE_FORMAT_ICO); //image creation + + // read the palette + RGBQUAD pal[256]; + hFile->Read(pal,head.biClrUsed*sizeof(RGBQUAD), 1); + SetPalette(pal,head.biClrUsed); //palette assign + + //read the icon + if (c<=24){ + hFile->Read(info.pImage, head.biSizeImage, 1); + } else { // 32 bit icon + BYTE* dst = info.pImage; + BYTE* buf=(BYTE*)malloc(4*head.biHeight*head.biWidth); + BYTE* src = buf; + hFile->Read(buf, 4*head.biHeight*head.biWidth, 1); +#if CXIMAGE_SUPPORT_ALPHA + if (!AlphaIsValid()) AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + for (long y = 0; y < head.biHeight; y++) { + for(long x=0;xRead(mask, masksize, 1)){ + + bool bGoodMask=false; + for (int im=0;im>3)]>>(7-x%8))&0x01)){ + AlphaSet(x,y,0); + bNeedAlpha=true; + } + } + } + if (!bNeedAlpha) AlphaDelete(); +#endif //CXIMAGE_SUPPORT_ALPHA + + if (c==24){ //check if there is only one transparent color + RGBQUAD cc,ct; + long* pcc = (long*)&cc; + long* pct = (long*)&ct; + int nTransColors=0; + for (int y = 0; y < head.biHeight; y++){ + for (int x = 0; x < head.biWidth; x++){ + if (((mask[y*maskwdt+(x>>3)] >> (7-x%8)) & 0x01)){ + cc = GetPixelColor(x,y,false); + if (nTransColors==0){ + nTransColors++; + ct = cc; + } else { + if (*pct!=*pcc){ + nTransColors++; + } + } + } + } + } + if (nTransColors==1){ + SetTransColor(ct); + SetTransIndex(0); +#if CXIMAGE_SUPPORT_ALPHA + AlphaDelete(); //because we have a unique transparent color in the image +#endif //CXIMAGE_SUPPORT_ALPHA + } + } + + // - Transparency support w/o Alpha support + if (c <= 8){ // only for icons with less than 256 colors (XP icons need alpha). + + // find a color index, which is not used in the image + // it is almost sure to find one, bcs. nobody uses all possible colors for an icon + + BYTE colorsUsed[256]; + memset(colorsUsed, 0, sizeof(colorsUsed)); + + for (int y = 0; y < head.biHeight; y++){ + for (int x = 0; x < head.biWidth; x++){ + colorsUsed[GetPixelIndex(x,y)] = 1; + } + } + + int iTransIdx = -1; + for (int x = 0; x < (int)head.biClrUsed; x++){ + if (colorsUsed[x] == 0){ + iTransIdx = x; // this one is not in use. we may use it as transparent color + break; + } + } + + // Go thru image and set unused color as transparent index if needed + if (iTransIdx >= 0){ + bool bNeedTrans = false; + for (int y = 0; y < head.biHeight; y++){ + for (int x = 0; x < head.biWidth; x++){ + // AND mask (Each Byte represents 8 Pixels) + if (((mask[y*maskwdt+(x>>3)] >> (7-x%8)) & 0x01)){ + // AND mask is set (!=0). This is a transparent part + SetPixelIndex(x, y, iTransIdx); + bNeedTrans = true; + } + } + } + // set transparent index if needed + if (bNeedTrans) SetTransIndex(iTransIdx); +#if CXIMAGE_SUPPORT_ALPHA + AlphaDelete(); //because we have a transparent color in the palette +#endif //CXIMAGE_SUPPORT_ALPHA + } + } + } else { + SetTransIndex(0); //empty mask, set black as transparent color + Negative(); + } + } + free(mask); + + free(icon_list); + // icon has been loaded successfully! + return true; + } + free(icon_list); + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageICO::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + //check format limits + if ((head.biWidth>255)||(head.biHeight>255)){ + strcpy(info.szLastError,"Can't save this image as icon"); + return false; + } + + //prepare the palette struct + RGBQUAD* pal=GetPalette(); + if (head.biBitCount<=8 && pal==NULL) return false; + + int maskwdt=((head.biWidth+31)/32)*4; //mask line width + int masksize=head.biHeight * maskwdt; //size of mask + int bitcount=head.biBitCount; + int imagesize=head.biSizeImage; +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid() && head.biClrUsed==0){ + bitcount=32; + imagesize=4*head.biHeight*head.biWidth; + } +#endif + + //fill the icon headers + ICONHEADER icon_header={0,1,1}; + ICONDIRENTRY icon_list={(BYTE)head.biWidth,(BYTE)head.biHeight,(BYTE)head.biClrUsed ,0,0,(WORD)bitcount, + sizeof(BITMAPINFOHEADER)+head.biClrUsed*sizeof(RGBQUAD)+ + imagesize+masksize, + sizeof(ICONHEADER)+sizeof(ICONDIRENTRY)}; + BITMAPINFOHEADER bi={sizeof(BITMAPINFOHEADER),head.biWidth,2*head.biHeight,1,(WORD)bitcount, + 0,imagesize,0,0,0,0}; + + hFile->Write(&icon_header,sizeof(ICONHEADER),1); //write the headers + hFile->Write(&icon_list,sizeof(ICONDIRENTRY),1); + hFile->Write(&bi,sizeof(BITMAPINFOHEADER),1); + if (pal) hFile->Write(pal,head.biClrUsed*sizeof(RGBQUAD),1); //write palette + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid() && head.biClrUsed==0){ + BYTE* src = info.pImage; + BYTE* buf=(BYTE*)malloc(imagesize); + BYTE* dst = buf; + for (long y = 0; y < head.biHeight; y++) { + for(long x=0;xWrite(buf,imagesize, 1); + free(buf); + } else { + hFile->Write(info.pImage,imagesize,1); //write image + } +#else + hFile->Write(info.pImage,imagesize,1); //write image +#endif + + //save transparency mask + BYTE* mask=(BYTE*)calloc(masksize,1); //create empty AND/XOR masks + if (!mask) return false; + + //prepare the variables to build the mask + BYTE* iDst; + int pos,i; + RGBQUAD c={0,0,0,0}; + RGBQUAD ct = GetTransColor(); + long* pc = (long*)&c; + long* pct= (long*)&ct; + bool bTransparent = info.nBkgndIndex != -1; +#if CXIMAGE_SUPPORT_ALPHA + bool bAlphaPaletteIsValid = AlphaPaletteIsValid(); + bool bAlphaIsValid = AlphaIsValid(); +#endif + //build the mask + for (int y = 0; y < head.biHeight; y++) { + for (int x = 0; x < head.biWidth; x++) { + i=0; +#if CXIMAGE_SUPPORT_ALPHA + if (bAlphaIsValid && AlphaGet(x,y)==0) i=1; + if (bAlphaPaletteIsValid && GetPixelColor(x,y).rgbReserved==0) i=1; +#endif + c=GetPixelColor(x,y,false); + if (bTransparent && *pc==*pct) i=1; + iDst = mask + y*maskwdt + (x>>3); + pos = 7-x%8; + *iDst &= ~(0x01<Write(mask,masksize,1); + free(mask); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ICO + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaico.h ./win32/dependencies/cximage/ximaico.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaico.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaico.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,52 @@ +/* + * File: ximaico.h + * Purpose: ICON Image Class Loader and Writer + */ +/* ========================================================== + * CxImageICO (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * ========================================================== + */ +#if !defined(__ximaICO_h) +#define __ximaICO_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_ICO + +class CxImageICO: public CxImage +{ +typedef struct tagIconDirectoryEntry { + BYTE bWidth; + BYTE bHeight; + BYTE bColorCount; + BYTE bReserved; + WORD wPlanes; + WORD wBitCount; + DWORD dwBytesInRes; + DWORD dwImageOffset; +} ICONDIRENTRY; + +typedef struct tagIconDir { + WORD idReserved; + WORD idType; + WORD idCount; +} ICONHEADER; + +public: + CxImageICO(): CxImage(CXIMAGE_FORMAT_ICO) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximainfo.cpp ./win32/dependencies/cximage/ximainfo.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximainfo.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximainfo.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,388 @@ +// ximainfo.cpp : main attributes +/* 03/10/2004 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * \return the color used for transparency, and/or for background color + */ +RGBQUAD CxImage::GetTransColor() +{ + if (head.biBitCount<24 && info.nBkgndIndex != -1) return GetPaletteColor((BYTE)info.nBkgndIndex); + return info.nBkgndColor; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Gets the index used for transparency. Returns -1 for no transparancy. + */ +long CxImage::GetTransIndex() const +{ + return info.nBkgndIndex; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Sets the index used for transparency with 1, 4 and 8 bpp images. Set to -1 to remove the effect. + */ +void CxImage::SetTransIndex(long idx) +{ + info.nBkgndIndex = idx; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Sets the color used for transparency with 24 bpp images. + * You must call SetTransIndex(0) to enable the effect, SetTransIndex(-1) to disable it. + */ +void CxImage::SetTransColor(RGBQUAD rgb) +{ + rgb.rgbReserved=0; + info.nBkgndColor = rgb; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::IsTransparent() const +{ + return info.nBkgndIndex>=0; // +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Returns true if the image has 256 colors or less. + */ +bool CxImage::IsIndexed() const +{ + return head.biClrUsed!=0; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return 1 = indexed, 2 = RGB, 4 = RGBA + */ +BYTE CxImage::GetColorType() +{ + BYTE b = (BYTE)((head.biBitCount>8) ? 2 /*COLORTYPE_COLOR*/ : 1 /*COLORTYPE_PALETTE*/); +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) b = 4 /*COLORTYPE_ALPHA*/; +#endif //CXIMAGE_SUPPORT_ALPHA + return b; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return Resolution for TIFF, JPEG, PNG and BMP formats. + */ +long CxImage::GetXDPI() const +{ + return info.xDPI; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \return Resolution for TIFF, JPEG, PNG and BMP formats. + */ +long CxImage::GetYDPI() const +{ + return info.yDPI; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Set resolution for TIFF, JPEG, PNG and BMP formats. + */ +void CxImage::SetXDPI(long dpi) +{ + if (dpi<=0) dpi=96; + info.xDPI = dpi; + head.biXPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Set resolution for TIFF, JPEG, PNG and BMP formats. + */ +void CxImage::SetYDPI(long dpi) +{ + if (dpi<=0) dpi=96; + info.yDPI = dpi; + head.biYPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \sa SetFlags + */ +DWORD CxImage::GetFlags() const +{ + return info.dwFlags; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Image flags, for future use + * \param flags + * - 0x??00000 = reserved for 16 bit, CMYK, multilayer + * - 0x00??0000 = blend modes + * - 0x0000???? = layer id or user flags + * + * \param bLockReservedFlags protects the "reserved" and "blend modes" flags + */ +void CxImage::SetFlags(DWORD flags, bool bLockReservedFlags) +{ + if (bLockReservedFlags) info.dwFlags = flags & 0x0000ffff; + else info.dwFlags = flags; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \sa SetCodecOption + */ +DWORD CxImage::GetCodecOption(DWORD imagetype) +{ + if (imagetype=head.biWidth) x=head.biWidth-(x % head.biWidth + 1); + if (y<0) y=((-y) % head.biHeight); + else if (y>=head.biHeight) y=head.biHeight-(y % head.biHeight + 1); + break; + default: + return; + }//switch +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * See OverflowCoordinates for integer version + * \author ***bd*** 2.2004 + */ +void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod) +{ + if (x>=0 && x=0 && y=head.biWidth) x=head.biWidth-((float)fmod(x, (float) head.biWidth) + 1); + if (y<0) y=(float)fmod(-y, (float) head.biHeight); + else if (y>=head.biHeight) y=head.biHeight-((float)fmod(y, (float) head.biHeight) + 1); + break; + default: + return; + }//switch +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Method return pixel color. Different methods are implemented for out of bounds pixels. + * If an image has alpha channel, alpha value is returned in .RGBReserved. + * + * \param x,y : pixel coordinates + * \param ofMethod : out-of-bounds method: + * - OF_WRAP - wrap over to pixels on other side of the image + * - OF_REPEAT - repeat last pixel on the edge + * - OF_COLOR - return input value of color + * - OF_BACKGROUND - return background color (if not set, return input color) + * - OF_TRANSPARENT - return transparent pixel + * + * \param rplColor : input color (returned for out-of-bound coordinates in OF_COLOR mode and if other mode is not applicable) + * + * \return color : color of pixel + * \author ***bd*** 2.2004 + */ +RGBQUAD CxImage::GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod, RGBQUAD* const rplColor) +{ + RGBQUAD color; //color to return + if ((!IsInside(x,y)) || pDib==NULL) { //is pixel within bouns?: + //pixel is out of bounds or no DIB + if (rplColor!=NULL) + color=*rplColor; + else { + color.rgbRed=color.rgbGreen=color.rgbBlue=255; color.rgbReserved=0; //default replacement colour: white transparent + }//if + if (pDib==NULL) return color; + //pixel is out of bounds: + switch (ofMethod) { + case OM_TRANSPARENT: +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) { + //alpha transparency is supported and image has alpha layer + color.rgbReserved=0; + } else { +#endif //CXIMAGE_SUPPORT_ALPHA + //no alpha transparency + if (GetTransIndex()>=0) { + color=GetTransColor(); //single color transparency enabled (return transparent color) + }//if +#if CXIMAGE_SUPPORT_ALPHA + }//if +#endif //CXIMAGE_SUPPORT_ALPHA + return color; + case OM_BACKGROUND: + //return background color (if it exists, otherwise input value) + if (info.nBkgndIndex != -1) { + if (head.biBitCount<24) color = GetPaletteColor((BYTE)info.nBkgndIndex); + else color = info.nBkgndColor; + }//if + return color; + case OM_REPEAT: + case OM_WRAP: + case OM_MIRROR: + OverflowCoordinates(x,y,ofMethod); + break; + default: + //simply return replacement color (OM_COLOR and others) + return color; + }//switch + }//if + //just return specified pixel (it's within bounds) + return BlindGetPixelColor(x,y); +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * This method reconstructs image according to chosen interpolation method and then returns pixel (x,y). + * (x,y) can lie between actual image pixels. If (x,y) lies outside of image, method returns value + * according to overflow method. + * This method is very useful for geometrical image transformations, where destination pixel + * can often assume color value lying between source pixels. + * + * \param (x,y) - coordinates of pixel to return + * GPCI method recreates "analogue" image back from digital data, so x and y + * are float values and color value of point (1.1,1) will generally not be same + * as (1,1). Center of first pixel is at (0,0) and center of pixel right to it is (1,0). + * (0.5,0) is half way between these two pixels. + * \param inMethod - interpolation (reconstruction) method (kernel) to use: + * - IM_NEAREST_NEIGHBOUR - returns colour of nearest lying pixel (causes stairy look of + * processed images) + * - IM_BILINEAR - interpolates colour from four neighbouring pixels (softens image a bit) + * - IM_BICUBIC - interpolates from 16 neighbouring pixels (can produce "halo" artifacts) + * - IM_BICUBIC2 - interpolates from 16 neighbouring pixels (perhaps a bit less halo artifacts + than IM_BICUBIC) + * - IM_BSPLINE - interpolates from 16 neighbouring pixels (softens image, washes colours) + * (As far as I know, image should be prefiltered for this method to give + * good results... some other time :) ) + * This method uses bicubic interpolation kernel from CXImage 5.99a and older + * versions. + * - IM_LANCZOS - interpolates from 12*12 pixels (slow, ringing artifacts) + * + * \param ofMethod - overflow method (see comments at GetPixelColorWithOverflow) + * \param rplColor - pointer to color used for out of borders pixels in OM_COLOR mode + * (and other modes if colour can't calculated in a specified way) + * + * \return interpolated color value (including interpolated alpha value, if image has alpha layer) + * + * \author ***bd*** 2.2004 + */ +RGBQUAD CxImage::GetPixelColorInterpolated( + float x,float y, + InterpolationMethod const inMethod, + OverflowMethod const ofMethod, + RGBQUAD* const rplColor) +{ + //calculate nearest pixel + int xi=(int)(x); if (x<0) xi--; //these replace (incredibly slow) floor (Visual c++ 2003, AMD Athlon) + int yi=(int)(y); if (y<0) yi--; + RGBQUAD color; //calculated colour + + switch (inMethod) { + case IM_NEAREST_NEIGHBOUR: + return GetPixelColorWithOverflow((long)(x+0.5f), (long)(y+0.5f), ofMethod, rplColor); + default: { + //bilinear interpolation + if (xi<-1 || xi>=head.biWidth || yi<-1 || yi>=head.biHeight) { //all 4 points are outside bounds?: + switch (ofMethod) { + case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: + //we don't need to interpolate anything with all points outside in this case + return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); + default: + //recalculate coordinates and use faster method later on + OverflowCoordinates(x,y,ofMethod); + xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi + yi=(int)(y); if (y<0) yi--; + }//switch + }//if + //get four neighbouring pixels + if ((xi+1)=0 && (yi+1)=0 && head.biClrUsed==0) { + //all pixels are inside RGB24 image... optimize reading (and use fixed point arithmetic) + WORD wt1=(WORD)((x-xi)*256.0f), wt2=(WORD)((y-yi)*256.0f); + WORD wd=wt1*wt2>>8; + WORD wb=wt1-wd; + WORD wc=wt2-wd; + WORD wa=256-wt1-wc; + WORD wrr,wgg,wbb; + BYTE *pxptr=(BYTE*)info.pImage+yi*info.dwEffWidth+xi*3; + wbb=wa*(*pxptr++); wgg=wa*(*pxptr++); wrr=wa*(*pxptr++); + wbb+=wb*(*pxptr++); wgg+=wb*(*pxptr++); wrr+=wb*(*pxptr); + pxptr+=(info.dwEffWidth-5); //move to next row + wbb+=wc*(*pxptr++); wgg+=wc*(*pxptr++); wrr+=wc*(*pxptr++); + wbb+=wd*(*pxptr++); wgg+=wd*(*pxptr++); wrr+=wd*(*pxptr); + color.rgbRed=(BYTE) (wrr>>8); color.rgbGreen=(BYTE) (wgg>>8); color.rgbBlue=(BYTE) (wbb>>8); +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha) { + WORD waa; + //image has alpha layer... we have to do the same for alpha data + pxptr=AlphaGetPointer(xi,yi); //pointer to first byte + waa=wa*(*pxptr++); waa+=wb*(*pxptr); //first two pixels + pxptr+=(head.biWidth-1); //move to next row + waa+=wc*(*pxptr++); waa+=wd*(*pxptr); //and second row pixels + color.rgbReserved=(BYTE) (waa>>8); + } else +#endif + { //Alpha not supported or no alpha at all + color.rgbReserved = 0; + } + return color; + } else { + //default (slower) way to get pixels (not RGB24 or some pixels out of borders) + float t1=x-xi, t2=y-yi; + float d=t1*t2; + float b=t1-d; + float c=t2-d; + float a=1-t1-c; + RGBQUAD rgb11,rgb21,rgb12,rgb22; + rgb11=GetPixelColorWithOverflow(xi, yi, ofMethod, rplColor); + rgb21=GetPixelColorWithOverflow(xi+1, yi, ofMethod, rplColor); + rgb12=GetPixelColorWithOverflow(xi, yi+1, ofMethod, rplColor); + rgb22=GetPixelColorWithOverflow(xi+1, yi+1, ofMethod, rplColor); + //calculate linear interpolation + color.rgbRed=(BYTE) (a*rgb11.rgbRed+b*rgb21.rgbRed+c*rgb12.rgbRed+d*rgb22.rgbRed); + color.rgbGreen=(BYTE) (a*rgb11.rgbGreen+b*rgb21.rgbGreen+c*rgb12.rgbGreen+d*rgb22.rgbGreen); + color.rgbBlue=(BYTE) (a*rgb11.rgbBlue+b*rgb21.rgbBlue+c*rgb12.rgbBlue+d*rgb22.rgbBlue); +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) + color.rgbReserved=(BYTE) (a*rgb11.rgbReserved+b*rgb21.rgbReserved+c*rgb12.rgbReserved+d*rgb22.rgbReserved); + else +#endif + { //Alpha not supported or no alpha at all + color.rgbReserved = 0; + } + return color; + }//if + }//default + case IM_BICUBIC: + case IM_BICUBIC2: + case IM_BSPLINE: + case IM_BOX: + case IM_HERMITE: + case IM_HAMMING: + case IM_SINC: + case IM_BLACKMAN: + case IM_BESSEL: + case IM_GAUSSIAN: + case IM_QUADRATIC: + case IM_MITCHELL: + case IM_CATROM: + //bicubic interpolation(s) + if (((xi+2)<0) || ((xi-1)>=head.biWidth) || ((yi+2)<0) || ((yi-1)>=head.biHeight)) { //all points are outside bounds?: + switch (ofMethod) { + case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: + //we don't need to interpolate anything with all points outside in this case + return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); + break; + default: + //recalculate coordinates and use faster method later on + OverflowCoordinates(x,y,ofMethod); + xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi + yi=(int)(y); if (y<0) yi--; + }//switch + }//if + + //some variables needed from here on + int xii,yii; //x any y integer indexes for loops + float kernel, kernelyc; //kernel cache + float kernelx[12], kernely[4]; //precalculated kernel values + float rr,gg,bb,aa; //accumulated color values + //calculate multiplication factors for all pixels + int i; + switch (inMethod) { + case IM_BICUBIC: + for (i=0; i<4; i++) { + kernelx[i]=KernelCubic((float)(xi+i-1-x)); + kernely[i]=KernelCubic((float)(yi+i-1-y)); + }//for i + break; + case IM_BICUBIC2: + for (i=0; i<4; i++) { + kernelx[i]=KernelGeneralizedCubic((float)(xi+i-1-x), -0.5); + kernely[i]=KernelGeneralizedCubic((float)(yi+i-1-y), -0.5); + }//for i + break; + case IM_BSPLINE: + for (i=0; i<4; i++) { + kernelx[i]=KernelBSpline((float)(xi+i-1-x)); + kernely[i]=KernelBSpline((float)(yi+i-1-y)); + }//for i + break; + case IM_BOX: + for (i=0; i<4; i++) { + kernelx[i]=KernelBox((float)(xi+i-1-x)); + kernely[i]=KernelBox((float)(yi+i-1-y)); + }//for i + break; + case IM_HERMITE: + for (i=0; i<4; i++) { + kernelx[i]=KernelHermite((float)(xi+i-1-x)); + kernely[i]=KernelHermite((float)(yi+i-1-y)); + }//for i + break; + case IM_HAMMING: + for (i=0; i<4; i++) { + kernelx[i]=KernelHamming((float)(xi+i-1-x)); + kernely[i]=KernelHamming((float)(yi+i-1-y)); + }//for i + break; + case IM_SINC: + for (i=0; i<4; i++) { + kernelx[i]=KernelSinc((float)(xi+i-1-x)); + kernely[i]=KernelSinc((float)(yi+i-1-y)); + }//for i + break; + case IM_BLACKMAN: + for (i=0; i<4; i++) { + kernelx[i]=KernelBlackman((float)(xi+i-1-x)); + kernely[i]=KernelBlackman((float)(yi+i-1-y)); + }//for i + break; + case IM_BESSEL: + for (i=0; i<4; i++) { + kernelx[i]=KernelBessel((float)(xi+i-1-x)); + kernely[i]=KernelBessel((float)(yi+i-1-y)); + }//for i + break; + case IM_GAUSSIAN: + for (i=0; i<4; i++) { + kernelx[i]=KernelGaussian((float)(xi+i-1-x)); + kernely[i]=KernelGaussian((float)(yi+i-1-y)); + }//for i + break; + case IM_QUADRATIC: + for (i=0; i<4; i++) { + kernelx[i]=KernelQuadratic((float)(xi+i-1-x)); + kernely[i]=KernelQuadratic((float)(yi+i-1-y)); + }//for i + break; + case IM_MITCHELL: + for (i=0; i<4; i++) { + kernelx[i]=KernelMitchell((float)(xi+i-1-x)); + kernely[i]=KernelMitchell((float)(yi+i-1-y)); + }//for i + break; + case IM_CATROM: + for (i=0; i<4; i++) { + kernelx[i]=KernelCatrom((float)(xi+i-1-x)); + kernely[i]=KernelCatrom((float)(yi+i-1-y)); + }//for i + break; + }//switch + rr=gg=bb=aa=0; + if (((xi+2)=1 && ((yi+2)=1) && !IsIndexed()) { + //optimized interpolation (faster pixel reads) for RGB24 images with all pixels inside bounds + BYTE *pxptr, *pxptra; + for (yii=yi-1; yii255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; + if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; + if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) { + if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; + } else +#endif + { //Alpha not supported or no alpha at all + color.rgbReserved = 0; + } + return color; + case IM_LANCZOS: + //lanczos window (16*16) sinc interpolation + if (((xi+6)<0) || ((xi-5)>=head.biWidth) || ((yi+6)<0) || ((yi-5)>=head.biHeight)) { + //all points are outside bounds + switch (ofMethod) { + case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: + //we don't need to interpolate anything with all points outside in this case + return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); + break; + default: + //recalculate coordinates and use faster method later on + OverflowCoordinates(x,y,ofMethod); + xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi + yi=(int)(y); if (y<0) yi--; + }//switch + }//if + + for (xii=xi-5; xii=0) && ((yi+6)=0) && !IsIndexed()) { + //optimized interpolation (faster pixel reads) for RGB24 images with all pixels inside bounds + BYTE *pxptr, *pxptra; + for (yii=yi-5; yii255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; + if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; + if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) { + if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; + } else +#endif + { //Alpha not supported or no alpha at all + color.rgbReserved = 0; + } + return color; + }//switch +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Helper function for GetAreaColorInterpolated. + * Adds 'surf' portion of image pixel with color 'color' to (rr,gg,bb,aa). + */ +void CxImage::AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa) +{ + rr+=color.rgbRed*surf; + gg+=color.rgbGreen*surf; + bb+=color.rgbBlue*surf; +#if CXIMAGE_SUPPORT_ALPHA + aa+=color.rgbReserved*surf; +#endif +} +//////////////////////////////////////////////////////////////////////////////// +/** + * This method is similar to GetPixelColorInterpolated, but this method also properly handles + * subsampling. + * If you need to sample original image with interval of more than 1 pixel (as when shrinking an image), + * you should use this method instead of GetPixelColorInterpolated or aliasing will occur. + * When area width and height are both less than pixel, this method gets pixel color by interpolating + * color of frame center with selected (inMethod) interpolation by calling GetPixelColorInterpolated. + * If width and height are more than 1, method calculates color by averaging color of pixels within area. + * Interpolation method is not used in this case. Pixel color is interpolated by averaging instead. + * If only one of both is more than 1, method uses combination of interpolation and averaging. + * Chosen interpolation method is used, but since it is averaged later on, there is little difference + * between IM_BILINEAR (perhaps best for this case) and better methods. IM_NEAREST_NEIGHBOUR again + * leads to aliasing artifacts. + * This method is a bit slower than GetPixelColorInterpolated and when aliasing is not a problem, you should + * simply use the later. + * + * \param xc, yc - center of (rectangular) area + * \param w, h - width and height of area + * \param inMethod - interpolation method that is used, when interpolation is used (see above) + * \param ofMethod - overflow method used when retrieving individual pixel colors + * \param rplColor - replacement colour to use, in OM_COLOR + * + * \author ***bd*** 2.2004 + */ +RGBQUAD CxImage::GetAreaColorInterpolated( + float const xc, float const yc, float const w, float const h, + InterpolationMethod const inMethod, + OverflowMethod const ofMethod, + RGBQUAD* const rplColor) +{ + RGBQUAD color; //calculated colour + + if (h<=1 && w<=1) { + //both width and height are less than one... we will use interpolation of center point + return GetPixelColorInterpolated(xc, yc, inMethod, ofMethod, rplColor); + } else { + //area is wider and/or taller than one pixel: + CxRect2 area(xc-w/2.0f, yc-h/2.0f, xc+w/2.0f, yc+h/2.0f); //area + int xi1=(int)(area.botLeft.x+0.49999999f); //low x + int yi1=(int)(area.botLeft.y+0.49999999f); //low y + + + int xi2=(int)(area.topRight.x+0.5f); //top x + int yi2=(int)(area.topRight.y+0.5f); //top y (for loops) + + float rr,gg,bb,aa; //red, green, blue and alpha components + rr=gg=bb=aa=0; + int x,y; //loop counters + float s=0; //surface of all pixels + float cps; //surface of current crosssection + if (h>1 && w>1) { + //width and height of area are greater than one pixel, so we can employ "ordinary" averaging + CxRect2 intBL, intTR; //bottom left and top right intersection + intBL=area.CrossSection(CxRect2(((float)xi1)-0.5f, ((float)yi1)-0.5f, ((float)xi1)+0.5f, ((float)yi1)+0.5f)); + intTR=area.CrossSection(CxRect2(((float)xi2)-0.5f, ((float)yi2)-0.5f, ((float)xi2)+0.5f, ((float)yi2)+0.5f)); + float wBL, wTR, hBL, hTR; + wBL=intBL.Width(); //width of bottom left pixel-area intersection + hBL=intBL.Height(); //height of bottom left... + wTR=intTR.Width(); //width of top right... + hTR=intTR.Height(); //height of top right... + + AddAveragingCont(GetPixelColorWithOverflow(xi1,yi1,ofMethod,rplColor), wBL*hBL, rr, gg, bb, aa); //bottom left pixel + AddAveragingCont(GetPixelColorWithOverflow(xi2,yi1,ofMethod,rplColor), wTR*hBL, rr, gg, bb, aa); //bottom right pixel + AddAveragingCont(GetPixelColorWithOverflow(xi1,yi2,ofMethod,rplColor), wBL*hTR, rr, gg, bb, aa); //top left pixel + AddAveragingCont(GetPixelColorWithOverflow(xi2,yi2,ofMethod,rplColor), wTR*hTR, rr, gg, bb, aa); //top right pixel + //bottom and top row + for (x=xi1+1; x255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; + if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; + if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) { + if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; + }//if +#endif + }//if + return color; +} + +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBSpline(const float x) +{ + if (x>2.0f) return 0.0f; + // thanks to Kristian Kratzenstein + float a, b, c, d; + float xm1 = x - 1.0f; // Was calculatet anyway cause the "if((x-1.0f) < 0)" + float xp1 = x + 1.0f; + float xp2 = x + 2.0f; + + if ((xp2) <= 0.0f) a = 0.0f; else a = xp2*xp2*xp2; // Only float, not float -> double -> float + if ((xp1) <= 0.0f) b = 0.0f; else b = xp1*xp1*xp1; + if (x <= 0) c = 0.0f; else c = x*x*x; + if ((xm1) <= 0.0f) d = 0.0f; else d = xm1*xm1*xm1; + + return (0.16666666666666666667f * (a - (4.0f * b) + (6.0f * c) - (4.0f * d))); + + /* equivalent + if (x < -2.0) + return(0.0f); + if (x < -1.0) + return((2.0f+x)*(2.0f+x)*(2.0f+x)*0.16666666666666666667f); + if (x < 0.0) + return((4.0f+x*x*(-6.0f-3.0f*x))*0.16666666666666666667f); + if (x < 1.0) + return((4.0f+x*x*(-6.0f+3.0f*x))*0.16666666666666666667f); + if (x < 2.0) + return((2.0f-x)*(2.0f-x)*(2.0f-x)*0.16666666666666666667f); + return(0.0f); + */ +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Bilinear interpolation kernel: + \verbatim + / + | 1-t , if 0 <= t <= 1 + h(t) = | t+1 , if -1 <= t < 0 + | 0 , otherwise + \ + \endverbatim + * ***bd*** 2.2004 + */ +float CxImage::KernelLinear(const float t) +{ +// if (0<=t && t<=1) return 1-t; +// if (-1<=t && t<0) return 1+t; +// return 0; + + // + if (t < -1.0f) + return 0.0f; + if (t < 0.0f) + return 1.0f+t; + if (t < 1.0f) + return 1.0f-t; + return 0.0f; +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Bicubic interpolation kernel (a=-1): + \verbatim + / + | 1-2|t|**2+|t|**3 , if |t| < 1 + h(t) = | 4-8|t|+5|t|**2-|t|**3 , if 1<=|t|<2 + | 0 , otherwise + \ + \endverbatim + * ***bd*** 2.2004 + */ +float CxImage::KernelCubic(const float t) +{ + float abs_t = (float)fabs(t); + float abs_t_sq = abs_t * abs_t; + if (abs_t<1) return 1-2*abs_t_sq+abs_t_sq*abs_t; + if (abs_t<2) return 4 - 8*abs_t +5*abs_t_sq - abs_t_sq*abs_t; + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Bicubic kernel (for a=-1 it is the same as BicubicKernel): + \verbatim + / + | (a+2)|t|**3 - (a+3)|t|**2 + 1 , |t| <= 1 + h(t) = | a|t|**3 - 5a|t|**2 + 8a|t| - 4a , 1 < |t| <= 2 + | 0 , otherwise + \ + \endverbatim + * Often used values for a are -1 and -1/2. + */ +float CxImage::KernelGeneralizedCubic(const float t, const float a) +{ + float abs_t = (float)fabs(t); + float abs_t_sq = abs_t * abs_t; + if (abs_t<1) return (a+2)*abs_t_sq*abs_t - (a+3)*abs_t_sq + 1; + if (abs_t<2) return a*abs_t_sq*abs_t - 5*a*abs_t_sq + 8*a*abs_t - 4*a; + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Lanczos windowed sinc interpolation kernel with radius r. + \verbatim + / + h(t) = | sinc(t)*sinc(t/r) , if |t| r) return 0; + if (t==0) return 1; + float pit=PI*t; + float pitd=pit/r; + return (float)((sin(pit)/pit) * (sin(pitd)/pitd)); +} + +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBox(const float x) +{ + if (x < -0.5f) + return 0.0f; + if (x < 0.5f) + return 1.0f; + return 0.0f; +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelHermite(const float x) +{ + if (x < -1.0f) + return 0.0f; + if (x < 0.0f) + return (-2.0f*x-3.0f)*x*x+1.0f; + if (x < 1.0f) + return (2.0f*x-3.0f)*x*x+1.0f; + return 0.0f; +// if (fabs(x)>1) return 0.0f; +// return(0.5f+0.5f*(float)cos(PI*x)); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelHamming(const float x) +{ + if (x < -1.0f) + return 0.0f; + if (x < 0.0f) + return 0.92f*(-2.0f*x-3.0f)*x*x+1.0f; + if (x < 1.0f) + return 0.92f*(2.0f*x-3.0f)*x*x+1.0f; + return 0.0f; +// if (fabs(x)>1) return 0.0f; +// return(0.54f+0.46f*(float)cos(PI*x)); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelSinc(const float x) +{ + if (x == 0.0) + return(1.0); + return((float)sin(PI*x)/(PI*x)); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBlackman(const float x) +{ + //if (fabs(x)>1) return 0.0f; + return (0.42f+0.5f*(float)cos(PI*x)+0.08f*(float)cos(2.0f*PI*x)); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBessel_J1(const float x) +{ + double p, q; + + register long i; + + static const double + Pone[] = + { + 0.581199354001606143928050809e+21, + -0.6672106568924916298020941484e+20, + 0.2316433580634002297931815435e+19, + -0.3588817569910106050743641413e+17, + 0.2908795263834775409737601689e+15, + -0.1322983480332126453125473247e+13, + 0.3413234182301700539091292655e+10, + -0.4695753530642995859767162166e+7, + 0.270112271089232341485679099e+4 + }, + Qone[] = + { + 0.11623987080032122878585294e+22, + 0.1185770712190320999837113348e+20, + 0.6092061398917521746105196863e+17, + 0.2081661221307607351240184229e+15, + 0.5243710262167649715406728642e+12, + 0.1013863514358673989967045588e+10, + 0.1501793594998585505921097578e+7, + 0.1606931573481487801970916749e+4, + 0.1e+1 + }; + + p = Pone[8]; + q = Qone[8]; + for (i=7; i >= 0; i--) + { + p = p*x*x+Pone[i]; + q = q*x*x+Qone[i]; + } + return (float)(p/q); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBessel_P1(const float x) +{ + double p, q; + + register long i; + + static const double + Pone[] = + { + 0.352246649133679798341724373e+5, + 0.62758845247161281269005675e+5, + 0.313539631109159574238669888e+5, + 0.49854832060594338434500455e+4, + 0.2111529182853962382105718e+3, + 0.12571716929145341558495e+1 + }, + Qone[] = + { + 0.352246649133679798068390431e+5, + 0.626943469593560511888833731e+5, + 0.312404063819041039923015703e+5, + 0.4930396490181088979386097e+4, + 0.2030775189134759322293574e+3, + 0.1e+1 + }; + + p = Pone[5]; + q = Qone[5]; + for (i=4; i >= 0; i--) + { + p = p*(8.0/x)*(8.0/x)+Pone[i]; + q = q*(8.0/x)*(8.0/x)+Qone[i]; + } + return (float)(p/q); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBessel_Q1(const float x) +{ + double p, q; + + register long i; + + static const double + Pone[] = + { + 0.3511751914303552822533318e+3, + 0.7210391804904475039280863e+3, + 0.4259873011654442389886993e+3, + 0.831898957673850827325226e+2, + 0.45681716295512267064405e+1, + 0.3532840052740123642735e-1 + }, + Qone[] = + { + 0.74917374171809127714519505e+4, + 0.154141773392650970499848051e+5, + 0.91522317015169922705904727e+4, + 0.18111867005523513506724158e+4, + 0.1038187585462133728776636e+3, + 0.1e+1 + }; + + p = Pone[5]; + q = Qone[5]; + for (i=4; i >= 0; i--) + { + p = p*(8.0/x)*(8.0/x)+Pone[i]; + q = q*(8.0/x)*(8.0/x)+Qone[i]; + } + return (float)(p/q); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBessel_Order1(float x) +{ + float p, q; + + if (x == 0.0) + return (0.0f); + p = x; + if (x < 0.0) + x=(-x); + if (x < 8.0) + return(p*KernelBessel_J1(x)); + q = (float)sqrt(2.0f/(PI*x))*(float)(KernelBessel_P1(x)*(1.0f/sqrt(2.0f)*(sin(x)-cos(x)))-8.0f/x*KernelBessel_Q1(x)* + (-1.0f/sqrt(2.0f)*(sin(x)+cos(x)))); + if (p < 0.0f) + q = (-q); + return (q); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelBessel(const float x) +{ + if (x == 0.0f) + return(PI/4.0f); + return(KernelBessel_Order1(PI*x)/(2.0f*x)); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelGaussian(const float x) +{ + return (float)(exp(-2.0f*x*x)*0.79788456080287f/*sqrt(2.0f/PI)*/); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelQuadratic(const float x) +{ + if (x < -1.5f) + return(0.0f); + if (x < -0.5f) + return(0.5f*(x+1.5f)*(x+1.5f)); + if (x < 0.5f) + return(0.75f-x*x); + if (x < 1.5f) + return(0.5f*(x-1.5f)*(x-1.5f)); + return(0.0f); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelMitchell(const float x) +{ +#define KM_B (1.0f/3.0f) +#define KM_C (1.0f/3.0f) +#define KM_P0 (( 6.0f - 2.0f * KM_B ) / 6.0f) +#define KM_P2 ((-18.0f + 12.0f * KM_B + 6.0f * KM_C) / 6.0f) +#define KM_P3 (( 12.0f - 9.0f * KM_B - 6.0f * KM_C) / 6.0f) +#define KM_Q0 (( 8.0f * KM_B + 24.0f * KM_C) / 6.0f) +#define KM_Q1 ((-12.0f * KM_B - 48.0f * KM_C) / 6.0f) +#define KM_Q2 (( 6.0f * KM_B + 30.0f * KM_C) / 6.0f) +#define KM_Q3 (( -1.0f * KM_B - 6.0f * KM_C) / 6.0f) + + if (x < -2.0) + return(0.0f); + if (x < -1.0) + return(KM_Q0-x*(KM_Q1-x*(KM_Q2-x*KM_Q3))); + if (x < 0.0f) + return(KM_P0+x*x*(KM_P2-x*KM_P3)); + if (x < 1.0f) + return(KM_P0+x*x*(KM_P2+x*KM_P3)); + if (x < 2.0f) + return(KM_Q0+x*(KM_Q1+x*(KM_Q2+x*KM_Q3))); + return(0.0f); +} +//////////////////////////////////////////////////////////////////////////////// +float CxImage::KernelCatrom(const float x) +{ + if (x < -2.0) + return(0.0f); + if (x < -1.0) + return(0.5f*(4.0f+x*(8.0f+x*(5.0f+x)))); + if (x < 0.0) + return(0.5f*(2.0f+x*x*(-5.0f-3.0f*x))); + if (x < 1.0) + return(0.5f*(2.0f+x*x*(-5.0f+3.0f*x))); + if (x < 2.0) + return(0.5f*(4.0f+x*(-8.0f+x*(5.0f-x)))); + return(0.0f); +} +//////////////////////////////////////////////////////////////////////////////// + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaiter.h ./win32/dependencies/cximage/ximaiter.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaiter.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaiter.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,252 @@ +/* + * File: ImaIter.h + * Purpose: Declaration of the Platform Independent Image Base Class + * Author: Alejandro Aguilar Sierra + * Created: 1995 + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * 07/08/2001 Davide Pizzolato - www.xdp.it + * - removed slow loops + * - added safe checks + * + * Permission is given by the author to freely redistribute and include + * this code in any program as long as this credit is given where due. + * + * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY + * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES + * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE + * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED + * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT + * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY + * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL + * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER + * THIS DISCLAIMER. + * + * Use at your own risk! + * ========================================================== + */ + +#if !defined(__ImaIter_h) +#define __ImaIter_h + +#include "ximage.h" +#include "ximadef.h" + +class CImageIterator +{ +friend class CxImage; +protected: + int Itx, Ity; // Counters + int Stepx, Stepy; + BYTE* IterImage; // Image pointer + CxImage *ima; +public: + // Constructors + CImageIterator ( void ); + CImageIterator ( CxImage *image ); + operator CxImage* (); + + // Iterators + BOOL ItOK (); + void Reset (); + void Upset (); + void SetRow(BYTE *buf, int n); + void GetRow(BYTE *buf, int n); + BYTE GetByte( ) { return IterImage[Itx]; } + void SetByte(BYTE b) { IterImage[Itx] = b; } + BYTE* GetRow(void); + BYTE* GetRow(int n); + BOOL NextRow(); + BOOL PrevRow(); + BOOL NextByte(); + BOOL PrevByte(); + + void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; } + void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; } + BOOL NextStep(); + BOOL PrevStep(); + + void SetY(int y); /* AD - for interlace */ + int GetY() {return Ity;} + BOOL GetCol(BYTE* pCol, DWORD x); + BOOL SetCol(BYTE* pCol, DWORD x); +}; + +///////////////////////////////////////////////////////////////////// +inline +CImageIterator::CImageIterator(void) +{ + ima = 0; + IterImage = 0; + Itx = Ity = 0; + Stepx = Stepy = 0; +} +///////////////////////////////////////////////////////////////////// +inline +CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl) +{ + if (ima) IterImage = ima->GetBits(); + Itx = Ity = 0; + Stepx = Stepy = 0; +} +///////////////////////////////////////////////////////////////////// +inline +CImageIterator::operator CxImage* () +{ + return ima; +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::ItOK () +{ + if (ima) return ima->IsInside(Itx, Ity); + else return FALSE; +} +///////////////////////////////////////////////////////////////////// +inline void CImageIterator::Reset() +{ + if (ima) IterImage = ima->GetBits(); + else IterImage=0; + Itx = Ity = 0; +} +///////////////////////////////////////////////////////////////////// +inline void CImageIterator::Upset() +{ + Itx = 0; + Ity = ima->GetHeight()-1; + IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1); +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::NextRow() +{ + if (++Ity >= (int)ima->GetHeight()) return 0; + IterImage += ima->GetEffWidth(); + return 1; +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::PrevRow() +{ + if (--Ity < 0) return 0; + IterImage -= ima->GetEffWidth(); + return 1; +} +/* AD - for interlace */ +inline void CImageIterator::SetY(int y) +{ + if ((y < 0) || (y > (int)ima->GetHeight())) return; + Ity = y; + IterImage = ima->GetBits() + ima->GetEffWidth()*y; +} +///////////////////////////////////////////////////////////////////// +inline void CImageIterator::SetRow(BYTE *buf, int n) +{ + if (n<0) n = (int)ima->GetEffWidth(); + else n = min(n,(int)ima->GetEffWidth()); + + if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n); +} +///////////////////////////////////////////////////////////////////// +inline void CImageIterator::GetRow(BYTE *buf, int n) +{ + if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(buf,IterImage,n); +} +///////////////////////////////////////////////////////////////////// +inline BYTE* CImageIterator::GetRow() +{ + return IterImage; +} +///////////////////////////////////////////////////////////////////// +inline BYTE* CImageIterator::GetRow(int n) +{ + SetY(n); + return IterImage; +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::NextByte() +{ + if (++Itx < (int)ima->GetEffWidth()) return 1; + else + if (++Ity < (int)ima->GetHeight()){ + IterImage += ima->GetEffWidth(); + Itx = 0; + return 1; + } else + return 0; +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::PrevByte() +{ + if (--Itx >= 0) return 1; + else + if (--Ity >= 0){ + IterImage -= ima->GetEffWidth(); + Itx = 0; + return 1; + } else + return 0; +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::NextStep() +{ + Itx += Stepx; + if (Itx < (int)ima->GetEffWidth()) return 1; + else { + Ity += Stepy; + if (Ity < (int)ima->GetHeight()){ + IterImage += ima->GetEffWidth(); + Itx = 0; + return 1; + } else + return 0; + } +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::PrevStep() +{ + Itx -= Stepx; + if (Itx >= 0) return 1; + else { + Ity -= Stepy; + if (Ity >= 0 && Ity < (int)ima->GetHeight()) { + IterImage -= ima->GetEffWidth(); + Itx = 0; + return 1; + } else + return 0; + } +} +///////////////////////////////////////////////////////////////////// +inline BOOL CImageIterator::GetCol(BYTE* pCol, DWORD x) +{ + if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth())) + return 0; + DWORD h = ima->GetHeight(); + //DWORD line = ima->GetEffWidth(); + BYTE bytes = ima->GetBpp()>>3; + BYTE* pSrc; + for (DWORD y=0;yGetBits(y) + x*bytes; + for (BYTE w=0;wGetBpp()<8)||(x>=ima->GetWidth())) + return 0; + DWORD h = ima->GetHeight(); + //DWORD line = ima->GetEffWidth(); + BYTE bytes = ima->GetBpp()>>3; + BYTE* pSrc; + for (DWORD y=0;yGetBits(y) + x*bytes; + for (BYTE w=0;wSize(); + src=(BYTE*)malloc(len); + hFile->Read(src, len, 1); + + if (!j2k_decode(src, len, &img, &cp)) { + free(src); + throw "failed to decode J2K image!"; + } + + free(src); + + if (img->numcomps==3 && + img->comps[0].dx==img->comps[1].dx && + img->comps[1].dx==img->comps[2].dx && + img->comps[0].dy==img->comps[1].dy && + img->comps[1].dy==img->comps[2].dy && + img->comps[0].prec==img->comps[1].prec && + img->comps[1].prec==img->comps[2].prec) + { + w=CEILDIV(img->x1-img->x0, img->comps[0].dx); + h=CEILDIV(img->y1-img->y0, img->comps[0].dy); + max=(1<comps[0].prec)-1; + + Create(w,h,24,CXIMAGE_FORMAT_J2K); + + RGBQUAD c; + for (i=0,y=0; ycomps[0].data[i]; + c.rgbGreen = img->comps[1].data[i]; + c.rgbBlue = img->comps[2].data[i]; + SetPixelColor(x,h-1-y,c); + } + } + } else { + int compno; + info.nNumFrames = img->numcomps; + if ((info.nFrame<0)||(info.nFrame>=info.nNumFrames)){ + j2k_destroy(&img,&cp); + throw "wrong frame!"; + } + for (compno=0; compno<=info.nFrame; compno++) { + w=CEILDIV(img->x1-img->x0, img->comps[compno].dx); + h=CEILDIV(img->y1-img->y0, img->comps[compno].dy); + max=(1<comps[compno].prec)-1; + Create(w,h,8,CXIMAGE_FORMAT_J2K); + SetGrayPalette(); + for (i=0,y=0; ycomps[compno].data[i]); + } + } + } + } + + j2k_destroy(&img,&cp); + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return FALSE; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJ2K::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + if (head.biClrUsed!=0 && !IsGrayScale()){ + strcpy(info.szLastError,"J2K can save only RGB or GrayScale images"); + return false; + } + + int i,x,y; + j2k_image_t *img; + j2k_cp_t *cp; + j2k_tcp_t *tcp; + j2k_tccp_t *tccp; + + img = (j2k_image_t *)calloc(sizeof(j2k_image_t),1); + cp = (j2k_cp_t *)calloc(sizeof(j2k_cp_t),1); + + cp->tx0=0; cp->ty0=0; + cp->tw=1; cp->th=1; + cp->tcps=(j2k_tcp_t*)calloc(sizeof(j2k_tcp_t),1); + tcp=&cp->tcps[0]; + + long w=head.biWidth; + long h=head.biHeight; + + tcp->numlayers=1; + for (i=0;inumlayers;i++) tcp->rates[i]=(w*h*GetJpegQuality())/600; + + + if (IsGrayScale()) { + img->x0=0; + img->y0=0; + img->x1=w; + img->y1=h; + img->numcomps=1; + img->comps=(j2k_comp_t*)calloc(sizeof(j2k_comp_t),1); + img->comps[0].data=(int*)calloc(w*h*sizeof(int),1); + img->comps[0].prec=8; + img->comps[0].sgnd=0; + img->comps[0].dx=1; + img->comps[0].dy=1; + for (i=0,y=0; ycomps[0].data[i]=GetPixelIndex(x,h-1-y); + } + } + } else if (!IsIndexed()) { + img->x0=0; + img->y0=0; + img->x1=w; + img->y1=h; + img->numcomps=3; + img->comps=(j2k_comp_t*)calloc(img->numcomps*sizeof(j2k_comp_t),1); + for (i=0; inumcomps; i++) { + img->comps[i].data=(int*)calloc(w*h*sizeof(int),1); + img->comps[i].prec=8; + img->comps[i].sgnd=0; + img->comps[i].dx=1; + img->comps[i].dy=1; + } + RGBQUAD c; + for (i=0,y=0; ycomps[0].data[i]=c.rgbRed; + img->comps[1].data[i]=c.rgbGreen; + img->comps[2].data[i]=c.rgbBlue; + } + } + } else { + return 0; + } + + cp->tdx=img->x1-img->x0; + cp->tdy=img->y1-img->y0; + + tcp->csty=0; + tcp->prg=0; + tcp->mct=img->numcomps==3?1:0; + tcp->tccps=(j2k_tccp_t*)calloc(img->numcomps*sizeof(j2k_tccp_t),1); + + int ir=0; /* or 1 ???*/ + + for (i=0; inumcomps; i++) { + tccp=&tcp->tccps[i]; + tccp->csty=0; + tccp->numresolutions=6; + tccp->cblkw=6; + tccp->cblkh=6; + tccp->cblksty=0; + tccp->qmfbid=ir?0:1; + tccp->qntsty=ir?J2K_CCP_QNTSTY_SEQNT:J2K_CCP_QNTSTY_NOQNT; + tccp->numgbits=2; + tccp->roishift=0; + j2k_calc_explicit_stepsizes(tccp, img->comps[i].prec); + } + + BYTE* dest=(BYTE*)calloc(tcp->rates[tcp->numlayers-1]+2,1); + long len = j2k_encode(img, cp, dest, tcp->rates[tcp->numlayers-1]+2); + + if (len==0) { + strcpy(info.szLastError,"J2K failed to encode image"); + } else { + hFile->Write(dest, len, 1); + } + + free(dest); + j2k_destroy(&img,&cp); + + return (len!=0); +} +//////////////////////////////////////////////////////////////////////////////// + +static const double dwt_norms_97[4][10]={ + {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9}, + {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, + {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, + {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2} +}; + +//////////////////////////////////////////////////////////////////////////////// +void CxImageJ2K::j2k_calc_explicit_stepsizes(j2k_tccp_t *tccp, int prec) { + int numbands, bandno; + numbands=3*tccp->numresolutions-2; + for (bandno=0; bandnonumresolutions-1-resno; + gain=tccp->qmfbid==0?0:(orient==0?0:(orient==1||orient==2?1:2)); + if (tccp->qntsty==J2K_CCP_QNTSTY_NOQNT) { + stepsize=1.0; + } else { + double norm=dwt_norms_97[orient][level]; + stepsize=(1<<(gain+1))/norm; + } + j2k_encode_stepsize((int)floor(stepsize*8192.0), prec+gain, &tccp->stepsizes[bandno].expn, &tccp->stepsizes[bandno].mant); + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageJ2K::j2k_encode_stepsize(int stepsize, int numbps, int *expn, int *mant) { + int p, n; + p=j2k_floorlog2(stepsize)-13; + n=11-j2k_floorlog2(stepsize); + *mant=(n<0?stepsize>>-n:stepsize<1; l++) { + a>>=1; + } + return l; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_J2K diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaj2k.h ./win32/dependencies/cximage/ximaj2k.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximaj2k.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximaj2k.h 2006-08-24 07:16:02 +0900 @@ -0,0 +1,46 @@ +/* + * File: ximaj2k.h + * Purpose: J2K Image Class Loader and Writer + */ +/* ========================================================== + * CxImageJ2K (c) 04/Aug/2002 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * based on LIBJ2K Copyright (c) 2001-2002, David Janssens - All rights reserved. + * ========================================================== + */ +#if !defined(__ximaJ2K_h) +#define __ximaJ2K_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_J2K + +#define LIBJ2K_EXPORTS +extern "C" { +#include "../j2k/j2k.h" +}; + +class CxImageJ2K: public CxImage +{ +public: + CxImageJ2K(): CxImage(CXIMAGE_FORMAT_J2K) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_J2K);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_J2K);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE +protected: + void j2k_calc_explicit_stepsizes(j2k_tccp_t *tccp, int prec); + void j2k_encode_stepsize(int stepsize, int numbps, int *expn, int *mant); + int j2k_floorlog2(int a); +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajas.cpp ./win32/dependencies/cximage/ximajas.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajas.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajas.cpp 2006-08-24 07:16:02 +0900 @@ -0,0 +1,265 @@ +/* + * File: ximajas.cpp + * Purpose: Platform Independent JasPer Image Class Loader and Writer + * 12/Apr/2003 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximajas.h" + +#if CXIMAGE_SUPPORT_JASPER + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJAS::Decode(CxFile *hFile, DWORD imagetype) +{ + if (hFile == NULL) return false; + + jas_image_t *image=0; + jas_stream_t *in=0; + jas_matrix_t **bufs=0; + long i,error=0; + //jas_setdbglevel(0); + + try + { + if (jas_init()) + throw "cannot initialize jasper"; + + if (!(in = jas_stream_fdopen(0, "rb"))) + throw "error: cannot open standard input"; + + CxFileJas src(hFile,in); + + if (!(image = jas_image_decode(in, -1, 0))) + throw "error: cannot load image data"; + + long x,y,w,h,depth,cmptno; + + w = jas_image_cmptwidth(image,0); + h = jas_image_cmptheight(image,0); + depth = jas_image_cmptprec(image,0); + + if (image->numcmpts_ > 64 || image->numcmpts_ < 0) + throw "error: too much components"; + + if (depth!=1 && depth!=4 && depth!=8){ + jas_image_t *newimage; + jas_cmprof_t *outprof; + //jas_eprintf("forcing conversion to sRGB\n"); + if (!(outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB))) { + throw "cannot create sRGB profile"; + } + if (!(newimage = jas_image_chclrspc(image, outprof, JAS_CMXFORM_INTENT_PER))) { + throw "cannot convert to sRGB"; + } + jas_image_destroy(image); + jas_cmprof_destroy(outprof); + image = newimage; + } + + bufs = (jas_matrix_t **)calloc(image->numcmpts_, sizeof(jas_matrix_t**)); + for (i = 0; i < image->numcmpts_; ++i) { + if (!(bufs[i] = jas_matrix_create(1, w))) { + throw "error: cannot allocate memory"; + } + } + + if (image->numcmpts_==3 && + image->cmpts_[0]->width_ == image->cmpts_[1]->width_ && + image->cmpts_[1]->width_ == image->cmpts_[2]->width_ && + image->cmpts_[0]->height_ == image->cmpts_[1]->height_ && + image->cmpts_[1]->height_ == image->cmpts_[2]->height_ && + image->cmpts_[0]->prec_ == image->cmpts_[1]->prec_ && + image->cmpts_[1]->prec_ == image->cmpts_[2]->prec_ ) + { + + if(!Create(w,h,24,imagetype)) + throw "Can't allocate memory"; + + RGBQUAD c; + for (y=0; ynumcmpts_; ++cmptno) { + jas_image_readcmpt(image, cmptno, 0, y, w, 1, bufs[cmptno]); + } + + for (x=0; xnumcmpts_; + if ((info.nFrame<0)||(info.nFrame>=info.nNumFrames)){ + throw "wrong frame!"; + } + for (cmptno=0; cmptno<=info.nFrame; cmptno++) { + w = jas_image_cmptwidth(image,cmptno); + h = jas_image_cmptheight(image,cmptno); + depth = jas_image_cmptprec(image,cmptno); + if (depth>8) depth=8; + if(!Create(w,h,depth,imagetype)) + throw "Can't allocate memory"; + SetGrayPalette(); + for (y=0; ynumcmpts_; ++i){ if (bufs[i]) jas_matrix_destroy(bufs[i]);} + free(bufs); + } + jas_cleanup(); + if (image) jas_image_destroy(image); + if (in) jas_stream_close(in); + return (error==0); +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJAS::Encode(CxFile * hFile, DWORD imagetype) +{ + if (EncodeSafeCheck(hFile)) return false; + + if (head.biClrUsed!=0 && !IsGrayScale()){ + strcpy(info.szLastError,"JasPer can save only RGB or GrayScale images"); + return false; + } + + jas_image_t *image=0; + jas_stream_t *out=0; + jas_matrix_t *cmpts[3]; + long x,y,yflip,error=0; + uint_fast16_t cmptno, numcmpts; + jas_image_cmptparm_t cmptparms[3], *cmptparm; + + try + { + + if (jas_init()) + throw "cannot initialize jasper"; + + if (!(out = jas_stream_fdopen(0, "wb"))) + throw "error: cannot open standard output"; + + CxFileJas src(hFile,out); + + numcmpts = head.biClrUsed==0 ? 3 : 1; + + for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno, ++cmptparm) { + cmptparm->tlx = 0; + cmptparm->tly = 0; + cmptparm->hstep = 1; + cmptparm->vstep = 1; + cmptparm->width = head.biWidth; + cmptparm->height = head.biHeight; + cmptparm->prec = 8; + cmptparm->sgnd = false; + } + + /* Create image object. */ + if (!(image = jas_image_create(numcmpts, cmptparms, JAS_CLRSPC_UNKNOWN))) + throw "error : jas_image_create"; + + if (numcmpts == 3) { + jas_image_setclrspc(image, JAS_CLRSPC_SRGB); + jas_image_setcmpttype(image, 0, + JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R)); + jas_image_setcmpttype(image, 1, + JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G)); + jas_image_setcmpttype(image, 2, + JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B)); + } else { + jas_image_setclrspc(image, JAS_CLRSPC_SGRAY); + jas_image_setcmpttype(image, 0, + JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y)); + } + + + for (x = 0; x < numcmpts; ++x) { cmpts[x] = 0; } + /* Create temporary matrices to hold component data. */ + for (x = 0; x < numcmpts; ++x) { + if (!(cmpts[x] = jas_matrix_create(1, head.biWidth))) { + throw "error : can't allocate memory"; + } + } + + RGBQUAD c; + for (y = 0; y < head.biHeight; ++y) { + for (x = 0; x < head.biWidth; ++x) { + if (head.biClrUsed==0){ + c = GetPixelColor(x,y); + jas_matrix_setv(cmpts[0], x, c.rgbRed); + jas_matrix_setv(cmpts[1], x, c.rgbGreen); + jas_matrix_setv(cmpts[2], x, c.rgbBlue); + } else { + jas_matrix_setv(cmpts[0], x, GetPixelIndex(x,y)); + } + } + yflip = head.biHeight - 1 - y; + for (cmptno = 0; cmptno < numcmpts; ++cmptno) { + if (jas_image_writecmpt(image, cmptno, 0, yflip, head.biWidth, 1, cmpts[cmptno])) { + throw "error : jas_image_writecmpt"; + } + } + } + + char szfmt[4]; + *szfmt = '\0'; +#if CXIMAGE_SUPPORT_JP2 + if (imagetype == CXIMAGE_FORMAT_JP2) strcpy(szfmt,"jp2"); +#endif +#if CXIMAGE_SUPPORT_JPC + if (imagetype == CXIMAGE_FORMAT_JPC) strcpy(szfmt,"jpc"); +#endif +#if CXIMAGE_SUPPORT_RAS + if (imagetype == CXIMAGE_FORMAT_RAS) strcpy(szfmt,"ras"); +#endif +#if CXIMAGE_SUPPORT_PNM + if (imagetype == CXIMAGE_FORMAT_PNM) strcpy(szfmt,"pnm"); +#endif +#if CXIMAGE_SUPPORT_PGX + if (imagetype == CXIMAGE_FORMAT_PGX){ + strcpy(szfmt,"pgx"); + if (head.biClrUsed==0) throw "PGX can save only GrayScale images"; + } +#endif + int outfmt = jas_image_strtofmt(szfmt); + + char szoutopts[16]; + sprintf(szoutopts,"rate=%.3f", info.nQuality/100.0f); + + if (jas_image_encode(image, out, outfmt, szoutopts)) { + throw "error: cannot encode image\n"; + } + jas_stream_flush(out); + + } catch (char *message) { + strncpy(info.szLastError,message,255); + error = 1; + } + + for (x = 0; x < numcmpts; ++x) { if (cmpts[x]) { jas_matrix_destroy(cmpts[x]); } } + jas_cleanup(); + if (image) jas_image_destroy(image); + if (out) jas_stream_close(out); + + return (error==0); +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_JASPER + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajas.h ./win32/dependencies/cximage/ximajas.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajas.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajas.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,84 @@ +/* + * File: ximajas.h + * Purpose: Jasper Image Class Loader and Writer + */ +/* ========================================================== + * CxImageJAS (c) 12/Apr/2003 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * based on JasPer Copyright (c) 2001-2003 Michael David Adams - All rights reserved. + * ========================================================== + */ +#if !defined(__ximaJAS_h) +#define __ximaJAS_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_JASPER + +#include "../jasper/include/jasper/jasper.h" + +class CxImageJAS: public CxImage +{ +public: + CxImageJAS(): CxImage((DWORD)0) {} // cast to DWORD + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,0);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,0);} + bool Decode(CxFile * hFile, DWORD imagetype = 0); + bool Decode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Decode(&file,imagetype); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile, DWORD imagetype = 0); + bool Encode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Encode(&file,imagetype); } +#endif // CXIMAGE_SUPPORT_ENCODE +protected: + + class CxFileJas + { + public: + CxFileJas(CxFile* pFile,jas_stream_t *stream) + { + if (stream->obj_) jas_free(stream->obj_); + stream->obj_ = pFile; + + // - cannot set the stream->ops_->functions here, + // because this overwrites a static structure in the Jasper library. + // This structure is used by Jasper for internal operations too, e.g. tempfile. + // However the ops_ pointer in the stream can be overwritten. + + //stream->ops_->close_ = JasClose; + //stream->ops_->read_ = JasRead; + //stream->ops_->seek_ = JasSeek; + //stream->ops_->write_ = JasWrite; + + jas_stream_CxFile.close_ = JasClose; + jas_stream_CxFile.read_ = JasRead; + jas_stream_CxFile.seek_ = JasSeek; + jas_stream_CxFile.write_ = JasWrite; + + stream->ops_ = &jas_stream_CxFile; + + // - end + } + static int JasRead(jas_stream_obj_t *obj, char *buf, int cnt) + { return ((CxFile*)obj)->Read(buf,1,cnt); } + static int JasWrite(jas_stream_obj_t *obj, char *buf, int cnt) + { return ((CxFile*)obj)->Write(buf,1,cnt); } + static long JasSeek(jas_stream_obj_t *obj, long offset, int origin) + { return ((CxFile*)obj)->Seek(offset,origin); } + static int JasClose(jas_stream_obj_t *obj) + { return 1; } + + // + private: + jas_stream_ops_t jas_stream_CxFile; + // - end + + }; + +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajbg.cpp ./win32/dependencies/cximage/ximajbg.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajbg.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajbg.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,162 @@ +/* + * File: ximajbg.cpp + * Purpose: Platform Independent JBG Image Class Loader and Writer + * 18/Aug/2002 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximajbg.h" + +#if CXIMAGE_SUPPORT_JBG + +#include "ximaiter.h" + +#define JBIG_BUFSIZE 8192 + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJBG::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + struct jbg_dec_state jbig_state; + unsigned long xmax = 4294967295UL, ymax = 4294967295UL; + unsigned int len, cnt; + BYTE *buffer,*p; + int result; + + try + { + jbg_dec_init(&jbig_state); + jbg_dec_maxsize(&jbig_state, xmax, ymax); + + buffer = (BYTE*)malloc(JBIG_BUFSIZE); + if (!buffer) throw "Sorry, not enough memory available!"; + + result = JBG_EAGAIN; + do { + len = hFile->Read(buffer, 1, JBIG_BUFSIZE); + if (!len) break; + cnt = 0; + p = buffer; + while (len > 0 && (result == JBG_EAGAIN || result == JBG_EOK)) { + result = jbg_dec_in(&jbig_state, p, len, &cnt); + p += cnt; + len -= cnt; + } + } while (result == JBG_EAGAIN || result == JBG_EOK); + + if (hFile->Error()) + throw "Problem while reading input file"; + if (result != JBG_EOK && result != JBG_EOK_INTR) + throw "Problem with input file"; + + int w, h, bpp, planes, ew; + + w = jbg_dec_getwidth(&jbig_state); + h = jbg_dec_getheight(&jbig_state); + planes = jbg_dec_getplanes(&jbig_state); + bpp = (planes+7)>>3; + ew = (w + 7)>>3; + + switch (planes){ + case 1: + { + BYTE* binary_image = jbg_dec_getimage(&jbig_state, 0); + + if (!Create(w,h,1,CXIMAGE_FORMAT_JBG)) + throw "Can't allocate memory"; + + SetPaletteColor(0,255,255,255); + SetPaletteColor(1,0,0,0); + + CImageIterator iter(this); + iter.Upset(); + for (int i=0;i>3; + ew = (w + 7)>>3; + + BYTE mask; + RGBQUAD *rgb = GetPalette(); + if (CompareColors(&rgb[0],&rgb[1])<0) mask=255; else mask=0; + + BYTE *buffer = (BYTE*)malloc(ew*h*2); + if (!buffer) { + strcpy(info.szLastError,"Sorry, not enough memory available!"); + return false; + } + + for (y=0; yError()){ + strcpy(info.szLastError,"Problem while writing JBG file"); + return false; + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_JBG + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajbg.h ./win32/dependencies/cximage/ximajbg.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajbg.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajbg.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,44 @@ +/* + * File: ximajbg.h + * Purpose: JBG Image Class Loader and Writer + */ +/* ========================================================== + * CxImageJBG (c) 18/Aug/2002 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * based on LIBJBG Copyright (c) 2002, Markus Kuhn - All rights reserved. + * ========================================================== + */ +#if !defined(__ximaJBG_h) +#define __ximaJBG_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_JBG + +extern "C" { +#include "../jbig/jbig.h" +}; + +class CxImageJBG: public CxImage +{ +public: + CxImageJBG(): CxImage(CXIMAGE_FORMAT_JBG) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JBG);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JBG);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE +protected: + static void jbig_data_out(BYTE *buffer, unsigned int len, void *file) + {((CxFile*)file)->Write(buffer,len,1);} +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajpg.cpp ./win32/dependencies/cximage/ximajpg.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajpg.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajpg.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,454 @@ +/* + * File: ximajpg.cpp + * Purpose: Platform Independent JPEG Image Class Loader and Writer + * 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximajpg.h" + +#if CXIMAGE_SUPPORT_JPG + +#include "../jpeg/jmorecfg.h" + +#include "ximaiter.h" + +#include + +struct jpg_error_mgr { + struct jpeg_error_mgr pub; /* "public" fields */ + jmp_buf setjmp_buffer; /* for return to caller */ + char* buffer; /* error message */ +}; +typedef jpg_error_mgr *jpg_error_ptr; + +//////////////////////////////////////////////////////////////////////////////// +// Here's the routine that will replace the standard error_exit method: +//////////////////////////////////////////////////////////////////////////////// +static void +ima_jpeg_error_exit (j_common_ptr cinfo) +{ + /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ + jpg_error_ptr myerr = (jpg_error_ptr) cinfo->err; + /* Create the message */ + myerr->pub.format_message (cinfo, myerr->buffer); + /* Send it to stderr, adding a newline */ + /* Return control to the setjmp point */ + longjmp(myerr->setjmp_buffer, 1); +} +//////////////////////////////////////////////////////////////////////////////// +CxImageJPG::CxImageJPG(): CxImage(CXIMAGE_FORMAT_JPG) +{ +#if CXIMAGEJPG_SUPPORT_EXIF + m_exif = NULL; + memset(&m_exifinfo, 0, sizeof(EXIFINFO)); +#endif +} +//////////////////////////////////////////////////////////////////////////////// +CxImageJPG::~CxImageJPG() +{ +#if CXIMAGEJPG_SUPPORT_EXIF + if (m_exif) delete m_exif; +#endif +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGEJPG_SUPPORT_EXIF +bool CxImageJPG::DecodeExif(CxFile * hFile) +{ + m_exif = new CxExifInfo(&m_exifinfo); + if (m_exif){ + long pos=hFile->Tell(); + m_exif->DecodeExif(hFile); + hFile->Seek(pos,SEEK_SET); + return m_exif->m_exifinfo->IsExif; + } else { + return false; + } +} +#endif //CXIMAGEJPG_SUPPORT_EXIF +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJPG::Decode(CxFile * hFile) +{ + + bool is_exif = false; +#if CXIMAGEJPG_SUPPORT_EXIF + is_exif = DecodeExif(hFile); +#endif + + CImageIterator iter(this); + /* This struct contains the JPEG decompression parameters and pointers to + * working space (which is allocated as needed by the JPEG library). + */ + struct jpeg_decompress_struct cinfo; + /* We use our private extension JPEG error handler. */ + struct jpg_error_mgr jerr; + jerr.buffer=info.szLastError; + /* More stuff */ + JSAMPARRAY buffer; /* Output row buffer */ + int row_stride; /* physical row width in output buffer */ + + /* In this example we want to open the input file before doing anything else, + * so that the setjmp() error recovery below can assume the file is open. + * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that + * requires it in order to read binary files. + */ + + /* Step 1: allocate and initialize JPEG decompression object */ + /* We set up the normal JPEG error routines, then override error_exit. */ + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = ima_jpeg_error_exit; + + /* Establish the setjmp return context for my_error_exit to use. */ + if (setjmp(jerr.setjmp_buffer)) { + /* If we get here, the JPEG code has signaled an error. + * We need to clean up the JPEG object, close the input file, and return. + */ + jpeg_destroy_decompress(&cinfo); + return 0; + } + /* Now we can initialize the JPEG decompression object. */ + jpeg_create_decompress(&cinfo); + + /* Step 2: specify data source (eg, a file) */ + //jpeg_stdio_src(&cinfo, infile); + CxFileJpg src(hFile); + cinfo.src = &src; + + /* Step 3: read file parameters with jpeg_read_header() */ + (void) jpeg_read_header(&cinfo, TRUE); + + /* Step 4 handle decoder options*/ + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_GRAYSCALE) != 0) + cinfo.out_color_space = JCS_GRAYSCALE; + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_QUANTIZE) != 0) { + cinfo.quantize_colors = TRUE; + cinfo.desired_number_of_colors = info.nQuality; + } + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_DITHER) != 0) + cinfo.dither_mode = m_nDither; + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_ONEPASS) != 0) + cinfo.two_pass_quantize = FALSE; + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_NOSMOOTH) != 0) + cinfo.do_fancy_upsampling = FALSE; + +//: Load true color images as RGB (no quantize) +/* Step 4: set parameters for decompression */ +/* if (cinfo.jpeg_color_space!=JCS_GRAYSCALE) { + * cinfo.quantize_colors = TRUE; + * cinfo.desired_number_of_colors = 128; + *} + */ // + + // Set the scale + cinfo.scale_denom = GetJpegScale(); + + // Borrowed the idea from GIF implementation + if (info.nEscape == -1) { + // Return output dimensions only + jpeg_calc_output_dimensions(&cinfo); + head.biWidth = cinfo.output_width; + head.biHeight = cinfo.output_height; + jpeg_destroy_decompress(&cinfo); + return true; + } + + /* Step 5: Start decompressor */ + jpeg_start_decompress(&cinfo); + + /* We may need to do some setup of our own at this point before reading + * the data. After jpeg_start_decompress() we have the correct scaled + * output image dimensions available, as well as the output colormap + * if we asked for color quantization. + */ + //Create the image using output dimensions + //Create(cinfo.image_width, cinfo.image_height, 8*cinfo.output_components, CXIMAGE_FORMAT_JPG); + Create(cinfo.output_width, cinfo.output_height, 8*cinfo.output_components, CXIMAGE_FORMAT_JPG); + + if (!pDib) longjmp(jerr.setjmp_buffer, 1); // check if the image has been created + + if (is_exif){ +#if CXIMAGEJPG_SUPPORT_EXIF + if ((m_exifinfo.Xresolution != 0.0) && (m_exifinfo.ResolutionUnit != 0)) + SetXDPI((long)(m_exifinfo.Xresolution/m_exifinfo.ResolutionUnit)); + if ((m_exifinfo.Yresolution != 0.0) && (m_exifinfo.ResolutionUnit != 0)) + SetYDPI((long)(m_exifinfo.Yresolution/m_exifinfo.ResolutionUnit)); +#endif + } else { + if (cinfo.density_unit==2){ + SetXDPI((long)floor(cinfo.X_density * 254.0 / 10000.0 + 0.5)); + SetYDPI((long)floor(cinfo.Y_density * 254.0 / 10000.0 + 0.5)); + } else { + SetXDPI(cinfo.X_density); + SetYDPI(cinfo.Y_density); + } + } + + if (cinfo.out_color_space==JCS_GRAYSCALE){ + SetGrayPalette(); + head.biClrUsed =256; + } else { + if (cinfo.quantize_colors==TRUE){ + SetPalette(cinfo.actual_number_of_colors, cinfo.colormap[0], cinfo.colormap[1], cinfo.colormap[2]); + head.biClrUsed=cinfo.actual_number_of_colors; + } else { + head.biClrUsed=0; + } + } + + /* JSAMPLEs per row in output buffer */ + row_stride = cinfo.output_width * cinfo.output_components; + + /* Make a one-row-high sample array that will go away when done with image */ + buffer = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); + + /* Step 6: while (scan lines remain to be read) */ + /* jpeg_read_scanlines(...); */ + /* Here we use the library's state variable cinfo.output_scanline as the + * loop counter, so that we don't have to keep track ourselves. + */ + iter.Upset(); + while (cinfo.output_scanline < cinfo.output_height) { + + if (info.nEscape) longjmp(jerr.setjmp_buffer, 1); // - cancel decoding + + (void) jpeg_read_scanlines(&cinfo, buffer, 1); + // info.nProgress = (long)(100*cinfo.output_scanline/cinfo.output_height); + // Step 6a: CMYK->RGB */ + if ((cinfo.num_components==4)&&(cinfo.quantize_colors==FALSE)){ + BYTE k,*dst,*src; + dst=iter.GetRow(); + src=buffer[0]; + for(long x3=0,x4=0; x3<(long)info.dwEffWidth && x4 Step 7A: Swap red and blue components + // not necessary if swapped red and blue definition in jmorecfg.h;ln322 + if ((cinfo.num_components==3)&&(cinfo.quantize_colors==FALSE)){ + BYTE* r0=GetBits(); + for(long y=0;y - cancel decoding + RGBtoBGR(r0,3*head.biWidth); + r0+=info.dwEffWidth; + } + } + + /* Step 8: Release JPEG decompression object */ + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_decompress(&cinfo); + + /* At this point you may want to check to see whether any corrupt-data + * warnings occurred (test whether jerr.pub.num_warnings is nonzero). + */ + + /* And we're done! */ + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageJPG::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + if (head.biClrUsed!=0 && !IsGrayScale()){ + strcpy(info.szLastError,"JPEG can save only RGB or GreyScale images"); + return false; + } + + // necessary for EXIF, and for roll backs + long pos=hFile->Tell(); + + /* This struct contains the JPEG compression parameters and pointers to + * working space (which is allocated as needed by the JPEG library). + * It is possible to have several such structures, representing multiple + * compression/decompression processes, in existence at once. We refer + * to any one struct (and its associated working data) as a "JPEG object". + */ + struct jpeg_compress_struct cinfo; + /* This struct represents a JPEG error handler. It is declared separately + * because applications often want to supply a specialized error handler + * (see the second half of this file for an example). But here we just + * take the easy way out and use the standard error handler, which will + * print a message on stderr and call exit() if compression fails. + * Note that this struct must live as long as the main JPEG parameter + * struct, to avoid dangling-pointer problems. + */ + //struct jpeg_error_mgr jerr; + /* We use our private extension JPEG error handler. */ + struct jpg_error_mgr jerr; + jerr.buffer=info.szLastError; + /* More stuff */ + int row_stride; /* physical row width in image buffer */ + JSAMPARRAY buffer; /* Output row buffer */ + + /* Step 1: allocate and initialize JPEG compression object */ + /* We have to set up the error handler first, in case the initialization + * step fails. (Unlikely, but it could happen if you are out of memory.) + * This routine fills in the contents of struct jerr, and returns jerr's + * address which we place into the link field in cinfo. + */ + //cinfo.err = jpeg_std_error(&jerr); + /* We set up the normal JPEG error routines, then override error_exit. */ + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = ima_jpeg_error_exit; + + /* Establish the setjmp return context for my_error_exit to use. */ + if (setjmp(jerr.setjmp_buffer)) { + /* If we get here, the JPEG code has signaled an error. + * We need to clean up the JPEG object, close the input file, and return. + */ + strcpy(info.szLastError, jerr.buffer); // + jpeg_destroy_compress(&cinfo); + return 0; + } + + /* Now we can initialize the JPEG compression object. */ + jpeg_create_compress(&cinfo); + /* Step 2: specify data destination (eg, a file) */ + /* Note: steps 2 and 3 can be done in either order. */ + /* Here we use the library-supplied code to send compressed data to a + * stdio stream. You can also write your own code to do something else. + * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that + * requires it in order to write binary files. + */ + + //jpeg_stdio_dest(&cinfo, outfile); + CxFileJpg dest(hFile); + cinfo.dest = &dest; + + /* Step 3: set parameters for compression */ + /* First we supply a description of the input image. + * Four fields of the cinfo struct must be filled in: + */ + cinfo.image_width = GetWidth(); // image width and height, in pixels + cinfo.image_height = GetHeight(); + + if (IsGrayScale()){ + cinfo.input_components = 1; // # of color components per pixel + cinfo.in_color_space = JCS_GRAYSCALE; /* colorspace of input image */ + } else { + cinfo.input_components = 3; // # of color components per pixel + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + } + + /* Now use the library's routine to set default compression parameters. + * (You must set at least cinfo.in_color_space before calling this, + * since the defaults depend on the source color space.) + */ + jpeg_set_defaults(&cinfo); + /* Now you can set any non-default parameters you wish to. + * Here we just illustrate the use of quality (quantization table) scaling: + */ + +//#ifdef C_ARITH_CODING_SUPPORTED + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_ARITHMETIC) != 0) + cinfo.arith_code = TRUE; +//#endif + +//#ifdef ENTROPY_OPT_SUPPORTED + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_OPTIMIZE) != 0) + cinfo.optimize_coding = TRUE; +//#endif + + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_GRAYSCALE) != 0) + jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE); + + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_SMOOTHING) != 0) + cinfo.smoothing_factor = m_nSmoothing; + + jpeg_set_quality(&cinfo, GetJpegQuality(), (GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_BASELINE) != 0); + +//#ifdef C_PROGRESSIVE_SUPPORTED + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_PROGRESSIVE) != 0) + jpeg_simple_progression(&cinfo); +//#endif + +#ifdef C_LOSSLESS_SUPPORTED + if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_LOSSLESS) != 0) + jpeg_simple_lossless(&cinfo, m_nPredictor, m_nPointTransform); +#endif + + cinfo.density_unit=1; + cinfo.X_density=(unsigned short)GetXDPI(); + cinfo.Y_density=(unsigned short)GetYDPI(); + + /* Step 4: Start compressor */ + /* TRUE ensures that we will write a complete interchange-JPEG file. + * Pass TRUE unless you are very sure of what you're doing. + */ + jpeg_start_compress(&cinfo, TRUE); + + /* Step 5: while (scan lines remain to be written) */ + /* jpeg_write_scanlines(...); */ + /* Here we use the library's state variable cinfo.next_scanline as the + * loop counter, so that we don't have to keep track ourselves. + * To keep things simple, we pass one scanline per call; you can pass + * more if you wish, though. + */ + row_stride = info.dwEffWidth; /* JSAMPLEs per row in image_buffer */ + + // "8+row_stride" fix heap deallocation problem during debug??? + buffer = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, 8+row_stride, 1); + + CImageIterator iter(this); + + iter.Upset(); + while (cinfo.next_scanline < cinfo.image_height) { + // info.nProgress = (long)(100*cinfo.next_scanline/cinfo.image_height); + iter.GetRow(buffer[0], row_stride); + // not necessary if swapped red and blue definition in jmorecfg.h;ln322 + if (head.biClrUsed==0){ // swap R & B for RGB images + RGBtoBGR(buffer[0], row_stride); // Lance : 1998/09/01 : Bug ID: EXP-2.1.1-9 + } + iter.PrevRow(); + (void) jpeg_write_scanlines(&cinfo, buffer, 1); + } + + /* Step 6: Finish compression */ + jpeg_finish_compress(&cinfo); + + /* Step 7: release JPEG compression object */ + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_compress(&cinfo); + + +#if CXIMAGEJPG_SUPPORT_EXIF + if (m_exif && m_exif->m_exifinfo->IsExif){ + // discard useless sections (if any) read from original image + m_exif->DiscardAllButExif(); + // read new created image, to split the sections + hFile->Seek(pos,SEEK_SET); + m_exif->DecodeExif(hFile,EXIF_READ_IMAGE); + // save back the image, adding EXIF section + hFile->Seek(pos,SEEK_SET); + m_exif->EncodeExif(hFile); + } +#endif + + + /* And we're done! */ + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_JPG + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajpg.h ./win32/dependencies/cximage/ximajpg.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximajpg.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximajpg.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,315 @@ +/* + * File: ximajpg.h + * Purpose: JPG Image Class Loader and Writer + */ +/* ========================================================== + * CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * Special thanks to Chris Shearer Cooper for CxFileJpg tips & code + * + * EXIF support based on jhead-1.8 by Matthias Wandel + * + * original CImageJPG and CImageIterator implementation are: + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * This software is based in part on the work of the Independent JPEG Group. + * Copyright (C) 1991-1998, Thomas G. Lane. + * ========================================================== + */ +#if !defined(__ximaJPEG_h) +#define __ixmaJPEG_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_JPG + +#define CXIMAGEJPG_SUPPORT_EXIF 1 + +extern "C" { + #include "../jpeg/jpeglib.h" + #include "../jpeg/jerror.h" +} + +class DLL_EXP CxImageJPG: public CxImage +{ +public: + CxImageJPG(); + ~CxImageJPG(); + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + +/* + * EXIF support based on jhead-1.8 by Matthias Wandel + */ + +#if CXIMAGEJPG_SUPPORT_EXIF + +#define MAX_COMMENT 1000 +#define MAX_SECTIONS 20 + +typedef struct tag_ExifInfo { + char Version [5]; + char CameraMake [32]; + char CameraModel [40]; + char DateTime [20]; + int Height, Width; + int Orientation; + int IsColor; + int Process; + int FlashUsed; + float FocalLength; + float ExposureTime; + float ApertureFNumber; + float Distance; + float CCDWidth; + float ExposureBias; + int Whitebalance; + int MeteringMode; + int ExposureProgram; + int ISOequivalent; + int CompressionLevel; + float FocalplaneXRes; + float FocalplaneYRes; + float FocalplaneUnits; + float Xresolution; + float Yresolution; + float ResolutionUnit; + float Brightness; + char Comments[MAX_COMMENT]; + + unsigned char * ThumbnailPointer; /* Pointer at the thumbnail */ + unsigned ThumbnailSize; /* Size of thumbnail. */ + + bool IsExif; +} EXIFINFO; + +//-------------------------------------------------------------------------- +// JPEG markers consist of one or more 0xFF bytes, followed by a marker +// code byte (which is not an FF). Here are the marker codes of interest +// in this program. (See jdmarker.c for a more complete list.) +//-------------------------------------------------------------------------- + +#define M_SOF0 0xC0 // Start Of Frame N +#define M_SOF1 0xC1 // N indicates which compression process +#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use +#define M_SOF3 0xC3 +#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers +#define M_SOF6 0xC6 +#define M_SOF7 0xC7 +#define M_SOF9 0xC9 +#define M_SOF10 0xCA +#define M_SOF11 0xCB +#define M_SOF13 0xCD +#define M_SOF14 0xCE +#define M_SOF15 0xCF +#define M_SOI 0xD8 // Start Of Image (beginning of datastream) +#define M_EOI 0xD9 // End Of Image (end of datastream) +#define M_SOS 0xDA // Start Of Scan (begins compressed data) +#define M_JFIF 0xE0 // Jfif marker +#define M_EXIF 0xE1 // Exif marker +#define M_COM 0xFE // COMment + +#define PSEUDO_IMAGE_MARKER 0x123; // Extra value. + +#define EXIF_READ_EXIF 0x01 +#define EXIF_READ_IMAGE 0x02 +#define EXIF_READ_ALL 0x03 + +class DLL_EXP CxExifInfo +{ + +typedef struct tag_Section_t{ + BYTE* Data; + int Type; + unsigned Size; +} Section_t; + +public: + EXIFINFO* m_exifinfo; + char m_szLastError[256]; + CxExifInfo(EXIFINFO* info = NULL); + ~CxExifInfo(); + bool DecodeExif(CxFile * hFile, int nReadMode = EXIF_READ_EXIF); + bool EncodeExif(CxFile * hFile); + void DiscardAllButExif(); +protected: + bool process_EXIF(unsigned char * CharBuf, unsigned int length); + void process_COM (const BYTE * Data, int length); + void process_SOFn (const BYTE * Data, int marker); + int Get16u(void * Short); + int Get16m(void * Short); + long Get32s(void * Long); + unsigned long Get32u(void * Long); + double ConvertAnyFormat(void * ValuePtr, int Format); + void* FindSection(int SectionType); + bool ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, + EXIFINFO * const pInfo, unsigned char ** const LastExifRefdP); + int ExifImageWidth; + int MotorolaOrder; + Section_t Sections[MAX_SECTIONS]; + int SectionsRead; + bool freeinfo; +}; + + CxExifInfo* m_exif; + EXIFINFO m_exifinfo; + bool DecodeExif(CxFile * hFile); + bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); } + +#endif //CXIMAGEJPG_SUPPORT_EXIF + +//////////////////////////////////////////////////////////////////////////////////////// +////////////////////// C x F i l e J p g //////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// + +// thanks to Chris Shearer Cooper +class CxFileJpg : public jpeg_destination_mgr, public jpeg_source_mgr + { +public: + enum { eBufSize = 4096 }; + + CxFileJpg(CxFile* pFile) + { + m_pFile = pFile; + + init_destination = InitDestination; + empty_output_buffer = EmptyOutputBuffer; + term_destination = TermDestination; + + init_source = InitSource; + fill_input_buffer = FillInputBuffer; + skip_input_data = SkipInputData; + resync_to_restart = jpeg_resync_to_restart; // use default method + term_source = TermSource; + next_input_byte = NULL; //* => next byte to read from buffer + bytes_in_buffer = 0; //* # of bytes remaining in buffer + + m_pBuffer = new unsigned char[eBufSize]; + } + ~CxFileJpg() + { + delete [] m_pBuffer; + } + + static void InitDestination(j_compress_ptr cinfo) + { + CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; + pDest->next_output_byte = pDest->m_pBuffer; + pDest->free_in_buffer = eBufSize; + } + + static boolean EmptyOutputBuffer(j_compress_ptr cinfo) + { + CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; + if (pDest->m_pFile->Write(pDest->m_pBuffer,1,eBufSize)!=(size_t)eBufSize) + ERREXIT(cinfo, JERR_FILE_WRITE); + pDest->next_output_byte = pDest->m_pBuffer; + pDest->free_in_buffer = eBufSize; + return TRUE; + } + + static void TermDestination(j_compress_ptr cinfo) + { + CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; + size_t datacount = eBufSize - pDest->free_in_buffer; + /* Write any data remaining in the buffer */ + if (datacount > 0) { + if (!pDest->m_pFile->Write(pDest->m_pBuffer,1,datacount)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + pDest->m_pFile->Flush(); + /* Make sure we wrote the output file OK */ + if (pDest->m_pFile->Error()) ERREXIT(cinfo, JERR_FILE_WRITE); + return; + } + + static void InitSource(j_decompress_ptr cinfo) + { + CxFileJpg* pSource = (CxFileJpg*)cinfo->src; + pSource->m_bStartOfFile = TRUE; + } + + static boolean FillInputBuffer(j_decompress_ptr cinfo) + { + size_t nbytes; + CxFileJpg* pSource = (CxFileJpg*)cinfo->src; + nbytes = pSource->m_pFile->Read(pSource->m_pBuffer,1,eBufSize); + if (nbytes <= 0){ + if (pSource->m_bStartOfFile) //* Treat empty input file as fatal error + ERREXIT(cinfo, JERR_INPUT_EMPTY); + WARNMS(cinfo, JWRN_JPEG_EOF); + // Insert a fake EOI marker + pSource->m_pBuffer[0] = (JOCTET) 0xFF; + pSource->m_pBuffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } + pSource->next_input_byte = pSource->m_pBuffer; + pSource->bytes_in_buffer = nbytes; + pSource->m_bStartOfFile = FALSE; + return TRUE; + } + + static void SkipInputData(j_decompress_ptr cinfo, long num_bytes) + { + CxFileJpg* pSource = (CxFileJpg*)cinfo->src; + if (num_bytes > 0){ + while (num_bytes > (long)pSource->bytes_in_buffer){ + num_bytes -= (long)pSource->bytes_in_buffer; + FillInputBuffer(cinfo); + // note we assume that fill_input_buffer will never return FALSE, + // so suspension need not be handled. + } + pSource->next_input_byte += (size_t) num_bytes; + pSource->bytes_in_buffer -= (size_t) num_bytes; + } + } + + static void TermSource(j_decompress_ptr cinfo) + { + return; + } +protected: + CxFile *m_pFile; + unsigned char *m_pBuffer; + bool m_bStartOfFile; +}; + +public: + enum CODEC_OPTION + { + ENCODE_BASELINE = 0x1, + ENCODE_ARITHMETIC = 0x2, + ENCODE_GRAYSCALE = 0x4, + ENCODE_OPTIMIZE = 0x8, + ENCODE_PROGRESSIVE = 0x10, + ENCODE_LOSSLESS = 0x20, + ENCODE_SMOOTHING = 0x40, + DECODE_GRAYSCALE = 0x80, + DECODE_QUANTIZE = 0x100, + DECODE_DITHER = 0x200, + DECODE_ONEPASS = 0x400, + DECODE_NOSMOOTH = 0x800 + }; + + int m_nPredictor; + int m_nPointTransform; + int m_nSmoothing; + int m_nQuantize; + J_DITHER_MODE m_nDither; + +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximalpha.cpp ./win32/dependencies/cximage/ximalpha.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximalpha.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximalpha.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,321 @@ +// xImalpha.cpp : Alpha channel functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_ALPHA + +//////////////////////////////////////////////////////////////////////////////// +/** + * \sa AlphaSetMax + */ +BYTE CxImage::AlphaGetMax() const +{ + return info.nAlphaMax; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Sets global Alpha (opacity) value applied to the whole image, + * valid only for painting functions. + * \param nAlphaMax: can be from 0 to 255 + */ +void CxImage::AlphaSetMax(BYTE nAlphaMax) +{ + info.nAlphaMax=nAlphaMax; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Checks if the image has a valid alpha channel. + */ +bool CxImage::AlphaIsValid() +{ + return pAlpha!=0; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Enables the alpha palette, so the Draw() function changes its behavior. + */ +void CxImage::AlphaPaletteEnable(bool enable) +{ + info.bAlphaPaletteEnabled=enable; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * True if the alpha palette is enabled for painting. + */ +bool CxImage::AlphaPaletteIsEnabled() +{ + return info.bAlphaPaletteEnabled; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Inverts the alpha channel. + */ +void CxImage::AlphaClear() +{ + if (pAlpha) memset(pAlpha,0,head.biWidth * head.biHeight); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Sets the alpha level for the whole image + */ +void CxImage::AlphaSet(BYTE level) +{ + if (pAlpha) memset(pAlpha,level,head.biWidth * head.biHeight); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Allocates an empty (opaque) alpha channel. + */ +void CxImage::AlphaCreate() +{ + if (pAlpha==NULL) { + pAlpha = (BYTE*)malloc(head.biWidth * head.biHeight); + if (pAlpha) memset(pAlpha,255,head.biWidth * head.biHeight); + } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::AlphaDelete() +{ + if (pAlpha) { free(pAlpha); pAlpha=0; } +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::AlphaInvert() +{ + if (pAlpha) { + BYTE *iSrc=pAlpha; + long n=head.biHeight*head.biWidth; + for(long i=0; i < n; i++){ + *iSrc=(BYTE)~(*(iSrc)); + iSrc++; + } + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Imports an existing alpa channel from another image with the same width and height. + */ +bool CxImage::AlphaCopy(CxImage &from) +{ + if (from.pAlpha == NULL || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; + if (pAlpha==NULL) pAlpha = (BYTE*)malloc(head.biWidth * head.biHeight); + if (pAlpha==NULL) return false; + memcpy(pAlpha,from.pAlpha,head.biWidth * head.biHeight); + info.nAlphaMax=from.info.nAlphaMax; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Creates the alpha channel from a gray scale image. + */ +bool CxImage::AlphaSet(CxImage &from) +{ + if (!from.IsGrayScale() || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; + if (pAlpha==NULL) pAlpha = (BYTE*)malloc(head.biWidth * head.biHeight); + BYTE* src = from.info.pImage; + BYTE* dst = pAlpha; + if (src==NULL || dst==NULL) return false; + for (long y=0; yTransfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Exports the alpha palette channel in a 8bpp grayscale image. + */ +bool CxImage::AlphaPaletteSplit(CxImage *dest) +{ + if (!AlphaPaletteIsValid() || !dest) return false; + + CxImage tmp(head.biWidth,head.biHeight,8); + if (!tmp.IsValid()) return false; + + for(long y=0; yTransfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_ALPHA diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximalyr.cpp ./win32/dependencies/cximage/ximalyr.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximalyr.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximalyr.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,105 @@ +// xImaLyr.cpp : Layers functions +/* 21/04/2003 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_LAYERS + +//////////////////////////////////////////////////////////////////////////////// +/** + * If the object is an internal layer, GetParent return its parent in the hierarchy. + */ +CxImage* CxImage::GetParent() const +{ + return info.pParent; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Number of layers allocated directly by the object. + */ +long CxImage::GetNumLayers() const +{ + return info.nNumLayers; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Creates an empty layer. If position is less than 0, the new layer will be placed in the last position + */ +bool CxImage::LayerCreate(long position) +{ + if ( position < 0 || position > info.nNumLayers ) position = info.nNumLayers; + + CxImage** ptmp = (CxImage**)malloc((info.nNumLayers + 1)*sizeof(CxImage**)); + if (ptmp==0) return false; + + int i=0; + for (int n=0; ninfo.pParent = this; + } else { + free(ptmp); + return false; + } + + info.nNumLayers++; + if (pLayers) free(pLayers); + pLayers = ptmp; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Deletes a layer. If position is less than 0, the last layer will be deleted + */ +bool CxImage::LayerDelete(long position) +{ + if ( position >= info.nNumLayers ) return false; + if ( position < 0) position = info.nNumLayers - 1; + + CxImage** ptmp = (CxImage**)malloc((info.nNumLayers - 1)*sizeof(CxImage**)); + if (ptmp==0) return false; + + int i=0; + for (int n=0; n<(info.nNumLayers - 1); n++){ + if (position == n){ + delete pLayers[n]; + i=1; + } + ptmp[n]=pLayers[n+i]; + } + if (i==0) delete pLayers[info.nNumLayers - 1]; + + info.nNumLayers--; + if (pLayers) free(pLayers); + pLayers = ptmp; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::LayerDeleteAll() +{ + if (pLayers) { + for(long n=0; n= info.nNumLayers ) return 0; + if ( position < 0) position = info.nNumLayers - 1; + return pLayers[position]; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_LAYERS diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximamng.cpp ./win32/dependencies/cximage/ximamng.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximamng.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximamng.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,366 @@ +/* + * File: ximamng.cpp + * Purpose: Platform Independent MNG Image Class Loader and Writer + * Author: 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximamng.h" + +#if CXIMAGE_SUPPORT_MNG + +//////////////////////////////////////////////////////////////////////////////// +// callbacks for the mng decoder: +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// memory allocation; data must be zeroed +static mng_ptr +mymngalloc( mng_uint32 size ) +{ + return (mng_ptr)calloc(1, size); +} + +//////////////////////////////////////////////////////////////////////////////// +// memory deallocation +static void mymngfree(mng_ptr p, mng_uint32 size) +{ + free(p); +} + +//////////////////////////////////////////////////////////////////////////////// +// Stream open/close: +// since the user is responsible for opening and closing the file, +// we leave the default implementation open +static mng_bool mymngopenstream(mng_handle mng) { return MNG_TRUE; } +static mng_bool mymngopenstreamwrite(mng_handle mng) { return MNG_TRUE; } +static mng_bool mymngclosestream(mng_handle mng) { return MNG_TRUE; } + +//////////////////////////////////////////////////////////////////////////////// +// feed data to the decoder +static mng_bool mymngreadstream(mng_handle mng, mng_ptr buffer, mng_uint32 size, mng_uint32 *bytesread) +{ + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + // read the requested amount of data from the file + *bytesread = mymng->file->Read( buffer, sizeof(BYTE), size); + return MNG_TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +static mng_bool mymngwritestream (mng_handle mng, mng_ptr pBuf, mng_uint32 iSize, mng_uint32 *iWritten) +{ + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + // write it + *iWritten = mymng->file->Write (pBuf, 1, iSize); + return MNG_TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +// the header's been read. set up the display stuff +static mng_bool mymngprocessheader( mng_handle mng, mng_uint32 width, mng_uint32 height ) +{ + // normally the image buffer is allocated here, + // but in this module we don't know nothing about + // the final environment. + + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + + mymng->width = width; + mymng->height = height; + mymng->bpp = 24; + mymng->effwdt = ((((width * mymng->bpp) + 31) >> 5) << 2); + + if (mng->bUseBKGD){ + mymng->nBkgndIndex = 0; + mymng->nBkgndColor.rgbRed = mng->iBGred >> 8; + mymng->nBkgndColor.rgbGreen =mng->iBGgreen >> 8; + mymng->nBkgndColor.rgbBlue = mng->iBGblue >> 8; + } + + mymng->image = (BYTE*)malloc(height * mymng->effwdt); + + // tell the mng decoder about our bit-depth choice + mng_set_canvasstyle( mng, MNG_CANVAS_BGR8 ); + return MNG_TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +// return a row pointer for the decoder to fill +static mng_ptr mymnggetcanvasline( mng_handle mng, mng_uint32 line ) +{ + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + return (mng_ptr)(mymng->image + (mymng->effwdt * (mymng->height - 1 - line))); +} + +//////////////////////////////////////////////////////////////////////////////// +// timer +static mng_uint32 mymnggetticks(mng_handle mng) +{ +#ifdef WIN32 + return (mng_uint32)GetTickCount(); +#else + return 0; +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +// Refresh: actual frame need to be updated (Invalidate) +static mng_bool mymngrefresh(mng_handle mng, mng_uint32 x, mng_uint32 y, mng_uint32 w, mng_uint32 h) +{ +// mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + return MNG_TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +// interframe delay callback +static mng_bool mymngsettimer(mng_handle mng, mng_uint32 msecs) +{ + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + mymng->delay = msecs; // set the timer for when the decoder wants to be woken + return MNG_TRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +static mng_bool mymngerror(mng_handle mng, mng_int32 code, mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, mng_int32 extra1, mng_int32 extra2, mng_pchar text) +{ + //throw (const char *)text; + return mng_cleanup(&mng); // +} + +//////////////////////////////////////////////////////////////////////////////// +// CxImage members +//////////////////////////////////////////////////////////////////////////////// +CxImageMNG::CxImageMNG(): CxImage(CXIMAGE_FORMAT_MNG) +{ + hmng = NULL; + memset(&mnginfo,0,sizeof(mngstuff)); + mnginfo.nBkgndIndex = -1; + mnginfo.speed = 1.0f; +} +//////////////////////////////////////////////////////////////////////////////// +CxImageMNG::~CxImageMNG() +{ + // cleanup and return + if (mnginfo.thread){ //close the animation thread + mnginfo.animation_enabled=0; + ResumeThread(mnginfo.thread); + WaitForSingleObject(mnginfo.thread,500); + CloseHandle(mnginfo.thread); + } + // free objects + if (mnginfo.image) free(mnginfo.image); + if (hmng) mng_cleanup(&hmng); //be sure it's not needed any more. (active timers ?) +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageMNG::SetCallbacks(mng_handle mng) +{ + // set the callbacks + mng_setcb_errorproc(mng, mymngerror); + mng_setcb_openstream(mng, mymngopenstream); + mng_setcb_closestream(mng, mymngclosestream); + mng_setcb_readdata(mng, mymngreadstream); + mng_setcb_processheader(mng, mymngprocessheader); + mng_setcb_getcanvasline(mng, mymnggetcanvasline); + mng_setcb_refresh(mng, mymngrefresh); + mng_setcb_gettickcount(mng, mymnggetticks); + mng_setcb_settimer(mng, mymngsettimer); + mng_setcb_refresh(mng, mymngrefresh); +} +//////////////////////////////////////////////////////////////////////////////// +// can't use the CxImage implementation because it looses mnginfo +bool CxImageMNG::Load(const char * imageFileName){ + FILE* hFile; //file handle to read the image + if ((hFile=fopen(imageFileName,"rb"))==NULL) return false; + bool bOK = Decode(hFile); + fclose(hFile); + return bOK; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageMNG::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + try { + // set up the mng decoder for our stream + hmng = mng_initialize(&mnginfo, mymngalloc, mymngfree, MNG_NULL); + if (hmng == NULL) throw "could not initialize libmng"; + + // set the file we want to play + mnginfo.file = hFile; + + // Set the colorprofile, lcms uses this: + mng_set_srgb(hmng, MNG_TRUE ); + // Set white as background color: + WORD Red,Green,Blue; + Red = Green = Blue = (255 << 8) + 255; + mng_set_bgcolor(hmng, Red, Green, Blue ); + // If PNG Background is available, use it: + mng_set_usebkgd(hmng, MNG_TRUE ); + + // No need to store chunks: + mng_set_storechunks(hmng, MNG_FALSE); + // No need to wait: straight reading + mng_set_suspensionmode(hmng, MNG_FALSE); + + SetCallbacks(hmng); + + mng_datap pData = (mng_datap)hmng; + + // read in the image + info.nNumFrames=0; + mng_readdisplay(hmng); + + // read all + int retval=MNG_NOERROR; + while(pData->bReading){ + retval = mng_display_resume(hmng); + info.nNumFrames++; + } + + // single frame check: + if (retval != MNG_NEEDTIMERWAIT){ + info.nNumFrames--; + } else { + mnginfo.animation=1; + } + + if (info.nNumFrames<=0) info.nNumFrames=1; + + if (mnginfo.animation_enabled==0){ + // select the frame + if (info.nFrame>=0 && info.nFramewidth,OffsetH=mymng->height; + + BYTE *tmpbuffer = new BYTE[ (mymng->effwdt+1) * mymng->height]; + if( tmpbuffer == 0 ) return; + + // Write DEFI chunk. + mng_putchunk_defi( hMNG, 0, 0, 0, MNG_TRUE, OffsetX, OffsetY, MNG_FALSE, 0, 0, 0, 0 ); + + // Write Header: + mng_putchunk_ihdr( + hMNG, + OffsetW, OffsetH, + MNG_BITDEPTH_8, + MNG_COLORTYPE_RGB, + MNG_COMPRESSION_DEFLATE, + MNG_FILTER_ADAPTIVE, + MNG_INTERLACE_NONE + ); + + // transfer data, add Filterbyte: + for( int Row=0; Row No Filter. + tmpbuffer[Row*(mymng->effwdt+1)]=0; + // Copy the scanline: (reverse order) + memcpy(tmpbuffer+Row*(mymng->effwdt+1)+1, + mymng->image+((OffsetH-1-(OffsetY+Row))*(mymng->effwdt))+OffsetX,mymng->effwdt); + // swap red and blue components + RGBtoBGR(tmpbuffer+Row*(mymng->effwdt+1)+1,mymng->effwdt); + } + + // Compress data with ZLib (Deflate): + BYTE *dstbuffer = new BYTE[(mymng->effwdt+1)*OffsetH]; + if( dstbuffer == 0 ) return; + DWORD dstbufferSize=(mymng->effwdt+1)*OffsetH; + + // Compress data: + if(Z_OK != compress2((Bytef *)dstbuffer,(ULONG *)&dstbufferSize,(const Bytef*)tmpbuffer, + (ULONG) (mymng->effwdt+1)*OffsetH,9 )) return; + + // Write Data into MNG File: + mng_putchunk_idat( hMNG, dstbufferSize, (mng_ptr*)dstbuffer); + mng_putchunk_iend(hMNG); + + // Free the stuff: + delete [] tmpbuffer; + delete [] dstbuffer; +} +//////////////////////////////////////////////////////////////////////////////// +long CxImageMNG::Resume() +{ + if (MNG_NEEDTIMERWAIT == mng_display_resume(hmng)){ + if (info.pImage==NULL) Create(mnginfo.width,mnginfo.height,mnginfo.bpp, CXIMAGE_FORMAT_MNG); + if (IsValid()) memcpy(GetBits(), mnginfo.image, mnginfo.effwdt * mnginfo.height); + } else { + mnginfo.animation_enabled = 0; + } + return mnginfo.animation_enabled; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageMNG::SetSpeed(float speed) +{ + if (speed>10.0) mnginfo.speed = 10.0f; + else if (speed<0.1) mnginfo.speed = 0.1f; + else mnginfo.speed=speed; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_MNG diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximamng.h ./win32/dependencies/cximage/ximamng.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximamng.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximamng.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,86 @@ +/* + * File: ximamng.h + * Purpose: Declaration of the MNG Image Class + * Author: Davide Pizzolato - www.xdp.it + * Created: 2001 + */ +/* ========================================================== + * CxImageMNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Frank Haug for suggestions and code. + * + * original mng.cpp code created by Nikolaus Brennig, November 14th, 2000. + * + * LIBMNG Copyright (c) 2000,2001 Gerard Juyn (gerard@libmng.com) + * ========================================================== + */ + +#if !defined(__ximaMNG_h) +#define __ximaMNG_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_MNG + +//#define MNG_NO_CMS +#define MNG_SUPPORT_DISPLAY +#define MNG_SUPPORT_READ +#define MNG_SUPPORT_WRITE +#define MNG_ACCESS_CHUNKS +#define MNG_STORE_CHUNKS + +extern "C" { +#include "../mng/libmng.h" +#include "../mng/libmng_data.h" +} + +//unsigned long _stdcall RunMNGThread(void *lpParam); + +typedef struct tagmngstuff +{ + CxFile *file; + BYTE *image; + HANDLE thread; + mng_uint32 delay; + mng_uint32 width; + mng_uint32 height; + mng_uint32 effwdt; + mng_int16 bpp; + mng_bool animation; + mng_bool animation_enabled; + float speed; + long nBkgndIndex; + RGBQUAD nBkgndColor; +} mngstuff; + +class CxImageMNG: public CxImage +{ +public: + CxImageMNG(); + ~CxImageMNG(); + + bool Load(const char * imageFileName); + bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_MNG);} + + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + + long Resume(); + void SetSpeed(float speed); + + mng_handle hmng; + mngstuff mnginfo; +protected: + void WritePNG(mng_handle hMNG, int Frame, int FrameCount ); + void SetCallbacks(mng_handle mng); +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapal.cpp ./win32/dependencies/cximage/ximapal.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapal.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximapal.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,707 @@ +// xImaPal.cpp : Palette and Pixel functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * returns the palette dimension in byte + */ +DWORD CxImage::GetPaletteSize() +{ + return (head.biClrUsed * sizeof(RGBQUAD)); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha) +{ + if ((pDib)&&(head.biClrUsed)){ + BYTE* iDst = (BYTE*)(pDib) + sizeof(BITMAPINFOHEADER); + if (idx=head.biWidth)||(y>=head.biHeight)) { + if (info.nBkgndIndex != -1) return (BYTE)info.nBkgndIndex; + else return *info.pImage; + } + if (head.biBitCount==8){ + return info.pImage[y*info.dwEffWidth + x]; + } else { + BYTE pos; + BYTE iDst= info.pImage[y*info.dwEffWidth + (x*head.biBitCount >> 3)]; + if (head.biBitCount==4){ + pos = (BYTE)(4*(1-x%2)); + iDst &= (0x0F<> pos); + } else if (head.biBitCount==1){ + pos = (BYTE)(7-x%8); + iDst &= (0x01<> pos); + } + } + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +BYTE CxImage::BlindGetPixelIndex(const long x,const long y) +{ +#ifdef _DEBUG + if ((pDib==NULL) || (head.biClrUsed==0) || !IsInside(x,y)) throw 0; +#endif + + if (head.biBitCount==8){ + return info.pImage[y*info.dwEffWidth + x]; + } else { + BYTE pos; + BYTE iDst= info.pImage[y*info.dwEffWidth + (x*head.biBitCount >> 3)]; + if (head.biBitCount==4){ + pos = (BYTE)(4*(1-x%2)); + iDst &= (0x0F<> pos); + } else if (head.biBitCount==1){ + pos = (BYTE)(7-x%8); + iDst &= (0x01<> pos); + } + } + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +RGBQUAD CxImage::GetPixelColor(long x,long y, bool bGetAlpha) +{ +// RGBQUAD rgb={0,0,0,0}; + RGBQUAD rgb=info.nBkgndColor; // + if ((pDib==NULL)||(x<0)||(y<0)|| + (x>=head.biWidth)||(y>=head.biHeight)){ + if (info.nBkgndIndex != -1){ + if (head.biBitCount<24) return GetPaletteColor((BYTE)info.nBkgndIndex); + else return info.nBkgndColor; + } else if (pDib) return GetPixelColor(0,0); + return rgb; + } + + if (head.biClrUsed){ + rgb = GetPaletteColor(GetPixelIndex(x,y)); + } else { + BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; + rgb.rgbBlue = *iDst++; + rgb.rgbGreen= *iDst++; + rgb.rgbRed = *iDst; + } +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha && bGetAlpha) rgb.rgbReserved = AlphaGet(x,y); +#else + rgb.rgbReserved = 0; +#endif //CXIMAGE_SUPPORT_ALPHA + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * This is (a bit) faster version of GetPixelColor. + * It tests bounds only in debug mode (_DEBUG defined). + * + * It is an error to request out-of-borders pixel with this method. + * In DEBUG mode an exception will be thrown, and data will be violated in non-DEBUG mode. + * \author ***bd*** 2.2004 + */ +RGBQUAD CxImage::BlindGetPixelColor(const long x,const long y) +{ + RGBQUAD rgb; +#ifdef _DEBUG + if ((pDib==NULL) || !IsInside(x,y)) throw 0; +#endif + + if (head.biClrUsed){ + return GetPaletteColor(BlindGetPixelIndex(x,y)); + } + + BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; + rgb.rgbBlue = *iDst++; + rgb.rgbGreen= *iDst++; + rgb.rgbRed = *iDst; +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha) rgb.rgbReserved = pAlpha[x+y*head.biWidth]; +#else + rgb.rgbReserved = 0; +#endif //CXIMAGE_SUPPORT_ALPHA + return rgb; +} +//////////////////////////////////////////////////////////////////////////////// +BYTE CxImage::GetPixelGray(long x, long y) +{ + RGBQUAD color = GetPixelColor(x,y); + return (BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::SetPixelIndex(long x,long y,BYTE i) +{ + if ((pDib==NULL)||(head.biClrUsed==0)|| + (x<0)||(y<0)||(x>=head.biWidth)||(y>=head.biHeight)) return ; + + if (head.biBitCount==8){ + info.pImage[y*info.dwEffWidth + x]=i; + return; + } else { + BYTE pos; + BYTE* iDst= info.pImage + y*info.dwEffWidth + (x*head.biBitCount >> 3); + if (head.biBitCount==4){ + pos = (BYTE)(4*(1-x%2)); + *iDst &= ~(0x0F<=head.biWidth)||(y>=head.biHeight)) return; + if (head.biClrUsed) + SetPixelIndex(x,y,GetNearestIndex(c)); + else { + BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; + *iDst++ = c.rgbBlue; + *iDst++ = c.rgbGreen; + *iDst = c.rgbRed; +#if CXIMAGE_SUPPORT_ALPHA + if (bSetAlpha) AlphaSet(x,y,c.rgbReserved); +#endif //CXIMAGE_SUPPORT_ALPHA + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Blends the current pixel color with a new color. + * \param x,y = pixel + * \param c = new color + * \param blend = can be from 0 (no effect) to 1 (full effect). + * \param bSetAlpha = if true, blends also the alpha component stored in c.rgbReserved + */ +void CxImage::BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha) +{ + if ((pDib==NULL)||(x<0)||(y<0)|| + (x>=head.biWidth)||(y>=head.biHeight)) return; + + int a0 = (int)(256*blend); + int a1 = 256 - a0; + + RGBQUAD c0 = BlindGetPixelColor(x,y); + c.rgbRed = (BYTE)((c.rgbRed * a0 + c0.rgbRed * a1)>>8); + c.rgbBlue = (BYTE)((c.rgbBlue * a0 + c0.rgbBlue * a1)>>8); + c.rgbGreen = (BYTE)((c.rgbGreen * a0 + c0.rgbGreen * a1)>>8); + + if (head.biClrUsed) + SetPixelIndex(x,y,GetNearestIndex(c)); + else { + BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; + *iDst++ = c.rgbBlue; + *iDst++ = c.rgbGreen; + *iDst = c.rgbRed; +#if CXIMAGE_SUPPORT_ALPHA + if (bSetAlpha) AlphaSet(x,y,c.rgbReserved); +#endif //CXIMAGE_SUPPORT_ALPHA + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Returns the best palette index that matches a specified color. + */ +BYTE CxImage::GetNearestIndex(RGBQUAD c) +{ + if ((pDib==NULL)||(head.biClrUsed==0)) return 0; + + // check matching with the previous result + if (info.last_c_isvalid && (*(long*)&info.last_c == *(long*)&c)) return info.last_c_index; + info.last_c = c; + info.last_c_isvalid = true; + + BYTE* iDst = (BYTE*)(pDib) + sizeof(BITMAPINFOHEADER); + long distance=200000; + int i,j = 0; + long k,l; + int m = (int)(head.biClrImportant==0 ? head.biClrUsed : head.biClrImportant); + for(i=0,l=0;i100) perc=100; + for(i=0;i=0){ + if (head.biClrUsed){ + if (GetPixelIndex(x,y) == info.nBkgndIndex) return true; + } else { + RGBQUAD ct = info.nBkgndColor; + RGBQUAD c = GetPixelColor(x,y,false); + if (*(long*)&c==*(long*)&ct) return true; + } + } + +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha) return AlphaGet(x,y)==0; +#endif + + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Checks if image has the same palette, if any. + * \param img = image to compare. + * \param bCheckAlpha = check also the rgbReserved field. + */ +bool CxImage::IsSamePalette(CxImage &img, bool bCheckAlpha) +{ + if (head.biClrUsed != img.head.biClrUsed) + return false; + if (head.biClrUsed == 0) + return false; + + RGBQUAD c1,c2; + for (DWORD n=0; n256) { + head.biClrImportant = 0; + return; + } + + switch(head.biBitCount){ + case 1: + head.biClrImportant = min(ncolors,2); + break; + case 4: + head.biClrImportant = min(ncolors,16); + break; + case 8: + head.biClrImportant = ncolors; + break; + } + return; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Returns pointer to pixel. Currently implemented only for truecolor images. + * + * \param x,y - coordinates + * + * \return pointer to first byte of pixel data + * + * \author ***bd*** 2.2004 + */ +void* CxImage::BlindGetPixelPointer(const long x, const long y) +{ + if (!IsIndexed()) + return info.pImage + y*info.dwEffWidth + x*3; + else + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr) +{ + DrawLine(StartX, EndX, StartY, EndY, RGBtoRGBQUAD(cr)); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImage::DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha) +{ + if (!pDib) return; + ////////////////////////////////////////////////////// + // Draws a line using the Bresenham line algorithm + // Thanks to Jordan DeLozier + ////////////////////////////////////////////////////// + int x1 = StartX; + int y1 = StartY; + int x = x1; // Start x off at the first pixel + int y = y1; // Start y off at the first pixel + int x2 = EndX; + int y2 = EndY; + + int xinc1,xinc2,yinc1,yinc2; // Increasing values + int den, num, numadd,numpixels; + int deltax = abs(x2 - x1); // The difference between the x's + int deltay = abs(y2 - y1); // The difference between the y's + + // Get Increasing Values + if (x2 >= x1) { // The x-values are increasing + xinc1 = 1; + xinc2 = 1; + } else { // The x-values are decreasing + xinc1 = -1; + xinc2 = -1; + } + + if (y2 >= y1) { // The y-values are increasing + yinc1 = 1; + yinc2 = 1; + } else { // The y-values are decreasing + yinc1 = -1; + yinc2 = -1; + } + + // Actually draw the line + if (deltax >= deltay) // There is at least one x-value for every y-value + { + xinc1 = 0; // Don't change the x when numerator >= denominator + yinc2 = 0; // Don't change the y for every iteration + den = deltax; + num = deltax / 2; + numadd = deltay; + numpixels = deltax; // There are more x-values than y-values + } + else // There is at least one y-value for every x-value + { + xinc2 = 0; // Don't change the x for every iteration + yinc1 = 0; // Don't change the y when numerator >= denominator + den = deltay; + num = deltay / 2; + numadd = deltax; + numpixels = deltay; // There are more y-values than x-values + } + + for (int curpixel = 0; curpixel <= numpixels; curpixel++) + { + // Draw the current pixel + SetPixelColor(x,y,color,bSetAlpha); + + num += numadd; // Increase the numerator by the top of the fraction + if (num >= den) // Check if numerator >= denominator + { + num -= den; // Calculate the new numerator value + x += xinc1; // Change the x as appropriate + y += yinc1; // Change the y as appropriate + } + x += xinc2; // Change the x as appropriate + y += yinc2; // Change the y as appropriate + } +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Sets a palette with standard colors for 4 and 8 bpp images. + */ +void CxImage::SetStdPalette() +{ + if (!pDib) return; + switch (head.biBitCount){ + case 8: + { + const BYTE pal256[1024] = {0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0,128,0,0,0,128,0,128,0,128,128,0,0,192,192,192,0, + 192,220,192,0,240,202,166,0,212,240,255,0,177,226,255,0,142,212,255,0,107,198,255,0, + 72,184,255,0,37,170,255,0,0,170,255,0,0,146,220,0,0,122,185,0,0,98,150,0,0,74,115,0,0, + 50,80,0,212,227,255,0,177,199,255,0,142,171,255,0,107,143,255,0,72,115,255,0,37,87,255,0,0, + 85,255,0,0,73,220,0,0,61,185,0,0,49,150,0,0,37,115,0,0,25,80,0,212,212,255,0,177,177,255,0, + 142,142,255,0,107,107,255,0,72,72,255,0,37,37,255,0,0,0,254,0,0,0,220,0,0,0,185,0,0,0,150,0, + 0,0,115,0,0,0,80,0,227,212,255,0,199,177,255,0,171,142,255,0,143,107,255,0,115,72,255,0, + 87,37,255,0,85,0,255,0,73,0,220,0,61,0,185,0,49,0,150,0,37,0,115,0,25,0,80,0,240,212,255,0, + 226,177,255,0,212,142,255,0,198,107,255,0,184,72,255,0,170,37,255,0,170,0,255,0,146,0,220,0, + 122,0,185,0,98,0,150,0,74,0,115,0,50,0,80,0,255,212,255,0,255,177,255,0,255,142,255,0,255,107,255,0, + 255,72,255,0,255,37,255,0,254,0,254,0,220,0,220,0,185,0,185,0,150,0,150,0,115,0,115,0,80,0,80,0, + 255,212,240,0,255,177,226,0,255,142,212,0,255,107,198,0,255,72,184,0,255,37,170,0,255,0,170,0, + 220,0,146,0,185,0,122,0,150,0,98,0,115,0,74,0,80,0,50,0,255,212,227,0,255,177,199,0,255,142,171,0, + 255,107,143,0,255,72,115,0,255,37,87,0,255,0,85,0,220,0,73,0,185,0,61,0,150,0,49,0,115,0,37,0, + 80,0,25,0,255,212,212,0,255,177,177,0,255,142,142,0,255,107,107,0,255,72,72,0,255,37,37,0,254,0, + 0,0,220,0,0,0,185,0,0,0,150,0,0,0,115,0,0,0,80,0,0,0,255,227,212,0,255,199,177,0,255,171,142,0, + 255,143,107,0,255,115,72,0,255,87,37,0,255,85,0,0,220,73,0,0,185,61,0,0,150,49,0,0,115,37,0, + 0,80,25,0,0,255,240,212,0,255,226,177,0,255,212,142,0,255,198,107,0,255,184,72,0,255,170,37,0, + 255,170,0,0,220,146,0,0,185,122,0,0,150,98,0,0,115,74,0,0,80,50,0,0,255,255,212,0,255,255,177,0, + 255,255,142,0,255,255,107,0,255,255,72,0,255,255,37,0,254,254,0,0,220,220,0,0,185,185,0,0,150,150,0, + 0,115,115,0,0,80,80,0,0,240,255,212,0,226,255,177,0,212,255,142,0,198,255,107,0,184,255,72,0, + 170,255,37,0,170,255,0,0,146,220,0,0,122,185,0,0,98,150,0,0,74,115,0,0,50,80,0,0,227,255,212,0, + 199,255,177,0,171,255,142,0,143,255,107,0,115,255,72,0,87,255,37,0,85,255,0,0,73,220,0,0,61,185,0, + 0,49,150,0,0,37,115,0,0,25,80,0,0,212,255,212,0,177,255,177,0,142,255,142,0,107,255,107,0,72,255,72,0, + 37,255,37,0,0,254,0,0,0,220,0,0,0,185,0,0,0,150,0,0,0,115,0,0,0,80,0,0,212,255,227,0,177,255,199,0, + 142,255,171,0,107,255,143,0,72,255,115,0,37,255,87,0,0,255,85,0,0,220,73,0,0,185,61,0,0,150,49,0,0, + 115,37,0,0,80,25,0,212,255,240,0,177,255,226,0,142,255,212,0,107,255,198,0,72,255,184,0,37,255,170,0, + 0,255,170,0,0,220,146,0,0,185,122,0,0,150,98,0,0,115,74,0,0,80,50,0,212,255,255,0,177,255,255,0, + 142,255,255,0,107,255,255,0,72,255,255,0,37,255,255,0,0,254,254,0,0,220,220,0,0,185,185,0,0, + 150,150,0,0,115,115,0,0,80,80,0,242,242,242,0,230,230,230,0,218,218,218,0,206,206,206,0,194,194,194,0, + 182,182,182,0,170,170,170,0,158,158,158,0,146,146,146,0,134,134,134,0,122,122,122,0,110,110,110,0, + 98,98,98,0,86,86,86,0,74,74,74,0,62,62,62,0,50,50,50,0,38,38,38,0,26,26,26,0,14,14,14,0,240,251,255,0, + 164,160,160,0,128,128,128,0,0,0,255,0,0,255,0,0,0,255,255,0,255,0,0,0,255,0,255,0,255,255,0,0,255,255,255,0}; + memcpy(GetPalette(),pal256,1024); + break; + } + case 4: + { + const BYTE pal16[64]={0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0,128,0,0,0,128,0,128,0,128,128,0,0,192,192,192,0, + 128,128,128,0,0,0,255,0,0,255,0,0,0,255,255,0,255,0,0,0,255,0,255,0,255,255,0,0,255,255,255,0}; + memcpy(GetPalette(),pal16,64); + break; + } + } + return; +} +//////////////////////////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapcx.cpp ./win32/dependencies/cximage/ximapcx.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapcx.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximapcx.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,445 @@ +/* + * File: ximapcx.cpp + * Purpose: Platform Independent PCX Image Class Loader and Writer + * 05/Jan/2002 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + * + * based on ppmtopcx.c - convert a portable pixmap to PCX + * Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * based on ppmtopcx.c by Michael Davidson + */ + +#include "ximapcx.h" + +#if CXIMAGE_SUPPORT_PCX + +#include "xmemfile.h" + +#define PCX_MAGIC 0X0A // PCX magic number +#define PCX_256_COLORS 0X0C // magic number for 256 colors +#define PCX_HDR_SIZE 128 // size of PCX header +#define PCX_MAXCOLORS 256 +#define PCX_MAXPLANES 4 +#define PCX_MAXVAL 255 + +//////////////////////////////////////////////////////////////////////////////// +bool CxImagePCX::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + PCXHEADER pcxHeader; + int i, x, y, y2, nbytes, count, Height, Width; + BYTE c, ColorMap[PCX_MAXCOLORS][3]; + BYTE *pcximage = NULL, *lpHead1 = NULL, *lpHead2 = NULL; + BYTE *pcxplanes, *pcxpixels; + + try + { + if (hFile->Read(&pcxHeader,sizeof(PCXHEADER),1)==0) throw "Can't read PCX image"; + + if (pcxHeader.Manufacturer != PCX_MAGIC) throw "Error: Not a PCX file"; + // Check for PCX run length encoding + if (pcxHeader.Encoding != 1) throw "PCX file has unknown encoding scheme"; + + Width = (pcxHeader.Xmax - pcxHeader.Xmin) + 1; + Height = (pcxHeader.Ymax - pcxHeader.Ymin) + 1; + info.xDPI = pcxHeader.Hres; + info.yDPI = pcxHeader.Vres; + + // Check that we can handle this image format + if (pcxHeader.ColorPlanes > 4) + throw "Can't handle image with more than 4 planes"; + + // Create the image + if (pcxHeader.ColorPlanes >= 3 && pcxHeader.BitsPerPixel == 8){ + Create (Width, Height, 24, CXIMAGE_FORMAT_PCX); +#if CXIMAGE_SUPPORT_ALPHA + if (pcxHeader.ColorPlanes==4) AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + } else if (pcxHeader.ColorPlanes == 4 && pcxHeader.BitsPerPixel == 1) + Create (Width, Height, 4, CXIMAGE_FORMAT_PCX); + else + Create (Width, Height, pcxHeader.BitsPerPixel, CXIMAGE_FORMAT_PCX); + + if (info.nEscape) throw "Cancelled"; // - cancel decoding + + //Read the image and check if it's ok + nbytes = pcxHeader.BytesPerLine * pcxHeader.ColorPlanes * Height; + lpHead1 = pcximage = (BYTE*)malloc(nbytes); + while (nbytes > 0){ + if (hFile == NULL || hFile->Eof()) throw "corrupted PCX"; + + hFile->Read(&c,1,1); + if ((c & 0XC0) != 0XC0){ // Repeated group + *pcximage++ = c; + --nbytes; + continue; + } + count = c & 0X3F; // extract count + hFile->Read(&c,1,1); + if (count > nbytes) throw "repeat count spans end of image"; + + nbytes -= count; + while (--count >=0) *pcximage++ = c; + } + pcximage = lpHead1; + + //store the palette + for (i = 0; i < 16; i++){ + ColorMap[i][0] = pcxHeader.ColorMap[i][0]; + ColorMap[i][1] = pcxHeader.ColorMap[i][1]; + ColorMap[i][2] = pcxHeader.ColorMap[i][2]; + } + if (pcxHeader.BitsPerPixel == 8 && pcxHeader.ColorPlanes == 1){ + hFile->Read(&c,1,1); + if (c != PCX_256_COLORS) throw "bad color map signature"; + + for (i = 0; i < PCX_MAXCOLORS; i++){ + hFile->Read(&ColorMap[i][0],1,1); + hFile->Read(&ColorMap[i][1],1,1); + hFile->Read(&ColorMap[i][2],1,1); + } + } + if (pcxHeader.BitsPerPixel == 1 && pcxHeader.ColorPlanes == 1){ + ColorMap[0][0] = ColorMap[0][1] = ColorMap[0][2] = 0; + ColorMap[1][0] = ColorMap[1][1] = ColorMap[1][2] = 255; + } + + for (DWORD idx=0; idx - cancel decoding + + y2=Height-1-y; + pcxpixels = lpHead2; + pcxplanes = pcximage + (y * pcxHeader.BytesPerLine * pcxHeader.ColorPlanes); + + if (pcxHeader.ColorPlanes == 3 && pcxHeader.BitsPerPixel == 8){ + // Deal with 24 bit color image + for (x = 0; x < Width; x++){ + SetPixelColor(x,y2,RGB(pcxplanes[x],pcxplanes[pcxHeader.BytesPerLine + x],pcxplanes[2*pcxHeader.BytesPerLine + x])); + } + continue; +#if CXIMAGE_SUPPORT_ALPHA + } else if (pcxHeader.ColorPlanes == 4 && pcxHeader.BitsPerPixel == 8){ + for (x = 0; x < Width; x++){ + SetPixelColor(x,y2,RGB(pcxplanes[x],pcxplanes[pcxHeader.BytesPerLine + x],pcxplanes[2*pcxHeader.BytesPerLine + x])); + AlphaSet(x,y2,pcxplanes[3*pcxHeader.BytesPerLine + x]); + } + continue; +#endif //CXIMAGE_SUPPORT_ALPHA + } else if (pcxHeader.ColorPlanes == 1) { + PCX_UnpackPixels(pcxpixels, pcxplanes, pcxHeader.BytesPerLine, pcxHeader.ColorPlanes, pcxHeader.BitsPerPixel); + } else { + PCX_PlanesToPixels(pcxpixels, pcxplanes, pcxHeader.BytesPerLine, pcxHeader.ColorPlanes, pcxHeader.BitsPerPixel); + } + for (x = 0; x < Width; x++) SetPixelIndex(x,y2,pcxpixels[x]); + } + + } catch (char *message) { + strncpy(info.szLastError,message,255); + if (lpHead1){ free(lpHead1); lpHead1 = NULL; } + if (lpHead2){ free(lpHead2); lpHead2 = NULL; } + return false; + } + if (lpHead1){ free(lpHead1); lpHead1 = NULL; } + if (lpHead2){ free(lpHead2); lpHead2 = NULL; } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImagePCX::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + try { + PCXHEADER pcxHeader; + memset(&pcxHeader,0,sizeof(pcxHeader)); + pcxHeader.Manufacturer = PCX_MAGIC; + pcxHeader.Version = 5; + pcxHeader.Encoding = 1; + pcxHeader.Xmin = 0; + pcxHeader.Ymin = 0; + pcxHeader.Xmax = (WORD)head.biWidth-1; + pcxHeader.Ymax = (WORD)head.biHeight-1; + pcxHeader.Hres = (WORD)info.xDPI; + pcxHeader.Vres = (WORD)info.yDPI; + pcxHeader.Reserved = 0; + pcxHeader.PaletteType = head.biClrUsed==0; + + switch(head.biBitCount){ + case 24: + case 8: + { + pcxHeader.BitsPerPixel = 8; + pcxHeader.ColorPlanes = head.biClrUsed==0 ? 3 : 1; +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid() && head.biClrUsed==0) pcxHeader.ColorPlanes =4; +#endif //CXIMAGE_SUPPORT_ALPHA + pcxHeader.BytesPerLine = (WORD)head.biWidth; + break; + } + default: //(4 1) + pcxHeader.BitsPerPixel = 1; + pcxHeader.ColorPlanes = head.biClrUsed==16 ? 4 : 1; + pcxHeader.BytesPerLine = (WORD)((head.biWidth * pcxHeader.BitsPerPixel + 7)>>3); + } + + if (pcxHeader.BitsPerPixel == 1 && pcxHeader.ColorPlanes == 1){ + pcxHeader.ColorMap[0][0] = pcxHeader.ColorMap[0][1] = pcxHeader.ColorMap[0][2] = 0; + pcxHeader.ColorMap[1][0] = pcxHeader.ColorMap[1][1] = pcxHeader.ColorMap[1][2] = 255; + } + if (pcxHeader.BitsPerPixel == 1 && pcxHeader.ColorPlanes == 4){ + RGBQUAD c; + for (int i = 0; i < 16; i++){ + c=GetPaletteColor(i); + pcxHeader.ColorMap[i][0] = c.rgbRed; + pcxHeader.ColorMap[i][1] = c.rgbGreen; + pcxHeader.ColorMap[i][2] = c.rgbBlue; + } + } + + pcxHeader.BytesPerLine = (pcxHeader.BytesPerLine + 1)&(~1); + + if (hFile->Write(&pcxHeader, sizeof(pcxHeader), 1) == 0 ) + throw "cannot write PCX header"; + + CxMemFile buffer; + buffer.Open(); + + BYTE c,n; + long x,y; + if (head.biClrUsed==0){ + for (y = head.biHeight-1; y >=0 ; y--){ + for (int p=0; pWrite(buffer.GetBuffer(false),buffer.Size(),1); + + } else if (head.biBitCount==8) { + + for (y = head.biHeight-1; y >=0 ; y--){ + c=n=0; + for (x = 0; xWrite(buffer.GetBuffer(false),buffer.Size(),1); + + if (head.biBitCount == 8){ + hFile->PutC(0x0C); + BYTE* pal = (BYTE*)malloc(768); + RGBQUAD c; + for (int i=0;i<256;i++){ + c=GetPaletteColor(i); + pal[3*i+0] = c.rgbRed; + pal[3*i+1] = c.rgbGreen; + pal[3*i+2] = c.rgbBlue; + } + hFile->Write(pal,768,1); + free(pal); + } + } else { //(head.biBitCount==4) || (head.biBitCount==1) + + RGBQUAD *rgb = GetPalette(); + bool binvert = false; + if (CompareColors(&rgb[0],&rgb[1])>0) binvert=(head.biBitCount==1); + + BYTE* plane = (BYTE*)malloc(pcxHeader.BytesPerLine); + BYTE* raw = (BYTE*)malloc(head.biWidth); + + for(y = head.biHeight-1; y >=0 ; y--) { + + for( x = 0; x < head.biWidth; x++) raw[x] = (BYTE)GetPixelIndex(x,y); + + if (binvert) for( x = 0; x < head.biWidth; x++) raw[x] = 1-raw[x]; + + for( x = 0; x < pcxHeader.ColorPlanes; x++ ) { + PCX_PixelsToPlanes(raw, head.biWidth, plane, x); + PCX_PackPlanes(plane, pcxHeader.BytesPerLine, buffer); + } + } + + free(plane); + free(raw); + + hFile->Write(buffer.GetBuffer(false),buffer.Size(),1); + + } + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return false; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +// Convert multi-plane format into 1 pixel per byte +// from unpacked file data bitplanes[] into pixel row pixels[] +// image Height rows, with each row having planes image planes each +// bytesperline bytes +void CxImagePCX::PCX_PlanesToPixels(BYTE * pixels, BYTE * bitplanes, short bytesperline, short planes, short bitsperpixel) +{ + int i, j, npixels; + BYTE * p; + if (planes > 4) throw "Can't handle more than 4 planes"; + if (bitsperpixel != 1) throw "Can't handle more than 1 bit per pixel"; + + // Clear the pixel buffer + npixels = (bytesperline * 8) / bitsperpixel; + p = pixels; + while (--npixels >= 0) *p++ = 0; + + // Do the format conversion + for (i = 0; i < planes; i++){ + int pixbit, bits, mask; + p = pixels; + pixbit = (1 << i); // pixel bit for this plane + for (j = 0; j < bytesperline; j++){ + bits = *bitplanes++; + for (mask = 0X80; mask != 0; mask >>= 1, p++) + if (bits & mask) *p |= pixbit; + } + } +} +//////////////////////////////////////////////////////////////////////////////// +// convert packed pixel format into 1 pixel per byte +// from unpacked file data bitplanes[] into pixel row pixels[] +// image Height rows, with each row having planes image planes each +// bytesperline bytes +void CxImagePCX::PCX_UnpackPixels(BYTE * pixels, BYTE * bitplanes, short bytesperline, short planes, short bitsperpixel) +{ + register int bits; + if (planes != 1) throw "Can't handle packed pixels with more than 1 plane."; + + if (bitsperpixel == 8){ // 8 bits/pixels, no unpacking needed + while (bytesperline-- > 0) *pixels++ = *bitplanes++; + } else if (bitsperpixel == 4){ // 4 bits/pixel, two pixels per byte + while (bytesperline-- > 0){ + bits = *bitplanes++; + *pixels++ = (BYTE)((bits >> 4) & 0X0F); + *pixels++ = (BYTE)((bits) & 0X0F); + } + } else if (bitsperpixel == 2){ // 2 bits/pixel, four pixels per byte + while (bytesperline-- > 0){ + bits = *bitplanes++; + *pixels++ = (BYTE)((bits >> 6) & 0X03); + *pixels++ = (BYTE)((bits >> 4) & 0X03); + *pixels++ = (BYTE)((bits >> 2) & 0X03); + *pixels++ = (BYTE)((bits) & 0X03); + } + } else if (bitsperpixel == 1){ // 1 bits/pixel, 8 pixels per byte + while (bytesperline-- > 0){ + bits = *bitplanes++; + *pixels++ = ((bits & 0X80) != 0); + *pixels++ = ((bits & 0X40) != 0); + *pixels++ = ((bits & 0X20) != 0); + *pixels++ = ((bits & 0X10) != 0); + *pixels++ = ((bits & 0X08) != 0); + *pixels++ = ((bits & 0X04) != 0); + *pixels++ = ((bits & 0X02) != 0); + *pixels++ = ((bits & 0X01) != 0); + } + } +} +//////////////////////////////////////////////////////////////////////////////// +/* PCX_PackPixels(const long p,BYTE &c, BYTE &n, long &l, CxFile &f) + * p = current pixel (-1 ends the line -2 ends odd line) + * c = previous pixel + * n = number of consecutive pixels + */ +void CxImagePCX::PCX_PackPixels(const long p,BYTE &c, BYTE &n, CxFile &f) +{ + if (p!=c && n){ + if (n==1 && c<0xC0){ + f.PutC(c); + } else { + f.PutC(0xC0|n); + f.PutC(c); + } + n=0; + } + if (n==0x3F) { + f.PutC(0xFF); + f.PutC(c); + n=0; + } + if (p==-2) f.PutC(0); + c=(BYTE)p; + n++; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImagePCX::PCX_PackPlanes(BYTE* buff, const long size, CxFile &f) +{ + BYTE *start,*end; + BYTE c, previous, count; + + start = buff; + end = buff + size; + previous = *start++; + count = 1; + + while (start < end) { + c = *start++; + if (c == previous && count < 63) { + ++count; + continue; + } + + if (count > 1 || (previous & 0xc0) == 0xc0) { + f.PutC( count | 0xc0 ); + } + f.PutC(previous); + previous = c; + count = 1; + } + + if (count > 1 || (previous & 0xc0) == 0xc0) { + count |= 0xc0; + f.PutC(count); + } + f.PutC(previous); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImagePCX::PCX_PixelsToPlanes(BYTE* raw, long width, BYTE* buf, long plane) +{ + int cbit, x, mask; + unsigned char *cp = buf-1; + + mask = 1 << plane; + cbit = -1; + for( x = 0; x < width; x++ ) { + if( cbit < 0 ) { + cbit = 7; + *++cp = 0; + } + if( raw[x] & mask ) + *cp |= (1<jmpbuf, 1); +} +//////////////////////////////////////////////////////////////////////////////// +void CxImagePNG::expand2to4bpp(BYTE* prow) +{ + BYTE *psrc,*pdst; + BYTE pos,idx; + for(long x=head.biWidth-1;x>=0;x--){ + psrc = prow + ((2*x)>>3); + pdst = prow + ((4*x)>>3); + pos = (BYTE)(2*(3-x%4)); + idx = (BYTE)((*psrc & (0x03<>pos); + pos = (BYTE)(4*(1-x%2)); + *pdst &= ~(0x0F<jmpbuf)) { + /* Free all of the memory associated with the png_ptr and info_ptr */ + if (row_pointers) delete[] row_pointers; + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); + throw ""; + } + /* set up the input control */ + //png_init_io(png_ptr, hFile); + + // use custom I/O functions + png_set_read_fn(png_ptr, hFile, (png_rw_ptr)user_read_data); + png_set_error_fn(png_ptr,info.szLastError,(png_error_ptr)user_error_fn,NULL); + + /* read the file information */ + png_read_info(png_ptr, info_ptr); + + /* allocate the memory to hold the image using the fields of png_info. */ + png_color_16 my_background={ 0, 192, 192, 192, 0 }; + png_color_16 *image_background; + + if (info_ptr->pixel_depth != 32){ + // preserve original background info. + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background,PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background,PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); +// - we call png_set_bgr() below +// // safe check +// if (info_ptr->pixel_depth > 16 ) info_ptr->color_type = COLORTYPE_COLOR; + } + + // hack for images with alpha channel + if (info_ptr->pixel_depth == 32){ +// info.nBkgndIndex = 0; //enable transparency + if (png_get_bKGD(png_ptr, info_ptr, &image_background)){ + info.nBkgndColor.rgbRed = (BYTE)image_background->red; + info.nBkgndColor.rgbGreen = (BYTE)image_background->green; + info.nBkgndColor.rgbBlue = (BYTE)image_background->blue; + info.nBkgndColor.rgbReserved = 0; // + } + } + + /* tell libpng to strip 16 bit depth files down to 8 bits */ + if (info_ptr->bit_depth == 16) png_set_strip_16(png_ptr); + + int pixel_depth=info_ptr->pixel_depth; + if (pixel_depth > 16 ) pixel_depth=24; + if (pixel_depth == 16 ) pixel_depth=8; + + Create(info_ptr->width, info_ptr->height, pixel_depth, CXIMAGE_FORMAT_PNG); + + /* get metrics */ + switch (info_ptr->phys_unit_type) + { + case PNG_RESOLUTION_UNKNOWN: + SetXDPI(info_ptr->x_pixels_per_unit); + SetYDPI(info_ptr->y_pixels_per_unit); + break; + case PNG_RESOLUTION_METER: + SetXDPI((long)floor(info_ptr->x_pixels_per_unit * 254.0 / 10000.0 + 0.5)); + SetYDPI((long)floor(info_ptr->y_pixels_per_unit * 254.0 / 10000.0 + 0.5)); + break; + } + + if (info_ptr->num_palette>0) + SetPalette((rgb_color*)info_ptr->palette,info_ptr->num_palette); + else if (info_ptr->bit_depth ==2) { // needed for 2 bpp grayscale PNGs + SetPaletteColor(0,0,0,0); + SetPaletteColor(1,85,85,85); + SetPaletteColor(2,170,170,170); + SetPaletteColor(3,255,255,255); + } else SetGrayPalette(); // needed for grayscale PNGs + + // simple transparency (the real PGN transparency is more complex) + if (info_ptr->num_trans!=0){ + //palette transparency + RGBQUAD* pal=GetPalette(); + if (pal){ + DWORD ip; + for (ip=0;ipnum_trans);ip++) + pal[ip].rgbReserved=info_ptr->trans[ip]; + if (info_ptr->num_trans==1 && pal[0].rgbReserved==0){ + info.nBkgndIndex = 0; + } else { + info.bAlphaPaletteEnabled=true; + for (;ipcolor_type == PNG_COLOR_TYPE_RGB_ALPHA || //Alpha channel + (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->pixel_depth == 32)){ + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA){ + png_set_gray_to_rgb(png_ptr); + png_set_expand(png_ptr); + } +#if CXIMAGE_SUPPORT_ALPHA // + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + AlphaCreate(); +#else + png_set_strip_alpha(png_ptr); +#endif //CXIMAGE_SUPPORT_ALPHA + } + + // - flip the RGB pixels to BGR (or RGBA to BGRA) + if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) png_set_bgr(png_ptr); + + // - handle cancel + if (info.nEscape) longjmp(png_ptr->jmpbuf, 1); + + //allocate the buffer + int row_stride = info_ptr->width * ((info_ptr->pixel_depth+7)>>3); + row_pointers = new BYTE[10+row_stride]; + + // turn on interlace handling + number_passes = png_set_interlace_handling(png_ptr); + + if (number_passes>1){ + SetCodecOption(1); + } else { + SetCodecOption(0); + } + + for (int pass=0; pass< number_passes; pass++) { + iter.Upset(); + int y=0; + do { + + // - handle cancel + if (info.nEscape) longjmp(png_ptr->jmpbuf, 1); + +#if CXIMAGE_SUPPORT_ALPHA // + if (!AlphaIsValid()) +#endif // CXIMAGE_SUPPORT_ALPHA + { + //recover data from previous scan + if (info_ptr->interlace_type && pass>0) + iter.GetRow(row_pointers, info.dwEffWidth); + //read next row + png_read_row(png_ptr, row_pointers, NULL); +// - already done by png_set_bgr() +// //HACK BY OP && ( for interlace, swap only in the last pass) +// if (info_ptr->color_type==COLORTYPE_COLOR && pass==(number_passes-1)) +// RGBtoBGR(row_pointers, info.dwEffWidth); + // expand 2 bpp images only in the last pass + if (info_ptr->bit_depth==2 && pass==(number_passes-1)) + expand2to4bpp(row_pointers); + //copy the pixels + iter.SetRow(row_pointers, info.dwEffWidth); + //go on + iter.PrevRow(); + } +#if CXIMAGE_SUPPORT_ALPHA // + else { //alpha blend + + //compute the correct position of the line + long ax,ay; + ay = head.biHeight-1-y; + BYTE* prow= iter.GetRow(ay); + + //recover data from previous scan + if (info_ptr->interlace_type && pass>0 && pass!=7){ + for(ax=head.biWidth;ax>=0;ax--){ + row_pointers[ax*4]=prow[3*ax]; + row_pointers[ax*4+1]=prow[3*ax+1]; + row_pointers[ax*4+2]=prow[3*ax+2]; + row_pointers[ax*4+3]=AlphaGet(ax,ay); + } + } + + //read next row + png_read_row(png_ptr, row_pointers, NULL); + + //RGBA -> RGB + A + for(ax=0;axjmpbuf)){ + /* If we get here, we had a problem reading the file */ + if (info_ptr->palette) free(info_ptr->palette); + png_destroy_write_struct(&png_ptr, (png_infopp)&info_ptr); + throw "Error saving PNG file"; + } + + int row_stride = info.dwEffWidth; + /* set up the output control */ + //png_init_io(png_ptr, hFile); + + // use custom I/O functions + png_set_write_fn(png_ptr,hFile,(png_rw_ptr)user_write_data,(png_flush_ptr)user_flush_data); + + /* set the file information here */ + info_ptr->width = GetWidth(); + info_ptr->height = GetHeight(); + info_ptr->pixel_depth = (BYTE)GetBpp(); + info_ptr->channels = (GetBpp()>8) ? (BYTE)3: (BYTE)1; + info_ptr->bit_depth = (BYTE)(GetBpp()/info_ptr->channels); + info_ptr->color_type = GetColorType(); + info_ptr->compression_type = info_ptr->filter_type = 0; + info_ptr->valid = 0; + info_ptr->rowbytes = row_stride; + + switch(GetCodecOption(CXIMAGE_FORMAT_PNG)){ + case 1: + info_ptr->interlace_type = PNG_INTERLACE_ADAM7; + break; + default: + info_ptr->interlace_type = PNG_INTERLACE_NONE; + } + + /* set compression level */ + //png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + + /* set background */ + png_color_16 image_background={ 0, 255, 255, 255, 0 }; + if (info.nBkgndIndex!=-1) { + image_background.blue = info.nBkgndColor.rgbBlue; + image_background.green = info.nBkgndColor.rgbGreen; + image_background.red = info.nBkgndColor.rgbRed; + } + png_set_bKGD(png_ptr, info_ptr, &image_background); + + /* set metrics */ + png_set_pHYs(png_ptr, info_ptr, head.biXPelsPerMeter, head.biYPelsPerMeter, PNG_RESOLUTION_METER); + + /* set the palette if there is one */ + if (GetPalette()){ + png_set_IHDR(png_ptr, info_ptr, info_ptr->width, info_ptr->height, info_ptr->bit_depth, + PNG_COLOR_TYPE_PALETTE, info_ptr->interlace_type, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + info_ptr->valid |= PNG_INFO_PLTE; + + // simple transparency + if (info.nBkgndIndex != -1){ + trans[0]=0; + info_ptr->num_trans = 1; + info_ptr->valid |= PNG_INFO_tRNS; + info_ptr->trans = trans; + // the transparency indexes start from 0 + if (info.nBkgndIndex){ + SwapIndex(0,(BYTE)info.nBkgndIndex); + // the ghost must set the changed attributes in the body + if (info.pGhost) info.pGhost->SetTransIndex(0); + } + } + + int nc = GetNumColors(); + + /* We not need to write unused colors! */ + /* only for small images */ + if ((nc>2)&&((head.biWidth*head.biHeight)<65536)){ + nc = 0; + for (DWORD y=0;ync){ + nc=GetPixelIndex(x,y); + } + } + } + nc++; + } + + if (info.bAlphaPaletteEnabled){ + for(WORD ip=0; ipnum_trans = (WORD)nc; + info_ptr->valid |= PNG_INFO_tRNS; + info_ptr->trans = trans; + } + + // copy the palette colors + info_ptr->palette = new png_color[nc]; + info_ptr->num_palette = (png_uint_16) nc; + for (int i=0; ipalette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue); + + } + +#if CXIMAGE_SUPPORT_ALPHA // + //Merge the transparent color with the alpha channel + bool bNeedTempAlpha = false; + if (head.biBitCount==24 && info.nBkgndIndex>=0){ + if (!AlphaIsValid()){ + bNeedTempAlpha = true; + AlphaCreate(); + } + RGBQUAD c,ct=GetTransColor(); + for(long y=0; y < head.biHeight; y++){ + for(long x=0; x < head.biWidth ; x++){ + c=GetPixelColor(x,y,false); + if (*(long*)&c==*(long*)&ct) + AlphaSet(x,y,0); + }} + } +#endif // CXIMAGE_SUPPORT_ALPHA // + +#if CXIMAGE_SUPPORT_ALPHA // + if (AlphaIsValid()){ + row_stride = 4 * head.biWidth; + + info_ptr->pixel_depth = 32; + info_ptr->channels = 4; + info_ptr->bit_depth = 8; + info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + info_ptr->rowbytes = row_stride; + + /* write the file information */ + png_write_info(png_ptr, info_ptr); + + // "10+row_stride" fix heap deallocation problem during debug??? + BYTE *row_pointers = new BYTE[10+row_stride]; + + //interlace handling + int num_pass = png_set_interlace_handling(png_ptr); + for (int pass = 0; pass < num_pass; pass++){ + + //write image + iter.Upset(); + long ay=head.biHeight-1; + RGBQUAD c; + do { + for (long ax=head.biWidth-1; ax>=0;ax--){ + c=GetPixelColor(ax,ay); + row_pointers[ax*4+3]=(BYTE)((AlphaGet(ax,ay)*info.nAlphaMax)/255); + row_pointers[ax*4+2]=c.rgbBlue; + row_pointers[ax*4+1]=c.rgbGreen; + row_pointers[ax*4]=c.rgbRed; + } + png_write_row(png_ptr, row_pointers); + ay--; + } while(iter.PrevRow()); + } + + delete [] row_pointers; + } + else +#endif //CXIMAGE_SUPPORT_ALPHA // + { + /* write the file information */ + png_write_info(png_ptr, info_ptr); + /* If you are only writing one row at a time, this works */ + BYTE *row_pointers = new BYTE[10+row_stride]; + + //interlace handling + int num_pass = png_set_interlace_handling(png_ptr); + for (int pass = 0; pass < num_pass; pass++){ + + //write image + iter.Upset(); + do { + iter.GetRow(row_pointers, row_stride); + //HACK BY OP + if (info_ptr->color_type == 2 /*COLORTYPE_COLOR*/) + RGBtoBGR(row_pointers, row_stride); + png_write_row(png_ptr, row_pointers); + } while(iter.PrevRow()); + + } + + delete [] row_pointers; + } + +#if CXIMAGE_SUPPORT_ALPHA // + /* remove the temporary alpha channel*/ + if (bNeedTempAlpha) AlphaDelete(); +#endif // CXIMAGE_SUPPORT_ALPHA // + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); + + /* if you malloced the palette, free it here */ + if (info_ptr->palette) delete[] (info_ptr->palette); + + /* clean up after the write, and free any memory allocated */ + png_destroy_write_struct(&png_ptr, (png_infopp)&info_ptr); + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return FALSE; + } + /* that's it */ + return TRUE; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_PNG diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapng.h ./win32/dependencies/cximage/ximapng.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximapng.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximapng.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,73 @@ +/* + * File: ximapng.h + * Purpose: PNG Image Class Loader and Writer + */ +/* ========================================================== + * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * original CImagePNG and CImageIterator implementation are: + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson + * ========================================================== + */ +#if !defined(__ximaPNG_h) +#define __ximaPNG_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_PNG + +extern "C" { +#include "../png/png.h" +} + +class CxImagePNG: public CxImage +{ +public: + CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + +protected: + void ima_png_error(png_struct *png_ptr, char *message); + void expand2to4bpp(BYTE* prow); + + static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) + { + CxFile* hFile = (CxFile*)png_ptr->io_ptr; + if (hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error"); + } + + static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) + { + CxFile* hFile = (CxFile*)png_ptr->io_ptr; + if (hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error"); + } + + static void user_flush_data(png_structp png_ptr) + { + CxFile* hFile = (CxFile*)png_ptr->io_ptr; + if (!hFile->Flush()) png_error(png_ptr, "Flush Error"); + } + static void user_error_fn(png_structp png_ptr,png_const_charp error_msg) + { + strncpy((char*)png_ptr->error_ptr,error_msg,255); + longjmp(png_ptr->jmpbuf, 1); + } +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximasel.cpp ./win32/dependencies/cximage/ximasel.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximasel.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximasel.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,469 @@ +// xImaSel.cpp : Selection functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_SELECTION + +//////////////////////////////////////////////////////////////////////////////// +/** + * Checks if the image has a valid selection. + */ +bool CxImage::SelectionIsValid() +{ + return pSelection!=0; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Gets the smallest rectangle that contains the selection + */ +void CxImage::SelectionGetBox(RECT& r) +{ + memcpy(&r,&info.rSelectionBox,sizeof(RECT)); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Empties the selection. + */ +bool CxImage::SelectionClear() +{ + if (pSelection){ + memset(pSelection,0,head.biWidth * head.biHeight); + info.rSelectionBox.left = head.biWidth; + info.rSelectionBox.bottom = head.biHeight; + info.rSelectionBox.right = info.rSelectionBox.top = 0; + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Allocates an empty selection. + */ +bool CxImage::SelectionCreate() +{ + SelectionDelete(); + pSelection = (BYTE*)calloc(head.biWidth * head.biHeight, 1); + return (pSelection!=0); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Deallocates the selction. + */ +bool CxImage::SelectionDelete() +{ + if (pSelection){ free(pSelection); pSelection=NULL; } + info.rSelectionBox.left = head.biWidth; + info.rSelectionBox.bottom = head.biHeight; + info.rSelectionBox.right = info.rSelectionBox.top = 0; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Checks if the coordinates are inside the selection. + */ +bool CxImage::SelectionIsInside(long x, long y) +{ + if (IsInside(x,y)){ + if (pSelection==NULL) return true; + return pSelection[x+y*head.biWidth]!=0; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adds a rectangle to the existing selection. + */ +bool CxImage::SelectionAddRect(RECT r) +{ + if (pSelection==NULL) SelectionCreate(); + if (pSelection==NULL) return false; + + RECT r2; + if (r.left r2.left) info.rSelectionBox.left = max(0L,min(head.biWidth,r2.left)); + if (info.rSelectionBox.right < r2.right) info.rSelectionBox.right = max(0L,min(head.biWidth,r2.right)); + if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = max(0L,min(head.biHeight,r2.bottom)); + + long ymin = max(0L,min(head.biHeight,r2.bottom)); + long ymax = max(0L,min(head.biHeight,r2.top)); + long xmin = max(0L,min(head.biWidth,r2.left)); + long xmax = max(0L,min(head.biWidth,r2.right)); + + for (long y=ymin; y (xcenter - xradius)) info.rSelectionBox.left = max(0L,min(head.biWidth,(xcenter - xradius))); + if (info.rSelectionBox.right < (xcenter + xradius)) info.rSelectionBox.right = max(0L,min(head.biWidth,(xcenter + xradius))); + if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = max(0L,min(head.biHeight,(ycenter - yradius))); + if (info.rSelectionBox.top < (ycenter + yradius)) info.rSelectionBox.top = max(0L,min(head.biHeight,(ycenter + yradius))); + + long xmin = max(0L,min(head.biWidth,xcenter - xradius)); + long xmax = max(0L,min(head.biWidth,xcenter + xradius)); + long ymin = max(0L,min(head.biHeight,ycenter - yradius)); + long ymax = max(0L,min(head.biHeight,ycenter + yradius)); + + long y,yo; + for (y=ymin; yy) pSelection[x + y * head.biWidth] = 255; + } + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Inverts the selection. + */ +bool CxImage::SelectionInvert() +{ + if (pSelection) { + BYTE *iSrc=pSelection; + long n=head.biHeight*head.biWidth; + for(long i=0; i < n; i++){ + *iSrc=(BYTE)~(*(iSrc)); + iSrc++; + } + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Imports an existing region from another image with the same width and height. + */ +bool CxImage::SelectionCopy(CxImage &from) +{ + if (from.pSelection == NULL || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; + if (pSelection==NULL) pSelection = (BYTE*)malloc(head.biWidth * head.biHeight); + if (pSelection==NULL) return false; + memcpy(pSelection,from.pSelection,head.biWidth * head.biHeight); + memcpy(&info.rSelectionBox,&from.info.rSelectionBox,sizeof(RECT)); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adds a polygonal region to the existing selection. points points to an array of POINT structures. + * Each structure specifies the x-coordinate and y-coordinate of one vertex of the polygon. + * npoints specifies the number of POINT structures in the array pointed to by points. + */ +bool CxImage::SelectionAddPolygon(POINT *points, long npoints) +{ + if (points==NULL || npoints<3) return false; + + if (pSelection==NULL) SelectionCreate(); + if (pSelection==NULL) return false; + + BYTE* plocal = (BYTE*)calloc(head.biWidth*head.biHeight, 1); + RECT localbox = {head.biWidth,0,0,head.biHeight}; + + long x,y,i=0; + POINT *current,*next,*start; + //trace contour + while (i < npoints){ + current = &points[i]; + if (current->x!=-1){ + if (i==0 || (i>0 && points[i-1].x==-1)) start = &points[i]; + + if ((i+1)==npoints || points[i+1].x==-1) + next = start; + else + next = &points[i+1]; + + float beta; + if (current->x != next->x){ + beta = (float)(next->y - current->y)/(float)(next->x - current->x); + if (current->x < next->x){ + for (x=current->x; x<=next->x; x++){ + y = (long)(current->y + (x - current->x) * beta); + if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; + } + } else { + for (x=current->x; x>=next->x; x--){ + y = (long)(current->y + (x - current->x) * beta); + if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; + } + } + } + if (current->y != next->y){ + beta = (float)(next->x - current->x)/(float)(next->y - current->y); + if (current->y < next->y){ + for (y=current->y; y<=next->y; y++){ + x = (long)(current->x + (y - current->y) * beta); + if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; + } + } else { + for (y=current->y; y>=next->y; y--){ + x = (long)(current->x + (y - current->y) * beta); + if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; + } + } + } + } + + RECT r2; + if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; } + if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; } + if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1)); + if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1)); + if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1)); + if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1)); + + i++; + } + + //fill the outer region + long npix=(localbox.right - localbox.left)*(localbox.top - localbox.bottom); + POINT* pix = (POINT*)calloc(npix,sizeof(POINT)); + BYTE back=0, mark=1; + long fx, fy, fxx, fyy, first, last,xmin,xmax,ymin,ymax; + + for (int side=0; side<4; side++){ + switch(side){ + case 0: + xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.bottom+1; + break; + case 1: + xmin=localbox.right; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.top+1; + break; + case 2: + xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.top; ymax=localbox.top+1; + break; + case 3: + xmin=localbox.left; xmax=localbox.left+1; ymin=localbox.bottom; ymax=localbox.top+1; + break; + } + //fill from the border points + for(y=ymin;y=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) + { + plocal[fxx + fyy*head.biWidth] = mark; + if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ + pix[last].x = fx; + pix[last].y = fy - 1; + last++; + if (last == npix) last = 0; + } + if ((fyy + 1)=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) + { + plocal[fxx + (y + fy)*head.biWidth] = mark; + if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ + pix[last].x = fx; + pix[last].y = fy - 1; + last++; + if (last == npix) last = 0; + } + if ((fyy + 1) localbox.left) info.rSelectionBox.left = localbox.left; + if (info.rSelectionBox.right < localbox.right) info.rSelectionBox.right = localbox.right+1; + if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = localbox.bottom; + + free(plocal); + free(pix); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adds to the selection all the pixels matching the specified color. + */ +bool CxImage::SelectionAddColor(RGBQUAD c) +{ + if (pSelection==NULL) SelectionCreate(); + if (pSelection==NULL) return false; + + RECT localbox = {head.biWidth,0,0,head.biHeight}; + + for (long y = 0; y < head.biHeight; y++){ + for (long x = 0; x < head.biWidth; x++){ + RGBQUAD color = GetPixelColor(x, y); + if (color.rgbRed == c.rgbRed && + color.rgbGreen == c.rgbGreen && + color.rgbBlue == c.rgbBlue) + { + pSelection[x + y * head.biWidth] = 255; // set the correct mask bit + + if (localbox.top < y) localbox.top = y; + if (localbox.left > x) localbox.left = x; + if (localbox.right < x) localbox.right = x; + if (localbox.bottom > y) localbox.bottom = y; + } + } + } + + if (info.rSelectionBox.top < localbox.top) info.rSelectionBox.top = localbox.top; + if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = localbox.left; + if (info.rSelectionBox.right < localbox.right) info.rSelectionBox.right = localbox.right; + if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = localbox.bottom; + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Adds a single pixel to the existing selection. + */ +bool CxImage::SelectionAddPixel(int x, int y) +{ + if (pSelection==NULL) SelectionCreate(); + if (pSelection==NULL) return false; + + if (IsInside(x,y)) { + pSelection[x + y * head.biWidth] = 255; // set the correct mask bit + return true; + } + + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Exports the selection channel in a 8bpp grayscale image. + */ +bool CxImage::SelectionSplit(CxImage *dest) +{ + if (!pSelection || !dest) return false; + + CxImage tmp(head.biWidth,head.biHeight,8); + if (!tmp.IsValid()) return false; + + for(long y=0; yTransfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_WINDOWS +/** + * Converts the selection in a HRGN object. + */ +bool CxImage::SelectionToHRGN(HRGN& region) +{ + if (pSelection && region){ + for(int y = 0; y < head.biHeight; y++){ + HRGN hTemp = NULL; + int iStart = -1; + int x = 0; + for(; x < head.biWidth; x++){ + if (pSelection[x + y * head.biWidth] == 255){ + if (iStart == -1) iStart = x; + continue; + }else{ + if (iStart >= 0){ + hTemp = CreateRectRgn(iStart, y, x, y + 1); + CombineRgn(region, hTemp, region, RGN_OR); + DeleteObject(hTemp); + iStart = -1; + } + } + } + if (iStart >= 0){ + hTemp = CreateRectRgn(iStart, y, x, y + 1); + CombineRgn(region, hTemp, region, RGN_OR); + DeleteObject(hTemp); + iStart = -1; + } + } + return true; + } + return false; +} +#endif //CXIMAGE_SUPPORT_WINDOWS +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_SELECTION diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatga.cpp ./win32/dependencies/cximage/ximatga.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatga.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximatga.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,300 @@ +/* + * File: ximatga.cpp + * Purpose: Platform Independent TGA Image Class Loader and Writer + * 05/Jan/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximatga.h" + +#if CXIMAGE_SUPPORT_TGA + +#include "ximaiter.h" + +// Definitions for image types. +#define TGA_Null 0 +#define TGA_Map 1 +#define TGA_RGB 2 +#define TGA_Mono 3 +#define TGA_RLEMap 9 +#define TGA_RLERGB 10 +#define TGA_RLEMono 11 +#define TGA_CompMap 32 +#define TGA_CompMap4 33 + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageTGA::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + TGAHEADER tgaHead; + + try + { + if (hFile->Read(&tgaHead,sizeof(tgaHead),1)==0) + throw "Not a TGA"; + + bool bCompressed; + switch (tgaHead.ImageType){ + case TGA_Map: + case TGA_RGB: + case TGA_Mono: + bCompressed = false; + break; + case TGA_RLEMap: + case TGA_RLERGB: + case TGA_RLEMono: + bCompressed = true; + break; + default: + throw "Unknown TGA image type"; + } + + if (tgaHead.ImageWidth==0 || tgaHead.ImageHeight==0 || tgaHead.PixelDepth==0 || tgaHead.CmapLength>256) + throw "bad TGA header"; + + if (tgaHead.PixelDepth!=8 && tgaHead.PixelDepth!=15 && tgaHead.PixelDepth!=16 && tgaHead.PixelDepth!=24 && tgaHead.PixelDepth!=32) + throw "bad TGA header"; + + if (tgaHead.IdLength>0) hFile->Seek(tgaHead.IdLength,SEEK_CUR); //skip descriptor + + Create(tgaHead.ImageWidth, tgaHead.ImageHeight, tgaHead.PixelDepth, CXIMAGE_FORMAT_TGA); +#if CXIMAGE_SUPPORT_ALPHA // + if (tgaHead.PixelDepth==32) AlphaCreate(); // Image has alpha channel +#endif //CXIMAGE_SUPPORT_ALPHA + + if (!IsValid()) throw "TGA Create failed"; + + if (info.nEscape) throw "Cancelled"; // - cancel decoding + + if (tgaHead.CmapType != 0){ // read the palette + rgb_color pal[256]; + hFile->Read(pal,tgaHead.CmapLength*sizeof(rgb_color), 1); + for (int i=0;i - cancel decoding + + if (hFile == NULL || hFile->Eof()) throw "corrupted TGA"; + + if (bYReversed) pDest = iter.GetRow(tgaHead.ImageHeight-y-1); + else pDest = iter.GetRow(y); + + if (bCompressed) rleLeftover = ExpandCompressedLine(pDest,&tgaHead,hFile,tgaHead.ImageWidth,y,rleLeftover); + else ExpandUncompressedLine (pDest,&tgaHead,hFile,tgaHead.ImageWidth,y,0); + } + + if (bXReversed) Mirror(); + +#if CXIMAGE_SUPPORT_ALPHA + if (bYReversed && tgaHead.PixelDepth==32) AlphaFlip(); // +#endif //CXIMAGE_SUPPORT_ALPHA + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return FALSE; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageTGA::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + if (head.biBitCount<8){ + strcpy(info.szLastError,"Bit depth must be 8 or 24"); + return false; + } + + TGAHEADER tgaHead; + + tgaHead.IdLength = 0; // Image ID Field Length + tgaHead.CmapType = GetPalette()!=0; // Color Map Type + tgaHead.ImageType = (head.biBitCount == 8) ? (BYTE)TGA_Map : (BYTE)TGA_RGB; // Image Type + + tgaHead.CmapIndex=0; // First Entry Index + tgaHead.CmapLength=(head.biBitCount == 8) ? 256 : 0; // Color Map Length + tgaHead.CmapEntrySize=(head.biBitCount == 8) ? (BYTE)24 : (BYTE)0; // Color Map Entry Size + + tgaHead.X_Origin=0; // X-origin of Image + tgaHead.Y_Origin=0; // Y-origin of Image + tgaHead.ImageWidth=(WORD)head.biWidth; // Image Width + tgaHead.ImageHeight=(WORD)head.biHeight; // Image Height + tgaHead.PixelDepth=(BYTE)head.biBitCount; // Pixel Depth + tgaHead.ImagDesc=0; // Image Descriptor + + if (pAlpha && head.biBitCount==24) tgaHead.PixelDepth=32; + + hFile->Write(&tgaHead,sizeof(TGAHEADER),1); + + if (head.biBitCount==8){ + rgb_color pal[256]; + RGBQUAD* ppal = GetPalette(); + for (int i=0;i<256; i++){ + pal[i].r = ppal[i].rgbBlue; + pal[i].g = ppal[i].rgbGreen; + pal[i].b = ppal[i].rgbRed; + } + hFile->Write(&pal,256*sizeof(rgb_color),1); + } + + CImageIterator iter(this); + BYTE* pDest; + if (pAlpha==0 || head.biBitCount==8){ + for (int y=0; y < tgaHead.ImageHeight; y++){ + pDest = iter.GetRow(y); + hFile->Write(pDest,tgaHead.ImageWidth * (head.biBitCount >> 3),1); + } + } else { + pDest = (BYTE*)malloc(4*tgaHead.ImageWidth); + RGBQUAD c; + for (int y=0; y < tgaHead.ImageHeight; y++){ + for(int x=0, x4=0;x + pDest[x4+3]=(BYTE)((AlphaGet(x,y)*info.nAlphaMax)/255); +#else + pDest[x4+3]=0; +#endif //CXIMAGE_SUPPORT_ALPHA + } + hFile->Write(pDest,4*tgaHead.ImageWidth,1); + } + free(pDest); + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +BYTE CxImageTGA::ExpandCompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, BYTE rleLeftover) +{ + try{ + BYTE rle; + long filePos; + for (int x=0; xRead(&rle,1,1); + } + if (rle & 128) { // RLE-Encoded packet + rle -= 127; // Calculate real repeat count. + if ((x+rle)>width){ + rleLeftover = 128 + (rle - (width - x) - 1); + filePos = hFile->Tell(); + rle=width-x; + } + switch (ptgaHead->PixelDepth) + { + case 32: { + RGBQUAD color; + hFile->Read(&color,4,1); + for (int ix = 0; ix < rle; ix++){ + memcpy(&pDest[3*ix],&color,3); +#if CXIMAGE_SUPPORT_ALPHA // + AlphaSet(ix+x,y,color.rgbReserved); +#endif //CXIMAGE_SUPPORT_ALPHA + } + break; + } + case 24: { + rgb_color triple; + hFile->Read(&triple,3,1); + for (int ix = 0; ix < rle; ix++) memcpy(&pDest[3*ix],&triple,3); + break; + } + case 15: + case 16: { + WORD pixel; + hFile->Read(&pixel,2,1); + rgb_color triple; + triple.r = (BYTE)(( pixel & 0x1F ) * 8); // red + triple.g = (BYTE)(( pixel >> 2 ) & 0x0F8); // green + triple.b = (BYTE)(( pixel >> 7 ) & 0x0F8); // blue + for (int ix = 0; ix < rle; ix++){ + memcpy(&pDest[3*ix],&triple,3); + } + break; + } + case 8: { + BYTE pixel; + hFile->Read(&pixel,1,1); + for (int ix = 0; ix < rle; ix++) pDest[ix] = pixel; + } + } + if (rleLeftover!=255) hFile->Seek(filePos, SEEK_SET); + } else { // Raw packet + rle += 1; // Calculate real repeat count. + if ((x+rle)>width){ + rleLeftover = rle - (width - x) - 1; + rle=width-x; + } + ExpandUncompressedLine(pDest,ptgaHead,hFile,rle,y,x); + } + if (head.biBitCount == 24) pDest += rle*3; else pDest += rle; + x += rle; + } + } catch(...){ } + return rleLeftover; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageTGA::ExpandUncompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, int xoffset) +{ + try{ + switch (ptgaHead->PixelDepth){ + case 8: + hFile->Read(pDest,width,1); + break; + case 15: + case 16:{ + BYTE* dst=pDest; + WORD pixel; + for (int x=0; xRead(&pixel,2,1); + *dst++ = (BYTE)(( pixel & 0x1F ) * 8); // blue + *dst++ = (BYTE)(( pixel >> 2 ) & 0x0F8); // green + *dst++ = (BYTE)(( pixel >> 7 ) & 0x0F8); // red + } + break; + } + case 24: + hFile->Read(pDest,3*width,1); + break; + case 32:{ + BYTE* dst=pDest; + for (int x=0; xRead(&pixel,4,1); + *dst++ = pixel.rgbBlue; + *dst++ = pixel.rgbGreen; + *dst++ = pixel.rgbRed; +#if CXIMAGE_SUPPORT_ALPHA // + AlphaSet(x+xoffset,y,pixel.rgbReserved); //alpha +#endif //CXIMAGE_SUPPORT_ALPHA + } + break; + } + } + } catch(...){ } +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_TGA + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatga.h ./win32/dependencies/cximage/ximatga.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatga.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximatga.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,60 @@ +/* + * File: ximatga.h + * Purpose: TARGA Image Class Loader and Writer + */ +/* ========================================================== + * CxImageTGA (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Parts of the code come from Paintlib : Copyright (c) 1996-1998 Ulrich von Zadow + * ========================================================== + */ +#if !defined(__ximaTGA_h) +#define __ximaTGA_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_TGA + +class CxImageTGA: public CxImage +{ +#pragma pack(1) +typedef struct tagTgaHeader +{ + BYTE IdLength; // Image ID Field Length + BYTE CmapType; // Color Map Type + BYTE ImageType; // Image Type + + WORD CmapIndex; // First Entry Index + WORD CmapLength; // Color Map Length + BYTE CmapEntrySize; // Color Map Entry Size + + WORD X_Origin; // X-origin of Image + WORD Y_Origin; // Y-origin of Image + WORD ImageWidth; // Image Width + WORD ImageHeight; // Image Height + BYTE PixelDepth; // Pixel Depth + BYTE ImagDesc; // Image Descriptor +} TGAHEADER; +#pragma pack() + +public: + CxImageTGA(): CxImage(CXIMAGE_FORMAT_TGA) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TGA);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TGA);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE +protected: + BYTE ExpandCompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, BYTE rleLeftover); + void ExpandUncompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, int xoffset); +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximath.cpp ./win32/dependencies/cximage/ximath.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximath.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximath.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,97 @@ +#include "ximage.h" +#include "ximath.h" +#include + +//this module should contain some classes for geometrical transformations +//usable with selections, etc... once it's done, that is. :) + +CxPoint2::CxPoint2() +{ + x=y=0.0f; +} + +CxPoint2::CxPoint2(float const x_, float const y_) +{ + x=x_; + y=y_; +} + +CxPoint2::CxPoint2(CxPoint2 const &p) +{ + x=p.x; + y=p.y; +} + +float CxPoint2::Distance(CxPoint2 const p2) +{ + return (float)sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y)); +} + +float CxPoint2::Distance(float const x_, float const y_) +{ + return (float)sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_)); +} + +CxRect2::CxRect2() +{ +} + +CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const y2_) +{ + botLeft.x=x1_; + botLeft.y=y1_; + topRight.x=x2_; + topRight.y=y2_; +} + +CxRect2::CxRect2(CxRect2 const &p) +{ + botLeft=p.botLeft; + topRight=p.topRight; +} + +float CxRect2::Surface() const +/* + * Returns the surface of rectangle. + */ +{ + return (topRight.x-botLeft.x)*(topRight.y-botLeft.y); +} + +CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const +/* + * Returns crossection with another rectangle. + */ +{ + CxRect2 cs; + cs.botLeft.x=max(botLeft.x, r2.botLeft.x); + cs.botLeft.y=max(botLeft.y, r2.botLeft.y); + cs.topRight.x=min(topRight.x, r2.topRight.x); + cs.topRight.y=min(topRight.y, r2.topRight.y); + if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) { + return cs; + } else { + return CxRect2(0,0,0,0); + }//if +} + +CxPoint2 CxRect2::Center() const +/* + * Returns the center point of rectangle. + */ +{ + return CxPoint2((topRight.x+botLeft.x)/2.0f, (topRight.y+botLeft.y)/2.0f); +} + +float CxRect2::Width() const +//returns rectangle width +{ + return topRight.x-botLeft.x; +} + +float CxRect2::Height() const +//returns rectangle height +{ + return topRight.y-botLeft.y; +} + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximath.h ./win32/dependencies/cximage/ximath.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximath.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximath.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,39 @@ +#if !defined(__ximath_h) +#define __ximath_h + +#include "ximadef.h" + +//***bd*** simple floating point point +class DLL_EXP CxPoint2 +{ +public: + CxPoint2(); + CxPoint2(float const x_, float const y_); + CxPoint2(CxPoint2 const &p); + + float Distance(CxPoint2 const p2); + float Distance(float const x_, float const y_); + + float x,y; +}; + +//and simple rectangle +class DLL_EXP CxRect2 +{ +public: + CxRect2(); + CxRect2(float const x1_, float const y1_, float const x2_, float const y2_); + CxRect2(CxPoint2 const &bl, CxPoint2 const &tr); + CxRect2(CxRect2 const &p); + + float Surface() const; + CxRect2 CrossSection(CxRect2 const &r2) const; + CxPoint2 Center() const; + float Width() const; + float Height() const; + + CxPoint2 botLeft; + CxPoint2 topRight; +}; + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatif.cpp ./win32/dependencies/cximage/ximatif.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatif.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximatif.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,763 @@ +/* + * File: ximatif.cpp + * Purpose: Platform Independent TIFF Image Class Loader and Writer + * 07/Aug/2001 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximatif.h" + +#if CXIMAGE_SUPPORT_TIF + +#include "../tiff/tiffio.h" + +#define CVT(x) (((x) * 255L) / ((1L<<16)-1)) +#define SCALE(x) (((x)*((1L<<16)-1))/255) +#define CalculateLine(width,bitdepth) (((width * bitdepth) + 7) / 8) +#define CalculatePitch(line) (line + 3 & ~3) + +extern "C" TIFF* _TIFFOpenEx(CxFile* stream, const char* mode); + +//////////////////////////////////////////////////////////////////////////////// +CxImageTIF::~CxImageTIF() +{ + if (m_tif2) TIFFClose(m_tif2); +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageTIF::Decode(CxFile * hFile) +{ + //Comment this line if you need more information on errors + // TIFFSetErrorHandler(NULL); // + + //Open file and fill the TIFF structure + // m_tif = TIFFOpen(imageFileName,"rb"); + TIFF* m_tif = _TIFFOpenEx(hFile, "rb"); + + uint32 height=0; + uint32 width=0; + uint16 bitspersample=1; + uint16 samplesperpixel=1; + uint32 rowsperstrip=(DWORD)-1; + uint16 photometric=0; + uint16 compression=1; + uint16 orientation=ORIENTATION_TOPLEFT; // + uint16 res_unit; // + uint32 x, y; + float resolution, offset; + BOOL isRGB; + BYTE *bits; //pointer to source data + BYTE *bits2; //pointer to destination data + + try{ + //check if it's a tiff file + if (!m_tif) + throw "Error encountered while opening TIFF file"; + + // - 12/2002 : get NumFrames directly, instead of looping + // info.nNumFrames=0; + // while(TIFFSetDirectory(m_tif,(uint16)info.nNumFrames)) info.nNumFrames++; + info.nNumFrames = TIFFNumberOfDirectories(m_tif); + + if (!TIFFSetDirectory(m_tif, (uint16)info.nFrame)) + throw "Error: page not present in TIFF file"; + + //get image info + TIFFGetField(m_tif, TIFFTAG_IMAGEWIDTH, &width); + TIFFGetField(m_tif, TIFFTAG_IMAGELENGTH, &height); + TIFFGetField(m_tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); + TIFFGetField(m_tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); + TIFFGetField(m_tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); + TIFFGetField(m_tif, TIFFTAG_PHOTOMETRIC, &photometric); + TIFFGetField(m_tif, TIFFTAG_ORIENTATION, &orientation); + + if (info.nEscape == -1) { + // Return output dimensions only + head.biWidth = width; + head.biHeight = height; + throw "output dimensions returned"; + } + + TIFFGetFieldDefaulted(m_tif, TIFFTAG_RESOLUTIONUNIT, &res_unit); + if (TIFFGetField(m_tif, TIFFTAG_XRESOLUTION, &resolution)) + { + if (res_unit == RESUNIT_CENTIMETER) resolution = (float)(resolution*2.54f + 0.5f); + SetXDPI((long)resolution); + } + if (TIFFGetField(m_tif, TIFFTAG_YRESOLUTION, &resolution)) + { + if (res_unit == RESUNIT_CENTIMETER) resolution = (float)(resolution*2.54f + 0.5f); + SetYDPI((long)resolution); + } + + if (TIFFGetField(m_tif, TIFFTAG_XPOSITION, &offset)) info.xOffset = (long)offset; + if (TIFFGetField(m_tif, TIFFTAG_YPOSITION, &offset)) info.yOffset = (long)offset; + + head.biClrUsed=0; + info.nBkgndIndex =-1; + + if (rowsperstrip>height){ + rowsperstrip=height; + TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); + } + + isRGB = (bitspersample >= 8) && + (photometric == PHOTOMETRIC_RGB) || + (photometric == PHOTOMETRIC_YCBCR) || + (photometric == PHOTOMETRIC_SEPARATED) || + (photometric == PHOTOMETRIC_LOGL) || + (photometric == PHOTOMETRIC_LOGLUV); + + if (isRGB){ + head.biBitCount=24; + }else{ + if ((photometric==PHOTOMETRIC_MINISBLACK)||(photometric==PHOTOMETRIC_MINISWHITE)){ + if (bitspersample == 1){ + head.biBitCount=1; //B&W image + head.biClrUsed =2; + } else if (bitspersample == 4) { + head.biBitCount=4; //16 colors gray scale + head.biClrUsed =16; + } else { + head.biBitCount=8; //gray scale + head.biClrUsed =256; + } + } else if (bitspersample == 4) { + head.biBitCount=4; // 16 colors + head.biClrUsed=16; + } else { + head.biBitCount=8; //256 colors + head.biClrUsed=256; + } + } + + if (info.nEscape) throw "Cancelled"; // - cancel decoding + + Create(width,height,head.biBitCount,CXIMAGE_FORMAT_TIF); //image creation + if (!pDib) throw "CxImageTIF can't create image"; + +#if CXIMAGE_SUPPORT_ALPHA + if (samplesperpixel==4) AlphaCreate(); //add alpha support for 32bpp tiffs + if (samplesperpixel==2 && bitspersample==8) AlphaCreate(); //add alpha support for 8bpp + alpha +#endif //CXIMAGE_SUPPORT_ALPHA + + TIFFGetField(m_tif, TIFFTAG_COMPRESSION, &compression); + SetCodecOption(compression); // save original compression type + + if (isRGB) { + // Read the whole image into one big RGBA buffer using + // the traditional TIFFReadRGBAImage() API that we trust. + uint32* raster; // retrieve RGBA image + uint32 *row; + + raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32)); + if (raster == NULL) throw "No space for raster buffer"; + + // Read the image in one chunk into an RGBA array + if(!TIFFReadRGBAImage(m_tif, width, height, raster, 1)) { + _TIFFfree(raster); + throw "Corrupted TIFF file!"; + } + + // read the raster lines and save them in the DIB + // with RGB mode, we have to change the order of the 3 samples RGB + row = &raster[0]; + bits2 = info.pImage; + for (y = 0; y < height; y++) { + + if (info.nEscape){ // - cancel decoding + _TIFFfree(raster); + throw "Cancelled"; + } + + bits = bits2; + for (x = 0; x < width; x++) { + *bits++ = (BYTE)TIFFGetB(row[x]); + *bits++ = (BYTE)TIFFGetG(row[x]); + *bits++ = (BYTE)TIFFGetR(row[x]); +#if CXIMAGE_SUPPORT_ALPHA + if (samplesperpixel==4) AlphaSet(x,y,(BYTE)TIFFGetA(row[x])); +#endif //CXIMAGE_SUPPORT_ALPHA + } + row += width; + bits2 += info.dwEffWidth; + } + _TIFFfree(raster); + } else { + RGBQUAD *pal; + pal=(RGBQUAD*)calloc(256,sizeof(RGBQUAD)); + if (pal==NULL) throw "Unable to allocate TIFF palette"; + + // set up the colormap based on photometric + switch(photometric) { + case PHOTOMETRIC_MINISBLACK: // bitmap and greyscale image types + case PHOTOMETRIC_MINISWHITE: + if (bitspersample == 1) { // Monochrome image + if (photometric == PHOTOMETRIC_MINISBLACK) { + pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; + } else { + pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; + } + } else { // need to build the scale for greyscale images + if (photometric == PHOTOMETRIC_MINISBLACK) { + for (DWORD i=0; i 0) { + if (red[n] >= 256 || green[n] >= 256 || blue[n] >= 256) { + Palette16Bits=TRUE; + break; + } + } + + // load the palette in the DIB + for (int i = (1 << bitspersample) - 1; i >= 0; i--) { + if (Palette16Bits) { + pal[i].rgbRed =(BYTE) CVT(red[i]); + pal[i].rgbGreen = (BYTE) CVT(green[i]); + pal[i].rgbBlue = (BYTE) CVT(blue[i]); + } else { + pal[i].rgbRed = (BYTE) red[i]; + pal[i].rgbGreen = (BYTE) green[i]; + pal[i].rgbBlue = (BYTE) blue[i]; + } + } + break; + } + SetPalette(pal,head.biClrUsed); //palette assign + free(pal); + + // read the tiff lines and save them in the DIB + uint32 nrow; + uint32 ys; + int line = CalculateLine(width, bitspersample * samplesperpixel); + long bitsize= TIFFStripSize(m_tif); + //verify bitsize: could be wrong if StripByteCounts is missing. + if (bitsize>(long)(head.biSizeImage*samplesperpixel)) bitsize=head.biSizeImage*samplesperpixel; + + int tiled_image = TIFFIsTiled(m_tif); + uint32 tw, tl; + BYTE* tilebuf; + if (tiled_image){ + TIFFGetField(m_tif, TIFFTAG_TILEWIDTH, &tw); + TIFFGetField(m_tif, TIFFTAG_TILELENGTH, &tl); + rowsperstrip = tl; + bitsize = TIFFTileSize(m_tif) * (int)(1+width/tw); + tilebuf = (BYTE*)malloc(TIFFTileSize(m_tif)); + } + + bits = (BYTE*)malloc(bitsize); + if (bits==NULL){ + throw "CxImageTIF can't allocate memory"; + } + + for (ys = 0; ys < height; ys += rowsperstrip) { + + if (info.nEscape){ // - cancel decoding + free(bits); + throw "Cancelled"; + } + + nrow = (ys + rowsperstrip > height ? height - ys : rowsperstrip); + + if (tiled_image){ + uint32 imagew = TIFFScanlineSize(m_tif); + uint32 tilew = TIFFTileRowSize(m_tif); + int iskew = imagew - tilew; + uint8* bufp = (uint8*) bits; + + uint32 colb = 0; + for (uint32 col = 0; col < width; col += tw) { + if (TIFFReadTile(m_tif, tilebuf, col, ys, 0, 0) < 0){ + free(tilebuf); + free(bits); + throw "Corrupted tiled TIFF file!"; + } + + if (colb + tw > imagew) { + uint32 owidth = imagew - colb; + uint32 oskew = tilew - owidth; + TileToStrip(bufp + colb, tilebuf, nrow, owidth, oskew + iskew, oskew ); + } else { + TileToStrip(bufp + colb, tilebuf, nrow, tilew, iskew, 0); + } + colb += tilew; + } + + } else { + if (TIFFReadEncodedStrip(m_tif, TIFFComputeStrip(m_tif, ys, 0), bits, nrow * line) == -1) { + free(bits); + throw "Corrupted TIFF file!"; + } + } + + for (y = 0; y < nrow; y++) { + long offset=(nrow-y-1)*line; + if (bitspersample==16) for (DWORD xi=0;xi=(int)width){ + yi--; + xi=0; + } + } + } else { //photometric==PHOTOMETRIC_CIELAB + if (head.biBitCount!=24){ //fix image + Create(width,height,24,CXIMAGE_FORMAT_TIF); +#if CXIMAGE_SUPPORT_ALPHA + if (samplesperpixel==4) AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + } + + int xi=0; + int ii=0; + int yi=height-ys-nrow+y; + RGBQUAD c; + int l,a,b,bitsoffset; + double p,cx,cy,cz,cr,cg,cb; + while (ii127) a-=256; + if (b>127) b-=256; + // lab to xyz + p = (l/2.55 + 16) / 116.0; + cx = pow( p + a * 0.002, 3); + cy = pow( p, 3); + cz = pow( p - b * 0.005, 3); + // white point + cx*=0.95047; + //cy*=1.000; + cz*=1.0883; + // xyz to rgb + cr = 3.240479 * cx - 1.537150 * cy - 0.498535 * cz; + cg = -0.969256 * cx + 1.875992 * cy + 0.041556 * cz; + cb = 0.055648 * cx - 0.204043 * cy + 1.057311 * cz; + + if ( cr > 0.00304 ) cr = 1.055 * pow(cr,0.41667) - 0.055; + else cr = 12.92 * cr; + if ( cg > 0.00304 ) cg = 1.055 * pow(cg,0.41667) - 0.055; + else cg = 12.92 * cg; + if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055; + else cb = 12.92 * cb; + + c.rgbRed =(BYTE)max(0,min(255,(int)(cr*255))); + c.rgbGreen=(BYTE)max(0,min(255,(int)(cg*255))); + c.rgbBlue =(BYTE)max(0,min(255,(int)(cb*255))); + + SetPixelColor(xi,yi,c); +#if CXIMAGE_SUPPORT_ALPHA + if (samplesperpixel==4) AlphaSet(xi,yi,bits[bitsoffset+3]); +#endif //CXIMAGE_SUPPORT_ALPHA + ii++; + xi++; + if (xi>=(int)width){ + yi--; + xi=0; + } + } + } + } + } + free(bits); + if (tiled_image) free(tilebuf); + + switch(orientation){ + case ORIENTATION_TOPRIGHT: /* row 0 top, col 0 rhs */ + Mirror(); + break; + case ORIENTATION_BOTRIGHT: /* row 0 bottom, col 0 rhs */ + Flip(); + Mirror(); + break; + case ORIENTATION_BOTLEFT: /* row 0 bottom, col 0 lhs */ + Flip(); + break; + case ORIENTATION_LEFTTOP: /* row 0 lhs, col 0 top */ + RotateRight(); + Mirror(); + break; + case ORIENTATION_RIGHTTOP: /* row 0 rhs, col 0 top */ + RotateLeft(); + break; + case ORIENTATION_RIGHTBOT: /* row 0 rhs, col 0 bottom */ + RotateLeft(); + Mirror(); + break; + case ORIENTATION_LEFTBOT: /* row 0 lhs, col 0 bottom */ + RotateRight(); + break; + } + + } + } catch (char *message) { + strncpy(info.szLastError,message,255); + if (m_tif) TIFFClose(m_tif); + if (info.nEscape==-1) return true; + return false; + } + TIFFClose(m_tif); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageTIF::Encode(CxFile * hFile, bool bAppend) +{ + try{ + if (hFile==NULL) throw CXIMAGE_ERR_NOFILE; + if (pDib==NULL) throw CXIMAGE_ERR_NOIMAGE; + + // replaced "w+b" with "a", to append an image directly on an existing file + if (m_tif2==NULL) m_tif2=_TIFFOpenEx(hFile, "a"); + if (m_tif2==NULL) throw "initialization fail"; + + if (bAppend || m_pages) m_multipage=true; + m_pages++; + + if (!EncodeBody(m_tif2,m_multipage,m_pages,m_pages)) throw "Error saving TIFF file"; + if (bAppend) { + if (!TIFFWriteDirectory(m_tif2)) throw "Error saving TIFF directory"; + } + } catch (char *message) { + strncpy(info.szLastError,message,255); + if (m_tif2){ + TIFFClose(m_tif2); + m_tif2=NULL; + m_multipage=false; + m_pages=0; + } + return false; + } + if (!bAppend){ + TIFFClose(m_tif2); + m_tif2=NULL; + m_multipage=false; + m_pages=0; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +// Thanks to Abe +bool CxImageTIF::Encode(CxFile * hFile, CxImage ** pImages, int pagecount) +{ + try{ + if (hFile==NULL) throw "invalid file pointer"; + if (pImages==NULL || pagecount==0) throw "multipage TIFF, no images!"; + + CxImageTIF ghost; + for (int i=1; i<=pagecount; i++){ + if (pImages[i-1]==NULL) throw "Bad image pointer"; + ghost.Ghost(pImages[i-1]); + if (!ghost.Encode(hFile,true)) throw "Error saving TIFF file"; + } + } catch (char *message) { + strncpy(info.szLastError,message,255); + return false; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImageTIF::EncodeBody(TIFF *m_tif, bool multipage, int page, int pagecount) +{ + uint32 height=head.biHeight; + uint32 width=head.biWidth; + uint16 bitcount=head.biBitCount; + uint16 bitspersample; + uint16 samplesperpixel; + uint16 photometric=0; + uint16 compression; +// uint16 pitch; +// int line; + uint32 x, y; + + samplesperpixel = ((bitcount == 24) || (bitcount == 32)) ? (BYTE)3 : (BYTE)1; +#if CXIMAGE_SUPPORT_ALPHA + if (bitcount==24 && AlphaIsValid()) { bitcount=32; samplesperpixel=4; } +#endif //CXIMAGE_SUPPORT_ALPHA + + bitspersample = bitcount / samplesperpixel; + + //set the PHOTOMETRIC tag + RGBQUAD *rgb = GetPalette(); + switch (bitcount) { + case 1: + if (CompareColors(&rgb[0],&rgb[1])<0) { + /* some viewers do not handle PHOTOMETRIC_MINISBLACK: + * let's transform the image in PHOTOMETRIC_MINISWHITE + */ + //invert the colors + RGBQUAD tempRGB=GetPaletteColor(0); + SetPaletteColor(0,GetPaletteColor(1)); + SetPaletteColor(1,tempRGB); + //invert the pixels + BYTE *iSrc=info.pImage; + for (unsigned long i=0;irgbRed != x)||(rgb->rgbRed != rgb->rgbGreen)||(rgb->rgbRed != rgb->rgbBlue)){ + photometric = PHOTOMETRIC_PALETTE; + break; + } + rgb++; + } + break; + case 24: + case 32: + photometric = PHOTOMETRIC_RGB; + break; + } + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid() && bitcount==8) samplesperpixel=2; //8bpp + alpha layer +#endif //CXIMAGE_SUPPORT_ALPHA + +// line = CalculateLine(width, bitspersample * samplesperpixel); +// pitch = (uint16)CalculatePitch(line); + + //prepare the palette struct + RGBQUAD pal[256]; + if (GetPalette()){ + BYTE b; + memcpy(pal,GetPalette(),GetPaletteSize()); + for(WORD a=0;a gives better compression + TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); + + // handle metrics + TIFFSetField(m_tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + TIFFSetField(m_tif, TIFFTAG_XRESOLUTION, (float)info.xDPI); + TIFFSetField(m_tif, TIFFTAG_YRESOLUTION, (float)info.yDPI); +// TIFFSetField(m_tif, TIFFTAG_XPOSITION, (float)info.xOffset); +// TIFFSetField(m_tif, TIFFTAG_YPOSITION, (float)info.yOffset); + + // multi-paging - Thanks to Abe + if (multipage) + { + char page_number[20]; + sprintf(page_number, "Page %d", page); + + TIFFSetField(m_tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); + TIFFSetField(m_tif, TIFFTAG_PAGENUMBER, page,pagecount); + TIFFSetField(m_tif, TIFFTAG_PAGENAME, page_number); + } else { + TIFFSetField(m_tif, TIFFTAG_SUBFILETYPE, 0); + } + + // palettes (image colormaps are automatically scaled to 16-bits) + if (photometric == PHOTOMETRIC_PALETTE) { + uint16 *r, *g, *b; + r = (uint16 *) _TIFFmalloc(sizeof(uint16) * 3 * 256); + g = r + 256; + b = g + 256; + + for (int i = 255; i >= 0; i--) { + b[i] = (uint16)SCALE((uint16)pal[i].rgbRed); + g[i] = (uint16)SCALE((uint16)pal[i].rgbGreen); + r[i] = (uint16)SCALE((uint16)pal[i].rgbBlue); + } + + TIFFSetField(m_tif, TIFFTAG_COLORMAP, r, g, b); + _TIFFfree(r); + } + + // compression + if (GetCodecOption(CXIMAGE_FORMAT_TIF)) { + compression = (WORD)GetCodecOption(CXIMAGE_FORMAT_TIF); + } else { + switch (bitcount) { + case 1 : + compression = COMPRESSION_CCITTFAX4; + break; + case 4 : + case 8 : + compression = COMPRESSION_LZW; + break; + case 24 : + case 32 : + compression = COMPRESSION_JPEG; + break; + default : + compression = COMPRESSION_NONE; + break; + } + } + TIFFSetField(m_tif, TIFFTAG_COMPRESSION, compression); + + switch (compression) { + case COMPRESSION_JPEG: + TIFFSetField(m_tif, TIFFTAG_JPEGQUALITY, info.nQuality); + TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, ((7+rowsperstrip)>>3)<<3); + break; + case COMPRESSION_LZW: + if (bitcount>=8) TIFFSetField(m_tif, TIFFTAG_PREDICTOR, 2); + break; + } + + // read the DIB lines from bottom to top and save them in the TIF + + BYTE *bits; + switch(bitcount) { + case 1 : + case 4 : + case 8 : + { + if (samplesperpixel==1){ + for (y = 0; y < height; y++) { + bits= info.pImage + (height - y - 1)*info.dwEffWidth; + if (TIFFWriteScanline(m_tif,bits, y, 0)==-1) return false; + } + } +#if CXIMAGE_SUPPORT_ALPHA + else { //8bpp + alpha layer + bits = (BYTE*)malloc(2*width); + if (!bits) return false; + for (y = 0; y < height; y++) { + for (x=0;x 0) { + uint32 j = cols; + while (j-- > 0) + *out++ = *in++; + out += outskew; + in += inskew; + } +} +//////////////////////////////////////////////////////////////////////////////// +TIFF* CxImageTIF::TIFFOpenEx(CxFile * hFile) +{ + if (hFile) return _TIFFOpenEx(hFile, "rb"); + return NULL; +} +//////////////////////////////////////////////////////////////////////////////// +void CxImageTIF::TIFFCloseEx(TIFF* tif) +{ + if (tif) TIFFClose(tif); +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_TIF diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatif.h ./win32/dependencies/cximage/ximatif.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatif.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximatif.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,60 @@ +/* + * File: ximatif.h + * Purpose: TIFF Image Class Loader and Writer + */ +/* ========================================================== + * CxImageTIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * Special thanks to Abe for MultiPageTIFF code. + * + * LibTIFF is: + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * ========================================================== + */ + +#if !defined(__ximatif_h) +#define __ximatif_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_TIF + +#include "../tiff/tiffio.h" + +class DLL_EXP CxImageTIF: public CxImage +{ +public: + CxImageTIF(): CxImage(CXIMAGE_FORMAT_TIF) {m_tif2=NULL; m_multipage=false; m_pages=0;} + ~CxImageTIF(); + + TIFF* TIFFOpenEx(CxFile * hFile); + void TIFFCloseEx(TIFF* tif); + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TIF);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TIF);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile, bool bAppend=false); + bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount); + bool Encode(FILE *hFile, bool bAppend=false) { CxIOFile file(hFile); return Encode(&file,bAppend); } + bool Encode(FILE *hFile, CxImage ** pImages, int pagecount) + { CxIOFile file(hFile); return Encode(&file, pImages, pagecount); } +#endif // CXIMAGE_SUPPORT_ENCODE + +protected: + void TileToStrip(uint8* out, uint8* in, uint32 rows, uint32 cols, int outskew, int inskew); + bool EncodeBody(TIFF *m_tif, bool multipage=false, int page=0, int pagecount=0); + TIFF *m_tif2; + bool m_multipage; + int m_pages; +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatran.cpp ./win32/dependencies/cximage/ximatran.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximatran.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximatran.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,2439 @@ +// xImaTran.cpp : Transformation functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" +#include "ximath.h" + +#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::GrayScale() +{ + if (!pDib) return false; + if (head.biBitCount<=8){ + RGBQUAD* ppal=GetPalette(); + int gray; + //converts the colors to gray, use the blue channel only + for(DWORD i=0;iIsValid()) return false; + BYTE *iSrc,*iDst; + iSrc=info.pImage + (head.biHeight-1)*info.dwEffWidth; + iDst=imatmp->info.pImage; + for(long y=0; y < head.biHeight; y++){ + memcpy(iDst,iSrc,info.dwEffWidth); + iSrc-=info.dwEffWidth; + iDst+=info.dwEffWidth; + } + +#if CXIMAGE_SUPPORT_ALPHA + imatmp->AlphaFlip(); +#endif //CXIMAGE_SUPPORT_ALPHA + + Transfer(*imatmp); + delete imatmp; + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Mirror() +{ + if (!pDib) return false; + + CxImage* imatmp = new CxImage(*this,false,false,true); + if (!imatmp) return false; + BYTE *iSrc,*iDst; + long wdt=(head.biWidth-1) * (head.biBitCount==24 ? 3:1); + iSrc=info.pImage + wdt; + iDst=imatmp->info.pImage; + long x,y; + switch (head.biBitCount){ + case 24: + for(y=0; y < head.biHeight; y++){ + for(x=0; x <= wdt; x+=3){ + *(iDst+x)=*(iSrc-x); + *(iDst+x+1)=*(iSrc-x+1); + *(iDst+x+2)=*(iSrc-x+2); + } + iSrc+=info.dwEffWidth; + iDst+=info.dwEffWidth; + } + break; + case 8: + for(y=0; y < head.biHeight; y++){ + for(x=0; x <= wdt; x++) + *(iDst+x)=*(iSrc-x); + iSrc+=info.dwEffWidth; + iDst+=info.dwEffWidth; + } + break; + default: + for(y=0; y < head.biHeight; y++){ + for(x=0; x <= wdt; x++) + imatmp->SetPixelIndex(x,y,GetPixelIndex(wdt-x,y)); + } + } + +#if CXIMAGE_SUPPORT_ALPHA + imatmp->AlphaMirror(); +#endif //CXIMAGE_SUPPORT_ALPHA + + Transfer(*imatmp); + delete imatmp; + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +#define RBLOCK 64 + +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::RotateLeft(CxImage* iDst) +{ + if (!pDib) return false; + + long newWidth = GetHeight(); + long newHeight = GetWidth(); + + CxImage imgDest; + imgDest.CopyInfo(*this); + imgDest.Create(newWidth,newHeight,GetBpp(),GetType()); + imgDest.SetPalette(GetPalette()); + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) imgDest.AlphaCreate(); +#endif + + long x,x2,y,dlineup; + + // Speedy rotate for BW images + if (head.biBitCount == 1) { + + BYTE *sbits, *dbits, *dbitsmax, bitpos, *nrow,*srcdisp; + div_t div_r; + + BYTE *bsrc = GetBits(), *bdest = imgDest.GetBits(); + dbitsmax = bdest + imgDest.head.biSizeImage - 1; + dlineup = 8 * imgDest.info.dwEffWidth - imgDest.head.biWidth; + + imgDest.Clear(0); + for (y = 0; y < head.biHeight; y++) { + // Figure out the Column we are going to be copying to + div_r = div((int)(y + dlineup), 8); + // set bit pos of src column byte + bitpos = 1 << div_r.rem; + srcdisp = bsrc + y * info.dwEffWidth; + for (x = 0; x < (long)info.dwEffWidth; x++) { + // Get Source Bits + sbits = srcdisp + x; + // Get destination column + nrow = bdest + (x * 8) * imgDest.info.dwEffWidth + imgDest.info.dwEffWidth - 1 - div_r.quot; + for (long z = 0; z < 8; z++) { + // Get Destination Byte + dbits = nrow + z * imgDest.info.dwEffWidth; + if ((dbits < bdest) || (dbits > dbitsmax)) break; + if (*sbits & (128 >> z)) *dbits |= bitpos; + } + } + }//for y + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) { + for (x = 0; x < newWidth; x++){ + x2=newWidth-x-1; + for (y = 0; y < newHeight; y++){ + imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2)); + }//for y + }//for x + } +#endif //CXIMAGE_SUPPORT_ALPHA + + } else { + //anything other than BW: + //bd, 10. 2004: This optimized version of rotation rotates image by smaller blocks. It is quite + //a bit faster than obvious algorithm, because it produces much less CPU cache misses. + //This optimization can be tuned by changing block size (RBLOCK). 96 is good value for current + //CPUs (tested on Athlon XP and Celeron D). Larger value (if CPU has enough cache) will increase + //speed somehow, but once you drop out of CPU's cache, things will slow down drastically. + //For older CPUs with less cache, lower value would yield better results. + + BYTE *srcPtr, *dstPtr; //source and destionation for 24-bit version + int xs, ys; //x-segment and y-segment + for (xs = 0; xs < newWidth; xs+=RBLOCK) { //for all image blocks of RBLOCK*RBLOCK pixels + for (ys = 0; ys < newHeight; ys+=RBLOCK) { + if (head.biBitCount==24) { + //RGB24 optimized pixel access: + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ //do rotation + info.nProgress = (long)(100*x/newWidth); + x2=newWidth-x-1; + dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(x,ys); + srcPtr = (BYTE*) BlindGetPixelPointer(ys, x2); + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + //imgDest.SetPixelColor(x, y, GetPixelColor(y, x2)); + *(dstPtr) = *(srcPtr); + *(dstPtr+1) = *(srcPtr+1); + *(dstPtr+2) = *(srcPtr+2); + srcPtr += 3; + dstPtr += imgDest.info.dwEffWidth; + }//for y + }//for x + } else { + //anything else than 24bpp (and 1bpp): palette + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ + info.nProgress = (long)(100*x/newWidth); // + x2=newWidth-x-1; + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y, x2)); + }//for y + }//for x + }//if (version selection) +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha) { + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ + x2=newWidth-x-1; + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + imgDest.AlphaSet(x,y,BlindAlphaGet(y, x2)); + }//for y + }//for x + }//if (alpha channel) +#endif //CXIMAGE_SUPPORT_ALPHA + }//for ys + }//for xs + }//if + + //select the destination + if (iDst) iDst->Transfer(imgDest); + else Transfer(imgDest); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::RotateRight(CxImage* iDst) +{ + if (!pDib) return false; + + long newWidth = GetHeight(); + long newHeight = GetWidth(); + + CxImage imgDest; + imgDest.CopyInfo(*this); + imgDest.Create(newWidth,newHeight,GetBpp(),GetType()); + imgDest.SetPalette(GetPalette()); + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) imgDest.AlphaCreate(); +#endif + + long x,y,y2; + // Speedy rotate for BW images + if (head.biBitCount == 1) { + + BYTE *sbits, *dbits, *dbitsmax, bitpos, *nrow,*srcdisp; + div_t div_r; + + BYTE *bsrc = GetBits(), *bdest = imgDest.GetBits(); + dbitsmax = bdest + imgDest.head.biSizeImage - 1; + + imgDest.Clear(0); + for (y = 0; y < head.biHeight; y++) { + // Figure out the Column we are going to be copying to + div_r = div((int)y, 8); + // set bit pos of src column byte + bitpos = 128 >> div_r.rem; + srcdisp = bsrc + y * info.dwEffWidth; + for (x = 0; x < (long)info.dwEffWidth; x++) { + // Get Source Bits + sbits = srcdisp + x; + // Get destination column + nrow = bdest + (imgDest.head.biHeight-1-(x*8)) * imgDest.info.dwEffWidth + div_r.quot; + for (long z = 0; z < 8; z++) { + // Get Destination Byte + dbits = nrow - z * imgDest.info.dwEffWidth; + if ((dbits < bdest) || (dbits > dbitsmax)) break; + if (*sbits & (128 >> z)) *dbits |= bitpos; + } + } + } + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()){ + for (y = 0; y < newHeight; y++){ + y2=newHeight-y-1; + for (x = 0; x < newWidth; x++){ + imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x)); + } + } + } +#endif //CXIMAGE_SUPPORT_ALPHA + + } else { + //anything else but BW + BYTE *srcPtr, *dstPtr; //source and destionation for 24-bit version + int xs, ys; //x-segment and y-segment + for (xs = 0; xs < newWidth; xs+=RBLOCK) { + for (ys = 0; ys < newHeight; ys+=RBLOCK) { + if (head.biBitCount==24) { + //RGB24 optimized pixel access: + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + info.nProgress = (long)(100*y/newHeight); // + y2=newHeight-y-1; + dstPtr = (BYTE*) imgDest.BlindGetPixelPointer(xs,y); + srcPtr = (BYTE*) BlindGetPixelPointer(y2, xs); + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ + //imgDest.SetPixelColor(x, y, GetPixelColor(y2, x)); + *(dstPtr) = *(srcPtr); + *(dstPtr+1) = *(srcPtr+1); + *(dstPtr+2) = *(srcPtr+2); + dstPtr += 3; + srcPtr += info.dwEffWidth; + }//for x + }//for y + } else { + //anything else than BW & RGB24: palette + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + info.nProgress = (long)(100*y/newHeight); // + y2=newHeight-y-1; + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ + imgDest.SetPixelIndex(x, y, BlindGetPixelIndex(y2, x)); + }//for x + }//for y + }//if +#if CXIMAGE_SUPPORT_ALPHA + if (pAlpha){ + for (y = ys; y < min(newHeight, ys+RBLOCK); y++){ + y2=newHeight-y-1; + for (x = xs; x < min(newWidth, xs+RBLOCK); x++){ + imgDest.AlphaSet(x,y,BlindAlphaGet(y2, x)); + }//for x + }//for y + }//if (has alpha) +#endif //CXIMAGE_SUPPORT_ALPHA + }//for ys + }//for xs + }//if + + //select the destination + if (iDst) iDst->Transfer(imgDest); + else Transfer(imgDest); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Negative() +{ + if (!pDib) return false; + + if (head.biBitCount<=8){ + if (IsGrayScale()){ //GRAYSCALE, selection + if (pSelection){ + for(long y=info.rSelectionBox.bottom; y invert transparent color too + info.nBkgndColor.rgbBlue = (BYTE)(255-info.nBkgndColor.rgbBlue); + info.nBkgndColor.rgbGreen = (BYTE)(255-info.nBkgndColor.rgbGreen); + info.nBkgndColor.rgbRed = (BYTE)(255-info.nBkgndColor.rgbRed); + } + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_TRANSFORMATION +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Rotate(float angle, CxImage* iDst) +{ + if (!pDib) return false; + + // Copyright (c) 1996-1998 Ulrich von Zadow + + // Negative the angle, because the y-axis is negative. + double ang = -angle*acos((float)0)/90; + int newWidth, newHeight; + int nWidth = GetWidth(); + int nHeight= GetHeight(); + double cos_angle = cos(ang); + double sin_angle = sin(ang); + + // Calculate the size of the new bitmap + POINT p1={0,0}; + POINT p2={nWidth,0}; + POINT p3={0,nHeight}; + POINT p4={nWidth-1,nHeight}; + POINT newP1,newP2,newP3,newP4, leftTop, rightTop, leftBottom, rightBottom; + + newP1.x = p1.x; + newP1.y = p1.y; + newP2.x = (long)floor(p2.x*cos_angle - p2.y*sin_angle); + newP2.y = (long)floor(p2.x*sin_angle + p2.y*cos_angle); + newP3.x = (long)floor(p3.x*cos_angle - p3.y*sin_angle); + newP3.y = (long)floor(p3.x*sin_angle + p3.y*cos_angle); + newP4.x = (long)floor(p4.x*cos_angle - p4.y*sin_angle); + newP4.y = (long)floor(p4.x*sin_angle + p4.y*cos_angle); + + leftTop.x = min(min(newP1.x,newP2.x),min(newP3.x,newP4.x)); + leftTop.y = min(min(newP1.y,newP2.y),min(newP3.y,newP4.y)); + rightBottom.x = max(max(newP1.x,newP2.x),max(newP3.x,newP4.x)); + rightBottom.y = max(max(newP1.y,newP2.y),max(newP3.y,newP4.y)); + leftBottom.x = leftTop.x; + leftBottom.y = 2+rightBottom.y; + rightTop.x = 2+rightBottom.x; + rightTop.y = leftTop.y; + + newWidth = rightTop.x - leftTop.x; + newHeight= leftBottom.y - leftTop.y; + CxImage imgDest; + imgDest.CopyInfo(*this); + imgDest.Create(newWidth,newHeight,GetBpp(),GetType()); + imgDest.SetPalette(GetPalette()); + +#if CXIMAGE_SUPPORT_ALPHA + if(AlphaIsValid()) //MTA: Fix for rotation problem when the image has an alpha channel + { + imgDest.AlphaCreate(); + imgDest.AlphaClear(); + } +#endif //CXIMAGE_SUPPORT_ALPHA + + int x,y,newX,newY,oldX,oldY; + + if (head.biClrUsed==0){ //RGB + for (y = leftTop.y, newY = 0; y<=leftBottom.y; y++,newY++){ + info.nProgress = (long)(100*newY/newHeight); + if (info.nEscape) break; + for (x = leftTop.x, newX = 0; x<=rightTop.x; x++,newX++){ + oldX = (long)(x*cos_angle + y*sin_angle - 0.5); + oldY = (long)(y*cos_angle - x*sin_angle - 0.5); + imgDest.SetPixelColor(newX,newY,GetPixelColor(oldX,oldY)); +#if CXIMAGE_SUPPORT_ALPHA + imgDest.AlphaSet(newX,newY,AlphaGet(oldX,oldY)); //MTA: copy the alpha value +#endif //CXIMAGE_SUPPORT_ALPHA + } + } + } else { //PALETTE + for (y = leftTop.y, newY = 0; y<=leftBottom.y; y++,newY++){ + info.nProgress = (long)(100*newY/newHeight); + if (info.nEscape) break; + for (x = leftTop.x, newX = 0; x<=rightTop.x; x++,newX++){ + oldX = (long)(x*cos_angle + y*sin_angle - 0.5); + oldY = (long)(y*cos_angle - x*sin_angle - 0.5); + imgDest.SetPixelIndex(newX,newY,GetPixelIndex(oldX,oldY)); +#if CXIMAGE_SUPPORT_ALPHA + imgDest.AlphaSet(newX,newY,AlphaGet(oldX,oldY)); //MTA: copy the alpha value +#endif //CXIMAGE_SUPPORT_ALPHA + } + } + } + //select the destination + if (iDst) iDst->Transfer(imgDest); + else Transfer(imgDest); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Rotates image around it's center. + * Method can use interpolation with paletted images, but does not change pallete, so results vary. + * (If you have only four colours in a palette, there's not much room for interpolation.) + * + * \param angle - angle in degrees (positive values rotate clockwise) + * \param *iDst - destination image (if null, this image is changed) + * \param inMethod - interpolation method used + * (IM_NEAREST_NEIGHBOUR produces aliasing (fast), IM_BILINEAR softens picture a bit (slower) + * IM_SHARPBICUBIC is slower and produces some halos...) + * \param ofMethod - overflow method (how to choose colour of pixels that have no source) + * \param replColor - replacement colour to use (OM_COLOR, OM_BACKGROUND with no background colour...) + * \param optimizeRightAngles - call faster methods for 90, 180, and 270 degree rotations. Faster methods + * are called for angles, where error (in location of corner pixels) is less + * than 0.25 pixels. + * \param bKeepOriginalSize - rotates the image without resizing. + * + * \author ***bd*** 2.2004 + */ +bool CxImage::Rotate2(float angle, + CxImage *iDst, + InterpolationMethod inMethod, + OverflowMethod ofMethod, + RGBQUAD *replColor, + bool const optimizeRightAngles, + bool const bKeepOriginalSize) +{ + if (!pDib) return false; //no dib no go + + double ang = -angle*acos(0.0f)/90.0f; //convert angle to radians and invert (positive angle performs clockwise rotation) + float cos_angle = (float) cos(ang); //these two are needed later (to rotate) + float sin_angle = (float) sin(ang); + + //Calculate the size of the new bitmap (rotate corners of image) + CxPoint2 p[4]; //original corners of the image + p[0]=CxPoint2(-0.5f,-0.5f); + p[1]=CxPoint2(GetWidth()-0.5f,-0.5f); + p[2]=CxPoint2(-0.5f,GetHeight()-0.5f); + p[3]=CxPoint2(GetWidth()-0.5f,GetHeight()-0.5f); + CxPoint2 newp[4]; //rotated positions of corners + //(rotate corners) + if (bKeepOriginalSize){ + for (int i=0; i<4; i++) { + newp[i].x = p[i].x; + newp[i].y = p[i].y; + }//for + } else { + for (int i=0; i<4; i++) { + newp[i].x = (p[i].x*cos_angle - p[i].y*sin_angle); + newp[i].y = (p[i].x*sin_angle + p[i].y*cos_angle); + }//for i + + if (optimizeRightAngles) { + //For rotations of 90, -90 or 180 or 0 degrees, call faster routines + if (newp[3].Distance(CxPoint2(GetHeight()-0.5f, 0.5f-GetWidth())) < 0.25) + //rotation right for circa 90 degrees (diagonal pixels less than 0.25 pixel away from 90 degree rotation destination) + return RotateRight(iDst); + if (newp[3].Distance(CxPoint2(0.5f-GetHeight(), -0.5f+GetWidth())) < 0.25) + //rotation left for ~90 degrees + return RotateLeft(iDst); + if (newp[3].Distance(CxPoint2(0.5f-GetWidth(), 0.5f-GetHeight())) < 0.25) + //rotation left for ~180 degrees + return Rotate180(iDst); + if (newp[3].Distance(p[3]) < 0.25) { + //rotation not significant + if (iDst) iDst->Copy(*this); //copy image to iDst, if required + return true; //and we're done + }//if + }//if + }//if + + //(read new dimensions from location of corners) + float minx = (float) min(min(newp[0].x,newp[1].x),min(newp[2].x,newp[3].x)); + float miny = (float) min(min(newp[0].y,newp[1].y),min(newp[2].y,newp[3].y)); + float maxx = (float) max(max(newp[0].x,newp[1].x),max(newp[2].x,newp[3].x)); + float maxy = (float) max(max(newp[0].y,newp[1].y),max(newp[2].y,newp[3].y)); + int newWidth = (int) floor(maxx-minx+0.5f); + int newHeight= (int) floor(maxy-miny+0.5f); + float ssx=((maxx+minx)- ((float) newWidth-1))/2.0f; //start for x + float ssy=((maxy+miny)- ((float) newHeight-1))/2.0f; //start for y + + float newxcenteroffset = 0.5f * newWidth; + float newycenteroffset = 0.5f * newHeight; + if (bKeepOriginalSize){ + ssx -= 0.5f * GetWidth(); + ssy -= 0.5f * GetHeight(); + } + + //create destination image + CxImage imgDest; + imgDest.CopyInfo(*this); + imgDest.Create(newWidth,newHeight,GetBpp(),GetType()); + imgDest.SetPalette(GetPalette()); +#if CXIMAGE_SUPPORT_ALPHA + if(AlphaIsValid()) imgDest.AlphaCreate(); //MTA: Fix for rotation problem when the image has an alpha channel +#endif //CXIMAGE_SUPPORT_ALPHA + + RGBQUAD rgb; //pixel colour + RGBQUAD rc; + if (replColor!=0) + rc=*replColor; + else { + rc.rgbRed=255; rc.rgbGreen=255; rc.rgbBlue=255; rc.rgbReserved=0; + }//if + float x,y; //destination location (float, with proper offset) + float origx, origy; //origin location + int destx, desty; //destination location + + y=ssy; //initialize y + if (!IsIndexed()){ //RGB24 + //optimized RGB24 implementation (direct write to destination): + BYTE *pxptr; +#if CXIMAGE_SUPPORT_ALPHA + BYTE *pxptra=0; +#endif //CXIMAGE_SUPPORT_ALPHA + for (desty=0; destyTransfer(imgDest); + else Transfer(imgDest); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Rotate180(CxImage* iDst) +{ + if (!pDib) return false; + + long wid = GetWidth(); + long ht = GetHeight(); + + CxImage imgDest; + imgDest.CopyInfo(*this); + imgDest.Create(wid,ht,GetBpp(),GetType()); + imgDest.SetPalette(GetPalette()); + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) imgDest.AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + + long x,y,y2; + for (y = 0; y < ht; y++){ + info.nProgress = (long)(100*y/ht); // + y2=ht-y-1; + for (x = 0; x < wid; x++){ + if(head.biClrUsed==0)//RGB + imgDest.SetPixelColor(wid-x-1, y2, GetPixelColor(x, y)); + else //PALETTE + imgDest.SetPixelIndex(wid-x-1, y2, GetPixelIndex(x, y)); + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) imgDest.AlphaSet(wid-x-1, y2,AlphaGet(x, y)); +#endif //CXIMAGE_SUPPORT_ALPHA + + } + } + + //select the destination + if (iDst) iDst->Transfer(imgDest); + else Transfer(imgDest); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +/** + * Resizes the image. mode can be 0 for slow (bilinear) method , + * 1 for fast (nearest pixel) method, or 2 for accurate (bicubic spline interpolation) method. + * The function is faster with 24 and 1 bpp images, slow for 4 bpp images and slowest for 8 bpp images. + */ +bool CxImage::Resample(long newx, long newy, int mode, CxImage* iDst) +{ + if (newx==0 || newy==0) return false; + + if (head.biWidth==newx && head.biHeight==newy){ + if (iDst) iDst->Copy(*this); + return true; + } + + float xScale, yScale, fX, fY; + xScale = (float)head.biWidth / (float)newx; + yScale = (float)head.biHeight / (float)newy; + + CxImage newImage; + newImage.CopyInfo(*this); + newImage.Create(newx,newy,head.biBitCount,GetType()); + newImage.SetPalette(GetPalette()); + if (!newImage.IsValid()) return false; + + switch (mode) { + case 1: // nearest pixel + { + for(long y=0; y=head.biHeight) yy = head.biHeight-1; + for(int n=-1; n<3; n++) { + r2 = r1 * KernelBSpline(b - (float)n); + xx = i_x+n; + if (xx<0) xx=0; + if (xx>=head.biWidth) xx=head.biWidth-1; + + if (head.biClrUsed){ + rgb = GetPixelColor(xx,yy); + } else { + iDst = info.pImage + yy*info.dwEffWidth + xx*3; + rgb.rgbBlue = *iDst++; + rgb.rgbGreen= *iDst++; + rgb.rgbRed = *iDst; + } + + rr += rgb.rgbRed * r2; + gg += rgb.rgbGreen * r2; + bb += rgb.rgbBlue * r2; + } + } + + if (head.biClrUsed) + newImage.SetPixelColor(x,y,RGB(rr,gg,bb)); + else { + iDst = newImage.info.pImage + y*newImage.info.dwEffWidth + x*3; + *iDst++ = (BYTE)bb; + *iDst++ = (BYTE)gg; + *iDst = (BYTE)rr; + } + + } + } + break; + } + default: // bilinear interpolation + if (!(head.biWidth>newx && head.biHeight>newy && head.biBitCount==24)) { + //© 1999 Steve McMahon (steve@dogma.demon.co.uk) + long ifX, ifY, ifX1, ifY1, xmax, ymax; + float ir1, ir2, ig1, ig2, ib1, ib2, dx, dy; + BYTE r,g,b; + RGBQUAD rgb1, rgb2, rgb3, rgb4; + xmax = head.biWidth-1; + ymax = head.biHeight-1; + for(long y=0; y + const long ACCURACY = 1000; + long i,j; // index for faValue + long x,y; // coordinates in source image + BYTE* pSource; + BYTE* pDest = newImage.info.pImage; + long* naAccu = new long[3 * newx + 3]; + long* naCarry = new long[3 * newx + 3]; + long* naTemp; + long nWeightX,nWeightY; + float fEndX; + long nScale = (long)(ACCURACY * xScale * yScale); + + memset(naAccu, 0, sizeof(long) * 3 * newx); + memset(naCarry, 0, sizeof(long) * 3 * newx); + + int u, v = 0; // coordinates in dest image + float fEndY = yScale - 1.0f; + for (y = 0; y < head.biHeight; y++){ + info.nProgress = (long)(100*y/head.biHeight); // + if (info.nEscape) break; + pSource = info.pImage + y * info.dwEffWidth; + u = i = 0; + fEndX = xScale - 1.0f; + if ((float)y < fEndY) { // complete source row goes into dest row + for (x = 0; x < head.biWidth; x++){ + if ((float)x < fEndX){ // complete source pixel goes into dest pixel + for (j = 0; j < 3; j++) naAccu[i + j] += (*pSource++) * ACCURACY; + } else { // source pixel is splitted for 2 dest pixels + nWeightX = (long)(((float)x - fEndX) * ACCURACY); + for (j = 0; j < 3; j++){ + naAccu[i] += (ACCURACY - nWeightX) * (*pSource); + naAccu[3 + i++] += nWeightX * (*pSource++); + } + fEndX += xScale; + u++; + } + } + } else { // source row is splitted for 2 dest rows + nWeightY = (long)(((float)y - fEndY) * ACCURACY); + for (x = 0; x < head.biWidth; x++){ + if ((float)x < fEndX){ // complete source pixel goes into 2 pixel + for (j = 0; j < 3; j++){ + naAccu[i + j] += ((ACCURACY - nWeightY) * (*pSource)); + naCarry[i + j] += nWeightY * (*pSource++); + } + } else { // source pixel is splitted for 4 dest pixels + nWeightX = (int)(((float)x - fEndX) * ACCURACY); + for (j = 0; j < 3; j++) { + naAccu[i] += ((ACCURACY - nWeightY) * (ACCURACY - nWeightX)) * (*pSource) / ACCURACY; + *pDest++ = (BYTE)(naAccu[i] / nScale); + naCarry[i] += (nWeightY * (ACCURACY - nWeightX) * (*pSource)) / ACCURACY; + naAccu[i + 3] += ((ACCURACY - nWeightY) * nWeightX * (*pSource)) / ACCURACY; + naCarry[i + 3] = (nWeightY * nWeightX * (*pSource)) / ACCURACY; + i++; + pSource++; + } + fEndX += xScale; + u++; + } + } + if (u < newx){ // possibly not completed due to rounding errors + for (j = 0; j < 3; j++) *pDest++ = (BYTE)(naAccu[i++] / nScale); + } + naTemp = naCarry; + naCarry = naAccu; + naAccu = naTemp; + memset(naCarry, 0, sizeof(int) * 3); // need only to set first pixel zero + pDest = newImage.info.pImage + (++v * newImage.info.dwEffWidth); + fEndY += yScale; + } + } + if (v < newy){ // possibly not completed due to rounding errors + for (i = 0; i < 3 * newx; i++) *pDest++ = (BYTE)(naAccu[i] / nScale); + } + delete [] naAccu; + delete [] naCarry; + } + } + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()){ + newImage.AlphaCreate(); + for(long y=0; yTransfer(newImage); + else Transfer(newImage); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * New simpler resample. Adds new interpolation methods and simplifies code (using GetPixelColorInterpolated + * and GetAreaColorInterpolated). It also (unlike old method) interpolates alpha layer. + * + * \param newx, newy - size of resampled image + * \param inMethod - interpolation method to use (see comments at GetPixelColorInterpolated) + * If image size is being reduced, averaging is used instead (or simultaneously with) inMethod. + * \param ofMethod - what to replace outside pixels by (only significant for bordering pixels of enlarged image) + * \param iDst - pointer to destination CxImage or NULL. + * \param disableAveraging - force no averaging when shrinking images (Produces aliasing. + * You probably just want to leave this off...) + * + * \author ***bd*** 2.2004 + */ +bool CxImage::Resample2( + long newx, long newy, + InterpolationMethod const inMethod, + OverflowMethod const ofMethod, + CxImage* const iDst, + bool const disableAveraging) +{ + if (newx<=0 || newy<=0 || !pDib) return false; + + if (head.biWidth==newx && head.biHeight==newy) { + //image already correct size (just copy and return) + if (iDst) iDst->Copy(*this); + return true; + }//if + + //calculate scale of new image (less than 1 for enlarge) + float xScale, yScale; + xScale = (float)head.biWidth / (float)newx; + yScale = (float)head.biHeight / (float)newy; + + //create temporary destination image + CxImage newImage; + newImage.CopyInfo(*this); + newImage.Create(newx,newy,head.biBitCount,GetType()); + newImage.SetPalette(GetPalette()); + if (!newImage.IsValid()) return false; + + //and alpha channel if required +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) newImage.AlphaCreate(); +#endif + + float sX, sY; //source location + long dX,dY; //destination pixel (int value) + if ((xScale<=1 && yScale<=1) || disableAveraging) { + //image is being enlarged (or interpolation on demand) + if (!IsIndexed()) { + //RGB24 image (optimized version with direct writes) + RGBQUAD q; //pixel colour + BYTE *pxptr; //pointer to destination pixel +#if CXIMAGE_SUPPORT_ALPHA + BYTE *pxptra; //and destination alpha data +#endif + for(dY=0; dYTransfer(newImage); + else + Transfer(newImage); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Reduces the number of bits per pixel to nbit (1, 4 or 8). + * ppal points to a valid palette for the final image; if not supplied the function will use a standard palette. + * ppal is not necessary for reduction to 1 bpp. + */ +bool CxImage::DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal, DWORD clrimportant) +{ + if (!pDib) return false; + if (head.biBitCount < nbit) return false; + if (head.biBitCount == nbit){ + if (clrimportant==0) return true; + if (head.biClrImportant && (head.biClrImportant4) return false; + + CxImage tmp; + tmp.CopyInfo(*this); + tmp.Create(head.biWidth,head.biHeight,4,info.dwType); + tmp.SetPalette(GetPalette(),GetNumColors()); + if (!tmp.IsValid()) return false; + + +#if CXIMAGE_SUPPORT_SELECTION + tmp.SelectionCopy(*this); +#endif //CXIMAGE_SUPPORT_SELECTION + +#if CXIMAGE_SUPPORT_ALPHA + tmp.AlphaCopy(*this); +#endif //CXIMAGE_SUPPORT_ALPHA + + for (long y=0;y8) return false; + + CxImage tmp; + tmp.CopyInfo(*this); + tmp.Create(head.biWidth,head.biHeight,8,info.dwType); + tmp.SetPalette(GetPalette(),GetNumColors()); + if (!tmp.IsValid()) return false; + +#if CXIMAGE_SUPPORT_SELECTION + tmp.SelectionCopy(*this); +#endif //CXIMAGE_SUPPORT_SELECTION + +#if CXIMAGE_SUPPORT_ALPHA + tmp.AlphaCopy(*this); +#endif //CXIMAGE_SUPPORT_ALPHA + + for (long y=0;y24) return false; + + CxImage tmp; + tmp.CopyInfo(*this); + tmp.Create(head.biWidth,head.biHeight,24,info.dwType); + if (!tmp.IsValid()) return false; + + if (info.nBkgndIndex>=0) //translate transparency + tmp.info.nBkgndColor=GetPaletteColor((BYTE)info.nBkgndIndex); + +#if CXIMAGE_SUPPORT_SELECTION + tmp.SelectionCopy(*this); +#endif //CXIMAGE_SUPPORT_SELECTION + +#if CXIMAGE_SUPPORT_ALPHA + tmp.AlphaCopy(*this); + if (AlphaPaletteIsValid() && !AlphaIsValid()) tmp.AlphaCreate(); +#endif //CXIMAGE_SUPPORT_ALPHA + + for (long y=0;y 128) { + tmp.SetPixelIndex(x, y, 1); + error = level - 255; + } else { + tmp.SetPixelIndex(x, y, 0); + error = level; + } + + nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 1, y, level); + nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 2, y, level); + int i; + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 2; + break; + case -1: + coeff = 4; + break; + case 0: + coeff = 8; + break; + case 1: + coeff = 4; + break; + case 2: + coeff = 2; + break; + } + nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 1, level); + } + } + } + break; + } + case 3: + { + //Stucki error diffusion (Thanks to Franco Gerevini) + int TotalCoeffSum = 42; + long error, nlevel, coeff; + BYTE level; + + for (long y = 0; y < head.biHeight; y++) { + info.nProgress = (long)(100 * y / head.biHeight); + if (info.nEscape) + break; + for (long x = 0; x < head.biWidth; x++) { + level = GetPixelIndex(x, y); + if (level > 128) { + tmp.SetPixelIndex(x, y, 1); + error = level - 255; + } else { + tmp.SetPixelIndex(x, y, 0); + error = level; + } + + nlevel = GetPixelIndex(x + 1, y) + (error * 8) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 1, y, level); + nlevel = GetPixelIndex(x + 2, y) + (error * 4) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 2, y, level); + int i; + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 2; + break; + case -1: + coeff = 4; + break; + case 0: + coeff = 8; + break; + case 1: + coeff = 4; + break; + case 2: + coeff = 2; + break; + } + nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 1, level); + } + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 1; + break; + case -1: + coeff = 2; + break; + case 0: + coeff = 4; + break; + case 1: + coeff = 2; + break; + case 2: + coeff = 1; + break; + } + nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 2, level); + } + } + } + break; + } + case 4: + { + //Jarvis, Judice and Ninke error diffusion (Thanks to Franco Gerevini) + int TotalCoeffSum = 48; + long error, nlevel, coeff; + BYTE level; + + for (long y = 0; y < head.biHeight; y++) { + info.nProgress = (long)(100 * y / head.biHeight); + if (info.nEscape) + break; + for (long x = 0; x < head.biWidth; x++) { + level = GetPixelIndex(x, y); + if (level > 128) { + tmp.SetPixelIndex(x, y, 1); + error = level - 255; + } else { + tmp.SetPixelIndex(x, y, 0); + error = level; + } + + nlevel = GetPixelIndex(x + 1, y) + (error * 7) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 1, y, level); + nlevel = GetPixelIndex(x + 2, y) + (error * 5) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 2, y, level); + int i; + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 3; + break; + case -1: + coeff = 5; + break; + case 0: + coeff = 7; + break; + case 1: + coeff = 5; + break; + case 2: + coeff = 3; + break; + } + nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 1, level); + } + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 1; + break; + case -1: + coeff = 3; + break; + case 0: + coeff = 5; + break; + case 1: + coeff = 3; + break; + case 2: + coeff = 1; + break; + } + nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 2, level); + } + } + } + break; + } + case 5: + { + //Sierra error diffusion (Thanks to Franco Gerevini) + int TotalCoeffSum = 32; + long error, nlevel, coeff; + BYTE level; + + for (long y = 0; y < head.biHeight; y++) { + info.nProgress = (long)(100 * y / head.biHeight); + if (info.nEscape) + break; + for (long x = 0; x < head.biWidth; x++) { + level = GetPixelIndex(x, y); + if (level > 128) { + tmp.SetPixelIndex(x, y, 1); + error = level - 255; + } else { + tmp.SetPixelIndex(x, y, 0); + error = level; + } + + nlevel = GetPixelIndex(x + 1, y) + (error * 5) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 1, y, level); + nlevel = GetPixelIndex(x + 2, y) + (error * 3) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + 2, y, level); + int i; + for (i = -2; i < 3; i++) { + switch (i) { + case -2: + coeff = 2; + break; + case -1: + coeff = 4; + break; + case 0: + coeff = 5; + break; + case 1: + coeff = 4; + break; + case 2: + coeff = 2; + break; + } + nlevel = GetPixelIndex(x + i, y + 1) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 1, level); + } + for (i = -1; i < 2; i++) { + switch (i) { + case -1: + coeff = 2; + break; + case 0: + coeff = 3; + break; + case 1: + coeff = 2; + break; + } + nlevel = GetPixelIndex(x + i, y + 2) + (error * coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(x + i, y + 2, level); + } + } + } + break; + } + case 6: + { + //Stevenson and Arce error diffusion (Thanks to Franco Gerevini) + int TotalCoeffSum = 200; + long error, nlevel; + BYTE level; + + for (long y = 0; y < head.biHeight; y++) { + info.nProgress = (long)(100 * y / head.biHeight); + if (info.nEscape) + break; + for (long x = 0; x < head.biWidth; x++) { + level = GetPixelIndex(x, y); + if (level > 128) { + tmp.SetPixelIndex(x, y, 1); + error = level - 255; + } else { + tmp.SetPixelIndex(x, y, 0); + error = level; + } + + int tmp_index_x = x + 2; + int tmp_index_y = y; + int tmp_coeff = 32; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x - 3; + tmp_index_y = y + 1; + tmp_coeff = 12; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x - 1; + tmp_coeff = 26; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x + 1; + tmp_coeff = 30; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x + 3; + tmp_coeff = 16; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x - 2; + tmp_index_y = y + 2; + tmp_coeff = 12; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x; + tmp_coeff = 26; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x + 2; + tmp_coeff = 12; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x - 3; + tmp_index_y = y + 2; + tmp_coeff = 5; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x - 1; + tmp_coeff = 12; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x + 1; + tmp_coeff = 12; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + + tmp_index_x = x + 3; + tmp_coeff = 5; + nlevel = GetPixelIndex(tmp_index_x, tmp_index_y) + (error * tmp_coeff) / TotalCoeffSum; + level = (BYTE)min(255, max(0, (int)nlevel)); + SetPixelIndex(tmp_index_x, tmp_index_y, level); + } + } + break; + } + case 7: + { + // Bayer ordered dither + int order = 4; + //create Bayer matrix + if (order>4) order = 4; + int size = (1 << (2*order)); + BYTE* Bmatrix = (BYTE*) malloc(size * sizeof(BYTE)); + for(int i = 0; i < size; i++) { + int n = order; + int x = i / n; + int y = i % n; + int dither = 0; + while (n-- > 0){ + dither = (((dither<<1)|((x&1) ^ (y&1)))<<1) | (y&1); + x >>= 1; + y >>= 1; + } + Bmatrix[i] = dither; + } + + int scale = max(0,(8-2*order)); + int level; + for (long y=0;y> scale; + if(level > Bmatrix[ (x % order) + order * (y % order) ]){ + tmp.SetPixelIndex(x,y,1); + } else { + tmp.SetPixelIndex(x,y,0); + } + } + } + + free(Bmatrix); + + break; + } + default: + { + // Floyd-Steinberg error diffusion (Thanks to Steve McMahon) + long error,nlevel,coeff; + BYTE level; + + for (long y=0;y 128){ + tmp.SetPixelIndex(x,y,1); + error = level-255; + } else { + tmp.SetPixelIndex(x,y,0); + error = level; + } + + nlevel = GetPixelIndex(x+1,y) + (error * 7)/16; + level = (BYTE)min(255,max(0,(int)nlevel)); + SetPixelIndex(x+1,y,level); + for(int i=-1; i<2; i++){ + switch(i){ + case -1: + coeff=3; break; + case 0: + coeff=5; break; + case 1: + coeff=1; break; + } + nlevel = GetPixelIndex(x+i,y+1) + (error * coeff)/16; + level = (BYTE)min(255,max(0,(int)nlevel)); + SetPixelIndex(x+i,y+1,level); + } + } + } + } + } + + tmp.SetPaletteColor(0,0,0,0); + tmp.SetPaletteColor(1,255,255,255); + Transfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * CropRotatedRectangle + * \param topx,topy : topmost and leftmost point of the rectangle + (topmost, and if there are 2 topmost points, the left one) + * \param width : size of the right hand side of rect, from (topx,topy) roundwalking clockwise + * \param height : size of the left hand side of rect, from (topx,topy) roundwalking clockwise + * \param angle : angle of the right hand side of rect, from (topx,topy) + * \param iDst : pointer to destination image (if 0, this image is modified) + * \author [VATI] + */ +bool CxImage::CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst) +{ + if (!pDib) return false; + + + long startx,starty,endx,endy; + double cos_angle = cos(angle/*/57.295779513082320877*/); + double sin_angle = sin(angle/*/57.295779513082320877*/); + + // if there is nothing special, call the original Crop(): + if ( fabs(angle)<0.0002 ) + return Crop( topx, topy, topx+width, topy+height, iDst); + + startx = min(topx, topx - (long)(sin_angle*(double)height)); + endx = topx + (long)(cos_angle*(double)width); + endy = topy + (long)(cos_angle*(double)height + sin_angle*(double)width); + // check: corners of the rectangle must be inside + if ( IsInside( startx, topy )==false || + IsInside( endx, endy ) == false ) + return false; + + // first crop to bounding rectangle + CxImage tmp(*this,false/*pSelection!=0*/,true,true); + tmp.Copy(*this, true, false, true); + if (!tmp.IsValid()) return false; + if ( false == tmp.Crop( startx, topy, endx, endy ) ) + return false; + + // the midpoint of the image now became the same as the midpoint of the rectangle + // rotate new image with minus angle amount + if ( false == tmp.Rotate( (float)(-angle*57.295779513082320877) ) ) // Rotate expects angle in degrees + return false; + + // crop rotated image to the original selection rectangle + endx = (tmp.head.biWidth+width)/2; + startx = (tmp.head.biWidth-width)/2; + starty = (tmp.head.biHeight+height)/2; + endy = (tmp.head.biHeight-height)/2; + if ( false == tmp.Crop( startx, starty, endx, endy ) ) + return false; + + if (iDst) iDst->Transfer(tmp); + else Transfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Crop(const RECT& rect, CxImage* iDst) +{ + return Crop(rect.left, rect.top, rect.right, rect.bottom, iDst); +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Crop(long left, long top, long right, long bottom, CxImage* iDst) +{ + if (!pDib) return false; + + long startx = max(0L,min(left,head.biWidth)); + long endx = max(0L,min(right,head.biWidth)); + long starty = head.biHeight - max(0L,min(top,head.biHeight)); + long endy = head.biHeight - max(0L,min(bottom,head.biHeight)); + + if (startx==endx || starty==endy) return false; + + if (startx>endx) {long tmp=startx; startx=endx; endx=tmp;} + if (starty>endy) {long tmp=starty; starty=endy; endy=tmp;} + + CxImage tmp(endx-startx,endy-starty,head.biBitCount,info.dwType); + if (!tmp.IsValid()) return false; + tmp.SetPalette(GetPalette(),head.biClrUsed); + tmp.info.nBkgndIndex = info.nBkgndIndex; + tmp.info.nBkgndColor = info.nBkgndColor; + + switch (head.biBitCount) { + case 1: + case 4: + { + for(long y=starty, yd=0; y + for(long x=startx, xd=0; x> 3; + BYTE* pDest = tmp.info.pImage; + BYTE* pSrc = info.pImage + starty * info.dwEffWidth + (startx*head.biBitCount >> 3); + for(long y=starty; y + memcpy(pDest,pSrc,linelen); + pDest+=tmp.info.dwEffWidth; + pSrc+=info.dwEffWidth; + } + } + } + +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()){ // + tmp.AlphaCreate(); + if (!tmp.AlphaIsValid()) return false; + BYTE* pDest = tmp.pAlpha; + BYTE* pSrc = pAlpha + startx + starty*head.biWidth; + for (long y=starty; yTransfer(tmp); + else Transfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * \param xgain, ygain : can be from 0 to 1. + * \param xpivot, ypivot : is the center of the transformation. + * \param bEnableInterpolation : if true, enables bilinear interpolation. + * \return true if everything is ok + */ +bool CxImage::Skew(float xgain, float ygain, long xpivot, long ypivot, bool bEnableInterpolation) +{ + if (!pDib) return false; + float nx,ny; + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + for(long y=ymin; y top) || (x < left) || (x > right)) { + tmp.SetPixelIndex(x,y, pixel); + } else { + tmp.SetPixelIndex(x,y,GetPixelIndex(x-left,y-bottom)); + } + } + } + break; + } + case 8: + case 24: + { + if (head.biBitCount == 8) { + BYTE pixel = tmp.GetNearestIndex( canvascolor); + memset(tmp.info.pImage, pixel, + (tmp.info.dwEffWidth * newHeight)); + } else { + for (long y = 0; y < newHeight; ++y) { + BYTE *pDest = tmp.info.pImage + (y * tmp.info.dwEffWidth); + for (long x = 0; x < newWidth; ++x) { + *pDest++ = canvascolor.rgbBlue; + *pDest++ = canvascolor.rgbGreen; + *pDest++ = canvascolor.rgbRed; + } + } + } + + BYTE* pDest = tmp.info.pImage + (tmp.info.dwEffWidth * bottom) + (left*(head.biBitCount >> 3)); + BYTE* pSrc = info.pImage; + for(long y=bottom; y <= top; y++){ + info.nProgress = (long)(100*y/(1 + top - bottom)); + memcpy(pDest,pSrc,(head.biBitCount >> 3) * (right - left + 1)); + pDest+=tmp.info.dwEffWidth; + pSrc+=info.dwEffWidth; + } + } + } + //select the destination + if (iDst) iDst->Transfer(tmp); + else Transfer(tmp); + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst) +{ + //thanks to + + if (!pDib) return false; + + if ((newx < head.biWidth) || (newy < head.biHeight)) return false; + + int nAddLeft = (newx - head.biWidth) / 2; + int nAddTop = (newy - head.biHeight) / 2; + + return Expand(nAddLeft, nAddTop, newx - (head.biWidth + nAddLeft), newy - (head.biHeight + nAddTop), canvascolor, iDst); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Resamples the image with the correct aspect ratio, and fills the borders. + * \param newx, newy = thumbnail size. + * \param canvascolor = border color. + * \param iDst = pointer to destination image (if it's 0, this image is modified). + * \return true if everything is ok. + * \author [Colin Urquhart] + */ +bool CxImage::Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst) +{ + if (!pDib) return false; + + if ((newx <= 0) || (newy <= 0)) return false; + + CxImage tmp(*this); + if (!tmp.IsValid()) return false; + + // determine whether we need to shrink the image + if ((head.biWidth > newx) || (head.biHeight > newy)) { + float fScale; + float fAspect = (float) newx / (float) newy; + if (fAspect * head.biHeight > head.biWidth) { + fScale = (float) newy / head.biHeight; + } else { + fScale = (float) newx / head.biWidth; + } + tmp.Resample((long) (fScale * head.biWidth), (long) (fScale * head.biHeight), 0); + } + + // expand the frame + tmp.Expand(newx, newy, canvascolor, iDst); + + //select the destination + if (iDst) iDst->Transfer(tmp); + else Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Perform circle_based transformations. + * \param type - for different transformations + * - 0 for normal (proturberant) FishEye + * - 1 for reverse (concave) FishEye + * - 2 for Swirle + * - 3 for Cilinder mirror + * - 4 for bathroom + * + * \param rmax - effect radius. If 0, the whole image is processed + * \param Koeff - only for swirle + * \author Arkadiy Olovyannikov ark(at)msun(dot)ru + */ +bool CxImage::CircleTransform(int type,long rmax,float Koeff) +{ + if (!pDib) return false; + + long nx,ny; + double angle,radius,rnew; + + CxImage tmp(*this,pSelection!=0,true,true); + if (!tmp.IsValid()) return false; + + long xmin,xmax,ymin,ymax,xmid,ymid; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + xmid = (long) (tmp.GetWidth()/2); + ymid = (long) (tmp.GetHeight()/2); + + if (!rmax) rmax=(long)sqrt((float)((xmid-xmin)*(xmid-xmin)+(ymid-ymin)*(ymid-ymin))); + if (Koeff==0.0f) Koeff=1.0f; + + for(long y=ymin; yhead.biWidth || newy>head.biHeight) { + //let me repeat... this method can't enlarge image + strcpy(info.szLastError,"QIShrink can't enlarge image"); + return false; + } + + if (newx==head.biWidth && newy==head.biHeight) { + //image already correct size (just copy and return) + if (iDst) iDst->Copy(*this); + return true; + }//if + + //create temporary destination image + CxImage newImage; + newImage.CopyInfo(*this); + newImage.Create(newx,newy,head.biBitCount,GetType()); + newImage.SetPalette(GetPalette()); + if (!newImage.IsValid()) return false; + + //and alpha channel if required +#if CXIMAGE_SUPPORT_ALPHA + if (AlphaIsValid()) newImage.AlphaCreate(); +#endif + + const int oldx = head.biWidth; + const int oldy = head.biHeight; + + int accuCellSize = 4; +#if CXIMAGE_SUPPORT_ALPHA + BYTE *alphaPtr; + if (AlphaIsValid()) accuCellSize=5; +#endif + + unsigned int *accu = new unsigned int[newx*accuCellSize]; //array for suming pixels... one pixel for every destination column + unsigned int *accuPtr; //pointer for walking through accu + //each cell consists of blue, red, green component and count of pixels summed in this cell + memset(accu, 0, newx * accuCellSize * sizeof(unsigned int)); //clear accu + + if (!IsIndexed()) { + //RGB24 version with pointers + BYTE *destPtr, *srcPtr, *destPtrS, *srcPtrS; //destination and source pixel, and beginnings of current row + srcPtrS=(BYTE*)BlindGetPixelPointer(0,0); + destPtrS=(BYTE*)newImage.BlindGetPixelPointer(0,0); + int ex=0, ey=0; //ex and ey replace division... + int dy=0; + //(we just add pixels, until by adding newx or newy we get a number greater than old size... then + // it's time to move to next pixel) + + for(int y=0; yoldx) { //when we reach oldx, it's time to move to new slot + accuPtr += accuCellSize; + ex -= oldx; //(substract oldx from ex and resume from there on) + }//if (ex overflow) + }//for x + + if (ey>=oldy) { //now when this happens + ey -= oldy; //it's time to move to new destination row + destPtr = destPtrS; //reset pointers to proper initial values + accuPtr = accu; +#if CXIMAGE_SUPPORT_ALPHA + alphaPtr = newImage.AlphaGetPointer(0, dy++); +#endif + for (int k=0; koldx) { //when we reach oldx, it's time to move to new slot + accuPtr += accuCellSize; + ex -= oldx; //(substract oldx from ex and resume from there on) + }//if (ex overflow) + }//for x + + if (ey>=oldy) { //now when this happens + ey -= oldy; //it's time to move to new destination row + accuPtr = accu; + for (int dx=0; dxTransfer(newImage); + else + Transfer(newImage); + return true; + +} + +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_TRANSFORMATION diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawbmp.cpp ./win32/dependencies/cximage/ximawbmp.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawbmp.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximawbmp.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,85 @@ +/* + * File: ximawbmp.cpp + * Purpose: Platform Independent WBMP Image Class Loader and Writer + * 12/Jul/2002 Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximawbmp.h" + +#if CXIMAGE_SUPPORT_WBMP + +#include "ximaiter.h" + +//////////////////////////////////////////////////////////////////////////////// +bool CxImageWBMP::Decode(CxFile *hFile) +{ + if (hFile == NULL) return false; + + WBMPHEADER wbmpHead; + + try + { + if (hFile->Read(&wbmpHead,sizeof(wbmpHead),1)==0) + throw "Not a WBMP"; + + if (wbmpHead.Type != 0) + throw "Unsupported WBMP type"; + + if (wbmpHead.ImageHeight==0 || wbmpHead.ImageWidth==0) + throw "Corrupted WBMP"; + + Create(wbmpHead.ImageWidth, wbmpHead.ImageHeight, 1, CXIMAGE_FORMAT_WBMP); + if (!IsValid()) throw "WBMP Create failed"; + SetGrayPalette(); + + int linewidth=(wbmpHead.ImageWidth+7)/8; + CImageIterator iter(this); + iter.Upset(); + for (int y=0; y < wbmpHead.ImageHeight; y++){ + hFile->Read(iter.GetRow(),linewidth,1); + iter.PrevRow(); + } + + } catch (char *message) { + strncpy(info.szLastError,message,255); + return FALSE; + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +bool CxImageWBMP::Encode(CxFile * hFile) +{ + if (EncodeSafeCheck(hFile)) return false; + + //check format limits + if ((head.biWidth>255)||(head.biHeight>255)||(head.biBitCount!=1)){ + strcpy(info.szLastError,"Can't save this image as WBMP"); + return false; + } + + WBMPHEADER wbmpHead; + wbmpHead.Type=0; + wbmpHead.FixHeader=0; + wbmpHead.ImageWidth=(BYTE)head.biWidth; + wbmpHead.ImageHeight=(BYTE)head.biHeight; + + // Write the file header + hFile->Write(&wbmpHead,sizeof(wbmpHead),1); + // Write the pixels + int linewidth=(wbmpHead.ImageWidth+7)/8; + CImageIterator iter(this); + iter.Upset(); + for (int y=0; y < wbmpHead.ImageHeight; y++){ + hFile->Write(iter.GetRow(),linewidth,1); + iter.PrevRow(); + } + return true; +} +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_ENCODE +//////////////////////////////////////////////////////////////////////////////// +#endif // CXIMAGE_SUPPORT_WBMP + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawbmp.h ./win32/dependencies/cximage/ximawbmp.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawbmp.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximawbmp.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,44 @@ +/* + * File: ximawbmp.h + * Purpose: WBMP Image Class Loader and Writer + */ +/* ========================================================== + * CxImageWBMP (c) 12/Jul/2002 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * ========================================================== + */ +#if !defined(__ximaWBMP_h) +#define __ximaWBMP_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_WBMP + +class CxImageWBMP: public CxImage +{ +#pragma pack(1) +typedef struct tagWbmpHeader +{ + BYTE Type; // 0 + BYTE FixHeader; // 0 + BYTE ImageWidth; // Image Width + BYTE ImageHeight; // Image Height +} WBMPHEADER; +#pragma pack() +public: + CxImageWBMP(): CxImage(CXIMAGE_FORMAT_WBMP) {} + +// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_WBMP);} +// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_WBMP);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE +}; + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawmf.cpp ./win32/dependencies/cximage/ximawmf.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawmf.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximawmf.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,458 @@ +/* +********************************************************************* + * File: ximawmf.cpp + * Purpose: Windows Metafile Class Loader and Writer + * Author: Volker Horch - vhorch@gmx.de + * created: 13-Jun-2002 + * + * Note: If the code below works, i wrote it. + * If it doesn't work, i don't know who wrote it. +********************************************************************* + */ + +/* +********************************************************************* + Note by Author: +********************************************************************* + + Metafile Formats: + ================= + + There are 2 kinds of Windows Metafiles: + - Standard Windows Metafile + - Placeable Windows Metafile + + A StandardWindows Metafile looks like: + - Metafile Header (MEATAHEADER) + - Metafile Records + + A Placeable Metafile looks like: + - Aldus Header (METAFILEHEADER) + - Metafile Header (METAHEADER) + - Metafile Records + + The "Metafile Header" and the "Metafile Records" are the same + for both formats. However, the Standard Metafile does not contain any + information about the original dimensions or x/y ratio of the Metafile. + + I decided, to allow only placeable Metafiles here. If you also want to + enable Standard Metafiles, you will have to guess the dimensions of + the image. + +********************************************************************* + Limitations: see ximawmf.h + you may configure some stuff there +********************************************************************* +*/ + +#include "ximawmf.h" + +#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS + +///////////////////////////////////////////////////////////////////// +bool CxImageWMF::Decode(CxFile *hFile, long nForceWidth, long nForceHeight) +{ + if (hFile == NULL) return false; + + HENHMETAFILE hMeta; + HDC hDC; + int cx,cy; + + //save the current position of the file + long pos = hFile->Tell(); + + // Read the Metafile and convert to an Enhanced Metafile + METAFILEHEADER mfh; + hMeta = ConvertWmfFiletoEmf(hFile, &mfh); + if (hMeta) { // ok, it's a WMF + +///////////////////////////////////////////////////////////////////// +// We use the original WMF size information, because conversion to +// EMF adjusts the Metafile to Full Screen or does not set rclBounds at all +// ENHMETAHEADER emh; +// UINT uRet; +// uRet = GetEnhMetaFileHeader(hMeta, // handle of enhanced metafile +// sizeof(ENHMETAHEADER), // size of buffer, in bytes +// &emh); // address of buffer to receive data +// if (!uRet){ +// DeleteEnhMetaFile(hMeta); +// return false; +// } +// // calculate size +// cx = emh.rclBounds.right - emh.rclBounds.left; +// cy = emh.rclBounds.bottom - emh.rclBounds.top; +///////////////////////////////////////////////////////////////////// + + // calculate size + // scale the metafile (pixels/inch of metafile => pixels/inch of display) + // mfh.inch already checked to be <> 0 + + hDC = ::GetDC(0); + int cx1 = ::GetDeviceCaps(hDC, LOGPIXELSX); + int cy1 = ::GetDeviceCaps(hDC, LOGPIXELSY); + ::ReleaseDC(0, hDC); + + cx = (mfh.bbox.right - mfh.bbox.left) * cx1 / mfh.inch; + cy = (mfh.bbox.bottom - mfh.bbox.top) * cy1 / mfh.inch; + + } else { // maybe it's an EMF... + + hFile->Seek(pos,SEEK_SET); + + ENHMETAHEADER emh; + hMeta = ConvertEmfFiletoEmf(hFile, &emh); + + if (!hMeta){ + strcpy(info.szLastError,"corrupted WMF"); + return false; // definitively give up + } + // ok, it's an EMF + // calculate size + cx = emh.rclBounds.right - emh.rclBounds.left; + cy = emh.rclBounds.bottom - emh.rclBounds.top; + } + + if (info.nEscape) { // Check if cancelled + DeleteEnhMetaFile(hMeta); + strcpy(info.szLastError,"Cancelled"); + return false; + } + + if (!cx || !cy) { + DeleteEnhMetaFile(hMeta); + strcpy(info.szLastError,"empty WMF"); + return false; + } + + if (nForceWidth) cx=nForceWidth; + if (nForceHeight) cy=nForceHeight; + ShrinkMetafile(cx, cy); // !! Otherwise Bitmap may have bombastic size + + HDC hDC0 = GetDC(0); // DC of screen + HBITMAP hBitmap = CreateCompatibleBitmap(hDC0, cx, cy); // has # colors of display + hDC = CreateCompatibleDC(hDC0); // memory dc compatible with screen + ReleaseDC(0, hDC0); // don't need anymore. get rid of it. + + if (hDC){ + if (hBitmap){ + RECT rc = {0,0,cx,cy}; + int bpp = ::GetDeviceCaps(hDC, BITSPIXEL); + + HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); + + // clear out the entire bitmap with windows background + // because the MetaFile may not contain background information + DWORD dwBack = XMF_COLOR_BACK; +#if XMF_SUPPORT_TRANSPARENCY + if (bpp == 24) dwBack = XMF_COLOR_TRANSPARENT; +#endif + DWORD OldColor = SetBkColor(hDC, dwBack); + ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); + SetBkColor(hDC, OldColor); + + //retrieves optional palette entries from the specified enhanced metafile + PLOGPALETTE plogPal; + PBYTE pjTmp; + HPALETTE hPal; + int iEntries = GetEnhMetaFilePaletteEntries(hMeta, 0, NULL); + if (iEntries) { + if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, + sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) { + DeleteObject(hBitmap); + DeleteDC(hDC); + DeleteEnhMetaFile(hMeta); + strcpy(info.szLastError,"Cancelled"); + return false; + } + + plogPal->palVersion = 0x300; + plogPal->palNumEntries = (WORD) iEntries; + pjTmp = (PBYTE) plogPal; + pjTmp += 4; + + GetEnhMetaFilePaletteEntries(hMeta, iEntries, (PPALETTEENTRY)pjTmp); + hPal = CreatePalette(plogPal); + GlobalFree(plogPal); + + SelectPalette(hDC, hPal, FALSE); + RealizePalette(hDC); + } + + // Play the Metafile into Memory DC + BOOL bRet = PlayEnhMetaFile(hDC, // handle to a device context + hMeta, // handle to an enhanced metafile + &rc); // pointer to bounding rectangle + + SelectObject(hDC, hBitmapOld); + DeleteEnhMetaFile(hMeta); // we are done with this one + + if (info.nEscape) { // Check if cancelled + DeleteObject(hBitmap); + DeleteDC(hDC); + strcpy(info.szLastError,"Cancelled"); + return false; + } + + // the Bitmap now has the image. + // Create our DIB and convert the DDB into DIB + if (!Create(cx, cy, bpp, CXIMAGE_FORMAT_WMF)) { + DeleteObject(hBitmap); + DeleteDC(hDC); + return false; + } + +#if XMF_SUPPORT_TRANSPARENCY + if (bpp == 24) { + RGBQUAD rgbTrans = { XMF_RGBQUAD_TRANSPARENT }; + SetTransColor(rgbTrans); + } +#endif + // We're finally ready to get the DIB. Call the driver and let + // it party on our bitmap. It will fill in the color table, + // and bitmap bits of our global memory block. + bRet = GetDIBits(hDC, hBitmap, 0, + (UINT)cy, GetBits(), (LPBITMAPINFO)pDib, DIB_RGB_COLORS); + + DeleteObject(hBitmap); + DeleteDC(hDC); + + return (bRet!=0); + } else { + DeleteDC(hDC); + } + } else { + if (hBitmap) DeleteObject(hBitmap); + } + + DeleteEnhMetaFile(hMeta); + + return false; +} + +/********************************************************************** + Function: CheckMetafileHeader + Purpose: Check if the Metafileheader of a file is valid +**********************************************************************/ +BOOL CxImageWMF::CheckMetafileHeader(METAFILEHEADER *metafileheader) +{ + WORD *pw; + WORD cs; + int i; + + // check magic # + if (metafileheader->key != 0x9ac6cdd7L) return false; + + // test checksum of header + pw = (WORD *)metafileheader; + cs = *pw; + pw++; + for (i = 0; i < 9; i++) { + cs ^= *pw; + pw++; + } + + if (cs != metafileheader->checksum) return false; + + // check resolution + if ((metafileheader->inch <= 0) || (metafileheader->inch > 2540)) return false; + + return true; +} + +/********************************************************************** + Function: ConvertWmfFiletoEmf + Purpose: Converts a Windows Metafile into an Enhanced Metafile +**********************************************************************/ +HENHMETAFILE CxImageWMF::ConvertWmfFiletoEmf(CxFile *fp, METAFILEHEADER *metafileheader) +{ + HENHMETAFILE hMeta; + long lenFile; + long len; + BYTE *p; + METAHEADER mfHeader; + DWORD seekpos; + + hMeta = 0; + + // get length of the file + lenFile = fp->Size(); + + // a placeable metafile starts with a METAFILEHEADER + // read it and check metafileheader + len = fp->Read(metafileheader, 1, sizeof(METAFILEHEADER)); + if (len < sizeof(METAFILEHEADER)) return (hMeta); + + if (CheckMetafileHeader(metafileheader)) { + // This is a placeable metafile + // Convert the placeable format into something that can + // be used with GDI metafile functions + seekpos = sizeof(METAFILEHEADER); + } else { + // Not a placeable wmf. A windows metafile? + // at least not scaleable. + // we could try to convert, but would loose ratio. don't allow this + return (hMeta); + + //metafileheader->bbox.right = ?; + //metafileheader->bbox.left = ?; + //metafileheader->bbox.bottom = ?; + //metafileheader->bbox.top = ?; + //metafileheader->inch = ?; + // + //seekpos = 0; + // fp->Seek(0, SEEK_SET); // rewind + } + + // At this point we have a metaheader regardless of whether + // the metafile was a windows metafile or a placeable metafile + // so check to see if it is valid. There is really no good + // way to do this so just make sure that the mtType is either + // 1 or 2 (memory or disk file) + // in addition we compare the length of the METAHEADER against + // the length of the file. if filelength < len => no Metafile + + len = fp->Read(&mfHeader, 1, sizeof(METAHEADER)); + if (len < sizeof(METAHEADER)) return (hMeta); + + if ((mfHeader.mtType != 1) && (mfHeader.mtType != 2)) return (hMeta); + + // Length in Bytes from METAHEADER + len = mfHeader.mtSize * 2; + if (len > lenFile) return (hMeta); + + // Allocate memory for the metafile bits + p = (BYTE *)malloc(len); + if (!p) return (hMeta); + + // seek back to METAHEADER and read all the stuff at once + fp->Seek(seekpos, SEEK_SET); + lenFile = fp->Read(p, 1, len); + if (lenFile != len) { + free(p); + return (hMeta); + } + + // the following (commented code) works, but adjusts rclBound of the + // Enhanced Metafile to full screen. + // the METAFILEHEADER from above is needed to scale the image + +// hMeta = SetWinMetaFileBits(len, p, NULL, NULL); + + // scale the metafile (pixels/inch of metafile => pixels/inch of display) + + METAFILEPICT mfp; + int cx1, cy1; + HDC hDC; + + hDC = ::GetDC(0); + cx1 = ::GetDeviceCaps(hDC, LOGPIXELSX); + cy1 = ::GetDeviceCaps(hDC, LOGPIXELSY); + + memset(&mfp, 0, sizeof(mfp)); + + mfp.mm = MM_ANISOTROPIC; + mfp.xExt = (metafileheader->bbox.right - metafileheader->bbox.left) * cx1 / metafileheader->inch; + mfp.yExt = (metafileheader->bbox.bottom - metafileheader->bbox.top) * cy1 / metafileheader->inch; + mfp.hMF = 0; + + // in MM_ANISOTROPIC mode xExt and yExt are in MM_HIENGLISH + // MM_HIENGLISH means: Each logical unit is converted to 0.001 inch + //mfp.xExt *= 1000; + //mfp.yExt *= 1000; + // ???? + //int k = 332800 / ::GetSystemMetrics(SM_CXSCREEN); + //mfp.xExt *= k; mfp.yExt *= k; + + // fix for Win9x + while ((mfp.xExt < 6554) && (mfp.yExt < 6554)) + { + mfp.xExt *= 10; + mfp.yExt *= 10; + } + + hMeta = SetWinMetaFileBits(len, p, hDC, &mfp); + + if (!hMeta){ //try 2nd conversion using a different mapping + mfp.mm = MM_TEXT; + hMeta = SetWinMetaFileBits(len, p, hDC, &mfp); + } + + ::ReleaseDC(0, hDC); + + // Free Memory + free(p); + + return (hMeta); +} +///////////////////////////////////////////////////////////////////// +HENHMETAFILE CxImageWMF::ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh) +{ + HENHMETAFILE hMeta; + long iLen = pFile->Size(); + + BYTE* pBuff = (BYTE *)malloc(iLen); + if (!pBuff) return (FALSE); + + // Read the Enhanced Metafile + long iLenRead = pFile->Read(pBuff, 1, iLen); + if (iLenRead != iLen) { + free(pBuff); + return (FALSE); + } + + // Make it a Memory Metafile + hMeta = SetEnhMetaFileBits(iLen, pBuff); + + free(pBuff); // finished with this one + + if (!hMeta) return (FALSE); // oops. + + // Get the Enhanced Metafile Header + UINT uRet = GetEnhMetaFileHeader(hMeta, // handle of enhanced metafile + sizeof(ENHMETAHEADER), // size of buffer, in bytes + pemfh); // address of buffer to receive data + + if (!uRet) { + DeleteEnhMetaFile(hMeta); + return (FALSE); + } + + return (hMeta); +} + + +///////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_ENCODE +///////////////////////////////////////////////////////////////////// +bool CxImageWMF::Encode(CxFile * hFile) +{ + if (hFile == NULL) return false; + strcpy(info.szLastError, "Save WMF not supported"); + return false; +} +#endif // CXIMAGE_SUPPORT_ENCODE +///////////////////////////////////////////////////////////////////// + +/********************************************************************** +Function: ShrinkMetafile +Purpose: Shrink the size of a metafile to be not larger than + the definition +**********************************************************************/ +void CxImageWMF::ShrinkMetafile(int &cx, int &cy) +{ + int xScreen = XMF_MAXSIZE_CX; + int yScreen = XMF_MAXSIZE_CY; + + if (cx > xScreen){ + cy = cy * xScreen / cx; + cx = xScreen; + } + + if (cy > yScreen){ + cx = cx * yScreen / cy; + cy = yScreen; + } +} + +#endif // CIMAGE_SUPPORT_WMF + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawmf.h ./win32/dependencies/cximage/ximawmf.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawmf.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximawmf.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,154 @@ +/* +********************************************************************* + * File: ximawmf.h + * Purpose: Windows Metafile Class Loader and Writer + * Author: Volker Horch - vhorch@gmx.de + * created: 13-Jun-2002 +********************************************************************* + */ + +/* +********************************************************************* + Notes by Author: +********************************************************************* + + Limitations: + ============ + + a) Transparency: + + A Metafile is vector graphics, which has transparency by design. + This class always converts into a Bitmap format. Transparency is + supported, but there is no good way to find out, which parts + of the Metafile are transparent. There are two ways how we can + handle this: + + - Clear the Background of the Bitmap with the background color + you like (i have used COLOR_WINDOW) and don't support transparency. + + below #define XMF_SUPPORT_TRANSPARENCY 0 + #define XMF_COLOR_BACK RGB(Background color you like) + + - Clear the Background of the Bitmap with a very unusual color + (which one ?) and use this color as the transparent color + + below #define XMF_SUPPORT_TRANSPARENCY 1 + #define XMF_COLOR_TRANSPARENT_R ... + #define XMF_COLOR_TRANSPARENT_G ... + #define XMF_COLOR_TRANSPARENT_B ... + + b) Resolution + + Once we have converted the Metafile into a Bitmap and we zoom in + or out, the image may not look very good. If we still had the + original Metafile, zooming would produce good results always. + + c) Size + + Although the filesize of a Metafile may be very small, it might + produce a Bitmap with a bombastic size. Assume you have a Metafile + with an image size of 6000*4000, which contains just one Metafile + record ((e.g. a line from (0,0) to (6000, 4000)). The filesize + of this Metafile would be let's say 100kB. If we convert it to + a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume + about 68MB of memory. + + I have choosen, to limit the size of the Bitmap to max. + screensize, to avoid memory problems. + + If you want something else, + modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below + +********************************************************************* +*/ + +#ifndef _XIMAWMF_H +#define _XIMAWMF_H + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS + +class CxImageWMF: public CxImage +{ + +#pragma pack(1) + +typedef struct tagRECT16 +{ + short int left; + short int top; + short int right; + short int bottom; +} RECT16; + +// taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources) +typedef struct tagMETAFILEHEADER +{ + DWORD key; // always 0x9ac6cdd7 + WORD reserved1; // reserved = 0 + RECT16 bbox; // bounding rectangle in metafile units as defined in "inch" + WORD inch; // number of metafile units per inch (should be < 1440) + DWORD reserved2; // reserved = 0 + WORD checksum; // sum of the first 10 WORDS (using XOR operator) +} METAFILEHEADER; + +#pragma pack() + +public: + CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { } + + bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0); + bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0) + { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + +protected: + void ShrinkMetafile(int &cx, int &cy); + BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader); + HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader); + HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh); + +}; + +#define METAFILEKEY 0x9ac6cdd7L + +// Background color definition (if no transparency). see Notes above +#define XMF_COLOR_BACK GetSysColor(COLOR_WINDOW) +// alternatives +//#define XMF_COLOR_BACK RGB(192, 192, 192) // lite gray +//#define XMF_COLOR_BACK RGB( 0, 0, 0) // black +//#define XMF_COLOR_BACK RGB(255, 255, 255) // white + + +// transparency support. see Notes above +#define XMF_SUPPORT_TRANSPARENCY 0 +#define XMF_COLOR_TRANSPARENT_R 211 +#define XMF_COLOR_TRANSPARENT_G 121 +#define XMF_COLOR_TRANSPARENT_B 112 +// don't change +#define XMF_COLOR_TRANSPARENT RGB (XMF_COLOR_TRANSPARENT_R, \ + XMF_COLOR_TRANSPARENT_G, \ + XMF_COLOR_TRANSPARENT_B) +// don't change +#define XMF_RGBQUAD_TRANSPARENT XMF_COLOR_TRANSPARENT_B, \ + XMF_COLOR_TRANSPARENT_G, \ + XMF_COLOR_TRANSPARENT_R, \ + 0 +// max. size. see Notes above +// alternatives +//#define XMF_MAXSIZE_CX (GetSystemMetrics(SM_CXSCREEN)-10) +//#define XMF_MAXSIZE_CY (GetSystemMetrics(SM_CYSCREEN)-50) +//#define XMF_MAXSIZE_CX (2*GetSystemMetrics(SM_CXSCREEN)/3) +//#define XMF_MAXSIZE_CY (2*GetSystemMetrics(SM_CYSCREEN)/3) +#define XMF_MAXSIZE_CX 4000 +#define XMF_MAXSIZE_CY 4000 + + +#endif + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawnd.cpp ./win32/dependencies/cximage/ximawnd.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/ximawnd.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/ximawnd.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,1110 @@ +// xImaWnd.cpp : Windows functions +/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it + * CxImage version 5.99c 17/Oct/2004 + */ + +#include "ximage.h" + +#include "ximaiter.h" +#include "ximabmp.h" + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_WINCE +//////////////////////////////////////////////////////////////////////////////// +long CxImage::Blt(HDC pDC, long x, long y) +{ + if((pDib==0)||(pDC==0)||(!info.bEnabled)) return 0; + + HBRUSH brImage = CreateDIBPatternBrushPt(pDib, DIB_RGB_COLORS); + HBRUSH brOld = (HBRUSH) SelectObject(pDC, brImage); + PatBlt(pDC, 0, 0, head.biWidth, head.biHeight, PATCOPY); + SelectObject(pDC, brOld); + DeleteObject(brImage); + return 1; +} +#endif //CXIMAGE_SUPPORT_WINCE +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +#if CXIMAGE_SUPPORT_WINDOWS +//////////////////////////////////////////////////////////////////////////////// +/** + * Transfer the image in a global bitmap handle (clipboard copy) + */ +HANDLE CxImage::CopyToHandle() +{ + HANDLE hMem=NULL; + if (pDib){ + hMem= GlobalAlloc(GHND, GetSize()); + if (hMem){ + BYTE* pDst=(BYTE*)GlobalLock(hMem); + if (pDst){ + memcpy(pDst,pDib,GetSize()); + } + GlobalUnlock(hMem); + } + } + return hMem; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Global object (clipboard paste) constructor + * \param hMem: source bitmap object, the clipboard format must be CF_DIB + * \return true if everything is ok + */ +bool CxImage::CreateFromHANDLE(HANDLE hMem) +{ + if (!Destroy()) + return false; + + DWORD dwSize = GlobalSize(hMem); + if (!dwSize) return false; + + BYTE *lpVoid; //pointer to the bitmap + lpVoid = (BYTE *)GlobalLock(hMem); + BITMAPINFOHEADER *pHead; //pointer to the bitmap header + pHead = (BITMAPINFOHEADER *)lpVoid; + if (lpVoid){ + + //CxMemFile hFile(lpVoid,dwSize); + + //copy the bitmap header + memcpy(&head,pHead,sizeof(BITMAPINFOHEADER)); + //create the image + if(!Create(head.biWidth,head.biHeight,head.biBitCount)){ + GlobalUnlock(lpVoid); + return false; + } + //preserve DPI + if (head.biXPelsPerMeter) SetXDPI((long)floor(head.biXPelsPerMeter * 254.0 / 10000.0 + 0.5)); else SetXDPI(96); + if (head.biYPelsPerMeter) SetYDPI((long)floor(head.biYPelsPerMeter * 254.0 / 10000.0 + 0.5)); else SetYDPI(96); + + /*//copy the pixels (old way) + if((pHead->biCompression != BI_RGB) || (pHead->biBitCount == 32)){ // + // BITFIELD case + // set the internal header in the dib + memcpy(pDib,&head,sizeof(head)); + // get the bitfield masks + DWORD bf[3]; + memcpy(bf,lpVoid+pHead->biSize,12); + // transform into RGB + Bitfield2RGB(lpVoid+pHead->biSize+12,(WORD)bf[0],(WORD)bf[1],(WORD)bf[2],(BYTE)pHead->biBitCount); + } else { //normal bitmap + memcpy(pDib,lpVoid,GetSize()); + }*/ + + // + // fill in color map + bool bIsOldBmp = (head.biSize == sizeof(BITMAPCOREHEADER)); + RGBQUAD *pRgb = GetPalette(); + if (pRgb) { + // number of colors to fill in + int nColors = DibNumColors(pHead); + if (bIsOldBmp) { + /* get pointer to BITMAPCOREINFO (old style 1.x) */ + LPBITMAPCOREINFO lpbmc = (LPBITMAPCOREINFO)lpVoid; + for (int i = nColors - 1; i >= 0; i--) { + pRgb[i].rgbRed = lpbmc->bmciColors[i].rgbtRed; + pRgb[i].rgbGreen = lpbmc->bmciColors[i].rgbtGreen; + pRgb[i].rgbBlue = lpbmc->bmciColors[i].rgbtBlue; + pRgb[i].rgbReserved = (BYTE)0; + } + } else { + /* get pointer to BITMAPINFO (new style 3.x) */ + LPBITMAPINFO lpbmi = (LPBITMAPINFO)lpVoid; + for (int i = nColors - 1; i >= 0; i--) { + pRgb[i].rgbRed = lpbmi->bmiColors[i].rgbRed; + pRgb[i].rgbGreen = lpbmi->bmiColors[i].rgbGreen; + pRgb[i].rgbBlue = lpbmi->bmiColors[i].rgbBlue; + pRgb[i].rgbReserved = (BYTE)0; + } + } + } + + // + DWORD dwCompression = pHead->biCompression; + // compressed bitmap ? + if(dwCompression!=BI_RGB || pHead->biBitCount==32) { + // get the bitmap bits + LPSTR lpDIBBits = (LPSTR)((BYTE*)pHead + *(DWORD*)pHead + (WORD)(GetNumColors() * sizeof(RGBQUAD))); + // decode and copy them to our image + switch (pHead->biBitCount) { + case 32 : + { + // BITFIELD case + if (dwCompression == BI_BITFIELDS || dwCompression == BI_RGB) { + // get the bitfield masks + DWORD bf[3]; + memcpy(bf,lpVoid+pHead->biSize,12); + // transform into RGB + Bitfield2RGB(lpVoid+pHead->biSize+12,(WORD)bf[0],(WORD)bf[1],(WORD)bf[2],(BYTE)pHead->biBitCount); + } else + throw "unknown compression"; + } + break; + case 16 : + { + // get the bitfield masks + long offset=0; + DWORD bf[3]; + if (dwCompression == BI_BITFIELDS) { + memcpy(bf,lpVoid+pHead->biSize,12); + offset= 12; + } else { + bf[0] = 0x7C00; + bf[1] = 0x3E0; + bf[2] = 0x1F; // RGB555 + } + // copy the pixels + memcpy(info.pImage, lpDIBBits + offset, head.biHeight*((head.biWidth+1)/2)*4); + // transform into RGB + Bitfield2RGB(info.pImage, (WORD)bf[0], (WORD)bf[1], (WORD)bf[2], 16); + } + break; + case 8 : + case 4 : + case 1 : + { + switch (dwCompression) { + case BI_RLE4: + { + BYTE status_byte = 0; + BYTE second_byte = 0; + int scanline = 0; + int bits = 0; + BOOL low_nibble = FALSE; + CImageIterator iter(this); + + for (BOOL bContinue = TRUE; bContinue; ) { + status_byte = *(lpDIBBits++); + switch (status_byte) { + case RLE_COMMAND : + status_byte = *(lpDIBBits++); + switch (status_byte) { + case RLE_ENDOFLINE : + bits = 0; + scanline++; + low_nibble = FALSE; + break; + case RLE_ENDOFBITMAP : + bContinue = FALSE; + break; + case RLE_DELTA : + { + // read the delta values + BYTE delta_x; + BYTE delta_y; + delta_x = *(lpDIBBits++); + delta_y = *(lpDIBBits++); + // apply them + bits += delta_x / 2; + scanline += delta_y; + break; + } + default : + second_byte = *(lpDIBBits++); + BYTE* sline = iter.GetRow(scanline); + for (int i = 0; i < status_byte; i++) { + if (low_nibble) { + if ((DWORD)(sline + bits) < (DWORD)(info.pImage + head.biSizeImage)) { + *(sline + bits) |= second_byte & 0x0F; + } + if (i != status_byte - 1) + second_byte = *(lpDIBBits++); + bits++; + } else { + if ((DWORD)(sline + bits) <(DWORD)(info.pImage + head.biSizeImage)) { + *(sline + bits) = (BYTE)(second_byte & 0xF0); + } + } + low_nibble = !low_nibble; + } + if ((((status_byte+1) >> 1) & 1 )== 1) + second_byte = *(lpDIBBits++); + break; + }; + break; + default : + { + BYTE* sline = iter.GetRow(scanline); + second_byte = *(lpDIBBits++); + for (unsigned i = 0; i < status_byte; i++) { + if (low_nibble) { + if ((DWORD)(sline + bits) <(DWORD)(info.pImage + head.biSizeImage)) { + *(sline + bits) |= second_byte & 0x0F; + } + bits++; + } else { + if ((DWORD)(sline + bits) <(DWORD)(info.pImage + head.biSizeImage)) { + *(sline + bits) = (BYTE)(second_byte & 0xF0); + } + } + low_nibble = !low_nibble; + } + } + break; + }; + } + } + break; + case BI_RLE8 : + { + BYTE status_byte = 0; + BYTE second_byte = 0; + int scanline = 0; + int bits = 0; + CImageIterator iter(this); + + for (BOOL bContinue = TRUE; bContinue; ) { + status_byte = *(lpDIBBits++); + if (status_byte==RLE_COMMAND) { + status_byte = *(lpDIBBits++); + switch (status_byte) { + case RLE_ENDOFLINE : + bits = 0; + scanline++; + break; + case RLE_ENDOFBITMAP : + bContinue = FALSE; + break; + case RLE_DELTA : + { + // read the delta values + BYTE delta_x; + BYTE delta_y; + delta_x = *(lpDIBBits++); + delta_y = *(lpDIBBits++); + // apply them + bits += delta_x; + scanline += delta_y; + } + break; + default : + int nNumBytes = sizeof(BYTE) * status_byte; + memcpy((void *)(iter.GetRow(scanline) + bits), lpDIBBits, nNumBytes); + lpDIBBits += nNumBytes; + // align run length to even number of bytes + if ((status_byte & 1) == 1) + second_byte = *(lpDIBBits++); + bits += status_byte; + break; + }; + } else { + BYTE *sline = iter.GetRow(scanline); + second_byte = *(lpDIBBits++); + for (unsigned i = 0; i < status_byte; i++) { + if ((DWORD)bits + // // Create a device-independent bitmap + // return CreateBitmap(head.biWidth,head.biHeight, 1, head.biBitCount, GetBits()); + // use instead this code + HDC hMemDC = CreateCompatibleDC(NULL); + LPVOID pBit32; + HBITMAP bmp = CreateDIBSection(hMemDC,(LPBITMAPINFO)pDib,DIB_RGB_COLORS, &pBit32, NULL, 0); + if (pBit32) memcpy(pBit32, GetBits(), head.biSizeImage); + DeleteDC(hMemDC); + return bmp; + } + + // this single line seems to work very well + HBITMAP bmp = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)pDib, CBM_INIT, + GetBits(), (LPBITMAPINFO)pDib, DIB_RGB_COLORS); + + return bmp; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Bitmap resource constructor + * \param hbmp : bitmap resource handle + * \param hpal : (optional) palette, useful for 8bpp DC + * \return true if everything is ok + */ +bool CxImage::CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal) +{ + if (!Destroy()) + return false; + + if (hbmp) { + BITMAP bm; + // get informations about the bitmap + GetObject(hbmp, sizeof(BITMAP), (LPSTR) &bm); + // create the image + if (!Create(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0)) + return false; + // create a device context for the bitmap + HDC dc = ::GetDC(NULL); + if (!dc) + return false; + + if (hpal){ + SelectObject(dc,hpal); //the palette you should get from the user or have a stock one + RealizePalette(dc); + } + + // copy the pixels + if (GetDIBits(dc, hbmp, 0, head.biHeight, info.pImage, + (LPBITMAPINFO)pDib, DIB_RGB_COLORS) == 0){ //replace &head with pDib + strcpy(info.szLastError,"GetDIBits failed"); + ::ReleaseDC(NULL, dc); + return false; + } + ::ReleaseDC(NULL, dc); + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * icon resource constructor + * \param hico : icon resource handle + * \return true if everything is ok + */ +bool CxImage::CreateFromHICON(HICON hico) +{ + if (!Destroy()) + return false; + + if (hico) { + ICONINFO iinfo; + GetIconInfo(hico,&iinfo); + if (!CreateFromHBITMAP(iinfo.hbmColor)) + return false; +#if CXIMAGE_SUPPORT_ALPHA + CxImage mask; + mask.CreateFromHBITMAP(iinfo.hbmMask); + mask.GrayScale(); + mask.Negative(); + AlphaSet(mask); +#endif + DeleteObject(iinfo.hbmColor); // + DeleteObject(iinfo.hbmMask); // + return true; + } + return false; +} +//////////////////////////////////////////////////////////////////////////////// +long CxImage::Draw(HDC hdc, const RECT& rect, RECT* pClipRect, bool bSmooth) +{ + return Draw(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pClipRect,bSmooth); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Draws the image in the specified device context, with support for alpha channel, alpha palette, transparency, opacity. + * \param hdc : destination device context + * \param x,y : (optional) offset + * \param cx,cy : (optional) size. + * - If cx or cy are not specified (or less than 0), the normal width or height will be used + * - If cx or cy are different than width or height, the image will be stretched + * + * \param pClipRect : limit the drawing operations inside a given rectangle in the output device context. + * \param bSmooth : activates a bilinear filter that will enhance the appearence for zommed pictures. + * Quite slow. Needs CXIMAGE_SUPPORT_INTERPOLATION. + * \return true if everything is ok + */ +long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, bool bSmooth) +{ + if((pDib==0)||(hdc==0)||(cx==0)||(cy==0)||(!info.bEnabled)) return 0; + + if (cx < 0) cx = head.biWidth; + if (cy < 0) cy = head.biHeight; + bool bTransparent = info.nBkgndIndex != -1; + bool bAlpha = pAlpha != 0; + + RECT mainbox; // (experimental) + if (pClipRect){ + GetClipBox(hdc,&mainbox); + HRGN rgn = CreateRectRgnIndirect(pClipRect); + ExtSelectClipRgn(hdc,rgn,RGN_AND); + DeleteObject(rgn); + } + + //find the smallest area to paint + RECT clipbox,paintbox; + GetClipBox(hdc,&clipbox); + + paintbox.top = min(clipbox.bottom,max(clipbox.top,y)); + paintbox.left = min(clipbox.right,max(clipbox.left,x)); + paintbox.right = max(clipbox.left,min(clipbox.right,x+cx)); + paintbox.bottom = max(clipbox.top,min(clipbox.bottom,y+cy)); + + long destw = paintbox.right - paintbox.left; + long desth = paintbox.bottom - paintbox.top; + + if (!(bTransparent || bAlpha || info.bAlphaPaletteEnabled)){ + if (cx==head.biWidth && cy==head.biHeight){ //NORMAL + SetStretchBltMode(hdc,COLORONCOLOR); + SetDIBitsToDevice(hdc, x, y, cx, cy, 0, 0, 0, cy, + info.pImage,(BITMAPINFO*)pDib,DIB_RGB_COLORS); + } else { //STRETCH + //pixel informations + RGBQUAD c={0,0,0,0}; + //Preparing Bitmap Info + BITMAPINFO bmInfo; + memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER)); + bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); + bmInfo.bmiHeader.biWidth=destw; + bmInfo.bmiHeader.biHeight=desth; + bmInfo.bmiHeader.biPlanes=1; + bmInfo.bmiHeader.biBitCount=24; + BYTE *pbase; //points to the final dib + BYTE *pdst; //current pixel from pbase + BYTE *ppix; //current pixel from image + //get the background + HDC TmpDC=CreateCompatibleDC(hdc); + HBITMAP TmpBmp=CreateDIBSection(hdc,&bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0); + HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp); + + if (pbase){ + long xx,yy; + long sx,sy; + float dx,dy; + BYTE *psrc; + + long ew = ((((24 * destw) + 31) / 32) * 4); + long ymax = paintbox.bottom; + long xmin = paintbox.left; + float fx=(float)head.biWidth/(float)cx; + float fy=(float)head.biHeight/(float)cy; + + for(yy=0;yy>8); + + if (head.biClrUsed){ + ci = GetPixelIndex(sx,sy); +#if CXIMAGE_SUPPORT_INTERPOLATION + if (bSmooth){ + c = GetPixelColorInterpolated(dx - 0.5f, dy - 0.5f, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); + } else +#endif //CXIMAGE_SUPPORT_INTERPOLATION + { + c = GetPaletteColor(GetPixelIndex(sx,sy)); + } + if (info.bAlphaPaletteEnabled){ + a = (BYTE)((a*(1+c.rgbReserved))>>8); + } + } else { +#if CXIMAGE_SUPPORT_INTERPOLATION + if (bSmooth){ + c = GetPixelColorInterpolated(dx - 0.5f, dy - 0.5f, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); + } else +#endif //CXIMAGE_SUPPORT_INTERPOLATION + { + ppix = psrc + sx*3; + c.rgbBlue = *ppix++; + c.rgbGreen= *ppix++; + c.rgbRed = *ppix; + } + } + //if (*pc!=*pct || !bTransparent){ + //if ((head.biClrUsed && ci!=cit) || ((!head.biClrUsed||bSmooth) && *pc!=*pct) || !bTransparent){ + if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){ + // DJT, assume many pixels are fully transparent or opaque and thus avoid multiplication + if (a == 0) { // Transparent, retain dest + pdst+=3; + } else if (a == 255) { // opaque, ignore dest + *pdst++= c.rgbBlue; + *pdst++= c.rgbGreen; + *pdst++= c.rgbRed; + } else { // semi transparent + a1=(BYTE)~a; + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbBlue)>>8); + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbGreen)>>8); + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbRed)>>8); + } + } else { + pdst+=3; + } + } + } + } else { + //NORMAL + iy=head.biHeight-ymax+y; + for(yy=0;yy>8); + + if (head.biClrUsed){ + ci = GetPixelIndex(ix,iy); + c = GetPaletteColor((BYTE)ci); + if (info.bAlphaPaletteEnabled){ + a = (BYTE)((a*(1+c.rgbReserved))>>8); + } + } else { + c.rgbBlue = *ppix++; + c.rgbGreen= *ppix++; + c.rgbRed = *ppix++; + } + + //if (*pc!=*pct || !bTransparent){ + if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){ + // DJT, assume many pixels are fully transparent or opaque and thus avoid multiplication + if (a == 0) { // Transparent, retain dest + pdst+=3; + } else if (a == 255) { // opaque, ignore dest + *pdst++= c.rgbBlue; + *pdst++= c.rgbGreen; + *pdst++= c.rgbRed; + } else { // semi transparent + a1=(BYTE)~a; + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbBlue)>>8); + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbGreen)>>8); + *pdst++=(BYTE)((*pdst * a1 + a * c.rgbRed)>>8); + } + } else { + pdst+=3; + } + } + } + } + } + //paint the image & cleanup + SetDIBitsToDevice(hdc,paintbox.left,paintbox.top,destw,desth,0,0,0,desth,pbase,&bmInfo,0); + DeleteObject(SelectObject(TmpDC,TmpObj)); + DeleteDC(TmpDC); + } + + if (pClipRect){ // (experimental) + HRGN rgn = CreateRectRgnIndirect(&mainbox); + ExtSelectClipRgn(hdc,rgn,RGN_OR); + DeleteObject(rgn); + } + + return 1; +} +//////////////////////////////////////////////////////////////////////////////// +long CxImage::Draw2(HDC hdc, const RECT& rect) +{ + return Draw2(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Draws (stretch) the image with single transparency support + * \param hdc : destination device context + * \param x,y : (optional) offset + * \param cx,cy : (optional) size. + * - If cx or cy are not specified (or less than 0), the normal width or height will be used + * - If cx or cy are different than width or height, the image will be stretched + * + * \return true if everything is ok + */ +long CxImage::Draw2(HDC hdc, long x, long y, long cx, long cy) +{ + if((pDib==0)||(hdc==0)||(cx==0)||(cy==0)||(!info.bEnabled)) return 0; + if (cx < 0) cx = head.biWidth; + if (cy < 0) cy = head.biHeight; + bool bTransparent = (info.nBkgndIndex != -1); + + if (!bTransparent){ + SetStretchBltMode(hdc,COLORONCOLOR); + StretchDIBits(hdc, x, y, cx, cy, 0, 0, head.biWidth, head.biHeight, + info.pImage,(BITMAPINFO*)pDib, DIB_RGB_COLORS,SRCCOPY); + } else { + // draw image with transparent background + const int safe = 0; // or else GDI fails in the following - sometimes + RECT rcDst = {x+safe, y+safe, x+cx, y+cy}; + if (RectVisible(hdc, &rcDst)){ + ///////////////////////////////////////////////////////////////// + // True Mask Method - Thanks to Paul Reynolds and Ron Gery + int nWidth = head.biWidth; + int nHeight = head.biHeight; + // Create two memory dcs for the image and the mask + HDC dcImage=CreateCompatibleDC(hdc); + HDC dcTrans=CreateCompatibleDC(hdc); + // Select the image into the appropriate dc + HBITMAP bm = CreateCompatibleBitmap(hdc, nWidth, nHeight); + HBITMAP pOldBitmapImage = (HBITMAP)SelectObject(dcImage,bm); + SetStretchBltMode(dcImage,COLORONCOLOR); + StretchDIBits(dcImage, 0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight, + info.pImage,(BITMAPINFO*)pDib,DIB_RGB_COLORS,SRCCOPY); + + // Create the mask bitmap + HBITMAP bitmapTrans = CreateBitmap(nWidth, nHeight, 1, 1, NULL); + // Select the mask bitmap into the appropriate dc + HBITMAP pOldBitmapTrans = (HBITMAP)SelectObject(dcTrans, bitmapTrans); + // Build mask based on transparent colour + RGBQUAD rgbBG; + if (head.biBitCount<24) rgbBG = GetPaletteColor((BYTE)info.nBkgndIndex); + else rgbBG = info.nBkgndColor; + COLORREF crColour = RGB(rgbBG.rgbRed, rgbBG.rgbGreen, rgbBG.rgbBlue); + COLORREF crOldBack = SetBkColor(dcImage,crColour); + BitBlt(dcTrans,0, 0, nWidth, nHeight, dcImage, 0, 0, SRCCOPY); + + // Do the work - True Mask method - cool if not actual display + StretchBlt(hdc,x, y,cx,cy, dcImage, 0, 0, nWidth, nHeight, SRCINVERT); + StretchBlt(hdc,x, y,cx,cy, dcTrans, 0, 0, nWidth, nHeight, SRCAND); + StretchBlt(hdc,x, y,cx,cy, dcImage, 0, 0, nWidth, nHeight, SRCINVERT); + + // Restore settings + SelectObject(dcImage,pOldBitmapImage); + SelectObject(dcTrans,pOldBitmapTrans); + SetBkColor(hdc,crOldBack); + DeleteObject( bitmapTrans ); // RG 29/01/2002 + DeleteDC(dcImage); + DeleteDC(dcTrans); + DeleteObject(bm); + } + } + return 1; +} +//////////////////////////////////////////////////////////////////////////////// +long CxImage::Stretch(HDC hdc, const RECT& rect, DWORD dwRop) +{ + return Stretch(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Stretch the image. Obsolete: use Draw() or Draw2() + * \param hdc : destination device context + * \param xoffset,yoffset : (optional) offset + * \param xsize,ysize : size. + * \param dwRop : raster operation code (see BitBlt documentation) + * \return true if everything is ok + */ +long CxImage::Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop) +{ + if((pDib)&&(hdc)) { + //palette must be correctly filled + SetStretchBltMode(hdc,COLORONCOLOR); + StretchDIBits(hdc, xoffset, yoffset, + xsize, ysize, 0, 0, head.biWidth, head.biHeight, + info.pImage,(BITMAPINFO*)pDib,DIB_RGB_COLORS,dwRop); + return 1; + } + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Tiles the device context in the specified rectangle with the image. + * \param hdc : destination device context + * \param rc : tiled rectangle in the output device context + * \return true if everything is ok + */ +long CxImage::Tile(HDC hdc, RECT *rc) +{ + if((pDib)&&(hdc)&&(rc)) { + int w = rc->right - rc->left; + int h = rc->bottom - rc->top; + int x,y,z; + int bx=head.biWidth; + int by=head.biHeight; + for (y = 0 ; y < h ; y += by){ + if ((y+by)>h) by=h-y; + z=bx; + for (x = 0 ; x < w ; x += z){ + if ((x+z)>w) z=w-x; + RECT r = {rc->left + x,rc->top + y,rc->left + x + z,rc->top + y + by}; + Draw(hdc,rc->left + x, rc->top + y,-1,-1,&r); + } + } + return 1; + } + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +// For UNICODE support: char -> TCHAR +long CxImage::DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize, long lWeight, BYTE bItalic, BYTE bUnderline, bool bSetAlpha) +//long CxImage::DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize, long lWeight, BYTE bItalic, BYTE bUnderline, bool bSetAlpha) +{ + if (IsValid()){ + //get the background + HDC TmpDC=CreateCompatibleDC(hdc); + //choose the font + HFONT m_Font; + LOGFONT* m_pLF; + m_pLF=(LOGFONT*)calloc(1,sizeof(LOGFONT)); + _tcsncpy(m_pLF->lfFaceName,font,31); // For UNICODE support + //strncpy(m_pLF->lfFaceName,font,31); + m_pLF->lfHeight=lSize; + m_pLF->lfWeight=lWeight; + m_pLF->lfItalic=bItalic; + m_pLF->lfUnderline=bUnderline; + m_Font=CreateFontIndirect(m_pLF); + //select the font in the dc + HFONT pOldFont=NULL; + if (m_Font) + pOldFont = (HFONT)SelectObject(TmpDC,m_Font); + else + pOldFont = (HFONT)SelectObject(TmpDC,GetStockObject(DEFAULT_GUI_FONT)); + + //Set text color + SetTextColor(TmpDC,RGB(255,255,255)); + SetBkColor(TmpDC,RGB(0,0,0)); + //draw the text + SetBkMode(TmpDC,OPAQUE); + //Set text position; + RECT pos = {0,0,0,0}; + //long len = (long)strlen(text); + long len = (long)_tcslen(text); // For UNICODE support + ::DrawText(TmpDC,text,len,&pos,DT_CALCRECT); + pos.right+=pos.bottom; //for italics + + //Preparing Bitmap Info + long width=pos.right; + long height=pos.bottom; + BITMAPINFO bmInfo; + memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER)); + bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); + bmInfo.bmiHeader.biWidth=width; + bmInfo.bmiHeader.biHeight=height; + bmInfo.bmiHeader.biPlanes=1; + bmInfo.bmiHeader.biBitCount=24; + BYTE *pbase; //points to the final dib + + HBITMAP TmpBmp=CreateDIBSection(TmpDC,&bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0); + HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp); + memset(pbase,0,height*((((24 * width) + 31) / 32) * 4)); + + ::DrawText(TmpDC,text,len,&pos,0); + + CxImage itext; + itext.CreateFromHBITMAP(TmpBmp); + + y=head.biHeight-y-1; + for (long ix=0;ix +long CxImage::DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha ) +{ + if (!IsValid()) + return -1; + + //get the background + HDC pDC; + if (hdc) pDC=hdc; else pDC = ::GetDC(0); + HDC TmpDC=CreateCompatibleDC(pDC); + + //choose the font + HFONT m_Font; + m_Font=CreateFontIndirect( &pTextType->lfont ); + + // get colors in RGBQUAD + RGBQUAD p_forecolor = RGBtoRGBQUAD(pTextType->fcolor); + RGBQUAD p_backcolor = RGBtoRGBQUAD(pTextType->bcolor); + + // check alignment and re-set default if necessary + if ( pTextType->align != DT_CENTER && + pTextType->align != DT_LEFT && + pTextType->align != DT_RIGHT ) + pTextType->align = DT_CENTER; + + // check rounding radius and re-set default if necessary + if ( pTextType->b_round > 50 || pTextType->b_round < 0 ) + pTextType->b_round = 10; + + // check opacity and re-set default if necessary + if ( pTextType->b_opacity > 1. || pTextType->b_opacity < .0 ) + pTextType->b_opacity = 0.; + + //select the font in the dc + HFONT pOldFont=NULL; + if (m_Font) + pOldFont = (HFONT)SelectObject(TmpDC,m_Font); + else + pOldFont = (HFONT)SelectObject(TmpDC,GetStockObject(DEFAULT_GUI_FONT)); + + //Set text color + SetTextColor(TmpDC,RGB(255,255,255)); + SetBkColor(TmpDC,RGB(0,0,0)); + SetBkMode(TmpDC,OPAQUE); + //Set text position; + RECT pos = {0,0,0,0}; + + // get text length and number of lines + long i=0, numlines=1, len=(long)_tcsclen(pTextType->text); + while (itext[i++]==13 ) + numlines++; + } + + ::DrawText(TmpDC, pTextType->text, len, &pos, /*DT_EDITCONTROL|DT_EXTERNALLEADING|*/DT_NOPREFIX | DT_CALCRECT ); + + // increase only if it's really italics, and only one line height + if ( pTextType->lfont.lfItalic ) + pos.right += pos.bottom/2/numlines; + + // background frame and rounding radius + int frame = 0, roundR = 0; + if ( pTextType->opaque ) + { + roundR= (int)(pos.bottom/numlines * pTextType->b_round / 100 ) ; + frame = (int)(/*3.5 + */0.29289*roundR ) ; + pos.right += pos.bottom/numlines/3 ; // JUST FOR BEAUTY + } + + //Preparing Bitmap Info + long width=pos.right +frame*2; + long height=pos.bottom +frame*2; + BITMAPINFO bmInfo; + memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER)); + bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); + bmInfo.bmiHeader.biWidth=width; + bmInfo.bmiHeader.biHeight=height; + bmInfo.bmiHeader.biPlanes=1; + bmInfo.bmiHeader.biBitCount=24; + BYTE *pbase; //points to the final dib + + HBITMAP TmpBmp=CreateDIBSection(TmpDC,&bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0); + HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp); + memset(pbase,0,height*((((24 * width) + 31) / 32) * 4)); + + ::DrawText(TmpDC,pTextType->text,len, &pos, /*DT_EDITCONTROL|DT_EXTERNALLEADING|*/DT_NOPREFIX| pTextType->align ); + + CxImage itext; + itext.CreateFromHBITMAP(TmpBmp); + y=head.biHeight-y-1; + + //move the insertion point according to alignment type + // DT_CENTER: cursor points to the center of text rectangle + // DT_RIGHT: cursor points to right side end of text rectangle + // DT_LEFT: cursor points to left end of text rectangle + if ( pTextType->align == DT_CENTER ) + x -= width/2; + else if ( pTextType->align == DT_RIGHT ) + x -= width; + if (x<0) x=0; + + //draw the background first, if it exists + long ix,iy; + if ( pTextType->opaque ) + { + int ixf=0; + for (ix=0;ix=width-roundR-1 ) + ixf = (int)(.5+roundR-sqrt((float)(roundR*roundR-(width-1-ix-roundR)*(width-1-ix-roundR)))); + else + ixf=0; + + for (iy=0;iy height-ixf-1 || iy < ixf )) || + (ix>=width-roundR-1 && ( iy > height-ixf-1 || iy < ixf )) ) + continue; + else + if ( pTextType->b_opacity > 0.0 && pTextType->b_opacity < 1.0 ) + { + RGBQUAD bcolor, pcolor; + // calculate a transition color from original image to background color: + pcolor = GetPixelColor(x+ix,y+iy); + bcolor.rgbBlue = (unsigned char)(pTextType->b_opacity * pcolor.rgbBlue + (1.0-pTextType->b_opacity) * p_backcolor.rgbBlue ); + bcolor.rgbRed = (unsigned char)(pTextType->b_opacity * pcolor.rgbRed + (1.0-pTextType->b_opacity) * p_backcolor.rgbRed ) ; + bcolor.rgbGreen = (unsigned char)(pTextType->b_opacity * pcolor.rgbGreen + (1.0-pTextType->b_opacity) * p_backcolor.rgbGreen ) ; + bcolor.rgbReserved = 0; + SetPixelColor(x+ix,y+iy,bcolor,bSetAlpha); + } + else + SetPixelColor(x+ix,y+iy,p_backcolor,bSetAlpha); + } + } + } + + // draw the text itself + for (ix=0;ixlfont.lfHeight = -36; + txt->lfont.lfCharSet = EASTEUROPE_CHARSET; // just for Central-European users + txt->lfont.lfWeight = FW_NORMAL; + txt->lfont.lfWidth = 0; + txt->lfont.lfEscapement = 0; + txt->lfont.lfOrientation = 0; + txt->lfont.lfItalic = FALSE; + txt->lfont.lfUnderline = FALSE; + txt->lfont.lfStrikeOut = FALSE; + txt->lfont.lfOutPrecision = OUT_DEFAULT_PRECIS; + txt->lfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; + txt->lfont.lfQuality = PROOF_QUALITY; + txt->lfont.lfPitchAndFamily= DEFAULT_PITCH | FF_DONTCARE ; + _stprintf( txt->lfont.lfFaceName, _T("Arial")); //use TCHAR mappings + + // initial colors + txt->fcolor = RGB( 255,255,160 ); // default foreground: light goldyellow + txt->bcolor = RGB( 32, 96, 0 ); // default background: deep green + + // background + txt->opaque = TRUE; // text has a non-transparent background; + txt->b_opacity = 0.0; // default: opaque background + txt->b_outline = 0; // default: no outline (OUTLINE NOT IMPLEMENTED AT THIS TIME) + txt->b_round = 20; // default: rounding radius is 20% of the rectangle height + // the text + _stprintf( txt->text, _T("Sample Text 01234õû")); // text use TCHAR mappings + txt->align = DT_CENTER; + return; +} +//////////////////////////////////////////////////////////////////////////////// +#endif //CXIMAGE_SUPPORT_WINDOWS +//////////////////////////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xiofile.h ./win32/dependencies/cximage/xiofile.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xiofile.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/xiofile.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,112 @@ +#if !defined(__xiofile_h) +#define __xiofile_h + +#include "xfile.h" + +class DLL_EXP CxIOFile : public CxFile + { +public: + CxIOFile(FILE* fp = NULL) + { + m_fp = fp; + m_bCloseFile = (bool)(fp==0); + } + + ~CxIOFile() + { + Close(); + } +////////////////////////////////////////////////////////// + bool Open(const char *filename, const char *mode) + { + if (m_fp) return false; // Can't re-open without closing first + + m_fp = fopen(filename, mode); + if (!m_fp) return false; + + m_bCloseFile = true; + + return true; + } +////////////////////////////////////////////////////////// + virtual bool Close() + { + int iErr = 0; + if ( (m_fp) && (m_bCloseFile) ){ + iErr = fclose(m_fp); + m_fp = NULL; + } + return (bool)(iErr==0); + } +////////////////////////////////////////////////////////// + virtual size_t Read(void *buffer, size_t size, size_t count) + { + if (!m_fp) return 0; + return fread(buffer, size, count, m_fp); + } +////////////////////////////////////////////////////////// + virtual size_t Write(const void *buffer, size_t size, size_t count) + { + if (!m_fp) return 0; + return fwrite(buffer, size, count, m_fp); + } +////////////////////////////////////////////////////////// + virtual bool Seek(long offset, int origin) + { + if (!m_fp) return false; + return (bool)(fseek(m_fp, offset, origin) == 0); + } +////////////////////////////////////////////////////////// + virtual long Tell() + { + if (!m_fp) return 0; + return ftell(m_fp); + } +////////////////////////////////////////////////////////// + virtual long Size() + { + if (!m_fp) return -1; + long pos,size; + pos = ftell(m_fp); + fseek(m_fp, 0, SEEK_END); + size = ftell(m_fp); + fseek(m_fp, pos,SEEK_SET); + return size; + } +////////////////////////////////////////////////////////// + virtual bool Flush() + { + if (!m_fp) return false; + return (bool)(fflush(m_fp) == 0); + } +////////////////////////////////////////////////////////// + virtual bool Eof() + { + if (!m_fp) return true; + return (bool)(feof(m_fp) != 0); + } +////////////////////////////////////////////////////////// + virtual long Error() + { + if (!m_fp) return -1; + return ferror(m_fp); + } +////////////////////////////////////////////////////////// + virtual bool PutC(unsigned char c) + { + if (!m_fp) return false; + return (bool)(fputc(c, m_fp) == c); + } +////////////////////////////////////////////////////////// + virtual long GetC() + { + if (!m_fp) return EOF; + return getc(m_fp); + } +////////////////////////////////////////////////////////// +protected: + FILE *m_fp; + bool m_bCloseFile; + }; + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xmemfile.cpp ./win32/dependencies/cximage/xmemfile.cpp --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xmemfile.cpp 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/xmemfile.cpp 2006-08-24 07:16:03 +0900 @@ -0,0 +1,173 @@ +#include "xmemfile.h" + +////////////////////////////////////////////////////////// +CxMemFile::CxMemFile(BYTE* pBuffer, DWORD size) +{ + m_pBuffer = pBuffer; + m_Position = 0; + m_Size = m_Edge = size; + m_bFreeOnClose = (bool)(pBuffer==0); +} +////////////////////////////////////////////////////////// +CxMemFile::~CxMemFile() +{ + Close(); +} +////////////////////////////////////////////////////////// +bool CxMemFile::Close() +{ + if ( (m_pBuffer) && (m_bFreeOnClose) ){ + free(m_pBuffer); + m_pBuffer = NULL; + m_Size = 0; + } + return true; +} +////////////////////////////////////////////////////////// +bool CxMemFile::Open() +{ + if (m_pBuffer) return false; // Can't re-open without closing first + + m_Position = m_Size = m_Edge = 0; + m_pBuffer=(BYTE*)malloc(1); + m_bFreeOnClose = true; + + return (m_pBuffer!=0); +} +////////////////////////////////////////////////////////// +BYTE* CxMemFile::GetBuffer(bool bDetachBuffer) +{ + m_bFreeOnClose = !bDetachBuffer; + return m_pBuffer; +} +////////////////////////////////////////////////////////// +size_t CxMemFile::Read(void *buffer, size_t size, size_t count) +{ + if (buffer==NULL) return 0; + + if (m_pBuffer==NULL) return 0; + if (m_Position >= (long)m_Size) return 0; + + long nCount = (long)(count*size); + if (nCount == 0) return 0; + + long nRead; + if (m_Position + nCount > (long)m_Size) + nRead = (m_Size - m_Position); + else + nRead = nCount; + + memcpy(buffer, m_pBuffer + m_Position, nRead); + m_Position += nRead; + + return (size_t)(nRead/size); +} +////////////////////////////////////////////////////////// +size_t CxMemFile::Write(const void *buffer, size_t size, size_t count) +{ + if (m_pBuffer==NULL) return 0; + if (buffer==NULL) return 0; + + long nCount = (long)(count*size); + if (nCount == 0) return 0; + + if (m_Position + nCount > m_Edge) Alloc(m_Position + nCount); + + memcpy(m_pBuffer + m_Position, buffer, nCount); + + m_Position += nCount; + + if (m_Position > (long)m_Size) m_Size = m_Position; + + return count; +} +////////////////////////////////////////////////////////// +bool CxMemFile::Seek(long offset, int origin) +{ + if (m_pBuffer==NULL) return false; + long lNewPos = m_Position; + + if (origin == SEEK_SET) lNewPos = offset; + else if (origin == SEEK_CUR) lNewPos += offset; + else if (origin == SEEK_END) lNewPos = m_Size + offset; + else return false; + + if (lNewPos < 0) lNewPos = 0; + + m_Position = lNewPos; + return true; +} +////////////////////////////////////////////////////////// +long CxMemFile::Tell() +{ + if (m_pBuffer==NULL) return -1; + return m_Position; +} +////////////////////////////////////////////////////////// +long CxMemFile::Size() +{ + if (m_pBuffer==NULL) return -1; + return m_Size; +} +////////////////////////////////////////////////////////// +bool CxMemFile::Flush() +{ + if (m_pBuffer==NULL) return false; + return true; +} +////////////////////////////////////////////////////////// +bool CxMemFile::Eof() +{ + if (m_pBuffer==NULL) return true; + return (m_Position >= (long)m_Size); +} +////////////////////////////////////////////////////////// +long CxMemFile::Error() +{ + if (m_pBuffer==NULL) return -1; + return (m_Position > (long)m_Size); +} +////////////////////////////////////////////////////////// +bool CxMemFile::PutC(unsigned char c) +{ + if (m_pBuffer==NULL) return false; + if (m_Position + 1 > m_Edge) Alloc(m_Position + 1); + + memcpy(m_pBuffer + m_Position, &c, 1); + + m_Position += 1; + + if (m_Position > (long)m_Size) m_Size = m_Position; + + return true; +} +////////////////////////////////////////////////////////// +long CxMemFile::GetC() +{ + if (Eof()) return EOF; + return *(BYTE*)((BYTE*)m_pBuffer + m_Position++); +} +////////////////////////////////////////////////////////// +void CxMemFile::Alloc(DWORD dwNewLen) +{ + if (dwNewLen > (DWORD)m_Edge) + { + // find new buffer size + DWORD dwNewBufferSize = (DWORD)(((dwNewLen>>12)+1)<<12); + + // allocate new buffer + if (m_pBuffer == NULL) m_pBuffer = (BYTE*)malloc(dwNewBufferSize); + else m_pBuffer = (BYTE*)realloc(m_pBuffer, dwNewBufferSize); + // I own this buffer now (caller knows nothing about it) + m_bFreeOnClose = true; + + m_Edge = dwNewBufferSize; + } + return; +} +////////////////////////////////////////////////////////// +void CxMemFile::Free() +{ + Close(); +} +////////////////////////////////////////////////////////// diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xmemfile.h ./win32/dependencies/cximage/xmemfile.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/cximage/xmemfile.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/cximage/xmemfile.h 2006-08-24 07:16:03 +0900 @@ -0,0 +1,39 @@ +#if !defined(__xmemfile_h) +#define __xmemfile_h + +#include "xfile.h" + +////////////////////////////////////////////////////////// +class DLL_EXP CxMemFile : public CxFile +{ +public: + CxMemFile(BYTE* pBuffer = NULL, DWORD size = 0); + ~CxMemFile(); + + bool Open(); + BYTE* GetBuffer(bool bDetachBuffer = true); + + virtual bool Close(); + virtual size_t Read(void *buffer, size_t size, size_t count); + virtual size_t Write(const void *buffer, size_t size, size_t count); + virtual bool Seek(long offset, int origin); + virtual long Tell(); + virtual long Size(); + virtual bool Flush(); + virtual bool Eof(); + virtual long Error(); + virtual bool PutC(unsigned char c); + virtual long GetC(); + +protected: + void Alloc(DWORD nBytes); + void Free(); + + BYTE* m_pBuffer; + DWORD m_Size; + bool m_bFreeOnClose; + long m_Position; //current position + long m_Edge; //buffer size +}; + +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/info.txt ./win32/dependencies/info.txt --- ../VisualBoyAdvance-1.7.2/win32/dependencies/info.txt 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/info.txt 2006-05-13 06:26:37 +0900 @@ -0,0 +1 @@ +All those libraries use the Static Multi-Threaded C/C++ [Release / Debug] libraries. \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/.cvsignore ./win32/dependencies/libpng/.cvsignore --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/.cvsignore 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/.cvsignore 2006-05-14 01:41:48 +0900 @@ -0,0 +1,3 @@ +release +libpng.vcproj.A2.Spacy.user +debug \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/libpng.vcproj ./win32/dependencies/libpng/libpng.vcproj --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/libpng.vcproj 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/libpng.vcproj 2006-08-24 07:13:29 +0900 @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/png.c ./win32/dependencies/libpng/png.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/png.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/png.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,847 @@ + +/* png.c - location for general purpose libpng functions + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#define PNG_NO_EXTERN +#include "png.h" + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef version_1_2_10 Your_png_h_is_not_version_1_2_10; + +/* Version information for C files. This had better match the version + * string defined in png.h. */ + +#ifdef PNG_USE_GLOBAL_ARRAYS +/* png_libpng_ver was changed to a function in version 1.0.5c */ +const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; + +#ifdef PNG_READ_SUPPORTED + +/* png_sig was changed to a function in version 1.0.5c */ +/* Place to hold the signature string for a PNG file. */ +const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; +#endif /* PNG_READ_SUPPORTED */ + +/* Invoke global declarations for constant strings for known chunk types */ +PNG_IHDR; +PNG_IDAT; +PNG_IEND; +PNG_PLTE; +PNG_bKGD; +PNG_cHRM; +PNG_gAMA; +PNG_hIST; +PNG_iCCP; +PNG_iTXt; +PNG_oFFs; +PNG_pCAL; +PNG_sCAL; +PNG_pHYs; +PNG_sBIT; +PNG_sPLT; +PNG_sRGB; +PNG_tEXt; +PNG_tIME; +PNG_tRNS; +PNG_zTXt; + +#ifdef PNG_READ_SUPPORTED +/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + +/* start of interlace block */ +const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + +/* offset to next interlace block */ +const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + +/* start of interlace block in the y direction */ +const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + +/* offset to next interlace block in the y direction */ +const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + +/* width of interlace block (used in assembler routines only) */ +#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW +const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; +#endif + +/* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h +const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; +*/ + +/* Mask to determine which pixels are valid in a pass */ +const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; + +/* Mask to determine which pixels to overwrite while displaying */ +const int FARDATA png_pass_dsp_mask[] + = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; + +#endif /* PNG_READ_SUPPORTED */ +#endif /* PNG_USE_GLOBAL_ARRAYS */ + +/* Tells libpng that we have already handled the first "num_bytes" bytes + * of the PNG file signature. If the PNG data is embedded into another + * stream we can set num_bytes = 8 so that libpng will not attempt to read + * or write any of the magic bytes before it starts on the IHDR. + */ + +#ifdef PNG_READ_SUPPORTED +void PNGAPI +png_set_sig_bytes(png_structp png_ptr, int num_bytes) +{ + png_debug(1, "in png_set_sig_bytes\n"); + if (num_bytes > 8) + png_error(png_ptr, "Too many bytes for PNG signature."); + + png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); +} + +/* Checks whether the supplied bytes match the PNG signature. We allow + * checking less than the full 8-byte signature so that those apps that + * already read the first few bytes of a file to determine the file type + * can simply check the remaining bytes for extra assurance. Returns + * an integer less than, equal to, or greater than zero if sig is found, + * respectively, to be less than, to match, or be greater than the correct + * PNG signature (this is the same behaviour as strcmp, memcmp, etc). + */ +int PNGAPI +png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + if (num_to_check > 8) + num_to_check = 8; + else if (num_to_check < 1) + return (-1); + + if (start > 7) + return (-1); + + if (start + num_to_check > 8) + num_to_check = 8 - start; + + return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); +} + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* (Obsolete) function to check signature bytes. It does not allow one + * to check a partial signature. This function might be removed in the + * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG. + */ +int PNGAPI +png_check_sig(png_bytep sig, int num) +{ + return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); +} +#endif +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Function to allocate memory for zlib and clear it to 0. */ +#ifdef PNG_1_0_X +voidpf PNGAPI +#else +voidpf /* private */ +#endif +png_zalloc(voidpf png_ptr, uInt items, uInt size) +{ + png_voidp ptr; + png_structp p=png_ptr; + png_uint_32 save_flags=p->flags; + png_uint_32 num_bytes; + + if (items > PNG_UINT_32_MAX/size) + { + png_warning (png_ptr, "Potential overflow in png_zalloc()"); + return (NULL); + } + num_bytes = (png_uint_32)items * size; + + p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); + p->flags=save_flags; + +#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO) + if (ptr == NULL) + return ((voidpf)ptr); + + if (num_bytes > (png_uint_32)0x8000L) + { + png_memset(ptr, 0, (png_size_t)0x8000L); + png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0, + (png_size_t)(num_bytes - (png_uint_32)0x8000L)); + } + else + { + png_memset(ptr, 0, (png_size_t)num_bytes); + } +#endif + return ((voidpf)ptr); +} + +/* function to free memory for zlib */ +#ifdef PNG_1_0_X +void PNGAPI +#else +void /* private */ +#endif +png_zfree(voidpf png_ptr, voidpf ptr) +{ + png_free((png_structp)png_ptr, (png_voidp)ptr); +} + +/* Reset the CRC variable to 32 bits of 1's. Care must be taken + * in case CRC is > 32 bits to leave the top bits 0. + */ +void /* PRIVATE */ +png_reset_crc(png_structp png_ptr) +{ + png_ptr->crc = crc32(0, Z_NULL, 0); +} + +/* Calculate the CRC over a section of data. We can only pass as + * much data to this routine as the largest single buffer size. We + * also check that this data will actually be used before going to the + * trouble of calculating it. + */ +void /* PRIVATE */ +png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) +{ + int need_crc = 1; + + if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + + if (need_crc) + png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length); +} + +/* Allocate the memory for an info_struct for the application. We don't + * really need the png_ptr, but it could potentially be useful in the + * future. This should be used in favour of malloc(png_sizeof(png_info)) + * and png_info_init() so that applications that want to use a shared + * libpng don't have to be recompiled if png_info changes size. + */ +png_infop PNGAPI +png_create_info_struct(png_structp png_ptr) +{ + png_infop info_ptr; + + png_debug(1, "in png_create_info_struct\n"); + if(png_ptr == NULL) return (NULL); +#ifdef PNG_USER_MEM_SUPPORTED + info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, + png_ptr->malloc_fn, png_ptr->mem_ptr); +#else + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); +#endif + if (info_ptr != NULL) + png_info_init_3(&info_ptr, png_sizeof(png_info)); + + return (info_ptr); +} + +/* This function frees the memory associated with a single info struct. + * Normally, one would use either png_destroy_read_struct() or + * png_destroy_write_struct() to free an info struct, but this may be + * useful for some applications. + */ +void PNGAPI +png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) +{ + png_infop info_ptr = NULL; + + png_debug(1, "in png_destroy_info_struct\n"); + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + png_info_destroy(png_ptr, info_ptr); + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, + png_ptr->mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } +} + +/* Initialize the info structure. This is now an internal function (0.89) + * and applications using it are urged to use png_create_info_struct() + * instead. + */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#undef png_info_init +void PNGAPI +png_info_init(png_infop info_ptr) +{ + /* We only come here via pre-1.0.12-compiled applications */ + png_info_init_3(&info_ptr, 0); +} +#endif + +void PNGAPI +png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) +{ + png_infop info_ptr = *ptr_ptr; + + png_debug(1, "in png_info_init_3\n"); + + if(png_sizeof(png_info) > png_info_struct_size) + { + png_destroy_struct(info_ptr); + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); + *ptr_ptr = info_ptr; + } + + /* set everything to 0 */ + png_memset(info_ptr, 0, png_sizeof (png_info)); +} + +#ifdef PNG_FREE_ME_SUPPORTED +void PNGAPI +png_data_freer(png_structp png_ptr, png_infop info_ptr, + int freer, png_uint_32 mask) +{ + png_debug(1, "in png_data_freer\n"); + if (png_ptr == NULL || info_ptr == NULL) + return; + if(freer == PNG_DESTROY_WILL_FREE_DATA) + info_ptr->free_me |= mask; + else if(freer == PNG_USER_WILL_FREE_DATA) + info_ptr->free_me &= ~mask; + else + png_warning(png_ptr, + "Unknown freer parameter in png_data_freer."); +} +#endif + +void PNGAPI +png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, + int num) +{ + png_debug(1, "in png_free_data\n"); + if (png_ptr == NULL || info_ptr == NULL) + return; + +#if defined(PNG_TEXT_SUPPORTED) +/* free text item num or (if num == -1) all text items */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) +#else +if (mask & PNG_FREE_TEXT) +#endif +{ + if (num != -1) + { + if (info_ptr->text && info_ptr->text[num].key) + { + png_free(png_ptr, info_ptr->text[num].key); + info_ptr->text[num].key = NULL; + } + } + else + { + int i; + for (i = 0; i < info_ptr->num_text; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); + png_free(png_ptr, info_ptr->text); + info_ptr->text = NULL; + info_ptr->num_text=0; + } +} +#endif + +#if defined(PNG_tRNS_SUPPORTED) +/* free any tRNS entry */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) +#else +if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) +#endif +{ + png_free(png_ptr, info_ptr->trans); + info_ptr->valid &= ~PNG_INFO_tRNS; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif + info_ptr->trans = NULL; +} +#endif + +#if defined(PNG_sCAL_SUPPORTED) +/* free any sCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) +#else +if (mask & PNG_FREE_SCAL) +#endif +{ +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, info_ptr->scal_s_width); + png_free(png_ptr, info_ptr->scal_s_height); + info_ptr->scal_s_width = NULL; + info_ptr->scal_s_height = NULL; +#endif + info_ptr->valid &= ~PNG_INFO_sCAL; +} +#endif + +#if defined(PNG_pCAL_SUPPORTED) +/* free any pCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) +#else +if (mask & PNG_FREE_PCAL) +#endif +{ + png_free(png_ptr, info_ptr->pcal_purpose); + png_free(png_ptr, info_ptr->pcal_units); + info_ptr->pcal_purpose = NULL; + info_ptr->pcal_units = NULL; + if (info_ptr->pcal_params != NULL) + { + int i; + for (i = 0; i < (int)info_ptr->pcal_nparams; i++) + { + png_free(png_ptr, info_ptr->pcal_params[i]); + info_ptr->pcal_params[i]=NULL; + } + png_free(png_ptr, info_ptr->pcal_params); + info_ptr->pcal_params = NULL; + } + info_ptr->valid &= ~PNG_INFO_pCAL; +} +#endif + +#if defined(PNG_iCCP_SUPPORTED) +/* free any iCCP entry */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) +#else +if (mask & PNG_FREE_ICCP) +#endif +{ + png_free(png_ptr, info_ptr->iccp_name); + png_free(png_ptr, info_ptr->iccp_profile); + info_ptr->iccp_name = NULL; + info_ptr->iccp_profile = NULL; + info_ptr->valid &= ~PNG_INFO_iCCP; +} +#endif + +#if defined(PNG_sPLT_SUPPORTED) +/* free a given sPLT entry, or (if num == -1) all sPLT entries */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) +#else +if (mask & PNG_FREE_SPLT) +#endif +{ + if (num != -1) + { + if(info_ptr->splt_palettes) + { + png_free(png_ptr, info_ptr->splt_palettes[num].name); + png_free(png_ptr, info_ptr->splt_palettes[num].entries); + info_ptr->splt_palettes[num].name = NULL; + info_ptr->splt_palettes[num].entries = NULL; + } + } + else + { + if(info_ptr->splt_palettes_num) + { + int i; + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes = NULL; + info_ptr->splt_palettes_num = 0; + } + info_ptr->valid &= ~PNG_INFO_sPLT; + } +} +#endif + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) +#else +if (mask & PNG_FREE_UNKN) +#endif +{ + if (num != -1) + { + if(info_ptr->unknown_chunks) + { + png_free(png_ptr, info_ptr->unknown_chunks[num].data); + info_ptr->unknown_chunks[num].data = NULL; + } + } + else + { + int i; + + if(info_ptr->unknown_chunks_num) + { + for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + info_ptr->unknown_chunks_num = 0; + } + } +} +#endif + +#if defined(PNG_hIST_SUPPORTED) +/* free any hIST entry */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_HIST) & info_ptr->free_me) +#else +if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) +#endif +{ + png_free(png_ptr, info_ptr->hist); + info_ptr->hist = NULL; + info_ptr->valid &= ~PNG_INFO_hIST; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif +} +#endif + +/* free any PLTE entry that was internally allocated */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) +#else +if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE)) +#endif +{ + png_zfree(png_ptr, info_ptr->palette); + info_ptr->palette = NULL; + info_ptr->valid &= ~PNG_INFO_PLTE; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif + info_ptr->num_palette = 0; +} + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +/* free any image bits attached to the info structure */ +#ifdef PNG_FREE_ME_SUPPORTED +if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) +#else +if (mask & PNG_FREE_ROWS) +#endif +{ + if(info_ptr->row_pointers) + { + int row; + for (row = 0; row < (int)info_ptr->height; row++) + { + png_free(png_ptr, info_ptr->row_pointers[row]); + info_ptr->row_pointers[row]=NULL; + } + png_free(png_ptr, info_ptr->row_pointers); + info_ptr->row_pointers=NULL; + } + info_ptr->valid &= ~PNG_INFO_IDAT; +} +#endif + +#ifdef PNG_FREE_ME_SUPPORTED + if(num == -1) + info_ptr->free_me &= ~mask; + else + info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); +#endif +} + +/* This is an internal routine to free any memory that the info struct is + * pointing to before re-using it or freeing the struct itself. Recall + * that png_free() checks for NULL pointers for us. + */ +void /* PRIVATE */ +png_info_destroy(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_info_destroy\n"); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; + png_ptr->num_chunk_list=0; + } +#endif + + png_info_init_3(&info_ptr, png_sizeof(png_info)); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* This function returns a pointer to the io_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy() or png_read_destroy() are called. + */ +png_voidp PNGAPI +png_get_io_ptr(png_structp png_ptr) +{ + return (png_ptr->io_ptr); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#if !defined(PNG_NO_STDIO) +/* Initialize the default input/output functions for the PNG file. If you + * use your own read or write routines, you can call either png_set_read_fn() + * or png_set_write_fn() instead of png_init_io(). If you have defined + * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't + * necessarily available. + */ +void PNGAPI +png_init_io(png_structp png_ptr, png_FILE_p fp) +{ + png_debug(1, "in png_init_io\n"); + png_ptr->io_ptr = (png_voidp)fp; +} +#endif + +#if defined(PNG_TIME_RFC1123_SUPPORTED) +/* Convert the supplied time into an RFC 1123 string suitable for use in + * a "Creation Time" or other text-based time string. + */ +png_charp PNGAPI +png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) +{ + static PNG_CONST char short_months[12][4] = + {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + + if (png_ptr->time_buffer == NULL) + { + png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* + png_sizeof(char))); + } + +#if defined(_WIN32_WCE) + { + wchar_t time_buf[29]; + wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29, + NULL, NULL); + } +#else +#ifdef USE_FAR_KEYWORD + { + char near_time_buf[29]; + sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000", + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + png_memcpy(png_ptr->time_buffer, near_time_buf, + 29*png_sizeof(char)); + } +#else + sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); +#endif +#endif /* _WIN32_WCE */ + return ((png_charp)png_ptr->time_buffer); +} +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + +#if 0 +/* Signature string for a PNG file. */ +png_bytep PNGAPI +png_sig_bytes(void) +{ + return ((png_bytep)"\211\120\116\107\015\012\032\012"); +} +#endif +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +png_charp PNGAPI +png_get_copyright(png_structp png_ptr) +{ + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) "\n libpng version 1.2.10 - April 23, 2006\n\ + Copyright (c) 1998-2006 Glenn Randers-Pehrson\n\ + Copyright (c) 1996-1997 Andreas Dilger\n\ + Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); + return ((png_charp) ""); +} + +/* The following return the library version as a short string in the + * format 1.0.0 through 99.99.99zz. To get the version of *.h files + * used with your application, print out PNG_LIBPNG_VER_STRING, which + * is defined in png.h. + * Note: now there is no difference between png_get_libpng_ver() and + * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, + * it is guaranteed that png.c uses the correct version of png.h. + */ +png_charp PNGAPI +png_get_libpng_ver(png_structp png_ptr) +{ + /* Version of *.c files used when building libpng */ + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); + return ((png_charp) ""); +} + +png_charp PNGAPI +png_get_header_ver(png_structp png_ptr) +{ + /* Version of *.h files used when building libpng */ + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); + return ((png_charp) ""); +} + +png_charp PNGAPI +png_get_header_version(png_structp png_ptr) +{ + /* Returns longer string containing both version and date */ + if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_HEADER_VERSION_STRING); + return ((png_charp) ""); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +int PNGAPI +png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) +{ + /* check chunk_name and return "keep" value if it's on the list, else 0 */ + int i; + png_bytep p; + if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0) + return 0; + p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5; + for (i = png_ptr->num_chunk_list; i; i--, p-=5) + if (!png_memcmp(chunk_name, p, 4)) + return ((int)*(p+4)); + return 0; +} +#endif + +/* This function, added to libpng-1.0.6g, is untested. */ +int PNGAPI +png_reset_zstream(png_structp png_ptr) +{ + return (inflateReset(&png_ptr->zstream)); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* This function was added to libpng-1.0.7 */ +png_uint_32 PNGAPI +png_access_version_number(void) +{ + /* Version of *.c files used when building libpng */ + return((png_uint_32) PNG_LIBPNG_VER); +} + + +#if defined(PNG_READ_SUPPORTED) +#if !defined(PNG_1_0_X) +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ +/* this INTERNAL function was added to libpng 1.2.0 */ +void /* PRIVATE */ +png_init_mmx_flags (png_structp png_ptr) +{ + png_ptr->mmx_rowbytes_threshold = 0; + png_ptr->mmx_bitdepth_threshold = 0; + +# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD)) + + png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED; + + if (png_mmx_support() > 0) { + png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU +# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW + | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW +# endif +# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE + | PNG_ASM_FLAG_MMX_READ_INTERLACE +# endif +# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW + ; +# else + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB + | PNG_ASM_FLAG_MMX_READ_FILTER_UP + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ; + + png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT; + png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT; +# endif + } else { + png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU + | PNG_MMX_READ_FLAGS + | PNG_MMX_WRITE_FLAGS ); + } + +# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */ + + /* clear all MMX flags; no support is compiled in */ + png_ptr->asm_flags &= ~( PNG_MMX_FLAGS ); + +# endif /* ?(PNGVCRD || PNGGCCRD) */ +} + +#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */ + +/* this function was added to libpng 1.2.0 */ +#if !defined(PNG_USE_PNGGCCRD) && \ + !(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)) +int PNGAPI +png_mmx_support(void) +{ + return -1; +} +#endif +#endif /* PNG_1_0_X */ +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#ifdef PNG_SIZE_T +/* Added at libpng version 1.2.6 */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); +png_size_t PNGAPI +png_convert_size(size_t size) +{ + if (size > (png_size_t)-1) + PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ + return ((png_size_t)size); +} +#endif /* PNG_SIZE_T */ +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/png.h ./win32/dependencies/libpng/png.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/png.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/png.h 2006-05-13 06:27:07 +0900 @@ -0,0 +1,3450 @@ + +/* png.h - header file for PNG reference library + * + * libpng version 1.2.10 - April 23, 2006 + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * Authors and maintainers: + * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat + * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.2.10 - April 23, 2006: Glenn + * See also "Contributing Authors", below. + * + * Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h png.h shared-lib + * version string int version + * ------- ------ ----- ---------- + * 0.89c "1.0 beta 3" 0.89 89 1.0.89 + * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] + * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] + * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] + * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] + * 0.97c 0.97 97 2.0.97 + * 0.98 0.98 98 2.0.98 + * 0.99 0.99 98 2.0.99 + * 0.99a-m 0.99 99 2.0.99 + * 1.00 1.00 100 2.1.0 [100 should be 10000] + * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] + * 1.0.1 png.h string is 10001 2.1.0 + * 1.0.1a-e identical to the 10002 from here on, the shared library + * 1.0.2 source version) 10002 is 2.V where V is the source code + * 1.0.2a-b 10003 version, except as noted. + * 1.0.3 10003 + * 1.0.3a-d 10004 + * 1.0.4 10004 + * 1.0.4a-f 10005 + * 1.0.5 (+ 2 patches) 10005 + * 1.0.5a-d 10006 + * 1.0.5e-r 10100 (not source compatible) + * 1.0.5s-v 10006 (not binary compatible) + * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) + * 1.0.6d-f 10007 (still binary incompatible) + * 1.0.6g 10007 + * 1.0.6h 10007 10.6h (testing xy.z so-numbering) + * 1.0.6i 10007 10.6i + * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + * 1.0.8rc1 1 10008 2.1.0.8rc1 + * 1.0.8 1 10008 2.1.0.8 + * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + * 1.0.9rc1 1 10009 2.1.0.9rc1 + * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + * 1.0.9rc2 1 10009 2.1.0.9rc2 + * 1.0.9 1 10009 2.1.0.9 + * 1.0.10beta1 1 10010 2.1.0.10beta1 + * 1.0.10rc1 1 10010 2.1.0.10rc1 + * 1.0.10 1 10010 2.1.0.10 + * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 + * 1.0.11rc1 1 10011 2.1.0.11rc1 + * 1.0.11 1 10011 2.1.0.11 + * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 + * 1.0.12rc1 2 10012 2.1.0.12rc1 + * 1.0.12 2 10012 2.1.0.12 + * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) + * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 + * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 + * 1.2.0rc1 3 10200 3.1.2.0rc1 + * 1.2.0 3 10200 3.1.2.0 + * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4 + * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 + * 1.2.1 3 10201 3.1.2.1 + * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 + * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 + * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 + * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 + * 1.0.13 10 10013 10.so.0.1.0.13 + * 1.2.2 12 10202 12.so.0.1.2.2 + * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 + * 1.2.3 12 10203 12.so.0.1.2.3 + * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 + * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1 + * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 + * 1.0.14 10 10014 10.so.0.1.0.14 + * 1.2.4 13 10204 12.so.0.1.2.4 + * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 + * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3 + * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3 + * 1.0.15 10 10015 10.so.0.1.0.15 + * 1.2.5 13 10205 12.so.0.1.2.5 + * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 + * 1.0.16 10 10016 10.so.0.1.0.16 + * 1.2.6 13 10206 12.so.0.1.2.6 + * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 + * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 + * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 + * 1.0.17 10 10017 12.so.0.1.0.17 + * 1.2.7 13 10207 12.so.0.1.2.7 + * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 + * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 + * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 + * 1.0.18 10 10018 12.so.0.1.0.18 + * 1.2.8 13 10208 12.so.0.1.2.8 + * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 + * 1.2.9beta4-11 13 10209 12.so.0.9[.0] + * 1.2.9rc1 13 10209 12.so.0.9[.0] + * 1.2.9 13 10209 12.so.0.9[.0] + * 1.2.10beta1-8 13 10210 12.so.0.10[.0] + * 1.2.10rc1-3 13 10210 12.so.0.10[.0] + * 1.2.10 13 10210 12.so.0.10[.0] + * + * Henceforth the source version will match the shared-library major + * and minor numbers; the shared-library major version number will be + * used for changes in backward compatibility, as it is intended. The + * PNG_LIBPNG_VER macro, which is not used within libpng but is available + * for applications, is an unsigned integer of the form xyyzz corresponding + * to the source version x.y.z (leading zeros in y and z). Beta versions + * were given the previous public release number plus a letter, until + * version 1.0.6j; from then on they were given the upcoming public + * release number plus "betaNN" or "rcN". + * + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. + * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * + * See libpng.txt or libpng.3 for more information. The PNG specification + * is available as a W3C Recommendation and as an ISO Specification, + * defines should NOT be changed. + */ +#define PNG_INFO_gAMA 0x0001 +#define PNG_INFO_sBIT 0x0002 +#define PNG_INFO_cHRM 0x0004 +#define PNG_INFO_PLTE 0x0008 +#define PNG_INFO_tRNS 0x0010 +#define PNG_INFO_bKGD 0x0020 +#define PNG_INFO_hIST 0x0040 +#define PNG_INFO_pHYs 0x0080 +#define PNG_INFO_oFFs 0x0100 +#define PNG_INFO_tIME 0x0200 +#define PNG_INFO_pCAL 0x0400 +#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ +#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ +#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ +#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ +#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */ + +/* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using + * the routines for other purposes. + */ +typedef struct png_row_info_struct +{ + png_uint_32 width; /* width of row */ + png_uint_32 rowbytes; /* number of bytes in row */ + png_byte color_type; /* color type of row */ + png_byte bit_depth; /* bit depth of row */ + png_byte channels; /* number of channels (1, 2, 3, or 4) */ + png_byte pixel_depth; /* bits per pixel (depth * channels) */ +} png_row_info; + +typedef png_row_info FAR * png_row_infop; +typedef png_row_info FAR * FAR * png_row_infopp; + +/* These are the function types for the I/O functions and for the functions + * that allow the user to override the default I/O functions with his or her + * own. The png_error_ptr type should match that of user-supplied warning + * and error functions, while the png_rw_ptr type should match that of the + * user read/write data functions. + */ +typedef struct png_struct_def png_struct; +typedef png_struct FAR * png_structp; + +typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp)); +typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t)); +typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp)); +typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32, + int)); +typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32, + int)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop)); +typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop)); +typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep, + png_uint_32, int)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp, + png_row_infop, png_bytep)); +#endif + +#if defined(PNG_USER_CHUNKS_SUPPORTED) +typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp)); +#endif +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); +#endif + +/* Transform masks for the high-level interface */ +#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ +#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ +#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ +#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ +#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ +#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ +#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ +#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ +#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ +#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ +#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ +#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */ + +/* Flags for MNG supported features */ +#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 +#define PNG_FLAG_MNG_FILTER_64 0x04 +#define PNG_ALL_MNG_FEATURES 0x05 + +typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t)); +typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp)); + +/* The structure that holds the information to read and write PNG files. + * The only people who need to care about what is inside of this are the + * people who will be modifying the library for their own special needs. + * It should NOT be accessed directly by an application, except to store + * the jmp_buf. + */ + +struct png_struct_def +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf jmpbuf; /* used in png_error */ +#endif + png_error_ptr error_fn; /* function for printing errors and aborting */ + png_error_ptr warning_fn; /* function for printing warnings */ + png_voidp error_ptr; /* user supplied struct for error functions */ + png_rw_ptr write_data_fn; /* function for writing output data */ + png_rw_ptr read_data_fn; /* function for reading input data */ + png_voidp io_ptr; /* ptr to application struct for I/O functions */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + png_user_transform_ptr read_user_transform_fn; /* user read transform */ +#endif + +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + png_user_transform_ptr write_user_transform_fn; /* user write transform */ +#endif + +/* These were added in libpng-1.0.2 */ +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + png_voidp user_transform_ptr; /* user supplied struct for user transform */ + png_byte user_transform_depth; /* bit depth of user transformed pixels */ + png_byte user_transform_channels; /* channels in user transformed pixels */ +#endif +#endif + + png_uint_32 mode; /* tells us where we are in the PNG file */ + png_uint_32 flags; /* flags indicating various things to libpng */ + png_uint_32 transformations; /* which transformations to perform */ + + z_stream zstream; /* pointer to decompression structure (below) */ + png_bytep zbuf; /* buffer for zlib */ + png_size_t zbuf_size; /* size of zbuf */ + int zlib_level; /* holds zlib compression level */ + int zlib_method; /* holds zlib compression method */ + int zlib_window_bits; /* holds zlib compression window bits */ + int zlib_mem_level; /* holds zlib compression memory level */ + int zlib_strategy; /* holds zlib compression strategy */ + + png_uint_32 width; /* width of image in pixels */ + png_uint_32 height; /* height of image in pixels */ + png_uint_32 num_rows; /* number of rows in current pass */ + png_uint_32 usr_width; /* width of row at start of write */ + png_uint_32 rowbytes; /* size of row in bytes */ + png_uint_32 irowbytes; /* size of current interlaced row in bytes */ + png_uint_32 iwidth; /* width of current interlaced row in pixels */ + png_uint_32 row_number; /* current row in interlace pass */ + png_bytep prev_row; /* buffer to save previous (unfiltered) row */ + png_bytep row_buf; /* buffer to save current (unfiltered) row */ + png_bytep sub_row; /* buffer to save "sub" row when filtering */ + png_bytep up_row; /* buffer to save "up" row when filtering */ + png_bytep avg_row; /* buffer to save "avg" row when filtering */ + png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ + png_row_info row_info; /* used for transformation routines */ + + png_uint_32 idat_size; /* current IDAT size for read */ + png_uint_32 crc; /* current chunk CRC value */ + png_colorp palette; /* palette from the input file */ + png_uint_16 num_palette; /* number of color entries in palette */ + png_uint_16 num_trans; /* number of transparency values */ + png_byte chunk_name[5]; /* null-terminated name of current chunk */ + png_byte compression; /* file compression type (always 0) */ + png_byte filter; /* file filter type (always 0) */ + png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + png_byte pass; /* current interlace pass (0 - 6) */ + png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ + png_byte color_type; /* color type of file */ + png_byte bit_depth; /* bit depth of file */ + png_byte usr_bit_depth; /* bit depth of users row */ + png_byte pixel_depth; /* number of bits per pixel */ + png_byte channels; /* number of channels in file */ + png_byte usr_channels; /* channels at start of write */ + png_byte sig_bytes; /* magic bytes read/written from start of file */ + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +#ifdef PNG_LEGACY_SUPPORTED + png_byte filler; /* filler byte for pixel expansion */ +#else + png_uint_16 filler; /* filler bytes for pixel expansion */ +#endif +#endif + +#if defined(PNG_bKGD_SUPPORTED) + png_byte background_gamma_type; +# ifdef PNG_FLOATING_POINT_SUPPORTED + float background_gamma; +# endif + png_color_16 background; /* background color in screen gamma space */ +#if defined(PNG_READ_GAMMA_SUPPORTED) + png_color_16 background_1; /* background normalized to gamma 1.0 */ +#endif +#endif /* PNG_bKGD_SUPPORTED */ + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) + png_flush_ptr output_flush_fn;/* Function for flushing output */ + png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ + png_uint_32 flush_rows; /* number of rows written since last flush */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + int gamma_shift; /* number of "insignificant" bits 16-bit gamma */ +#ifdef PNG_FLOATING_POINT_SUPPORTED + float gamma; /* file gamma value */ + float screen_gamma; /* screen gamma value (display_exponent) */ +#endif +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep gamma_table; /* gamma table for 8-bit depth files */ + png_bytep gamma_from_1; /* converts from 1.0 to screen */ + png_bytep gamma_to_1; /* converts from file to 1.0 */ + png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ + png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ + png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) + png_color_8 sig_bit; /* significant bits in each available channel */ +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) + png_color_8 shift; /* shift for significant bit tranformation */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ + || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep trans; /* transparency values for paletted files */ + png_color_16 trans_values; /* transparency values for non-paletted files */ +#endif + + png_read_status_ptr read_row_fn; /* called after each row is decoded */ + png_write_status_ptr write_row_fn; /* called after each row is encoded */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_progressive_info_ptr info_fn; /* called after header data fully read */ + png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */ + png_progressive_end_ptr end_fn; /* called after image is complete */ + png_bytep save_buffer_ptr; /* current location in save_buffer */ + png_bytep save_buffer; /* buffer for previously read data */ + png_bytep current_buffer_ptr; /* current location in current_buffer */ + png_bytep current_buffer; /* buffer for recently used data */ + png_uint_32 push_length; /* size of current input chunk */ + png_uint_32 skip_length; /* bytes to skip in input data */ + png_size_t save_buffer_size; /* amount of data now in save_buffer */ + png_size_t save_buffer_max; /* total size of save_buffer */ + png_size_t buffer_size; /* total amount of available input data */ + png_size_t current_buffer_size; /* amount of data now in current_buffer */ + int process_mode; /* what push library is currently doing */ + int cur_palette; /* current push library palette index */ + +# if defined(PNG_TEXT_SUPPORTED) + png_size_t current_text_size; /* current size of text input data */ + png_size_t current_text_left; /* how much text left to read in input */ + png_charp current_text; /* current text chunk buffer */ + png_charp current_text_ptr; /* current location in current_text */ +# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */ + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* for the Borland special 64K segment handler */ + png_bytepp offset_table_ptr; + png_bytep offset_table; + png_uint_16 offset_table_number; + png_uint_16 offset_table_count; + png_uint_16 offset_table_count_free; +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) + png_bytep palette_lookup; /* lookup table for dithering */ + png_bytep dither_index; /* index translation for palette files */ +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED) + png_uint_16p hist; /* histogram */ +#endif + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + png_byte heuristic_method; /* heuristic for row filter selection */ + png_byte num_prev_filters; /* number of weights for previous rows */ + png_bytep prev_filters; /* filter type(s) of previous row(s) */ + png_uint_16p filter_weights; /* weight(s) for previous line(s) */ + png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ + png_uint_16p filter_costs; /* relative filter calculation cost */ + png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ +#endif + +#if defined(PNG_TIME_RFC1123_SUPPORTED) + png_charp time_buffer; /* String to hold RFC 1123 time text */ +#endif + +/* New members added in libpng-1.0.6 */ + +#ifdef PNG_FREE_ME_SUPPORTED + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ +#endif + +#if defined(PNG_USER_CHUNKS_SUPPORTED) + png_voidp user_chunk_ptr; + png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ +#endif + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + int num_chunk_list; + png_bytep chunk_list; +#endif + +/* New members added in libpng-1.0.3 */ +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_byte rgb_to_gray_status; + /* These were changed from png_byte in libpng-1.0.6 */ + png_uint_16 rgb_to_gray_red_coeff; + png_uint_16 rgb_to_gray_green_coeff; + png_uint_16 rgb_to_gray_blue_coeff; +#endif + +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ + defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +/* changed from png_byte to png_uint_32 at version 1.2.0 */ +#ifdef PNG_1_0_X + png_byte mng_features_permitted; +#else + png_uint_32 mng_features_permitted; +#endif /* PNG_1_0_X */ +#endif + +/* New member added in libpng-1.0.7 */ +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_fixed_point int_gamma; +#endif + +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) + png_byte filter_type; +#endif + +#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD)) +/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */ + png_uint_32 row_buf_size; +#endif + +/* New members added in libpng-1.2.0 */ +#if !defined(PNG_1_0_X) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) + png_byte mmx_bitdepth_threshold; + png_uint_32 mmx_rowbytes_threshold; + png_uint_32 asm_flags; +#endif + +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +#ifdef PNG_USER_MEM_SUPPORTED + png_voidp mem_ptr; /* user supplied struct for mem functions */ + png_malloc_ptr malloc_fn; /* function for allocating memory */ + png_free_ptr free_fn; /* function for freeing memory */ +#endif + +/* New member added in libpng-1.0.13 and 1.2.0 */ + png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ + +#if defined(PNG_READ_DITHER_SUPPORTED) +/* The following three members were added at version 1.0.14 and 1.2.4 */ + png_bytep dither_sort; /* working sort array */ + png_bytep index_to_palette; /* where the original index currently is */ + /* in the palette */ + png_bytep palette_to_index; /* which original index points to this */ + /* palette color */ +#endif + +/* New members added in libpng-1.0.16 and 1.2.6 */ + png_byte compression_type; + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_uint_32 user_width_max; + png_uint_32 user_height_max; +#endif + +}; + + +/* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +typedef png_structp version_1_2_10; + +typedef png_struct FAR * FAR * png_structpp; + +/* Here are the function definitions most commonly used. This is not + * the place to find out how to use libpng. See libpng.txt for the + * full explanation, see example.c for the summary. This just provides + * a simple one line description of the use of each function. + */ + +/* Returns the version number of the library */ +extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void)); + +/* Tell lib we have already handled the first magic bytes. + * Handling more than 8 bytes from the beginning of the file is an error. + */ +extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, + int num_bytes)); + +/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a + * PNG file. Returns zero if the supplied bytes match the 8-byte PNG + * signature, and non-zero otherwise. Having num_to_check == 0 or + * start > 7 will always fail (ie return non-zero). + */ +extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, + png_size_t num_to_check)); + +/* Simple signature checking function. This is the same as calling + * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). + */ +extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num)); + +/* Allocate and initialize png_ptr struct for reading, and any other memory. */ +extern PNG_EXPORT(png_structp,png_create_read_struct) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn)); + +/* Allocate and initialize png_ptr struct for writing, and any other memory */ +extern PNG_EXPORT(png_structp,png_create_write_struct) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn)); + +#ifdef PNG_WRITE_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size) + PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_WRITE_SUPPORTED +extern PNG_EXPORT(void,png_set_compression_buffer_size) + PNGARG((png_structp png_ptr, png_uint_32 size)); +#endif + +/* Reset the compression stream */ +extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); + +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ +#ifdef PNG_USER_MEM_SUPPORTED +extern PNG_EXPORT(png_structp,png_create_read_struct_2) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +extern PNG_EXPORT(png_structp,png_create_write_struct_2) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +#endif + +/* Write a PNG chunk - size, type, (optional) data, CRC. */ +extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, + png_bytep chunk_name, png_bytep data, png_size_t length)); + +/* Write the start of a PNG chunk - length and chunk name. */ +extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr, + png_bytep chunk_name, png_uint_32 length)); + +/* Write the data of a PNG chunk started with png_write_chunk_start(). */ +extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ +extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); + +/* Allocate and initialize the info structure */ +extern PNG_EXPORT(png_infop,png_create_info_struct) + PNGARG((png_structp png_ptr)); + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize the info structure (old interface - DEPRECATED) */ +extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)); +#undef png_info_init +#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\ + png_sizeof(png_info)); +#endif + +extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, + png_size_t png_info_struct_size)); + +/* Writes all the PNG information before the image. */ +extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* read the information before the actual image data. */ +extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +#if defined(PNG_TIME_RFC1123_SUPPORTED) +extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) + PNGARG((png_structp png_ptr, png_timep ptime)); +#endif + +#if !defined(_WIN32_WCE) +/* "time.h" functions are not supported on WindowsCE */ +#if defined(PNG_WRITE_tIME_SUPPORTED) +/* convert from a struct tm to png_time */ +extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, + struct tm FAR * ttime)); + +/* convert from time_t to png_time. Uses gmtime() */ +extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, + time_t ttime)); +#endif /* PNG_WRITE_tIME_SUPPORTED */ +#endif /* _WIN32_WCE */ + +#if defined(PNG_READ_EXPAND_SUPPORTED) +/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ +extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); +#if !defined(PNG_1_0_X) +extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp + png_ptr)); +#endif +extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated */ +extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); +#endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Use blue, green, red order for pixels. */ +extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) +/* Expand the grayscale to 24-bit RGB if necessary. */ +extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +/* Reduce RGB to grayscale. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr, + int error_action, double red, double green )); +#endif +extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green )); +extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp + png_ptr)); +#endif + +extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth, + png_colorp palette)); + +#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ +extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, + png_uint_32 filler, int flags)); +/* The values of the PNG_FILLER_ defines should NOT be changed */ +#define PNG_FILLER_BEFORE 0 +#define PNG_FILLER_AFTER 1 +/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ +#if !defined(PNG_1_0_X) +extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr, + png_uint_32 filler, int flags)); +#endif +#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swap bytes in 16-bit depth files. */ +extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ +extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Swap packing order of pixels in bytes. */ +extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Converts files to legal bit depths. */ +extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr, + png_color_8p true_bits)); +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Have the code handle the interlacing. Returns the number of passes. */ +extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +/* Invert monochrome files */ +extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) +/* Handle alpha and tRNS by replacing with a background color. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, + png_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma)); +#endif +#define PNG_BACKGROUND_GAMMA_UNKNOWN 0 +#define PNG_BACKGROUND_GAMMA_SCREEN 1 +#define PNG_BACKGROUND_GAMMA_FILE 2 +#define PNG_BACKGROUND_GAMMA_UNIQUE 3 +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) +/* strip the second byte of information from a 16-bit depth file. */ +extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) +/* Turn on dithering, and reduce the palette to the number of colors available. */ +extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette, int maximum_colors, + png_uint_16p histogram, int full_dither)); +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) +/* Handle gamma correction. Screen_gamma=(display_exponent) */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, + double screen_gamma, double default_file_gamma)); +#endif +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */ +/* Deprecated and will be removed. Use png_permit_mng_features() instead. */ +extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr, + int empty_plte_permitted)); +#endif +#endif + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +/* Set how many lines between output flushes - 0 for no flushing */ +extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows)); +/* Flush the current PNG output buffer */ +extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr)); +#endif + +/* optional update palette with requested transformations */ +extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); + +/* optional call to update the users info structure */ +extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* read one or more rows of image data. */ +extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, + png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); +#endif + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* read a row of data. */ +extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, + png_bytep row, + png_bytep display_row)); +#endif + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* read the whole image into memory at once. */ +extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, + png_bytepp image)); +#endif + +/* write a row of image data */ +extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr, + png_bytep row)); + +/* write a few rows of image data */ +extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, + png_bytepp row, png_uint_32 num_rows)); + +/* write the image data */ +extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, + png_bytepp image)); + +/* writes the end of the PNG file. */ +extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* read the end of the PNG file. */ +extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +/* free any memory associated with the png_info_struct */ +extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr, + png_infopp info_ptr_ptr)); + +/* free any memory associated with the png_struct and the png_info_structs */ +extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp + png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); + +/* free all memory used by the read (old method - NOT DLL EXPORTED) */ +extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr, + png_infop end_info_ptr)); + +/* free any memory associated with the png_struct and the png_info_structs */ +extern PNG_EXPORT(void,png_destroy_write_struct) + PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); + +/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ +extern void png_write_destroy PNGARG((png_structp png_ptr)); + +/* set the libpng method of handling chunk CRC errors */ +extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, + int crit_action, int ancil_action)); + +/* Values for png_set_crc_action() to say how to handle CRC errors in + * ancillary and critical chunks, and whether to use the data contained + * therein. Note that it is impossible to "discard" data in a critical + * chunk. For versions prior to 0.90, the action was always error/quit, + * whereas in version 0.90 and later, the action for CRC errors in ancillary + * chunks is warn/discard. These values should NOT be changed. + * + * value action:critical action:ancillary + */ +#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ +#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ +#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ +#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ +#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ +#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ + +/* These functions give the user control over the scan-line filtering in + * libpng and the compression methods used by zlib. These functions are + * mainly useful for testing, as the defaults should work with most users. + * Those users who are tight on memory or want faster performance at the + * expense of compression can modify them. See the compression library + * header file (zlib.h) for an explination of the compression functions. + */ + +/* set the filtering method(s) used by libpng. Currently, the only valid + * value for "method" is 0. + */ +extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, + int filters)); + +/* Flags for png_set_filter() to say which filters to use. The flags + * are chosen so that they don't conflict with real filter types + * below, in case they are supplied instead of the #defined constants. + * These values should NOT be changed. + */ +#define PNG_NO_FILTERS 0x00 +#define PNG_FILTER_NONE 0x08 +#define PNG_FILTER_SUB 0x10 +#define PNG_FILTER_UP 0x20 +#define PNG_FILTER_AVG 0x40 +#define PNG_FILTER_PAETH 0x80 +#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ + PNG_FILTER_AVG | PNG_FILTER_PAETH) + +/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. + * These defines should NOT be changed. + */ +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_LAST 5 + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */ +/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ + * defines, either the default (minimum-sum-of-absolute-differences), or + * the experimental method (weighted-minimum-sum-of-absolute-differences). + * + * Weights are factors >= 1.0, indicating how important it is to keep the + * filter type consistent between rows. Larger numbers mean the current + * filter is that many times as likely to be the same as the "num_weights" + * previous filters. This is cumulative for each previous row with a weight. + * There needs to be "num_weights" values in "filter_weights", or it can be + * NULL if the weights aren't being specified. Weights have no influence on + * the selection of the first row filter. Well chosen weights can (in theory) + * improve the compression for a given image. + * + * Costs are factors >= 1.0 indicating the relative decoding costs of a + * filter type. Higher costs indicate more decoding expense, and are + * therefore less likely to be selected over a filter with lower computational + * costs. There needs to be a value in "filter_costs" for each valid filter + * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't + * setting the costs. Costs try to improve the speed of decompression without + * unduly increasing the compressed image size. + * + * A negative weight or cost indicates the default value is to be used, and + * values in the range [0.0, 1.0) indicate the value is to remain unchanged. + * The default values for both weights and costs are currently 1.0, but may + * change if good general weighting/cost heuristics can be found. If both + * the weights and costs are set to 1.0, this degenerates the WEIGHTED method + * to the UNWEIGHTED method, but with added encoding time/computation. + */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, + int heuristic_method, int num_weights, png_doublep filter_weights, + png_doublep filter_costs)); +#endif +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +/* Heuristic used for row filter selection. These defines should NOT be + * changed. + */ +#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ +#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ +#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ +#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ + +/* Set the library compression level. Currently, valid values range from + * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 + * (0 - no compression, 9 - "maximal" compression). Note that tests have + * shown that zlib compression levels 3-6 usually perform as well as level 9 + * for PNG images, and do considerably fewer caclulations. In the future, + * these values may not correspond directly to the zlib compression levels. + */ +extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr, + int level)); + +extern PNG_EXPORT(void,png_set_compression_mem_level) + PNGARG((png_structp png_ptr, int mem_level)); + +extern PNG_EXPORT(void,png_set_compression_strategy) + PNGARG((png_structp png_ptr, int strategy)); + +extern PNG_EXPORT(void,png_set_compression_window_bits) + PNGARG((png_structp png_ptr, int window_bits)); + +extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, + int method)); + +/* These next functions are called for input/output, memory, and error + * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, + * and call standard C I/O routines such as fread(), fwrite(), and + * fprintf(). These functions can be made to use other I/O routines + * at run time for those applications that need to handle I/O in a + * different manner by calling png_set_???_fn(). See libpng.txt for + * more information. + */ + +#if !defined(PNG_NO_STDIO) +/* Initialize the input/output for the PNG file to the default functions. */ +extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)); +#endif + +/* Replace the (error and abort), and warning functions with user + * supplied functions. If no messages are to be printed you must still + * write and use replacement functions. The replacement error_fn should + * still do a longjmp to the last setjmp location if you are using this + * method of error handling. If error_fn or warning_fn is NULL, the + * default function will be used. + */ + +extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); + +/* Return the user pointer associated with the error functions */ +extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr)); + +/* Replace the default data output functions with a user supplied one(s). + * If buffered output is not used, then output_flush_fn can be set to NULL. + * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time + * output_flush_fn will be ignored (and thus can be NULL). + */ +extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr, + png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); + +/* Replace the default data input function with a user supplied one. */ +extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr, + png_voidp io_ptr, png_rw_ptr read_data_fn)); + +/* Return the user pointer associated with the I/O functions */ +extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr)); + +extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr, + png_read_status_ptr read_row_fn)); + +extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, + png_write_status_ptr write_row_fn)); + +#ifdef PNG_USER_MEM_SUPPORTED +/* Replace the default memory allocation functions with user supplied one(s). */ +extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +/* Return the user pointer associated with the memory functions */ +extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp + png_ptr, png_user_transform_ptr read_user_transform_fn)); +#endif + +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp + png_ptr, png_user_transform_ptr write_user_transform_fn)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp + png_ptr, png_voidp user_transform_ptr, int user_transform_depth, + int user_transform_channels)); +/* Return the user pointer associated with the user transform functions */ +extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr) + PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); +extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp + png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +/* Sets the function callbacks for the push reader, and a pointer to a + * user-defined structure available to the callback functions. + */ +extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr, + png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn)); + +/* returns the user pointer associated with the push read functions */ +extern PNG_EXPORT(png_voidp,png_get_progressive_ptr) + PNGARG((png_structp png_ptr)); + +/* function to be called when data becomes available */ +extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); + +/* function that combines rows. Not very much different than the + * png_combine_row() call. Is this even used????? + */ +extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, + png_bytep old_row, png_bytep new_row)); +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, + png_uint_32 size)); + +#if defined(PNG_1_0_X) +# define png_malloc_warn png_malloc +#else +/* Added at libpng version 1.2.4 */ +extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr, + png_uint_32 size)); +#endif + +/* frees a pointer allocated by png_malloc() */ +extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); + +#if defined(PNG_1_0_X) +/* Function to allocate memory for zlib. */ +extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items, + uInt size)); + +/* Function to free memory for zlib */ +extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr)); +#endif + +/* Free data that was allocated internally */ +extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 free_me, int num)); +#ifdef PNG_FREE_ME_SUPPORTED +/* Reassign responsibility for freeing existing data, whether allocated + * by libpng or by the application */ +extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, + png_infop info_ptr, int freer, png_uint_32 mask)); +#endif +/* assignments for png_data_freer */ +#define PNG_DESTROY_WILL_FREE_DATA 1 +#define PNG_SET_WILL_FREE_DATA 1 +#define PNG_USER_WILL_FREE_DATA 2 +/* Flags for png_ptr->free_me and info_ptr->free_me */ +#define PNG_FREE_HIST 0x0008 +#define PNG_FREE_ICCP 0x0010 +#define PNG_FREE_SPLT 0x0020 +#define PNG_FREE_ROWS 0x0040 +#define PNG_FREE_PCAL 0x0080 +#define PNG_FREE_SCAL 0x0100 +#define PNG_FREE_UNKN 0x0200 +#define PNG_FREE_LIST 0x0400 +#define PNG_FREE_PLTE 0x1000 +#define PNG_FREE_TRNS 0x2000 +#define PNG_FREE_TEXT 0x4000 +#define PNG_FREE_ALL 0x7fff +#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ + +#ifdef PNG_USER_MEM_SUPPORTED +extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, + png_uint_32 size)); +extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, + png_voidp ptr)); +#endif + +extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr, + png_voidp s1, png_voidp s2, png_uint_32 size)); + +extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr, + png_voidp s1, int value, png_uint_32 size)); + +#if defined(USE_FAR_KEYWORD) /* memory model conversion function */ +extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, + int check)); +#endif /* USE_FAR_KEYWORD */ + +/* Fatal error in PNG image of libpng - can't continue */ +extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, + png_const_charp error_message)); + +/* The same, but the chunk name is prepended to the error string. */ +extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, + png_const_charp error_message)); + +/* Non-fatal error in libpng. Can continue, but may have a problem. */ +extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, + png_const_charp warning_message)); + +/* Non-fatal error in libpng, chunk name is prepended to message. */ +extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, + png_const_charp warning_message)); + +/* The png_set_ functions are for storing values in the png_info_struct. + * Similarly, the png_get_ calls are used to read values from the + * png_info_struct, either storing the parameters in the passed variables, or + * setting pointers into the png_info_struct where the data is stored. The + * png_get_ functions return a non-zero value if the data was available + * in info_ptr, or return zero and do not change any of the parameters if the + * data was not available. + * + * These functions should be used instead of directly accessing png_info + * to avoid problems with future changes in the size and internal layout of + * png_info_struct. + */ +/* Returns "flag" if chunk data is valid in info_ptr. */ +extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr, +png_infop info_ptr, png_uint_32 flag)); + +/* Returns number of bytes needed to hold a transformed row. */ +extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +/* Returns row_pointers, which is an array of pointers to scanlines that was +returned from png_read_png(). */ +extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr, +png_infop info_ptr)); +/* Set row_pointers, which is an array of pointers to scanlines for use +by png_write_png(). */ +extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytepp row_pointers)); +#endif + +/* Returns number of color channels in image. */ +extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Returns image width in pixels. */ +extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image height in pixels. */ +extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image bit_depth. */ +extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image color_type. */ +extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image filter_type. */ +extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image interlace_type. */ +extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image compression_type. */ +extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image resolution in pixels per meter, from pHYs chunk data. */ +extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns pixel aspect ratio, computed from pHYs chunk data. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +#endif + +/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ +extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +/* Returns pointer to signature string read from PNG header */ +extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#if defined(PNG_bKGD_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_16p *background)); +#endif + +#if defined(PNG_bKGD_SUPPORTED) +extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_16p background)); +#endif + +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, double *white_x, double *white_y, double *red_x, + double *red_y, double *green_x, double *green_y, double *blue_x, + double *blue_y)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point + *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point + *int_blue_x, png_fixed_point *int_blue_y)); +#endif +#endif + +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, double white_x, double white_y, double red_x, + double red_y, double green_x, double green_y, double blue_x, double blue_y)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)); +#endif +#endif + +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, + png_infop info_ptr, double *file_gamma)); +#endif +extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point *int_file_gamma)); +#endif + +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, + png_infop info_ptr, double file_gamma)); +#endif +extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_file_gamma)); +#endif + +#if defined(PNG_hIST_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_16p *hist)); +#endif + +#if defined(PNG_hIST_SUPPORTED) +extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_16p hist)); +#endif + +extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); + +extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_method, int compression_method, + int filter_method)); + +#if defined(PNG_oFFs_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); +#endif + +#if defined(PNG_oFFs_SUPPORTED) +extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, + int unit_type)); +#endif + +#if defined(PNG_pCAL_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, + int *type, int *nparams, png_charp *units, png_charpp *params)); +#endif + +#if defined(PNG_pCAL_SUPPORTED) +extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, + int type, int nparams, png_charp units, png_charpp params)); +#endif + +#if defined(PNG_pHYs_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif + +#if defined(PNG_pHYs_SUPPORTED) +extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +#endif + +extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_colorp *palette, int *num_palette)); + +extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_colorp palette, int num_palette)); + +#if defined(PNG_sBIT_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_8p *sig_bit)); +#endif + +#if defined(PNG_sBIT_SUPPORTED) +extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_8p sig_bit)); +#endif + +#if defined(PNG_sRGB_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *intent)); +#endif + +#if defined(PNG_sRGB_SUPPORTED) +extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr, + png_infop info_ptr, int intent)); +extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, int intent)); +#endif + +#if defined(PNG_iCCP_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charpp name, int *compression_type, + png_charpp profile, png_uint_32 *proflen)); + /* Note to maintainer: profile should be png_bytepp */ +#endif + +#if defined(PNG_iCCP_SUPPORTED) +extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp name, int compression_type, + png_charp profile, png_uint_32 proflen)); + /* Note to maintainer: profile should be png_bytep */ +#endif + +#if defined(PNG_sPLT_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_sPLT_tpp entries)); +#endif + +#if defined(PNG_sPLT_SUPPORTED) +extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_sPLT_tp entries, int nentries)); +#endif + +#if defined(PNG_TEXT_SUPPORTED) +/* png_get_text also returns the number of text chunks in *num_text */ +extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp *text_ptr, int *num_text)); +#endif + +/* + * Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. + */ + +#if defined(PNG_TEXT_SUPPORTED) +extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp text_ptr, int num_text)); +#endif + +#if defined(PNG_tIME_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_timep *mod_time)); +#endif + +#if defined(PNG_tIME_SUPPORTED) +extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_timep mod_time)); +#endif + +#if defined(PNG_tRNS_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep *trans, int *num_trans, + png_color_16p *trans_values)); +#endif + +#if defined(PNG_tRNS_SUPPORTED) +extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep trans, int num_trans, + png_color_16p trans_values)); +#endif + +#if defined(PNG_tRNS_SUPPORTED) +#endif + +#if defined(PNG_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *unit, double *width, double *height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); +#endif +#endif +#endif /* PNG_sCAL_SUPPORTED */ + +#if defined(PNG_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, int unit, double width, double height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, + png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); +#endif +#endif +#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +/* provide a list of chunks and how they are to be handled, if the built-in + handling or default unknown chunk handling is not desired. Any chunks not + listed will be handled in the default manner. The IHDR and IEND chunks + must not be listed. + keep = 0: follow default behavour + = 1: do not keep + = 2: keep only if safe-to-copy + = 3: keep even if unsafe-to-copy +*/ +extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp + png_ptr, int keep, png_bytep chunk_list, int num_chunks)); +extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)); +extern PNG_EXPORT(void, png_set_unknown_chunk_location) + PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location)); +extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp + png_ptr, png_infop info_ptr, png_unknown_chunkpp entries)); +#endif +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep + chunk_name)); +#endif + +/* Png_free_data() will turn off the "valid" flag for anything it frees. + If you need to turn it off for a chunk that your application has freed, + you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */ +extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr, + png_infop info_ptr, int mask)); + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +/* The "params" pointer is currently not used and is for future expansion. */ +extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr, + png_infop info_ptr, + int transforms, + png_voidp params)); +extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, + png_infop info_ptr, + int transforms, + png_voidp params)); +#endif + +/* Define PNG_DEBUG at compile time for debugging information. Higher + * numbers for PNG_DEBUG mean more debugging information. This has + * only been added since version 0.95 so it is not implemented throughout + * libpng yet, but more support will be added as needed. + */ +#ifdef PNG_DEBUG +#if (PNG_DEBUG > 0) +#if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) +#include +#if (PNG_DEBUG > 1) +#define png_debug(l,m) _RPT0(_CRT_WARN,m) +#define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1) +#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2) +#endif +#else /* PNG_DEBUG_FILE || !_MSC_VER */ +#ifndef PNG_DEBUG_FILE +#define PNG_DEBUG_FILE stderr +#endif /* PNG_DEBUG_FILE */ +#if (PNG_DEBUG > 1) +#define png_debug(l,m) \ +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ +} +#define png_debug1(l,m,p1) \ +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ +} +#define png_debug2(l,m,p1,p2) \ +{ \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ +} +#endif /* (PNG_DEBUG > 1) */ +#endif /* _MSC_VER */ +#endif /* (PNG_DEBUG > 0) */ +#endif /* PNG_DEBUG */ +#ifndef png_debug +#define png_debug(l, m) +#endif +#ifndef png_debug1 +#define png_debug1(l, m, p1) +#endif +#ifndef png_debug2 +#define png_debug2(l, m, p1, p2) +#endif + +#if 0 +extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void)); +#endif + +extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); + +#ifdef PNG_MNG_FEATURES_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp + png_ptr, png_uint_32 mng_features_permitted)); +#endif + +/* For use in png_set_keep_unknown, added to version 1.2.6 */ +#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 +#define PNG_HANDLE_CHUNK_NEVER 1 +#define PNG_HANDLE_CHUNK_IF_SAFE 2 +#define PNG_HANDLE_CHUNK_ALWAYS 3 + +/* Added to version 1.2.0 */ +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04 +#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08 +#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10 +#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20 +#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40 +#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80 +#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */ + +#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ + | PNG_ASM_FLAG_MMX_READ_INTERLACE \ + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ) +#define PNG_MMX_WRITE_FLAGS ( 0 ) + +#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \ + | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \ + | PNG_MMX_READ_FLAGS \ + | PNG_MMX_WRITE_FLAGS ) + +#define PNG_SELECT_READ 1 +#define PNG_SELECT_WRITE 2 + +#if !defined(PNG_1_0_X) +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask) + PNGARG((int flag_select, int *compilerID)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask) + PNGARG((int flag_select)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flags) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold) + PNGARG((png_structp png_ptr)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_asm_flags) + PNGARG((png_structp png_ptr, png_uint_32 asm_flags)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_mmx_thresholds) + PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold)); + +#endif /* PNG_1_0_X */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ + +#if !defined(PNG_1_0_X) +/* png.c, pnggccrd.c, or pngvcrd.c */ +extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp + png_ptr, png_uint_32 strip_mode)); +#endif + +#endif /* PNG_1_0_X */ + +/* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp + png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); +extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp + png_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp + png_ptr)); +#endif + +/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */ + +#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +/* With these routines we avoid an integer divide, which will be slower on + * most machines. However, it does take more operations than the corresponding + * divide method, so it may be slower on a few RISC systems. There are two + * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] + */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ + +# define png_composite(composite, fg, alpha, bg) \ + { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \ + + (png_uint_16)(bg)*(png_uint_16)(255 - \ + (png_uint_16)(alpha)) + (png_uint_16)128); \ + (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } + +# define png_composite_16(composite, fg, alpha, bg) \ + { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \ + + (png_uint_32)(bg)*(png_uint_32)(65535L - \ + (png_uint_32)(alpha)) + (png_uint_32)32768L); \ + (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } + +#else /* standard method using integer division */ + +# define png_composite(composite, fg, alpha, bg) \ + (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + (png_uint_16)127) / 255) + +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ + (png_uint_32)32767) / (png_uint_32)65535L) + +#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ + +/* Inline macros to do direct reads of bytes from the input buffer. These + * require that you are using an architecture that uses PNG byte ordering + * (MSB first) and supports unaligned data storage. I think that PowerPC + * in big-endian mode and 680x0 are the only ones that will support this. + * The x86 line of processors definitely do not. The png_get_int_32() + * routine also assumes we are using two's complement format for negative + * values, which is almost certainly true. + */ +#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED) +# define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) +# define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) +# define png_get_int_32(buf) ( *((png_int_32p) (buf))) +#else +extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf)); +extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf)); +extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf)); +#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ +extern PNG_EXPORT(png_uint_32,png_get_uint_31) + PNGARG((png_structp png_ptr, png_bytep buf)); +/* No png_get_int_16 -- may be added if there's a real need for it. */ + +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). + */ +extern PNG_EXPORT(void,png_save_uint_32) + PNGARG((png_bytep buf, png_uint_32 i)); +extern PNG_EXPORT(void,png_save_int_32) + PNGARG((png_bytep buf, png_int_32 i)); + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +extern PNG_EXPORT(void,png_save_uint_16) + PNGARG((png_bytep buf, unsigned int i)); +/* No png_save_int_16 -- may be added if there's a real need for it. */ + +/* ************************************************************************* */ + +/* These next functions are used internally in the code. They generally + * shouldn't be used unless you are writing code to add or replace some + * functionality in libpng. More information about most functions can + * be found in the files where the functions are located. + */ + +#if defined(PNG_INTERNAL) + +/* Various modes of operation. Note that after an init, mode is set to + * zero automatically when the structure is created. + */ +#define PNG_HAVE_IHDR 0x01 +#define PNG_HAVE_PLTE 0x02 +#define PNG_HAVE_IDAT 0x04 +#define PNG_AFTER_IDAT 0x08 +#define PNG_HAVE_IEND 0x10 +#define PNG_HAVE_gAMA 0x20 +#define PNG_HAVE_cHRM 0x40 +#define PNG_HAVE_sRGB 0x80 +#define PNG_HAVE_CHUNK_HEADER 0x100 +#define PNG_WROTE_tIME 0x200 +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 +#define PNG_BACKGROUND_IS_GRAY 0x800 +#define PNG_HAVE_PNG_SIGNATURE 0x1000 + +/* flags for the transformations the PNG library does on the image data */ +#define PNG_BGR 0x0001 +#define PNG_INTERLACE 0x0002 +#define PNG_PACK 0x0004 +#define PNG_SHIFT 0x0008 +#define PNG_SWAP_BYTES 0x0010 +#define PNG_INVERT_MONO 0x0020 +#define PNG_DITHER 0x0040 +#define PNG_BACKGROUND 0x0080 +#define PNG_BACKGROUND_EXPAND 0x0100 + /* 0x0200 unused */ +#define PNG_16_TO_8 0x0400 +#define PNG_RGBA 0x0800 +#define PNG_EXPAND 0x1000 +#define PNG_GAMMA 0x2000 +#define PNG_GRAY_TO_RGB 0x4000 +#define PNG_FILLER 0x8000L +#define PNG_PACKSWAP 0x10000L +#define PNG_SWAP_ALPHA 0x20000L +#define PNG_STRIP_ALPHA 0x40000L +#define PNG_INVERT_ALPHA 0x80000L +#define PNG_USER_TRANSFORM 0x100000L +#define PNG_RGB_TO_GRAY_ERR 0x200000L +#define PNG_RGB_TO_GRAY_WARN 0x400000L +#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ + /* 0x800000L Unused */ +#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ + /* 0x4000000L unused */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +/* flags for png_create_struct */ +#define PNG_STRUCT_PNG 0x0001 +#define PNG_STRUCT_INFO 0x0002 + +/* Scaling factor for filter heuristic weighting calculations */ +#define PNG_WEIGHT_SHIFT 8 +#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) +#define PNG_COST_SHIFT 3 +#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) + +/* flags for the png_ptr->flags rather than declaring a byte for each one */ +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 +#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 +#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 +#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 +#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 +#define PNG_FLAG_ZLIB_FINISHED 0x0020 +#define PNG_FLAG_ROW_INIT 0x0040 +#define PNG_FLAG_FILLER_AFTER 0x0080 +#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 +#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 +#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 +#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 +#define PNG_FLAG_FREE_PLTE 0x1000 +#define PNG_FLAG_FREE_TRNS 0x2000 +#define PNG_FLAG_FREE_HIST 0x4000 +#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L +#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L +#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L +#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */ +#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */ + /* 0x800000L unused */ + /* 0x1000000L unused */ + /* 0x2000000L unused */ + /* 0x4000000L unused */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ + PNG_FLAG_CRC_ANCILLARY_NOWARN) + +#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ + PNG_FLAG_CRC_CRITICAL_IGNORE) + +#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ + PNG_FLAG_CRC_CRITICAL_MASK) + +/* save typing and make code easier to understand */ + +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ + abs((int)((c1).green) - (int)((c2).green)) + \ + abs((int)((c1).blue) - (int)((c2).blue))) + +/* Added to libpng-1.2.6 JB */ +#define PNG_ROWBYTES(pixel_bits, width) \ + ((pixel_bits) >= 8 ? \ + ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \ + (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) ) + +/* PNG_OUT_OF_RANGE returns true if value is outside the range + ideal-delta..ideal+delta. Each argument is evaluated twice. + "ideal" and "delta" should be constants, normally simple + integers, "value" a variable. Added to libpng-1.2.6 JB */ +#define PNG_OUT_OF_RANGE(value, ideal, delta) \ + ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) + +/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */ +#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) +/* place to hold the signature string for a PNG file. */ +#ifdef PNG_USE_GLOBAL_ARRAYS + PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8]; +#else +#if 0 +#define png_sig png_sig_bytes(NULL) +#endif +#endif +#endif /* PNG_NO_EXTERN */ + +/* Constant strings for known chunk types. If you need to add a chunk, + * define the name here, and add an invocation of the macro in png.c and + * wherever it's needed. + */ +#define PNG_IHDR const png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} +#define PNG_IDAT const png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} +#define PNG_IEND const png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} +#define PNG_PLTE const png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} +#define PNG_bKGD const png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} +#define PNG_cHRM const png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} +#define PNG_gAMA const png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} +#define PNG_hIST const png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} +#define PNG_iCCP const png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} +#define PNG_iTXt const png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} +#define PNG_oFFs const png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} +#define PNG_pCAL const png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} +#define PNG_sCAL const png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} +#define PNG_pHYs const png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} +#define PNG_sBIT const png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} +#define PNG_sPLT const png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} +#define PNG_sRGB const png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} +#define PNG_tEXt const png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} +#define PNG_tIME const png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} +#define PNG_tRNS const png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} +#define PNG_zTXt const png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} + +#ifdef PNG_USE_GLOBAL_ARRAYS +PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_iTXt[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_sCAL[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_sPLT[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5]; +PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5]; +#endif /* PNG_USE_GLOBAL_ARRAYS */ + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for reading, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_read_struct instead). + */ +extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr)); +#undef png_read_init +#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for writing, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_write_struct instead). + */ +extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr)); +#undef png_write_init +#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); + +/* Allocate memory for an internal libpng struct */ +PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); + +/* Free memory from internal libpng struct */ +PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); + +PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr + malloc_fn, png_voidp mem_ptr)); +PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, + png_free_ptr free_fn, png_voidp mem_ptr)); + +/* Free any memory that info_ptr points to and reset struct. */ +PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_1_0_X +/* Function to allocate memory for zlib. */ +PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size)); + +/* Function to free memory for zlib */ +PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); + +#ifdef PNG_SIZE_T +/* Function to convert a sizeof an item to png_sizeof item */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); +#endif + +/* Next four functions are used internally as callbacks. PNGAPI is required + * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. */ + +PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)); +#endif + +PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +#if !defined(PNG_NO_STDIO) +PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr)); +#endif +#endif +#else /* PNG_1_0_X */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)); +#endif +#endif /* PNG_1_0_X */ + +/* Reset the CRC variable */ +PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); + +/* Write the "data" buffer to whatever output you are using. */ +PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +/* Read data from whatever input you are using into the "data" buffer */ +PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +/* Read bytes into buf, and update png_ptr->crc */ +PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, + png_size_t length)); + +/* Decompress data in a chunk that uses compression */ +#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) +PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr, + int comp_type, png_charp chunkdata, png_size_t chunklength, + png_size_t prefix_length, png_size_t *data_length)); +#endif + +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ +PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); + +/* Read the CRC from the file and compare it to the libpng calculated CRC */ +PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); + +/* Calculate the CRC over a section of data. Note that we are only + * passing a maximum of 64K on systems that have this as a memory limit, + * since this is the maximum buffer size we can specify. + */ +PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr, + png_size_t length)); + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); +#endif + +/* simple function to write the signature */ +PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr)); + +/* write various chunks */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. + */ +PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, + png_uint_32 height, + int bit_depth, int color_type, int compression_method, int filter_method, + int interlace_method)); + +PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette, + png_uint_32 num_pal)); + +PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); + +#if defined(PNG_WRITE_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point + file_gamma)); +#endif +#endif + +#if defined(PNG_WRITE_sBIT_SUPPORTED) +PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit, + int color_type)); +#endif + +#if defined(PNG_WRITE_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, + double white_x, double white_y, + double red_x, double red_y, double green_x, double green_y, + double blue_x, double blue_y)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, + png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)); +#endif +#endif + +#if defined(PNG_WRITE_sRGB_SUPPORTED) +PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, + int intent)); +#endif + +#if defined(PNG_WRITE_iCCP_SUPPORTED) +PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, + png_charp name, int compression_type, + png_charp profile, int proflen)); + /* Note to maintainer: profile should be png_bytep */ +#endif + +#if defined(PNG_WRITE_sPLT_SUPPORTED) +PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, + png_sPLT_tp palette)); +#endif + +#if defined(PNG_WRITE_tRNS_SUPPORTED) +PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans, + png_color_16p values, int number, int color_type)); +#endif + +#if defined(PNG_WRITE_bKGD_SUPPORTED) +PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, + png_color_16p values, int color_type)); +#endif + +#if defined(PNG_WRITE_hIST_SUPPORTED) +PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist, + int num_hist)); +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, + png_charp key, png_charpp new_key)); +#endif + +#if defined(PNG_WRITE_tEXt_SUPPORTED) +PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len)); +#endif + +#if defined(PNG_WRITE_zTXt_SUPPORTED) +PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len, int compression)); +#endif + +#if defined(PNG_WRITE_iTXt_SUPPORTED) +PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, + int compression, png_charp key, png_charp lang, png_charp lang_key, + png_charp text)); +#endif + +#if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */ +PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp text_ptr, int num_text)); +#endif + +#if defined(PNG_WRITE_oFFs_SUPPORTED) +PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type)); +#endif + +#if defined(PNG_WRITE_pCAL_SUPPORTED) +PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, + png_int_32 X0, png_int_32 X1, int type, int nparams, + png_charp units, png_charpp params)); +#endif + +#if defined(PNG_WRITE_pHYs_SUPPORTED) +PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, + png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, + int unit_type)); +#endif + +#if defined(PNG_WRITE_tIME_SUPPORTED) +PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, + png_timep mod_time)); +#endif + +#if defined(PNG_WRITE_sCAL_SUPPORTED) +#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) +PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr, + int unit, double width, double height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, + int unit, png_charp width, png_charp height)); +#endif +#endif +#endif + +/* Called when finished processing a row of data */ +PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); + +/* Internal use only. Called before first row of data */ +PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); + +#if defined(PNG_READ_GAMMA_SUPPORTED) +PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr)); +#endif + +/* combine a row of data, dealing with alpha, etc. if requested */ +PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, + int mask)); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) +/* expand an interlaced row */ +/* OLD pre-1.0.9 interface: +PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations)); + */ +PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); +#endif + +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* grab pixels out of a row for an interlaced pass */ +PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass)); +#endif + +/* unfilter a row */ +PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, + png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter)); + +/* Choose the best filter to use and filter the row data */ +PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, + png_row_infop row_info)); + +/* Write out the filtered row. */ +PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr, + png_bytep filtered_row)); +/* finish a row while reading, dealing with interlacing passes, etc. */ +PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); + +/* initialize the row buffers, etc. */ +PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); +/* optional call to update the users info structure */ +PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +/* these are the functions that do the transformations */ +#if defined(PNG_READ_FILLER_SUPPORTED) +PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 filler, png_uint_32 flags)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 flags)); +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) +PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop + row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) +PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) +PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) +PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p sig_bits)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) +PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) +PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info, + png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup)); + +# if defined(PNG_CORRECT_PALETTE_SUPPORTED) +PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette)); +# endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row)); +#endif + +#if defined(PNG_WRITE_PACK_SUPPORTED) +PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 bit_depth)); +#endif + +#if defined(PNG_WRITE_SHIFT_SUPPORTED) +PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p bit_depth)); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) +#if defined(PNG_READ_GAMMA_SUPPORTED) +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background, + png_color_16p background_1, + png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, + png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, + png_uint_16pp gamma_16_to_1, int gamma_shift)); +#else +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background)); +#endif +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) +PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row, + png_bytep gamma_table, png_uint_16pp gamma_16_table, + int gamma_shift)); +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) +PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, + png_bytep row, png_colorp palette, png_bytep trans, int num_trans)); +PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, + png_bytep row, png_color_16p trans_value)); +#endif + +/* The following decodes the appropriate chunks, and does error correction, + * then calls the appropriate callback for the chunk if it is valid. + */ + +/* decode the IHDR chunk */ +PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); + +#if defined(PNG_READ_bKGD_SUPPORTED) +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_cHRM_SUPPORTED) +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_gAMA_SUPPORTED) +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_hIST_SUPPORTED) +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_iCCP_SUPPORTED) +extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#if defined(PNG_READ_iTXt_SUPPORTED) +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_oFFs_SUPPORTED) +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_pCAL_SUPPORTED) +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_pHYs_SUPPORTED) +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_sBIT_SUPPORTED) +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_sCAL_SUPPORTED) +PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_sPLT_SUPPORTED) +extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#if defined(PNG_READ_sRGB_SUPPORTED) +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_tEXt_SUPPORTED) +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_tIME_SUPPORTED) +PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_tRNS_SUPPORTED) +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#if defined(PNG_READ_zTXt_SUPPORTED) +PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); + +PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, + png_bytep chunk_name)); + +/* handle the transformations for reading and writing */ +PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr)); + +PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, + png_uint_32 length)); +PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); +PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); +#if defined(PNG_READ_tEXt_SUPPORTED) +PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) +PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) +PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) +/* png.c */ /* PRIVATE */ +PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr)); +#endif +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +#endif /* PNG_INTERNAL */ + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +/* do not put anything past this line */ +#endif /* PNG_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngconf.h ./win32/dependencies/libpng/pngconf.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngconf.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngconf.h 2006-05-13 06:27:07 +0900 @@ -0,0 +1,1472 @@ + +/* pngconf.h - machine configurable file for libpng + * + * libpng version 1.2.10 - April 23, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2005 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +/* Any machine specific code is near the front of this file, so if you + * are configuring libpng for a machine, you may want to read the section + * starting here down to where it starts to typedef png_color, png_text, + * and png_info. + */ + +#ifndef PNGCONF_H +#define PNGCONF_H + +#define PNG_1_2_X + +/* + * PNG_USER_CONFIG has to be defined on the compiler command line. This + * includes the resource compiler for Windows DLL configurations. + */ +#ifdef PNG_USER_CONFIG +# ifndef PNG_USER_PRIVATEBUILD +# define PNG_USER_PRIVATEBUILD +# endif +#include "pngusr.h" +#endif + +/* PNG_CONFIGURE_LIBPNG is set by the "configure" script. */ +#ifdef PNG_CONFIGURE_LIBPNG +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#endif + +/* + * Added at libpng-1.2.8 + * + * If you create a private DLL you need to define in "pngusr.h" the followings: + * #define PNG_USER_PRIVATEBUILD + * e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons." + * #define PNG_USER_DLLFNAME_POSTFIX + * e.g. // private DLL "libpng13gx.dll" + * #define PNG_USER_DLLFNAME_POSTFIX "gx" + * + * The following macros are also at your disposal if you want to complete the + * DLL VERSIONINFO structure. + * - PNG_USER_VERSIONINFO_COMMENTS + * - PNG_USER_VERSIONINFO_COMPANYNAME + * - PNG_USER_VERSIONINFO_LEGALTRADEMARKS + */ + +#ifdef __STDC__ +#ifdef SPECIALBUILD +# pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\ + are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.") +#endif + +#ifdef PRIVATEBUILD +# pragma message("PRIVATEBUILD is deprecated.\ + Use PNG_USER_PRIVATEBUILD instead.") +# define PNG_USER_PRIVATEBUILD PRIVATEBUILD +#endif +#endif /* __STDC__ */ + +#ifndef PNG_VERSION_INFO_ONLY + +/* End of material added to libpng-1.2.8 */ + +/* This is the size of the compression buffer, and thus the size of + * an IDAT chunk. Make this whatever size you feel is best for your + * machine. One of these will be allocated per png_struct. When this + * is full, it writes the data to the disk, and does some other + * calculations. Making this an extremely small size will slow + * the library down, but you may want to experiment to determine + * where it becomes significant, if you are concerned with memory + * usage. Note that zlib allocates at least 32Kb also. For readers, + * this describes the size of the buffer available to read the data in. + * Unless this gets smaller than the size of a row (compressed), + * it should not make much difference how big this is. + */ + +#ifndef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 8192 +#endif + +/* Enable if you want a write-only libpng */ + +#ifndef PNG_NO_READ_SUPPORTED +# define PNG_READ_SUPPORTED +#endif + +/* Enable if you want a read-only libpng */ + +#ifndef PNG_NO_WRITE_SUPPORTED +# define PNG_WRITE_SUPPORTED +#endif + +/* Enabled by default in 1.2.0. You can disable this if you don't need to + support PNGs that are embedded in MNG datastreams */ +#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES) +# ifndef PNG_MNG_FEATURES_SUPPORTED +# define PNG_MNG_FEATURES_SUPPORTED +# endif +#endif + +#ifndef PNG_NO_FLOATING_POINT_SUPPORTED +# ifndef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FLOATING_POINT_SUPPORTED +# endif +#endif + +/* If you are running on a machine where you cannot allocate more + * than 64K of memory at once, uncomment this. While libpng will not + * normally need that much memory in a chunk (unless you load up a very + * large file), zlib needs to know how big of a chunk it can use, and + * libpng thus makes sure to check any memory allocation to verify it + * will fit into memory. +#define PNG_MAX_MALLOC_64K + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) +# define PNG_MAX_MALLOC_64K +#endif + +/* Special munging to support doing things the 'cygwin' way: + * 'Normal' png-on-win32 defines/defaults: + * PNG_BUILD_DLL -- building dll + * PNG_USE_DLL -- building an application, linking to dll + * (no define) -- building static library, or building an + * application and linking to the static lib + * 'Cygwin' defines/defaults: + * PNG_BUILD_DLL -- (ignored) building the dll + * (no define) -- (ignored) building an application, linking to the dll + * PNG_STATIC -- (ignored) building the static lib, or building an + * application that links to the static lib. + * ALL_STATIC -- (ignored) building various static libs, or building an + * application that links to the static libs. + * Thus, + * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and + * this bit of #ifdefs will define the 'correct' config variables based on + * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but + * unnecessary. + * + * Also, the precedence order is: + * ALL_STATIC (since we can't #undef something outside our namespace) + * PNG_BUILD_DLL + * PNG_STATIC + * (nothing) == PNG_USE_DLL + * + * CYGWIN (2002-01-20): The preceding is now obsolete. With the advent + * of auto-import in binutils, we no longer need to worry about + * __declspec(dllexport) / __declspec(dllimport) and friends. Therefore, + * we don't need to worry about PNG_STATIC or ALL_STATIC when it comes + * to __declspec() stuff. However, we DO need to worry about + * PNG_BUILD_DLL and PNG_STATIC because those change some defaults + * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. + */ +#if defined(__CYGWIN__) +# if defined(ALL_STATIC) +# if defined(PNG_BUILD_DLL) +# undef PNG_BUILD_DLL +# endif +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if defined(PNG_DLL) +# undef PNG_DLL +# endif +# if !defined(PNG_STATIC) +# define PNG_STATIC +# endif +# else +# if defined (PNG_BUILD_DLL) +# if defined(PNG_STATIC) +# undef PNG_STATIC +# endif +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if !defined(PNG_DLL) +# define PNG_DLL +# endif +# else +# if defined(PNG_STATIC) +# if defined(PNG_USE_DLL) +# undef PNG_USE_DLL +# endif +# if defined(PNG_DLL) +# undef PNG_DLL +# endif +# else +# if !defined(PNG_USE_DLL) +# define PNG_USE_DLL +# endif +# if !defined(PNG_DLL) +# define PNG_DLL +# endif +# endif +# endif +# endif +#endif + +/* This protects us against compilers that run on a windowing system + * and thus don't have or would rather us not use the stdio types: + * stdin, stdout, and stderr. The only one currently used is stderr + * in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will + * prevent these from being compiled and used. #defining PNG_NO_STDIO + * will also prevent these, plus will prevent the entire set of stdio + * macros and functions (FILE *, printf, etc.) from being compiled and used, + * unless (PNG_DEBUG > 0) has been #defined. + * + * #define PNG_NO_CONSOLE_IO + * #define PNG_NO_STDIO + */ + +#if defined(_WIN32_WCE) +# include + /* Console I/O functions are not supported on WindowsCE */ +# define PNG_NO_CONSOLE_IO +# ifdef PNG_DEBUG +# undef PNG_DEBUG +# endif +#endif + +#ifdef PNG_BUILD_DLL +# ifndef PNG_CONSOLE_IO_SUPPORTED +# ifndef PNG_NO_CONSOLE_IO +# define PNG_NO_CONSOLE_IO +# endif +# endif +#endif + +# ifdef PNG_NO_STDIO +# ifndef PNG_NO_CONSOLE_IO +# define PNG_NO_CONSOLE_IO +# endif +# ifdef PNG_DEBUG +# if (PNG_DEBUG > 0) +# include +# endif +# endif +# else +# if !defined(_WIN32_WCE) +/* "stdio.h" functions are not supported on WindowsCE */ +# include +# endif +# endif + +/* This macro protects us against machines that don't have function + * prototypes (ie K&R style headers). If your compiler does not handle + * function prototypes, define this macro and use the included ansi2knr. + * I've always been able to use _NO_PROTO as the indicator, but you may + * need to drag the empty declaration out in front of here, or change the + * ifdef to suit your own needs. + */ +#ifndef PNGARG + +#ifdef OF /* zlib prototype munger */ +# define PNGARG(arglist) OF(arglist) +#else + +#ifdef _NO_PROTO +# define PNGARG(arglist) () +# ifndef PNG_TYPECAST_NULL +# define PNG_TYPECAST_NULL +# endif +#else +# define PNGARG(arglist) arglist +#endif /* _NO_PROTO */ + +#endif /* OF */ + +#endif /* PNGARG */ + +/* Try to determine if we are compiling on a Mac. Note that testing for + * just __MWERKS__ is not good enough, because the Codewarrior is now used + * on non-Mac platforms. + */ +#ifndef MACOS +# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ + defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) +# define MACOS +# endif +#endif + +/* enough people need this for various reasons to include it here */ +#if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) +# include +#endif + +#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) +# define PNG_SETJMP_SUPPORTED +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This is an attempt to force a single setjmp behaviour on Linux. If + * the X config stuff didn't define _BSD_SOURCE we wouldn't need this. + */ + +# ifdef __linux__ +# ifdef _BSD_SOURCE +# define PNG_SAVE_BSD_SOURCE +# undef _BSD_SOURCE +# endif +# ifdef _SETJMP_H + /* If you encounter a compiler error here, see the explanation + * near the end of INSTALL. + */ + __png.h__ already includes setjmp.h; + __dont__ include it again.; +# endif +# endif /* __linux__ */ + + /* include setjmp.h for error handling */ +# include + +# ifdef __linux__ +# ifdef PNG_SAVE_BSD_SOURCE +# define _BSD_SOURCE +# undef PNG_SAVE_BSD_SOURCE +# endif +# endif /* __linux__ */ +#endif /* PNG_SETJMP_SUPPORTED */ + +#ifdef BSD +# include +#else +# include +#endif + +/* Other defines for things like memory and the like can go here. */ +#ifdef PNG_INTERNAL + +#include + +/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which + * aren't usually used outside the library (as far as I know), so it is + * debatable if they should be exported at all. In the future, when it is + * possible to have run-time registry of chunk-handling functions, some of + * these will be made available again. +#define PNG_EXTERN extern + */ +#define PNG_EXTERN + +/* Other defines specific to compilers can go here. Try to keep + * them inside an appropriate ifdef/endif pair for portability. + */ + +#if defined(PNG_FLOATING_POINT_SUPPORTED) +# if defined(MACOS) + /* We need to check that hasn't already been included earlier + * as it seems it doesn't agree with , yet we should really use + * if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include +# endif +# else +# include +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include +# endif +#endif + +/* Codewarrior on NT has linking problems without this. */ +#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) +# define PNG_ALWAYS_EXTERN +#endif + +/* This provides the non-ANSI (far) memory allocation routines. */ +#if defined(__TURBOC__) && defined(__MSDOS__) +# include +# include +#endif + +/* I have no idea why is this necessary... */ +#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ + defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) +# include +#endif + +/* This controls how fine the dithering gets. As this allocates + * a largish chunk of memory (32K), those who are not as concerned + * with dithering quality can decrease some or all of these. + */ +#ifndef PNG_DITHER_RED_BITS +# define PNG_DITHER_RED_BITS 5 +#endif +#ifndef PNG_DITHER_GREEN_BITS +# define PNG_DITHER_GREEN_BITS 5 +#endif +#ifndef PNG_DITHER_BLUE_BITS +# define PNG_DITHER_BLUE_BITS 5 +#endif + +/* This controls how fine the gamma correction becomes when you + * are only interested in 8 bits anyway. Increasing this value + * results in more memory being used, and more pow() functions + * being called to fill in the gamma tables. Don't set this value + * less then 8, and even that may not work (I haven't tested it). + */ + +#ifndef PNG_MAX_GAMMA_8 +# define PNG_MAX_GAMMA_8 11 +#endif + +/* This controls how much a difference in gamma we can tolerate before + * we actually start doing gamma conversion. + */ +#ifndef PNG_GAMMA_THRESHOLD +# define PNG_GAMMA_THRESHOLD 0.05 +#endif + +#endif /* PNG_INTERNAL */ + +/* The following uses const char * instead of char * for error + * and warning message functions, so some compilers won't complain. + * If you do not want to use const, define PNG_NO_CONST here. + */ + +#ifndef PNG_NO_CONST +# define PNG_CONST const +#else +# define PNG_CONST +#endif + +/* The following defines give you the ability to remove code from the + * library that you will not be using. I wish I could figure out how to + * automate this, but I can't do that without making it seriously hard + * on the users. So if you are not using an ability, change the #define + * to and #undef, and that part of the library will not be compiled. If + * your linker can't find a function, you may want to make sure the + * ability is defined here. Some of these depend upon some others being + * defined. I haven't figured out all the interactions here, so you may + * have to experiment awhile to get everything to compile. If you are + * creating or using a shared library, you probably shouldn't touch this, + * as it will affect the size of the structures, and this will cause bad + * things to happen if the library and/or application ever change. + */ + +/* Any features you will not be using can be undef'ed here */ + +/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user + * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS + * on the compile line, then pick and choose which ones to define without + * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED + * if you only want to have a png-compliant reader/writer but don't need + * any of the extra transformations. This saves about 80 kbytes in a + * typical installation of the library. (PNG_NO_* form added in version + * 1.0.1c, for consistency) + */ + +/* The size of the png_text structure changed in libpng-1.0.6 when + * iTXt support was added. iTXt support was turned off by default through + * libpng-1.2.x, to support old apps that malloc the png_text structure + * instead of calling png_set_text() and letting libpng malloc it. It + * was turned on by default in libpng-1.3.0. + */ + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +# ifndef PNG_NO_iTXt_SUPPORTED +# define PNG_NO_iTXt_SUPPORTED +# endif +# ifndef PNG_NO_READ_iTXt +# define PNG_NO_READ_iTXt +# endif +# ifndef PNG_NO_WRITE_iTXt +# define PNG_NO_WRITE_iTXt +# endif +#endif + +#if !defined(PNG_NO_iTXt_SUPPORTED) +# if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt) +# define PNG_READ_iTXt +# endif +# if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt) +# define PNG_WRITE_iTXt +# endif +#endif + +/* The following support, added after version 1.0.0, can be turned off here en + * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility + * with old applications that require the length of png_struct and png_info + * to remain unchanged. + */ + +#ifdef PNG_LEGACY_SUPPORTED +# define PNG_NO_FREE_ME +# define PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_NO_READ_USER_CHUNKS +# define PNG_NO_READ_iCCP +# define PNG_NO_WRITE_iCCP +# define PNG_NO_READ_iTXt +# define PNG_NO_WRITE_iTXt +# define PNG_NO_READ_sCAL +# define PNG_NO_WRITE_sCAL +# define PNG_NO_READ_sPLT +# define PNG_NO_WRITE_sPLT +# define PNG_NO_INFO_IMAGE +# define PNG_NO_READ_RGB_TO_GRAY +# define PNG_NO_READ_USER_TRANSFORM +# define PNG_NO_WRITE_USER_TRANSFORM +# define PNG_NO_USER_MEM +# define PNG_NO_READ_EMPTY_PLTE +# define PNG_NO_MNG_FEATURES +# define PNG_NO_FIXED_POINT_SUPPORTED +#endif + +/* Ignore attempt to turn off both floating and fixed point support */ +#if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ + !defined(PNG_NO_FIXED_POINT_SUPPORTED) +# define PNG_FIXED_POINT_SUPPORTED +#endif + +#ifndef PNG_NO_FREE_ME +# define PNG_FREE_ME_SUPPORTED +#endif + +#if defined(PNG_READ_SUPPORTED) + +#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ + !defined(PNG_NO_READ_TRANSFORMS) +# define PNG_READ_TRANSFORMS_SUPPORTED +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +# ifndef PNG_NO_READ_EXPAND +# define PNG_READ_EXPAND_SUPPORTED +# endif +# ifndef PNG_NO_READ_SHIFT +# define PNG_READ_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACK +# define PNG_READ_PACK_SUPPORTED +# endif +# ifndef PNG_NO_READ_BGR +# define PNG_READ_BGR_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP +# define PNG_READ_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACKSWAP +# define PNG_READ_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT +# define PNG_READ_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_READ_DITHER +# define PNG_READ_DITHER_SUPPORTED +# endif +# ifndef PNG_NO_READ_BACKGROUND +# define PNG_READ_BACKGROUND_SUPPORTED +# endif +# ifndef PNG_NO_READ_16_TO_8 +# define PNG_READ_16_TO_8_SUPPORTED +# endif +# ifndef PNG_NO_READ_FILLER +# define PNG_READ_FILLER_SUPPORTED +# endif +# ifndef PNG_NO_READ_GAMMA +# define PNG_READ_GAMMA_SUPPORTED +# endif +# ifndef PNG_NO_READ_GRAY_TO_RGB +# define PNG_READ_GRAY_TO_RGB_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP_ALPHA +# define PNG_READ_SWAP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT_ALPHA +# define PNG_READ_INVERT_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_STRIP_ALPHA +# define PNG_READ_STRIP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_USER_TRANSFORM +# define PNG_READ_USER_TRANSFORM_SUPPORTED +# endif +# ifndef PNG_NO_READ_RGB_TO_GRAY +# define PNG_READ_RGB_TO_GRAY_SUPPORTED +# endif +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ + +#if !defined(PNG_NO_PROGRESSIVE_READ) && \ + !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */ +# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ +#endif /* about interlacing capability! You'll */ + /* still have interlacing unless you change the following line: */ + +#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */ + +#ifndef PNG_NO_READ_COMPOSITE_NODIV +# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ +# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ +# endif +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, will be removed from version 2.0.0. + Use PNG_MNG_FEATURES_SUPPORTED instead. */ +#ifndef PNG_NO_READ_EMPTY_PLTE +# define PNG_READ_EMPTY_PLTE_SUPPORTED +#endif +#endif + +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_WRITE_SUPPORTED) + +# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ + !defined(PNG_NO_WRITE_TRANSFORMS) +# define PNG_WRITE_TRANSFORMS_SUPPORTED +#endif + +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED +# ifndef PNG_NO_WRITE_SHIFT +# define PNG_WRITE_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACK +# define PNG_WRITE_PACK_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_BGR +# define PNG_WRITE_BGR_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_SWAP +# define PNG_WRITE_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACKSWAP +# define PNG_WRITE_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_INVERT +# define PNG_WRITE_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_FILLER +# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */ +# endif +# ifndef PNG_NO_WRITE_SWAP_ALPHA +# define PNG_WRITE_SWAP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_INVERT_ALPHA +# define PNG_WRITE_INVERT_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_USER_TRANSFORM +# define PNG_WRITE_USER_TRANSFORM_SUPPORTED +# endif +#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ + +#if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \ + !defined(PNG_WRITE_INTERLACING_SUPPORTED) +#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant + encoders, but can cause trouble + if left undefined */ +#endif + +#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ + !defined(PNG_WRITE_WEIGHTED_FILTER) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) +# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#endif + +#ifndef PNG_NO_WRITE_FLUSH +# define PNG_WRITE_FLUSH_SUPPORTED +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ +#ifndef PNG_NO_WRITE_EMPTY_PLTE +# define PNG_WRITE_EMPTY_PLTE_SUPPORTED +#endif +#endif + +#endif /* PNG_WRITE_SUPPORTED */ + +#ifndef PNG_1_0_X +# ifndef PNG_NO_ERROR_NUMBERS +# define PNG_ERROR_NUMBERS_SUPPORTED +# endif +#endif /* PNG_1_0_X */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +# ifndef PNG_NO_USER_TRANSFORM_PTR +# define PNG_USER_TRANSFORM_PTR_SUPPORTED +# endif +#endif + +#ifndef PNG_NO_STDIO +# define PNG_TIME_RFC1123_SUPPORTED +#endif + +/* This adds extra functions in pngget.c for accessing data from the + * info pointer (added in version 0.99) + * png_get_image_width() + * png_get_image_height() + * png_get_bit_depth() + * png_get_color_type() + * png_get_compression_type() + * png_get_filter_type() + * png_get_interlace_type() + * png_get_pixel_aspect_ratio() + * png_get_pixels_per_meter() + * png_get_x_offset_pixels() + * png_get_y_offset_pixels() + * png_get_x_offset_microns() + * png_get_y_offset_microns() + */ +#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED) +# define PNG_EASY_ACCESS_SUPPORTED +#endif + +/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 + even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined */ +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) +# ifndef PNG_ASSEMBLER_CODE_SUPPORTED +# define PNG_ASSEMBLER_CODE_SUPPORTED +# endif +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) && \ + defined(__MMX__) +# define PNG_MMX_CODE_SUPPORTED +# endif +# if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_NO_MMX_CODE) && \ + !defined(PNG_USE_PNGVCRD) && defined(__MMX__) +# define PNG_USE_PNGGCCRD +# endif +#endif + +/* If you are sure that you don't need thread safety and you are compiling + with PNG_USE_PNGCCRD for an MMX application, you can define this for + faster execution. See pnggccrd.c. +#define PNG_THREAD_UNSAFE_OK +*/ + +#if !defined(PNG_1_0_X) +#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) +# define PNG_USER_MEM_SUPPORTED +#endif +#endif /* PNG_1_0_X */ + +/* Added at libpng-1.2.6 */ +#if !defined(PNG_1_0_X) +#ifndef PNG_SET_USER_LIMITS_SUPPORTED +#if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED) +# define PNG_SET_USER_LIMITS_SUPPORTED +#endif +#endif +#endif /* PNG_1_0_X */ + +/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter + * how large, set these limits to 0x7fffffffL + */ +#ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 1000000L +#endif +#ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 1000000L +#endif + +/* These are currently experimental features, define them if you want */ + +/* very little testing */ +/* +#ifdef PNG_READ_SUPPORTED +# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# endif +#endif +*/ + +/* This is only for PowerPC big-endian and 680x0 systems */ +/* some testing */ +/* +#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED +# define PNG_READ_BIG_ENDIAN_SUPPORTED +#endif +*/ + +/* Buggy compilers (e.g., gcc 2.7.2.2) need this */ +/* +#define PNG_NO_POINTER_INDEXING +*/ + +/* These functions are turned off by default, as they will be phased out. */ +/* +#define PNG_USELESS_TESTS_SUPPORTED +#define PNG_CORRECT_PALETTE_SUPPORTED +*/ + +/* Any chunks you are not interested in, you can undef here. The + * ones that allocate memory may be expecially important (hIST, + * tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info + * a bit smaller. + */ + +#if defined(PNG_READ_SUPPORTED) && \ + !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ + !defined(PNG_NO_READ_ANCILLARY_CHUNKS) +# define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#endif + +#if defined(PNG_WRITE_SUPPORTED) && \ + !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ + !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) +# define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#endif + +#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED + +#ifdef PNG_NO_READ_TEXT +# define PNG_NO_READ_iTXt +# define PNG_NO_READ_tEXt +# define PNG_NO_READ_zTXt +#endif +#ifndef PNG_NO_READ_bKGD +# define PNG_READ_bKGD_SUPPORTED +# define PNG_bKGD_SUPPORTED +#endif +#ifndef PNG_NO_READ_cHRM +# define PNG_READ_cHRM_SUPPORTED +# define PNG_cHRM_SUPPORTED +#endif +#ifndef PNG_NO_READ_gAMA +# define PNG_READ_gAMA_SUPPORTED +# define PNG_gAMA_SUPPORTED +#endif +#ifndef PNG_NO_READ_hIST +# define PNG_READ_hIST_SUPPORTED +# define PNG_hIST_SUPPORTED +#endif +#ifndef PNG_NO_READ_iCCP +# define PNG_READ_iCCP_SUPPORTED +# define PNG_iCCP_SUPPORTED +#endif +#ifndef PNG_NO_READ_iTXt +# ifndef PNG_READ_iTXt_SUPPORTED +# define PNG_READ_iTXt_SUPPORTED +# endif +# ifndef PNG_iTXt_SUPPORTED +# define PNG_iTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_READ_oFFs +# define PNG_READ_oFFs_SUPPORTED +# define PNG_oFFs_SUPPORTED +#endif +#ifndef PNG_NO_READ_pCAL +# define PNG_READ_pCAL_SUPPORTED +# define PNG_pCAL_SUPPORTED +#endif +#ifndef PNG_NO_READ_sCAL +# define PNG_READ_sCAL_SUPPORTED +# define PNG_sCAL_SUPPORTED +#endif +#ifndef PNG_NO_READ_pHYs +# define PNG_READ_pHYs_SUPPORTED +# define PNG_pHYs_SUPPORTED +#endif +#ifndef PNG_NO_READ_sBIT +# define PNG_READ_sBIT_SUPPORTED +# define PNG_sBIT_SUPPORTED +#endif +#ifndef PNG_NO_READ_sPLT +# define PNG_READ_sPLT_SUPPORTED +# define PNG_sPLT_SUPPORTED +#endif +#ifndef PNG_NO_READ_sRGB +# define PNG_READ_sRGB_SUPPORTED +# define PNG_sRGB_SUPPORTED +#endif +#ifndef PNG_NO_READ_tEXt +# define PNG_READ_tEXt_SUPPORTED +# define PNG_tEXt_SUPPORTED +#endif +#ifndef PNG_NO_READ_tIME +# define PNG_READ_tIME_SUPPORTED +# define PNG_tIME_SUPPORTED +#endif +#ifndef PNG_NO_READ_tRNS +# define PNG_READ_tRNS_SUPPORTED +# define PNG_tRNS_SUPPORTED +#endif +#ifndef PNG_NO_READ_zTXt +# define PNG_READ_zTXt_SUPPORTED +# define PNG_zTXt_SUPPORTED +#endif +#ifndef PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_UNKNOWN_CHUNKS_SUPPORTED +# endif +# ifndef PNG_NO_HANDLE_AS_UNKNOWN +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif +#endif +#if !defined(PNG_NO_READ_USER_CHUNKS) && \ + defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +# define PNG_READ_USER_CHUNKS_SUPPORTED +# define PNG_USER_CHUNKS_SUPPORTED +# ifdef PNG_NO_READ_UNKNOWN_CHUNKS +# undef PNG_NO_READ_UNKNOWN_CHUNKS +# endif +# ifdef PNG_NO_HANDLE_AS_UNKNOWN +# undef PNG_NO_HANDLE_AS_UNKNOWN +# endif +#endif +#ifndef PNG_NO_READ_OPT_PLTE +# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ +#endif /* optional PLTE chunk in RGB and RGBA images */ +#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \ + defined(PNG_READ_zTXt_SUPPORTED) +# define PNG_READ_TEXT_SUPPORTED +# define PNG_TEXT_SUPPORTED +#endif + +#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */ + +#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED + +#ifdef PNG_NO_WRITE_TEXT +# define PNG_NO_WRITE_iTXt +# define PNG_NO_WRITE_tEXt +# define PNG_NO_WRITE_zTXt +#endif +#ifndef PNG_NO_WRITE_bKGD +# define PNG_WRITE_bKGD_SUPPORTED +# ifndef PNG_bKGD_SUPPORTED +# define PNG_bKGD_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_cHRM +# define PNG_WRITE_cHRM_SUPPORTED +# ifndef PNG_cHRM_SUPPORTED +# define PNG_cHRM_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_gAMA +# define PNG_WRITE_gAMA_SUPPORTED +# ifndef PNG_gAMA_SUPPORTED +# define PNG_gAMA_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_hIST +# define PNG_WRITE_hIST_SUPPORTED +# ifndef PNG_hIST_SUPPORTED +# define PNG_hIST_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_iCCP +# define PNG_WRITE_iCCP_SUPPORTED +# ifndef PNG_iCCP_SUPPORTED +# define PNG_iCCP_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_iTXt +# ifndef PNG_WRITE_iTXt_SUPPORTED +# define PNG_WRITE_iTXt_SUPPORTED +# endif +# ifndef PNG_iTXt_SUPPORTED +# define PNG_iTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_oFFs +# define PNG_WRITE_oFFs_SUPPORTED +# ifndef PNG_oFFs_SUPPORTED +# define PNG_oFFs_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_pCAL +# define PNG_WRITE_pCAL_SUPPORTED +# ifndef PNG_pCAL_SUPPORTED +# define PNG_pCAL_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sCAL +# define PNG_WRITE_sCAL_SUPPORTED +# ifndef PNG_sCAL_SUPPORTED +# define PNG_sCAL_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_pHYs +# define PNG_WRITE_pHYs_SUPPORTED +# ifndef PNG_pHYs_SUPPORTED +# define PNG_pHYs_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sBIT +# define PNG_WRITE_sBIT_SUPPORTED +# ifndef PNG_sBIT_SUPPORTED +# define PNG_sBIT_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sPLT +# define PNG_WRITE_sPLT_SUPPORTED +# ifndef PNG_sPLT_SUPPORTED +# define PNG_sPLT_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sRGB +# define PNG_WRITE_sRGB_SUPPORTED +# ifndef PNG_sRGB_SUPPORTED +# define PNG_sRGB_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tEXt +# define PNG_WRITE_tEXt_SUPPORTED +# ifndef PNG_tEXt_SUPPORTED +# define PNG_tEXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tIME +# define PNG_WRITE_tIME_SUPPORTED +# ifndef PNG_tIME_SUPPORTED +# define PNG_tIME_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tRNS +# define PNG_WRITE_tRNS_SUPPORTED +# ifndef PNG_tRNS_SUPPORTED +# define PNG_tRNS_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_zTXt +# define PNG_WRITE_zTXt_SUPPORTED +# ifndef PNG_zTXt_SUPPORTED +# define PNG_zTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_UNKNOWN_CHUNKS_SUPPORTED +# endif +# ifndef PNG_NO_HANDLE_AS_UNKNOWN +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif +# endif +#endif +#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ + defined(PNG_WRITE_zTXt_SUPPORTED) +# define PNG_WRITE_TEXT_SUPPORTED +# ifndef PNG_TEXT_SUPPORTED +# define PNG_TEXT_SUPPORTED +# endif +#endif + +#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ + +/* Turn this off to disable png_read_png() and + * png_write_png() and leave the row_pointers member + * out of the info structure. + */ +#ifndef PNG_NO_INFO_IMAGE +# define PNG_INFO_IMAGE_SUPPORTED +#endif + +/* need the time information for reading tIME chunks */ +#if defined(PNG_tIME_SUPPORTED) +# if !defined(_WIN32_WCE) + /* "time.h" functions are not supported on WindowsCE */ +# include +# endif +#endif + +/* Some typedefs to get us started. These should be safe on most of the + * common platforms. The typedefs should be at least as large as the + * numbers suggest (a png_uint_32 must be at least 32 bits long), but they + * don't have to be exactly that size. Some compilers dislike passing + * unsigned shorts as function parameters, so you may be better off using + * unsigned int for png_uint_16. Likewise, for 64-bit systems, you may + * want to have unsigned int for png_uint_32 instead of unsigned long. + */ + +typedef unsigned long png_uint_32; +typedef long png_int_32; +typedef unsigned short png_uint_16; +typedef short png_int_16; +typedef unsigned char png_byte; + +/* This is usually size_t. It is typedef'ed just in case you need it to + change (I'm not sure if you will or not, so I thought I'd be safe) */ +#ifdef PNG_SIZE_T + typedef PNG_SIZE_T png_size_t; +# define png_sizeof(x) png_convert_size(sizeof (x)) +#else + typedef size_t png_size_t; +# define png_sizeof(x) sizeof (x) +#endif + +/* The following is needed for medium model support. It cannot be in the + * PNG_INTERNAL section. Needs modification for other compilers besides + * MSC. Model independent support declares all arrays and pointers to be + * large using the far keyword. The zlib version used must also support + * model independent data. As of version zlib 1.0.4, the necessary changes + * have been made in zlib. The USE_FAR_KEYWORD define triggers other + * changes that are needed. (Tim Wegner) + */ + +/* Separate compiler dependencies (problem here is that zlib.h always + defines FAR. (SJT) */ +#ifdef __BORLANDC__ +# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) +# define LDATA 1 +# else +# define LDATA 0 +# endif + /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ +# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) +# define PNG_MAX_MALLOC_64K +# if (LDATA != 1) +# ifndef FAR +# define FAR __far +# endif +# define USE_FAR_KEYWORD +# endif /* LDATA != 1 */ + /* Possibly useful for moving data out of default segment. + * Uncomment it if you want. Could also define FARDATA as + * const if your compiler supports it. (SJT) +# define FARDATA FAR + */ +# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ +#endif /* __BORLANDC__ */ + + +/* Suggest testing for specific compiler first before testing for + * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, + * making reliance oncertain keywords suspect. (SJT) + */ + +/* MSC Medium model */ +#if defined(FAR) +# if defined(M_I86MM) +# define USE_FAR_KEYWORD +# define FARDATA FAR +# include +# endif +#endif + +/* SJT: default case */ +#ifndef FAR +# define FAR +#endif + +/* At this point FAR is always defined */ +#ifndef FARDATA +# define FARDATA +#endif + +/* Typedef for floating-point numbers that are converted + to fixed-point with a multiple of 100,000, e.g., int_gamma */ +typedef png_int_32 png_fixed_point; + +/* Add typedefs for pointers */ +typedef void FAR * png_voidp; +typedef png_byte FAR * png_bytep; +typedef png_uint_32 FAR * png_uint_32p; +typedef png_int_32 FAR * png_int_32p; +typedef png_uint_16 FAR * png_uint_16p; +typedef png_int_16 FAR * png_int_16p; +typedef PNG_CONST char FAR * png_const_charp; +typedef char FAR * png_charp; +typedef png_fixed_point FAR * png_fixed_point_p; + +#ifndef PNG_NO_STDIO +#if defined(_WIN32_WCE) +typedef HANDLE png_FILE_p; +#else +typedef FILE * png_FILE_p; +#endif +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * png_doublep; +#endif + +/* Pointers to pointers; i.e. arrays */ +typedef png_byte FAR * FAR * png_bytepp; +typedef png_uint_32 FAR * FAR * png_uint_32pp; +typedef png_int_32 FAR * FAR * png_int_32pp; +typedef png_uint_16 FAR * FAR * png_uint_16pp; +typedef png_int_16 FAR * FAR * png_int_16pp; +typedef PNG_CONST char FAR * FAR * png_const_charpp; +typedef char FAR * FAR * png_charpp; +typedef png_fixed_point FAR * FAR * png_fixed_point_pp; +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * FAR * png_doublepp; +#endif + +/* Pointers to pointers to pointers; i.e., pointer to array */ +typedef char FAR * FAR * FAR * png_charppp; + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* SPC - Is this stuff deprecated? */ +/* It'll be removed as of libpng-1.3.0 - GR-P */ +/* libpng typedefs for types in zlib. If zlib changes + * or another compression library is used, then change these. + * Eliminates need to change all the source files. + */ +typedef charf * png_zcharp; +typedef charf * FAR * png_zcharpp; +typedef z_stream FAR * png_zstreamp; +#endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */ + +/* + * Define PNG_BUILD_DLL if the module being built is a Windows + * LIBPNG DLL. + * + * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. + * It is equivalent to Microsoft predefined macro _DLL that is + * automatically defined when you compile using the share + * version of the CRT (C Run-Time library) + * + * The cygwin mods make this behavior a little different: + * Define PNG_BUILD_DLL if you are building a dll for use with cygwin + * Define PNG_STATIC if you are building a static library for use with cygwin, + * -or- if you are building an application that you want to link to the + * static library. + * PNG_USE_DLL is defined by default (no user action needed) unless one of + * the other flags is defined. + */ + +#if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) +# define PNG_DLL +#endif +/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. + * When building a static lib, default to no GLOBAL ARRAYS, but allow + * command-line override + */ +#if defined(__CYGWIN__) +# if !defined(PNG_STATIC) +# if defined(PNG_USE_GLOBAL_ARRAYS) +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +# else +# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) +# if defined(PNG_USE_GLOBAL_ARRAYS) +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# endif +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +#endif + +/* Do not use global arrays (helps with building DLL's) + * They are no longer used in libpng itself, since version 1.0.5c, + * but might be required for some pre-1.0.5c applications. + */ +#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# if defined(PNG_NO_GLOBAL_ARRAYS) || (defined(__GNUC__) && defined(PNG_DLL)) +# define PNG_USE_LOCAL_ARRAYS +# else +# define PNG_USE_GLOBAL_ARRAYS +# endif +#endif + +#if defined(__CYGWIN__) +# undef PNGAPI +# define PNGAPI __cdecl +# undef PNG_IMPEXP +# define PNG_IMPEXP +#endif + +/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", + * you may get warnings regarding the linkage of png_zalloc and png_zfree. + * Don't ignore those warnings; you must also reset the default calling + * convention in your compiler to match your PNGAPI, and you must build + * zlib and your applications the same way you build libpng. + */ + +#if defined(__MINGW32__) && !defined(PNG_MODULEDEF) +# ifndef PNG_NO_MODULEDEF +# define PNG_NO_MODULEDEF +# endif +#endif + +#if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF) +# define PNG_IMPEXP +#endif + +#if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \ + (( defined(_Windows) || defined(_WINDOWS) || \ + defined(WIN32) || defined(_WIN32) || defined(__WIN32__) )) + +# ifndef PNGAPI +# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) +# define PNGAPI __cdecl +# else +# define PNGAPI _cdecl +# endif +# endif + +# if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \ + 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */) +# define PNG_IMPEXP +# endif + +# if !defined(PNG_IMPEXP) + +# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol +# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol + + /* Borland/Microsoft */ +# if defined(_MSC_VER) || defined(__BORLANDC__) +# if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) +# define PNG_EXPORT PNG_EXPORT_TYPE1 +# else +# define PNG_EXPORT PNG_EXPORT_TYPE2 +# if defined(PNG_BUILD_DLL) +# define PNG_IMPEXP __export +# else +# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in + VC++ */ +# endif /* Exists in Borland C++ for + C++ classes (== huge) */ +# endif +# endif + +# if !defined(PNG_IMPEXP) +# if defined(PNG_BUILD_DLL) +# define PNG_IMPEXP __declspec(dllexport) +# else +# define PNG_IMPEXP __declspec(dllimport) +# endif +# endif +# endif /* PNG_IMPEXP */ +#else /* !(DLL || non-cygwin WINDOWS) */ +# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) +# ifndef PNGAPI +# define PNGAPI _System +# endif +# else +# if 0 /* ... other platforms, with other meanings */ +# endif +# endif +#endif + +#ifndef PNGAPI +# define PNGAPI +#endif +#ifndef PNG_IMPEXP +# define PNG_IMPEXP +#endif + +#ifdef PNG_BUILDSYMS +# ifndef PNG_EXPORT +# define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END +# endif +# ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT +# endif +# endif +#endif + +#ifndef PNG_EXPORT +# define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol +#endif + +#ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type +# endif +#endif + +/* User may want to use these so they are not in PNG_INTERNAL. Any library + * functions that are passed far data must be model independent. + */ + +#ifndef PNG_ABORT +# define PNG_ABORT() abort() +#endif + +#ifdef PNG_SETJMP_SUPPORTED +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#else +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) +#endif + +#if defined(USE_FAR_KEYWORD) /* memory model independent fns */ +/* use this to make far-to-near assignments */ +# define CHECK 1 +# define NOCHECK 0 +# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) +# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) +# define png_strcpy _fstrcpy +# define png_strncpy _fstrncpy /* Added to v 1.2.6 */ +# define png_strlen _fstrlen +# define png_memcmp _fmemcmp /* SJT: added */ +# define png_memcpy _fmemcpy +# define png_memset _fmemset +#else /* use the usual functions */ +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# define png_strcpy strcpy +# define png_strncpy strncpy /* Added to v 1.2.6 */ +# define png_strlen strlen +# define png_memcmp memcmp /* SJT: added */ +# define png_memcpy memcpy +# define png_memset memset +#endif +/* End of memory model independent support */ + +/* Just a little check that someone hasn't tried to define something + * contradictory. + */ +#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) +# undef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 65536L +#endif + +#ifdef PNG_READ_SUPPORTED +/* Prior to libpng-1.0.9, this block was in pngasmrd.h */ +#if defined(PNG_INTERNAL) + +/* These are the default thresholds before the MMX code kicks in; if either + * rowbytes or bitdepth is below the threshold, plain C code is used. These + * can be overridden at runtime via the png_set_mmx_thresholds() call in + * libpng 1.2.0 and later. The values below were chosen by Intel. + */ + +#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT +# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */ +#endif +#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT +# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */ +#endif + +/* Set this in the makefile for VC++ on Pentium, not here. */ +/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c . + * MMX will be detected at run time and used if present. + */ +#ifdef PNG_USE_PNGVCRD +# define PNG_HAVE_ASSEMBLER_COMBINE_ROW +# define PNG_HAVE_ASSEMBLER_READ_INTERLACE +# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +#endif + +/* Set this in the makefile for gcc/as on Pentium, not here. */ +/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c . + * MMX will be detected at run time and used if present. + */ +#ifdef PNG_USE_PNGGCCRD +# define PNG_HAVE_ASSEMBLER_COMBINE_ROW +# define PNG_HAVE_ASSEMBLER_READ_INTERLACE +# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +#endif +/* - see pnggccrd.c for info about what is currently enabled */ + +#endif /* PNG_INTERNAL */ +#endif /* PNG_READ_SUPPORTED */ + +/* Added at libpng-1.2.8 */ +#endif /* PNG_VERSION_INFO_ONLY */ + +#endif /* PNGCONF_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngerror.c ./win32/dependencies/libpng/pngerror.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngerror.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngerror.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,313 @@ + +/* pngerror.c - stub functions for i/o and memory allocation + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file provides a location for all error handling. Users who + * need special error handling are expected to write replacement functions + * and use png_set_error_fn() to use those functions. See the instructions + * at each function. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +static void /* PRIVATE */ +png_default_error PNGARG((png_structp png_ptr, + png_const_charp error_message)); +static void /* PRIVATE */ +png_default_warning PNGARG((png_structp png_ptr, + png_const_charp warning_message)); + +/* This function is called whenever there is a fatal error. This function + * should not be changed. If there is a need to handle errors differently, + * you should supply a replacement error function and use png_set_error_fn() + * to replace the error function at run-time. + */ +void PNGAPI +png_error(png_structp png_ptr, png_const_charp error_message) +{ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + char msg[16]; + if (png_ptr != NULL) + { + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + { + if (*error_message == '#') + { + int offset; + for (offset=1; offset<15; offset++) + if (*(error_message+offset) == ' ') + break; + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + int i; + for (i=0; iflags&PNG_FLAG_STRIP_ERROR_TEXT) + { + msg[0]='0'; + msg[1]='\0'; + error_message=msg; + } + } + } + } +#endif + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_ptr, error_message); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, error_message); +} + +/* This function is called whenever there is a non-fatal error. This function + * should not be changed. If there is a need to handle warnings differently, + * you should supply a replacement warning function and use + * png_set_error_fn() to replace the warning function at run-time. + */ +void PNGAPI +png_warning(png_structp png_ptr, png_const_charp warning_message) +{ + int offset = 0; + if (png_ptr != NULL) + { +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) +#endif + { + if (*warning_message == '#') + { + for (offset=1; offset<15; offset++) + if (*(warning_message+offset) == ' ') + break; + } + } + if (png_ptr != NULL && png_ptr->warning_fn != NULL) + (*(png_ptr->warning_fn))(png_ptr, warning_message+offset); + } + else + png_default_warning(png_ptr, warning_message+offset); +} + +/* These utilities are used internally to build an error message that relates + * to the current chunk. The chunk name comes from png_ptr->chunk_name, + * this is used to prefix the message. The message is limited in length + * to 63 bytes, the name characters are output as hex digits wrapped in [] + * if the character is invalid. + */ +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) +static PNG_CONST char png_digit[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' +}; + +static void /* PRIVATE */ +png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp + error_message) +{ + int iout = 0, iin = 0; + + while (iin < 4) + { + int c = png_ptr->chunk_name[iin++]; + if (isnonalpha(c)) + { + buffer[iout++] = '['; + buffer[iout++] = png_digit[(c & 0xf0) >> 4]; + buffer[iout++] = png_digit[c & 0x0f]; + buffer[iout++] = ']'; + } + else + { + buffer[iout++] = (png_byte)c; + } + } + + if (error_message == NULL) + buffer[iout] = 0; + else + { + buffer[iout++] = ':'; + buffer[iout++] = ' '; + png_strncpy(buffer+iout, error_message, 63); + buffer[iout+63] = 0; + } +} + +void PNGAPI +png_chunk_error(png_structp png_ptr, png_const_charp error_message) +{ + char msg[18+64]; + if (png_ptr == NULL) + png_error(png_ptr, error_message); + png_format_buffer(png_ptr, msg, error_message); + png_error(png_ptr, msg); +} + +void PNGAPI +png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) +{ + char msg[18+64]; + if (png_ptr == NULL) + png_warning(png_ptr, warning_message); + png_format_buffer(png_ptr, msg, warning_message); + png_warning(png_ptr, msg); +} + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static void /* PRIVATE */ +png_default_error(png_structp png_ptr, png_const_charp error_message) +{ +#ifndef PNG_NO_CONSOLE_IO +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*error_message == '#') + { + int offset; + char error_number[16]; + for (offset=0; offset<15; offset++) + { + error_number[offset] = *(error_message+offset+1); + if (*(error_message+offset) == ' ') + break; + } + if((offset > 1) && (offset < 15)) + { + error_number[offset-1]='\0'; + fprintf(stderr, "libpng error no. %s: %s\n", error_number, + error_message+offset); + } + else + fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset); + } + else +#endif + fprintf(stderr, "libpng error: %s\n", error_message); +#endif + +#ifdef PNG_SETJMP_SUPPORTED +# ifdef USE_FAR_KEYWORD + { + jmp_buf jmpbuf; + png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf)); + longjmp(jmpbuf, 1); + } +# else + longjmp(png_ptr->jmpbuf, 1); +# endif +#else + /* make compiler happy */ ; + if (png_ptr) + PNG_ABORT(); +#endif +#ifdef PNG_NO_CONSOLE_IO + /* make compiler happy */ ; + if (&error_message != NULL) + return; +#endif +} + +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want them to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void /* PRIVATE */ +png_default_warning(png_structp png_ptr, png_const_charp warning_message) +{ +#ifndef PNG_NO_CONSOLE_IO +# ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*warning_message == '#') + { + int offset; + char warning_number[16]; + for (offset=0; offset<15; offset++) + { + warning_number[offset]=*(warning_message+offset+1); + if (*(warning_message+offset) == ' ') + break; + } + if((offset > 1) && (offset < 15)) + { + warning_number[offset-1]='\0'; + fprintf(stderr, "libpng warning no. %s: %s\n", warning_number, + warning_message+offset); + } + else + fprintf(stderr, "libpng warning: %s\n", warning_message); + } + else +# endif + fprintf(stderr, "libpng warning: %s\n", warning_message); +#else + /* make compiler happy */ ; + if (warning_message) + return; +#endif + /* make compiler happy */ ; + if (png_ptr) + return; +} + +/* This function is called when the application wants to use another method + * of handling errors and warnings. Note that the error function MUST NOT + * return to the calling routine or serious problems will occur. The return + * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) + */ +void PNGAPI +png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warning_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->error_ptr = error_ptr; + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; +} + + +/* This function returns a pointer to the error_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_error_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return NULL; + return ((png_voidp)png_ptr->error_ptr); +} + + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +void PNGAPI +png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) +{ + if(png_ptr != NULL) + { + png_ptr->flags &= + ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); + } +} +#endif +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngget.c ./win32/dependencies/libpng/pngget.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngget.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngget.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,937 @@ + +/* pngget.c - retrieval of values from info struct + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +png_uint_32 PNGAPI +png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->valid & flag); + else + return(0); +} + +png_uint_32 PNGAPI +png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->rowbytes); + else + return(0); +} + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +png_bytepp PNGAPI +png_get_rows(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->row_pointers); + else + return(0); +} +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* easy access to info, added in libpng-0.99 */ +png_uint_32 PNGAPI +png_get_image_width(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->width; + } + return (0); +} + +png_uint_32 PNGAPI +png_get_image_height(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->height; + } + return (0); +} + +png_byte PNGAPI +png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->bit_depth; + } + return (0); +} + +png_byte PNGAPI +png_get_color_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->color_type; + } + return (0); +} + +png_byte PNGAPI +png_get_filter_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->filter_type; + } + return (0); +} + +png_byte PNGAPI +png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->interlace_type; + } + return (0); +} + +png_byte PNGAPI +png_get_compression_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + { + return info_ptr->compression_type; + } + return (0); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_pHYs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); + if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) + return (0); + else return (info_ptr->x_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_pHYs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); + if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) + return (0); + else return (info_ptr->y_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +png_uint_32 PNGAPI +png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_pHYs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); + if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || + info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) + return (0); + else return (info_ptr->x_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) + { + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_pHYs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); + if (info_ptr->x_pixels_per_unit == 0) + return ((float)0.0); + else + return ((float)((float)info_ptr->y_pixels_per_unit + /(float)info_ptr->x_pixels_per_unit)); + } +#else + return (0.0); +#endif + return ((float)0.0); +} +#endif + +png_int_32 PNGAPI +png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_oFFs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); + if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) + return (0); + else return (info_ptr->x_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_oFFs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); + if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) + return (0); + else return (info_ptr->y_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_oFFs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); + if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) + return (0); + else return (info_ptr->x_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#if defined(PNG_oFFs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); + if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) + return (0); + else return (info_ptr->y_offset); + } +#else + return (0); +#endif + return (0); +} + +#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) +png_uint_32 PNGAPI +png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +float PNGAPI +png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) +{ + return ((float)png_get_x_offset_microns(png_ptr, info_ptr) + *.00003937); +} + +float PNGAPI +png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) +{ + return ((float)png_get_y_offset_microns(png_ptr, info_ptr) + *.00003937); +} + +#if defined(PNG_pHYs_SUPPORTED) +png_uint_32 PNGAPI +png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function\n", "pHYs"); + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + if(*unit_type == 1) + { + if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); + if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); + } + } + } + return (retval); +} +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ + +/* png_get_channels really belongs in here, too, but it's been around longer */ + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +png_byte PNGAPI +png_get_channels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->channels); + else + return (0); +} + +png_bytep PNGAPI +png_get_signature(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->signature); + else + return (NULL); +} + +#if defined(PNG_bKGD_SUPPORTED) +png_uint_32 PNGAPI +png_get_bKGD(png_structp png_ptr, png_infop info_ptr, + png_color_16p *background) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) + && background != NULL) + { + png_debug1(1, "in %s retrieval function\n", "bKGD"); + *background = &(info_ptr->background); + return (PNG_INFO_bKGD); + } + return (0); +} +#endif + +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM(png_structp png_ptr, png_infop info_ptr, + double *white_x, double *white_y, double *red_x, double *red_y, + double *green_x, double *green_y, double *blue_x, double *blue_y) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + png_debug1(1, "in %s retrieval function\n", "cHRM"); + if (white_x != NULL) + *white_x = (double)info_ptr->x_white; + if (white_y != NULL) + *white_y = (double)info_ptr->y_white; + if (red_x != NULL) + *red_x = (double)info_ptr->x_red; + if (red_y != NULL) + *red_y = (double)info_ptr->y_red; + if (green_x != NULL) + *green_x = (double)info_ptr->x_green; + if (green_y != NULL) + *green_y = (double)info_ptr->y_green; + if (blue_x != NULL) + *blue_x = (double)info_ptr->x_blue; + if (blue_y != NULL) + *blue_y = (double)info_ptr->y_blue; + return (PNG_INFO_cHRM); + } + return (0); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, + png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, + png_fixed_point *blue_x, png_fixed_point *blue_y) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + png_debug1(1, "in %s retrieval function\n", "cHRM"); + if (white_x != NULL) + *white_x = info_ptr->int_x_white; + if (white_y != NULL) + *white_y = info_ptr->int_y_white; + if (red_x != NULL) + *red_x = info_ptr->int_x_red; + if (red_y != NULL) + *red_y = info_ptr->int_y_red; + if (green_x != NULL) + *green_x = info_ptr->int_x_green; + if (green_y != NULL) + *green_y = info_ptr->int_y_green; + if (blue_x != NULL) + *blue_x = info_ptr->int_x_blue; + if (blue_y != NULL) + *blue_y = info_ptr->int_y_blue; + return (PNG_INFO_cHRM); + } + return (0); +} +#endif +#endif + +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) + && file_gamma != NULL) + { + png_debug1(1, "in %s retrieval function\n", "gAMA"); + *file_gamma = (double)info_ptr->gamma; + return (PNG_INFO_gAMA); + } + return (0); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point *int_file_gamma) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) + && int_file_gamma != NULL) + { + png_debug1(1, "in %s retrieval function\n", "gAMA"); + *int_file_gamma = info_ptr->int_gamma; + return (PNG_INFO_gAMA); + } + return (0); +} +#endif +#endif + +#if defined(PNG_sRGB_SUPPORTED) +png_uint_32 PNGAPI +png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) + && file_srgb_intent != NULL) + { + png_debug1(1, "in %s retrieval function\n", "sRGB"); + *file_srgb_intent = (int)info_ptr->srgb_intent; + return (PNG_INFO_sRGB); + } + return (0); +} +#endif + +#if defined(PNG_iCCP_SUPPORTED) +png_uint_32 PNGAPI +png_get_iCCP(png_structp png_ptr, png_infop info_ptr, + png_charpp name, int *compression_type, + png_charpp profile, png_uint_32 *proflen) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) + && name != NULL && profile != NULL && proflen != NULL) + { + png_debug1(1, "in %s retrieval function\n", "iCCP"); + *name = info_ptr->iccp_name; + *profile = info_ptr->iccp_profile; + /* compression_type is a dummy so the API won't have to change + if we introduce multiple compression types later. */ + *proflen = (int)info_ptr->iccp_proflen; + *compression_type = (int)info_ptr->iccp_compression; + return (PNG_INFO_iCCP); + } + return (0); +} +#endif + +#if defined(PNG_sPLT_SUPPORTED) +png_uint_32 PNGAPI +png_get_sPLT(png_structp png_ptr, png_infop info_ptr, + png_sPLT_tpp spalettes) +{ + if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) + *spalettes = info_ptr->splt_palettes; + return ((png_uint_32)info_ptr->splt_palettes_num); +} +#endif + +#if defined(PNG_hIST_SUPPORTED) +png_uint_32 PNGAPI +png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) + && hist != NULL) + { + png_debug1(1, "in %s retrieval function\n", "hIST"); + *hist = info_ptr->hist; + return (PNG_INFO_hIST); + } + return (0); +} +#endif + +png_uint_32 PNGAPI +png_get_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *width, png_uint_32 *height, int *bit_depth, + int *color_type, int *interlace_type, int *compression_type, + int *filter_type) + +{ + if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && + bit_depth != NULL && color_type != NULL) + { + png_debug1(1, "in %s retrieval function\n", "IHDR"); + *width = info_ptr->width; + *height = info_ptr->height; + *bit_depth = info_ptr->bit_depth; + if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16) + png_error(png_ptr, "Invalid bit depth"); + *color_type = info_ptr->color_type; + if (info_ptr->color_type > 6) + png_error(png_ptr, "Invalid color type"); + if (compression_type != NULL) + *compression_type = info_ptr->compression_type; + if (filter_type != NULL) + *filter_type = info_ptr->filter_type; + if (interlace_type != NULL) + *interlace_type = info_ptr->interlace_type; + + /* check for potential overflow of rowbytes */ + if (*width == 0 || *width > PNG_UINT_31_MAX) + png_error(png_ptr, "Invalid image width"); + if (*height == 0 || *height > PNG_UINT_31_MAX) + png_error(png_ptr, "Invalid image height"); + if (info_ptr->width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 64 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + { + png_warning(png_ptr, + "Width too large for libpng to process image data."); + } + return (1); + } + return (0); +} + +#if defined(PNG_oFFs_SUPPORTED) +png_uint_32 PNGAPI +png_get_oFFs(png_structp png_ptr, png_infop info_ptr, + png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) + && offset_x != NULL && offset_y != NULL && unit_type != NULL) + { + png_debug1(1, "in %s retrieval function\n", "oFFs"); + *offset_x = info_ptr->x_offset; + *offset_y = info_ptr->y_offset; + *unit_type = (int)info_ptr->offset_unit_type; + return (PNG_INFO_oFFs); + } + return (0); +} +#endif + +#if defined(PNG_pCAL_SUPPORTED) +png_uint_32 PNGAPI +png_get_pCAL(png_structp png_ptr, png_infop info_ptr, + png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, + png_charp *units, png_charpp *params) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) + && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + nparams != NULL && units != NULL && params != NULL) + { + png_debug1(1, "in %s retrieval function\n", "pCAL"); + *purpose = info_ptr->pcal_purpose; + *X0 = info_ptr->pcal_X0; + *X1 = info_ptr->pcal_X1; + *type = (int)info_ptr->pcal_type; + *nparams = (int)info_ptr->pcal_nparams; + *units = info_ptr->pcal_units; + *params = info_ptr->pcal_params; + return (PNG_INFO_pCAL); + } + return (0); +} +#endif + +#if defined(PNG_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL(png_structp png_ptr, png_infop info_ptr, + int *unit, double *width, double *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_pixel_width; + *height = info_ptr->scal_pixel_height; + return (PNG_INFO_sCAL); + } + return(0); +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, + int *unit, png_charpp width, png_charpp height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_s_width; + *height = info_ptr->scal_s_height; + return (PNG_INFO_sCAL); + } + return(0); +} +#endif +#endif +#endif + +#if defined(PNG_pHYs_SUPPORTED) +png_uint_32 PNGAPI +png_get_pHYs(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function\n", "pHYs"); + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + } + } + return (retval); +} +#endif + +png_uint_32 PNGAPI +png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, + int *num_palette) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) + && palette != NULL) + { + png_debug1(1, "in %s retrieval function\n", "PLTE"); + *palette = info_ptr->palette; + *num_palette = info_ptr->num_palette; + png_debug1(3, "num_palette = %d\n", *num_palette); + return (PNG_INFO_PLTE); + } + return (0); +} + +#if defined(PNG_sBIT_SUPPORTED) +png_uint_32 PNGAPI +png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) + && sig_bit != NULL) + { + png_debug1(1, "in %s retrieval function\n", "sBIT"); + *sig_bit = &(info_ptr->sig_bit); + return (PNG_INFO_sBIT); + } + return (0); +} +#endif + +#if defined(PNG_TEXT_SUPPORTED) +png_uint_32 PNGAPI +png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, + int *num_text) +{ + if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) + { + png_debug1(1, "in %s retrieval function\n", + (png_ptr->chunk_name[0] == '\0' ? "text" + : (png_const_charp)png_ptr->chunk_name)); + if (text_ptr != NULL) + *text_ptr = info_ptr->text; + if (num_text != NULL) + *num_text = info_ptr->num_text; + return ((png_uint_32)info_ptr->num_text); + } + if (num_text != NULL) + *num_text = 0; + return(0); +} +#endif + +#if defined(PNG_tIME_SUPPORTED) +png_uint_32 PNGAPI +png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) + && mod_time != NULL) + { + png_debug1(1, "in %s retrieval function\n", "tIME"); + *mod_time = &(info_ptr->mod_time); + return (PNG_INFO_tIME); + } + return (0); +} +#endif + +#if defined(PNG_tRNS_SUPPORTED) +png_uint_32 PNGAPI +png_get_tRNS(png_structp png_ptr, png_infop info_ptr, + png_bytep *trans, int *num_trans, png_color_16p *trans_values) +{ + png_uint_32 retval = 0; + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_debug1(1, "in %s retrieval function\n", "tRNS"); + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (trans != NULL) + { + *trans = info_ptr->trans; + retval |= PNG_INFO_tRNS; + } + if (trans_values != NULL) + *trans_values = &(info_ptr->trans_values); + } + else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ + { + if (trans_values != NULL) + { + *trans_values = &(info_ptr->trans_values); + retval |= PNG_INFO_tRNS; + } + if(trans != NULL) + *trans = NULL; + } + if(num_trans != NULL) + { + *num_trans = info_ptr->num_trans; + retval |= PNG_INFO_tRNS; + } + } + return (retval); +} +#endif + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +png_uint_32 PNGAPI +png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, + png_unknown_chunkpp unknowns) +{ + if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) + *unknowns = info_ptr->unknown_chunks; + return ((png_uint_32)info_ptr->unknown_chunks_num); +} +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +png_byte PNGAPI +png_get_rgb_to_gray_status (png_structp png_ptr) +{ + return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); +} +#endif + +#if defined(PNG_USER_CHUNKS_SUPPORTED) +png_voidp PNGAPI +png_get_user_chunk_ptr(png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_chunk_ptr : NULL); +} +#endif + +#ifdef PNG_WRITE_SUPPORTED +png_uint_32 PNGAPI +png_get_compression_buffer_size(png_structp png_ptr) +{ + return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); +} +#endif + +#ifndef PNG_1_0_X +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +/* this function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flags (png_structp png_ptr) +{ + return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L); +} + +/* this function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flagmask (int flag_select) +{ + png_uint_32 settable_asm_flags = 0; + + if (flag_select & PNG_SELECT_READ) + settable_asm_flags |= + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | + PNG_ASM_FLAG_MMX_READ_INTERLACE | + PNG_ASM_FLAG_MMX_READ_FILTER_SUB | + PNG_ASM_FLAG_MMX_READ_FILTER_UP | + PNG_ASM_FLAG_MMX_READ_FILTER_AVG | + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ; + /* no non-MMX flags yet */ + +#if 0 + /* GRR: no write-flags yet, either, but someday... */ + if (flag_select & PNG_SELECT_WRITE) + settable_asm_flags |= + PNG_ASM_FLAG_MMX_WRITE_ [whatever] ; +#endif /* 0 */ + + return settable_asm_flags; /* _theoretically_ settable capabilities only */ +} +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ + + +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) + /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ +/* this function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_flagmask (int flag_select, int *compilerID) +{ + png_uint_32 settable_mmx_flags = 0; + + if (flag_select & PNG_SELECT_READ) + settable_mmx_flags |= + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | + PNG_ASM_FLAG_MMX_READ_INTERLACE | + PNG_ASM_FLAG_MMX_READ_FILTER_SUB | + PNG_ASM_FLAG_MMX_READ_FILTER_UP | + PNG_ASM_FLAG_MMX_READ_FILTER_AVG | + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ; +#if 0 + /* GRR: no MMX write support yet, but someday... */ + if (flag_select & PNG_SELECT_WRITE) + settable_mmx_flags |= + PNG_ASM_FLAG_MMX_WRITE_ [whatever] ; +#endif /* 0 */ + + if (compilerID != NULL) { +#ifdef PNG_USE_PNGVCRD + *compilerID = 1; /* MSVC */ +#else +#ifdef PNG_USE_PNGGCCRD + *compilerID = 2; /* gcc/gas */ +#else + *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ +#endif +#endif + } + + return settable_mmx_flags; /* _theoretically_ settable capabilities only */ +} + +/* this function was added to libpng 1.2.0 */ +png_byte PNGAPI +png_get_mmx_bitdepth_threshold (png_structp png_ptr) +{ + return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0); +} + +/* this function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_rowbytes_threshold (png_structp png_ptr) +{ + return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L); +} +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ +#endif /* ?PNG_1_0_X */ + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* these functions were added to libpng 1.2.6 */ +png_uint_32 PNGAPI +png_get_user_width_max (png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_width_max : 0); +} +png_uint_32 PNGAPI +png_get_user_height_max (png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_height_max : 0); +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngmem.c ./win32/dependencies/libpng/pngmem.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngmem.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngmem.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,598 @@ + +/* pngmem.c - stub functions for memory allocation + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file provides a location for all memory allocation. Users who + * need special memory handling are expected to supply replacement + * functions for png_malloc() and png_free(), and to use + * png_create_read_struct_2() and png_create_write_struct_2() to + * identify the replacement functions. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +/* Borland DOS special memory handler */ +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* if you change this, be sure to change the one in png.h also */ + +/* Allocate memory for a png_struct. The malloc and memset can be replaced + by a single call to calloc() if this is thought to improve performance. */ +png_voidp /* PRIVATE */ +png_create_struct(int type) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); +} + +/* Alternate version of png_create_struct, for use with user-defined malloc. */ +png_voidp /* PRIVATE */ +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + else + return (png_get_copyright(NULL)); + +#ifdef PNG_USER_MEM_SUPPORTED + if(malloc_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size); + } + else +#endif /* PNG_USER_MEM_SUPPORTED */ + struct_ptr = (png_voidp)farmalloc(size); + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + return (struct_ptr); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +#endif + if (struct_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + if(free_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + (*(free_fn))(png_ptr, struct_ptr); + return; + } +#endif /* PNG_USER_MEM_SUPPORTED */ + farfree (struct_ptr); + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * Borland seems to have a problem in DOS mode for exactly 64K. + * It gives you a segment with an offset of 8 (perhaps to store its + * memory stuff). zlib doesn't like this at all, so we have to + * detect and deal with it. This code should not be needed in + * Windows or OS/2 modes, and only in 16 bit mode. This code has + * been updated by Alexander Lehmann for version 0.89 to waste less + * memory. + * + * Note that we can't use png_size_t for the "size" declaration, + * since on some systems a png_size_t is a 16-bit quantity, and as a + * result, we would be truncating potentially larger memory requests + * (which should cause a fatal error) and introducing major problems. + */ + +png_voidp PNGAPI +png_malloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + + if (png_ptr == NULL || size == 0) + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + if(png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); + else + ret = (png_malloc_default(png_ptr, size)); + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory!"); + return (ret); +} + +png_voidp PNGAPI +png_malloc_default(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; +#endif /* PNG_USER_MEM_SUPPORTED */ + +#ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { + png_warning(png_ptr, "Cannot Allocate > 64K"); + ret = NULL; + } + else +#endif + + if (size != (size_t)size) + ret = NULL; + else if (size == (png_uint_32)65536L) + { + if (png_ptr->offset_table == NULL) + { + /* try to see if we need to do any of this fancy stuff */ + ret = farmalloc(size); + if (ret == NULL || ((png_size_t)ret & 0xffff)) + { + int num_blocks; + png_uint_32 total_size; + png_bytep table; + int i; + png_byte huge * hptr; + + if (ret != NULL) + { + farfree(ret); + ret = NULL; + } + + if(png_ptr->zlib_window_bits > 14) + num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14)); + else + num_blocks = 1; + if (png_ptr->zlib_mem_level >= 7) + num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7)); + else + num_blocks++; + + total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; + + table = farmalloc(total_size); + + if (table == NULL) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */ + else + png_warning(png_ptr, "Out Of Memory."); +#endif + return (NULL); + } + + if ((png_size_t)table & 0xfff0) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, + "Farmalloc didn't return normalized pointer"); + else + png_warning(png_ptr, + "Farmalloc didn't return normalized pointer"); +#endif + return (NULL); + } + + png_ptr->offset_table = table; + png_ptr->offset_table_ptr = farmalloc(num_blocks * + png_sizeof (png_bytep)); + + if (png_ptr->offset_table_ptr == NULL) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */ + else + png_warning(png_ptr, "Out Of memory."); +#endif + return (NULL); + } + + hptr = (png_byte huge *)table; + if ((png_size_t)hptr & 0xf) + { + hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); + hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */ + } + for (i = 0; i < num_blocks; i++) + { + png_ptr->offset_table_ptr[i] = (png_bytep)hptr; + hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */ + } + + png_ptr->offset_table_number = num_blocks; + png_ptr->offset_table_count = 0; + png_ptr->offset_table_count_free = 0; + } + } + + if (png_ptr->offset_table_count >= png_ptr->offset_table_number) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */ + else + png_warning(png_ptr, "Out of Memory."); +#endif + return (NULL); + } + + ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; + } + else + ret = farmalloc(size); + +#ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL) + { + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */ + else + png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */ + } +#endif + + return (ret); +} + +/* free a pointer allocated by png_malloc(). In the default + configuration, png_ptr is not used, but is passed in case it + is needed. If ptr is NULL, return without taking any action. */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + else png_free_default(png_ptr, ptr); +} + +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr->offset_table != NULL) + { + int i; + + for (i = 0; i < png_ptr->offset_table_count; i++) + { + if (ptr == png_ptr->offset_table_ptr[i]) + { + ptr = NULL; + png_ptr->offset_table_count_free++; + break; + } + } + if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) + { + farfree(png_ptr->offset_table); + farfree(png_ptr->offset_table_ptr); + png_ptr->offset_table = NULL; + png_ptr->offset_table_ptr = NULL; + } + } + + if (ptr != NULL) + { + farfree(ptr); + } +} + +#else /* Not the Borland DOS special memory handler */ + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +png_voidp /* PRIVATE */ +png_create_struct(int type) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); +} + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +png_voidp /* PRIVATE */ +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + else + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + if(malloc_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, size); + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + return (struct_ptr); + } +#endif /* PNG_USER_MEM_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(__FLAT__) + struct_ptr = (png_voidp)farmalloc(size); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + struct_ptr = (png_voidp)halloc(size,1); +# else + struct_ptr = (png_voidp)malloc(size); +# endif +#endif + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + + return (struct_ptr); +} + + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + if (struct_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + if(free_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + (*(free_fn))(png_ptr, struct_ptr); + return; + } +#endif /* PNG_USER_MEM_SUPPORTED */ +#if defined(__TURBOC__) && !defined(__FLAT__) + farfree(struct_ptr); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(struct_ptr); +# else + free(struct_ptr); +# endif +#endif + } +} + +/* Allocate memory. For reasonable files, size should never exceed + 64K. However, zlib may allocate more then 64K if you don't tell + it not to. See zconf.h and png.h for more information. zlib does + need to allocate exactly 64K, so whatever you call here must + have the ability to do that. */ + +png_voidp PNGAPI +png_malloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr == NULL || size == 0) + return (NULL); + + if(png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); + else + ret = (png_malloc_default(png_ptr, size)); + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory!"); + return (ret); +} + +png_voidp PNGAPI +png_malloc_default(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; +#endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || size == 0) + return (NULL); + +#ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { +#ifndef PNG_USER_MEM_SUPPORTED + if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Cannot Allocate > 64K"); + else +#endif + return NULL; + } +#endif + + /* Check for overflow */ +#if defined(__TURBOC__) && !defined(__FLAT__) + if (size != (unsigned long)size) + ret = NULL; + else + ret = farmalloc(size); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + if (size != (unsigned long)size) + ret = NULL; + else + ret = halloc(size, 1); +# else + if (size != (size_t)size) + ret = NULL; + else + ret = malloc((size_t)size); +# endif +#endif + +#ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory"); +#endif + + return (ret); +} + +/* Free a pointer allocated by png_malloc(). If ptr is NULL, return + without taking any action. */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + else png_free_default(png_ptr, ptr); +} +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#endif /* PNG_USER_MEM_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(__FLAT__) + farfree(ptr); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(ptr); +# else + free(ptr); +# endif +#endif +} + +#endif /* Not Borland DOS special memory handler */ + +#if defined(PNG_1_0_X) +# define png_malloc_warn png_malloc +#else +/* This function was added at libpng version 1.2.3. The png_malloc_warn() + * function will set up png_malloc() to issue a png_warning and return NULL + * instead of issuing a png_error, if it fails to allocate the requested + * memory. + */ +png_voidp PNGAPI +png_malloc_warn(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ptr; + png_uint_32 save_flags=png_ptr->flags; + + png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); + png_ptr->flags=save_flags; + return(ptr); +} +#endif + +png_voidp PNGAPI +png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr,"Overflow in png_memcpy_check."); + + return(png_memcpy (s1, s2, size)); +} + +png_voidp PNGAPI +png_memset_check (png_structp png_ptr, png_voidp s1, int value, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr,"Overflow in png_memset_check."); + + return (png_memset (s1, value, size)); + +} + +#ifdef PNG_USER_MEM_SUPPORTED +/* This function is called when the application wants to use another method + * of allocating and freeing memory. + */ +void PNGAPI +png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr + malloc_fn, png_free_ptr free_fn) +{ + png_ptr->mem_ptr = mem_ptr; + png_ptr->malloc_fn = malloc_fn; + png_ptr->free_fn = free_fn; +} + +/* This function returns a pointer to the mem_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_mem_ptr(png_structp png_ptr) +{ + return ((png_voidp)png_ptr->mem_ptr); +} +#endif /* PNG_USER_MEM_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngpread.c ./win32/dependencies/libpng/pngpread.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngpread.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngpread.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,1573 @@ + +/* pngpread.c - read a png file in push mode + * + * Last changed in libpng 1.2.8 - December 3, 2004 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2004 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#include "png.h" + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + +/* push model modes */ +#define PNG_READ_SIG_MODE 0 +#define PNG_READ_CHUNK_MODE 1 +#define PNG_READ_IDAT_MODE 2 +#define PNG_SKIP_MODE 3 +#define PNG_READ_tEXt_MODE 4 +#define PNG_READ_zTXt_MODE 5 +#define PNG_READ_DONE_MODE 6 +#define PNG_READ_iTXt_MODE 7 +#define PNG_ERROR_MODE 8 + +void PNGAPI +png_process_data(png_structp png_ptr, png_infop info_ptr, + png_bytep buffer, png_size_t buffer_size) +{ + png_push_restore_buffer(png_ptr, buffer, buffer_size); + + while (png_ptr->buffer_size) + { + png_process_some_data(png_ptr, info_ptr); + } +} + +/* What we do with the incoming data depends on what we were previously + * doing before we ran out of data... + */ +void /* PRIVATE */ +png_process_some_data(png_structp png_ptr, png_infop info_ptr) +{ + switch (png_ptr->process_mode) + { + case PNG_READ_SIG_MODE: + { + png_push_read_sig(png_ptr, info_ptr); + break; + } + case PNG_READ_CHUNK_MODE: + { + png_push_read_chunk(png_ptr, info_ptr); + break; + } + case PNG_READ_IDAT_MODE: + { + png_push_read_IDAT(png_ptr); + break; + } +#if defined(PNG_READ_tEXt_SUPPORTED) + case PNG_READ_tEXt_MODE: + { + png_push_read_tEXt(png_ptr, info_ptr); + break; + } +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + case PNG_READ_zTXt_MODE: + { + png_push_read_zTXt(png_ptr, info_ptr); + break; + } +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + case PNG_READ_iTXt_MODE: + { + png_push_read_iTXt(png_ptr, info_ptr); + break; + } +#endif + case PNG_SKIP_MODE: + { + png_push_crc_finish(png_ptr); + break; + } + default: + { + png_ptr->buffer_size = 0; + break; + } + } +} + +/* Read any remaining signature bytes from the stream and compare them with + * the correct PNG signature. It is possible that this routine is called + * with bytes already read from the signature, either because they have been + * checked by the calling application, or because of multiple calls to this + * routine. + */ +void /* PRIVATE */ +png_push_read_sig(png_structp png_ptr, png_infop info_ptr) +{ + png_size_t num_checked = png_ptr->sig_bytes, + num_to_check = 8 - num_checked; + + if (png_ptr->buffer_size < num_to_check) + { + num_to_check = png_ptr->buffer_size; + } + + png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), + num_to_check); + png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check); + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + else + { + if (png_ptr->sig_bytes >= 8) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + } +} + +void /* PRIVATE */ +png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IHDR; + PNG_IDAT; + PNG_IEND; + PNG_PLTE; +#if defined(PNG_READ_bKGD_SUPPORTED) + PNG_bKGD; +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + PNG_cHRM; +#endif +#if defined(PNG_READ_gAMA_SUPPORTED) + PNG_gAMA; +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + PNG_hIST; +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + PNG_iCCP; +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + PNG_iTXt; +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + PNG_oFFs; +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + PNG_pCAL; +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + PNG_pHYs; +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + PNG_sBIT; +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + PNG_sCAL; +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + PNG_sRGB; +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + PNG_sPLT; +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + PNG_tEXt; +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + PNG_tIME; +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + PNG_tRNS; +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + PNG_zTXt; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + /* First we make sure we have enough data for the 4 byte chunk name + * and the 4 byte chunk length before proceeding with decoding the + * chunk data. To fully decode each of these chunks, we also make + * sure we have enough data in the buffer for the 4 byte CRC at the + * end of every chunk (except IDAT, which is handled separately). + */ + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + } + + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); + } + else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); + + png_ptr->process_mode = PNG_READ_DONE_MODE; + png_push_have_end(png_ptr, info_ptr); + } +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_ptr->mode |= PNG_HAVE_IDAT; + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + } + } +#endif + else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); + } + else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) + { + /* If we reach an IDAT chunk, this means we have read all of the + * header chunks, and we can start reading the image (or if this + * is called after the image has been read - we have an error). + */ + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + { + if (png_ptr->push_length == 0) + return; + + if (png_ptr->mode & PNG_AFTER_IDAT) + png_error(png_ptr, "Too many IDAT's found"); + } + + png_ptr->idat_size = png_ptr->push_length; + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + png_push_have_info(png_ptr, info_ptr); + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; + png_ptr->zstream.next_out = png_ptr->row_buf; + return; + } +#if defined(PNG_READ_gAMA_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_bKGD_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); + } +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); + } +#endif + else + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + } + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; +} + +void /* PRIVATE */ +png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) +{ + png_ptr->process_mode = PNG_SKIP_MODE; + png_ptr->skip_length = skip; +} + +void /* PRIVATE */ +png_push_crc_finish(png_structp png_ptr) +{ + if (png_ptr->skip_length && png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size) + save_size = (png_size_t)png_ptr->skip_length; + else + save_size = png_ptr->save_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->skip_length -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (png_ptr->skip_length && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size) + save_size = (png_size_t)png_ptr->skip_length; + else + save_size = png_ptr->current_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->skip_length -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + if (!png_ptr->skip_length) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } +} + +void PNGAPI +png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) +{ + png_bytep ptr; + + ptr = buffer; + if (png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->save_buffer_size) + save_size = length; + else + save_size = png_ptr->save_buffer_size; + + png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); + length -= save_size; + ptr += save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (length && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->current_buffer_size) + save_size = length; + else + save_size = png_ptr->current_buffer_size; + + png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } +} + +void /* PRIVATE */ +png_push_save_buffer(png_structp png_ptr) +{ + if (png_ptr->save_buffer_size) + { + if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) + { + png_size_t i,istop; + png_bytep sp; + png_bytep dp; + + istop = png_ptr->save_buffer_size; + for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; + i < istop; i++, sp++, dp++) + { + *dp = *sp; + } + } + } + if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > + png_ptr->save_buffer_max) + { + png_size_t new_max; + png_bytep old_buffer; + + if (png_ptr->save_buffer_size > PNG_SIZE_MAX - + (png_ptr->current_buffer_size + 256)) + { + png_error(png_ptr, "Potential overflow of save_buffer"); + } + new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; + old_buffer = png_ptr->save_buffer; + png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, + (png_uint_32)new_max); + png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); + png_free(png_ptr, old_buffer); + png_ptr->save_buffer_max = new_max; + } + if (png_ptr->current_buffer_size) + { + png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, + png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); + png_ptr->save_buffer_size += png_ptr->current_buffer_size; + png_ptr->current_buffer_size = 0; + } + png_ptr->save_buffer_ptr = png_ptr->save_buffer; + png_ptr->buffer_size = 0; +} + +void /* PRIVATE */ +png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + png_ptr->current_buffer = buffer; + png_ptr->current_buffer_size = buffer_length; + png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; + png_ptr->current_buffer_ptr = png_ptr->current_buffer; +} + +void /* PRIVATE */ +png_push_read_IDAT(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#endif + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + png_error(png_ptr, "Not enough compressed data"); + return; + } + + png_ptr->idat_size = png_ptr->push_length; + } + if (png_ptr->idat_size && png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size) + { + save_size = (png_size_t)png_ptr->idat_size; + /* check for overflow */ + if((png_uint_32)save_size != png_ptr->idat_size) + png_error(png_ptr, "save_size overflowed in pngpread"); + } + else + save_size = png_ptr->save_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); + png_ptr->idat_size -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (png_ptr->idat_size && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size) + { + save_size = (png_size_t)png_ptr->idat_size; + /* check for overflow */ + if((png_uint_32)save_size != png_ptr->idat_size) + png_error(png_ptr, "save_size overflowed in pngpread"); + } + else + save_size = png_ptr->current_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->idat_size -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + if (!png_ptr->idat_size) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + png_ptr->mode |= PNG_AFTER_IDAT; + } +} + +void /* PRIVATE */ +png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + int ret; + + if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length) + png_error(png_ptr, "Extra compression data"); + + png_ptr->zstream.next_in = buffer; + png_ptr->zstream.avail_in = (uInt)buffer_length; + for(;;) + { + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret != Z_OK) + { + if (ret == Z_STREAM_END) + { + if (png_ptr->zstream.avail_in) + png_error(png_ptr, "Extra compressed data"); + if (!(png_ptr->zstream.avail_out)) + { + png_push_process_row(png_ptr); + } + + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + else if (ret == Z_BUF_ERROR) + break; + else + png_error(png_ptr, "Decompression Error"); + } + if (!(png_ptr->zstream.avail_out)) + { + if (( +#if defined(PNG_READ_INTERLACING_SUPPORTED) + png_ptr->interlaced && png_ptr->pass > 6) || + (!png_ptr->interlaced && +#endif + png_ptr->row_number == png_ptr->num_rows)) + { + if (png_ptr->zstream.avail_in) + png_warning(png_ptr, "Too much data in IDAT chunks"); + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + png_push_process_row(png_ptr); + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; + png_ptr->zstream.next_out = png_ptr->row_buf; + } + else + break; + } +} + +void /* PRIVATE */ +png_push_process_row(png_structp png_ptr) +{ + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->iwidth; + png_ptr->row_info.channels = png_ptr->channels; + png_ptr->row_info.bit_depth = png_ptr->bit_depth; + png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; + + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + png_read_filter_row(png_ptr, &(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->prev_row + 1, + (int)(png_ptr->row_buf[0])); + + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); + + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) + /* blow up interlaced rows to full size */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) +/* old interface (pre-1.0.9): + png_do_read_interlace(&(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); + + switch (png_ptr->pass) + { + case 0: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 0; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */ + } + if (png_ptr->pass == 2) /* pass 1 might be empty */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + if (png_ptr->pass == 6 && png_ptr->height <= 4) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + break; + } + case 1: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 1; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + if (png_ptr->pass == 2) /* skip top 4 generated rows */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + break; + } + case 2: + { + int i; + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + if (png_ptr->pass == 4) /* pass 3 might be empty */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + break; + } + case 3: + { + int i; + for (i = 0; i < 4 && png_ptr->pass == 3; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + if (png_ptr->pass == 4) /* skip top two generated rows */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + break; + } + case 4: + { + int i; + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + if (png_ptr->pass == 6) /* pass 5 might be empty */ + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + break; + } + case 5: + { + int i; + for (i = 0; i < 2 && png_ptr->pass == 5; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + if (png_ptr->pass == 6) /* skip top generated row */ + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + break; + } + case 6: + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + if (png_ptr->pass != 6) + break; + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + } + else +#endif + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } +} + +void /* PRIVATE */ +png_read_push_finish_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + + /* Width of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h + const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; + */ + + /* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h + const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; + */ +#endif + + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + png_memset_check(png_ptr, png_ptr->prev_row, 0, + png_ptr->rowbytes + 1); + do + { + png_ptr->pass++; + if ((png_ptr->pass == 1 && png_ptr->width < 5) || + (png_ptr->pass == 3 && png_ptr->width < 3) || + (png_ptr->pass == 5 && png_ptr->width < 2)) + png_ptr->pass++; + + if (png_ptr->pass > 7) + png_ptr->pass--; + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + + if (png_ptr->transformations & PNG_INTERLACE) + break; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); + } +} + +#if defined(PNG_READ_tEXt_SUPPORTED) +void /* PRIVATE */ +png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place tEXt"); + /* to quiet some compiler warnings */ + if(info_ptr == NULL) return; + } + +#ifdef PNG_MAX_MALLOC_64K + png_ptr->skip_length = 0; /* This may not be necessary */ + + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ + { + png_warning(png_ptr, "tEXt chunk too large to fit in memory"); + png_ptr->skip_length = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length+1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_tEXt_MODE; +} + +void /* PRIVATE */ +png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + else + text_size = png_ptr->current_text_left; + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp text; + png_charp key; + int ret; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + +#if defined(PNG_MAX_MALLOC_64K) + if (png_ptr->skip_length) + return; +#endif + + key = png_ptr->current_text; + + for (text = key; *text; text++) + /* empty loop */ ; + + if (text != key + png_ptr->current_text_size) + text++; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; +#endif + text_ptr->text = text; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, key); + png_free(png_ptr, text_ptr); + png_ptr->current_text = NULL; + + if (ret) + png_warning(png_ptr, "Insufficient memory to store text chunk."); + } +} +#endif + +#if defined(PNG_READ_zTXt_SUPPORTED) +void /* PRIVATE */ +png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place zTXt"); + /* to quiet some compiler warnings */ + if(info_ptr == NULL) return; + } + +#ifdef PNG_MAX_MALLOC_64K + /* We can't handle zTXt chunks > 64K, since we don't have enough space + * to be able to store the uncompressed data. Actually, the threshold + * is probably around 32K, but it isn't as definite as 64K is. + */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "zTXt chunk too large to fit in memory"); + png_push_crc_skip(png_ptr, length); + return; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length+1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_zTXt_MODE; +} + +void /* PRIVATE */ +png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + else + text_size = png_ptr->current_text_left; + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp text; + png_charp key; + int ret; + png_size_t text_size, key_size; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + + key = png_ptr->current_text; + + for (text = key; *text; text++) + /* empty loop */ ; + + /* zTXt can't have zero text */ + if (text == key + png_ptr->current_text_size) + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + return; + } + + text++; + + if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */ + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + return; + } + + text++; + + png_ptr->zstream.next_in = (png_bytep )text; + png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - + (text - key)); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + key_size = text - key; + text_size = 0; + text = NULL; + ret = Z_STREAM_END; + + while (png_ptr->zstream.avail_in) + { + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret != Z_OK && ret != Z_STREAM_END) + { + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + png_ptr->current_text = NULL; + png_free(png_ptr, key); + png_free(png_ptr, text); + return; + } + if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) + { + if (text == NULL) + { + text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + + key_size + 1)); + png_memcpy(text + key_size, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + png_memcpy(text, key, key_size); + text_size = key_size + png_ptr->zbuf_size - + png_ptr->zstream.avail_out; + *(text + text_size) = '\0'; + } + else + { + png_charp tmp; + + tmp = text; + text = (png_charp)png_malloc(png_ptr, text_size + + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + + 1)); + png_memcpy(text, tmp, text_size); + png_free(png_ptr, tmp); + png_memcpy(text + text_size, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; + *(text + text_size) = '\0'; + } + if (ret != Z_STREAM_END) + { + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + else + { + break; + } + + if (ret == Z_STREAM_END) + break; + } + + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + + if (ret != Z_STREAM_END) + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + png_free(png_ptr, text); + return; + } + + png_ptr->current_text = NULL; + png_free(png_ptr, key); + key = text; + text += key_size; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; +#endif + text_ptr->text = text; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, key); + png_free(png_ptr, text_ptr); + + if (ret) + png_warning(png_ptr, "Insufficient memory to store text chunk."); + } +} +#endif + +#if defined(PNG_READ_iTXt_SUPPORTED) +void /* PRIVATE */ +png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place iTXt"); + /* to quiet some compiler warnings */ + if(info_ptr == NULL) return; + } + +#ifdef PNG_MAX_MALLOC_64K + png_ptr->skip_length = 0; /* This may not be necessary */ + + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ + { + png_warning(png_ptr, "iTXt chunk too large to fit in memory"); + png_ptr->skip_length = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length+1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_iTXt_MODE; +} + +void /* PRIVATE */ +png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) +{ + + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + else + text_size = png_ptr->current_text_left; + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp key; + int comp_flag; + png_charp lang; + png_charp lang_key; + png_charp text; + int ret; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + +#if defined(PNG_MAX_MALLOC_64K) + if (png_ptr->skip_length) + return; +#endif + + key = png_ptr->current_text; + + for (lang = key; *lang; lang++) + /* empty loop */ ; + + if (lang != key + png_ptr->current_text_size) + lang++; + + comp_flag = *lang++; + lang++; /* skip comp_type, always zero */ + + for (lang_key = lang; *lang_key; lang_key++) + /* empty loop */ ; + lang_key++; /* skip NUL separator */ + + for (text = lang_key; *text; text++) + /* empty loop */ ; + + if (text != key + png_ptr->current_text_size) + text++; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + text_ptr->compression = comp_flag + 2; + text_ptr->key = key; + text_ptr->lang = lang; + text_ptr->lang_key = lang_key; + text_ptr->text = text; + text_ptr->text_length = 0; + text_ptr->itxt_length = png_strlen(text); + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_ptr->current_text = NULL; + + png_free(png_ptr, text_ptr); + if (ret) + png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); + } +} +#endif + +/* This function is called when we haven't found a handler for this + * chunk. If there isn't a problem with the chunk itself (ie a bad chunk + * name or a critical chunk), the chunk is (currently) silently ignored. + */ +void /* PRIVATE */ +png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + png_uint_32 skip=0; + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + + if (!(png_ptr->chunk_name[0] & 0x20)) + { +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS +#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) + && png_ptr->read_user_chunk_fn == NULL +#endif + ) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + + /* to quiet compiler warnings about unused info_ptr */ + if (info_ptr == NULL) + return; + } + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) + { + png_unknown_chunk chunk; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "unknown chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); + chunk.data = (png_bytep)png_malloc(png_ptr, length); + png_crc_read(png_ptr, chunk.data, length); + chunk.size = length; +#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) + if(png_ptr->read_user_chunk_fn != NULL) + { + /* callback to user unknown chunk handler */ + if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0) + { + if (!(png_ptr->chunk_name[0] & 0x20)) + if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS) + png_chunk_error(png_ptr, "unknown critical chunk"); + } + png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1); + } + else +#endif + png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1); + png_free(png_ptr, chunk.data); + } + else +#endif + skip=length; + png_push_crc_skip(png_ptr, skip); +} + +void /* PRIVATE */ +png_push_have_info(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->info_fn != NULL) + (*(png_ptr->info_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_end(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->end_fn != NULL) + (*(png_ptr->end_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_row(png_structp png_ptr, png_bytep row) +{ + if (png_ptr->row_fn != NULL) + (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, + (int)png_ptr->pass); +} + +void PNGAPI +png_progressive_combine_row (png_structp png_ptr, + png_bytep old_row, png_bytep new_row) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + const int FARDATA png_pass_dsp_mask[7] = + {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; +#endif + if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ + png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); +} + +void PNGAPI +png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn) +{ + png_ptr->info_fn = info_fn; + png_ptr->row_fn = row_fn; + png_ptr->end_fn = end_fn; + + png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); +} + +png_voidp PNGAPI +png_get_progressive_ptr(png_structp png_ptr) +{ + return png_ptr->io_ptr; +} +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngread.c ./win32/dependencies/libpng/pngread.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngread.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngread.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,1459 @@ + +/* pngread.c - read a PNG file + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file contains routines that an application calls directly to + * read a PNG file or stream. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) + +/* Create a PNG structure for reading, and allocate any memory needed. */ +png_structp PNGAPI +png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn) +{ + +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); +} + +/* Alternate create PNG structure for reading, and allocate any memory needed. */ +png_structp PNGAPI +png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + + png_structp png_ptr; + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + + int i; + + png_debug(1, "in png_create_read_struct\n"); +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif + if (png_ptr == NULL) + return (NULL); + +#if !defined(PNG_1_0_X) +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED + png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ +#endif +#endif /* PNG_1_0_X */ + + /* added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max=PNG_USER_WIDTH_MAX; + png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_ptr->jmpbuf)) +#endif + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf=NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); +#endif +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif + + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + i=0; + do + { + if(user_png_ver[i] != png_libpng_ver[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + } while (png_libpng_ver[i++]); + + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so + * we must recompile any applications that use any older library version. + * For versions after libpng 1.0, we will be compatible, so we need + * only check the first digit. + */ + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || + (user_png_ver[0] == '0' && user_png_ver[2] < '9')) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "Incompatible libpng version in application and library"); + } + } + + /* initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: /* Do nothing */ break; + case Z_MEM_ERROR: + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; + default: png_error(png_ptr, "Unknown zlib error"); + } + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then encounter + a png_error() will longjmp here. Since the jmpbuf is then meaningless we + abort instead of returning. */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif + return (png_ptr); +} + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Initialize PNG structure for reading, and allocate any memory needed. + This interface is deprecated in favour of the png_create_read_struct(), + and it will disappear as of libpng-1.3.0. */ +#undef png_read_init +void PNGAPI +png_read_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + if(png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn=NULL; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if(png_sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn=NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for reading is too small."); + } + if(png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn=NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The info struct allocated by application for reading is too small."); + } + png_read_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + +void PNGAPI +png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i=0; + + png_structp png_ptr=*ptr_ptr; + + do + { + if(user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; +#else + png_ptr->warning_fn=NULL; + png_warning(png_ptr, + "Application uses deprecated png_read_init() and should be recompiled."); + break; +#endif + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_read_init_3\n"); + +#ifdef PNG_SETJMP_SUPPORTED + /* save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); +#endif + + if(png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + png_ptr = *ptr_ptr; + } + + /* reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof (png_struct)); + +#ifdef PNG_SETJMP_SUPPORTED + /* restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); +#endif + + /* added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max=PNG_USER_WIDTH_MAX; + png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; +#endif + + /* initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: /* Do nothing */ break; + case Z_MEM_ERROR: + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break; + default: png_error(png_ptr, "Unknown zlib error"); + } + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); +} + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. This has been + * changed in v0.90 to allow reading a file that already has the magic + * bytes read from the stream. You can tell libpng how many bytes have + * been read from the beginning of the stream (up to the maximum of 8) + * via png_set_sig_bytes(), and we will only check the remaining bytes + * here. The application can then have access to the signature bytes we + * read if it is determined that this isn't a valid PNG file. + */ +void PNGAPI +png_read_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_info\n"); + /* If we haven't checked all of the PNG signature bytes, do so now. */ + if (png_ptr->sig_bytes < 8) + { + png_size_t num_checked = png_ptr->sig_bytes, + num_to_check = 8 - num_checked; + + png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); + png_ptr->sig_bytes = 8; + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; + } + + for(;;) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IHDR; + PNG_IDAT; + PNG_IEND; + PNG_PLTE; +#if defined(PNG_READ_bKGD_SUPPORTED) + PNG_bKGD; +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + PNG_cHRM; +#endif +#if defined(PNG_READ_gAMA_SUPPORTED) + PNG_gAMA; +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + PNG_hIST; +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + PNG_iCCP; +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + PNG_iTXt; +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + PNG_oFFs; +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + PNG_pCAL; +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + PNG_pHYs; +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + PNG_sBIT; +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + PNG_sCAL; +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + PNG_sPLT; +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + PNG_sRGB; +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + PNG_tEXt; +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + PNG_tIME; +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + PNG_tRNS; +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + PNG_zTXt; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + png_byte chunk_length[4]; + png_uint_32 length; + + png_read_data(png_ptr, chunk_length, 4); + length = png_get_uint_31(png_ptr,chunk_length); + + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + + png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name, + length); + + /* This should be a binary subdivision search or a hash for + * matching the chunk name rather than a linear search. + */ + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) + png_handle_IHDR(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_ptr->mode |= PNG_HAVE_IDAT; + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + break; + } + } +#endif + else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_handle_PLTE(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + png_ptr->idat_size = length; + png_ptr->mode |= PNG_HAVE_IDAT; + break; + } +#if defined(PNG_READ_bKGD_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_gAMA_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) + png_handle_hIST(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) + png_handle_tIME(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + else + png_handle_unknown(png_ptr, info_ptr, length); + } +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +/* optional call to update the users info_ptr structure */ +void PNGAPI +png_read_update_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_update_info\n"); + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); + else + png_warning(png_ptr, + "Ignoring extra png_read_update_info() call; row buffer not reallocated"); + png_read_transform_info(png_ptr, info_ptr); +} + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Initialize palette, background, etc, after transformations + * are set, but before any reading takes place. This allows + * the user to obtain a gamma-corrected palette, for example. + * If the user doesn't call this, we will do it ourselves. + */ +void PNGAPI +png_start_read_image(png_structp png_ptr) +{ + png_debug(1, "in png_start_read_image\n"); + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +void PNGAPI +png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; + const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; + const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; +#endif + int ret; + png_debug2(1, "in png_read_row (row %lu, pass %d)\n", + png_ptr->row_number, png_ptr->pass); + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* check for transforms that have been set but were defined out */ +#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); +#endif + } + +#if defined(PNG_READ_INTERLACING_SUPPORTED) + /* if interlaced and we do not need a new row, combine row and return */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + if (dsp_row != NULL && (png_ptr->row_number & 4)) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 3: + if ((png_ptr->row_number & 3) || png_ptr->width < 3) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 4: + if ((png_ptr->row_number & 3) != 2) + { + if (dsp_row != NULL && (png_ptr->row_number & 2)) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 5: + if ((png_ptr->row_number & 1) || png_ptr->width < 2) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 6: + if (!(png_ptr->row_number & 1)) + { + png_read_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "Invalid attempt to read row data"); + + png_ptr->zstream.next_out = png_ptr->row_buf; + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; + do + { + if (!(png_ptr->zstream.avail_in)) + { + while (!png_ptr->idat_size) + { + png_byte chunk_length[4]; + + png_crc_finish(png_ptr, 0); + + png_read_data(png_ptr, chunk_length, 4); + png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length); + + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_error(png_ptr, "Not enough image data"); + } + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + png_crc_read(png_ptr, png_ptr->zbuf, + (png_size_t)png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret == Z_STREAM_END) + { + if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_error(png_ptr, "Extra compressed data"); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression error"); + + } while (png_ptr->zstream.avail_out); + + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->iwidth; + png_ptr->row_info.channels = png_ptr->channels; + png_ptr->row_info.bit_depth = png_ptr->bit_depth; + png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + if(png_ptr->row_buf[0]) + png_read_filter_row(png_ptr, &(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->prev_row + 1, + (int)(png_ptr->row_buf[0])); + + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); + +#if defined(PNG_MNG_FEATURES_SUPPORTED) + if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + } +#endif + + + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) + /* blow up interlaced rows to full size */ + if (png_ptr->interlaced && + (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) +/* old interface (pre-1.0.9): + png_do_read_interlace(&(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + if (row != NULL) + png_combine_row(png_ptr, row, + png_pass_mask[png_ptr->pass]); + } + else +#endif + { + if (row != NULL) + png_combine_row(png_ptr, row, 0xff); + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 0xff); + } + png_read_finish_row(png_ptr); + + if (png_ptr->read_row_fn != NULL) + (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. If the image is interlaced, + * and png_set_interlace_handling() has been called, the rows need to + * contain the contents of the rows from the previous pass. If the + * image has alpha or transparency, and png_handle_alpha()[*] has been + * called, the rows contents must be initialized to the contents of the + * screen. + * + * "row" holds the actual image, and pixels are placed in it + * as they arrive. If the image is displayed after each pass, it will + * appear to "sparkle" in. "display_row" can be used to display a + * "chunky" progressive image, with finer detail added as it becomes + * available. If you do not want this "chunky" display, you may pass + * NULL for display_row. If you do not want the sparkle display, and + * you have not called png_handle_alpha(), you may pass NULL for rows. + * If you have called png_handle_alpha(), and the image has either an + * alpha channel or a transparency chunk, you must provide a buffer for + * rows. In this case, you do not have to provide a display_row buffer + * also, but you may. If the image is not interlaced, or if you have + * not called png_set_interlace_handling(), the display_row buffer will + * be ignored, so pass NULL to it. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ + +void PNGAPI +png_read_rows(png_structp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows) +{ + png_uint_32 i; + png_bytepp rp; + png_bytepp dp; + + png_debug(1, "in png_read_rows\n"); + rp = row; + dp = display_row; + if (rp != NULL && dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp++; + png_bytep dptr = *dp++; + + png_read_row(png_ptr, rptr, dptr); + } + else if(rp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp; + png_read_row(png_ptr, rptr, png_bytep_NULL); + rp++; + } + else if(dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep dptr = *dp; + png_read_row(png_ptr, png_bytep_NULL, dptr); + dp++; + } +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read the entire image. If the image has an alpha channel or a tRNS + * chunk, and you have called png_handle_alpha()[*], you will need to + * initialize the image to the current image that PNG will be overlaying. + * We set the num_rows again here, in case it was incorrectly set in + * png_read_start_row() by a call to png_read_update_info() or + * png_start_read_image() if png_set_interlace_handling() wasn't called + * prior to either of these functions like it should have been. You can + * only call this function once. If you desire to have an image for + * each pass of a interlaced image, use png_read_rows() instead. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ +void PNGAPI +png_read_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i,image_height; + int pass, j; + png_bytepp rp; + + png_debug(1, "in png_read_image\n"); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + pass = png_set_interlace_handling(png_ptr); +#else + if (png_ptr->interlaced) + png_error(png_ptr, + "Cannot read interlaced image -- interlace handler disabled."); + pass = 1; +#endif + + + image_height=png_ptr->height; + png_ptr->num_rows = image_height; /* Make sure this is set correctly */ + + for (j = 0; j < pass; j++) + { + rp = image; + for (i = 0; i < image_height; i++) + { + png_read_row(png_ptr, *rp, png_bytep_NULL); + rp++; + } + } +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. Will not read past the end of the + * file, will verify the end is accurate, and will read any comments + * or time information at the end of the file, if info is not NULL. + */ +void PNGAPI +png_read_end(png_structp png_ptr, png_infop info_ptr) +{ + png_byte chunk_length[4]; + png_uint_32 length; + + png_debug(1, "in png_read_end\n"); + png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ + + do + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IHDR; + PNG_IDAT; + PNG_IEND; + PNG_PLTE; +#if defined(PNG_READ_bKGD_SUPPORTED) + PNG_bKGD; +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + PNG_cHRM; +#endif +#if defined(PNG_READ_gAMA_SUPPORTED) + PNG_gAMA; +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + PNG_hIST; +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + PNG_iCCP; +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + PNG_iTXt; +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + PNG_oFFs; +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + PNG_pCAL; +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + PNG_pHYs; +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + PNG_sBIT; +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + PNG_sCAL; +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + PNG_sPLT; +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + PNG_sRGB; +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + PNG_tEXt; +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + PNG_tIME; +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + PNG_tRNS; +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + PNG_zTXt; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + + png_read_data(png_ptr, chunk_length, 4); + length = png_get_uint_31(png_ptr,chunk_length); + + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + + png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name); + + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) + png_handle_IHDR(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) + png_error(png_ptr, "Too many IDAT's found"); + } + else + png_ptr->mode |= PNG_AFTER_IDAT; + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + /* Zero length IDATs are legal after the last IDAT has been + * read, but not after other chunks have been read. + */ + if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) + png_error(png_ptr, "Too many IDAT's found"); + png_crc_finish(png_ptr, length); + } + else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_handle_PLTE(png_ptr, info_ptr, length); +#if defined(PNG_READ_bKGD_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_cHRM_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_gAMA_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_hIST_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) + png_handle_hIST(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_oFFs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_pCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sCAL_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_pHYs_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sBIT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sRGB_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_iCCP_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_sPLT_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tEXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tIME_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) + png_handle_tIME(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_tRNS_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_zTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_iTXt_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + else + png_handle_unknown(png_ptr, info_ptr, length); + } while (!(png_ptr->mode & PNG_HAVE_IEND)); +} +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ + +/* free all memory used by the read */ +void PNGAPI +png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, + png_infopp end_info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL, end_info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; + png_voidp mem_ptr; +#endif + + png_debug(1, "in png_destroy_read_struct\n"); + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (end_info_ptr_ptr != NULL) + end_info_ptr = *end_info_ptr_ptr; + +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; +#endif + + png_read_destroy(png_ptr, info_ptr, end_info_ptr); + + if (info_ptr != NULL) + { +#if defined(PNG_TEXT_SUPPORTED) + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (end_info_ptr != NULL) + { +#if defined(PNG_READ_TEXT_SUPPORTED) + png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); +#endif +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)end_info_ptr); +#endif + *end_info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + +/* free all memory used by the read (old method) */ +void /* PRIVATE */ +png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; +#endif + png_error_ptr error_fn; + png_error_ptr warning_fn; + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_read_destroy\n"); + if (info_ptr != NULL) + png_info_destroy(png_ptr, info_ptr); + + if (end_info_ptr != NULL) + png_info_destroy(png_ptr, end_info_ptr); + + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->prev_row); +#if defined(PNG_READ_DITHER_SUPPORTED) + png_free(png_ptr, png_ptr->palette_lookup); + png_free(png_ptr, png_ptr->dither_index); +#endif +#if defined(PNG_READ_GAMMA_SUPPORTED) + png_free(png_ptr, png_ptr->gamma_table); +#endif +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + png_free(png_ptr, png_ptr->gamma_from_1); + png_free(png_ptr, png_ptr->gamma_to_1); +#endif +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->free_me &= ~PNG_FREE_PLTE; +#else + if (png_ptr->flags & PNG_FLAG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif +#if defined(PNG_tRNS_SUPPORTED) || \ + defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans); + png_ptr->free_me &= ~PNG_FREE_TRNS; +#else + if (png_ptr->flags & PNG_FLAG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans); + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif +#endif +#if defined(PNG_READ_hIST_SUPPORTED) +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->free_me &= ~PNG_FREE_HIST; +#else + if (png_ptr->flags & PNG_FLAG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif +#endif +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (png_ptr->gamma_16_table != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_table[i]); + } + png_free(png_ptr, png_ptr->gamma_16_table); + } +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_from_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_from_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_from_1); + } + if (png_ptr->gamma_16_to_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_to_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_to_1); + } +#endif +#endif +#if defined(PNG_TIME_RFC1123_SUPPORTED) + png_free(png_ptr, png_ptr->time_buffer); +#endif + + inflateEnd(&png_ptr->zstream); +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_free(png_ptr, png_ptr->save_buffer); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +#ifdef PNG_TEXT_SUPPORTED + png_free(png_ptr, png_ptr->current_text); +#endif /* PNG_TEXT_SUPPORTED */ +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + + /* Save the important info out of the png_struct, in case it is + * being used again. + */ +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; + warning_fn = png_ptr->warning_fn; + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof (png_struct)); + + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); +#endif + +} + +void PNGAPI +png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) +{ + png_ptr->read_row_fn = read_row_fn; +} + + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +#if defined(PNG_INFO_IMAGE_SUPPORTED) +void PNGAPI +png_read_png(png_structp png_ptr, png_infop info_ptr, + int transforms, + voidp params) +{ + int row; + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) + /* invert the alpha channel from opacity to transparency + */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + + /* png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). + */ + png_read_info(png_ptr, info_ptr); + if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error(png_ptr,"Image is too high to process with png_read_png()"); + + /* -------------- image transformations start here ------------------- */ + +#if defined(PNG_READ_16_TO_8_SUPPORTED) + /* tell libpng to strip 16 bit/color files down to 8 bits per color + */ + if (transforms & PNG_TRANSFORM_STRIP_16) + png_set_strip_16(png_ptr); +#endif + +#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) + /* Strip alpha bytes from the input data without combining with + * the background (not recommended). + */ + if (transforms & PNG_TRANSFORM_STRIP_ALPHA) + png_set_strip_alpha(png_ptr); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) + /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). + */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) + /* Expand paletted colors into true RGB triplets + * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel + * Expand paletted or RGB images with transparency to full alpha + * channels so the data will be available as RGBA quartets. + */ + if (transforms & PNG_TRANSFORM_EXPAND) + if ((png_ptr->bit_depth < 8) || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || + (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) + png_set_expand(png_ptr); +#endif + + /* We don't handle background color or gamma transformation or dithering. + */ + +#if defined(PNG_READ_INVERT_SUPPORTED) + /* invert monochrome files to have 0 as white and 1 as black + */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) + { + png_color_8p sig_bit; + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + png_set_shift(png_ptr, sig_bit); + } +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) + /* flip the RGB pixels to BGR (or RGBA to BGRA) + */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) + /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) + */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) + /* swap bytes of 16 bit files to least significant byte first + */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + + /* We don't handle adding filler bytes */ + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (i.e., you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* -------------- image transformations end here ------------------- */ + +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); +#endif + if(info_ptr->row_pointers == NULL) + { + info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, + info_ptr->height * png_sizeof(png_bytep)); +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_ROWS; +#endif + for (row = 0; row < (int)info_ptr->height; row++) + { + info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, + png_get_rowbytes(png_ptr, info_ptr)); + } + } + + png_read_image(png_ptr, info_ptr->row_pointers); + info_ptr->valid |= PNG_INFO_IDAT; + + /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); + + if(transforms == 0 || params == NULL) + /* quiet compiler warnings */ return; + +} +#endif /* PNG_INFO_IMAGE_SUPPORTED */ +#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrio.c ./win32/dependencies/libpng/pngrio.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrio.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngrio.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,164 @@ + +/* pngrio.c - functions for data input + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file provides a location for all input. Users who need + * special handling are expected to write a function that has the same + * arguments as this and performs a similar function, but that possibly + * has a different input method. Note that you shouldn't change this + * function, but rather write a replacement function and then make + * libpng use it at run time with png_set_read_fn(...). + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) + +/* Read the data from whatever input you are using. The default routine + reads from a file pointer. Note that this routine sometimes gets called + with very small lengths, so you should implement some kind of simple + buffering if you are using unbuffered reads. This should never be asked + to read more then 64K on a 16 bit machine. */ +void /* PRIVATE */ +png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_debug1(4,"reading %d bytes\n", (int)length); + if (png_ptr->read_data_fn != NULL) + (*(png_ptr->read_data_fn))(png_ptr, data, length); + else + png_error(png_ptr, "Call to NULL read function"); +} + +#if !defined(PNG_NO_STDIO) +/* This is the function that does the actual reading of data. If you are + not reading from a standard C stream, you should create a replacement + read_data function and use it at run time with png_set_read_fn(), rather + than changing the library. */ +#ifndef USE_FAR_KEYWORD +void PNGAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = (png_size_t)fread(data, (png_size_t)1, length, + (png_FILE_p)png_ptr->io_ptr); +#endif + + if (check != length) + png_error(png_ptr, "Read Error"); +} +#else +/* this is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void PNGAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + int check; + png_byte *n_data; + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + n_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)n_data == data) + { +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = fread(n_data, 1, length, io_ptr); +#endif + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t read, remaining, err; + check = 0; + remaining = length; + do + { + read = MIN(NEAR_BUF_SIZE, remaining); +#if defined(_WIN32_WCE) + if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) + err = 0; +#else + err = fread(buf, (png_size_t)1, read, io_ptr); +#endif + png_memcpy(data, buf, read); /* copy far buffer to near buffer */ + if(err != read) + break; + else + check += err; + data += read; + remaining -= read; + } + while (remaining != 0); + } + if ((png_uint_32)check != (png_uint_32)length) + png_error(png_ptr, "read Error"); +} +#endif +#endif + +/* This function allows the application to supply a new input function + for libpng if standard C streams aren't being used. + + This function takes as its arguments: + png_ptr - pointer to a png input data structure + io_ptr - pointer to user supplied structure containing info about + the input functions. May be NULL. + read_data_fn - pointer to a new input function that takes as its + arguments a pointer to a png_struct, a pointer to + a location where input data can be stored, and a 32-bit + unsigned int that is the number of bytes to be read. + To exit and output any fatal error messages the new write + function should call png_error(png_ptr, "Error msg"). */ +void PNGAPI +png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn) +{ + png_ptr->io_ptr = io_ptr; + +#if !defined(PNG_NO_STDIO) + if (read_data_fn != NULL) + png_ptr->read_data_fn = read_data_fn; + else + png_ptr->read_data_fn = png_default_read_data; +#else + png_ptr->read_data_fn = read_data_fn; +#endif + + /* It is an error to write to a read device */ + if (png_ptr->write_data_fn != NULL) + { + png_ptr->write_data_fn = NULL; + png_warning(png_ptr, + "It's an error to set both read_data_fn and write_data_fn in the "); + png_warning(png_ptr, + "same structure. Resetting write_data_fn to NULL."); + } + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) + png_ptr->output_flush_fn = NULL; +#endif +} +#endif /* PNG_READ_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrtran.c ./win32/dependencies/libpng/pngrtran.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrtran.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngrtran.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,4219 @@ + +/* pngrtran.c - transforms the data in a row for PNG readers + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file contains functions optionally called by an application + * in order to tell libpng how to handle data when reading a PNG. + * Transformations that are used in both reading and writing are + * in pngtrans.c. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) + +/* Set the action on getting a CRC error for an ancillary or critical chunk. */ +void PNGAPI +png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) +{ + png_debug(1, "in png_set_crc_action\n"); + /* Tell libpng how we react to CRC errors in critical chunks */ + switch (crit_action) + { + case PNG_CRC_NO_CHANGE: /* leave setting as is */ + break; + case PNG_CRC_WARN_USE: /* warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; + break; + case PNG_CRC_QUIET_USE: /* quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | + PNG_FLAG_CRC_CRITICAL_IGNORE; + break; + case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */ + png_warning(png_ptr, "Can't discard critical data on CRC error."); + case PNG_CRC_ERROR_QUIT: /* error/quit */ + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + break; + } + + switch (ancil_action) + { + case PNG_CRC_NO_CHANGE: /* leave setting as is */ + break; + case PNG_CRC_WARN_USE: /* warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; + break; + case PNG_CRC_QUIET_USE: /* quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE | + PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + case PNG_CRC_ERROR_QUIT: /* error/quit */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + case PNG_CRC_WARN_DISCARD: /* warn/discard data */ + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + break; + } +} + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) +/* handle alpha and tRNS via a background color */ +void PNGAPI +png_set_background(png_structp png_ptr, + png_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma) +{ + png_debug(1, "in png_set_background\n"); + if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) + { + png_warning(png_ptr, "Application must supply a known background gamma"); + return; + } + + png_ptr->transformations |= PNG_BACKGROUND; + png_memcpy(&(png_ptr->background), background_color, + png_sizeof(png_color_16)); + png_ptr->background_gamma = (float)background_gamma; + png_ptr->background_gamma_type = (png_byte)(background_gamma_code); + png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); + + /* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA + * (in which case need_expand is superfluous anyway), the background color + * might actually be gray yet not be flagged as such. This is not a problem + * for the current code, which uses PNG_BACKGROUND_IS_GRAY only to + * decide when to do the png_do_gray_to_rgb() transformation. + */ + if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) || + (!need_expand && background_color->red == background_color->green && + background_color->red == background_color->blue)) + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; +} +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) +/* strip 16 bit depth files to 8 bit depth */ +void PNGAPI +png_set_strip_16(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_16\n"); + png_ptr->transformations |= PNG_16_TO_8; +} +#endif + +#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +void PNGAPI +png_set_strip_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_alpha\n"); + png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; +} +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) +/* Dither file to 8 bit. Supply a palette, the current number + * of elements in the palette, the maximum number of elements + * allowed, and a histogram if possible. If the current number + * of colors is greater then the maximum number, the palette will be + * modified to fit in the maximum number. "full_dither" indicates + * whether we need a dithering cube set up for RGB images, or if we + * simply are reducing the number of colors in a paletted image. + */ + +typedef struct png_dsort_struct +{ + struct png_dsort_struct FAR * next; + png_byte left; + png_byte right; +} png_dsort; +typedef png_dsort FAR * png_dsortp; +typedef png_dsort FAR * FAR * png_dsortpp; + +void PNGAPI +png_set_dither(png_structp png_ptr, png_colorp palette, + int num_palette, int maximum_colors, png_uint_16p histogram, + int full_dither) +{ + png_debug(1, "in png_set_dither\n"); + png_ptr->transformations |= PNG_DITHER; + + if (!full_dither) + { + int i; + + png_ptr->dither_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof (png_byte))); + for (i = 0; i < num_palette; i++) + png_ptr->dither_index[i] = (png_byte)i; + } + + if (num_palette > maximum_colors) + { + if (histogram != NULL) + { + /* This is easy enough, just throw out the least used colors. + Perhaps not the best solution, but good enough. */ + + int i; + + /* initialize an array to sort colors */ + png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof (png_byte))); + + /* initialize the dither_sort array */ + for (i = 0; i < num_palette; i++) + png_ptr->dither_sort[i] = (png_byte)i; + + /* Find the least used palette entries by starting a + bubble sort, and running it until we have sorted + out enough colors. Note that we don't care about + sorting all the colors, just finding which are + least used. */ + + for (i = num_palette - 1; i >= maximum_colors; i--) + { + int done; /* to stop early if the list is pre-sorted */ + int j; + + done = 1; + for (j = 0; j < i; j++) + { + if (histogram[png_ptr->dither_sort[j]] + < histogram[png_ptr->dither_sort[j + 1]]) + { + png_byte t; + + t = png_ptr->dither_sort[j]; + png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1]; + png_ptr->dither_sort[j + 1] = t; + done = 0; + } + } + if (done) + break; + } + + /* swap the palette around, and set up a table, if necessary */ + if (full_dither) + { + int j = num_palette; + + /* put all the useful colors within the max, but don't + move the others */ + for (i = 0; i < maximum_colors; i++) + { + if ((int)png_ptr->dither_sort[i] >= maximum_colors) + { + do + j--; + while ((int)png_ptr->dither_sort[j] >= maximum_colors); + palette[i] = palette[j]; + } + } + } + else + { + int j = num_palette; + + /* move all the used colors inside the max limit, and + develop a translation table */ + for (i = 0; i < maximum_colors; i++) + { + /* only move the colors we need to */ + if ((int)png_ptr->dither_sort[i] >= maximum_colors) + { + png_color tmp_color; + + do + j--; + while ((int)png_ptr->dither_sort[j] >= maximum_colors); + + tmp_color = palette[j]; + palette[j] = palette[i]; + palette[i] = tmp_color; + /* indicate where the color went */ + png_ptr->dither_index[j] = (png_byte)i; + png_ptr->dither_index[i] = (png_byte)j; + } + } + + /* find closest color for those colors we are not using */ + for (i = 0; i < num_palette; i++) + { + if ((int)png_ptr->dither_index[i] >= maximum_colors) + { + int min_d, k, min_k, d_index; + + /* find the closest color to one we threw out */ + d_index = png_ptr->dither_index[i]; + min_d = PNG_COLOR_DIST(palette[d_index], palette[0]); + for (k = 1, min_k = 0; k < maximum_colors; k++) + { + int d; + + d = PNG_COLOR_DIST(palette[d_index], palette[k]); + + if (d < min_d) + { + min_d = d; + min_k = k; + } + } + /* point to closest color */ + png_ptr->dither_index[i] = (png_byte)min_k; + } + } + } + png_free(png_ptr, png_ptr->dither_sort); + png_ptr->dither_sort=NULL; + } + else + { + /* This is much harder to do simply (and quickly). Perhaps + we need to go through a median cut routine, but those + don't always behave themselves with only a few colors + as input. So we will just find the closest two colors, + and throw out one of them (chosen somewhat randomly). + [We don't understand this at all, so if someone wants to + work on improving it, be our guest - AED, GRP] + */ + int i; + int max_d; + int num_new_palette; + png_dsortp t; + png_dsortpp hash; + + t=NULL; + + /* initialize palette index arrays */ + png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof (png_byte))); + png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof (png_byte))); + + /* initialize the sort array */ + for (i = 0; i < num_palette; i++) + { + png_ptr->index_to_palette[i] = (png_byte)i; + png_ptr->palette_to_index[i] = (png_byte)i; + } + + hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 * + png_sizeof (png_dsortp))); + for (i = 0; i < 769; i++) + hash[i] = NULL; +/* png_memset(hash, 0, 769 * png_sizeof (png_dsortp)); */ + + num_new_palette = num_palette; + + /* initial wild guess at how far apart the farthest pixel + pair we will be eliminating will be. Larger + numbers mean more areas will be allocated, Smaller + numbers run the risk of not saving enough data, and + having to do this all over again. + + I have not done extensive checking on this number. + */ + max_d = 96; + + while (num_new_palette > maximum_colors) + { + for (i = 0; i < num_new_palette - 1; i++) + { + int j; + + for (j = i + 1; j < num_new_palette; j++) + { + int d; + + d = PNG_COLOR_DIST(palette[i], palette[j]); + + if (d <= max_d) + { + + t = (png_dsortp)png_malloc_warn(png_ptr, + (png_uint_32)(png_sizeof(png_dsort))); + if (t == NULL) + break; + t->next = hash[d]; + t->left = (png_byte)i; + t->right = (png_byte)j; + hash[d] = t; + } + } + if (t == NULL) + break; + } + + if (t != NULL) + for (i = 0; i <= max_d; i++) + { + if (hash[i] != NULL) + { + png_dsortp p; + + for (p = hash[i]; p; p = p->next) + { + if ((int)png_ptr->index_to_palette[p->left] + < num_new_palette && + (int)png_ptr->index_to_palette[p->right] + < num_new_palette) + { + int j, next_j; + + if (num_new_palette & 0x01) + { + j = p->left; + next_j = p->right; + } + else + { + j = p->right; + next_j = p->left; + } + + num_new_palette--; + palette[png_ptr->index_to_palette[j]] + = palette[num_new_palette]; + if (!full_dither) + { + int k; + + for (k = 0; k < num_palette; k++) + { + if (png_ptr->dither_index[k] == + png_ptr->index_to_palette[j]) + png_ptr->dither_index[k] = + png_ptr->index_to_palette[next_j]; + if ((int)png_ptr->dither_index[k] == + num_new_palette) + png_ptr->dither_index[k] = + png_ptr->index_to_palette[j]; + } + } + + png_ptr->index_to_palette[png_ptr->palette_to_index + [num_new_palette]] = png_ptr->index_to_palette[j]; + png_ptr->palette_to_index[png_ptr->index_to_palette[j]] + = png_ptr->palette_to_index[num_new_palette]; + + png_ptr->index_to_palette[j] = (png_byte)num_new_palette; + png_ptr->palette_to_index[num_new_palette] = (png_byte)j; + } + if (num_new_palette <= maximum_colors) + break; + } + if (num_new_palette <= maximum_colors) + break; + } + } + + for (i = 0; i < 769; i++) + { + if (hash[i] != NULL) + { + png_dsortp p = hash[i]; + while (p) + { + t = p->next; + png_free(png_ptr, p); + p = t; + } + } + hash[i] = 0; + } + max_d += 96; + } + png_free(png_ptr, hash); + png_free(png_ptr, png_ptr->palette_to_index); + png_free(png_ptr, png_ptr->index_to_palette); + png_ptr->palette_to_index=NULL; + png_ptr->index_to_palette=NULL; + } + num_palette = maximum_colors; + } + if (png_ptr->palette == NULL) + { + png_ptr->palette = palette; + } + png_ptr->num_palette = (png_uint_16)num_palette; + + if (full_dither) + { + int i; + png_bytep distance; + int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS + + PNG_DITHER_BLUE_BITS; + int num_red = (1 << PNG_DITHER_RED_BITS); + int num_green = (1 << PNG_DITHER_GREEN_BITS); + int num_blue = (1 << PNG_DITHER_BLUE_BITS); + png_size_t num_entries = ((png_size_t)1 << total_bits); + + png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr, + (png_uint_32)(num_entries * png_sizeof (png_byte))); + + png_memset(png_ptr->palette_lookup, 0, num_entries * + png_sizeof (png_byte)); + + distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * + png_sizeof(png_byte))); + + png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); + + for (i = 0; i < num_palette; i++) + { + int ir, ig, ib; + int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); + int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS)); + int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS)); + + for (ir = 0; ir < num_red; ir++) + { + /* int dr = abs(ir - r); */ + int dr = ((ir > r) ? ir - r : r - ir); + int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS)); + + for (ig = 0; ig < num_green; ig++) + { + /* int dg = abs(ig - g); */ + int dg = ((ig > g) ? ig - g : g - ig); + int dt = dr + dg; + int dm = ((dr > dg) ? dr : dg); + int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS); + + for (ib = 0; ib < num_blue; ib++) + { + int d_index = index_g | ib; + /* int db = abs(ib - b); */ + int db = ((ib > b) ? ib - b : b - ib); + int dmax = ((dm > db) ? dm : db); + int d = dmax + dt + db; + + if (d < (int)distance[d_index]) + { + distance[d_index] = (png_byte)d; + png_ptr->palette_lookup[d_index] = (png_byte)i; + } + } + } + } + } + + png_free(png_ptr, distance); + } +} +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) +/* Transform the image from the file_gamma to the screen_gamma. We + * only do transformations on images where the file_gamma and screen_gamma + * are not close reciprocals, otherwise it slows things down slightly, and + * also needlessly introduces small errors. + * + * We will turn off gamma transformation later if no semitransparent entries + * are present in the tRNS array for palette images. We can't do it here + * because we don't necessarily have the tRNS chunk yet. + */ +void PNGAPI +png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) +{ + png_debug(1, "in png_set_gamma\n"); + if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + png_ptr->transformations |= PNG_GAMMA; + png_ptr->gamma = (float)file_gamma; + png_ptr->screen_gamma = (float)scrn_gamma; +} +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) +/* Expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ +void PNGAPI +png_set_expand(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand\n"); + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} + +/* GRR 19990627: the following three functions currently are identical + * to png_set_expand(). However, it is entirely reasonable that someone + * might wish to expand an indexed image to RGB but *not* expand a single, + * fully transparent palette entry to a full alpha channel--perhaps instead + * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace + * the transparent color with a particular RGB value, or drop tRNS entirely. + * IOW, a future version of the library may make the transformations flag + * a bit more fine-grained, with separate bits for each of these three + * functions. + * + * More to the point, these functions make it obvious what libpng will be + * doing, whereas "expand" can (and does) mean any number of things. + * + * GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified + * to expand only the sample depth but not to expand the tRNS to alpha. + */ + +/* Expand paletted images to RGB. */ +void PNGAPI +png_set_palette_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_palette_to_rgb\n"); + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} + +#if !defined(PNG_1_0_X) +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +void PNGAPI +png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n"); + png_ptr->transformations |= PNG_EXPAND_tRNS; +} +#endif + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +/* Deprecated as of libpng-1.2.9 */ +void PNGAPI +png_set_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_1_2_4_to_8\n"); + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif + + +/* Expand tRNS chunks to alpha channels. */ +void PNGAPI +png_set_tRNS_to_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand\n"); + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) +void PNGAPI +png_set_gray_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_to_rgb\n"); + png_ptr->transformations |= PNG_GRAY_TO_RGB; +} +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +#if defined(PNG_FLOATING_POINT_SUPPORTED) +/* Convert a RGB image to a grayscale of the same width. This allows us, + * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. + */ + +void PNGAPI +png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, + double green) +{ + int red_fixed = (int)((float)red*100000.0 + 0.5); + int green_fixed = (int)((float)green*100000.0 + 0.5); + png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); +} +#endif + +void PNGAPI +png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, + png_fixed_point red, png_fixed_point green) +{ + png_debug(1, "in png_set_rgb_to_gray\n"); + switch(error_action) + { + case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; + break; + case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; + break; + case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + } + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#if defined(PNG_READ_EXPAND_SUPPORTED) + png_ptr->transformations |= PNG_EXPAND; +#else + { + png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); + png_ptr->transformations &= ~PNG_RGB_TO_GRAY; + } +#endif + { + png_uint_16 red_int, green_int; + if(red < 0 || green < 0) + { + red_int = 6968; /* .212671 * 32768 + .5 */ + green_int = 23434; /* .715160 * 32768 + .5 */ + } + else if(red + green < 100000L) + { + red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L); + green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L); + } + else + { + png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); + red_int = 6968; + green_int = 23434; + } + png_ptr->rgb_to_gray_red_coeff = red_int; + png_ptr->rgb_to_gray_green_coeff = green_int; + png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int); + } +} +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +void PNGAPI +png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + read_user_transform_fn) +{ + png_debug(1, "in png_set_read_user_transform_fn\n"); +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->read_user_transform_fn = read_user_transform_fn; +#endif +#ifdef PNG_LEGACY_SUPPORTED + if(read_user_transform_fn) + png_warning(png_ptr, + "This version of libpng does not support user transforms"); +#endif +} +#endif + +/* Initialize everything needed for the read. This includes modifying + * the palette. + */ +void /* PRIVATE */ +png_init_read_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_init_read_transformations\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if(png_ptr != NULL) +#endif + { +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \ + || defined(PNG_READ_GAMMA_SUPPORTED) + int color_type = png_ptr->color_type; +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_EXPAND)) + { + if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */ + { + /* expand background and tRNS chunks */ + switch (png_ptr->bit_depth) + { + case 1: + png_ptr->background.gray *= (png_uint_16)0xff; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0xff; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + case 2: + png_ptr->background.gray *= (png_uint_16)0x55; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0x55; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + case 4: + png_ptr->background.gray *= (png_uint_16)0x11; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0x11; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + case 8: + case 16: + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + break; + } + } + else if (color_type == PNG_COLOR_TYPE_PALETTE) + { + png_ptr->background.red = + png_ptr->palette[png_ptr->background.index].red; + png_ptr->background.green = + png_ptr->palette[png_ptr->background.index].green; + png_ptr->background.blue = + png_ptr->palette[png_ptr->background.index].blue; + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_ALPHA) + { +#if defined(PNG_READ_EXPAND_SUPPORTED) + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) +#endif + { + /* invert the alpha channel (in tRNS) unless the pixels are + going to be expanded, in which case leave it for later */ + int i,istop; + istop=(int)png_ptr->num_trans; + for (i=0; itrans[i] = (png_byte)(255 - png_ptr->trans[i]); + } + } +#endif + + } + } +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) + png_ptr->background_1 = png_ptr->background; +#endif +#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) + + if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0) + && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0) + < PNG_GAMMA_THRESHOLD)) + { + int i,k; + k=0; + for (i=0; inum_trans; i++) + { + if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff) + k=1; /* partial transparency is present */ + } + if (k == 0) + png_ptr->transformations &= (~PNG_GAMMA); + } + + if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) && + png_ptr->gamma != 0.0) + { + png_build_gamma_table(png_ptr); +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->transformations & PNG_BACKGROUND) + { + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + /* could skip if no transparency and + */ + png_color back, back_1; + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + double g, gs; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = 1.0; + break; + case PNG_BACKGROUND_GAMMA_FILE: + g = 1.0 / (png_ptr->gamma); + gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + break; + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = 1.0 / (png_ptr->background_gamma); + gs = 1.0 / (png_ptr->background_gamma * + png_ptr->screen_gamma); + break; + default: + g = 1.0; /* back_1 */ + gs = 1.0; /* back */ + } + + if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD) + { + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + } + else + { + back.red = (png_byte)(pow( + (double)png_ptr->background.red/255, gs) * 255.0 + .5); + back.green = (png_byte)(pow( + (double)png_ptr->background.green/255, gs) * 255.0 + .5); + back.blue = (png_byte)(pow( + (double)png_ptr->background.blue/255, gs) * 255.0 + .5); + } + + back_1.red = (png_byte)(pow( + (double)png_ptr->background.red/255, g) * 255.0 + .5); + back_1.green = (png_byte)(pow( + (double)png_ptr->background.green/255, g) * 255.0 + .5); + back_1.blue = (png_byte)(pow( + (double)png_ptr->background.blue/255, g) * 255.0 + .5); + } + for (i = 0; i < num_palette; i++) + { + if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff) + { + if (png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else /* if (png_ptr->trans[i] != 0xff) */ + { + png_byte v, w; + + v = png_ptr->gamma_to_1[palette[i].red]; + png_composite(w, v, png_ptr->trans[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].green]; + png_composite(w, v, png_ptr->trans[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].blue]; + png_composite(w, v, png_ptr->trans[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ + else + /* color_type != PNG_COLOR_TYPE_PALETTE */ + { + double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1); + double g = 1.0; + double gs = 1.0; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = 1.0; + break; + case PNG_BACKGROUND_GAMMA_FILE: + g = 1.0 / (png_ptr->gamma); + gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + break; + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = 1.0 / (png_ptr->background_gamma); + gs = 1.0 / (png_ptr->background_gamma * + png_ptr->screen_gamma); + break; + } + + png_ptr->background_1.gray = (png_uint_16)(pow( + (double)png_ptr->background.gray / m, g) * m + .5); + png_ptr->background.gray = (png_uint_16)(pow( + (double)png_ptr->background.gray / m, gs) * m + .5); + + if ((png_ptr->background.red != png_ptr->background.green) || + (png_ptr->background.red != png_ptr->background.blue) || + (png_ptr->background.red != png_ptr->background.gray)) + { + /* RGB or RGBA with color background */ + png_ptr->background_1.red = (png_uint_16)(pow( + (double)png_ptr->background.red / m, g) * m + .5); + png_ptr->background_1.green = (png_uint_16)(pow( + (double)png_ptr->background.green / m, g) * m + .5); + png_ptr->background_1.blue = (png_uint_16)(pow( + (double)png_ptr->background.blue / m, g) * m + .5); + png_ptr->background.red = (png_uint_16)(pow( + (double)png_ptr->background.red / m, gs) * m + .5); + png_ptr->background.green = (png_uint_16)(pow( + (double)png_ptr->background.green / m, gs) * m + .5); + png_ptr->background.blue = (png_uint_16)(pow( + (double)png_ptr->background.blue / m, gs) * m + .5); + } + else + { + /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */ + png_ptr->background_1.red = png_ptr->background_1.green + = png_ptr->background_1.blue = png_ptr->background_1.gray; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + } + } + } + else + /* transformation does not include PNG_BACKGROUND */ +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + else +#endif +#endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */ +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + /* No GAMMA transformation */ + if ((png_ptr->transformations & PNG_BACKGROUND) && + (color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = (int)png_ptr->num_trans; + png_color back; + png_colorp palette = png_ptr->palette; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < istop; i++) + { + if (png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else if (png_ptr->trans[i] != 0xff) + { + /* The png_composite() macro is defined in png.h */ + png_composite(palette[i].red, palette[i].red, + png_ptr->trans[i], back.red); + png_composite(palette[i].green, palette[i].green, + png_ptr->trans[i], back.green); + png_composite(palette[i].blue, palette[i].blue, + png_ptr->trans[i], back.blue); + } + } + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + +#if defined(PNG_READ_SHIFT_SUPPORTED) + if ((png_ptr->transformations & PNG_SHIFT) && + (color_type == PNG_COLOR_TYPE_PALETTE)) + { + png_uint_16 i; + png_uint_16 istop = png_ptr->num_palette; + int sr = 8 - png_ptr->sig_bit.red; + int sg = 8 - png_ptr->sig_bit.green; + int sb = 8 - png_ptr->sig_bit.blue; + + if (sr < 0 || sr > 8) + sr = 0; + if (sg < 0 || sg > 8) + sg = 0; + if (sb < 0 || sb > 8) + sb = 0; + for (i = 0; i < istop; i++) + { + png_ptr->palette[i].red >>= sr; + png_ptr->palette[i].green >>= sg; + png_ptr->palette[i].blue >>= sb; + } + } +#endif /* PNG_READ_SHIFT_SUPPORTED */ + } +#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \ + && !defined(PNG_READ_BACKGROUND_SUPPORTED) + if(png_ptr) + return; +#endif +} + +/* Modify the info structure to reflect the transformations. The + * info should be updated so a PNG file could be written with it, + * assuming the transformations result in valid PNG data. + */ +void /* PRIVATE */ +png_read_transform_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_transform_info\n"); +#if defined(PNG_READ_EXPAND_SUPPORTED) + if (png_ptr->transformations & PNG_EXPAND) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS)) + info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + else + info_ptr->color_type = PNG_COLOR_TYPE_RGB; + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + } + else + { + if (png_ptr->num_trans) + { + if (png_ptr->transformations & PNG_EXPAND_tRNS) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + else + info_ptr->color_type |= PNG_COLOR_MASK_COLOR; + } + if (info_ptr->bit_depth < 8) + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + } + } +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->transformations & PNG_BACKGROUND) + { + info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; + info_ptr->num_trans = 0; + info_ptr->background = png_ptr->background; + } +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (png_ptr->transformations & PNG_GAMMA) + { +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->gamma = png_ptr->gamma; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = png_ptr->int_gamma; +#endif + } +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) + if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) + info_ptr->bit_depth = 8; +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + info_ptr->color_type |= PNG_COLOR_MASK_COLOR; +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) + if (png_ptr->transformations & PNG_DITHER) + { + if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && + png_ptr->palette_lookup && info_ptr->bit_depth == 8) + { + info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; + } + } +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) + if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) + info_ptr->bit_depth = 8; +#endif + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + else + info_ptr->channels = 1; + +#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) + if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) + info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; +#endif + + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + +#if defined(PNG_READ_FILLER_SUPPORTED) + /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ + if ((png_ptr->transformations & PNG_FILLER) && + ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) + { + info_ptr->channels++; + /* if adding a true alpha channel not just filler */ +#if !defined(PNG_1_0_X) + if (png_ptr->transformations & PNG_ADD_ALPHA) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; +#endif + } +#endif + +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ +defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + if(png_ptr->transformations & PNG_USER_TRANSFORM) + { + if(info_ptr->bit_depth < png_ptr->user_transform_depth) + info_ptr->bit_depth = png_ptr->user_transform_depth; + if(info_ptr->channels < png_ptr->user_transform_channels) + info_ptr->channels = png_ptr->user_transform_channels; + } +#endif + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * + info_ptr->bit_depth); + + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width); + +#if !defined(PNG_READ_EXPAND_SUPPORTED) + if(png_ptr) + return; +#endif +} + +/* Transform the row. The order of transformations is significant, + * and is very touchy. If you add a transformation, take care to + * decide how it fits in with the other transformations here. + */ +void /* PRIVATE */ +png_do_read_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_do_read_transformations\n"); +#if !defined(PNG_USELESS_TESTS_SUPPORTED) + if (png_ptr->row_buf == NULL) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[50]; + + sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number, + png_ptr->pass); + png_error(png_ptr, msg); +#else + png_error(png_ptr, "NULL row buffer"); +#endif + } +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) + { + png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->palette, png_ptr->trans, png_ptr->num_trans); + } + else + { + if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS)) + png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->trans_values)); + else + png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, + NULL); + } + } +#endif + +#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) + if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) + png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)); +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + { + int rgb_error = + png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1); + if(rgb_error) + { + png_ptr->rgb_to_gray_status=1; + if(png_ptr->transformations == PNG_RGB_TO_GRAY_WARN) + png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + if(png_ptr->transformations == PNG_RGB_TO_GRAY_ERR) + png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + } + } +#endif + +/* +From Andreas Dilger e-mail to png-implement, 26 March 1998: + + In most cases, the "simple transparency" should be done prior to doing + gray-to-RGB, or you will have to test 3x as many bytes to check if a + pixel is transparent. You would also need to make sure that the + transparency information is upgraded to RGB. + + To summarize, the current flow is: + - Gray + simple transparency -> compare 1 or 2 gray bytes and composite + with background "in place" if transparent, + convert to RGB if necessary + - Gray + alpha -> composite with gray background and remove alpha bytes, + convert to RGB if necessary + + To support RGB backgrounds for gray images we need: + - Gray + simple transparency -> convert to RGB + simple transparency, compare + 3 or 6 bytes and composite with background + "in place" if transparent (3x compare/pixel + compared to doing composite with gray bkgrnd) + - Gray + alpha -> convert to RGB + alpha, composite with background and + remove alpha bytes (3x float operations/pixel + compared with composite on gray background) + + Greg's change will do this. The reason it wasn't done before is for + performance, as this increases the per-pixel operations. If we would check + in advance if the background was gray or RGB, and position the gray-to-RGB + transform appropriately, then it would save a lot of work/time. + */ + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + /* if gray -> RGB, do so now only if background is non-gray; else do later + * for performance reasons */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + if ((png_ptr->transformations & PNG_BACKGROUND) && + ((png_ptr->num_trans != 0 ) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) + png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->trans_values), &(png_ptr->background) +#if defined(PNG_READ_GAMMA_SUPPORTED) + , &(png_ptr->background_1), + png_ptr->gamma_table, png_ptr->gamma_from_1, + png_ptr->gamma_to_1, png_ptr->gamma_16_table, + png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1, + png_ptr->gamma_shift +#endif +); +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) + if ((png_ptr->transformations & PNG_GAMMA) && +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + !((png_ptr->transformations & PNG_BACKGROUND) && + ((png_ptr->num_trans != 0) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && +#endif + (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) + png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->gamma_table, png_ptr->gamma_16_table, + png_ptr->gamma_shift); +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) + if (png_ptr->transformations & PNG_16_TO_8) + png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) + if (png_ptr->transformations & PNG_DITHER) + { + png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->palette_lookup, png_ptr->dither_index); + if(png_ptr->row_info.rowbytes == (png_uint_32)0) + png_error(png_ptr, "png_do_dither returned rowbytes=0"); + } +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + /* if gray -> RGB, do so now only if we did not do so above */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + (png_uint_32)png_ptr->filler, png_ptr->flags); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + if(png_ptr->read_user_transform_fn != NULL) + (*(png_ptr->read_user_transform_fn)) /* user read transform function */ + (png_ptr, /* png_ptr */ + &(png_ptr->row_info), /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_uint_32 rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + if(png_ptr->user_transform_depth) + png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; + if(png_ptr->user_transform_channels) + png_ptr->row_info.channels = png_ptr->user_transform_channels; +#endif + png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * + png_ptr->row_info.channels); + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + } +#endif + +} + +#if defined(PNG_READ_PACK_SUPPORTED) +/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, + * without changing the actual values. Thus, if you had a row with + * a bit depth of 1, you would end up with bytes that only contained + * the numbers 0 or 1. If you would rather they contain 0 and 255, use + * png_do_shift() after this. + */ +void /* PRIVATE */ +png_do_unpack(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_unpack\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL && row_info->bit_depth < 8) +#else + if (row_info->bit_depth < 8) +#endif + { + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + switch (row_info->bit_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x01); + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + case 2: + { + + png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x03); + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + case 4: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x0f); + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift = 4; + + dp--; + } + break; + } + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_width * row_info->channels; + } +} +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) +/* Reverse the effects of png_do_shift. This routine merely shifts the + * pixels back to their significant bits values. Thus, if you have + * a row of bit depth 8, but only 5 are significant, this will shift + * the values back to 0 through 31. + */ +void /* PRIVATE */ +png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) +{ + png_debug(1, "in png_do_unshift\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && sig_bits != NULL && +#endif + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift[4]; + int channels = 0; + int c; + png_uint_16 value = 0; + png_uint_32 row_width = row_info->width; + + if (row_info->color_type & PNG_COLOR_MASK_COLOR) + { + shift[channels++] = row_info->bit_depth - sig_bits->red; + shift[channels++] = row_info->bit_depth - sig_bits->green; + shift[channels++] = row_info->bit_depth - sig_bits->blue; + } + else + { + shift[channels++] = row_info->bit_depth - sig_bits->gray; + } + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + shift[channels++] = row_info->bit_depth - sig_bits->alpha; + } + + for (c = 0; c < channels; c++) + { + if (shift[c] <= 0) + shift[c] = 0; + else + value = 1; + } + + if (!value) + return; + + switch (row_info->bit_depth) + { + case 2: + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (bp = row, i = 0; i < istop; i++) + { + *bp >>= 1; + *bp++ &= 0x55; + } + break; + } + case 4: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) | + (png_byte)((int)0xf >> shift[0])); + + for (i = 0; i < istop; i++) + { + *bp >>= shift[0]; + *bp++ &= mask; + } + break; + } + case 8: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = row_width * channels; + + for (i = 0; i < istop; i++) + { + *bp++ >>= shift[i%channels]; + } + break; + } + case 16: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_width; + + for (i = 0; i < istop; i++) + { + value = (png_uint_16)((*bp << 8) + *(bp + 1)); + value >>= shift[i%channels]; + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + break; + } + } + } +} +#endif + +#if defined(PNG_READ_16_TO_8_SUPPORTED) +/* chop rows of bit depth 16 down to 8 */ +void /* PRIVATE */ +png_do_chop(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_chop\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL && row_info->bit_depth == 16) +#else + if (row_info->bit_depth == 16) +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + png_uint_32 istop = row_info->width * row_info->channels; + + for (i = 0; i> 8)) >> 8; + * + * Approximate calculation with shift/add instead of multiply/divide: + * *dp = ((((png_uint_32)(*sp) << 8) | + * (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8; + * + * What we actually do to avoid extra shifting and conversion: + */ + + *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0); +#else + /* Simply discard the low order byte */ + *dp = *sp; +#endif + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) +void /* PRIVATE */ +png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_swap_alpha\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from RGBA to ARGB */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + /* This converts from RRGGBBAA to AARRGGBB */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from GA to AG */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + /* This converts from GGAA to AAGG */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } + } + } +} +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) +void /* PRIVATE */ +png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_invert_alpha\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This inverts the alpha channel in RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=3; + dp=sp; + } + } + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=6; + dp=sp; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This inverts the alpha channel in GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = *(--sp); + } + } + /* This inverts the alpha channel in GGAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); +/* + *(--dp) = *(--sp); + *(--dp) = *(--sp); +*/ + sp-=2; + dp=sp; + } + } + } + } +} +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) +/* Add filler channel if we have RGB color */ +void /* PRIVATE */ +png_do_read_filler(png_row_infop row_info, png_bytep row, + png_uint_32 filler, png_uint_32 flags) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_byte hi_filler = (png_byte)((filler>>8) & 0xff); + png_byte lo_filler = (png_byte)(filler & 0xff); + + png_debug(1, "in png_do_read_filler\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if(row_info->bit_depth == 8) + { + /* This changes the data from G to GX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + /* This changes the data from G to XG */ + else + { + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + } + else if(row_info->bit_depth == 16) + { + /* This changes the data from GG to GGXX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + /* This changes the data from GG to XXGG */ + else + { + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + } /* COLOR_TYPE == GRAY */ + else if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if(row_info->bit_depth == 8) + { + /* This changes the data from RGB to RGBX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + /* This changes the data from RGB to XRGB */ + else + { + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + else if(row_info->bit_depth == 16) + { + /* This changes the data from RRGGBB to RRGGBBXX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + /* This changes the data from RRGGBB to XXRRGGBB */ + else + { + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + } + } /* COLOR_TYPE == RGB */ +} +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) +/* expand grayscale files to RGB, with or without alpha */ +void /* PRIVATE */ +png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_gray_to_rgb\n"); + if (row_info->bit_depth >= 8 && +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + !(row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + png_bytep sp = row + (png_size_t)row_width - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + else + { + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + else + { + png_bytep sp = row + (png_size_t)row_width * 4 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + row_info->channels += (png_byte)2; + row_info->color_type |= PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } +} +#endif + +#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) +/* reduce RGB files to grayscale, with or without alpha + * using the equation given in Poynton's ColorFAQ at + * + * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net + * + * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + * + * We approximate this with + * + * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B + * + * which can be expressed with integers as + * + * Y = (6969 * R + 23434 * G + 2365 * B)/32768 + * + * The calculation is to be done in a linear colorspace. + * + * Other integer coefficents can be used via png_set_rgb_to_gray(). + */ +int /* PRIVATE */ +png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) + +{ + png_uint_32 i; + + png_uint_32 row_width = row_info->width; + int rgb_error = 0; + + png_debug(1, "in png_do_rgb_to_gray\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; + png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; + png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + + for (i = 0; i < row_width; i++) + { + png_byte red = png_ptr->gamma_to_1[*(sp++)]; + png_byte green = png_ptr->gamma_to_1[*(sp++)]; + png_byte blue = png_ptr->gamma_to_1[*(sp++)]; + if(red != green || red != blue) + { + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1[ + (rc*red+gc*green+bc*blue)>>15]; + } + else + *(dp++) = *(sp-1); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + if(red != green || red != blue) + { + rgb_error |= 1; + *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15); + } + else + *(dp++) = *(sp-1); + } + } + } + + else /* RGB bit_depth == 16 */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_to_1 != NULL && + png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if(red == green && red == blue) + w = red; + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> + png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> + png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 + + bc*blue_1)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if(red != green || red != blue) + rgb_error |= 1; + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = (png_byte)((gray16>>8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + } + } + } + } + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = png_ptr->gamma_to_1[*(sp++)]; + png_byte green = png_ptr->gamma_to_1[*(sp++)]; + png_byte blue = png_ptr->gamma_to_1[*(sp++)]; + if(red != green || red != blue) + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1 + [(rc*red + gc*green + bc*blue)>>15]; + *(dp++) = *(sp++); /* alpha */ + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + if(red != green || red != blue) + rgb_error |= 1; + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = *(sp++); /* alpha */ + } + } + } + else /* RGBA bit_depth == 16 */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_to_1 != NULL && + png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if(red == green && red == blue) + w = red; + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> + png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> + png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc * red_1 + + gc * green_1 + bc * blue_1)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + *(dp++) = *(sp++); /* alpha */ + *(dp++) = *(sp++); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + if(red != green || red != blue) + rgb_error |= 1; + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = (png_byte)((gray16>>8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + *(dp++) = *(sp++); /* alpha */ + *(dp++) = *(sp++); + } + } + } + } + row_info->channels -= (png_byte)2; + row_info->color_type &= ~PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } + return rgb_error; +} +#endif + +/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth + * large of png_color. This lets grayscale images be treated as + * paletted. Most useful for gamma correction and simplification + * of code. + */ +void PNGAPI +png_build_grayscale_palette(int bit_depth, png_colorp palette) +{ + int num_palette; + int color_inc; + int i; + int v; + + png_debug(1, "in png_do_build_grayscale_palette\n"); + if (palette == NULL) + return; + + switch (bit_depth) + { + case 1: + num_palette = 2; + color_inc = 0xff; + break; + case 2: + num_palette = 4; + color_inc = 0x55; + break; + case 4: + num_palette = 16; + color_inc = 0x11; + break; + case 8: + num_palette = 256; + color_inc = 1; + break; + default: + num_palette = 0; + color_inc = 0; + break; + } + + for (i = 0, v = 0; i < num_palette; i++, v += color_inc) + { + palette[i].red = (png_byte)v; + palette[i].green = (png_byte)v; + palette[i].blue = (png_byte)v; + } +} + +/* This function is currently unused. Do we really need it? */ +#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED) +void /* PRIVATE */ +png_correct_palette(png_structp png_ptr, png_colorp palette, + int num_palette) +{ + png_debug(1, "in png_correct_palette\n"); +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) + if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND)) + { + png_color back, back_1; + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + double g; + + g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN || + fabs(g - 1.0) < PNG_GAMMA_THRESHOLD) + { + back.red = png_ptr->background.red; + back.green = png_ptr->background.green; + back.blue = png_ptr->background.blue; + } + else + { + back.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + g = 1.0 / png_ptr->background_gamma; + + back_1.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back_1.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back_1.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_uint_32 i; + + for (i = 0; i < (png_uint_32)num_palette; i++) + { + if (i < png_ptr->num_trans && png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff) + { + png_byte v, w; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].red]; + png_composite(w, v, png_ptr->trans[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].green]; + png_composite(w, v, png_ptr->trans[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].blue]; + png_composite(w, v, png_ptr->trans[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + else + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (palette[i].red == (png_byte)png_ptr->trans_values.gray) + { + palette[i] = back; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + } + else +#endif +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (png_ptr->transformations & PNG_GAMMA) + { + int i; + + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + else +#endif +#endif +#if defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->transformations & PNG_BACKGROUND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_color back; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < (int)png_ptr->num_trans; i++) + { + if (png_ptr->trans[i] == 0) + { + palette[i].red = back.red; + palette[i].green = back.green; + palette[i].blue = back.blue; + } + else if (png_ptr->trans[i] != 0xff) + { + png_composite(palette[i].red, png_ptr->palette[i].red, + png_ptr->trans[i], back.red); + png_composite(palette[i].green, png_ptr->palette[i].green, + png_ptr->trans[i], back.green); + png_composite(palette[i].blue, png_ptr->palette[i].blue, + png_ptr->trans[i], back.blue); + } + } + } + else /* assume grayscale palette (what else could it be?) */ + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (i == (png_byte)png_ptr->trans_values.gray) + { + palette[i].red = (png_byte)png_ptr->background.red; + palette[i].green = (png_byte)png_ptr->background.green; + palette[i].blue = (png_byte)png_ptr->background.blue; + } + } + } + } +#endif +} +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) +/* Replace any alpha or transparency with the supplied background color. + * "background" is already in the screen gamma, while "background_1" is + * at a gamma of 1.0. Paletted files have already been taken care of. + */ +void /* PRIVATE */ +png_do_background(png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background +#if defined(PNG_READ_GAMMA_SUPPORTED) + , png_color_16p background_1, + png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, + png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, + png_uint_16pp gamma_16_to_1, int gamma_shift +#endif + ) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + int shift; + + png_debug(1, "in png_do_background\n"); + if (background != NULL && +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) || + (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values))) + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_GRAY: + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row; + shift = 7; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x01) + == trans_values->gray) + { + *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 7; + sp++; + } + else + shift--; + } + break; + } + case 2: + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == trans_values->gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x03); + png_byte g = (png_byte)((gamma_table [p | (p << 2) | + (p << 4) | (p << 6)] >> 6) & 0x03); + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + if (!shift) + { + shift = 6; + sp++; + } + else + shift -= 2; + } + } + else +#endif + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == trans_values->gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 6; + sp++; + } + else + shift -= 2; + } + } + break; + } + case 4: + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == trans_values->gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x0f); + png_byte g = (png_byte)((gamma_table[p | + (p << 4)] >> 4) & 0x0f); + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + if (!shift) + { + shift = 4; + sp++; + } + else + shift -= 4; + } + } + else +#endif + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == trans_values->gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 4; + sp++; + } + else + shift -= 4; + } + } + break; + } + case 8: + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == trans_values->gray) + { + *sp = (png_byte)background->gray; + } + else + { + *sp = gamma_table[*sp]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == trans_values->gray) + { + *sp = (png_byte)background->gray; + } + } + } + break; + } + case 16: + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + if (v == trans_values->gray) + { + /* background is already in screen gamma */ + *sp = (png_byte)((background->gray >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->gray & 0xff); + } + else + { + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + if (v == trans_values->gray) + { + *sp = (png_byte)((background->gray >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->gray & 0xff); + } + } + } + break; + } + } + break; + } + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) + { + *sp = (png_byte)background->red; + *(sp + 1) = (png_byte)background->green; + *(sp + 2) = (png_byte)background->blue; + } + else + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) + { + *sp = (png_byte)background->red; + *(sp + 1) = (png_byte)background->green; + *(sp + 2) = (png_byte)background->blue; + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) + { + /* background is already in screen gamma */ + *sp = (png_byte)((background->red >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->red & 0xff); + *(sp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(sp + 3) = (png_byte)(background->green & 0xff); + *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(sp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1)); + png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); + + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) + { + *sp = (png_byte)((background->red >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->red & 0xff); + *(sp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(sp + 3) = (png_byte)(background->green & 0xff); + *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(sp + 5) = (png_byte)(background->blue & 0xff); + } + } + } + } + break; + } + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 2, dp++) + { + png_uint_16 a = *(sp + 1); + + if (a == 0xff) + { + *dp = gamma_table[*sp]; + } + else if (a == 0) + { + /* background is already in screen gamma */ + *dp = (png_byte)background->gray; + } + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, background_1->gray); + *dp = gamma_from_1[w]; + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 2, dp++) + { + png_byte a = *(sp + 1); + + if (a == 0xff) + { + *dp = *sp; + } +#if defined(PNG_READ_GAMMA_SUPPORTED) + else if (a == 0) + { + *dp = (png_byte)background->gray; + } + else + { + png_composite(*dp, *sp, a, background_1->gray); + } +#else + *dp = (png_byte)background->gray; +#endif + } + } + } + else /* if (png_ptr->bit_depth == 16) */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 2) + { + png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + } +#if defined(PNG_READ_GAMMA_SUPPORTED) + else if (a == 0) +#else + else +#endif + { + /* background is already in screen gamma */ + *dp = (png_byte)((background->gray >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->gray & 0xff); + } +#if defined(PNG_READ_GAMMA_SUPPORTED) + else + { + png_uint_16 g, v, w; + + g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(v, g, a, background_1->gray); + w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; + *dp = (png_byte)((w >> 8) & 0xff); + *(dp + 1) = (png_byte)(w & 0xff); + } +#endif + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 2) + { + png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + if (a == (png_uint_16)0xffff) + { + png_memcpy(dp, sp, 2); + } +#if defined(PNG_READ_GAMMA_SUPPORTED) + else if (a == 0) +#else + else +#endif + { + *dp = (png_byte)((background->gray >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->gray & 0xff); + } +#if defined(PNG_READ_GAMMA_SUPPORTED) + else + { + png_uint_16 g, v; + + g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_composite_16(v, g, a, background_1->gray); + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + } +#endif + } + } + } + break; + } + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 3) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *dp = gamma_table[*sp]; + *(dp + 1) = gamma_table[*(sp + 1)]; + *(dp + 2) = gamma_table[*(sp + 2)]; + } + else if (a == 0) + { + /* background is already in screen gamma */ + *dp = (png_byte)background->red; + *(dp + 1) = (png_byte)background->green; + *(dp + 2) = (png_byte)background->blue; + } + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, background_1->red); + *dp = gamma_from_1[w]; + v = gamma_to_1[*(sp + 1)]; + png_composite(w, v, a, background_1->green); + *(dp + 1) = gamma_from_1[w]; + v = gamma_to_1[*(sp + 2)]; + png_composite(w, v, a, background_1->blue); + *(dp + 2) = gamma_from_1[w]; + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 3) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *dp = *sp; + *(dp + 1) = *(sp + 1); + *(dp + 2) = *(sp + 2); + } + else if (a == 0) + { + *dp = (png_byte)background->red; + *(dp + 1) = (png_byte)background->green; + *(dp + 2) = (png_byte)background->blue; + } + else + { + png_composite(*dp, *sp, a, background->red); + png_composite(*(dp + 1), *(sp + 1), a, + background->green); + png_composite(*(dp + 2), *(sp + 2), a, + background->blue); + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 8, dp += 6) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(dp + 2) = (png_byte)((v >> 8) & 0xff); + *(dp + 3) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(dp + 4) = (png_byte)((v >> 8) & 0xff); + *(dp + 5) = (png_byte)(v & 0xff); + } + else if (a == 0) + { + /* background is already in screen gamma */ + *dp = (png_byte)((background->red >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->red & 0xff); + *(dp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(dp + 3) = (png_byte)(background->green & 0xff); + *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(dp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v, w, x; + + v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(w, v, a, background_1->red); + x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + *dp = (png_byte)((x >> 8) & 0xff); + *(dp + 1) = (png_byte)(x & 0xff); + v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; + png_composite_16(w, v, a, background_1->green); + x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + *(dp + 2) = (png_byte)((x >> 8) & 0xff); + *(dp + 3) = (png_byte)(x & 0xff); + v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; + png_composite_16(w, v, a, background_1->blue); + x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8]; + *(dp + 4) = (png_byte)((x >> 8) & 0xff); + *(dp + 5) = (png_byte)(x & 0xff); + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 8, dp += 6) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + if (a == (png_uint_16)0xffff) + { + png_memcpy(dp, sp, 6); + } + else if (a == 0) + { + *dp = (png_byte)((background->red >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->red & 0xff); + *(dp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(dp + 3) = (png_byte)(background->green & 0xff); + *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(dp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v; + + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + png_composite_16(v, r, a, background->red); + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + png_composite_16(v, g, a, background->green); + *(dp + 2) = (png_byte)((v >> 8) & 0xff); + *(dp + 3) = (png_byte)(v & 0xff); + png_composite_16(v, b, a, background->blue); + *(dp + 4) = (png_byte)((v >> 8) & 0xff); + *(dp + 5) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + } + + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; + row_info->channels--; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } + } +} +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) +/* Gamma correct the image, avoiding the alpha channel. Make sure + * you do this after you deal with the transparency issue on grayscale + * or RGB images. If your bit depth is 8, use gamma_table, if it + * is 16, use gamma_16_table and gamma_shift. Build these with + * build_gamma_table(). + */ +void /* PRIVATE */ +png_do_gamma(png_row_infop row_info, png_bytep row, + png_bytep gamma_table, png_uint_16pp gamma_16_table, + int gamma_shift) +{ + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_gamma\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + ((row_info->bit_depth <= 8 && gamma_table != NULL) || + (row_info->bit_depth == 16 && gamma_16_table != NULL))) + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + sp++; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp += 2; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + case PNG_COLOR_TYPE_GRAY: + { + if (row_info->bit_depth == 2) + { + sp = row; + for (i = 0; i < row_width; i += 4) + { + int a = *sp & 0xc0; + int b = *sp & 0x30; + int c = *sp & 0x0c; + int d = *sp & 0x03; + + *sp = (png_byte)( + ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| + ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| + ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| + ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); + sp++; + } + } + if (row_info->bit_depth == 4) + { + sp = row; + for (i = 0; i < row_width; i += 2) + { + int msb = *sp & 0xf0; + int lsb = *sp & 0x0f; + + *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) + | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); + sp++; + } + } + else if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + } + } + else if (row_info->bit_depth == 16) + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + } + } +} +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) +/* Expands a palette row to an RGB or RGBA row depending + * upon whether you supply trans and num_trans. + */ +void /* PRIVATE */ +png_do_expand_palette(png_row_infop row_info, png_bytep row, + png_colorp palette, png_bytep trans, int num_trans) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand_palette\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 1; + else + *dp = 0; + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + case 2: + { + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)value; + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + case 4: + { + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((row_width & 0x01) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)value; + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift += 4; + + dp--; + } + break; + } + } + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + switch (row_info->bit_depth) + { + case 8: + { + if (trans != NULL) + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + + for (i = 0; i < row_width; i++) + { + if ((int)(*sp) >= num_trans) + *dp-- = 0xff; + else + *dp-- = trans[*sp]; + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + row_info->color_type = 6; + row_info->channels = 4; + } + else + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width * 3) - 1; + + for (i = 0; i < row_width; i++) + { + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + row_info->color_type = 2; + row_info->channels = 3; + } + break; + } + } + } +} + +/* If the bit depth < 8, it is expanded to 8. Also, if the already + * expanded transparency value is supplied, an alpha channel is built. + */ +void /* PRIVATE */ +png_do_expand(png_row_infop row_info, png_bytep row, + png_color_16p trans_value) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0); + + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + gray = (png_uint_16)(gray*0xff); + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 0xff; + else + *dp = 0; + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + case 2: + { + gray = (png_uint_16)(gray*0x55); + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)(value | (value << 2) | (value << 4) | + (value << 6)); + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + case 4: + { + gray = (png_uint_16)(gray*0x11); + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)(value | (value << 4)); + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift = 4; + + dp--; + } + break; + } + } + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (trans_value != NULL) + { + if (row_info->bit_depth == 8) + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 1) - 1; + for (i = 0; i < row_width; i++) + { + if (*sp == gray) + *dp-- = 0; + else + *dp-- = 0xff; + *dp-- = *sp--; + } + } + else if (row_info->bit_depth == 16) + { + sp = row + row_info->rowbytes - 1; + dp = row + (row_info->rowbytes << 1) - 1; + for (i = 0; i < row_width; i++) + { + if (((png_uint_16)*(sp) | + ((png_uint_16)*(sp - 1) << 8)) == gray) + { + *dp-- = 0; + *dp-- = 0; + } + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + row_info->channels = 2; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_width); + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value) + { + if (row_info->bit_depth == 8) + { + sp = row + (png_size_t)row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 2) == trans_value->red && + *(sp - 1) == trans_value->green && + *(sp - 0) == trans_value->blue) + *dp-- = 0; + else + *dp-- = 0xff; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + else if (row_info->bit_depth == 16) + { + sp = row + row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 3) - 1; + for (i = 0; i < row_width; i++) + { + if ((((png_uint_16)*(sp - 4) | + ((png_uint_16)*(sp - 5) << 8)) == trans_value->red) && + (((png_uint_16)*(sp - 2) | + ((png_uint_16)*(sp - 3) << 8)) == trans_value->green) && + (((png_uint_16)*(sp - 0) | + ((png_uint_16)*(sp - 1) << 8)) == trans_value->blue)) + { + *dp-- = 0; + *dp-- = 0; + } + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + row_info->channels = 4; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } + } +} +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) +void /* PRIVATE */ +png_do_dither(png_row_infop row_info, png_bytep row, + png_bytep palette_lookup, png_bytep dither_lookup) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_dither\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB && + palette_lookup && row_info->bit_depth == 8) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + + /* this looks real messy, but the compiler will reduce + it down to a reasonable formula. For example, with + 5 bits per color, we get: + p = (((r >> 3) & 0x1f) << 10) | + (((g >> 3) & 0x1f) << 5) | + ((b >> 3) & 0x1f); + */ + p = (((r >> (8 - PNG_DITHER_RED_BITS)) & + ((1 << PNG_DITHER_RED_BITS) - 1)) << + (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) | + (((g >> (8 - PNG_DITHER_GREEN_BITS)) & + ((1 << PNG_DITHER_GREEN_BITS) - 1)) << + (PNG_DITHER_BLUE_BITS)) | + ((b >> (8 - PNG_DITHER_BLUE_BITS)) & + ((1 << PNG_DITHER_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + palette_lookup != NULL && row_info->bit_depth == 8) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + sp++; + + p = (((r >> (8 - PNG_DITHER_RED_BITS)) & + ((1 << PNG_DITHER_RED_BITS) - 1)) << + (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) | + (((g >> (8 - PNG_DITHER_GREEN_BITS)) & + ((1 << PNG_DITHER_GREEN_BITS) - 1)) << + (PNG_DITHER_BLUE_BITS)) | + ((b >> (8 - PNG_DITHER_BLUE_BITS)) & + ((1 << PNG_DITHER_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); + } + else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + dither_lookup && row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + *sp = dither_lookup[*sp]; + } + } + } +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +#if defined(PNG_READ_GAMMA_SUPPORTED) +static int png_gamma_shift[] = + {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0}; + +/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit + * tables, we don't make a full table if we are reducing to 8-bit in + * the future. Note also how the gamma_16 tables are segmented so that + * we don't need to allocate > 64K chunks for a full 16-bit table. + */ +void /* PRIVATE */ +png_build_gamma_table(png_structp png_ptr) +{ + png_debug(1, "in png_build_gamma_table\n"); + + if (png_ptr->bit_depth <= 8) + { + int i; + double g; + + if (png_ptr->screen_gamma > .000001) + g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + else + g = 1.0; + + png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + } + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY)) + { + + g = 1.0 / (png_ptr->gamma); + + png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + } + + + png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + if(png_ptr->screen_gamma > 0.000001) + g = 1.0 / png_ptr->screen_gamma; + else + g = png_ptr->gamma; /* probably doing rgb_to_gray */ + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + + } + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ + } + else + { + double g; + int i, j, shift, num; + int sig_bit; + png_uint_32 ig; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit = (int)png_ptr->sig_bit.red; + if ((int)png_ptr->sig_bit.green > sig_bit) + sig_bit = png_ptr->sig_bit.green; + if ((int)png_ptr->sig_bit.blue > sig_bit) + sig_bit = png_ptr->sig_bit.blue; + } + else + { + sig_bit = (int)png_ptr->sig_bit.gray; + } + + if (sig_bit > 0) + shift = 16 - sig_bit; + else + shift = 0; + + if (png_ptr->transformations & PNG_16_TO_8) + { + if (shift < (16 - PNG_MAX_GAMMA_8)) + shift = (16 - PNG_MAX_GAMMA_8); + } + + if (shift > 8) + shift = 8; + if (shift < 0) + shift = 0; + + png_ptr->gamma_shift = (png_byte)shift; + + num = (1 << (8 - shift)); + + if (png_ptr->screen_gamma > .000001) + g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + else + g = 1.0; + + png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr, + (png_uint_32)(num * png_sizeof (png_uint_16p))); + + if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) + { + double fin, fout; + png_uint_32 last, max; + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof (png_uint_16))); + } + + g = 1.0 / g; + last = 0; + for (i = 0; i < 256; i++) + { + fout = ((double)i + 0.5) / 256.0; + fin = pow(fout, g); + max = (png_uint_32)(fin * (double)((png_uint_32)num << 8)); + while (last <= max) + { + png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] + [(int)(last >> (8 - shift))] = (png_uint_16)( + (png_uint_16)i | ((png_uint_16)i << 8)); + last++; + } + } + while (last < ((png_uint_32)num << 8)) + { + png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] + [(int)(last >> (8 - shift))] = (png_uint_16)65535L; + last++; + } + } + else + { + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof (png_uint_16))); + + ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4); + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_table[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + } + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) + { + + g = 1.0 / (png_ptr->gamma); + + png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr, + (png_uint_32)(num * png_sizeof (png_uint_16p ))); + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof (png_uint_16))); + + ig = (((png_uint_32)i * + (png_uint_32)png_gamma_shift[shift]) >> 4); + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_to_1[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + + if(png_ptr->screen_gamma > 0.000001) + g = 1.0 / png_ptr->screen_gamma; + else + g = png_ptr->gamma; /* probably doing rgb_to_gray */ + + png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr, + (png_uint_32)(num * png_sizeof (png_uint_16p))); + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof (png_uint_16))); + + ig = (((png_uint_32)i * + (png_uint_32)png_gamma_shift[shift]) >> 4); + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_from_1[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ + } +} +#endif +/* To do: install integer version of png_build_gamma_table here */ +#endif + +#if defined(PNG_MNG_FEATURES_SUPPORTED) +/* undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_read_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_intrapixel\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff); + *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp+1); + png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3); + png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5); + png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp+1) = (png_byte)(red & 0xff); + *(rp+4) = (png_byte)((blue >> 8) & 0xff); + *(rp+5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrutil.c ./win32/dependencies/libpng/pngrutil.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngrutil.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngrutil.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,3124 @@ + +/* pngrutil.c - utilities to read a PNG file + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file contains routines that are only called from within + * libpng itself during the course of reading an image. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) + +#if defined(_WIN32_WCE) +/* strtod() function is not supported on WindowsCE */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +__inline double strtod(const char *nptr, char **endptr) +{ + double result = 0; + int len; + wchar_t *str, *end; + + len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); + str = (wchar_t *)malloc(len * sizeof(wchar_t)); + if ( NULL != str ) + { + MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); + result = wcstod(str, &end); + len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL); + *endptr = (char *)nptr + (png_strlen(nptr) - len + 1); + free(str); + } + return result; +} +# endif +#endif + +png_uint_32 PNGAPI +png_get_uint_31(png_structp png_ptr, png_bytep buf) +{ + png_uint_32 i = png_get_uint_32(buf); + if (i > PNG_UINT_31_MAX) + png_error(png_ptr, "PNG unsigned integer out of range."); + return (i); +} +#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ +png_uint_32 PNGAPI +png_get_uint_32(png_bytep buf) +{ + png_uint_32 i = ((png_uint_32)(*buf) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + (png_uint_32)(*(buf + 3)); + + return (i); +} + +/* Grab a signed 32-bit integer from a buffer in big-endian format. The + * data is stored in the PNG file in two's complement format, and it is + * assumed that the machine format for signed integers is the same. */ +png_int_32 PNGAPI +png_get_int_32(png_bytep buf) +{ + png_int_32 i = ((png_int_32)(*buf) << 24) + + ((png_int_32)(*(buf + 1)) << 16) + + ((png_int_32)(*(buf + 2)) << 8) + + (png_int_32)(*(buf + 3)); + + return (i); +} + +/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ +png_uint_16 PNGAPI +png_get_uint_16(png_bytep buf) +{ + png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) + + (png_uint_16)(*(buf + 1))); + + return (i); +} +#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ + +/* Read data, and (optionally) run it through the CRC. */ +void /* PRIVATE */ +png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) +{ + png_read_data(png_ptr, buf, length); + png_calculate_crc(png_ptr, buf, length); +} + +/* Optionally skip data and then check the CRC. Depending on whether we + are reading a ancillary or critical chunk, and how the program has set + things up, we may calculate the CRC on the data and print a message. + Returns '1' if there was a CRC error, '0' otherwise. */ +int /* PRIVATE */ +png_crc_finish(png_structp png_ptr, png_uint_32 skip) +{ + png_size_t i; + png_size_t istop = png_ptr->zbuf_size; + + for (i = (png_size_t)skip; i > istop; i -= istop) + { + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + } + if (i) + { + png_crc_read(png_ptr, png_ptr->zbuf, i); + } + + if (png_crc_error(png_ptr)) + { + if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ + !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || + (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) + { + png_chunk_warning(png_ptr, "CRC error"); + } + else + { + png_chunk_error(png_ptr, "CRC error"); + } + return (1); + } + + return (0); +} + +/* Compare the CRC stored in the PNG file with that calculated by libpng from + the data it has read thus far. */ +int /* PRIVATE */ +png_crc_error(png_structp png_ptr) +{ + png_byte crc_bytes[4]; + png_uint_32 crc; + int need_crc = 1; + + if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + + png_read_data(png_ptr, crc_bytes, 4); + + if (need_crc) + { + crc = png_get_uint_32(crc_bytes); + return ((int)(crc != png_ptr->crc)); + } + else + return (0); +} + +#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \ + defined(PNG_READ_iCCP_SUPPORTED) +/* + * Decompress trailing data in a chunk. The assumption is that chunkdata + * points at an allocated area holding the contents of a chunk with a + * trailing compressed part. What we get back is an allocated area + * holding the original prefix part and an uncompressed version of the + * trailing part (the malloc area passed in is freed). + */ +png_charp /* PRIVATE */ +png_decompress_chunk(png_structp png_ptr, int comp_type, + png_charp chunkdata, png_size_t chunklength, + png_size_t prefix_size, png_size_t *newlength) +{ + static char msg[] = "Error decoding compressed text"; + png_charp text; + png_size_t text_size; + + if (comp_type == PNG_COMPRESSION_TYPE_BASE) + { + int ret = Z_OK; + png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size); + png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + text_size = 0; + text = NULL; + + while (png_ptr->zstream.avail_in) + { + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret != Z_OK && ret != Z_STREAM_END) + { + if (png_ptr->zstream.msg != NULL) + png_warning(png_ptr, png_ptr->zstream.msg); + else + png_warning(png_ptr, msg); + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + + if (text == NULL) + { + text_size = prefix_size + png_sizeof(msg) + 1; + text = (png_charp)png_malloc_warn(png_ptr, text_size); + if (text == NULL) + { + png_free(png_ptr,chunkdata); + png_error(png_ptr,"Not enough memory to decompress chunk"); + } + png_memcpy(text, chunkdata, prefix_size); + } + + text[text_size - 1] = 0x00; + + /* Copy what we can of the error message into the text chunk */ + text_size = (png_size_t)(chunklength - (text - chunkdata) - 1); + text_size = png_sizeof(msg) > text_size ? text_size : + png_sizeof(msg); + png_memcpy(text + prefix_size, msg, text_size + 1); + break; + } + if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END) + { + if (text == NULL) + { + text_size = prefix_size + + png_ptr->zbuf_size - png_ptr->zstream.avail_out; + text = (png_charp)png_malloc_warn(png_ptr, text_size + 1); + if (text == NULL) + { + png_free(png_ptr,chunkdata); + png_error(png_ptr,"Not enough memory to decompress chunk."); + } + png_memcpy(text + prefix_size, png_ptr->zbuf, + text_size - prefix_size); + png_memcpy(text, chunkdata, prefix_size); + *(text + text_size) = 0x00; + } + else + { + png_charp tmp; + + tmp = text; + text = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)(text_size + + png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1)); + if (text == NULL) + { + png_free(png_ptr, tmp); + png_free(png_ptr, chunkdata); + png_error(png_ptr,"Not enough memory to decompress chunk.."); + } + png_memcpy(text, tmp, text_size); + png_free(png_ptr, tmp); + png_memcpy(text + text_size, png_ptr->zbuf, + (png_ptr->zbuf_size - png_ptr->zstream.avail_out)); + text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; + *(text + text_size) = 0x00; + } + if (ret == Z_STREAM_END) + break; + else + { + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + } + if (ret != Z_STREAM_END) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char umsg[50]; + + if (ret == Z_BUF_ERROR) + sprintf(umsg,"Buffer error in compressed datastream in %s chunk", + png_ptr->chunk_name); + else if (ret == Z_DATA_ERROR) + sprintf(umsg,"Data error in compressed datastream in %s chunk", + png_ptr->chunk_name); + else + sprintf(umsg,"Incomplete compressed datastream in %s chunk", + png_ptr->chunk_name); + png_warning(png_ptr, umsg); +#else + png_warning(png_ptr, + "Incomplete compressed datastream in chunk other than IDAT"); +#endif + text_size=prefix_size; + if (text == NULL) + { + text = (png_charp)png_malloc_warn(png_ptr, text_size+1); + if (text == NULL) + { + png_free(png_ptr, chunkdata); + png_error(png_ptr,"Not enough memory for text."); + } + png_memcpy(text, chunkdata, prefix_size); + } + *(text + text_size) = 0x00; + } + + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + + png_free(png_ptr, chunkdata); + chunkdata = text; + *newlength=text_size; + } + else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char umsg[50]; + + sprintf(umsg, "Unknown zTXt compression type %d", comp_type); + png_warning(png_ptr, umsg); +#else + png_warning(png_ptr, "Unknown zTXt compression type"); +#endif + + *(chunkdata + prefix_size) = 0x00; + *newlength=prefix_size; + } + + return chunkdata; +} +#endif + +/* read and check the IDHR chunk */ +void /* PRIVATE */ +png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[13]; + png_uint_32 width, height; + int bit_depth, color_type, compression_type, filter_type; + int interlace_type; + + png_debug(1, "in png_handle_IHDR\n"); + + if (png_ptr->mode & PNG_HAVE_IHDR) + png_error(png_ptr, "Out of place IHDR"); + + /* check the length */ + if (length != 13) + png_error(png_ptr, "Invalid IHDR chunk"); + + png_ptr->mode |= PNG_HAVE_IHDR; + + png_crc_read(png_ptr, buf, 13); + png_crc_finish(png_ptr, 0); + + width = png_get_uint_31(png_ptr, buf); + height = png_get_uint_31(png_ptr, buf + 4); + bit_depth = buf[8]; + color_type = buf[9]; + compression_type = buf[10]; + filter_type = buf[11]; + interlace_type = buf[12]; + + /* set internal variables */ + png_ptr->width = width; + png_ptr->height = height; + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->interlaced = (png_byte)interlace_type; + png_ptr->color_type = (png_byte)color_type; +#if defined(PNG_MNG_FEATURES_SUPPORTED) + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + + /* find number of channels */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_PALETTE: + png_ptr->channels = 1; + break; + case PNG_COLOR_TYPE_RGB: + png_ptr->channels = 3; + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_ptr->channels = 2; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + png_ptr->channels = 4; + break; + } + + /* set up other useful info */ + png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * + png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width); + png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth); + png_debug1(3,"channels = %d\n", png_ptr->channels); + png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes); + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, + color_type, interlace_type, compression_type, filter_type); +} + +/* read and check the palette */ +void /* PRIVATE */ +png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_color palette[PNG_MAX_PALETTE_LENGTH]; + int num, i; +#ifndef PNG_NO_POINTER_INDEXING + png_colorp pal_ptr; +#endif + + png_debug(1, "in png_handle_PLTE\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before PLTE"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid PLTE after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + png_error(png_ptr, "Duplicate PLTE chunk"); + + png_ptr->mode |= PNG_HAVE_PLTE; + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring PLTE chunk in grayscale PNG"); + png_crc_finish(png_ptr, length); + return; + } +#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_crc_finish(png_ptr, length); + return; + } +#endif + + if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) + { + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_warning(png_ptr, "Invalid palette chunk"); + png_crc_finish(png_ptr, length); + return; + } + else + { + png_error(png_ptr, "Invalid palette chunk"); + } + } + + num = (int)length / 3; + +#ifndef PNG_NO_POINTER_INDEXING + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + pal_ptr->red = buf[0]; + pal_ptr->green = buf[1]; + pal_ptr->blue = buf[2]; + } +#else + for (i = 0; i < num; i++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + /* don't depend upon png_color being any order */ + palette[i].red = buf[0]; + palette[i].green = buf[1]; + palette[i].blue = buf[2]; + } +#endif + + /* If we actually NEED the PLTE chunk (ie for a paletted image), we do + whatever the normal CRC configuration tells us. However, if we + have an RGB image, the PLTE can be considered ancillary, so + we will act as though it is. */ +#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#endif + { + png_crc_finish(png_ptr, 0); + } +#if !defined(PNG_READ_OPT_PLTE_SUPPORTED) + else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ + { + /* If we don't want to use the data from an ancillary chunk, + we have two options: an error abort, or a warning and we + ignore the data in this chunk (which should be OK, since + it's considered ancillary for a RGB or RGBA image). */ + if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) + { + if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) + { + png_chunk_error(png_ptr, "CRC error"); + } + else + { + png_chunk_warning(png_ptr, "CRC error"); + return; + } + } + /* Otherwise, we (optionally) emit a warning and use the chunk. */ + else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) + { + png_chunk_warning(png_ptr, "CRC error"); + } + } +#endif + + png_set_PLTE(png_ptr, info_ptr, palette, num); + +#if defined(PNG_READ_tRNS_SUPPORTED) + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + if (png_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); + png_ptr->num_trans = (png_uint_16)num; + } + if (info_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect info tRNS chunk length"); + info_ptr->num_trans = (png_uint_16)num; + } + } + } +#endif + +} + +void /* PRIVATE */ +png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_debug(1, "in png_handle_IEND\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) + { + png_error(png_ptr, "No image in file"); + } + + png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); + + if (length != 0) + { + png_warning(png_ptr, "Incorrect IEND chunk length"); + } + png_crc_finish(png_ptr, length); + + if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */ + return; +} + +#if defined(PNG_READ_gAMA_SUPPORTED) +void /* PRIVATE */ +png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_fixed_point igamma; +#ifdef PNG_FLOATING_POINT_SUPPORTED + float file_gamma; +#endif + png_byte buf[4]; + + png_debug(1, "in png_handle_gAMA\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before gAMA"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid gAMA after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place gAMA chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) +#if defined(PNG_READ_sRGB_SUPPORTED) + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) + { + png_warning(png_ptr, "Duplicate gAMA chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 4) + { + png_warning(png_ptr, "Incorrect gAMA chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 4); + if (png_crc_finish(png_ptr, 0)) + return; + + igamma = (png_fixed_point)png_get_uint_32(buf); + /* check for zero gamma */ + if (igamma == 0) + { + png_warning(png_ptr, + "Ignoring gAMA chunk with gamma=0"); + return; + } + +#if defined(PNG_READ_sRGB_SUPPORTED) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) + { + png_warning(png_ptr, + "Ignoring incorrect gAMA value when sRGB is also present"); +#ifndef PNG_NO_CONSOLE_IO + fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma); +#endif + return; + } +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + file_gamma = (float)igamma / (float)100000.0; +# ifdef PNG_READ_GAMMA_SUPPORTED + png_ptr->gamma = file_gamma; +# endif + png_set_gAMA(png_ptr, info_ptr, file_gamma); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_gAMA_fixed(png_ptr, info_ptr, igamma); +#endif +} +#endif + +#if defined(PNG_READ_sBIT_SUPPORTED) +void /* PRIVATE */ +png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[4]; + + png_debug(1, "in png_handle_sBIT\n"); + + buf[0] = buf[1] = buf[2] = buf[3] = 0; + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sBIT"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sBIT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + { + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sBIT chunk"); + } + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) + { + png_warning(png_ptr, "Duplicate sBIT chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 3; + else + truelen = (png_size_t)png_ptr->channels; + + if (length != truelen || length > 4) + { + png_warning(png_ptr, "Incorrect sBIT chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + if (png_crc_finish(png_ptr, 0)) + return; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[1]; + png_ptr->sig_bit.blue = buf[2]; + png_ptr->sig_bit.alpha = buf[3]; + } + else + { + png_ptr->sig_bit.gray = buf[0]; + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[0]; + png_ptr->sig_bit.blue = buf[0]; + png_ptr->sig_bit.alpha = buf[1]; + } + png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); +} +#endif + +#if defined(PNG_READ_cHRM_SUPPORTED) +void /* PRIVATE */ +png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[4]; +#ifdef PNG_FLOATING_POINT_SUPPORTED + float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; +#endif + png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, + int_y_green, int_x_blue, int_y_blue; + + png_uint_32 uint_x, uint_y; + + png_debug(1, "in png_handle_cHRM\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before cHRM"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid cHRM after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Missing PLTE before cHRM"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) +#if defined(PNG_READ_sRGB_SUPPORTED) + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) + { + png_warning(png_ptr, "Duplicate cHRM chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 32) + { + png_warning(png_ptr, "Incorrect cHRM chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 4); + uint_x = png_get_uint_32(buf); + + png_crc_read(png_ptr, buf, 4); + uint_y = png_get_uint_32(buf); + + if (uint_x > 80000L || uint_y > 80000L || + uint_x + uint_y > 100000L) + { + png_warning(png_ptr, "Invalid cHRM white point"); + png_crc_finish(png_ptr, 24); + return; + } + int_x_white = (png_fixed_point)uint_x; + int_y_white = (png_fixed_point)uint_y; + + png_crc_read(png_ptr, buf, 4); + uint_x = png_get_uint_32(buf); + + png_crc_read(png_ptr, buf, 4); + uint_y = png_get_uint_32(buf); + + if (uint_x + uint_y > 100000L) + { + png_warning(png_ptr, "Invalid cHRM red point"); + png_crc_finish(png_ptr, 16); + return; + } + int_x_red = (png_fixed_point)uint_x; + int_y_red = (png_fixed_point)uint_y; + + png_crc_read(png_ptr, buf, 4); + uint_x = png_get_uint_32(buf); + + png_crc_read(png_ptr, buf, 4); + uint_y = png_get_uint_32(buf); + + if (uint_x + uint_y > 100000L) + { + png_warning(png_ptr, "Invalid cHRM green point"); + png_crc_finish(png_ptr, 8); + return; + } + int_x_green = (png_fixed_point)uint_x; + int_y_green = (png_fixed_point)uint_y; + + png_crc_read(png_ptr, buf, 4); + uint_x = png_get_uint_32(buf); + + png_crc_read(png_ptr, buf, 4); + uint_y = png_get_uint_32(buf); + + if (uint_x + uint_y > 100000L) + { + png_warning(png_ptr, "Invalid cHRM blue point"); + png_crc_finish(png_ptr, 0); + return; + } + int_x_blue = (png_fixed_point)uint_x; + int_y_blue = (png_fixed_point)uint_y; + +#ifdef PNG_FLOATING_POINT_SUPPORTED + white_x = (float)int_x_white / (float)100000.0; + white_y = (float)int_y_white / (float)100000.0; + red_x = (float)int_x_red / (float)100000.0; + red_y = (float)int_y_red / (float)100000.0; + green_x = (float)int_x_green / (float)100000.0; + green_y = (float)int_y_green / (float)100000.0; + blue_x = (float)int_x_blue / (float)100000.0; + blue_y = (float)int_y_blue / (float)100000.0; +#endif + +#if defined(PNG_READ_sRGB_SUPPORTED) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + { + if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) || + PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) || + PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000)) + { + + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); +#ifndef PNG_NO_CONSOLE_IO +#ifdef PNG_FLOATING_POINT_SUPPORTED + fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n", + white_x, white_y, red_x, red_y); + fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n", + green_x, green_y, blue_x, blue_y); +#else + fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", + int_x_white, int_y_white, int_x_red, int_y_red); + fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n", + int_x_green, int_y_green, int_x_blue, int_y_blue); +#endif +#endif /* PNG_NO_CONSOLE_IO */ + } + png_crc_finish(png_ptr, 0); + return; + } +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_cHRM(png_ptr, info_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_cHRM_fixed(png_ptr, info_ptr, + int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, + int_y_green, int_x_blue, int_y_blue); +#endif + if (png_crc_finish(png_ptr, 0)) + return; +} +#endif + +#if defined(PNG_READ_sRGB_SUPPORTED) +void /* PRIVATE */ +png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + int intent; + png_byte buf[1]; + + png_debug(1, "in png_handle_sRGB\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sRGB"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sRGB after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sRGB chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + { + png_warning(png_ptr, "Duplicate sRGB chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 1) + { + png_warning(png_ptr, "Incorrect sRGB chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 1); + if (png_crc_finish(png_ptr, 0)) + return; + + intent = buf[0]; + /* check for bad intent */ + if (intent >= PNG_sRGB_INTENT_LAST) + { + png_warning(png_ptr, "Unknown sRGB intent"); + return; + } + +#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) + { + png_fixed_point igamma; +#ifdef PNG_FIXED_POINT_SUPPORTED + igamma=info_ptr->int_gamma; +#else +# ifdef PNG_FLOATING_POINT_SUPPORTED + igamma=(png_fixed_point)(info_ptr->gamma * 100000.); +# endif +#endif + if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) + { + png_warning(png_ptr, + "Ignoring incorrect gAMA value when sRGB is also present"); +#ifndef PNG_NO_CONSOLE_IO +# ifdef PNG_FIXED_POINT_SUPPORTED + fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma); +# else +# ifdef PNG_FLOATING_POINT_SUPPORTED + fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma); +# endif +# endif +#endif + } + } +#endif /* PNG_READ_gAMA_SUPPORTED */ + +#ifdef PNG_READ_cHRM_SUPPORTED +#ifdef PNG_FIXED_POINT_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000)) + { + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); + } +#endif /* PNG_FIXED_POINT_SUPPORTED */ +#endif /* PNG_READ_cHRM_SUPPORTED */ + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); +} +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#if defined(PNG_READ_iCCP_SUPPORTED) +void /* PRIVATE */ +png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_charp chunkdata; + png_byte compression_type; + png_bytep pC; + png_charp profile; + png_uint_32 skip = 0; + png_uint_32 profile_size, profile_length; + png_size_t slength, prefix_length, data_length; + + png_debug(1, "in png_handle_iCCP\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iCCP"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid iCCP after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place iCCP chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)) + { + png_warning(png_ptr, "Duplicate iCCP chunk"); + png_crc_finish(png_ptr, length); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "iCCP chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, chunkdata); + return; + } + + chunkdata[slength] = 0x00; + + for (profile = chunkdata; *profile; profile++) + /* empty loop to find end of name */ ; + + ++profile; + + /* there should be at least one zero (the compression type byte) + following the separator, and we should be on it */ + if ( profile >= chunkdata + slength) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "Malformed iCCP chunk"); + return; + } + + /* compression_type should always be zero */ + compression_type = *profile++; + if (compression_type) + { + png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); + compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 + wrote nonzero) */ + } + + prefix_length = profile - chunkdata; + chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata, + slength, prefix_length, &data_length); + + profile_length = data_length - prefix_length; + + if ( prefix_length > data_length || profile_length < 4) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "Profile size field missing from iCCP chunk"); + return; + } + + /* Check the profile_size recorded in the first 32 bits of the ICC profile */ + pC = (png_bytep)(chunkdata+prefix_length); + profile_size = ((*(pC ))<<24) | + ((*(pC+1))<<16) | + ((*(pC+2))<< 8) | + ((*(pC+3)) ); + + if(profile_size < profile_length) + profile_length = profile_size; + + if(profile_size > profile_length) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "Ignoring truncated iCCP profile."); + return; + } + + png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type, + chunkdata + prefix_length, profile_length); + png_free(png_ptr, chunkdata); +} +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#if defined(PNG_READ_sPLT_SUPPORTED) +void /* PRIVATE */ +png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_bytep chunkdata; + png_bytep entry_start; + png_sPLT_t new_palette; +#ifdef PNG_NO_POINTER_INDEXING + png_sPLT_entryp pp; +#endif + int data_length, entry_size, i; + png_uint_32 skip = 0; + png_size_t slength; + + png_debug(1, "in png_handle_sPLT\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sPLT"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sPLT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "sPLT chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + chunkdata = (png_bytep)png_malloc(png_ptr, length + 1); + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, chunkdata); + return; + } + + chunkdata[slength] = 0x00; + + for (entry_start = chunkdata; *entry_start; entry_start++) + /* empty loop to find end of name */ ; + ++entry_start; + + /* a sample depth should follow the separator, and we should be on it */ + if (entry_start > chunkdata + slength) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "malformed sPLT chunk"); + return; + } + + new_palette.depth = *entry_start++; + entry_size = (new_palette.depth == 8 ? 6 : 10); + data_length = (slength - (entry_start - chunkdata)); + + /* integrity-check the data length */ + if (data_length % entry_size) + { + png_free(png_ptr, chunkdata); + png_warning(png_ptr, "sPLT chunk has bad length"); + return; + } + + new_palette.nentries = (png_int_32) ( data_length / entry_size); + if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX / + png_sizeof(png_sPLT_entry))) + { + png_warning(png_ptr, "sPLT chunk too long"); + return; + } + new_palette.entries = (png_sPLT_entryp)png_malloc_warn( + png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); + if (new_palette.entries == NULL) + { + png_warning(png_ptr, "sPLT chunk requires too much memory"); + return; + } + +#ifndef PNG_NO_POINTER_INDEXING + for (i = 0; i < new_palette.nentries; i++) + { + png_sPLT_entryp pp = new_palette.entries + i; + + if (new_palette.depth == 8) + { + pp->red = *entry_start++; + pp->green = *entry_start++; + pp->blue = *entry_start++; + pp->alpha = *entry_start++; + } + else + { + pp->red = png_get_uint_16(entry_start); entry_start += 2; + pp->green = png_get_uint_16(entry_start); entry_start += 2; + pp->blue = png_get_uint_16(entry_start); entry_start += 2; + pp->alpha = png_get_uint_16(entry_start); entry_start += 2; + } + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#else + pp = new_palette.entries; + for (i = 0; i < new_palette.nentries; i++) + { + + if (new_palette.depth == 8) + { + pp[i].red = *entry_start++; + pp[i].green = *entry_start++; + pp[i].blue = *entry_start++; + pp[i].alpha = *entry_start++; + } + else + { + pp[i].red = png_get_uint_16(entry_start); entry_start += 2; + pp[i].green = png_get_uint_16(entry_start); entry_start += 2; + pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; + pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; + } + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#endif + + /* discard all chunk data except the name and stash that */ + new_palette.name = (png_charp)chunkdata; + + png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); + + png_free(png_ptr, chunkdata); + png_free(png_ptr, new_palette.entries); +} +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#if defined(PNG_READ_tRNS_SUPPORTED) +void /* PRIVATE */ +png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_tRNS\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tRNS"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid tRNS after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_warning(png_ptr, "Duplicate tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + png_byte buf[2]; + + if (length != 2) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 2); + png_ptr->num_trans = 1; + png_ptr->trans_values.gray = png_get_uint_16(buf); + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_byte buf[6]; + + if (length != 6) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + png_crc_read(png_ptr, buf, (png_size_t)length); + png_ptr->num_trans = 1; + png_ptr->trans_values.red = png_get_uint_16(buf); + png_ptr->trans_values.green = png_get_uint_16(buf + 2); + png_ptr->trans_values.blue = png_get_uint_16(buf + 4); + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + /* Should be an error, but we can cope with it. */ + png_warning(png_ptr, "Missing PLTE before tRNS"); + } + if (length > (png_uint_32)png_ptr->num_palette || + length > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + if (length == 0) + { + png_warning(png_ptr, "Zero length tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + png_crc_read(png_ptr, readbuf, (png_size_t)length); + png_ptr->num_trans = (png_uint_16)length; + } + else + { + png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_crc_finish(png_ptr, 0)) + return; + + png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, + &(png_ptr->trans_values)); +} +#endif + +#if defined(PNG_READ_bKGD_SUPPORTED) +void /* PRIVATE */ +png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[6]; + + png_debug(1, "in png_handle_bKGD\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before bKGD"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid bKGD after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before bKGD"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) + { + png_warning(png_ptr, "Duplicate bKGD chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 1; + else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + truelen = 6; + else + truelen = 2; + + if (length != truelen) + { + png_warning(png_ptr, "Incorrect bKGD chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + if (png_crc_finish(png_ptr, 0)) + return; + + /* We convert the index value into RGB components so that we can allow + * arbitrary RGB values for background when we have transparency, and + * so it is easy to determine the RGB values of the background color + * from the info_ptr struct. */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_ptr->background.index = buf[0]; + if(info_ptr->num_palette) + { + if(buf[0] > info_ptr->num_palette) + { + png_warning(png_ptr, "Incorrect bKGD chunk index value"); + return; + } + png_ptr->background.red = + (png_uint_16)png_ptr->palette[buf[0]].red; + png_ptr->background.green = + (png_uint_16)png_ptr->palette[buf[0]].green; + png_ptr->background.blue = + (png_uint_16)png_ptr->palette[buf[0]].blue; + } + } + else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ + { + png_ptr->background.red = + png_ptr->background.green = + png_ptr->background.blue = + png_ptr->background.gray = png_get_uint_16(buf); + } + else + { + png_ptr->background.red = png_get_uint_16(buf); + png_ptr->background.green = png_get_uint_16(buf + 2); + png_ptr->background.blue = png_get_uint_16(buf + 4); + } + + png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background)); +} +#endif + +#if defined(PNG_READ_hIST_SUPPORTED) +void /* PRIVATE */ +png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + unsigned int num, i; + png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_hIST\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before hIST"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid hIST after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before hIST"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) + { + png_warning(png_ptr, "Duplicate hIST chunk"); + png_crc_finish(png_ptr, length); + return; + } + + num = length / 2 ; + if (num != (unsigned int) png_ptr->num_palette || num > + (unsigned int) PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, "Incorrect hIST chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + for (i = 0; i < num; i++) + { + png_byte buf[2]; + + png_crc_read(png_ptr, buf, 2); + readbuf[i] = png_get_uint_16(buf); + } + + if (png_crc_finish(png_ptr, 0)) + return; + + png_set_hIST(png_ptr, info_ptr, readbuf); +} +#endif + +#if defined(PNG_READ_pHYs_SUPPORTED) +void /* PRIVATE */ +png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_uint_32 res_x, res_y; + int unit_type; + + png_debug(1, "in png_handle_pHYs\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pHYs"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pHYs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_warning(png_ptr, "Duplicate pHYs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect pHYs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + if (png_crc_finish(png_ptr, 0)) + return; + + res_x = png_get_uint_32(buf); + res_y = png_get_uint_32(buf + 4); + unit_type = buf[8]; + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); +} +#endif + +#if defined(PNG_READ_oFFs_SUPPORTED) +void /* PRIVATE */ +png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_int_32 offset_x, offset_y; + int unit_type; + + png_debug(1, "in png_handle_oFFs\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before oFFs"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid oFFs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_warning(png_ptr, "Duplicate oFFs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect oFFs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + if (png_crc_finish(png_ptr, 0)) + return; + + offset_x = png_get_int_32(buf); + offset_y = png_get_int_32(buf + 4); + unit_type = buf[8]; + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); +} +#endif + +#if defined(PNG_READ_pCAL_SUPPORTED) +/* read the pCAL chunk (described in the PNG Extensions document) */ +void /* PRIVATE */ +png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_charp purpose; + png_int_32 X0, X1; + png_byte type, nparams; + png_charp buf, units, endptr; + png_charpp params; + png_size_t slength; + int i; + + png_debug(1, "in png_handle_pCAL\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pCAL"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) + { + png_warning(png_ptr, "Duplicate pCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n", + length + 1); + purpose = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (purpose == NULL) + { + png_warning(png_ptr, "No memory for pCAL purpose."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)purpose, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, purpose); + return; + } + + purpose[slength] = 0x00; /* null terminate the last string */ + + png_debug(3, "Finding end of pCAL purpose string\n"); + for (buf = purpose; *buf; buf++) + /* empty loop */ ; + + endptr = purpose + slength; + + /* We need to have at least 12 bytes after the purpose string + in order to get the parameter information. */ + if (endptr <= buf + 12) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, purpose); + return; + } + + png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n"); + X0 = png_get_int_32((png_bytep)buf+1); + X1 = png_get_int_32((png_bytep)buf+5); + type = buf[9]; + nparams = buf[10]; + units = buf + 11; + + png_debug(3, "Checking pCAL equation type and number of parameters\n"); + /* Check that we have the right number of parameters for known + equation types. */ + if ((type == PNG_EQUATION_LINEAR && nparams != 2) || + (type == PNG_EQUATION_BASE_E && nparams != 3) || + (type == PNG_EQUATION_ARBITRARY && nparams != 3) || + (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) + { + png_warning(png_ptr, "Invalid pCAL parameters for equation type"); + png_free(png_ptr, purpose); + return; + } + else if (type >= PNG_EQUATION_LAST) + { + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + } + + for (buf = units; *buf; buf++) + /* Empty loop to move past the units string. */ ; + + png_debug(3, "Allocating pCAL parameters array\n"); + params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams + *png_sizeof(png_charp))) ; + if (params == NULL) + { + png_free(png_ptr, purpose); + png_warning(png_ptr, "No memory for pCAL params."); + return; + } + + /* Get pointers to the start of each parameter string. */ + for (i = 0; i < (int)nparams; i++) + { + buf++; /* Skip the null string terminator from previous parameter. */ + + png_debug1(3, "Reading pCAL parameter %d\n", i); + for (params[i] = buf; *buf != 0x00 && buf <= endptr; buf++) + /* Empty loop to move past each parameter string */ ; + + /* Make sure we haven't run out of data yet */ + if (buf > endptr) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, purpose); + png_free(png_ptr, params); + return; + } + } + + png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams, + units, params); + + png_free(png_ptr, purpose); + png_free(png_ptr, params); +} +#endif + +#if defined(PNG_READ_sCAL_SUPPORTED) +/* read the sCAL chunk */ +void /* PRIVATE */ +png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_charp buffer, ep; +#ifdef PNG_FLOATING_POINT_SUPPORTED + double width, height; + png_charp vp; +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_charp swidth, sheight; +#endif +#endif + png_size_t slength; + + png_debug(1, "in png_handle_sCAL\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sCAL"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) + { + png_warning(png_ptr, "Duplicate sCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n", + length + 1); + buffer = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (buffer == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk"); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)buffer, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, buffer); + return; + } + + buffer[slength] = 0x00; /* null terminate the last string */ + + ep = buffer + 1; /* skip unit byte */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + width = strtod(ep, &vp); + if (*vp) + { + png_warning(png_ptr, "malformed width string in sCAL chunk"); + return; + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); + if (swidth == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); + return; + } + png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); +#endif +#endif + + for (ep = buffer; *ep; ep++) + /* empty loop */ ; + ep++; + +#ifdef PNG_FLOATING_POINT_SUPPORTED + height = strtod(ep, &vp); + if (*vp) + { + png_warning(png_ptr, "malformed height string in sCAL chunk"); + return; + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); + if (swidth == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); + return; + } + png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); +#endif +#endif + + if (buffer + slength < ep +#ifdef PNG_FLOATING_POINT_SUPPORTED + || width <= 0. || height <= 0. +#endif + ) + { + png_warning(png_ptr, "Invalid sCAL data"); + png_free(png_ptr, buffer); +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); + png_free(png_ptr, sheight); +#endif + return; + } + + +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight); +#endif +#endif + + png_free(png_ptr, buffer); +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); + png_free(png_ptr, sheight); +#endif +} +#endif + +#if defined(PNG_READ_tIME_SUPPORTED) +void /* PRIVATE */ +png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[7]; + png_time mod_time; + + png_debug(1, "in png_handle_tIME\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Out of place tIME chunk"); + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) + { + png_warning(png_ptr, "Duplicate tIME chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + + if (length != 7) + { + png_warning(png_ptr, "Incorrect tIME chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 7); + if (png_crc_finish(png_ptr, 0)) + return; + + mod_time.second = buf[6]; + mod_time.minute = buf[5]; + mod_time.hour = buf[4]; + mod_time.day = buf[3]; + mod_time.month = buf[2]; + mod_time.year = png_get_uint_16(buf); + + png_set_tIME(png_ptr, info_ptr, &mod_time); +} +#endif + +#if defined(PNG_READ_tEXt_SUPPORTED) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp key; + png_charp text; + png_uint_32 skip = 0; + png_size_t slength; + int ret; + + png_debug(1, "in png_handle_tEXt\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tEXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "tEXt chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + key = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (key == NULL) + { + png_warning(png_ptr, "No memory to process text chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)key, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, key); + return; + } + + key[slength] = 0x00; + + for (text = key; *text; text++) + /* empty loop to find end of key */ ; + + if (text != key + slength) + text++; + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process text chunk."); + png_free(png_ptr, key); + return; + } + text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; +#endif + text_ptr->text = text; + text_ptr->text_length = png_strlen(text); + + ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, key); + png_free(png_ptr, text_ptr); + if (ret) + png_warning(png_ptr, "Insufficient memory to process text chunk."); +} +#endif + +#if defined(PNG_READ_zTXt_SUPPORTED) +/* note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp chunkdata; + png_charp text; + int comp_type; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_zTXt\n"); + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before zTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + there is no hard and fast rule to tell us where to stop. */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr,"zTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (chunkdata == NULL) + { + png_warning(png_ptr,"Out of memory processing zTXt chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunkdata, slength); + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, chunkdata); + return; + } + + chunkdata[slength] = 0x00; + + for (text = chunkdata; *text; text++) + /* empty loop */ ; + + /* zTXt must have some text after the chunkdataword */ + if (text == chunkdata + slength) + { + comp_type = PNG_TEXT_COMPRESSION_NONE; + png_warning(png_ptr, "Zero length zTXt chunk"); + } + else + { + comp_type = *(++text); + if (comp_type != PNG_TEXT_COMPRESSION_zTXt) + { + png_warning(png_ptr, "Unknown compression type in zTXt chunk"); + comp_type = PNG_TEXT_COMPRESSION_zTXt; + } + text++; /* skip the compression_method byte */ + } + prefix_len = text - chunkdata; + + chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata, + (png_size_t)length, prefix_len, &data_len); + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr,"Not enough memory to process zTXt chunk."); + png_free(png_ptr, chunkdata); + return; + } + text_ptr->compression = comp_type; + text_ptr->key = chunkdata; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; +#endif + text_ptr->text = chunkdata + prefix_len; + text_ptr->text_length = data_len; + + ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, chunkdata); + if (ret) + png_error(png_ptr, "Insufficient memory to store zTXt chunk."); +} +#endif + +#if defined(PNG_READ_iTXt_SUPPORTED) +/* note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp chunkdata; + png_charp key, lang, text, lang_key; + int comp_flag; + int comp_type = 0; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_iTXt\n"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + there is no hard and fast rule to tell us where to stop. */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr,"iTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (chunkdata == NULL) + { + png_warning(png_ptr, "No memory to process iTXt chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunkdata, slength); + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, chunkdata); + return; + } + + chunkdata[slength] = 0x00; + + for (lang = chunkdata; *lang; lang++) + /* empty loop */ ; + lang++; /* skip NUL separator */ + + /* iTXt must have a language tag (possibly empty), two compression bytes, + translated keyword (possibly empty), and possibly some text after the + keyword */ + + if (lang >= chunkdata + slength) + { + comp_flag = PNG_TEXT_COMPRESSION_NONE; + png_warning(png_ptr, "Zero length iTXt chunk"); + } + else + { + comp_flag = *lang++; + comp_type = *lang++; + } + + for (lang_key = lang; *lang_key; lang_key++) + /* empty loop */ ; + lang_key++; /* skip NUL separator */ + + for (text = lang_key; *text; text++) + /* empty loop */ ; + text++; /* skip NUL separator */ + + prefix_len = text - chunkdata; + + key=chunkdata; + if (comp_flag) + chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata, + (size_t)length, prefix_len, &data_len); + else + data_len=png_strlen(chunkdata + prefix_len); + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr,"Not enough memory to process iTXt chunk."); + png_free(png_ptr, chunkdata); + return; + } + text_ptr->compression = (int)comp_flag + 1; + text_ptr->lang_key = chunkdata+(lang_key-key); + text_ptr->lang = chunkdata+(lang-key); + text_ptr->itxt_length = data_len; + text_ptr->text_length = 0; + text_ptr->key = chunkdata; + text_ptr->text = chunkdata + prefix_len; + + ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, chunkdata); + if (ret) + png_error(png_ptr, "Insufficient memory to store iTXt chunk."); +} +#endif + +/* This function is called when we haven't found a handler for a + chunk. If there isn't a problem with the chunk itself (ie bad + chunk name, CRC, or a critical chunk), the chunk is silently ignored + -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which + case it will be saved away to be written out later. */ +void /* PRIVATE */ +png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_uint_32 skip = 0; + + png_debug(1, "in png_handle_unknown\n"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#endif + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */ + png_ptr->mode |= PNG_AFTER_IDAT; + } + + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + + if (!(png_ptr->chunk_name[0] & 0x20)) + { +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS +#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) + && png_ptr->read_user_chunk_fn == NULL +#endif + ) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + } + +#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) || + (png_ptr->read_user_chunk_fn != NULL)) + { + png_unknown_chunk chunk; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "unknown chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); + chunk.data = (png_bytep)png_malloc(png_ptr, length); + chunk.size = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)chunk.data, length); +#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) + if(png_ptr->read_user_chunk_fn != NULL) + { + /* callback to user unknown chunk handler */ + if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0) + { + if (!(png_ptr->chunk_name[0] & 0x20)) + if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS) + { + png_free(png_ptr, chunk.data); + png_chunk_error(png_ptr, "unknown critical chunk"); + } + png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1); + } + } + else +#endif + png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1); + png_free(png_ptr, chunk.data); + } + else +#endif + skip = length; + + png_crc_finish(png_ptr, skip); + +#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) + if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */ + return; +#endif +} + +/* This function is called to verify that a chunk name is valid. + This function can't have the "critical chunk check" incorporated + into it, since in the future we will need to be able to call user + functions to handle unknown critical chunks after we check that + the chunk name itself is valid. */ + +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) + +void /* PRIVATE */ +png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name) +{ + png_debug(1, "in png_check_chunk_name\n"); + if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) || + isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3])) + { + png_chunk_error(png_ptr, "invalid chunk type"); + } +} + +/* Combines the row recently read in with the existing pixels in the + row. This routine takes care of alpha and transparency if requested. + This routine also handles the two methods of progressive display + of interlaced images, depending on the mask value. + The mask value describes which pixels are to be combined with + the row. The pattern always repeats every 8 pixels, so just 8 + bits are needed. A one indicates the pixel is to be combined, + a zero indicates the pixel is to be skipped. This is in addition + to any alpha or transparency value associated with the pixel. If + you want all pixels to be combined, pass 0xff (255) in mask. */ +#ifndef PNG_HAVE_ASSEMBLER_COMBINE_ROW +void /* PRIVATE */ +png_combine_row(png_structp png_ptr, png_bytep row, int mask) +{ + png_debug(1,"in png_combine_row\n"); + if (mask == 0xff) + { + png_memcpy(row, png_ptr->row_buf + 1, + PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width)); + } + else + { + switch (png_ptr->row_info.pixel_depth) + { + case 1: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_inc, s_start, s_end; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 7; + s_inc = 1; + } + else +#endif + { + s_start = 7; + s_end = 0; + s_inc = -1; + } + + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + int value; + + value = (*sp >> shift) & 0x01; + *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + case 2: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_start, s_end, s_inc; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + int value; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 6; + s_inc = 2; + } + else +#endif + { + s_start = 6; + s_end = 0; + s_inc = -2; + } + + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + value = (*sp >> shift) & 0x03; + *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + case 4: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_start, s_end, s_inc; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + int value; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 4; + s_inc = 4; + } + else +#endif + { + s_start = 4; + s_end = 0; + s_inc = -4; + } + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + value = (*sp >> shift) & 0xf; + *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + default: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3); + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + png_byte m = 0x80; + + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + png_memcpy(dp, sp, pixel_bytes); + } + + sp += pixel_bytes; + dp += pixel_bytes; + + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + } + } +} +#endif /* !PNG_HAVE_ASSEMBLER_COMBINE_ROW */ + +#ifdef PNG_READ_INTERLACING_SUPPORTED +#ifndef PNG_HAVE_ASSEMBLER_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */ +/* OLD pre-1.0.9 interface: +void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, + png_uint_32 transformations) + */ +void /* PRIVATE */ +png_do_read_interlace(png_structp png_ptr) +{ + png_row_infop row_info = &(png_ptr->row_info); + png_bytep row = png_ptr->row_buf + 1; + int pass = png_ptr->pass; + png_uint_32 transformations = png_ptr->transformations; +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + /* offset to next interlace block */ + const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; +#endif + + png_debug(1,"in png_do_read_interlace (stock C version)\n"); + if (row != NULL && row_info != NULL) + { + png_uint_32 final_width; + + final_width = row_info->width * png_pass_inc[pass]; + + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_byte v; + png_uint_32 i; + int j; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (transformations & PNG_PACKSWAP) + { + sshift = (int)((row_info->width + 7) & 0x07); + dshift = (int)((final_width + 7) & 0x07); + s_start = 7; + s_end = 0; + s_inc = -1; + } + else +#endif + { + sshift = 7 - (int)((row_info->width + 7) & 0x07); + dshift = 7 - (int)((final_width + 7) & 0x07); + s_start = 0; + s_end = 7; + s_inc = 1; + } + + for (i = 0; i < row_info->width; i++) + { + v = (png_byte)((*sp >> sshift) & 0x01); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + case 2: + { + png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); + png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_uint_32 i; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 3) & 0x03) << 1); + dshift = (int)(((final_width + 3) & 0x03) << 1); + s_start = 6; + s_end = 0; + s_inc = -2; + } + else +#endif + { + sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1); + dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1); + s_start = 0; + s_end = 6; + s_inc = 2; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v; + int j; + + v = (png_byte)((*sp >> sshift) & 0x03); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + case 4: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); + int sshift, dshift; + int s_start, s_end, s_inc; + png_uint_32 i; + int jstop = png_pass_inc[pass]; + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 1) & 0x01) << 2); + dshift = (int)(((final_width + 1) & 0x01) << 2); + s_start = 4; + s_end = 0; + s_inc = -4; + } + else +#endif + { + sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2); + dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2); + s_start = 0; + s_end = 4; + s_inc = 4; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v = (png_byte)((*sp >> sshift) & 0xf); + int j; + + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + default: + { + png_size_t pixel_bytes = (row_info->pixel_depth >> 3); + png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes; + png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; + + int jstop = png_pass_inc[pass]; + png_uint_32 i; + + for (i = 0; i < row_info->width; i++) + { + png_byte v[8]; + int j; + + png_memcpy(v, sp, pixel_bytes); + for (j = 0; j < jstop; j++) + { + png_memcpy(dp, v, pixel_bytes); + dp -= pixel_bytes; + } + sp -= pixel_bytes; + } + break; + } + } + row_info->width = final_width; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width); + } +#if !defined(PNG_READ_PACKSWAP_SUPPORTED) + if (&transformations == NULL) /* silence compiler warning */ + return; +#endif +} +#endif /* !PNG_HAVE_ASSEMBLER_READ_INTERLACE */ +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + +#ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW +void /* PRIVATE */ +png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, + png_bytep prev_row, int filter) +{ + png_debug(1, "in png_read_filter_row\n"); + png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter); + switch (filter) + { + case PNG_FILTER_VALUE_NONE: + break; + case PNG_FILTER_VALUE_SUB: + { + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp = row + bpp; + png_bytep lp = row; + + for (i = bpp; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_UP: + { + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_bytep rp = row; + png_bytep pp = prev_row; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_AVG: + { + png_uint_32 i; + png_bytep rp = row; + png_bytep pp = prev_row; + png_bytep lp = row; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_uint_32 istop = row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + + ((int)(*pp++) / 2 )) & 0xff); + rp++; + } + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + + (int)(*pp++ + *lp++) / 2 ) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_PAETH: + { + png_uint_32 i; + png_bytep rp = row; + png_bytep pp = prev_row; + png_bytep lp = row; + png_bytep cp = prev_row; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_uint_32 istop=row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } + + for (i = 0; i < istop; i++) /* use leftover rp,pp */ + { + int a, b, c, pa, pb, pc, p; + + a = *lp++; + b = *pp++; + c = *cp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + /* + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; + */ + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + *rp = (png_byte)(((int)(*rp) + p) & 0xff); + rp++; + } + break; + } + default: + png_warning(png_ptr, "Ignoring bad adaptive filter type"); + *row=0; + break; + } +} +#endif /* !PNG_HAVE_ASSEMBLER_READ_FILTER_ROW */ + +void /* PRIVATE */ +png_read_finish_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_debug(1, "in png_read_finish_row\n"); + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + do + { + png_ptr->pass++; + if (png_ptr->pass >= 7) + break; + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + if (!(png_ptr->num_rows)) + continue; + } + else /* if (png_ptr->transformations & PNG_INTERLACE) */ + break; + } while (png_ptr->iwidth == 0); + + if (png_ptr->pass < 7) + return; + } + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#endif + char extra; + int ret; + + png_ptr->zstream.next_out = (Byte *)&extra; + png_ptr->zstream.avail_out = (uInt)1; + for(;;) + { + if (!(png_ptr->zstream.avail_in)) + { + while (!png_ptr->idat_size) + { + png_byte chunk_length[4]; + + png_crc_finish(png_ptr, 0); + + png_read_data(png_ptr, chunk_length, 4); + png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) + png_error(png_ptr, "Not enough image data"); + + } + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret == Z_STREAM_END) + { + if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_warning(png_ptr, "Extra compressed data"); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression Error"); + + if (!(png_ptr->zstream.avail_out)) + { + png_warning(png_ptr, "Extra compressed data."); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + + } + png_ptr->zstream.avail_out = 0; + } + + if (png_ptr->idat_size || png_ptr->zstream.avail_in) + png_warning(png_ptr, "Extra compression data"); + + inflateReset(&png_ptr->zstream); + + png_ptr->mode |= PNG_AFTER_IDAT; +} + +void /* PRIVATE */ +png_read_start_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int max_pixel_depth; + png_uint_32 row_bytes; + + png_debug(1, "in png_read_start_row\n"); + png_ptr->zstream.avail_in = 0; + png_init_read_transformations(png_ptr); + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + else + png_ptr->num_rows = png_ptr->height; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1; + + png_ptr->irowbytes = (png_size_t)row_bytes; + if((png_uint_32)png_ptr->irowbytes != row_bytes) + png_error(png_ptr, "Rowbytes overflow in png_read_start_row"); + } + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; + png_ptr->irowbytes = png_ptr->rowbytes + 1; + } + max_pixel_depth = png_ptr->pixel_depth; + +#if defined(PNG_READ_PACK_SUPPORTED) + if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) + max_pixel_depth = 8; +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans) + max_pixel_depth = 32; + else + max_pixel_depth = 24; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth < 8) + max_pixel_depth = 8; + if (png_ptr->num_trans) + max_pixel_depth *= 2; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (png_ptr->num_trans) + { + max_pixel_depth *= 4; + max_pixel_depth /= 3; + } + } + } +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & (PNG_FILLER)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + max_pixel_depth = 32; + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth <= 8) + max_pixel_depth = 16; + else + max_pixel_depth = 32; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (max_pixel_depth <= 32) + max_pixel_depth = 32; + else + max_pixel_depth = 64; + } + } +#endif + +#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + { + if ( +#if defined(PNG_READ_EXPAND_SUPPORTED) + (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || +#endif +#if defined(PNG_READ_FILLER_SUPPORTED) + (png_ptr->transformations & (PNG_FILLER)) || +#endif + png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (max_pixel_depth <= 16) + max_pixel_depth = 32; + else + max_pixel_depth = 64; + } + else + { + if (max_pixel_depth <= 8) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 32; + else + max_pixel_depth = 24; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 64; + else + max_pixel_depth = 48; + } + } +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ +defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + if(png_ptr->transformations & PNG_USER_TRANSFORM) + { + int user_pixel_depth=png_ptr->user_transform_depth* + png_ptr->user_transform_channels; + if(user_pixel_depth > max_pixel_depth) + max_pixel_depth=user_pixel_depth; + } +#endif + + /* align the width on the next larger 8 pixels. Mainly used + for interlacing */ + row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); + /* calculate the maximum bytes needed, adding a byte and a pixel + for safety's sake */ + row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) + + 1 + ((max_pixel_depth + 7) >> 3); +#ifdef PNG_MAX_MALLOC_64K + if (row_bytes > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64); + png_ptr->row_buf = png_ptr->big_row_buf+32; +#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD) + png_ptr->row_buf_size = row_bytes; +#endif + +#ifdef PNG_MAX_MALLOC_64K + if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + if ((png_uint_32)png_ptr->rowbytes > PNG_SIZE_MAX - 1) + png_error(png_ptr, "Row has too many bytes to allocate in memory."); + png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( + png_ptr->rowbytes + 1)); + + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + png_debug1(3, "width = %lu,\n", png_ptr->width); + png_debug1(3, "height = %lu,\n", png_ptr->height); + png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth); + png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes); + + png_ptr->flags |= PNG_FLAG_ROW_INIT; +} +#endif /* PNG_READ_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngset.c ./win32/dependencies/libpng/pngset.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngset.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngset.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,1265 @@ + +/* pngset.c - storage of image information into info struct + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * The functions here are used during reads to store data from the file + * into the info struct, and during writes to store application data + * into the info struct for writing into the file. This abstracts the + * info struct and allows us to change the structure in the future. + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#if defined(PNG_bKGD_SUPPORTED) +void PNGAPI +png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) +{ + png_debug1(1, "in %s storage function\n", "bKGD"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); + info_ptr->valid |= PNG_INFO_bKGD; +} +#endif + +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_cHRM(png_structp png_ptr, png_infop info_ptr, + double white_x, double white_y, double red_x, double red_y, + double green_x, double green_y, double blue_x, double blue_y) +{ + png_debug1(1, "in %s storage function\n", "cHRM"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (white_x < 0.0 || white_y < 0.0 || + red_x < 0.0 || red_y < 0.0 || + green_x < 0.0 || green_y < 0.0 || + blue_x < 0.0 || blue_y < 0.0) + { + png_warning(png_ptr, + "Ignoring attempt to set negative chromaticity value"); + return; + } + if (white_x > 21474.83 || white_y > 21474.83 || + red_x > 21474.83 || red_y > 21474.83 || + green_x > 21474.83 || green_y > 21474.83 || + blue_x > 21474.83 || blue_y > 21474.83) + { + png_warning(png_ptr, + "Ignoring attempt to set chromaticity value exceeding 21474.83"); + return; + } + + info_ptr->x_white = (float)white_x; + info_ptr->y_white = (float)white_y; + info_ptr->x_red = (float)red_x; + info_ptr->y_red = (float)red_y; + info_ptr->x_green = (float)green_x; + info_ptr->y_green = (float)green_y; + info_ptr->x_blue = (float)blue_x; + info_ptr->y_blue = (float)blue_y; +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5); + info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5); + info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5); + info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5); + info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5); + info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5); + info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5); + info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5); +#endif + info_ptr->valid |= PNG_INFO_cHRM; +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + png_debug1(1, "in %s storage function\n", "cHRM"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (white_x < 0 || white_y < 0 || + red_x < 0 || red_y < 0 || + green_x < 0 || green_y < 0 || + blue_x < 0 || blue_y < 0) + { + png_warning(png_ptr, + "Ignoring attempt to set negative chromaticity value"); + return; + } +#ifdef PNG_FLOATING_POINT_SUPPORTED + if (white_x > (double) PNG_UINT_31_MAX || + white_y > (double) PNG_UINT_31_MAX || + red_x > (double) PNG_UINT_31_MAX || + red_y > (double) PNG_UINT_31_MAX || + green_x > (double) PNG_UINT_31_MAX || + green_y > (double) PNG_UINT_31_MAX || + blue_x > (double) PNG_UINT_31_MAX || + blue_y > (double) PNG_UINT_31_MAX) +#else + if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L || + white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L || + red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L || + red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L || + green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L || + green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L || + blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L || + blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L) +#endif + { + png_warning(png_ptr, + "Ignoring attempt to set chromaticity value exceeding 21474.83"); + return; + } + info_ptr->int_x_white = white_x; + info_ptr->int_y_white = white_y; + info_ptr->int_x_red = red_x; + info_ptr->int_y_red = red_y; + info_ptr->int_x_green = green_x; + info_ptr->int_y_green = green_y; + info_ptr->int_x_blue = blue_x; + info_ptr->int_y_blue = blue_y; +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->x_white = (float)(white_x/100000.); + info_ptr->y_white = (float)(white_y/100000.); + info_ptr->x_red = (float)( red_x/100000.); + info_ptr->y_red = (float)( red_y/100000.); + info_ptr->x_green = (float)(green_x/100000.); + info_ptr->y_green = (float)(green_y/100000.); + info_ptr->x_blue = (float)( blue_x/100000.); + info_ptr->y_blue = (float)( blue_y/100000.); +#endif + info_ptr->valid |= PNG_INFO_cHRM; +} +#endif +#endif + +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) +{ + double gamma; + png_debug1(1, "in %s storage function\n", "gAMA"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Check for overflow */ + if (file_gamma > 21474.83) + { + png_warning(png_ptr, "Limiting gamma to 21474.83"); + gamma=21474.83; + } + else + gamma=file_gamma; + info_ptr->gamma = (float)gamma; +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = (int)(gamma*100000.+.5); +#endif + info_ptr->valid |= PNG_INFO_gAMA; + if(gamma == 0.0) + png_warning(png_ptr, "Setting gamma=0"); +} +#endif +void PNGAPI +png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point + int_gamma) +{ + png_fixed_point gamma; + + png_debug1(1, "in %s storage function\n", "gAMA"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Limiting gamma to 21474.83"); + gamma=PNG_UINT_31_MAX; + } + else + { + if (int_gamma < 0) + { + png_warning(png_ptr, "Setting negative gamma to zero"); + gamma=0; + } + else + gamma=int_gamma; + } +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->gamma = (float)(gamma/100000.); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = gamma; +#endif + info_ptr->valid |= PNG_INFO_gAMA; + if(gamma == 0) + png_warning(png_ptr, "Setting gamma=0"); +} +#endif + +#if defined(PNG_hIST_SUPPORTED) +void PNGAPI +png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) +{ + int i; + + png_debug1(1, "in %s storage function\n", "hIST"); + if (png_ptr == NULL || info_ptr == NULL) + return; + if (info_ptr->num_palette <= 0 || info_ptr->num_palette + > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, + "Invalid palette size, hIST allocation skipped."); + return; + } + +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); +#endif + /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version + 1.2.1 */ + png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, + (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16))); + if (png_ptr->hist == NULL) + { + png_warning(png_ptr, "Insufficient memory for hIST chunk data."); + return; + } + + for (i = 0; i < info_ptr->num_palette; i++) + png_ptr->hist[i] = hist[i]; + info_ptr->hist = png_ptr->hist; + info_ptr->valid |= PNG_INFO_hIST; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_HIST; +#else + png_ptr->flags |= PNG_FLAG_FREE_HIST; +#endif +} +#endif + +void PNGAPI +png_set_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + png_debug1(1, "in %s storage function\n", "IHDR"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* check for width and height valid values */ + if (width == 0 || height == 0) + png_error(png_ptr, "Image width or height is zero in IHDR"); +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (width > png_ptr->user_width_max || height > png_ptr->user_height_max) + png_error(png_ptr, "image size exceeds user limits in IHDR"); +#else + if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX) + png_error(png_ptr, "image size exceeds user limits in IHDR"); +#endif + if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX) + png_error(png_ptr, "Invalid image size in IHDR"); + if ( width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 64 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + png_warning(png_ptr, "Width is too large for libpng to process pixels"); + + /* check other values */ + if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && + bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth in IHDR"); + + if (color_type < 0 || color_type == 1 || + color_type == 5 || color_type > 6) + png_error(png_ptr, "Invalid color type in IHDR"); + + if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || + ((color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) + png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); + + if (interlace_type >= PNG_INTERLACE_LAST) + png_error(png_ptr, "Unknown interlace method in IHDR"); + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_error(png_ptr, "Unknown compression method in IHDR"); + +#if defined(PNG_MNG_FEATURES_SUPPORTED) + /* Accept filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not read a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) + png_warning(png_ptr,"MNG features are not allowed in a PNG datastream"); + if(filter_type != PNG_FILTER_TYPE_BASE) + { + if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && + ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + png_error(png_ptr, "Unknown filter method in IHDR"); + if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) + png_warning(png_ptr, "Invalid filter method in IHDR"); + } +#else + if(filter_type != PNG_FILTER_TYPE_BASE) + png_error(png_ptr, "Unknown filter method in IHDR"); +#endif + + info_ptr->width = width; + info_ptr->height = height; + info_ptr->bit_depth = (png_byte)bit_depth; + info_ptr->color_type =(png_byte) color_type; + info_ptr->compression_type = (png_byte)compression_type; + info_ptr->filter_type = (png_byte)filter_type; + info_ptr->interlace_type = (png_byte)interlace_type; + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + else + info_ptr->channels = 1; + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); + + /* check for potential overflow */ + if ( width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 64 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + info_ptr->rowbytes = (png_size_t)0; + else + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width); +} + +#if defined(PNG_oFFs_SUPPORTED) +void PNGAPI +png_set_oFFs(png_structp png_ptr, png_infop info_ptr, + png_int_32 offset_x, png_int_32 offset_y, int unit_type) +{ + png_debug1(1, "in %s storage function\n", "oFFs"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_offset = offset_x; + info_ptr->y_offset = offset_y; + info_ptr->offset_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_oFFs; +} +#endif + +#if defined(PNG_pCAL_SUPPORTED) +void PNGAPI +png_set_pCAL(png_structp png_ptr, png_infop info_ptr, + png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, + png_charp units, png_charpp params) +{ + png_uint_32 length; + int i; + + png_debug1(1, "in %s storage function\n", "pCAL"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + length = png_strlen(purpose) + 1; + png_debug1(3, "allocating purpose for info (%lu bytes)\n", length); + info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_purpose == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL purpose."); + return; + } + png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); + + png_debug(3, "storing X0, X1, type, and nparams in info\n"); + info_ptr->pcal_X0 = X0; + info_ptr->pcal_X1 = X1; + info_ptr->pcal_type = (png_byte)type; + info_ptr->pcal_nparams = (png_byte)nparams; + + length = png_strlen(units) + 1; + png_debug1(3, "allocating units for info (%lu bytes)\n", length); + info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_units == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL units."); + return; + } + png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); + + info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, + (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); + if (info_ptr->pcal_params == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL params."); + return; + } + + info_ptr->pcal_params[nparams] = NULL; + + for (i = 0; i < nparams; i++) + { + length = png_strlen(params[i]) + 1; + png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length); + info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_params[i] == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL parameter."); + return; + } + png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); + } + + info_ptr->valid |= PNG_INFO_pCAL; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_PCAL; +#endif +} +#endif + +#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_sCAL(png_structp png_ptr, png_infop info_ptr, + int unit, double width, double height) +{ + png_debug1(1, "in %s storage function\n", "sCAL"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->scal_unit = (png_byte)unit; + info_ptr->scal_pixel_width = width; + info_ptr->scal_pixel_height = height; + + info_ptr->valid |= PNG_INFO_sCAL; +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, + int unit, png_charp swidth, png_charp sheight) +{ + png_uint_32 length; + + png_debug1(1, "in %s storage function\n", "sCAL"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->scal_unit = (png_byte)unit; + + length = png_strlen(swidth) + 1; + png_debug1(3, "allocating unit for info (%d bytes)\n", length); + info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->scal_s_width == NULL) + { + png_warning(png_ptr, "Memory allocation failed while processing sCAL."); + } + png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); + + length = png_strlen(sheight) + 1; + png_debug1(3, "allocating unit for info (%d bytes)\n", length); + info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->scal_s_height == NULL) + { + png_free (png_ptr, info_ptr->scal_s_width); + png_warning(png_ptr, "Memory allocation failed while processing sCAL."); + } + png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); + + info_ptr->valid |= PNG_INFO_sCAL; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_SCAL; +#endif +} +#endif +#endif +#endif + +#if defined(PNG_pHYs_SUPPORTED) +void PNGAPI +png_set_pHYs(png_structp png_ptr, png_infop info_ptr, + png_uint_32 res_x, png_uint_32 res_y, int unit_type) +{ + png_debug1(1, "in %s storage function\n", "pHYs"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_pixels_per_unit = res_x; + info_ptr->y_pixels_per_unit = res_y; + info_ptr->phys_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_pHYs; +} +#endif + +void PNGAPI +png_set_PLTE(png_structp png_ptr, png_infop info_ptr, + png_colorp palette, int num_palette) +{ + + png_debug1(1, "in %s storage function\n", "PLTE"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); + else + { + png_warning(png_ptr, "Invalid palette length"); + return; + } + } + + /* + * It may not actually be necessary to set png_ptr->palette here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); +#endif + + /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead + of num_palette entries, + in case of an invalid PNG file that has too-large sample values. */ + png_ptr->palette = (png_colorp)png_malloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); + png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * + png_sizeof(png_color)); + png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color)); + info_ptr->palette = png_ptr->palette; + info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_PLTE; +#else + png_ptr->flags |= PNG_FLAG_FREE_PLTE; +#endif + + info_ptr->valid |= PNG_INFO_PLTE; +} + +#if defined(PNG_sBIT_SUPPORTED) +void PNGAPI +png_set_sBIT(png_structp png_ptr, png_infop info_ptr, + png_color_8p sig_bit) +{ + png_debug1(1, "in %s storage function\n", "sBIT"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8)); + info_ptr->valid |= PNG_INFO_sBIT; +} +#endif + +#if defined(PNG_sRGB_SUPPORTED) +void PNGAPI +png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) +{ + png_debug1(1, "in %s storage function\n", "sRGB"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->srgb_intent = (png_byte)intent; + info_ptr->valid |= PNG_INFO_sRGB; +} + +void PNGAPI +png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, + int intent) +{ +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED + float file_gamma; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_fixed_point int_file_gamma; +#endif +#endif +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED + float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, + int_green_y, int_blue_x, int_blue_y; +#endif +#endif + png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_set_sRGB(png_ptr, info_ptr, intent); + +#if defined(PNG_gAMA_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED + file_gamma = (float).45455; + png_set_gAMA(png_ptr, info_ptr, file_gamma); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + int_file_gamma = 45455L; + png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); +#endif +#endif + +#if defined(PNG_cHRM_SUPPORTED) +#ifdef PNG_FIXED_POINT_SUPPORTED + int_white_x = 31270L; + int_white_y = 32900L; + int_red_x = 64000L; + int_red_y = 33000L; + int_green_x = 30000L; + int_green_y = 60000L; + int_blue_x = 15000L; + int_blue_y = 6000L; + + png_set_cHRM_fixed(png_ptr, info_ptr, + int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y, + int_blue_x, int_blue_y); +#endif +#ifdef PNG_FLOATING_POINT_SUPPORTED + white_x = (float).3127; + white_y = (float).3290; + red_x = (float).64; + red_y = (float).33; + green_x = (float).30; + green_y = (float).60; + blue_x = (float).15; + blue_y = (float).06; + + png_set_cHRM(png_ptr, info_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); +#endif +#endif +} +#endif + + +#if defined(PNG_iCCP_SUPPORTED) +void PNGAPI +png_set_iCCP(png_structp png_ptr, png_infop info_ptr, + png_charp name, int compression_type, + png_charp profile, png_uint_32 proflen) +{ + png_charp new_iccp_name; + png_charp new_iccp_profile; + + png_debug1(1, "in %s storage function\n", "iCCP"); + if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) + return; + + new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1); + if (new_iccp_name == NULL) + { + png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); + return; + } + png_strcpy(new_iccp_name, name); + new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen); + if (new_iccp_profile == NULL) + { + png_free (png_ptr, new_iccp_name); + png_warning(png_ptr, "Insufficient memory to process iCCP profile."); + return; + } + png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); + + info_ptr->iccp_proflen = proflen; + info_ptr->iccp_name = new_iccp_name; + info_ptr->iccp_profile = new_iccp_profile; + /* Compression is always zero but is here so the API and info structure + * does not have to change if we introduce multiple compression types */ + info_ptr->iccp_compression = (png_byte)compression_type; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_ICCP; +#endif + info_ptr->valid |= PNG_INFO_iCCP; +} +#endif + +#if defined(PNG_TEXT_SUPPORTED) +void PNGAPI +png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, + int num_text) +{ + int ret; + ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); + if (ret) + png_error(png_ptr, "Insufficient memory to store text"); +} + +int /* PRIVATE */ +png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, + int num_text) +{ + int i; + + png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ? + "text" : (png_const_charp)png_ptr->chunk_name)); + + if (png_ptr == NULL || info_ptr == NULL || num_text == 0) + return(0); + + /* Make sure we have enough space in the "text" array in info_struct + * to hold all of the incoming text_ptr objects. + */ + if (info_ptr->num_text + num_text > info_ptr->max_text) + { + if (info_ptr->text != NULL) + { + png_textp old_text; + int old_max; + + old_max = info_ptr->max_text; + info_ptr->max_text = info_ptr->num_text + num_text + 8; + old_text = info_ptr->text; + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)(info_ptr->max_text * png_sizeof (png_text))); + if (info_ptr->text == NULL) + { + png_free(png_ptr, old_text); + return(1); + } + png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * + png_sizeof(png_text))); + png_free(png_ptr, old_text); + } + else + { + info_ptr->max_text = num_text + 8; + info_ptr->num_text = 0; + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)(info_ptr->max_text * png_sizeof (png_text))); + if (info_ptr->text == NULL) + return(1); +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_TEXT; +#endif + } + png_debug1(3, "allocated %d entries for info_ptr->text\n", + info_ptr->max_text); + } + for (i = 0; i < num_text; i++) + { + png_size_t text_length,key_len; + png_size_t lang_len,lang_key_len; + png_textp textp = &(info_ptr->text[info_ptr->num_text]); + + if (text_ptr[i].key == NULL) + continue; + + key_len = png_strlen(text_ptr[i].key); + + if(text_ptr[i].compression <= 0) + { + lang_len = 0; + lang_key_len = 0; + } + else +#ifdef PNG_iTXt_SUPPORTED + { + /* set iTXt data */ + if (text_ptr[i].lang != NULL) + lang_len = png_strlen(text_ptr[i].lang); + else + lang_len = 0; + if (text_ptr[i].lang_key != NULL) + lang_key_len = png_strlen(text_ptr[i].lang_key); + else + lang_key_len = 0; + } +#else + { + png_warning(png_ptr, "iTXt chunk not supported."); + continue; + } +#endif + + if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') + { + text_length = 0; +#ifdef PNG_iTXt_SUPPORTED + if(text_ptr[i].compression > 0) + textp->compression = PNG_ITXT_COMPRESSION_NONE; + else +#endif + textp->compression = PNG_TEXT_COMPRESSION_NONE; + } + else + { + text_length = png_strlen(text_ptr[i].text); + textp->compression = text_ptr[i].compression; + } + + textp->key = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4)); + if (textp->key == NULL) + return(1); + png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n", + (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4), + (int)textp->key); + + png_memcpy(textp->key, text_ptr[i].key, + (png_size_t)(key_len)); + *(textp->key+key_len) = '\0'; +#ifdef PNG_iTXt_SUPPORTED + if (text_ptr[i].compression > 0) + { + textp->lang=textp->key + key_len + 1; + png_memcpy(textp->lang, text_ptr[i].lang, lang_len); + *(textp->lang+lang_len) = '\0'; + textp->lang_key=textp->lang + lang_len + 1; + png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); + *(textp->lang_key+lang_key_len) = '\0'; + textp->text=textp->lang_key + lang_key_len + 1; + } + else +#endif + { +#ifdef PNG_iTXt_SUPPORTED + textp->lang=NULL; + textp->lang_key=NULL; +#endif + textp->text=textp->key + key_len + 1; + } + if(text_length) + png_memcpy(textp->text, text_ptr[i].text, + (png_size_t)(text_length)); + *(textp->text+text_length) = '\0'; + +#ifdef PNG_iTXt_SUPPORTED + if(textp->compression > 0) + { + textp->text_length = 0; + textp->itxt_length = text_length; + } + else +#endif + { + textp->text_length = text_length; +#ifdef PNG_iTXt_SUPPORTED + textp->itxt_length = 0; +#endif + } + info_ptr->text[info_ptr->num_text]= *textp; + info_ptr->num_text++; + png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text); + } + return(0); +} +#endif + +#if defined(PNG_tIME_SUPPORTED) +void PNGAPI +png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) +{ + png_debug1(1, "in %s storage function\n", "tIME"); + if (png_ptr == NULL || info_ptr == NULL || + (png_ptr->mode & PNG_WROTE_tIME)) + return; + + png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time)); + info_ptr->valid |= PNG_INFO_tIME; +} +#endif + +#if defined(PNG_tRNS_SUPPORTED) +void PNGAPI +png_set_tRNS(png_structp png_ptr, png_infop info_ptr, + png_bytep trans, int num_trans, png_color_16p trans_values) +{ + png_debug1(1, "in %s storage function\n", "tRNS"); + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (trans != NULL) + { + /* + * It may not actually be necessary to set png_ptr->trans here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); +#endif + /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ + png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, + (png_uint_32)PNG_MAX_PALETTE_LENGTH); + if (num_trans <= PNG_MAX_PALETTE_LENGTH) + png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_TRNS; +#else + png_ptr->flags |= PNG_FLAG_FREE_TRNS; +#endif + } + + if (trans_values != NULL) + { + png_memcpy(&(info_ptr->trans_values), trans_values, + png_sizeof(png_color_16)); + if (num_trans == 0) + num_trans = 1; + } + info_ptr->num_trans = (png_uint_16)num_trans; + info_ptr->valid |= PNG_INFO_tRNS; +} +#endif + +#if defined(PNG_sPLT_SUPPORTED) +void PNGAPI +png_set_sPLT(png_structp png_ptr, + png_infop info_ptr, png_sPLT_tp entries, int nentries) +{ + png_sPLT_tp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL) + return; + + np = (png_sPLT_tp)png_malloc_warn(png_ptr, + (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t)); + if (np == NULL) + { + png_warning(png_ptr, "No memory for sPLT palettes."); + return; + } + + png_memcpy(np, info_ptr->splt_palettes, + info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes=NULL; + + for (i = 0; i < nentries; i++) + { + png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; + png_sPLT_tp from = entries + i; + + to->name = (png_charp)png_malloc(png_ptr, + png_strlen(from->name) + 1); + /* TODO: use png_malloc_warn */ + png_strcpy(to->name, from->name); + to->entries = (png_sPLT_entryp)png_malloc(png_ptr, + from->nentries * png_sizeof(png_sPLT_t)); + /* TODO: use png_malloc_warn */ + png_memcpy(to->entries, from->entries, + from->nentries * png_sizeof(png_sPLT_t)); + to->nentries = from->nentries; + to->depth = from->depth; + } + + info_ptr->splt_palettes = np; + info_ptr->splt_palettes_num += nentries; + info_ptr->valid |= PNG_INFO_sPLT; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_SPLT; +#endif +} +#endif /* PNG_sPLT_SUPPORTED */ + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +void PNGAPI +png_set_unknown_chunks(png_structp png_ptr, + png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) +{ + png_unknown_chunkp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) + return; + + np = (png_unknown_chunkp)png_malloc_warn(png_ptr, + (info_ptr->unknown_chunks_num + num_unknowns) * + png_sizeof(png_unknown_chunk)); + if (np == NULL) + { + png_warning(png_ptr, "Out of memory while processing unknown chunk."); + return; + } + + png_memcpy(np, info_ptr->unknown_chunks, + info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks=NULL; + + for (i = 0; i < num_unknowns; i++) + { + png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; + png_unknown_chunkp from = unknowns + i; + + png_strncpy((png_charp)to->name, (png_charp)from->name, 5); + to->data = (png_bytep)png_malloc_warn(png_ptr, from->size); + if (to->data == NULL) + { + png_warning(png_ptr, "Out of memory processing unknown chunk."); + } + else + { + png_memcpy(to->data, from->data, from->size); + to->size = from->size; + + /* note our location in the read or write sequence */ + to->location = (png_byte)(png_ptr->mode & 0xff); + } + } + + info_ptr->unknown_chunks = np; + info_ptr->unknown_chunks_num += num_unknowns; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_UNKN; +#endif +} +void PNGAPI +png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, + int chunk, int location) +{ + if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < + (int)info_ptr->unknown_chunks_num) + info_ptr->unknown_chunks[chunk].location = (png_byte)location; +} +#endif + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +void PNGAPI +png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) +{ + /* This function is deprecated in favor of png_permit_mng_features() + and will be removed from libpng-1.3.0 */ + png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n"); + if (png_ptr == NULL) + return; + png_ptr->mng_features_permitted = (png_byte) + ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) | + ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); +} +#endif +#endif + +#if defined(PNG_MNG_FEATURES_SUPPORTED) +png_uint_32 PNGAPI +png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) +{ + png_debug(1, "in png_permit_mng_features\n"); + if (png_ptr == NULL) + return (png_uint_32)0; + png_ptr->mng_features_permitted = + (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); + return (png_uint_32)png_ptr->mng_features_permitted; +} +#endif + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +void PNGAPI +png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep + chunk_list, int num_chunks) +{ + png_bytep new_list, p; + int i, old_num_chunks; + if (png_ptr == NULL) + return; + if (num_chunks == 0) + { + if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) + png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + + if(keep == PNG_HANDLE_CHUNK_ALWAYS) + png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; + return; + } + if (chunk_list == NULL) + return; + old_num_chunks=png_ptr->num_chunk_list; + new_list=(png_bytep)png_malloc(png_ptr, + (png_uint_32)(5*(num_chunks+old_num_chunks))); + if(png_ptr->chunk_list != NULL) + { + png_memcpy(new_list, png_ptr->chunk_list, + (png_size_t)(5*old_num_chunks)); + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; + } + png_memcpy(new_list+5*old_num_chunks, chunk_list, + (png_size_t)(5*num_chunks)); + for (p=new_list+5*old_num_chunks+4, i=0; inum_chunk_list=old_num_chunks+num_chunks; + png_ptr->chunk_list=new_list; +#ifdef PNG_FREE_ME_SUPPORTED + png_ptr->free_me |= PNG_FREE_LIST; +#endif +} +#endif + +#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) +void PNGAPI +png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, + png_user_chunk_ptr read_user_chunk_fn) +{ + png_debug(1, "in png_set_read_user_chunk_fn\n"); + if (png_ptr == NULL) + return; + png_ptr->read_user_chunk_fn = read_user_chunk_fn; + png_ptr->user_chunk_ptr = user_chunk_ptr; +} +#endif + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +void PNGAPI +png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) +{ + png_debug1(1, "in %s storage function\n", "rows"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + info_ptr->row_pointers = row_pointers; + if(row_pointers) + info_ptr->valid |= PNG_INFO_IDAT; +} +#endif + +#ifdef PNG_WRITE_SUPPORTED +void PNGAPI +png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size) +{ + if (png_ptr == NULL) + return; + if(png_ptr->zbuf) + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf_size = (png_size_t)size; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; +} +#endif + +void PNGAPI +png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) +{ + if (png_ptr && info_ptr) + info_ptr->valid &= ~(mask); +} + + +#ifndef PNG_1_0_X +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +/* this function was added to libpng 1.2.0 and should always exist by default */ +void PNGAPI +png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) +{ + png_uint_32 settable_asm_flags; + png_uint_32 settable_mmx_flags; + + if (png_ptr == NULL) + return; + + settable_mmx_flags = +#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | +#endif +#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE + PNG_ASM_FLAG_MMX_READ_INTERLACE | +#endif +#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW + PNG_ASM_FLAG_MMX_READ_FILTER_SUB | + PNG_ASM_FLAG_MMX_READ_FILTER_UP | + PNG_ASM_FLAG_MMX_READ_FILTER_AVG | + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH | +#endif + 0; + + /* could be some non-MMX ones in the future, but not currently: */ + settable_asm_flags = settable_mmx_flags; + + if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) || + !(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU)) + { + /* clear all MMX flags if MMX isn't supported */ + settable_asm_flags &= ~settable_mmx_flags; + png_ptr->asm_flags &= ~settable_mmx_flags; + } + + /* we're replacing the settable bits with those passed in by the user, + * so first zero them out of the master copy, then logical-OR in the + * allowed subset that was requested */ + + png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */ + png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */ +} +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ + +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +/* this function was added to libpng 1.2.0 */ +void PNGAPI +png_set_mmx_thresholds (png_structp png_ptr, + png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold) +{ + if (png_ptr == NULL) + return; + png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold; + png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold; +} +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* this function was added to libpng 1.2.6 */ +void PNGAPI +png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, + png_uint_32 user_height_max) +{ + /* Images with dimensions larger than these limits will be + * rejected by png_set_IHDR(). To accept any PNG datastream + * regardless of dimensions, set both limits to 0x7ffffffL. + */ + png_ptr->user_width_max = user_width_max; + png_ptr->user_height_max = user_height_max; +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + +#endif /* ?PNG_1_0_X */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngtrans.c ./win32/dependencies/libpng/pngtrans.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngtrans.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngtrans.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,652 @@ + +/* pngtrans.c - transforms the data in a row (used by both readers and writers) + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#include "png.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* turn on BGR-to-RGB mapping */ +void PNGAPI +png_set_bgr(png_structp png_ptr) +{ + png_debug(1, "in png_set_bgr\n"); + png_ptr->transformations |= PNG_BGR; +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* turn on 16 bit byte swapping */ +void PNGAPI +png_set_swap(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap\n"); + if (png_ptr->bit_depth == 16) + png_ptr->transformations |= PNG_SWAP_BYTES; +} +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* turn on pixel packing */ +void PNGAPI +png_set_packing(png_structp png_ptr) +{ + png_debug(1, "in png_set_packing\n"); + if (png_ptr->bit_depth < 8) + { + png_ptr->transformations |= PNG_PACK; + png_ptr->usr_bit_depth = 8; + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* turn on packed pixel swapping */ +void PNGAPI +png_set_packswap(png_structp png_ptr) +{ + png_debug(1, "in png_set_packswap\n"); + if (png_ptr->bit_depth < 8) + png_ptr->transformations |= PNG_PACKSWAP; +} +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +void PNGAPI +png_set_shift(png_structp png_ptr, png_color_8p true_bits) +{ + png_debug(1, "in png_set_shift\n"); + png_ptr->transformations |= PNG_SHIFT; + png_ptr->shift = *true_bits; +} +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +int PNGAPI +png_set_interlace_handling(png_structp png_ptr) +{ + png_debug(1, "in png_set_interlace handling\n"); + if (png_ptr->interlaced) + { + png_ptr->transformations |= PNG_INTERLACE; + return (7); + } + + return (1); +} +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte on read, or remove a filler or alpha byte on write. + * The filler type has changed in v0.95 to allow future 2-byte fillers + * for 48-bit input data, as well as to avoid problems with some compilers + * that don't like bytes as parameters. + */ +void PNGAPI +png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_filler\n"); + png_ptr->transformations |= PNG_FILLER; + png_ptr->filler = (png_byte)filler; + if (filler_loc == PNG_FILLER_AFTER) + png_ptr->flags |= PNG_FLAG_FILLER_AFTER; + else + png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; + + /* This should probably go in the "do_read_filler" routine. + * I attempted to do that in libpng-1.0.1a but that caused problems + * so I restored it in libpng-1.0.2a + */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_ptr->usr_channels = 4; + } + + /* Also I added this in libpng-1.0.2a (what happens when we expand + * a less-than-8-bit grayscale to GA? */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) + { + png_ptr->usr_channels = 2; + } +} + +#if !defined(PNG_1_0_X) +/* Added to libpng-1.2.7 */ +void PNGAPI +png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_add_alpha\n"); + png_set_filler(png_ptr, filler, filler_loc); + png_ptr->transformations |= PNG_ADD_ALPHA; +} +#endif + +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +void PNGAPI +png_set_swap_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap_alpha\n"); + png_ptr->transformations |= PNG_SWAP_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +void PNGAPI +png_set_invert_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_alpha\n"); + png_ptr->transformations |= PNG_INVERT_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +void PNGAPI +png_set_invert_mono(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_mono\n"); + png_ptr->transformations |= PNG_INVERT_MONO; +} + +/* invert monochrome grayscale data */ +void /* PRIVATE */ +png_do_invert(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_invert\n"); + /* This test removed from libpng version 1.0.13 and 1.2.0: + * if (row_info->bit_depth == 1 && + */ +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row == NULL || row_info == NULL) + return; +#endif + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(~(*rp)); + rp++; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 8) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i+=2) + { + *rp = (png_byte)(~(*rp)); + rp+=2; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i+=4) + { + *rp = (png_byte)(~(*rp)); + *(rp+1) = (png_byte)(~(*(rp+1))); + rp+=4; + } + } +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* swaps byte order on 16 bit depth images */ +void /* PRIVATE */ +png_do_swap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_swap\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop= row_info->width * row_info->channels; + + for (i = 0; i < istop; i++, rp += 2) + { + png_byte t = *rp; + *rp = *(rp + 1); + *(rp + 1) = t; + } + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +static PNG_CONST png_byte onebppswaptable[256] = { + 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, + 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, + 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, + 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, + 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, + 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, + 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, + 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, + 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, + 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, + 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, + 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, + 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, + 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, + 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, + 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, + 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, + 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, + 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, + 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, + 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, + 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, + 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, + 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, + 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, + 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, + 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, + 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +static PNG_CONST png_byte twobppswaptable[256] = { + 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, + 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, + 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, + 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4, + 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8, + 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, + 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC, + 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC, + 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1, + 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1, + 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5, + 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5, + 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9, + 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9, + 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD, + 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD, + 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2, + 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2, + 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6, + 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6, + 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA, + 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA, + 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE, + 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE, + 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3, + 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3, + 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7, + 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7, + 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB, + 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, + 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF, + 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF +}; + +static PNG_CONST png_byte fourbppswaptable[256] = { + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, + 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, + 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, + 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1, + 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, + 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2, + 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, + 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3, + 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, + 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, + 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, + 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5, + 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76, + 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6, + 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, + 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, + 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, + 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, + 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79, + 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, + 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, + 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA, + 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, + 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB, + 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, + 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC, + 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D, + 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, + 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E, + 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE, + 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, + 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF +}; + +/* swaps pixel packing order within bytes */ +void /* PRIVATE */ +png_do_packswap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_packswap\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + row_info->bit_depth < 8) + { + png_bytep rp, end, table; + + end = row + row_info->rowbytes; + + if (row_info->bit_depth == 1) + table = (png_bytep)onebppswaptable; + else if (row_info->bit_depth == 2) + table = (png_bytep)twobppswaptable; + else if (row_info->bit_depth == 4) + table = (png_bytep)fourbppswaptable; + else + return; + + for (rp = row; rp < end; rp++) + *rp = table[*rp]; + } +} +#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +/* remove filler or alpha byte(s) */ +void /* PRIVATE */ +png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) +{ + png_debug(1, "in png_do_strip_filler\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + png_bytep sp=row; + png_bytep dp=row; + png_uint_32 row_width=row_info->width; + png_uint_32 i; + + if ((row_info->color_type == PNG_COLOR_TYPE_RGB || + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + (flags & PNG_FLAG_STRIP_ALPHA))) && + row_info->channels == 4) + { + if (row_info->bit_depth == 8) + { + /* This converts from RGBX or RGBA to RGB */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + dp+=3; sp+=4; + for (i = 1; i < row_width; i++) + { + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + sp++; + } + } + /* This converts from XRGB or ARGB to RGB */ + else + { + for (i = 0; i < row_width; i++) + { + sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + } + else /* if (row_info->bit_depth == 16) */ + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */ + sp += 8; dp += 6; + for (i = 1; i < row_width; i++) + { + /* This could be (although png_memcpy is probably slower): + png_memcpy(dp, sp, 6); + sp += 8; + dp += 6; + */ + + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + sp += 2; + } + } + else + { + /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ + for (i = 0; i < row_width; i++) + { + /* This could be (although png_memcpy is probably slower): + png_memcpy(dp, sp, 6); + sp += 8; + dp += 6; + */ + + sp+=2; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 48; + row_info->rowbytes = row_width * 6; + } + row_info->channels = 3; + } + else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY || + (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + (flags & PNG_FLAG_STRIP_ALPHA))) && + row_info->channels == 2) + { + if (row_info->bit_depth == 8) + { + /* This converts from GX or GA to G */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + for (i = 0; i < row_width; i++) + { + *dp++ = *sp++; + sp++; + } + } + /* This converts from XG or AG to G */ + else + { + for (i = 0; i < row_width; i++) + { + sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + else /* if (row_info->bit_depth == 16) */ + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This converts from GGXX or GGAA to GG */ + sp += 4; dp += 2; + for (i = 1; i < row_width; i++) + { + *dp++ = *sp++; + *dp++ = *sp++; + sp += 2; + } + } + else + { + /* This converts from XXGG or AAGG to GG */ + for (i = 0; i < row_width; i++) + { + sp += 2; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + row_info->channels = 1; + } + if (flags & PNG_FLAG_STRIP_ALPHA) + row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; + } +} +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* swaps red and blue bytes within a pixel */ +void /* PRIVATE */ +png_do_bgr(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_bgr\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 3) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 4) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + } + else if (row_info->bit_depth == 16) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 6) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 8) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + } + } +} +#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +void PNGAPI +png_set_user_transform_info(png_structp png_ptr, png_voidp + user_transform_ptr, int user_transform_depth, int user_transform_channels) +{ + png_debug(1, "in png_set_user_transform_info\n"); +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + png_ptr->user_transform_ptr = user_transform_ptr; + png_ptr->user_transform_depth = (png_byte)user_transform_depth; + png_ptr->user_transform_channels = (png_byte)user_transform_channels; +#else + if(user_transform_ptr || user_transform_depth || user_transform_channels) + png_warning(png_ptr, + "This version of libpng does not support user transform info"); +#endif +} +#endif + +/* This function returns a pointer to the user_transform_ptr associated with + * the user transform functions. The application should free any memory + * associated with this pointer before png_write_destroy and png_read_destroy + * are called. + */ +png_voidp PNGAPI +png_get_user_transform_ptr(png_structp png_ptr) +{ +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + return ((png_voidp)png_ptr->user_transform_ptr); +#else + if(png_ptr) + return (NULL); + return (NULL); +#endif +} +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwio.c ./win32/dependencies/libpng/pngwio.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwio.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngwio.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,228 @@ + +/* pngwio.c - functions for data output + * + * Last changed in libpng 1.2.3 - May 21, 2002 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2002 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This file provides a location for all output. Users who need + * special handling are expected to write functions that have the same + * arguments as these and perform similar functions, but that possibly + * use different output methods. Note that you shouldn't change these + * functions, but rather write replacement functions and then change + * them at run time with png_set_write_fn(...). + */ + +#define PNG_INTERNAL +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Write the data to whatever output you are using. The default routine + writes to a file pointer. Note that this routine sometimes gets called + with very small lengths, so you should implement some kind of simple + buffering if you are using unbuffered writes. This should never be asked + to write more than 64K on a 16 bit machine. */ + +void /* PRIVATE */ +png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + if (png_ptr->write_data_fn != NULL ) + (*(png_ptr->write_data_fn))(png_ptr, data, length); + else + png_error(png_ptr, "Call to NULL write function"); +} + +#if !defined(PNG_NO_STDIO) +/* This is the function that does the actual writing of data. If you are + not writing to a standard C stream, you should create a replacement + write_data function and use it at run time with png_set_write_fn(), rather + than changing the library. */ +#ifndef USE_FAR_KEYWORD +void PNGAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + +#if defined(_WIN32_WCE) + if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); +#endif + if (check != length) + png_error(png_ptr, "Write Error"); +} +#else +/* this is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +void PNGAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + near_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)near_data == data) + { +#if defined(_WIN32_WCE) + if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) + check = 0; +#else + check = fwrite(near_data, 1, length, io_ptr); +#endif + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t written, remaining, err; + check = 0; + remaining = length; + do + { + written = MIN(NEAR_BUF_SIZE, remaining); + png_memcpy(buf, data, written); /* copy far buffer to near buffer */ +#if defined(_WIN32_WCE) + if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) + err = 0; +#else + err = fwrite(buf, 1, written, io_ptr); +#endif + if (err != written) + break; + else + check += err; + data += written; + remaining -= written; + } + while (remaining != 0); + } + if (check != length) + png_error(png_ptr, "Write Error"); +} + +#endif +#endif + +/* This function is called to output any data pending writing (normally + to disk). After png_flush is called, there should be no data pending + writing in any buffers. */ +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +void /* PRIVATE */ +png_flush(png_structp png_ptr) +{ + if (png_ptr->output_flush_fn != NULL) + (*(png_ptr->output_flush_fn))(png_ptr); +} + +#if !defined(PNG_NO_STDIO) +void PNGAPI +png_default_flush(png_structp png_ptr) +{ +#if !defined(_WIN32_WCE) + png_FILE_p io_ptr; + io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); + if (io_ptr != NULL) + fflush(io_ptr); +#endif +} +#endif +#endif + +/* This function allows the application to supply new output functions for + libpng if standard C streams aren't being used. + + This function takes as its arguments: + png_ptr - pointer to a png output data structure + io_ptr - pointer to user supplied structure containing info about + the output functions. May be NULL. + write_data_fn - pointer to a new output function that takes as its + arguments a pointer to a png_struct, a pointer to + data to be written, and a 32-bit unsigned int that is + the number of bytes to be written. The new write + function should call png_error(png_ptr, "Error msg") + to exit and output any fatal error messages. + flush_data_fn - pointer to a new flush function that takes as its + arguments a pointer to a png_struct. After a call to + the flush function, there should be no data in any buffers + or pending transmission. If the output method doesn't do + any buffering of ouput, a function prototype must still be + supplied although it doesn't have to do anything. If + PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile + time, output_flush_fn will be ignored, although it must be + supplied for compatibility. */ +void PNGAPI +png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) +{ + png_ptr->io_ptr = io_ptr; + +#if !defined(PNG_NO_STDIO) + if (write_data_fn != NULL) + png_ptr->write_data_fn = write_data_fn; + else + png_ptr->write_data_fn = png_default_write_data; +#else + png_ptr->write_data_fn = write_data_fn; +#endif + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +#if !defined(PNG_NO_STDIO) + if (output_flush_fn != NULL) + png_ptr->output_flush_fn = output_flush_fn; + else + png_ptr->output_flush_fn = png_default_flush; +#else + png_ptr->output_flush_fn = output_flush_fn; +#endif +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + + /* It is an error to read while writing a png file */ + if (png_ptr->read_data_fn != NULL) + { + png_ptr->read_data_fn = NULL; + png_warning(png_ptr, + "Attempted to set both read_data_fn and write_data_fn in"); + png_warning(png_ptr, + "the same structure. Resetting read_data_fn to NULL."); + } +} + +#if defined(USE_FAR_KEYWORD) +#if defined(_MSC_VER) +void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + FP_OFF(near_ptr) = FP_OFF(ptr); + far_ptr = (void FAR *)near_ptr; + if(check != 0) + if(FP_SEG(ptr) != FP_SEG(far_ptr)) + png_error(png_ptr,"segment lost in conversion"); + return(near_ptr); +} +# else +void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + near_ptr = (void FAR *)ptr; + far_ptr = (void FAR *)near_ptr; + if(check != 0) + if(far_ptr != ptr) + png_error(png_ptr,"segment lost in conversion"); + return(near_ptr); +} +# endif +# endif +#endif /* PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwrite.c ./win32/dependencies/libpng/pngwrite.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwrite.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngwrite.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,1513 @@ + +/* pngwrite.c - general routines to write a PNG file + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +/* get internal access to png.h */ +#define PNG_INTERNAL +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Writes all the PNG information. This is the suggested way to use the + * library. If you have a new chunk to add, make a function to write it, + * and put it in the correct location here. If you want the chunk written + * after the image data, put it in png_write_end(). I strongly encourage + * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing + * the chunk, as that will keep the code from breaking if you want to just + * write a plain PNG file. If you have long comments, I suggest writing + * them in png_write_end(), and compressing them. + */ +void PNGAPI +png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_info_before_PLTE\n"); + if (png_ptr == NULL || info_ptr == NULL) + return; + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + { + png_write_sig(png_ptr); /* write PNG signature */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) + if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) + { + png_warning(png_ptr,"MNG features are not allowed in a PNG datastream"); + png_ptr->mng_features_permitted=0; + } +#endif + /* write IHDR information. */ + png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, + info_ptr->filter_type, +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) + info_ptr->interlace_type); +#else + 0); +#endif + /* the rest of these check to see if the valid field has the appropriate + flag set, and if it does, writes the chunk. */ +#if defined(PNG_WRITE_gAMA_SUPPORTED) + if (info_ptr->valid & PNG_INFO_gAMA) + { +# ifdef PNG_FLOATING_POINT_SUPPORTED + png_write_gAMA(png_ptr, info_ptr->gamma); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma); +# endif +#endif + } +#endif +#if defined(PNG_WRITE_sRGB_SUPPORTED) + if (info_ptr->valid & PNG_INFO_sRGB) + png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); +#endif +#if defined(PNG_WRITE_iCCP_SUPPORTED) + if (info_ptr->valid & PNG_INFO_iCCP) + png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, + info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); +#endif +#if defined(PNG_WRITE_sBIT_SUPPORTED) + if (info_ptr->valid & PNG_INFO_sBIT) + png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); +#endif +#if defined(PNG_WRITE_cHRM_SUPPORTED) + if (info_ptr->valid & PNG_INFO_cHRM) + { +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_write_cHRM(png_ptr, + info_ptr->x_white, info_ptr->y_white, + info_ptr->x_red, info_ptr->y_red, + info_ptr->x_green, info_ptr->y_green, + info_ptr->x_blue, info_ptr->y_blue); +#else +# ifdef PNG_FIXED_POINT_SUPPORTED + png_write_cHRM_fixed(png_ptr, + info_ptr->int_x_white, info_ptr->int_y_white, + info_ptr->int_x_red, info_ptr->int_y_red, + info_ptr->int_x_green, info_ptr->int_y_green, + info_ptr->int_x_blue, info_ptr->int_y_blue); +# endif +#endif + } +#endif +#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks\n"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && !(up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; + } +} + +void PNGAPI +png_write_info(png_structp png_ptr, png_infop info_ptr) +{ +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) + int i; +#endif + + png_debug(1, "in png_write_info\n"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_write_info_before_PLTE(png_ptr, info_ptr); + + if (info_ptr->valid & PNG_INFO_PLTE) + png_write_PLTE(png_ptr, info_ptr->palette, + (png_uint_32)info_ptr->num_palette); + else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Valid palette required for paletted images"); + +#if defined(PNG_WRITE_tRNS_SUPPORTED) + if (info_ptr->valid & PNG_INFO_tRNS) + { +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) + /* invert the alpha channel (in tRNS) */ + if ((png_ptr->transformations & PNG_INVERT_ALPHA) && + info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + int j; + for (j=0; j<(int)info_ptr->num_trans; j++) + info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); + } +#endif + png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), + info_ptr->num_trans, info_ptr->color_type); + } +#endif +#if defined(PNG_WRITE_bKGD_SUPPORTED) + if (info_ptr->valid & PNG_INFO_bKGD) + png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); +#endif +#if defined(PNG_WRITE_hIST_SUPPORTED) + if (info_ptr->valid & PNG_INFO_hIST) + png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); +#endif +#if defined(PNG_WRITE_oFFs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_oFFs) + png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, + info_ptr->offset_unit_type); +#endif +#if defined(PNG_WRITE_pCAL_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pCAL) + png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, + info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, + info_ptr->pcal_units, info_ptr->pcal_params); +#endif +#if defined(PNG_WRITE_sCAL_SUPPORTED) + if (info_ptr->valid & PNG_INFO_sCAL) +#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) + png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_s_width, info_ptr->scal_s_height); +#else + png_warning(png_ptr, + "png_write_sCAL not supported; sCAL chunk not written."); +#endif +#endif +#endif +#if defined(PNG_WRITE_pHYs_SUPPORTED) + if (info_ptr->valid & PNG_INFO_pHYs) + png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, + info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); +#endif +#if defined(PNG_WRITE_tIME_SUPPORTED) + if (info_ptr->valid & PNG_INFO_tIME) + { + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + png_ptr->mode |= PNG_WROTE_tIME; + } +#endif +#if defined(PNG_WRITE_sPLT_SUPPORTED) + if (info_ptr->valid & PNG_INFO_sPLT) + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); +#endif +#if defined(PNG_WRITE_TEXT_SUPPORTED) + /* Check to see if we need to write text chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing header text chunk %d, type %d\n", i, + info_ptr->text[i].compression); + /* an internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#if defined(PNG_WRITE_iTXt_SUPPORTED) + /* write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + /* If we want a compressed text chunk */ + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) + { +#if defined(PNG_WRITE_zTXt_SUPPORTED) + /* write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#if defined(PNG_WRITE_tEXt_SUPPORTED) + /* write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, + 0); +#else + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + } +#endif +#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks\n"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif +} + +/* Writes the end of the PNG file. If you don't want to write comments or + * time information, you can pass NULL for info. If you already wrote these + * in png_write_info(), do not write them again here. If you have long + * comments, I suggest writing them here, and compressing them. + */ +void PNGAPI +png_write_end(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_end\n"); + if (png_ptr == NULL) + return; + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "No IDATs written into file"); + + /* see if user wants us to write information chunks */ + if (info_ptr != NULL) + { +#if defined(PNG_WRITE_TEXT_SUPPORTED) + int i; /* local index variable */ +#endif +#if defined(PNG_WRITE_tIME_SUPPORTED) + /* check to see if user has supplied a time chunk */ + if ((info_ptr->valid & PNG_INFO_tIME) && + !(png_ptr->mode & PNG_WROTE_tIME)) + png_write_tIME(png_ptr, &(info_ptr->mod_time)); +#endif +#if defined(PNG_WRITE_TEXT_SUPPORTED) + /* loop through comment chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing trailer text chunk %d, type %d\n", i, + info_ptr->text[i].compression); + /* an internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#if defined(PNG_WRITE_iTXt_SUPPORTED) + /* write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) + { +#if defined(PNG_WRITE_zTXt_SUPPORTED) + /* write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#if defined(PNG_WRITE_tEXt_SUPPORTED) + /* write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0); +#else + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + } +#endif +#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks\n"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep=png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + } + + png_ptr->mode |= PNG_AFTER_IDAT; + + /* write end of PNG file */ + png_write_IEND(png_ptr); +#if 0 +/* This flush, added in libpng-1.0.8, causes some applications to crash + because they do not set png_ptr->output_flush_fn */ + png_flush(png_ptr); +#endif +} + +#if defined(PNG_WRITE_tIME_SUPPORTED) +#if !defined(_WIN32_WCE) +/* "time.h" functions are not supported on WindowsCE */ +void PNGAPI +png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) +{ + png_debug(1, "in png_convert_from_struct_tm\n"); + ptime->year = (png_uint_16)(1900 + ttime->tm_year); + ptime->month = (png_byte)(ttime->tm_mon + 1); + ptime->day = (png_byte)ttime->tm_mday; + ptime->hour = (png_byte)ttime->tm_hour; + ptime->minute = (png_byte)ttime->tm_min; + ptime->second = (png_byte)ttime->tm_sec; +} + +void PNGAPI +png_convert_from_time_t(png_timep ptime, time_t ttime) +{ + struct tm *tbuf; + + png_debug(1, "in png_convert_from_time_t\n"); + tbuf = gmtime(&ttime); + png_convert_from_struct_tm(ptime, tbuf); +} +#endif +#endif + +/* Initialize png_ptr structure, and allocate any memory needed */ +png_structp PNGAPI +png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); +} + +/* Alternate initialize png_ptr structure, and allocate any memory needed */ +png_structp PNGAPI +png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + png_structp png_ptr; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + int i; + png_debug(1, "in png_create_write_struct\n"); +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif /* PNG_USER_MEM_SUPPORTED */ + if (png_ptr == NULL) + return (NULL); + +#if !defined(PNG_1_0_X) +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED + png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ +#endif +#endif /* PNG_1_0_X */ + + /* added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max=PNG_USER_WIDTH_MAX; + png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_ptr->jmpbuf)) +#endif + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf=NULL; + png_destroy_struct(png_ptr); + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); +#endif +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif /* PNG_USER_MEM_SUPPORTED */ + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + i=0; + do + { + if(user_png_ver[i] != png_libpng_ver[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + } while (png_libpng_ver[i++]); + + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so + * we must recompile any applications that use any older library version. + * For versions after libpng 1.0, we will be compatible, so we need + * only check the first digit. + */ + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || + (user_png_ver[0] == '0' && user_png_ver[2] < '9')) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "Incompatible libpng version in application and library"); + } + } + + /* initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, + 1, png_doublep_NULL, png_doublep_NULL); +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then encounter + a png_error() will longjmp here. Since the jmpbuf is then meaningless we + abort instead of returning. */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif + return (png_ptr); +} + +/* Initialize png_ptr structure, and allocate any memory needed */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Deprecated. */ +#undef png_write_init +void PNGAPI +png_write_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + if(png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn=NULL; + if (user_png_ver) + { + sprintf(msg, "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + sprintf(msg, "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if(png_sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn=NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for writing is too small."); + } + if(png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn=NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags=0; +#endif + png_error(png_ptr, + "The info struct allocated by the application for writing is too small."); + } + png_write_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + + +void PNGAPI +png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ + png_structp png_ptr=*ptr_ptr; +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i = 0; + + if (png_ptr == NULL) + return; + + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; +#else + png_ptr->warning_fn=NULL; + png_warning(png_ptr, + "Application uses deprecated png_write_init() and should be recompiled."); + break; +#endif + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_write_init_3\n"); + +#ifdef PNG_SETJMP_SUPPORTED + /* save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); +#endif + + if (png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + *ptr_ptr = png_ptr; + } + + /* reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof (png_struct)); + + /* added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max=PNG_USER_WIDTH_MAX; + png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; +#endif + +#if !defined(PNG_1_0_X) +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED + png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ +#endif +#endif /* PNG_1_0_X */ + +#ifdef PNG_SETJMP_SUPPORTED + /* restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); +#endif + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + + /* initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, + 1, png_doublep_NULL, png_doublep_NULL); +#endif +} + +/* Write a few rows of image data. If the image is interlaced, + * either you will have to write the 7 sub images, or, if you + * have called png_set_interlace_handling(), you will have to + * "write" the image seven times. + */ +void PNGAPI +png_write_rows(png_structp png_ptr, png_bytepp row, + png_uint_32 num_rows) +{ + png_uint_32 i; /* row counter */ + png_bytepp rp; /* row pointer */ + + png_debug(1, "in png_write_rows\n"); + + if (png_ptr == NULL) + return; + + /* loop through the rows */ + for (i = 0, rp = row; i < num_rows; i++, rp++) + { + png_write_row(png_ptr, *rp); + } +} + +/* Write the image. You only need to call this function once, even + * if you are writing an interlaced image. + */ +void PNGAPI +png_write_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i; /* row index */ + int pass, num_pass; /* pass variables */ + png_bytepp rp; /* points to current row */ + + if (png_ptr == NULL) + return; + + png_debug(1, "in png_write_image\n"); +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) + /* intialize interlace handling. If image is not interlaced, + this will set pass to 1 */ + num_pass = png_set_interlace_handling(png_ptr); +#else + num_pass = 1; +#endif + /* loop through passes */ + for (pass = 0; pass < num_pass; pass++) + { + /* loop through image */ + for (i = 0, rp = image; i < png_ptr->height; i++, rp++) + { + png_write_row(png_ptr, *rp); + } + } +} + +/* called by user to write a row of image data */ +void PNGAPI +png_write_row(png_structp png_ptr, png_bytep row) +{ + if (png_ptr == NULL) + return; + png_debug2(1, "in png_write_row (row %ld, pass %d)\n", + png_ptr->row_number, png_ptr->pass); + + /* initialize transformations and other stuff if first time */ + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* make sure we wrote the header info */ + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + png_error(png_ptr, + "png_write_info was never called before png_write_row."); + + /* check for transforms that have been set but were defined out */ +#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); +#endif + + png_write_start_row(png_ptr); + } + +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) + /* if interlaced and not interested in row, return */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 3: + if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 4: + if ((png_ptr->row_number & 0x03) != 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 5: + if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 6: + if (!(png_ptr->row_number & 0x01)) + { + png_write_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + /* set up row info for transformations */ + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->usr_width; + png_ptr->row_info.channels = png_ptr->usr_channels; + png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; + png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * + png_ptr->row_info.channels); + + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); + png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width); + png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); + png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth); + png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth); + png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes); + + /* Copy user's row into buffer, leaving room for filter byte. */ + png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, + png_ptr->row_info.rowbytes); + +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) + /* handle interlacing */ + if (png_ptr->interlaced && png_ptr->pass < 6 && + (png_ptr->transformations & PNG_INTERLACE)) + { + png_do_write_interlace(&(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->pass); + /* this should always get caught above, but still ... */ + if (!(png_ptr->row_info.width)) + { + png_write_finish_row(png_ptr); + return; + } + } +#endif + + /* handle other transformations */ + if (png_ptr->transformations) + png_do_write_transformations(png_ptr); + +#if defined(PNG_MNG_FEATURES_SUPPORTED) + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + } +#endif + + /* Find a filter if necessary, filter the row and write it out. */ + png_write_find_filter(png_ptr, &(png_ptr->row_info)); + + if (png_ptr->write_row_fn != NULL) + (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) +/* Set the automatic flush interval or 0 to turn flushing off */ +void PNGAPI +png_set_flush(png_structp png_ptr, int nrows) +{ + png_debug(1, "in png_set_flush\n"); + if (png_ptr == NULL) + return; + png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); +} + +/* flush the current output buffers now */ +void PNGAPI +png_write_flush(png_structp png_ptr) +{ + int wrote_IDAT; + + png_debug(1, "in png_write_flush\n"); + if (png_ptr == NULL) + return; + /* We have already written out all of the data */ + if (png_ptr->row_number >= png_ptr->num_rows) + return; + + do + { + int ret; + + /* compress the data */ + ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); + wrote_IDAT = 0; + + /* check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + + if (!(png_ptr->zstream.avail_out)) + { + /* write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + wrote_IDAT = 1; + } + } while(wrote_IDAT == 1); + + /* If there is any data left to be output, write it into a new IDAT */ + if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) + { + /* write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + png_ptr->flush_rows = 0; + png_flush(png_ptr); +} +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + +/* free all memory used by the write */ +void PNGAPI +png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; +#endif + + png_debug(1, "in png_destroy_write_struct\n"); + if (png_ptr_ptr != NULL) + { + png_ptr = *png_ptr_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; +#endif + } + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; + png_ptr->num_chunk_list=0; + } +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { + png_write_destroy(png_ptr); +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + + +/* Free any memory used in png_ptr struct (old method) */ +void /* PRIVATE */ +png_write_destroy(png_structp png_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* save jump buffer */ +#endif + png_error_ptr error_fn; + png_error_ptr warning_fn; + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_write_destroy\n"); + /* free any memory zlib uses */ + deflateEnd(&png_ptr->zstream); + + /* free our memory. png_free checks NULL for us. */ + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->row_buf); + png_free(png_ptr, png_ptr->prev_row); + png_free(png_ptr, png_ptr->sub_row); + png_free(png_ptr, png_ptr->up_row); + png_free(png_ptr, png_ptr->avg_row); + png_free(png_ptr, png_ptr->paeth_row); + +#if defined(PNG_TIME_RFC1123_SUPPORTED) + png_free(png_ptr, png_ptr->time_buffer); +#endif + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + png_free(png_ptr, png_ptr->prev_filters); + png_free(png_ptr, png_ptr->filter_weights); + png_free(png_ptr, png_ptr->inv_filter_weights); + png_free(png_ptr, png_ptr->filter_costs); + png_free(png_ptr, png_ptr->inv_filter_costs); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* reset structure */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; + warning_fn = png_ptr->warning_fn; + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof (png_struct)); + + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); +#endif +} + +/* Allow the application to select one or more row filters to use. */ +void PNGAPI +png_set_filter(png_structp png_ptr, int method, int filters) +{ + png_debug(1, "in png_set_filter\n"); + if (png_ptr == NULL) + return; +#if defined(PNG_MNG_FEATURES_SUPPORTED) + if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (method == PNG_INTRAPIXEL_DIFFERENCING)) + method = PNG_FILTER_TYPE_BASE; +#endif + if (method == PNG_FILTER_TYPE_BASE) + { + switch (filters & (PNG_ALL_FILTERS | 0x07)) + { + case 5: + case 6: + case 7: png_warning(png_ptr, "Unknown row filter for method 0"); + case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break; + case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break; + case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break; + case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break; + case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break; + default: png_ptr->do_filter = (png_byte)filters; break; + } + + /* If we have allocated the row_buf, this means we have already started + * with the image and we should have allocated all of the filter buffers + * that have been selected. If prev_row isn't already allocated, then + * it is too late to start using the filters that need it, since we + * will be missing the data in the previous row. If an application + * wants to start and stop using particular filters during compression, + * it should start out with all of the filters, and then add and + * remove them after the start of compression. + */ + if (png_ptr->row_buf != NULL) + { + if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Up filter after starting"); + png_ptr->do_filter &= ~PNG_FILTER_UP; + } + else + { + png_ptr->up_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Average filter after starting"); + png_ptr->do_filter &= ~PNG_FILTER_AVG; + } + else + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_PAETH) && + png_ptr->paeth_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Paeth filter after starting"); + png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); + } + else + { + png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } + + if (png_ptr->do_filter == PNG_NO_FILTERS) + png_ptr->do_filter = PNG_FILTER_NONE; + } + } + else + png_error(png_ptr, "Unknown custom filter method"); +} + +/* This allows us to influence the way in which libpng chooses the "best" + * filter for the current scanline. While the "minimum-sum-of-absolute- + * differences metric is relatively fast and effective, there is some + * question as to whether it can be improved upon by trying to keep the + * filtered data going to zlib more consistent, hopefully resulting in + * better compression. + */ +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ +void PNGAPI +png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, + int num_weights, png_doublep filter_weights, + png_doublep filter_costs) +{ + int i; + + png_debug(1, "in png_set_filter_heuristics\n"); + if (png_ptr == NULL) + return; + if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) + { + png_warning(png_ptr, "Unknown filter heuristic method"); + return; + } + + if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) + { + heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; + } + + if (num_weights < 0 || filter_weights == NULL || + heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) + { + num_weights = 0; + } + + png_ptr->num_prev_filters = (png_byte)num_weights; + png_ptr->heuristic_method = (png_byte)heuristic_method; + + if (num_weights > 0) + { + if (png_ptr->prev_filters == NULL) + { + png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_byte) * num_weights)); + + /* To make sure that the weighting starts out fairly */ + for (i = 0; i < num_weights; i++) + { + png_ptr->prev_filters[i] = 255; + } + } + + if (png_ptr->filter_weights == NULL) + { + png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + + png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + for (i = 0; i < num_weights; i++) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + } + + for (i = 0; i < num_weights; i++) + { + if (filter_weights[i] < 0.0) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + else + { + png_ptr->inv_filter_weights[i] = + (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5); + png_ptr->filter_weights[i] = + (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5); + } + } + } + + /* If, in the future, there are other filter methods, this would + * need to be based on png_ptr->filter. + */ + if (png_ptr->filter_costs == NULL) + { + png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + + png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + { + png_ptr->inv_filter_costs[i] = + png_ptr->filter_costs[i] = PNG_COST_FACTOR; + } + } + + /* Here is where we set the relative costs of the different filters. We + * should take the desired compression level into account when setting + * the costs, so that Paeth, for instance, has a high relative cost at low + * compression levels, while it has a lower relative cost at higher + * compression settings. The filter types are in order of increasing + * relative cost, so it would be possible to do this with an algorithm. + */ + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + { + if (filter_costs == NULL || filter_costs[i] < 0.0) + { + png_ptr->inv_filter_costs[i] = + png_ptr->filter_costs[i] = PNG_COST_FACTOR; + } + else if (filter_costs[i] >= 1.0) + { + png_ptr->inv_filter_costs[i] = + (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5); + png_ptr->filter_costs[i] = + (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); + } + } +} +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +void PNGAPI +png_set_compression_level(png_structp png_ptr, int level) +{ + png_debug(1, "in png_set_compression_level\n"); + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; + png_ptr->zlib_level = level; +} + +void PNGAPI +png_set_compression_mem_level(png_structp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_compression_mem_level\n"); + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; + png_ptr->zlib_mem_level = mem_level; +} + +void PNGAPI +png_set_compression_strategy(png_structp png_ptr, int strategy) +{ + png_debug(1, "in png_set_compression_strategy\n"); + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; + png_ptr->zlib_strategy = strategy; +} + +void PNGAPI +png_set_compression_window_bits(png_structp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + if (window_bits > 15) + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + else if (window_bits < 8) + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); +#ifndef WBITS_8_OK + /* avoid libpng bug with 256-byte windows */ + if (window_bits == 8) + { + png_warning(png_ptr, "Compression window is being reset to 512"); + window_bits=9; + } +#endif + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; + png_ptr->zlib_window_bits = window_bits; +} + +void PNGAPI +png_set_compression_method(png_structp png_ptr, int method) +{ + png_debug(1, "in png_set_compression_method\n"); + if (png_ptr == NULL) + return; + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; + png_ptr->zlib_method = method; +} + +void PNGAPI +png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->write_row_fn = write_row_fn; +} + +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +void PNGAPI +png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + write_user_transform_fn) +{ + png_debug(1, "in png_set_write_user_transform_fn\n"); + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->write_user_transform_fn = write_user_transform_fn; +} +#endif + + +#if defined(PNG_INFO_IMAGE_SUPPORTED) +void PNGAPI +png_write_png(png_structp png_ptr, png_infop info_ptr, + int transforms, voidp params) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) + /* invert the alpha channel from opacity to transparency */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + + /* Write the file header information. */ + png_write_info(png_ptr, info_ptr); + + /* ------ these transformations don't touch the info structure ------- */ + +#if defined(PNG_WRITE_INVERT_SUPPORTED) + /* invert monochrome pixels */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#if defined(PNG_WRITE_SHIFT_SUPPORTED) + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && (info_ptr->valid & PNG_INFO_sBIT)) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#endif + +#if defined(PNG_WRITE_PACK_SUPPORTED) + /* pack pixels into bytes */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) + /* swap location of alpha bytes from ARGB to RGBA */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) + /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into + * RGB (4 channels -> 3 channels). The second parameter is not used. + */ + if (transforms & PNG_TRANSFORM_STRIP_FILLER) + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); +#endif + +#if defined(PNG_WRITE_BGR_SUPPORTED) + /* flip BGR pixels to RGB */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#if defined(PNG_WRITE_SWAP_SUPPORTED) + /* swap bytes of 16-bit files to most significant byte first */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) + /* swap bits of 1, 2, 4 bit packed pixel formats */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + + /* ----------------------- end of transformations ------------------- */ + + /* write the bits */ + if (info_ptr->valid & PNG_INFO_IDAT) + png_write_image(png_ptr, info_ptr->row_pointers); + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); + + if(transforms == 0 || params == NULL) + /* quiet compiler warnings */ return; +} +#endif +#endif /* PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwtran.c ./win32/dependencies/libpng/pngwtran.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwtran.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngwtran.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,572 @@ + +/* pngwtran.c - transforms the data in a row for PNG writers + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Transform the data according to the user's wishes. The order of + * transformations is significant. + */ +void /* PRIVATE */ +png_do_write_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_do_write_transformations\n"); + + if (png_ptr == NULL) + return; + +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + if(png_ptr->write_user_transform_fn != NULL) + (*(png_ptr->write_user_transform_fn)) /* user write transform function */ + (png_ptr, /* png_ptr */ + &(png_ptr->row_info), /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_uint_32 rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#endif +#if defined(PNG_WRITE_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->flags); +#endif +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#if defined(PNG_WRITE_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, + (png_uint_32)png_ptr->bit_depth); +#endif +#if defined(PNG_WRITE_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#if defined(PNG_WRITE_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif +#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#if defined(PNG_WRITE_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#if defined(PNG_WRITE_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +} + +#if defined(PNG_WRITE_PACK_SUPPORTED) +/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The + * row_info bit depth should be 8 (one pixel per byte). The channels + * should be 1 (this only happens on grayscale and paletted images). + */ +void /* PRIVATE */ +png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) +{ + png_debug(1, "in png_do_pack\n"); + if (row_info->bit_depth == 8 && +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + row_info->channels == 1) + { + switch ((int)bit_depth) + { + case 1: + { + png_bytep sp, dp; + int mask, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + mask = 0x80; + v = 0; + + for (i = 0; i < row_width; i++) + { + if (*sp != 0) + v |= mask; + sp++; + if (mask > 1) + mask >>= 1; + else + { + mask = 0x80; + *dp = (png_byte)v; + dp++; + v = 0; + } + } + if (mask != 0x80) + *dp = (png_byte)v; + break; + } + case 2: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 6; + v = 0; + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x03); + v |= (value << shift); + if (shift == 0) + { + shift = 6; + *dp = (png_byte)v; + dp++; + v = 0; + } + else + shift -= 2; + sp++; + } + if (shift != 6) + *dp = (png_byte)v; + break; + } + case 4: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 4; + v = 0; + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x0f); + v |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp = (png_byte)v; + dp++; + v = 0; + } + else + shift -= 4; + + sp++; + } + if (shift != 4) + *dp = (png_byte)v; + break; + } + } + row_info->bit_depth = (png_byte)bit_depth; + row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +#if defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Shift pixel values to take advantage of whole range. Pass the + * true number of bits in bit_depth. The row should be packed + * according to row_info->bit_depth. Thus, if you had a row of + * bit depth 4, but the pixels only had values from 0 to 7, you + * would pass 3 as bit_depth, and this routine would translate the + * data to 0 to 15. + */ +void /* PRIVATE */ +png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) +{ + png_debug(1, "in png_do_shift\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL && +#else + if ( +#endif + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift_start[4], shift_dec[4]; + int channels = 0; + + if (row_info->color_type & PNG_COLOR_MASK_COLOR) + { + shift_start[channels] = row_info->bit_depth - bit_depth->red; + shift_dec[channels] = bit_depth->red; + channels++; + shift_start[channels] = row_info->bit_depth - bit_depth->green; + shift_dec[channels] = bit_depth->green; + channels++; + shift_start[channels] = row_info->bit_depth - bit_depth->blue; + shift_dec[channels] = bit_depth->blue; + channels++; + } + else + { + shift_start[channels] = row_info->bit_depth - bit_depth->gray; + shift_dec[channels] = bit_depth->gray; + channels++; + } + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + shift_start[channels] = row_info->bit_depth - bit_depth->alpha; + shift_dec[channels] = bit_depth->alpha; + channels++; + } + + /* with low row depths, could only be grayscale, so one channel */ + if (row_info->bit_depth < 8) + { + png_bytep bp = row; + png_uint_32 i; + png_byte mask; + png_uint_32 row_bytes = row_info->rowbytes; + + if (bit_depth->gray == 1 && row_info->bit_depth == 2) + mask = 0x55; + else if (row_info->bit_depth == 4 && bit_depth->gray == 3) + mask = 0x11; + else + mask = 0xff; + + for (i = 0; i < row_bytes; i++, bp++) + { + png_uint_16 v; + int j; + + v = *bp; + *bp = 0; + for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + else + *bp |= (png_byte)((v >> (-j)) & mask); + } + } + } + else if (row_info->bit_depth == 8) + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (i = 0; i < istop; i++, bp++) + { + + png_uint_16 v; + int j; + int c = (int)(i%channels); + + v = *bp; + *bp = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + else + *bp |= (png_byte)((v >> (-j)) & 0xff); + } + } + } + else + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (bp = row, i = 0; i < istop; i++) + { + int c = (int)(i%channels); + png_uint_16 value, v; + int j; + + v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); + value = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); + else + value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); + } + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + } + } +} +#endif + +#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +void /* PRIVATE */ +png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_swap_alpha\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from ARGB to RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + /* This converts from AARRGGBB to RRGGBBAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from AG to GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + /* This converts from AAGG to GGAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } + } + } +} +#endif + +#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +void /* PRIVATE */ +png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_invert_alpha\n"); +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This inverts the alpha channel in RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=3; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=6; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This inverts the alpha channel in GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + *(dp++) = *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + /* This inverts the alpha channel in GGAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=2; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + } + } +} +#endif + +#if defined(PNG_MNG_FEATURES_SUPPORTED) +/* undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel\n"); + if ( +#if defined(PNG_USELESS_TESTS_SUPPORTED) + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((*rp - *(rp+1))&0xff); + *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp+1); + png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3); + png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5); + png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp+1) = (png_byte)(red & 0xff); + *(rp+4) = (png_byte)((blue >> 8) & 0xff); + *(rp+5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwutil.c ./win32/dependencies/libpng/pngwutil.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/libpng/pngwutil.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/libpng/pngwutil.c 2006-05-13 06:27:07 +0900 @@ -0,0 +1,2745 @@ + +/* pngwutil.c - utilities to write a PNG file + * + * Last changed in libpng 1.2.9 April 14, 2006 + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +#define PNG_INTERNAL +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Place a 32-bit number into a buffer in PNG byte order. We work + * with unsigned numbers for convenience, although one supported + * ancillary chunk uses signed (two's complement) numbers. + */ +void PNGAPI +png_save_uint_32(png_bytep buf, png_uint_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} + +/* The png_save_int_32 function assumes integers are stored in two's + * complement format. If this isn't the case, then this routine needs to + * be modified to write data in two's complement format. + */ +void PNGAPI +png_save_int_32(png_bytep buf, png_int_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +void PNGAPI +png_save_uint_16(png_bytep buf, unsigned int i) +{ + buf[0] = (png_byte)((i >> 8) & 0xff); + buf[1] = (png_byte)(i & 0xff); +} + +/* Write a PNG chunk all at once. The type is an array of ASCII characters + * representing the chunk name. The array must be at least 4 bytes in + * length, and does not need to be null terminated. To be safe, pass the + * pre-defined chunk names here, and if you need a new one, define it + * where the others are defined. The length is the length of the data. + * All the data must be present. If that is not possible, use the + * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() + * functions instead. + */ +void PNGAPI +png_write_chunk(png_structp png_ptr, png_bytep chunk_name, + png_bytep data, png_size_t length) +{ + png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); + png_write_chunk_data(png_ptr, data, length); + png_write_chunk_end(png_ptr); +} + +/* Write the start of a PNG chunk. The type is the chunk type. + * The total_length is the sum of the lengths of all the data you will be + * passing in png_write_chunk_data(). + */ +void PNGAPI +png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, + png_uint_32 length) +{ + png_byte buf[4]; + png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length); + + /* write the length */ + png_save_uint_32(buf, length); + png_write_data(png_ptr, buf, (png_size_t)4); + + /* write the chunk name */ + png_write_data(png_ptr, chunk_name, (png_size_t)4); + /* reset the crc and run it over the chunk name */ + png_reset_crc(png_ptr); + png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); +} + +/* Write the data of a PNG chunk started with png_write_chunk_start(). + * Note that multiple calls to this function are allowed, and that the + * sum of the lengths from these calls *must* add up to the total_length + * given to png_write_chunk_start(). + */ +void PNGAPI +png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + /* write the data, and run the CRC over it */ + if (data != NULL && length > 0) + { + png_calculate_crc(png_ptr, data, length); + png_write_data(png_ptr, data, length); + } +} + +/* Finish a chunk started with png_write_chunk_start(). */ +void PNGAPI +png_write_chunk_end(png_structp png_ptr) +{ + png_byte buf[4]; + + /* write the crc */ + png_save_uint_32(buf, png_ptr->crc); + + png_write_data(png_ptr, buf, (png_size_t)4); +} + +/* Simple function to write the signature. If we have already written + * the magic bytes of the signature, or more likely, the PNG stream is + * being embedded into another stream and doesn't need its own signature, + * we should call png_set_sig_bytes() to tell libpng how many of the + * bytes have already been written. + */ +void /* PRIVATE */ +png_write_sig(png_structp png_ptr) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + /* write the rest of the 8 byte signature */ + png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], + (png_size_t)8 - png_ptr->sig_bytes); + if(png_ptr->sig_bytes < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) +/* + * This pair of functions encapsulates the operation of (a) compressing a + * text string, and (b) issuing it later as a series of chunk data writes. + * The compression_state structure is shared context for these functions + * set up by the caller in order to make the whole mess thread-safe. + */ + +typedef struct +{ + char *input; /* the uncompressed input data */ + int input_len; /* its length */ + int num_output_ptr; /* number of output pointers used */ + int max_output_ptr; /* size of output_ptr */ + png_charpp output_ptr; /* array of pointers to output */ +} compression_state; + +/* compress given text into storage in the png_ptr structure */ +static int /* PRIVATE */ +png_text_compress(png_structp png_ptr, + png_charp text, png_size_t text_len, int compression, + compression_state *comp) +{ + int ret; + + comp->num_output_ptr = 0; + comp->max_output_ptr = 0; + comp->output_ptr = NULL; + comp->input = NULL; + comp->input_len = 0; + + /* we may just want to pass the text right through */ + if (compression == PNG_TEXT_COMPRESSION_NONE) + { + comp->input = text; + comp->input_len = text_len; + return((int)text_len); + } + + if (compression >= PNG_TEXT_COMPRESSION_LAST) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[50]; + sprintf(msg, "Unknown compression type %d", compression); + png_warning(png_ptr, msg); +#else + png_warning(png_ptr, "Unknown compression type"); +#endif + } + + /* We can't write the chunk until we find out how much data we have, + * which means we need to run the compressor first and save the + * output. This shouldn't be a problem, as the vast majority of + * comments should be reasonable, but we will set up an array of + * malloc'd pointers to be sure. + * + * If we knew the application was well behaved, we could simplify this + * greatly by assuming we can always malloc an output buffer large + * enough to hold the compressed text ((1001 * text_len / 1000) + 12) + * and malloc this directly. The only time this would be a bad idea is + * if we can't malloc more than 64K and we have 64K of random input + * data, or if the input string is incredibly large (although this + * wouldn't cause a failure, just a slowdown due to swapping). + */ + + /* set up the compression buffers */ + png_ptr->zstream.avail_in = (uInt)text_len; + png_ptr->zstream.next_in = (Bytef *)text; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; + + /* this is the same compression loop as in png_write_row() */ + do + { + /* compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + if (ret != Z_OK) + { + /* error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + /* check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* make sure the output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_charpp old_ptr; + + old_ptr = comp->output_ptr; + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof (png_charpp))); + png_memcpy(comp->output_ptr, old_ptr, old_max + * png_sizeof (png_charp)); + png_free(png_ptr, old_ptr); + } + else + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof (png_charp))); + } + + /* save the data */ + comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + comp->num_output_ptr++; + + /* and reset the buffer */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + /* continue until we don't have any more to compress */ + } while (png_ptr->zstream.avail_in); + + /* finish the compression */ + do + { + /* tell zlib we are finished */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + + if (ret == Z_OK) + { + /* check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* check to make sure our output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_charpp old_ptr; + + old_ptr = comp->output_ptr; + /* This could be optimized to realloc() */ + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof (png_charpp))); + png_memcpy(comp->output_ptr, old_ptr, + old_max * png_sizeof (png_charp)); + png_free(png_ptr, old_ptr); + } + else + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof (png_charp))); + } + + /* save off the data */ + comp->output_ptr[comp->num_output_ptr] = + (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size); + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + comp->num_output_ptr++; + + /* and reset the buffer pointers */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + } + else if (ret != Z_STREAM_END) + { + /* we got an error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* text length is number of buffers plus last buffer */ + text_len = png_ptr->zbuf_size * comp->num_output_ptr; + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; + + return((int)text_len); +} + +/* ship the compressed text out via chunk writes */ +static void /* PRIVATE */ +png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) +{ + int i; + + /* handle the no-compression case */ + if (comp->input) + { + png_write_chunk_data(png_ptr, (png_bytep)comp->input, + (png_size_t)comp->input_len); + return; + } + + /* write saved output buffers, if any */ + for (i = 0; i < comp->num_output_ptr; i++) + { + png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i], + png_ptr->zbuf_size); + png_free(png_ptr, comp->output_ptr[i]); + comp->output_ptr[i]=NULL; + } + if (comp->max_output_ptr != 0) + png_free(png_ptr, comp->output_ptr); + comp->output_ptr=NULL; + /* write anything left in zbuf */ + if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) + png_write_chunk_data(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + + /* reset zlib for another zTXt/iTXt or image data */ + deflateReset(&png_ptr->zstream); + png_ptr->zstream.data_type = Z_BINARY; +} +#endif + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. Note that the rest of this code depends upon this + * information being correct. + */ +void /* PRIVATE */ +png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, + int bit_depth, int color_type, int compression_type, int filter_type, + int interlace_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IHDR; +#endif + png_byte buf[13]; /* buffer to store the IHDR info */ + + png_debug(1, "in png_write_IHDR\n"); + /* Check that we have valid input data from the application info */ + switch (color_type) + { + case PNG_COLOR_TYPE_GRAY: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: + case 16: png_ptr->channels = 1; break; + default: png_error(png_ptr,"Invalid bit depth for grayscale image"); + } + break; + case PNG_COLOR_TYPE_RGB: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for RGB image"); + png_ptr->channels = 3; + break; + case PNG_COLOR_TYPE_PALETTE: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: png_ptr->channels = 1; break; + default: png_error(png_ptr, "Invalid bit depth for paletted image"); + } + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); + png_ptr->channels = 2; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for RGBA image"); + png_ptr->channels = 4; + break; + default: + png_error(png_ptr, "Invalid image color type specified"); + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Invalid compression type specified"); + compression_type = PNG_COMPRESSION_TYPE_BASE; + } + + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ( +#if defined(PNG_MNG_FEATURES_SUPPORTED) + !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && +#endif + filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Invalid filter type specified"); + filter_type = PNG_FILTER_TYPE_BASE; + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + if (interlace_type != PNG_INTERLACE_NONE && + interlace_type != PNG_INTERLACE_ADAM7) + { + png_warning(png_ptr, "Invalid interlace type specified"); + interlace_type = PNG_INTERLACE_ADAM7; + } +#else + interlace_type=PNG_INTERLACE_NONE; +#endif + + /* save off the relevent information */ + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->color_type = (png_byte)color_type; + png_ptr->interlaced = (png_byte)interlace_type; +#if defined(PNG_MNG_FEATURES_SUPPORTED) + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + png_ptr->width = width; + png_ptr->height = height; + + png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + /* set the usr info, so any transformations can modify it */ + png_ptr->usr_width = png_ptr->width; + png_ptr->usr_bit_depth = png_ptr->bit_depth; + png_ptr->usr_channels = png_ptr->channels; + + /* pack the header information into the buffer */ + png_save_uint_32(buf, width); + png_save_uint_32(buf + 4, height); + buf[8] = (png_byte)bit_depth; + buf[9] = (png_byte)color_type; + buf[10] = (png_byte)compression_type; + buf[11] = (png_byte)filter_type; + buf[12] = (png_byte)interlace_type; + + /* write the chunk */ + png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13); + + /* initialize zlib with PNG info */ + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + if (!(png_ptr->do_filter)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + png_ptr->bit_depth < 8) + png_ptr->do_filter = PNG_FILTER_NONE; + else + png_ptr->do_filter = PNG_ALL_FILTERS; + } + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) + { + if (png_ptr->do_filter != PNG_FILTER_NONE) + png_ptr->zlib_strategy = Z_FILTERED; + else + png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; + } + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) + png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) + png_ptr->zlib_mem_level = 8; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) + png_ptr->zlib_window_bits = 15; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) + png_ptr->zlib_method = 8; + deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + /* libpng is not interested in zstream.data_type */ + /* set it to a predefined value, to avoid its evaluation inside zlib */ + png_ptr->zstream.data_type = Z_BINARY; + + png_ptr->mode = PNG_HAVE_IHDR; +} + +/* write the palette. We are careful not to trust png_color to be in the + * correct order for PNG, so people can redefine it to any convenient + * structure. + */ +void /* PRIVATE */ +png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_PLTE; +#endif + png_uint_32 i; + png_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE\n"); + if (( +#if defined(PNG_MNG_FEATURES_SUPPORTED) + !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && +#endif + num_pal == 0) || num_pal > 256) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_error(png_ptr, "Invalid number of colors in palette"); + } + else + { + png_warning(png_ptr, "Invalid number of colors in palette"); + return; + } + } + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring request to write a PLTE chunk in grayscale PNG"); + return; + } + + png_ptr->num_palette = (png_uint_16)num_pal; + png_debug1(3, "num_palette = %d\n", png_ptr->num_palette); + + png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, num_pal * 3); +#ifndef PNG_NO_POINTER_INDEXING + for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) + { + buf[0] = pal_ptr->red; + buf[1] = pal_ptr->green; + buf[2] = pal_ptr->blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } +#else + /* This is a little slower but some buggy compilers need to do this instead */ + pal_ptr=palette; + for (i = 0; i < num_pal; i++) + { + buf[0] = pal_ptr[i].red; + buf[1] = pal_ptr[i].green; + buf[2] = pal_ptr[i].blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } +#endif + png_write_chunk_end(png_ptr); + png_ptr->mode |= PNG_HAVE_PLTE; +} + +/* write an IDAT chunk */ +void /* PRIVATE */ +png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#endif + png_debug(1, "in png_write_IDAT\n"); + + /* Optimize the CMF field in the zlib stream. */ + /* This hack of the zlib stream is compliant to the stream specification. */ + if (!(png_ptr->mode & PNG_HAVE_IDAT) && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + { + unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + /* Avoid memory underflows and multiplication overflows. */ + /* The conditions below are practically always satisfied; + however, they still must be checked. */ + if (length >= 2 && + png_ptr->height < 16384 && png_ptr->width < 16384) + { + png_uint_32 uncompressed_idat_size = png_ptr->height * + ((png_ptr->width * + png_ptr->channels * png_ptr->bit_depth + 15) >> 3); + unsigned int z_cinfo = z_cmf >> 4; + unsigned int half_z_window_size = 1 << (z_cinfo + 7); + while (uncompressed_idat_size <= half_z_window_size && + half_z_window_size >= 256) + { + z_cinfo--; + half_z_window_size >>= 1; + } + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + if (data[0] != (png_byte)z_cmf) + { + data[0] = (png_byte)z_cmf; + data[1] &= 0xe0; + data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f); + } + } + } + else + png_error(png_ptr, + "Invalid zlib compression method or flags in IDAT"); + } + + png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); + png_ptr->mode |= PNG_HAVE_IDAT; +} + +/* write an IEND chunk */ +void /* PRIVATE */ +png_write_IEND(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IEND; +#endif + png_debug(1, "in png_write_IEND\n"); + png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, + (png_size_t)0); + png_ptr->mode |= PNG_HAVE_IEND; +} + +#if defined(PNG_WRITE_gAMA_SUPPORTED) +/* write a gAMA chunk */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void /* PRIVATE */ +png_write_gAMA(png_structp png_ptr, double file_gamma) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_gAMA; +#endif + png_uint_32 igamma; + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA\n"); + /* file_gamma is saved in 1/100,000ths */ + igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5); + png_save_uint_32(buf, igamma); + png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_gAMA; +#endif + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA\n"); + /* file_gamma is saved in 1/100,000ths */ + png_save_uint_32(buf, (png_uint_32)file_gamma); + png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); +} +#endif +#endif + +#if defined(PNG_WRITE_sRGB_SUPPORTED) +/* write a sRGB chunk */ +void /* PRIVATE */ +png_write_sRGB(png_structp png_ptr, int srgb_intent) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sRGB; +#endif + png_byte buf[1]; + + png_debug(1, "in png_write_sRGB\n"); + if(srgb_intent >= PNG_sRGB_INTENT_LAST) + png_warning(png_ptr, + "Invalid sRGB rendering intent specified"); + buf[0]=(png_byte)srgb_intent; + png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); +} +#endif + +#if defined(PNG_WRITE_iCCP_SUPPORTED) +/* write an iCCP chunk */ +void /* PRIVATE */ +png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, + png_charp profile, int profile_len) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_iCCP; +#endif + png_size_t name_len; + png_charp new_name; + compression_state comp; + + png_debug(1, "in png_write_iCCP\n"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if (name == NULL || (name_len = png_check_keyword(png_ptr, name, + &new_name)) == 0) + { + png_warning(png_ptr, "Empty keyword in iCCP chunk"); + return; + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_warning(png_ptr, "Unknown compression type in iCCP chunk"); + + if (profile == NULL) + profile_len = 0; + + if (profile_len) + profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len, + PNG_COMPRESSION_TYPE_BASE, &comp); + + /* make sure we include the NULL after the name and the compression type */ + png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, + (png_uint_32)name_len+profile_len+2); + new_name[name_len+1]=0x00; + png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2); + + if (profile_len) + png_write_compressed_data_out(png_ptr, &comp); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#if defined(PNG_WRITE_sPLT_SUPPORTED) +/* write a sPLT chunk */ +void /* PRIVATE */ +png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sPLT; +#endif + png_size_t name_len; + png_charp new_name; + png_byte entrybuf[10]; + int entry_size = (spalette->depth == 8 ? 6 : 10); + int palette_size = entry_size * spalette->nentries; + png_sPLT_entryp ep; +#ifdef PNG_NO_POINTER_INDEXING + int i; +#endif + + png_debug(1, "in png_write_sPLT\n"); + if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr, + spalette->name, &new_name))==0) + { + png_warning(png_ptr, "Empty keyword in sPLT chunk"); + return; + } + + /* make sure we include the NULL after the name */ + png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, + (png_uint_32)(name_len + 2 + palette_size)); + png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1); + png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1); + + /* loop through each palette entry, writing appropriately */ +#ifndef PNG_NO_POINTER_INDEXING + for (ep = spalette->entries; epentries+spalette->nentries; ep++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep->red; + entrybuf[1] = (png_byte)ep->green; + entrybuf[2] = (png_byte)ep->blue; + entrybuf[3] = (png_byte)ep->alpha; + png_save_uint_16(entrybuf + 4, ep->frequency); + } + else + { + png_save_uint_16(entrybuf + 0, ep->red); + png_save_uint_16(entrybuf + 2, ep->green); + png_save_uint_16(entrybuf + 4, ep->blue); + png_save_uint_16(entrybuf + 6, ep->alpha); + png_save_uint_16(entrybuf + 8, ep->frequency); + } + png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + } +#else + ep=spalette->entries; + for (i=0; i>spalette->nentries; i++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep[i].red; + entrybuf[1] = (png_byte)ep[i].green; + entrybuf[2] = (png_byte)ep[i].blue; + entrybuf[3] = (png_byte)ep[i].alpha; + png_save_uint_16(entrybuf + 4, ep[i].frequency); + } + else + { + png_save_uint_16(entrybuf + 0, ep[i].red); + png_save_uint_16(entrybuf + 2, ep[i].green); + png_save_uint_16(entrybuf + 4, ep[i].blue); + png_save_uint_16(entrybuf + 6, ep[i].alpha); + png_save_uint_16(entrybuf + 8, ep[i].frequency); + } + png_write_chunk_data(png_ptr, entrybuf, entry_size); + } +#endif + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#if defined(PNG_WRITE_sBIT_SUPPORTED) +/* write the sBIT chunk */ +void /* PRIVATE */ +png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sBIT; +#endif + png_byte buf[4]; + png_size_t size; + + png_debug(1, "in png_write_sBIT\n"); + /* make sure we don't depend upon the order of PNG_COLOR_8 */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + png_byte maxbits; + + maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : + png_ptr->usr_bit_depth); + if (sbit->red == 0 || sbit->red > maxbits || + sbit->green == 0 || sbit->green > maxbits || + sbit->blue == 0 || sbit->blue > maxbits) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[0] = sbit->red; + buf[1] = sbit->green; + buf[2] = sbit->blue; + size = 3; + } + else + { + if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[0] = sbit->gray; + size = 1; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[size++] = sbit->alpha; + } + + png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size); +} +#endif + +#if defined(PNG_WRITE_cHRM_SUPPORTED) +/* write the cHRM chunk */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void /* PRIVATE */ +png_write_cHRM(png_structp png_ptr, double white_x, double white_y, + double red_x, double red_y, double green_x, double green_y, + double blue_x, double blue_y) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_cHRM; +#endif + png_byte buf[32]; + png_uint_32 itemp; + + png_debug(1, "in png_write_cHRM\n"); + /* each value is saved in 1/100,000ths */ + if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 || + white_x + white_y > 1.0) + { + png_warning(png_ptr, "Invalid cHRM white point specified"); +#if !defined(PNG_NO_CONSOLE_IO) + fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y); +#endif + return; + } + itemp = (png_uint_32)(white_x * 100000.0 + 0.5); + png_save_uint_32(buf, itemp); + itemp = (png_uint_32)(white_y * 100000.0 + 0.5); + png_save_uint_32(buf + 4, itemp); + + if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0) + { + png_warning(png_ptr, "Invalid cHRM red point specified"); + return; + } + itemp = (png_uint_32)(red_x * 100000.0 + 0.5); + png_save_uint_32(buf + 8, itemp); + itemp = (png_uint_32)(red_y * 100000.0 + 0.5); + png_save_uint_32(buf + 12, itemp); + + if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0) + { + png_warning(png_ptr, "Invalid cHRM green point specified"); + return; + } + itemp = (png_uint_32)(green_x * 100000.0 + 0.5); + png_save_uint_32(buf + 16, itemp); + itemp = (png_uint_32)(green_y * 100000.0 + 0.5); + png_save_uint_32(buf + 20, itemp); + + if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0) + { + png_warning(png_ptr, "Invalid cHRM blue point specified"); + return; + } + itemp = (png_uint_32)(blue_x * 100000.0 + 0.5); + png_save_uint_32(buf + 24, itemp); + itemp = (png_uint_32)(blue_y * 100000.0 + 0.5); + png_save_uint_32(buf + 28, itemp); + + png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, + png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, + png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, + png_fixed_point blue_y) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_cHRM; +#endif + png_byte buf[32]; + + png_debug(1, "in png_write_cHRM\n"); + /* each value is saved in 1/100,000ths */ + if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L) + { + png_warning(png_ptr, "Invalid fixed cHRM white point specified"); +#if !defined(PNG_NO_CONSOLE_IO) + fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y); +#endif + return; + } + png_save_uint_32(buf, (png_uint_32)white_x); + png_save_uint_32(buf + 4, (png_uint_32)white_y); + + if (red_x + red_y > 100000L) + { + png_warning(png_ptr, "Invalid cHRM fixed red point specified"); + return; + } + png_save_uint_32(buf + 8, (png_uint_32)red_x); + png_save_uint_32(buf + 12, (png_uint_32)red_y); + + if (green_x + green_y > 100000L) + { + png_warning(png_ptr, "Invalid fixed cHRM green point specified"); + return; + } + png_save_uint_32(buf + 16, (png_uint_32)green_x); + png_save_uint_32(buf + 20, (png_uint_32)green_y); + + if (blue_x + blue_y > 100000L) + { + png_warning(png_ptr, "Invalid fixed cHRM blue point specified"); + return; + } + png_save_uint_32(buf + 24, (png_uint_32)blue_x); + png_save_uint_32(buf + 28, (png_uint_32)blue_y); + + png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); +} +#endif +#endif + +#if defined(PNG_WRITE_tRNS_SUPPORTED) +/* write the tRNS chunk */ +void /* PRIVATE */ +png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, + int num_trans, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tRNS; +#endif + png_byte buf[6]; + + png_debug(1, "in png_write_tRNS\n"); + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) + { + png_warning(png_ptr,"Invalid number of transparent colors specified"); + return; + } + /* write the chunk out as it is */ + png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, (png_size_t)num_trans); + } + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + /* one 16 bit value */ + if(tran->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); + return; + } + png_save_uint_16(buf, tran->gray); + png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2); + } + else if (color_type == PNG_COLOR_TYPE_RGB) + { + /* three 16 bit values */ + png_save_uint_16(buf, tran->red); + png_save_uint_16(buf + 2, tran->green); + png_save_uint_16(buf + 4, tran->blue); + if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); + return; + } + png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6); + } + else + { + png_warning(png_ptr, "Can't write tRNS with an alpha channel"); + } +} +#endif + +#if defined(PNG_WRITE_bKGD_SUPPORTED) +/* write the background chunk */ +void /* PRIVATE */ +png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_bKGD; +#endif + png_byte buf[6]; + + png_debug(1, "in png_write_bKGD\n"); + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if ( +#if defined(PNG_MNG_FEATURES_SUPPORTED) + (png_ptr->num_palette || + (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && +#endif + back->index > png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid background palette index"); + return; + } + buf[0] = back->index; + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1); + } + else if (color_type & PNG_COLOR_MASK_COLOR) + { + png_save_uint_16(buf, back->red); + png_save_uint_16(buf + 2, back->green); + png_save_uint_16(buf + 4, back->blue); + if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); + return; + } + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6); + } + else + { + if(back->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); + return; + } + png_save_uint_16(buf, back->gray); + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2); + } +} +#endif + +#if defined(PNG_WRITE_hIST_SUPPORTED) +/* write the histogram */ +void /* PRIVATE */ +png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_hIST; +#endif + int i; + png_byte buf[3]; + + png_debug(1, "in png_write_hIST\n"); + if (num_hist > (int)png_ptr->num_palette) + { + png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist, + png_ptr->num_palette); + png_warning(png_ptr, "Invalid number of histogram entries specified"); + return; + } + + png_write_chunk_start(png_ptr, (png_bytep)png_hIST, (png_uint_32)(num_hist * 2)); + for (i = 0; i < num_hist; i++) + { + png_save_uint_16(buf, hist[i]); + png_write_chunk_data(png_ptr, buf, (png_size_t)2); + } + png_write_chunk_end(png_ptr); +} +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The new_key is allocated to hold the corrected keyword and must be freed + * by the calling routine. This avoids problems with trying to write to + * static keywords without having to have duplicate copies of the strings. + */ +png_size_t /* PRIVATE */ +png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) +{ + png_size_t key_len; + png_charp kp, dp; + int kflag; + int kwarn=0; + + png_debug(1, "in png_check_keyword\n"); + *new_key = NULL; + + if (key == NULL || (key_len = png_strlen(key)) == 0) + { + png_warning(png_ptr, "zero length keyword"); + return ((png_size_t)0); + } + + png_debug1(2, "Keyword to be checked is '%s'\n", key); + + *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); + if (*new_key == NULL) + { + png_warning(png_ptr, "Out of memory while procesing keyword"); + return ((png_size_t)0); + } + + /* Replace non-printing characters with a blank and print a warning */ + for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++) + { + if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1)) + { +#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) + char msg[40]; + + sprintf(msg, "invalid keyword character 0x%02X", *kp); + png_warning(png_ptr, msg); +#else + png_warning(png_ptr, "invalid character in keyword"); +#endif + *dp = ' '; + } + else + { + *dp = *kp; + } + } + *dp = '\0'; + + /* Remove any trailing white space. */ + kp = *new_key + key_len - 1; + if (*kp == ' ') + { + png_warning(png_ptr, "trailing spaces removed from keyword"); + + while (*kp == ' ') + { + *(kp--) = '\0'; + key_len--; + } + } + + /* Remove any leading white space. */ + kp = *new_key; + if (*kp == ' ') + { + png_warning(png_ptr, "leading spaces removed from keyword"); + + while (*kp == ' ') + { + kp++; + key_len--; + } + } + + png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp); + + /* Remove multiple internal spaces. */ + for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) + { + if (*kp == ' ' && kflag == 0) + { + *(dp++) = *kp; + kflag = 1; + } + else if (*kp == ' ') + { + key_len--; + kwarn=1; + } + else + { + *(dp++) = *kp; + kflag = 0; + } + } + *dp = '\0'; + if(kwarn) + png_warning(png_ptr, "extra interior spaces removed from keyword"); + + if (key_len == 0) + { + png_free(png_ptr, *new_key); + *new_key=NULL; + png_warning(png_ptr, "Zero length keyword"); + } + + if (key_len > 79) + { + png_warning(png_ptr, "keyword length must be 1 - 79 characters"); + new_key[79] = '\0'; + key_len = 79; + } + + return (key_len); +} +#endif + +#if defined(PNG_WRITE_tEXt_SUPPORTED) +/* write a tEXt chunk */ +void /* PRIVATE */ +png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, + png_size_t text_len) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tEXt; +#endif + png_size_t key_len; + png_charp new_key; + + png_debug(1, "in png_write_tEXt\n"); + if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) + { + png_warning(png_ptr, "Empty keyword in tEXt chunk"); + return; + } + + if (text == NULL || *text == '\0') + text_len = 0; + else + text_len = png_strlen(text); + + /* make sure we include the 0 after the key */ + png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, (png_uint_32)key_len+text_len+1); + /* + * We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); + if (text_len) + png_write_chunk_data(png_ptr, (png_bytep)text, text_len); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_key); +} +#endif + +#if defined(PNG_WRITE_zTXt_SUPPORTED) +/* write a compressed text chunk */ +void /* PRIVATE */ +png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, + png_size_t text_len, int compression) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_zTXt; +#endif + png_size_t key_len; + char buf[1]; + png_charp new_key; + compression_state comp; + + png_debug(1, "in png_write_zTXt\n"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) + { + png_warning(png_ptr, "Empty keyword in zTXt chunk"); + return; + } + + if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) + { + png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); + png_free(png_ptr, new_key); + return; + } + + text_len = png_strlen(text); + + png_free(png_ptr, new_key); + + /* compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression, + &comp); + + /* write start of chunk */ + png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32) + (key_len+text_len+2)); + /* write key */ + png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1); + buf[0] = (png_byte)compression; + /* write compression */ + png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); + /* write the compressed data */ + png_write_compressed_data_out(png_ptr, &comp); + + /* close the chunk */ + png_write_chunk_end(png_ptr); +} +#endif + +#if defined(PNG_WRITE_iTXt_SUPPORTED) +/* write an iTXt chunk */ +void /* PRIVATE */ +png_write_iTXt(png_structp png_ptr, int compression, png_charp key, + png_charp lang, png_charp lang_key, png_charp text) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_iTXt; +#endif + png_size_t lang_len, key_len, lang_key_len, text_len; + png_charp new_lang, new_key; + png_byte cbuf[2]; + compression_state comp; + + png_debug(1, "in png_write_iTXt\n"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + + if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) + { + png_warning(png_ptr, "Empty keyword in iTXt chunk"); + return; + } + if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) + { + png_warning(png_ptr, "Empty language field in iTXt chunk"); + new_lang = NULL; + lang_len = 0; + } + + if (lang_key == NULL) + lang_key_len = 0; + else + lang_key_len = png_strlen(lang_key); + + if (text == NULL) + text_len = 0; + else + text_len = png_strlen(text); + + /* compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression-2, + &comp); + + + /* make sure we include the compression flag, the compression byte, + * and the NULs after the key, lang, and lang_key parts */ + + png_write_chunk_start(png_ptr, (png_bytep)png_iTXt, + (png_uint_32)( + 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ + + key_len + + lang_len + + lang_key_len + + text_len)); + + /* + * We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); + + /* set the compression flag */ + if (compression == PNG_ITXT_COMPRESSION_NONE || \ + compression == PNG_TEXT_COMPRESSION_NONE) + cbuf[0] = 0; + else /* compression == PNG_ITXT_COMPRESSION_zTXt */ + cbuf[0] = 1; + /* set the compression method */ + cbuf[1] = 0; + png_write_chunk_data(png_ptr, cbuf, 2); + + cbuf[0] = 0; + png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1); + png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1); + png_write_compressed_data_out(png_ptr, &comp); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_key); + if (new_lang) + png_free(png_ptr, new_lang); +} +#endif + +#if defined(PNG_WRITE_oFFs_SUPPORTED) +/* write the oFFs chunk */ +void /* PRIVATE */ +png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, + int unit_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_oFFs; +#endif + png_byte buf[9]; + + png_debug(1, "in png_write_oFFs\n"); + if (unit_type >= PNG_OFFSET_LAST) + png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); + + png_save_int_32(buf, x_offset); + png_save_int_32(buf + 4, y_offset); + buf[8] = (png_byte)unit_type; + + png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); +} +#endif + +#if defined(PNG_WRITE_pCAL_SUPPORTED) +/* write the pCAL chunk (described in the PNG extensions document) */ +void /* PRIVATE */ +png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, + png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_pCAL; +#endif + png_size_t purpose_len, units_len, total_len; + png_uint_32p params_len; + png_byte buf[10]; + png_charp new_purpose; + int i; + + png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams); + if (type >= PNG_EQUATION_LAST) + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + + purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; + png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len); + units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); + png_debug1(3, "pCAL units length = %d\n", (int)units_len); + total_len = purpose_len + units_len + 10; + + params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams + *png_sizeof(png_uint_32))); + + /* Find the length of each parameter, making sure we don't count the + null terminator for the last parameter. */ + for (i = 0; i < nparams; i++) + { + params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); + png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]); + total_len += (png_size_t)params_len[i]; + } + + png_debug1(3, "pCAL total length = %d\n", (int)total_len); + png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len); + png_save_int_32(buf, X0); + png_save_int_32(buf + 4, X1); + buf[8] = (png_byte)type; + buf[9] = (png_byte)nparams; + png_write_chunk_data(png_ptr, buf, (png_size_t)10); + png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len); + + png_free(png_ptr, new_purpose); + + for (i = 0; i < nparams; i++) + { + png_write_chunk_data(png_ptr, (png_bytep)params[i], + (png_size_t)params_len[i]); + } + + png_free(png_ptr, params_len); + png_write_chunk_end(png_ptr); +} +#endif + +#if defined(PNG_WRITE_sCAL_SUPPORTED) +/* write the sCAL chunk */ +#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) +void /* PRIVATE */ +png_write_sCAL(png_structp png_ptr, int unit, double width,double height) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sCAL; +#endif + png_size_t total_len; + char wbuf[32], hbuf[32]; + png_byte bunit = (png_byte)unit; + + png_debug(1, "in png_write_sCAL\n"); + +#if defined(_WIN32_WCE) +/* sprintf() function is not supported on WindowsCE */ + { + wchar_t wc_buf[32]; + swprintf(wc_buf, TEXT("%12.12e"), width); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, wbuf, 32, NULL, NULL); + swprintf(wc_buf, TEXT("%12.12e"), height); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, hbuf, 32, NULL, NULL); + } +#else + sprintf(wbuf, "%12.12e", width); + sprintf(hbuf, "%12.12e", height); +#endif + total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); + + png_debug1(3, "sCAL total length = %d\n", (int)total_len); + png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1); + png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); + png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); + + png_write_chunk_end(png_ptr); +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, + png_charp height) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sCAL; +#endif + png_size_t total_len; + char wbuf[32], hbuf[32]; + png_byte bunit = unit; + + png_debug(1, "in png_write_sCAL_s\n"); + + png_strcpy(wbuf,(const char *)width); + png_strcpy(hbuf,(const char *)height); + total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf); + + png_debug1(3, "sCAL total length = %d\n", total_len); + png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1); + png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1); + png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf)); + + png_write_chunk_end(png_ptr); +} +#endif +#endif +#endif + +#if defined(PNG_WRITE_pHYs_SUPPORTED) +/* write the pHYs chunk */ +void /* PRIVATE */ +png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, + png_uint_32 y_pixels_per_unit, + int unit_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_pHYs; +#endif + png_byte buf[9]; + + png_debug(1, "in png_write_pHYs\n"); + if (unit_type >= PNG_RESOLUTION_LAST) + png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); + + png_save_uint_32(buf, x_pixels_per_unit); + png_save_uint_32(buf + 4, y_pixels_per_unit); + buf[8] = (png_byte)unit_type; + + png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9); +} +#endif + +#if defined(PNG_WRITE_tIME_SUPPORTED) +/* Write the tIME chunk. Use either png_convert_from_struct_tm() + * or png_convert_from_time_t(), or fill in the structure yourself. + */ +void /* PRIVATE */ +png_write_tIME(png_structp png_ptr, png_timep mod_time) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tIME; +#endif + png_byte buf[7]; + + png_debug(1, "in png_write_tIME\n"); + if (mod_time->month > 12 || mod_time->month < 1 || + mod_time->day > 31 || mod_time->day < 1 || + mod_time->hour > 23 || mod_time->second > 60) + { + png_warning(png_ptr, "Invalid time specified for tIME chunk"); + return; + } + + png_save_uint_16(buf, mod_time->year); + buf[2] = mod_time->month; + buf[3] = mod_time->day; + buf[4] = mod_time->hour; + buf[5] = mod_time->minute; + buf[6] = mod_time->second; + + png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7); +} +#endif + +/* initializes the row writing capability of libpng */ +void /* PRIVATE */ +png_write_start_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_size_t buf_size; + + png_debug(1, "in png_write_start_row\n"); + buf_size = (png_size_t)(PNG_ROWBYTES( + png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1); + + /* set up row buffer */ + png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); + png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; + + /* set up filtering buffer, if using this filter */ + if (png_ptr->do_filter & PNG_FILTER_SUB) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + /* We only need to keep the previous row if we are using one of these. */ + if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) + { + /* set up previous row buffer */ + png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); + png_memset(png_ptr->prev_row, 0, buf_size); + + if (png_ptr->do_filter & PNG_FILTER_UP) + { + png_ptr->up_row = (png_bytep )png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + + if (png_ptr->do_filter & PNG_FILTER_AVG) + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + + if (png_ptr->do_filter & PNG_FILTER_PAETH) + { + png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* if interlaced, we need to set up width and height of pass */ + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - + png_pass_start[0]) / png_pass_inc[0]; + } + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + } + else +#endif + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; +} + +/* Internal use only. Called when finished processing a row of data. */ +void /* PRIVATE */ +png_write_finish_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int ret; + + png_debug(1, "in png_write_finish_row\n"); + /* next row */ + png_ptr->row_number++; + + /* see if we are done */ + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* if interlaced, go to next pass */ + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + if (png_ptr->transformations & PNG_INTERLACE) + { + png_ptr->pass++; + } + else + { + /* loop until we find a non-zero width or height pass */ + do + { + png_ptr->pass++; + if (png_ptr->pass >= 7) + break; + png_ptr->usr_width = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + if (png_ptr->transformations & PNG_INTERLACE) + break; + } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); + + } + + /* reset the row above the image for the next pass */ + if (png_ptr->pass < 7) + { + if (png_ptr->prev_row != NULL) + png_memset(png_ptr->prev_row, 0, + (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* + png_ptr->usr_bit_depth,png_ptr->width))+1); + return; + } + } +#endif + + /* if we get here, we've just written the last row, so we need + to flush the compressor */ + do + { + /* tell the compressor we are done */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + /* check for an error */ + if (ret == Z_OK) + { + /* check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + else if (ret != Z_STREAM_END) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* write any extra space */ + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - + png_ptr->zstream.avail_out); + } + + deflateReset(&png_ptr->zstream); + png_ptr->zstream.data_type = Z_BINARY; +} + +#if defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Pick out the correct pixels for the interlace pass. + * The basic idea here is to go through the row with a source + * pointer and a destination pointer (sp and dp), and copy the + * correct pixels for the pass. As the row gets compacted, + * sp will always be >= dp, so we should never overwrite anything. + * See the default: case for the easiest code to understand. + */ +void /* PRIVATE */ +png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; +#endif + + png_debug(1, "in png_do_write_interlace\n"); + /* we don't have to do anything on the last pass (6) */ +#if defined(PNG_USELESS_TESTS_SUPPORTED) + if (row != NULL && row_info != NULL && pass < 6) +#else + if (pass < 6) +#endif + { + /* each pixel depth is handled separately */ + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + d = 0; + shift = 7; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 3); + value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; + d |= (value << shift); + + if (shift == 0) + { + shift = 7; + *dp++ = (png_byte)d; + d = 0; + } + else + shift--; + + } + if (shift != 7) + *dp = (png_byte)d; + break; + } + case 2: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 6; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 2); + value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; + d |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp++ = (png_byte)d; + d = 0; + } + else + shift -= 2; + } + if (shift != 6) + *dp = (png_byte)d; + break; + } + case 4: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 4; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 1); + value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; + d |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp++ = (png_byte)d; + d = 0; + } + else + shift -= 4; + } + if (shift != 4) + *dp = (png_byte)d; + break; + } + default: + { + png_bytep sp; + png_bytep dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + png_size_t pixel_bytes; + + /* start at the beginning */ + dp = row; + /* find out how many bytes each pixel takes up */ + pixel_bytes = (row_info->pixel_depth >> 3); + /* loop through the row, only looking at the pixels that + matter */ + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + /* find out where the original pixel is */ + sp = row + (png_size_t)i * pixel_bytes; + /* move the pixel */ + if (dp != sp) + png_memcpy(dp, sp, pixel_bytes); + /* next pixel */ + dp += pixel_bytes; + } + break; + } + } + /* set new row width */ + row_info->width = (row_info->width + + png_pass_inc[pass] - 1 - + png_pass_start[pass]) / + png_pass_inc[pass]; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +/* This filters the row, chooses which filter to use, if it has not already + * been specified by the application, and then writes the row out with the + * chosen filter. + */ +#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) +#define PNG_HISHIFT 10 +#define PNG_LOMASK ((png_uint_32)0xffffL) +#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) +void /* PRIVATE */ +png_write_find_filter(png_structp png_ptr, png_row_infop row_info) +{ + png_bytep prev_row, best_row, row_buf; + png_uint_32 mins, bpp; + png_byte filter_to_do = png_ptr->do_filter; + png_uint_32 row_bytes = row_info->rowbytes; +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + int num_p_filters = (int)png_ptr->num_prev_filters; +#endif + + png_debug(1, "in png_write_find_filter\n"); + /* find out how many bytes offset each pixel is */ + bpp = (row_info->pixel_depth + 7) >> 3; + + prev_row = png_ptr->prev_row; + best_row = row_buf = png_ptr->row_buf; + mins = PNG_MAXSUM; + + /* The prediction method we use is to find which method provides the + * smallest value when summing the absolute values of the distances + * from zero, using anything >= 128 as negative numbers. This is known + * as the "minimum sum of absolute differences" heuristic. Other + * heuristics are the "weighted minimum sum of absolute differences" + * (experimental and can in theory improve compression), and the "zlib + * predictive" method (not implemented yet), which does test compressions + * of lines using different filter methods, and then chooses the + * (series of) filter(s) that give minimum compressed data size (VERY + * computationally expensive). + * + * GRR 980525: consider also + * (1) minimum sum of absolute differences from running average (i.e., + * keep running sum of non-absolute differences & count of bytes) + * [track dispersion, too? restart average if dispersion too large?] + * (1b) minimum sum of absolute differences from sliding average, probably + * with window size <= deflate window (usually 32K) + * (2) minimum sum of squared differences from zero or running average + * (i.e., ~ root-mean-square approach) + */ + + + /* We don't need to test the 'no filter' case if this is the only filter + * that has been chosen, as it doesn't actually do anything to the data. + */ + if ((filter_to_do & PNG_FILTER_NONE) && + filter_to_do != PNG_FILTER_NONE) + { + png_bytep rp; + png_uint_32 sum = 0; + png_uint_32 i; + int v; + + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + { + v = *rp; + sum += (v < 128) ? v : 256 - v; + } + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + png_uint_32 sumhi, sumlo; + int j; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */ + + /* Reduce the sum if we match any of the previous rows */ + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + /* Factor in the cost of this filter (this is here for completeness, + * but it makes no sense to have a "cost" for the NONE filter, as + * it has the minimum possible computational cost - none). + */ + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + mins = sum; + } + + /* sub filter */ + if (filter_to_do == PNG_FILTER_SUB) + /* it's the only filter so no testing is needed */ + { + png_bytep rp, lp, dp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + *dp = *rp; + } + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + } + best_row = png_ptr->sub_row; + } + + else if (filter_to_do & PNG_FILTER_SUB) + { + png_bytep rp, dp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + /* We temporarily increase the "minimum sum" by the factor we + * would reduce the sum of this filter, so that we can do the + * early exit comparison without scaling the sum each time. + */ + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + v = *dp = *rp; + + sum += (v < 128) ? v : 256 - v; + } + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->sub_row; + } + } + + /* up filter */ + if (filter_to_do == PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_uint_32 i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + } + best_row = png_ptr->up_row; + } + + else if (filter_to_do & PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->up_row; + } + } + + /* avg filter */ + if (filter_to_do == PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + } + for (lp = row_buf + 1; i < row_bytes; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + } + best_row = png_ptr->avg_row; + } + + else if (filter_to_do & PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + for (lp = row_buf + 1; i < row_bytes; i++) + { + v = *dp++ = + (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->avg_row; + } + } + + /* Paeth filter */ + if (filter_to_do == PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + } + best_row = png_ptr->paeth_row; + } + + else if (filter_to_do & PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + +#ifndef PNG_SLOW_PAETH + p = b - c; + pc = a - c; +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; +#else /* PNG_SLOW_PAETH */ + p = a + b - c; + pa = abs(p - a); + pb = abs(p - b); + pc = abs(p - c); + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; +#endif /* PNG_SLOW_PAETH */ + + v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + best_row = png_ptr->paeth_row; + } + } + + /* Do the actual writing of the filtered row data from the chosen filter. */ + + png_write_filtered_row(png_ptr, best_row); + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) + /* Save the type of filter we picked this time for future calculations */ + if (png_ptr->num_prev_filters > 0) + { + int j; + for (j = 1; j < num_p_filters; j++) + { + png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; + } + png_ptr->prev_filters[j] = best_row[0]; + } +#endif +} + + +/* Do the actual writing of a previously filtered row. */ +void /* PRIVATE */ +png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) +{ + png_debug(1, "in png_write_filtered_row\n"); + png_debug1(2, "filter = %d\n", filtered_row[0]); + /* set up the zlib input buffer */ + + png_ptr->zstream.next_in = filtered_row; + png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1; + /* repeat until we have compressed all the data */ + do + { + int ret; /* return of zlib */ + + /* compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + /* check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + + /* see if it is time to write another IDAT */ + if (!(png_ptr->zstream.avail_out)) + { + /* write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + /* repeat until all data has been compressed */ + } while (png_ptr->zstream.avail_in); + + /* swap the current and previous rows */ + if (png_ptr->prev_row != NULL) + { + png_bytep tptr; + + tptr = png_ptr->prev_row; + png_ptr->prev_row = png_ptr->row_buf; + png_ptr->row_buf = tptr; + } + + /* finish row - updates counters and flushes zlib if last row */ + png_write_finish_row(png_ptr); + +#if defined(PNG_WRITE_FLUSH_SUPPORTED) + png_ptr->flush_rows++; + + if (png_ptr->flush_dist > 0 && + png_ptr->flush_rows >= png_ptr->flush_dist) + { + png_write_flush(png_ptr); + } +#endif +} +#endif /* PNG_WRITE_SUPPORTED */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL.h ./win32/dependencies/sdl/SDL.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,94 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Main include header for the SDL library */ + +#ifndef _SDL_H +#define _SDL_H + +#include "SDL_main.h" +#include "SDL_stdinc.h" +#include "SDL_audio.h" +#include "SDL_cdrom.h" +#include "SDL_cpuinfo.h" +#include "SDL_endian.h" +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_loadso.h" +#include "SDL_mutex.h" +#include "SDL_rwops.h" +#include "SDL_thread.h" +#include "SDL_timer.h" +#include "SDL_video.h" +#include "SDL_version.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* As of version 0.5, SDL is loaded dynamically into the application */ + +/* These are the flags which may be passed to SDL_Init() -- you should + specify the subsystems which you will be using in your application. +*/ +#define SDL_INIT_TIMER 0x00000001 +#define SDL_INIT_AUDIO 0x00000010 +#define SDL_INIT_VIDEO 0x00000020 +#define SDL_INIT_CDROM 0x00000100 +#define SDL_INIT_JOYSTICK 0x00000200 +#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */ +#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */ +#define SDL_INIT_EVERYTHING 0x0000FFFF + +/* This function loads the SDL dynamically linked library and initializes + * the subsystems specified by 'flags' (and those satisfying dependencies) + * Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup + * signal handlers for some commonly ignored fatal signals (like SIGSEGV) + */ +extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); + +/* This function initializes specific SDL subsystems */ +extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags); + +/* This function cleans up specific SDL subsystems */ +extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags); + +/* This function returns mask of the specified subsystems which have + been initialized. + If 'flags' is 0, it returns a mask of all initialized subsystems. +*/ +extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags); + +/* This function cleans up all initialized subsystems and unloads the + * dynamically linked library. You should call it upon all exit conditions. + */ +extern DECLSPEC void SDLCALL SDL_Quit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_H */ Binary files ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_Debug/SDL.lib and ./win32/dependencies/sdl/SDL_Debug/SDL.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_Debug/SDLmain.lib and ./win32/dependencies/sdl/SDL_Debug/SDLmain.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_Release/SDL.lib and ./win32/dependencies/sdl/SDL_Release/SDL.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_Release/SDLmain.lib and ./win32/dependencies/sdl/SDL_Release/SDLmain.lib differ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_active.h ./win32/dependencies/sdl/SDL_active.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_active.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_active.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,58 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL application focus event handling */ + +#ifndef _SDL_active_h +#define _SDL_active_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* The available application states */ +#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */ +#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */ +#define SDL_APPACTIVE 0x04 /* The application is active */ + +/* Function prototypes */ +/* + * This function returns the current state of the application, which is a + * bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and + * SDL_APPACTIVE. If SDL_APPACTIVE is set, then the user is able to + * see your application, otherwise it has been iconified or disabled. + */ +extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_active_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_audio.h ./win32/dependencies/sdl/SDL_audio.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_audio.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_audio.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,253 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Access to the raw audio mixing buffer for the SDL library */ + +#ifndef _SDL_audio_h +#define _SDL_audio_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_endian.h" +#include "SDL_mutex.h" +#include "SDL_thread.h" +#include "SDL_rwops.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* The calculated values in this structure are calculated by SDL_OpenAudio() */ +typedef struct SDL_AudioSpec { + int freq; /* DSP frequency -- samples per second */ + Uint16 format; /* Audio data format */ + Uint8 channels; /* Number of channels: 1 mono, 2 stereo */ + Uint8 silence; /* Audio buffer silence value (calculated) */ + Uint16 samples; /* Audio buffer size in samples (power of 2) */ + Uint16 padding; /* Necessary for some compile environments */ + Uint32 size; /* Audio buffer size in bytes (calculated) */ + /* This function is called when the audio device needs more data. + 'stream' is a pointer to the audio data buffer + 'len' is the length of that buffer in bytes. + Once the callback returns, the buffer will no longer be valid. + Stereo samples are stored in a LRLRLR ordering. + */ + void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len); + void *userdata; +} SDL_AudioSpec; + +/* Audio format flags (defaults to LSB byte order) */ +#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */ +#define AUDIO_S8 0x8008 /* Signed 8-bit samples */ +#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */ +#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */ +#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */ +#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */ +#define AUDIO_U16 AUDIO_U16LSB +#define AUDIO_S16 AUDIO_S16LSB + +/* Native audio byte ordering */ +#if SDL_BYTEORDER == SDL_LIL_ENDIAN +#define AUDIO_U16SYS AUDIO_U16LSB +#define AUDIO_S16SYS AUDIO_S16LSB +#else +#define AUDIO_U16SYS AUDIO_U16MSB +#define AUDIO_S16SYS AUDIO_S16MSB +#endif + + +/* A structure to hold a set of audio conversion filters and buffers */ +typedef struct SDL_AudioCVT { + int needed; /* Set to 1 if conversion possible */ + Uint16 src_format; /* Source audio format */ + Uint16 dst_format; /* Target audio format */ + double rate_incr; /* Rate conversion increment */ + Uint8 *buf; /* Buffer to hold entire audio data */ + int len; /* Length of original audio buffer */ + int len_cvt; /* Length of converted audio buffer */ + int len_mult; /* buffer must be len*len_mult big */ + double len_ratio; /* Given len, final size is len*len_ratio */ + void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format); + int filter_index; /* Current audio conversion function */ +} SDL_AudioCVT; + + +/* Function prototypes */ + +/* These functions are used internally, and should not be used unless you + * have a specific need to specify the audio driver you want to use. + * You should normally use SDL_Init() or SDL_InitSubSystem(). + */ +extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name); +extern DECLSPEC void SDLCALL SDL_AudioQuit(void); + +/* This function fills the given character buffer with the name of the + * current audio driver, and returns a pointer to it if the audio driver has + * been initialized. It returns NULL if no driver has been initialized. + */ +extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen); + +/* + * This function opens the audio device with the desired parameters, and + * returns 0 if successful, placing the actual hardware parameters in the + * structure pointed to by 'obtained'. If 'obtained' is NULL, the audio + * data passed to the callback function will be guaranteed to be in the + * requested format, and will be automatically converted to the hardware + * audio format if necessary. This function returns -1 if it failed + * to open the audio device, or couldn't set up the audio thread. + * + * When filling in the desired audio spec structure, + * 'desired->freq' should be the desired audio frequency in samples-per-second. + * 'desired->format' should be the desired audio format. + * 'desired->samples' is the desired size of the audio buffer, in samples. + * This number should be a power of two, and may be adjusted by the audio + * driver to a value more suitable for the hardware. Good values seem to + * range between 512 and 8096 inclusive, depending on the application and + * CPU speed. Smaller values yield faster response time, but can lead + * to underflow if the application is doing heavy processing and cannot + * fill the audio buffer in time. A stereo sample consists of both right + * and left channels in LR ordering. + * Note that the number of samples is directly related to time by the + * following formula: ms = (samples*1000)/freq + * 'desired->size' is the size in bytes of the audio buffer, and is + * calculated by SDL_OpenAudio(). + * 'desired->silence' is the value used to set the buffer to silence, + * and is calculated by SDL_OpenAudio(). + * 'desired->callback' should be set to a function that will be called + * when the audio device is ready for more data. It is passed a pointer + * to the audio buffer, and the length in bytes of the audio buffer. + * This function usually runs in a separate thread, and so you should + * protect data structures that it accesses by calling SDL_LockAudio() + * and SDL_UnlockAudio() in your code. + * 'desired->userdata' is passed as the first parameter to your callback + * function. + * + * The audio device starts out playing silence when it's opened, and should + * be enabled for playing by calling SDL_PauseAudio(0) when you are ready + * for your audio callback function to be called. Since the audio driver + * may modify the requested size of the audio buffer, you should allocate + * any local mixing buffers after you open the audio device. + */ +extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained); + +/* + * Get the current audio state: + */ +typedef enum { + SDL_AUDIO_STOPPED = 0, + SDL_AUDIO_PLAYING, + SDL_AUDIO_PAUSED +} SDL_audiostatus; +extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void); + +/* + * This function pauses and unpauses the audio callback processing. + * It should be called with a parameter of 0 after opening the audio + * device to start playing sound. This is so you can safely initialize + * data for your callback function after opening the audio device. + * Silence will be written to the audio device during the pause. + */ +extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on); + +/* + * This function loads a WAVE from the data source, automatically freeing + * that source if 'freesrc' is non-zero. For example, to load a WAVE file, + * you could do: + * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); + * + * If this function succeeds, it returns the given SDL_AudioSpec, + * filled with the audio data format of the wave data, and sets + * 'audio_buf' to a malloc()'d buffer containing the audio data, + * and sets 'audio_len' to the length of that audio buffer, in bytes. + * You need to free the audio buffer with SDL_FreeWAV() when you are + * done with it. + * + * This function returns NULL and sets the SDL error message if the + * wave file cannot be opened, uses an unknown data format, or is + * corrupt. Currently raw and MS-ADPCM WAVE files are supported. + */ +extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len); + +/* Compatibility convenience function -- loads a WAV from a file */ +#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \ + SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len) + +/* + * This function frees data previously allocated with SDL_LoadWAV_RW() + */ +extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 *audio_buf); + +/* + * This function takes a source format and rate and a destination format + * and rate, and initializes the 'cvt' structure with information needed + * by SDL_ConvertAudio() to convert a buffer of audio data from one format + * to the other. + * This function returns 0, or -1 if there was an error. + */ +extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt, + Uint16 src_format, Uint8 src_channels, int src_rate, + Uint16 dst_format, Uint8 dst_channels, int dst_rate); + +/* Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(), + * created an audio buffer cvt->buf, and filled it with cvt->len bytes of + * audio data in the source format, this function will convert it in-place + * to the desired format. + * The data conversion may expand the size of the audio data, so the buffer + * cvt->buf should be allocated after the cvt structure is initialized by + * SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long. + */ +extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt); + +/* + * This takes two audio buffers of the playing audio format and mixes + * them, performing addition, volume adjustment, and overflow clipping. + * The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME + * for full audio volume. Note this does not change hardware volume. + * This is provided for convenience -- you can mix your own audio data. + */ +#define SDL_MIX_MAXVOLUME 128 +extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume); + +/* + * The lock manipulated by these functions protects the callback function. + * During a LockAudio/UnlockAudio pair, you can be guaranteed that the + * callback function is not running. Do not call these from the callback + * function or you will cause deadlock. + */ +extern DECLSPEC void SDLCALL SDL_LockAudio(void); +extern DECLSPEC void SDLCALL SDL_UnlockAudio(void); + +/* + * This function shuts down audio processing and closes the audio device. + */ +extern DECLSPEC void SDLCALL SDL_CloseAudio(void); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_audio_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_byteorder.h ./win32/dependencies/sdl/SDL_byteorder.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_byteorder.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_byteorder.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,24 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* DEPRECATED */ +#include "SDL_endian.h" diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_cdrom.h ./win32/dependencies/sdl/SDL_cdrom.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_cdrom.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_cdrom.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,171 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This is the CD-audio control API for Simple DirectMedia Layer */ + +#ifndef _SDL_cdrom_h +#define _SDL_cdrom_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* In order to use these functions, SDL_Init() must have been called + with the SDL_INIT_CDROM flag. This causes SDL to scan the system + for CD-ROM drives, and load appropriate drivers. +*/ + +/* The maximum number of CD-ROM tracks on a disk */ +#define SDL_MAX_TRACKS 99 + +/* The types of CD-ROM track possible */ +#define SDL_AUDIO_TRACK 0x00 +#define SDL_DATA_TRACK 0x04 + +/* The possible states which a CD-ROM drive can be in. */ +typedef enum { + CD_TRAYEMPTY, + CD_STOPPED, + CD_PLAYING, + CD_PAUSED, + CD_ERROR = -1 +} CDstatus; + +/* Given a status, returns true if there's a disk in the drive */ +#define CD_INDRIVE(status) ((int)(status) > 0) + +typedef struct SDL_CDtrack { + Uint8 id; /* Track number */ + Uint8 type; /* Data or audio track */ + Uint16 unused; + Uint32 length; /* Length, in frames, of this track */ + Uint32 offset; /* Offset, in frames, from start of disk */ +} SDL_CDtrack; + +/* This structure is only current as of the last call to SDL_CDStatus() */ +typedef struct SDL_CD { + int id; /* Private drive identifier */ + CDstatus status; /* Current drive status */ + + /* The rest of this structure is only valid if there's a CD in drive */ + int numtracks; /* Number of tracks on disk */ + int cur_track; /* Current track position */ + int cur_frame; /* Current frame offset within current track */ + SDL_CDtrack track[SDL_MAX_TRACKS+1]; +} SDL_CD; + +/* Conversion functions from frames to Minute/Second/Frames and vice versa */ +#define CD_FPS 75 +#define FRAMES_TO_MSF(f, M,S,F) { \ + int value = f; \ + *(F) = value%CD_FPS; \ + value /= CD_FPS; \ + *(S) = value%60; \ + value /= 60; \ + *(M) = value; \ +} +#define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F)) + +/* CD-audio API functions: */ + +/* Returns the number of CD-ROM drives on the system, or -1 if + SDL_Init() has not been called with the SDL_INIT_CDROM flag. + */ +extern DECLSPEC int SDLCALL SDL_CDNumDrives(void); + +/* Returns a human-readable, system-dependent identifier for the CD-ROM. + Example: + "/dev/cdrom" + "E:" + "/dev/disk/ide/1/master" +*/ +extern DECLSPEC const char * SDLCALL SDL_CDName(int drive); + +/* Opens a CD-ROM drive for access. It returns a drive handle on success, + or NULL if the drive was invalid or busy. This newly opened CD-ROM + becomes the default CD used when other CD functions are passed a NULL + CD-ROM handle. + Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. +*/ +extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive); + +/* This function returns the current status of the given drive. + If the drive has a CD in it, the table of contents of the CD and current + play position of the CD will be stored in the SDL_CD structure. +*/ +extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom); + +/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks' + tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play + until the end of the CD. This function will skip data tracks. + This function should only be called after calling SDL_CDStatus() to + get track information about the CD. + For example: + // Play entire CD: + if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) + SDL_CDPlayTracks(cdrom, 0, 0, 0, 0); + // Play last track: + if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { + SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0); + } + // Play first and second track and 10 seconds of third track: + if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) + SDL_CDPlayTracks(cdrom, 0, 0, 2, 10); + + This function returns 0, or -1 if there was an error. +*/ +extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom, + int start_track, int start_frame, int ntracks, int nframes); + +/* Play the given CD starting at 'start' frame for 'length' frames. + It returns 0, or -1 if there was an error. +*/ +extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length); + +/* Pause play -- returns 0, or -1 on error */ +extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom); + +/* Resume play -- returns 0, or -1 on error */ +extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom); + +/* Stop play -- returns 0, or -1 on error */ +extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom); + +/* Eject CD-ROM -- returns 0, or -1 on error */ +extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom); + +/* Closes the handle for the CD-ROM drive */ +extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_video_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h ./win32/dependencies/sdl/SDL_config.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,45 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_h +#define _SDL_config_h + +#include "SDL_platform.h" + +/* Add any platform that doesn't build using the configure system */ +#if defined(__AMIGA__) +#include "SDL_config_amiga.h" +#elif defined(__DREAMCAST__) +#include "SDL_config_dreamcast.h" +#elif defined(__MACOS__) +#include "SDL_config_macos.h" +#elif defined(__MACOSX__) +#include "SDL_config_macosx.h" +#elif defined(__WIN32__) +#include "SDL_config_win32.h" +#elif defined(__OS2__) +#include "SDL_config_os2.h" +#else +#include "SDL_config_minimal.h" +#endif /* platform config */ + +#endif /* _SDL_config_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h.default ./win32/dependencies/sdl/SDL_config.h.default --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h.default 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config.h.default 2006-06-25 04:59:04 +0900 @@ -0,0 +1,45 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_h +#define _SDL_config_h + +#include "SDL_platform.h" + +/* Add any platform that doesn't build using the configure system */ +#if defined(__AMIGA__) +#include "SDL_config_amiga.h" +#elif defined(__DREAMCAST__) +#include "SDL_config_dreamcast.h" +#elif defined(__MACOS__) +#include "SDL_config_macos.h" +#elif defined(__MACOSX__) +#include "SDL_config_macosx.h" +#elif defined(__WIN32__) +#include "SDL_config_win32.h" +#elif defined(__OS2__) +#include "SDL_config_os2.h" +#else +#include "SDL_config_minimal.h" +#endif /* platform config */ + +#endif /* _SDL_config_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h.in ./win32/dependencies/sdl/SDL_config.h.in --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config.h.in 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config.h.in 2006-06-25 04:59:04 +0900 @@ -0,0 +1,305 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_h +#define _SDL_config_h + +/* This is a set of defines to configure the SDL features */ + +/* General platform specific identifiers */ +#include "SDL_platform.h" + +/* C language features */ +#undef const +#undef inline +#undef volatile + +/* C datatypes */ +#undef size_t +#undef int8_t +#undef uint8_t +#undef int16_t +#undef uint16_t +#undef int32_t +#undef uint32_t +#undef int64_t +#undef uint64_t +#undef uintptr_t +#undef SDL_HAS_64BIT_TYPE + +/* Endianness */ +#undef SDL_BYTEORDER + +/* Comment this if you want to build without any C library requirements */ +#undef HAVE_LIBC +#if HAVE_LIBC + +/* Useful headers */ +#undef HAVE_ALLOCA_H +#undef HAVE_SYS_TYPES_H +#undef HAVE_STDIO_H +#undef STDC_HEADERS +#undef HAVE_STDLIB_H +#undef HAVE_STDARG_H +#undef HAVE_MALLOC_H +#undef HAVE_MEMORY_H +#undef HAVE_STRING_H +#undef HAVE_STRINGS_H +#undef HAVE_INTTYPES_H +#undef HAVE_STDINT_H +#undef HAVE_CTYPE_H +#undef HAVE_MATH_H +#undef HAVE_ICONV_H +#undef HAVE_SIGNAL_H +#undef HAVE_ALTIVEC_H + +/* C library functions */ +#undef HAVE_MALLOC +#undef HAVE_CALLOC +#undef HAVE_REALLOC +#undef HAVE_FREE +#undef HAVE_ALLOCA +#ifndef _WIN32 /* Don't use C runtime versions of these on Windows */ +#undef HAVE_GETENV +#undef HAVE_PUTENV +#undef HAVE_UNSETENV +#endif +#undef HAVE_QSORT +#undef HAVE_ABS +#undef HAVE_BCOPY +#undef HAVE_MEMSET +#undef HAVE_MEMCPY +#undef HAVE_MEMMOVE +#undef HAVE_MEMCMP +#undef HAVE_STRLEN +#undef HAVE_STRLCPY +#undef HAVE_STRLCAT +#undef HAVE_STRDUP +#undef HAVE__STRREV +#undef HAVE__STRUPR +#undef HAVE__STRLWR +#undef HAVE_INDEX +#undef HAVE_RINDEX +#undef HAVE_STRCHR +#undef HAVE_STRRCHR +#undef HAVE_STRSTR +#undef HAVE_ITOA +#undef HAVE__LTOA +#undef HAVE__UITOA +#undef HAVE__ULTOA +#undef HAVE_STRTOL +#undef HAVE_STRTOUL +#undef HAVE__I64TOA +#undef HAVE__UI64TOA +#undef HAVE_STRTOLL +#undef HAVE_STRTOULL +#undef HAVE_STRTOD +#undef HAVE_ATOI +#undef HAVE_ATOF +#undef HAVE_STRCMP +#undef HAVE_STRNCMP +#undef HAVE__STRICMP +#undef HAVE_STRCASECMP +#undef HAVE__STRNICMP +#undef HAVE_STRNCASECMP +#undef HAVE_SSCANF +#undef HAVE_SNPRINTF +#undef HAVE_VSNPRINTF +#undef HAVE_ICONV +#undef HAVE_SIGACTION +#undef HAVE_SETJMP +#undef HAVE_NANOSLEEP +#undef HAVE_CLOCK_GETTIME +#undef HAVE_DLVSYM + +#else +/* We may need some replacement for stdarg.h here */ +#include +#endif /* HAVE_LIBC */ + +/* Allow disabling of core subsystems */ +#undef SDL_AUDIO_DISABLED +#undef SDL_CDROM_DISABLED +#undef SDL_CPUINFO_DISABLED +#undef SDL_EVENTS_DISABLED +#undef SDL_FILE_DISABLED +#undef SDL_JOYSTICK_DISABLED +#undef SDL_LOADSO_DISABLED +#undef SDL_THREADS_DISABLED +#undef SDL_TIMERS_DISABLED +#undef SDL_VIDEO_DISABLED + +/* Enable various audio drivers */ +#undef SDL_AUDIO_DRIVER_AHI +#undef SDL_AUDIO_DRIVER_ALSA +#undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC +#undef SDL_AUDIO_DRIVER_ARTS +#undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC +#undef SDL_AUDIO_DRIVER_BAUDIO +#undef SDL_AUDIO_DRIVER_BSD +#undef SDL_AUDIO_DRIVER_COREAUDIO +#undef SDL_AUDIO_DRIVER_DART +#undef SDL_AUDIO_DRIVER_DC +#undef SDL_AUDIO_DRIVER_DISK +#undef SDL_AUDIO_DRIVER_DUMMY +#undef SDL_AUDIO_DRIVER_DMEDIA +#undef SDL_AUDIO_DRIVER_DSOUND +#undef SDL_AUDIO_DRIVER_ESD +#undef SDL_AUDIO_DRIVER_ESD_DYNAMIC +#undef SDL_AUDIO_DRIVER_MINT +#undef SDL_AUDIO_DRIVER_MMEAUDIO +#undef SDL_AUDIO_DRIVER_NAS +#undef SDL_AUDIO_DRIVER_OSS +#undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H +#undef SDL_AUDIO_DRIVER_PAUD +#undef SDL_AUDIO_DRIVER_QNXNTO +#undef SDL_AUDIO_DRIVER_SNDMGR +#undef SDL_AUDIO_DRIVER_SUNAUDIO +#undef SDL_AUDIO_DRIVER_WAVEOUT + +/* Enable various cdrom drivers */ +#undef SDL_CDROM_AIX +#undef SDL_CDROM_BEOS +#undef SDL_CDROM_BSDI +#undef SDL_CDROM_DC +#undef SDL_CDROM_DUMMY +#undef SDL_CDROM_FREEBSD +#undef SDL_CDROM_LINUX +#undef SDL_CDROM_MACOS +#undef SDL_CDROM_MACOSX +#undef SDL_CDROM_MINT +#undef SDL_CDROM_OPENBSD +#undef SDL_CDROM_OS2 +#undef SDL_CDROM_OSF +#undef SDL_CDROM_QNX +#undef SDL_CDROM_WIN32 + +/* Enable various input drivers */ +#undef SDL_INPUT_TSLIB +#undef SDL_JOYSTICK_AMIGA +#undef SDL_JOYSTICK_BEOS +#undef SDL_JOYSTICK_DC +#undef SDL_JOYSTICK_DUMMY +#undef SDL_JOYSTICK_IOKIT +#undef SDL_JOYSTICK_LINUX +#undef SDL_JOYSTICK_LINUXEV +#undef SDL_JOYSTICK_MACOS +#undef SDL_JOYSTICK_MINT +#undef SDL_JOYSTICK_OS2 +#undef SDL_JOYSTICK_RISCOS +#undef SDL_JOYSTICK_WINMM +#undef SDL_JOYSTICK_USBHID +#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H + +/* Enable various shared object loading systems */ +#undef SDL_LOADSO_BEOS +#undef SDL_LOADSO_DLCOMPAT +#undef SDL_LOADSO_DLOPEN +#undef SDL_LOADSO_DUMMY +#undef SDL_LOADSO_LDG +#undef SDL_LOADSO_MACOS +#undef SDL_LOADSO_OS2 +#undef SDL_LOADSO_WIN32 + +/* Enable various threading systems */ +#undef SDL_THREAD_AMIGA +#undef SDL_THREAD_BEOS +#undef SDL_THREAD_DC +#undef SDL_THREAD_EPOC +#undef SDL_THREAD_OS2 +#undef SDL_THREAD_PTH +#undef SDL_THREAD_PTHREAD +#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX +#undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP +#undef SDL_THREAD_SPROC +#undef SDL_THREAD_WIN32 + +/* Enable various timer systems */ +#undef SDL_TIMER_AMIGA +#undef SDL_TIMER_BEOS +#undef SDL_TIMER_DC +#undef SDL_TIMER_DUMMY +#undef SDL_TIMER_EPOC +#undef SDL_TIMER_MACOS +#undef SDL_TIMER_MINT +#undef SDL_TIMER_OS2 +#undef SDL_TIMER_RISCOS +#undef SDL_TIMER_UNIX +#undef SDL_TIMER_WIN32 +#undef SDL_TIMER_WINCE + +/* Enable various video drivers */ +#undef SDL_VIDEO_DRIVER_AALIB +#undef SDL_VIDEO_DRIVER_BWINDOW +#undef SDL_VIDEO_DRIVER_CYBERGRAPHICS +#undef SDL_VIDEO_DRIVER_DC +#undef SDL_VIDEO_DRIVER_DDRAW +#undef SDL_VIDEO_DRIVER_DGA +#undef SDL_VIDEO_DRIVER_DIRECTFB +#undef SDL_VIDEO_DRIVER_DRAWSPROCKET +#undef SDL_VIDEO_DRIVER_DUMMY +#undef SDL_VIDEO_DRIVER_EPOC +#undef SDL_VIDEO_DRIVER_FBCON +#undef SDL_VIDEO_DRIVER_GAPI +#undef SDL_VIDEO_DRIVER_GEM +#undef SDL_VIDEO_DRIVER_GGI +#undef SDL_VIDEO_DRIVER_IPOD +#undef SDL_VIDEO_DRIVER_NANOX +#undef SDL_VIDEO_DRIVER_OS2FS +#undef SDL_VIDEO_DRIVER_PHOTON +#undef SDL_VIDEO_DRIVER_PICOGUI +#undef SDL_VIDEO_DRIVER_PS2GS +#undef SDL_VIDEO_DRIVER_QTOPIA +#undef SDL_VIDEO_DRIVER_QUARTZ +#undef SDL_VIDEO_DRIVER_RISCOS +#undef SDL_VIDEO_DRIVER_SVGALIB +#undef SDL_VIDEO_DRIVER_TOOLBOX +#undef SDL_VIDEO_DRIVER_VGL +#undef SDL_VIDEO_DRIVER_WINDIB +#undef SDL_VIDEO_DRIVER_WSCONS +#undef SDL_VIDEO_DRIVER_X11 +#undef SDL_VIDEO_DRIVER_X11_DGAMOUSE +#undef SDL_VIDEO_DRIVER_X11_DPMS +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER +#undef SDL_VIDEO_DRIVER_X11_VIDMODE +#undef SDL_VIDEO_DRIVER_X11_XINERAMA +#undef SDL_VIDEO_DRIVER_X11_XME +#undef SDL_VIDEO_DRIVER_X11_XRANDR +#undef SDL_VIDEO_DRIVER_X11_XV +#undef SDL_VIDEO_DRIVER_XBIOS + +/* Enable OpenGL support */ +#undef SDL_VIDEO_OPENGL +#undef SDL_VIDEO_OPENGL_GLX +#undef SDL_VIDEO_OPENGL_WGL +#undef SDL_VIDEO_OPENGL_OSMESA +#undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC + +/* Enable assembly routines */ +#undef SDL_ASSEMBLY_ROUTINES +#undef SDL_HERMES_BLITTERS +#undef SDL_ALTIVEC_BLITTERS + +#endif /* _SDL_config_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_amiga.h ./win32/dependencies/sdl/SDL_config_amiga.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_amiga.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_amiga.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,80 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_amiga_h +#define _SDL_config_amiga_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +#define SDL_HAS_64BIT_TYPE 1 + +/* Useful headers */ +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_AHI 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#define SDL_CDROM_DUMMY 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_AMIGA 1 + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_DUMMY 1 + +/* Enable various threading systems */ +#define SDL_THREAD_AMIGA 1 + +/* Enable various timer systems */ +#define SDL_TIMER_AMIGA 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_CYBERGRAPHICS 1 +#define SDL_VIDEO_DRIVER_DUMMY 1 + +/* Enable OpenGL support */ +#define SDL_VIDEO_OPENGL 1 + +#endif /* _SDL_config_amiga_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_dreamcast.h ./win32/dependencies/sdl/SDL_config_dreamcast.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_dreamcast.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_dreamcast.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,106 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_dreamcast_h +#define _SDL_config_dreamcast_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +typedef unsigned long uintptr_t; +#define SDL_HAS_64BIT_TYPE 1 + +/* Useful headers */ +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_CTYPE_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRDUP 1 +#define HAVE_INDEX 1 +#define HAVE_RINDEX 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRICMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_DC 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#define SDL_CDROM_DC 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_DC 1 + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_DUMMY 1 + +/* Enable various threading systems */ +#define SDL_THREAD_DC 1 + +/* Enable various timer systems */ +#define SDL_TIMER_DC 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_DC 1 +#define SDL_VIDEO_DRIVER_DUMMY 1 + +#endif /* _SDL_config_dreamcast_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_macos.h ./win32/dependencies/sdl/SDL_config_macos.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_macos.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_macos.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,112 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_macos_h +#define _SDL_config_macos_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +#include + +typedef SInt8 int8_t; +typedef UInt8 uint8_t; +typedef SInt16 int16_t; +typedef UInt16 uint16_t; +typedef SInt32 int32_t; +typedef UInt32 uint32_t; +typedef SInt64 int64_t; +typedef UInt64 uint64_t; +typedef unsigned long uintptr_t; + +#define SDL_HAS_64BIT_TYPE 1 + +/* Useful headers */ +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_ABS 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_ITOA 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_SSCANF 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_SNDMGR 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#if TARGET_API_MAC_CARBON +#define SDL_CDROM_DUMMY 1 +#else +#define SDL_CDROM_MACOS 1 +#endif + +/* Enable various input drivers */ +#if TARGET_API_MAC_CARBON +#define SDL_JOYSTICK_DUMMY 1 +#else +#define SDL_JOYSTICK_MACOS 1 +#endif + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_MACOS 1 + +/* Enable various threading systems */ +#define SDL_THREADS_DISABLED 1 + +/* Enable various timer systems */ +#define SDL_TIMER_MACOS 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_DUMMY 1 +#define SDL_VIDEO_DRIVER_DRAWSPROCKET 1 +#define SDL_VIDEO_DRIVER_TOOLBOX 1 + +/* Enable OpenGL support */ +#define SDL_VIDEO_OPENGL 1 + +#endif /* _SDL_config_macos_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_macosx.h ./win32/dependencies/sdl/SDL_config_macosx.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_macosx.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_macosx.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,132 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_macosx_h +#define _SDL_config_macosx_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +#define SDL_HAS_64BIT_TYPE 1 + +/* Useful headers */ +/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */ +#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) ) +#define HAVE_ALLOCA_H 1 +#endif +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_UNSETENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE_STRDUP 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_SIGACTION 1 +#define HAVE_SETJMP 1 +#define HAVE_NANOSLEEP 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_COREAUDIO 1 +#define SDL_AUDIO_DRIVER_SNDMGR 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#define SDL_CDROM_MACOSX 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_IOKIT 1 + +/* Enable various shared object loading systems */ +#ifdef __ppc__ +/* For Mac OS X 10.2 compatibility */ +#define SDL_LOADSO_DLCOMPAT 1 +#else +#define SDL_LOADSO_DLOPEN 1 +#endif + +/* Enable various threading systems */ +#define SDL_THREAD_PTHREAD 1 +#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1 + +/* Enable various timer systems */ +#define SDL_TIMER_UNIX 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_DUMMY 1 +#if TARGET_API_MAC_CARBON +#define SDL_VIDEO_DRIVER_TOOLBOX 1 +#else +#define SDL_VIDEO_DRIVER_QUARTZ 1 +#endif + +/* Enable OpenGL support */ +#define SDL_VIDEO_OPENGL 1 + +/* Enable assembly routines */ +#define SDL_ASSEMBLY_ROUTINES 1 +#ifdef __ppc__ +#define SDL_ALTIVEC_BLITTERS 1 +#endif + +#endif /* _SDL_config_macosx_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_minimal.h ./win32/dependencies/sdl/SDL_config_minimal.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_minimal.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_minimal.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,62 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_minimal_h +#define _SDL_config_minimal_h + +#include "SDL_platform.h" + +/* This is the minimal configuration that can be used to build SDL */ + +#include + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned int size_t; +typedef unsigned long uintptr_t; + +/* Enable the dummy audio driver (src/audio/dummy/\*.c) */ +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */ +#define SDL_CDROM_DISABLED 1 + +/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */ +#define SDL_JOYSTICK_DISABLED 1 + +/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */ +#define SDL_LOADSO_DISABLED 1 + +/* Enable the stub thread support (src/thread/generic/\*.c) */ +#define SDL_THREADS_DISABLED 1 + +/* Enable the stub timer support (src/timer/dummy/\*.c) */ +#define SDL_TIMERS_DISABLED 1 + +/* Enable the dummy video driver (src/video/dummy/\*.c) */ +#define SDL_VIDEO_DRIVER_DUMMY 1 + +#endif /* _SDL_config_minimal_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_os2.h ./win32/dependencies/sdl/SDL_config_os2.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_os2.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_os2.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,141 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_os2_h +#define _SDL_config_os2_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef unsigned int size_t; +typedef unsigned long uintptr_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; + +#define SDL_HAS_64BIT_TYPE 1 + +/* Use Watcom's LIBC */ +#define HAVE_LIBC 1 + +/* Useful headers */ +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_MALLOC_H 1 +#define HAVE_MEMORY_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRINGS_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_UNSETENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE_STRDUP 1 +#define HAVE__STRREV 1 +#define HAVE__STRUPR 1 +#define HAVE__STRLWR 1 +#define HAVE_INDEX 1 +#define HAVE_RINDEX 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_ITOA 1 +#define HAVE__LTOA 1 +#define HAVE__UITOA 1 +#define HAVE__ULTOA 1 +#define HAVE_STRTOL 1 +#define HAVE__I64TOA 1 +#define HAVE__UI64TOA 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRICMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_SETJMP 1 +#define HAVE_CLOCK_GETTIME 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_DART 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#define SDL_CDROM_OS2 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_OS2 1 + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_OS2 1 + +/* Enable various threading systems */ +#define SDL_THREAD_OS2 1 + +/* Enable various timer systems */ +#define SDL_TIMER_OS2 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_DUMMY 1 +#define SDL_VIDEO_DRIVER_OS2FS 1 + +/* Enable OpenGL support */ +/* Nothing here yet for OS/2... :( */ + +/* Enable assembly routines where available */ +#define SDL_ASSEMBLY_ROUTINES 1 + +#endif /* _SDL_config_os2_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_win32.h ./win32/dependencies/sdl/SDL_config_win32.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_config_win32.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_config_win32.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,171 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_win32_h +#define _SDL_config_win32_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +#ifdef _MSC_VER +typedef signed __int8 int8_t; +typedef unsigned __int8 uint8_t; +typedef signed __int16 int16_t; +typedef unsigned __int16 uint16_t; +typedef signed __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +#ifndef _UINTPTR_T_DEFINED +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned int uintptr_t; +#endif +#define _UINTPTR_T_DEFINED +#endif +#else +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef unsigned int size_t; +#endif +typedef unsigned int uintptr_t; +#endif /* _MSC_VER */ +#define SDL_HAS_64BIT_TYPE 1 + +/* Enabled for SDL 1.2 (binary compatibility) */ +#define HAVE_LIBC 1 +#ifdef HAVE_LIBC +/* Useful headers */ +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#ifndef _WIN32_WCE +#define HAVE_SIGNAL_H 1 +#endif + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE__STRREV 1 +#define HAVE__STRUPR 1 +#define HAVE__STRLWR 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_ITOA 1 +#define HAVE__LTOA 1 +#define HAVE__ULTOA 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE__STRICMP 1 +#define HAVE__STRNICMP 1 +#define HAVE_SSCANF 1 +#else +#define HAVE_STDARG_H 1 +#define HAVE_STDDEF_H 1 +#endif + +/* Enable various audio drivers */ +#ifndef _WIN32_WCE +#define SDL_AUDIO_DRIVER_DSOUND 1 +#endif +#define SDL_AUDIO_DRIVER_WAVEOUT 1 +#define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable various cdrom drivers */ +#ifdef _WIN32_WCE +#define SDL_CDROM_DISABLED 1 +#else +#define SDL_CDROM_WIN32 1 +#endif + +/* Enable various input drivers */ +#ifdef _WIN32_WCE +#define SDL_JOYSTICK_DISABLED 1 +#else +#define SDL_JOYSTICK_WINMM 1 +#endif + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_WIN32 1 + +/* Enable various threading systems */ +#define SDL_THREAD_WIN32 1 + +/* Enable various timer systems */ +#ifdef _WIN32_WCE +#define SDL_TIMER_WINCE 1 +#else +#define SDL_TIMER_WIN32 1 +#endif + +/* Enable various video drivers */ +#ifdef _WIN32_WCE +#define SDL_VIDEO_DRIVER_GAPI 1 +#endif +#ifndef _WIN32_WCE +#define SDL_VIDEO_DRIVER_DDRAW 1 +#endif +#define SDL_VIDEO_DRIVER_DUMMY 1 +#define SDL_VIDEO_DRIVER_WINDIB 1 + +/* Enable OpenGL support */ +#ifndef _WIN32_WCE +#define SDL_VIDEO_OPENGL 1 +#define SDL_VIDEO_OPENGL_WGL 1 +#endif + +/* Enable assembly routines (Win64 doesn't have inline asm) */ +#ifndef _WIN64 +#define SDL_ASSEMBLY_ROUTINES 1 +#endif + +#endif /* _SDL_config_win32_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_copying.h ./win32/dependencies/sdl/SDL_copying.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_copying.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_copying.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,22 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_cpuinfo.h ./win32/dependencies/sdl/SDL_cpuinfo.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_cpuinfo.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_cpuinfo.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,75 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* CPU feature detection for SDL */ + +#ifndef _SDL_cpuinfo_h +#define _SDL_cpuinfo_h + +#include "SDL_stdinc.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* This function returns true if the CPU has the RDTSC instruction + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void); + +/* This function returns true if the CPU has MMX features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void); + +/* This function returns true if the CPU has MMX Ext. features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasMMXExt(void); + +/* This function returns true if the CPU has 3DNow features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void); + +/* This function returns true if the CPU has 3DNow! Ext. features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNowExt(void); + +/* This function returns true if the CPU has SSE features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void); + +/* This function returns true if the CPU has SSE2 features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void); + +/* This function returns true if the CPU has AltiVec features + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_cpuinfo_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_endian.h ./win32/dependencies/sdl/SDL_endian.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_endian.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_endian.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,192 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Functions for reading and writing endian-specific values */ + +#ifndef _SDL_endian_h +#define _SDL_endian_h + +#include "SDL_stdinc.h" + +/* The two types of endianness */ +#define SDL_LIL_ENDIAN 1234 +#define SDL_BIG_ENDIAN 4321 + +#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */ +#if defined(__hppa__) || \ + defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ + (defined(__MIPS__) && defined(__MISPEB__)) || \ + defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ + defined(__sparc__) +#define SDL_BYTEORDER SDL_BIG_ENDIAN +#else +#define SDL_BYTEORDER SDL_LIL_ENDIAN +#endif +#endif /* !SDL_BYTEORDER */ + + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Use inline functions for compilers that support them, and static + functions for those that do not. Because these functions become + static for compilers that do not support inline functions, this + header should only be included in files that actually use them. +*/ +#if defined(__GNUC__) && defined(__i386__) && \ + !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */) +static __inline__ Uint16 SDL_Swap16(Uint16 x) +{ + __asm__("xchgb %b0,%h0" : "=q" (x) : "0" (x)); + return x; +} +#elif defined(__GNUC__) && defined(__x86_64__) +static __inline__ Uint16 SDL_Swap16(Uint16 x) +{ + __asm__("xchgb %b0,%h0" : "=Q" (x) : "0" (x)); + return x; +} +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) +static __inline__ Uint16 SDL_Swap16(Uint16 x) +{ + Uint16 result; + + __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x)); + return result; +} +#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) +static __inline__ Uint16 SDL_Swap16(Uint16 x) +{ + __asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc"); + return x; +} +#else +static __inline__ Uint16 SDL_Swap16(Uint16 x) { + return((x<<8)|(x>>8)); +} +#endif + +#if defined(__GNUC__) && defined(__i386__) +static __inline__ Uint32 SDL_Swap32(Uint32 x) +{ + __asm__("bswap %0" : "=r" (x) : "0" (x)); + return x; +} +#elif defined(__GNUC__) && defined(__x86_64__) +static __inline__ Uint32 SDL_Swap32(Uint32 x) +{ + __asm__("bswapl %0" : "=r" (x) : "0" (x)); + return x; +} +#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) +static __inline__ Uint32 SDL_Swap32(Uint32 x) +{ + Uint32 result; + + __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x)); + __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x)); + __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x)); + return result; +} +#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) +static __inline__ Uint32 SDL_Swap32(Uint32 x) +{ + __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc"); + return x; +} +#else +static __inline__ Uint32 SDL_Swap32(Uint32 x) { + return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)); +} +#endif + +#ifdef SDL_HAS_64BIT_TYPE +#if defined(__GNUC__) && defined(__i386__) +static __inline__ Uint64 SDL_Swap64(Uint64 x) +{ + union { + struct { Uint32 a,b; } s; + Uint64 u; + } v; + v.u = x; + __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1" + : "=r" (v.s.a), "=r" (v.s.b) + : "0" (v.s.a), "1" (v.s.b)); + return v.u; +} +#elif defined(__GNUC__) && defined(__x86_64__) +static __inline__ Uint64 SDL_Swap64(Uint64 x) +{ + __asm__("bswapq %0" : "=r" (x) : "0" (x)); + return x; +} +#else +static __inline__ Uint64 SDL_Swap64(Uint64 x) +{ + Uint32 hi, lo; + + /* Separate into high and low 32-bit values and swap them */ + lo = (Uint32)(x&0xFFFFFFFF); + x >>= 32; + hi = (Uint32)(x&0xFFFFFFFF); + x = SDL_Swap32(lo); + x <<= 32; + x |= SDL_Swap32(hi); + return(x); +} +#endif +#else +/* This is mainly to keep compilers from complaining in SDL code. + If there is no real 64-bit datatype, then compilers will complain about + the fake 64-bit datatype that SDL provides when it compiles user code. +*/ +#define SDL_Swap64(X) (X) +#endif /* SDL_HAS_64BIT_TYPE */ + + +/* Byteswap item from the specified endianness to the native endianness */ +#if SDL_BYTEORDER == SDL_LIL_ENDIAN +#define SDL_SwapLE16(X) (X) +#define SDL_SwapLE32(X) (X) +#define SDL_SwapLE64(X) (X) +#define SDL_SwapBE16(X) SDL_Swap16(X) +#define SDL_SwapBE32(X) SDL_Swap32(X) +#define SDL_SwapBE64(X) SDL_Swap64(X) +#else +#define SDL_SwapLE16(X) SDL_Swap16(X) +#define SDL_SwapLE32(X) SDL_Swap32(X) +#define SDL_SwapLE64(X) SDL_Swap64(X) +#define SDL_SwapBE16(X) (X) +#define SDL_SwapBE32(X) (X) +#define SDL_SwapBE64(X) (X) +#endif + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_endian_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_error.h ./win32/dependencies/sdl/SDL_error.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_error.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_error.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,61 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Simple error message routines for SDL */ + +#ifndef _SDL_error_h +#define _SDL_error_h + +#include "SDL_stdinc.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Public functions */ +extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); +extern DECLSPEC char * SDLCALL SDL_GetError(void); +extern DECLSPEC void SDLCALL SDL_ClearError(void); + +/* Private error message function - used internally */ +#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM) +#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED) +typedef enum { + SDL_ENOMEM, + SDL_EFREAD, + SDL_EFWRITE, + SDL_EFSEEK, + SDL_UNSUPPORTED, + SDL_LASTERROR +} SDL_errorcode; +extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_error_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_events.h ./win32/dependencies/sdl/SDL_events.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_events.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_events.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,337 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL event handling */ + +#ifndef _SDL_events_h +#define _SDL_events_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_active.h" +#include "SDL_keyboard.h" +#include "SDL_mouse.h" +#include "SDL_joystick.h" +#include "SDL_quit.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* General keyboard/mouse state definitions */ +#define SDL_RELEASED 0 +#define SDL_PRESSED 1 + +/* Event enumerations */ +typedef enum { + SDL_NOEVENT = 0, /* Unused (do not remove) */ + SDL_ACTIVEEVENT, /* Application loses/gains visibility */ + SDL_KEYDOWN, /* Keys pressed */ + SDL_KEYUP, /* Keys released */ + SDL_MOUSEMOTION, /* Mouse moved */ + SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */ + SDL_MOUSEBUTTONUP, /* Mouse button released */ + SDL_JOYAXISMOTION, /* Joystick axis motion */ + SDL_JOYBALLMOTION, /* Joystick trackball motion */ + SDL_JOYHATMOTION, /* Joystick hat position change */ + SDL_JOYBUTTONDOWN, /* Joystick button pressed */ + SDL_JOYBUTTONUP, /* Joystick button released */ + SDL_QUIT, /* User-requested quit */ + SDL_SYSWMEVENT, /* System specific event */ + SDL_EVENT_RESERVEDA, /* Reserved for future use.. */ + SDL_EVENT_RESERVEDB, /* Reserved for future use.. */ + SDL_VIDEORESIZE, /* User resized video mode */ + SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */ + SDL_EVENT_RESERVED2, /* Reserved for future use.. */ + SDL_EVENT_RESERVED3, /* Reserved for future use.. */ + SDL_EVENT_RESERVED4, /* Reserved for future use.. */ + SDL_EVENT_RESERVED5, /* Reserved for future use.. */ + SDL_EVENT_RESERVED6, /* Reserved for future use.. */ + SDL_EVENT_RESERVED7, /* Reserved for future use.. */ + /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ + SDL_USEREVENT = 24, + /* This last event is only for bounding internal arrays + It is the number of bits in the event mask datatype -- Uint32 + */ + SDL_NUMEVENTS = 32 +} SDL_EventType; + +/* Predefined event masks */ +#define SDL_EVENTMASK(X) (1<<(X)) +typedef enum { + SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT), + SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN), + SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP), + SDL_KEYEVENTMASK = SDL_EVENTMASK(SDL_KEYDOWN)| + SDL_EVENTMASK(SDL_KEYUP), + SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION), + SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN), + SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP), + SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION)| + SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)| + SDL_EVENTMASK(SDL_MOUSEBUTTONUP), + SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION), + SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION), + SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION), + SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN), + SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP), + SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION)| + SDL_EVENTMASK(SDL_JOYBALLMOTION)| + SDL_EVENTMASK(SDL_JOYHATMOTION)| + SDL_EVENTMASK(SDL_JOYBUTTONDOWN)| + SDL_EVENTMASK(SDL_JOYBUTTONUP), + SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE), + SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE), + SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT), + SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT) +} SDL_EventMask ; +#define SDL_ALLEVENTS 0xFFFFFFFF + +/* Application visibility event structure */ +typedef struct SDL_ActiveEvent { + Uint8 type; /* SDL_ACTIVEEVENT */ + Uint8 gain; /* Whether given states were gained or lost (1/0) */ + Uint8 state; /* A mask of the focus states */ +} SDL_ActiveEvent; + +/* Keyboard event structure */ +typedef struct SDL_KeyboardEvent { + Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */ + Uint8 which; /* The keyboard device index */ + Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ + SDL_keysym keysym; +} SDL_KeyboardEvent; + +/* Mouse motion event structure */ +typedef struct SDL_MouseMotionEvent { + Uint8 type; /* SDL_MOUSEMOTION */ + Uint8 which; /* The mouse device index */ + Uint8 state; /* The current button state */ + Uint16 x, y; /* The X/Y coordinates of the mouse */ + Sint16 xrel; /* The relative motion in the X direction */ + Sint16 yrel; /* The relative motion in the Y direction */ +} SDL_MouseMotionEvent; + +/* Mouse button event structure */ +typedef struct SDL_MouseButtonEvent { + Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ + Uint8 which; /* The mouse device index */ + Uint8 button; /* The mouse button index */ + Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ + Uint16 x, y; /* The X/Y coordinates of the mouse at press time */ +} SDL_MouseButtonEvent; + +/* Joystick axis motion event structure */ +typedef struct SDL_JoyAxisEvent { + Uint8 type; /* SDL_JOYAXISMOTION */ + Uint8 which; /* The joystick device index */ + Uint8 axis; /* The joystick axis index */ + Sint16 value; /* The axis value (range: -32768 to 32767) */ +} SDL_JoyAxisEvent; + +/* Joystick trackball motion event structure */ +typedef struct SDL_JoyBallEvent { + Uint8 type; /* SDL_JOYBALLMOTION */ + Uint8 which; /* The joystick device index */ + Uint8 ball; /* The joystick trackball index */ + Sint16 xrel; /* The relative motion in the X direction */ + Sint16 yrel; /* The relative motion in the Y direction */ +} SDL_JoyBallEvent; + +/* Joystick hat position change event structure */ +typedef struct SDL_JoyHatEvent { + Uint8 type; /* SDL_JOYHATMOTION */ + Uint8 which; /* The joystick device index */ + Uint8 hat; /* The joystick hat index */ + Uint8 value; /* The hat position value: + SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP + SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT + SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN + Note that zero means the POV is centered. + */ +} SDL_JoyHatEvent; + +/* Joystick button event structure */ +typedef struct SDL_JoyButtonEvent { + Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ + Uint8 which; /* The joystick device index */ + Uint8 button; /* The joystick button index */ + Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ +} SDL_JoyButtonEvent; + +/* The "window resized" event + When you get this event, you are responsible for setting a new video + mode with the new width and height. + */ +typedef struct SDL_ResizeEvent { + Uint8 type; /* SDL_VIDEORESIZE */ + int w; /* New width */ + int h; /* New height */ +} SDL_ResizeEvent; + +/* The "screen redraw" event */ +typedef struct SDL_ExposeEvent { + Uint8 type; /* SDL_VIDEOEXPOSE */ +} SDL_ExposeEvent; + +/* The "quit requested" event */ +typedef struct SDL_QuitEvent { + Uint8 type; /* SDL_QUIT */ +} SDL_QuitEvent; + +/* A user-defined event type */ +typedef struct SDL_UserEvent { + Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ + int code; /* User defined event code */ + void *data1; /* User defined data pointer */ + void *data2; /* User defined data pointer */ +} SDL_UserEvent; + +/* If you want to use this event, you should include SDL_syswm.h */ +struct SDL_SysWMmsg; +typedef struct SDL_SysWMmsg SDL_SysWMmsg; +typedef struct SDL_SysWMEvent { + Uint8 type; + SDL_SysWMmsg *msg; +} SDL_SysWMEvent; + +/* General event structure */ +typedef union SDL_Event { + Uint8 type; + SDL_ActiveEvent active; + SDL_KeyboardEvent key; + SDL_MouseMotionEvent motion; + SDL_MouseButtonEvent button; + SDL_JoyAxisEvent jaxis; + SDL_JoyBallEvent jball; + SDL_JoyHatEvent jhat; + SDL_JoyButtonEvent jbutton; + SDL_ResizeEvent resize; + SDL_ExposeEvent expose; + SDL_QuitEvent quit; + SDL_UserEvent user; + SDL_SysWMEvent syswm; +} SDL_Event; + + +/* Function prototypes */ + +/* Pumps the event loop, gathering events from the input devices. + This function updates the event queue and internal input device state. + This should only be run in the thread that sets the video mode. +*/ +extern DECLSPEC void SDLCALL SDL_PumpEvents(void); + +/* Checks the event queue for messages and optionally returns them. + If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to + the back of the event queue. + If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front + of the event queue, matching 'mask', will be returned and will not + be removed from the queue. + If 'action' is SDL_GETEVENT, up to 'numevents' events at the front + of the event queue, matching 'mask', will be returned and will be + removed from the queue. + This function returns the number of events actually stored, or -1 + if there was an error. This function is thread-safe. +*/ +typedef enum { + SDL_ADDEVENT, + SDL_PEEKEVENT, + SDL_GETEVENT +} SDL_eventaction; +/* */ +extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, + SDL_eventaction action, Uint32 mask); + +/* Polls for currently pending events, and returns 1 if there are any pending + events, or 0 if there are none available. If 'event' is not NULL, the next + event is removed from the queue and stored in that area. + */ +extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event); + +/* Waits indefinitely for the next available event, returning 1, or 0 if there + was an error while waiting for events. If 'event' is not NULL, the next + event is removed from the queue and stored in that area. + */ +extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event *event); + +/* Add an event to the event queue. + This function returns 0 on success, or -1 if the event queue was full + or there was some other error. + */ +extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event); + +/* + This function sets up a filter to process all events before they + change internal state and are posted to the internal event queue. + + The filter is protypted as: +*/ +typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event); +/* + If the filter returns 1, then the event will be added to the internal queue. + If it returns 0, then the event will be dropped from the queue, but the + internal state will still be updated. This allows selective filtering of + dynamically arriving events. + + WARNING: Be very careful of what you do in the event filter function, as + it may run in a different thread! + + There is one caveat when dealing with the SDL_QUITEVENT event type. The + event filter is only called when the window manager desires to close the + application window. If the event filter returns 1, then the window will + be closed, otherwise the window will remain open if possible. + If the quit event is generated by an interrupt signal, it will bypass the + internal queue and be delivered to the application at the next event poll. +*/ +extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter); + +/* + Return the current event filter - can be used to "chain" filters. + If there is no event filter set, this function returns NULL. +*/ +extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void); + +/* + This function allows you to set the state of processing certain events. + If 'state' is set to SDL_IGNORE, that event will be automatically dropped + from the event queue and will not event be filtered. + If 'state' is set to SDL_ENABLE, that event will be processed normally. + If 'state' is set to SDL_QUERY, SDL_EventState() will return the + current processing state of the specified event. +*/ +#define SDL_QUERY -1 +#define SDL_IGNORE 0 +#define SDL_DISABLE 0 +#define SDL_ENABLE 1 +extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint8 type, int state); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_events_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_getenv.h ./win32/dependencies/sdl/SDL_getenv.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_getenv.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_getenv.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,24 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* DEPRECATED */ +#include "SDL_stdinc.h" diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_joystick.h ./win32/dependencies/sdl/SDL_joystick.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_joystick.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_joystick.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,167 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL joystick event handling */ + +#ifndef _SDL_joystick_h +#define _SDL_joystick_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* In order to use these functions, SDL_Init() must have been called + with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system + for joysticks, and load appropriate drivers. +*/ + +/* The joystick structure used to identify an SDL joystick */ +struct _SDL_Joystick; +typedef struct _SDL_Joystick SDL_Joystick; + + +/* Function prototypes */ +/* + * Count the number of joysticks attached to the system + */ +extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); + +/* + * Get the implementation dependent name of a joystick. + * This can be called before any joysticks are opened. + * If no name can be found, this function returns NULL. + */ +extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index); + +/* + * Open a joystick for use - the index passed as an argument refers to + * the N'th joystick on the system. This index is the value which will + * identify this joystick in future joystick events. + * + * This function returns a joystick identifier, or NULL if an error occurred. + */ +extern DECLSPEC SDL_Joystick * SDLCALL SDL_JoystickOpen(int device_index); + +/* + * Returns 1 if the joystick has been opened, or 0 if it has not. + */ +extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index); + +/* + * Get the device index of an opened joystick. + */ +extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick); + +/* + * Get the number of general axis controls on a joystick + */ +extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick); + +/* + * Get the number of trackballs on a joystick + * Joystick trackballs have only relative motion events associated + * with them and their state cannot be polled. + */ +extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick); + +/* + * Get the number of POV hats on a joystick + */ +extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick); + +/* + * Get the number of buttons on a joystick + */ +extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick); + +/* + * Update the current state of the open joysticks. + * This is called automatically by the event loop if any joystick + * events are enabled. + */ +extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); + +/* + * Enable/disable joystick event polling. + * If joystick events are disabled, you must call SDL_JoystickUpdate() + * yourself and check the state of the joystick when you want joystick + * information. + * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE. + */ +extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); + +/* + * Get the current state of an axis control on a joystick + * The state is a value ranging from -32768 to 32767. + * The axis indices start at index 0. + */ +extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis); + +/* + * Get the current state of a POV hat on a joystick + * The return value is one of the following positions: + */ +#define SDL_HAT_CENTERED 0x00 +#define SDL_HAT_UP 0x01 +#define SDL_HAT_RIGHT 0x02 +#define SDL_HAT_DOWN 0x04 +#define SDL_HAT_LEFT 0x08 +#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) +#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) +#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) +#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) +/* + * The hat indices start at index 0. + */ +extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat); + +/* + * Get the ball axis change since the last poll + * This returns 0, or -1 if you passed it invalid parameters. + * The ball indices start at index 0. + */ +extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); + +/* + * Get the current state of a button on a joystick + * The button indices start at index 0. + */ +extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button); + +/* + * Close a joystick previously opened with SDL_JoystickOpen() + */ +extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_joystick_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_keyboard.h ./win32/dependencies/sdl/SDL_keyboard.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_keyboard.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_keyboard.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,121 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL keyboard event handling */ + +#ifndef _SDL_keyboard_h +#define _SDL_keyboard_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_keysym.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Keysym structure + - The scancode is hardware dependent, and should not be used by general + applications. If no hardware scancode is available, it will be 0. + + - The 'unicode' translated character is only available when character + translation is enabled by the SDL_EnableUNICODE() API. If non-zero, + this is a UNICODE character corresponding to the keypress. If the + high 9 bits of the character are 0, then this maps to the equivalent + ASCII character: + char ch; + if ( (keysym.unicode & 0xFF80) == 0 ) { + ch = keysym.unicode & 0x7F; + } else { + An international character.. + } + */ +typedef struct SDL_keysym { + Uint8 scancode; /* hardware specific scancode */ + SDLKey sym; /* SDL virtual keysym */ + SDLMod mod; /* current key modifiers */ + Uint16 unicode; /* translated character */ +} SDL_keysym; + +/* This is the mask which refers to all hotkey bindings */ +#define SDL_ALL_HOTKEYS 0xFFFFFFFF + +/* Function prototypes */ +/* + * Enable/Disable UNICODE translation of keyboard input. + * This translation has some overhead, so translation defaults off. + * If 'enable' is 1, translation is enabled. + * If 'enable' is 0, translation is disabled. + * If 'enable' is -1, the translation state is not changed. + * It returns the previous state of keyboard translation. + */ +extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); + +/* + * Enable/Disable keyboard repeat. Keyboard repeat defaults to off. + * 'delay' is the initial delay in ms between the time when a key is + * pressed, and keyboard repeat begins. + * 'interval' is the time in ms between keyboard repeat events. + */ +#define SDL_DEFAULT_REPEAT_DELAY 500 +#define SDL_DEFAULT_REPEAT_INTERVAL 30 +/* + * If 'delay' is set to 0, keyboard repeat is disabled. + */ +extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); +extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); + +/* + * Get a snapshot of the current state of the keyboard. + * Returns an array of keystates, indexed by the SDLK_* syms. + * Used: + * Uint8 *keystate = SDL_GetKeyState(NULL); + * if ( keystate[SDLK_RETURN] ) ... is pressed. + */ +extern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys); + +/* + * Get the current key modifier state + */ +extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void); + +/* + * Set the current key modifier state + * This does not change the keyboard state, only the key modifier flags. + */ +extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); + +/* + * Get the name of an SDL virtual keysym + */ +extern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_keyboard_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_keysym.h ./win32/dependencies/sdl/SDL_keysym.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_keysym.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_keysym.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,311 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_keysym_h +#define _SDL_keysym_h + +/* What we really want is a mapping of every raw key on the keyboard. + To support international keyboards, we use the range 0xA1 - 0xFF + as international virtual keycodes. We'll follow in the footsteps of X11... + The names of the keys + */ + +typedef enum { + /* The keyboard syms have been cleverly chosen to map to ASCII */ + SDLK_UNKNOWN = 0, + SDLK_FIRST = 0, + SDLK_BACKSPACE = 8, + SDLK_TAB = 9, + SDLK_CLEAR = 12, + SDLK_RETURN = 13, + SDLK_PAUSE = 19, + SDLK_ESCAPE = 27, + SDLK_SPACE = 32, + SDLK_EXCLAIM = 33, + SDLK_QUOTEDBL = 34, + SDLK_HASH = 35, + SDLK_DOLLAR = 36, + SDLK_AMPERSAND = 38, + SDLK_QUOTE = 39, + SDLK_LEFTPAREN = 40, + SDLK_RIGHTPAREN = 41, + SDLK_ASTERISK = 42, + SDLK_PLUS = 43, + SDLK_COMMA = 44, + SDLK_MINUS = 45, + SDLK_PERIOD = 46, + SDLK_SLASH = 47, + SDLK_0 = 48, + SDLK_1 = 49, + SDLK_2 = 50, + SDLK_3 = 51, + SDLK_4 = 52, + SDLK_5 = 53, + SDLK_6 = 54, + SDLK_7 = 55, + SDLK_8 = 56, + SDLK_9 = 57, + SDLK_COLON = 58, + SDLK_SEMICOLON = 59, + SDLK_LESS = 60, + SDLK_EQUALS = 61, + SDLK_GREATER = 62, + SDLK_QUESTION = 63, + SDLK_AT = 64, + /* + Skip uppercase letters + */ + SDLK_LEFTBRACKET = 91, + SDLK_BACKSLASH = 92, + SDLK_RIGHTBRACKET = 93, + SDLK_CARET = 94, + SDLK_UNDERSCORE = 95, + SDLK_BACKQUOTE = 96, + SDLK_a = 97, + SDLK_b = 98, + SDLK_c = 99, + SDLK_d = 100, + SDLK_e = 101, + SDLK_f = 102, + SDLK_g = 103, + SDLK_h = 104, + SDLK_i = 105, + SDLK_j = 106, + SDLK_k = 107, + SDLK_l = 108, + SDLK_m = 109, + SDLK_n = 110, + SDLK_o = 111, + SDLK_p = 112, + SDLK_q = 113, + SDLK_r = 114, + SDLK_s = 115, + SDLK_t = 116, + SDLK_u = 117, + SDLK_v = 118, + SDLK_w = 119, + SDLK_x = 120, + SDLK_y = 121, + SDLK_z = 122, + SDLK_DELETE = 127, + /* End of ASCII mapped keysyms */ + + /* International keyboard syms */ + SDLK_WORLD_0 = 160, /* 0xA0 */ + SDLK_WORLD_1 = 161, + SDLK_WORLD_2 = 162, + SDLK_WORLD_3 = 163, + SDLK_WORLD_4 = 164, + SDLK_WORLD_5 = 165, + SDLK_WORLD_6 = 166, + SDLK_WORLD_7 = 167, + SDLK_WORLD_8 = 168, + SDLK_WORLD_9 = 169, + SDLK_WORLD_10 = 170, + SDLK_WORLD_11 = 171, + SDLK_WORLD_12 = 172, + SDLK_WORLD_13 = 173, + SDLK_WORLD_14 = 174, + SDLK_WORLD_15 = 175, + SDLK_WORLD_16 = 176, + SDLK_WORLD_17 = 177, + SDLK_WORLD_18 = 178, + SDLK_WORLD_19 = 179, + SDLK_WORLD_20 = 180, + SDLK_WORLD_21 = 181, + SDLK_WORLD_22 = 182, + SDLK_WORLD_23 = 183, + SDLK_WORLD_24 = 184, + SDLK_WORLD_25 = 185, + SDLK_WORLD_26 = 186, + SDLK_WORLD_27 = 187, + SDLK_WORLD_28 = 188, + SDLK_WORLD_29 = 189, + SDLK_WORLD_30 = 190, + SDLK_WORLD_31 = 191, + SDLK_WORLD_32 = 192, + SDLK_WORLD_33 = 193, + SDLK_WORLD_34 = 194, + SDLK_WORLD_35 = 195, + SDLK_WORLD_36 = 196, + SDLK_WORLD_37 = 197, + SDLK_WORLD_38 = 198, + SDLK_WORLD_39 = 199, + SDLK_WORLD_40 = 200, + SDLK_WORLD_41 = 201, + SDLK_WORLD_42 = 202, + SDLK_WORLD_43 = 203, + SDLK_WORLD_44 = 204, + SDLK_WORLD_45 = 205, + SDLK_WORLD_46 = 206, + SDLK_WORLD_47 = 207, + SDLK_WORLD_48 = 208, + SDLK_WORLD_49 = 209, + SDLK_WORLD_50 = 210, + SDLK_WORLD_51 = 211, + SDLK_WORLD_52 = 212, + SDLK_WORLD_53 = 213, + SDLK_WORLD_54 = 214, + SDLK_WORLD_55 = 215, + SDLK_WORLD_56 = 216, + SDLK_WORLD_57 = 217, + SDLK_WORLD_58 = 218, + SDLK_WORLD_59 = 219, + SDLK_WORLD_60 = 220, + SDLK_WORLD_61 = 221, + SDLK_WORLD_62 = 222, + SDLK_WORLD_63 = 223, + SDLK_WORLD_64 = 224, + SDLK_WORLD_65 = 225, + SDLK_WORLD_66 = 226, + SDLK_WORLD_67 = 227, + SDLK_WORLD_68 = 228, + SDLK_WORLD_69 = 229, + SDLK_WORLD_70 = 230, + SDLK_WORLD_71 = 231, + SDLK_WORLD_72 = 232, + SDLK_WORLD_73 = 233, + SDLK_WORLD_74 = 234, + SDLK_WORLD_75 = 235, + SDLK_WORLD_76 = 236, + SDLK_WORLD_77 = 237, + SDLK_WORLD_78 = 238, + SDLK_WORLD_79 = 239, + SDLK_WORLD_80 = 240, + SDLK_WORLD_81 = 241, + SDLK_WORLD_82 = 242, + SDLK_WORLD_83 = 243, + SDLK_WORLD_84 = 244, + SDLK_WORLD_85 = 245, + SDLK_WORLD_86 = 246, + SDLK_WORLD_87 = 247, + SDLK_WORLD_88 = 248, + SDLK_WORLD_89 = 249, + SDLK_WORLD_90 = 250, + SDLK_WORLD_91 = 251, + SDLK_WORLD_92 = 252, + SDLK_WORLD_93 = 253, + SDLK_WORLD_94 = 254, + SDLK_WORLD_95 = 255, /* 0xFF */ + + /* Numeric keypad */ + SDLK_KP0 = 256, + SDLK_KP1 = 257, + SDLK_KP2 = 258, + SDLK_KP3 = 259, + SDLK_KP4 = 260, + SDLK_KP5 = 261, + SDLK_KP6 = 262, + SDLK_KP7 = 263, + SDLK_KP8 = 264, + SDLK_KP9 = 265, + SDLK_KP_PERIOD = 266, + SDLK_KP_DIVIDE = 267, + SDLK_KP_MULTIPLY = 268, + SDLK_KP_MINUS = 269, + SDLK_KP_PLUS = 270, + SDLK_KP_ENTER = 271, + SDLK_KP_EQUALS = 272, + + /* Arrows + Home/End pad */ + SDLK_UP = 273, + SDLK_DOWN = 274, + SDLK_RIGHT = 275, + SDLK_LEFT = 276, + SDLK_INSERT = 277, + SDLK_HOME = 278, + SDLK_END = 279, + SDLK_PAGEUP = 280, + SDLK_PAGEDOWN = 281, + + /* Function keys */ + SDLK_F1 = 282, + SDLK_F2 = 283, + SDLK_F3 = 284, + SDLK_F4 = 285, + SDLK_F5 = 286, + SDLK_F6 = 287, + SDLK_F7 = 288, + SDLK_F8 = 289, + SDLK_F9 = 290, + SDLK_F10 = 291, + SDLK_F11 = 292, + SDLK_F12 = 293, + SDLK_F13 = 294, + SDLK_F14 = 295, + SDLK_F15 = 296, + + /* Key state modifier keys */ + SDLK_NUMLOCK = 300, + SDLK_CAPSLOCK = 301, + SDLK_SCROLLOCK = 302, + SDLK_RSHIFT = 303, + SDLK_LSHIFT = 304, + SDLK_RCTRL = 305, + SDLK_LCTRL = 306, + SDLK_RALT = 307, + SDLK_LALT = 308, + SDLK_RMETA = 309, + SDLK_LMETA = 310, + SDLK_LSUPER = 311, /* Left "Windows" key */ + SDLK_RSUPER = 312, /* Right "Windows" key */ + SDLK_MODE = 313, /* "Alt Gr" key */ + SDLK_COMPOSE = 314, /* Multi-key compose key */ + + /* Miscellaneous function keys */ + SDLK_HELP = 315, + SDLK_PRINT = 316, + SDLK_SYSREQ = 317, + SDLK_BREAK = 318, + SDLK_MENU = 319, + SDLK_POWER = 320, /* Power Macintosh power key */ + SDLK_EURO = 321, /* Some european keyboards */ + SDLK_UNDO = 322, /* Atari keyboard has Undo */ + + /* Add any other keys here */ + + SDLK_LAST +} SDLKey; + +/* Enumeration of valid key mods (possibly OR'd together) */ +typedef enum { + KMOD_NONE = 0x0000, + KMOD_LSHIFT= 0x0001, + KMOD_RSHIFT= 0x0002, + KMOD_LCTRL = 0x0040, + KMOD_RCTRL = 0x0080, + KMOD_LALT = 0x0100, + KMOD_RALT = 0x0200, + KMOD_LMETA = 0x0400, + KMOD_RMETA = 0x0800, + KMOD_NUM = 0x1000, + KMOD_CAPS = 0x2000, + KMOD_MODE = 0x4000, + KMOD_RESERVED = 0x8000 +} SDLMod; + +#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL) +#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT) +#define KMOD_ALT (KMOD_LALT|KMOD_RALT) +#define KMOD_META (KMOD_LMETA|KMOD_RMETA) + +#endif /* _SDL_keysym_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_loadso.h ./win32/dependencies/sdl/SDL_loadso.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_loadso.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_loadso.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,74 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* System dependent library loading routines */ + +/* Some things to keep in mind: + - These functions only work on C function names. Other languages may + have name mangling and intrinsic language support that varies from + compiler to compiler. + - Make sure you declare your function pointers with the same calling + convention as the actual library function. Your code will crash + mysteriously if you do not do this. + - Avoid namespace collisions. If you load a symbol from the library, + it is not defined whether or not it goes into the global symbol + namespace for the application. If it does and it conflicts with + symbols in your code or other shared libraries, you will not get + the results you expect. :) +*/ + + +#ifndef _SDL_loadso_h +#define _SDL_loadso_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* This function dynamically loads a shared object and returns a pointer + * to the object handle (or NULL if there was an error). + * The 'sofile' parameter is a system dependent name of the object file. + */ +extern DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile); + +/* Given an object handle, this function looks up the address of the + * named function in the shared object and returns it. This address + * is no longer valid after calling SDL_UnloadObject(). + */ +extern DECLSPEC void * SDLCALL SDL_LoadFunction(void *handle, const char *name); + +/* Unload a shared object from memory */ +extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_loadso_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_main.h ./win32/dependencies/sdl/SDL_main.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_main.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_main.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,98 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_main_h +#define _SDL_main_h + +#include "SDL_stdinc.h" + +/* Redefine main() on Win32 and MacOS so that it is called by winmain.c */ + +#if defined(__WIN32__) || \ + (defined(__MWERKS__) && !defined(__BEOS__)) || \ + defined(__MACOS__) || defined(__MACOSX__) || \ + defined(__SYMBIAN32__) || defined(QWS) + +#ifdef __cplusplus +#define C_LINKAGE "C" +#else +#define C_LINKAGE +#endif /* __cplusplus */ + +/* The application's main() function must be called with C linkage, + and should be declared like this: +#ifdef __cplusplus +extern "C" +#endif + int main(int argc, char *argv[]) + { + } + */ +#define main SDL_main + +/* The prototype for the application's main() function */ +extern C_LINKAGE int SDL_main(int argc, char *argv[]); + + +/* From the SDL library code -- needed for registering the app on Win32 */ +#ifdef __WIN32__ + +#include "begin_code.h" +#ifdef __cplusplus +extern "C" { +#endif + +/* This should be called from your WinMain() function, if any */ +extern DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst); +/* This can also be called, but is no longer necessary */ +extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst); +/* This can also be called, but is no longer necessary (SDL_Quit calls it) */ +extern DECLSPEC void SDLCALL SDL_UnregisterApp(void); +#ifdef __cplusplus +} +#endif +#include "close_code.h" +#endif + +/* From the SDL library code -- needed for registering QuickDraw on MacOS */ +#if defined(__MACOS__) + +#include "begin_code.h" +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward declaration so we don't need to include QuickDraw.h */ +struct QDGlobals; + +/* This should be called from your main() function, if any */ +extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd); + +#ifdef __cplusplus +} +#endif +#include "close_code.h" +#endif + +#endif /* Need to redefine main()? */ + +#endif /* _SDL_main_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_mouse.h ./win32/dependencies/sdl/SDL_mouse.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_mouse.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_mouse.h 2006-06-25 04:59:04 +0900 @@ -0,0 +1,136 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL mouse event handling */ + +#ifndef _SDL_mouse_h +#define _SDL_mouse_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_video.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct WMcursor WMcursor; /* Implementation dependent */ +typedef struct SDL_Cursor { + SDL_Rect area; /* The area of the mouse cursor */ + Sint16 hot_x, hot_y; /* The "tip" of the cursor */ + Uint8 *data; /* B/W cursor data */ + Uint8 *mask; /* B/W cursor mask */ + Uint8 *save[2]; /* Place to save cursor area */ + WMcursor *wm_cursor; /* Window-manager cursor */ +} SDL_Cursor; + +/* Function prototypes */ +/* + * Retrieve the current state of the mouse. + * The current button state is returned as a button bitmask, which can + * be tested using the SDL_BUTTON(X) macros, and x and y are set to the + * current mouse cursor position. You can pass NULL for either x or y. + */ +extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y); + +/* + * Retrieve the current state of the mouse. + * The current button state is returned as a button bitmask, which can + * be tested using the SDL_BUTTON(X) macros, and x and y are set to the + * mouse deltas since the last call to SDL_GetRelativeMouseState(). + */ +extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y); + +/* + * Set the position of the mouse cursor (generates a mouse motion event) + */ +extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y); + +/* + * Create a cursor using the specified data and mask (in MSB format). + * The cursor width must be a multiple of 8 bits. + * + * The cursor is created in black and white according to the following: + * data mask resulting pixel on screen + * 0 1 White + * 1 1 Black + * 0 0 Transparent + * 1 0 Inverted color if possible, black if not. + * + * Cursors created with this function must be freed with SDL_FreeCursor(). + */ +extern DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor + (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); + +/* + * Set the currently active cursor to the specified one. + * If the cursor is currently visible, the change will be immediately + * represented on the display. + */ +extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor *cursor); + +/* + * Returns the currently active cursor. + */ +extern DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void); + +/* + * Deallocates a cursor created with SDL_CreateCursor(). + */ +extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor *cursor); + +/* + * Toggle whether or not the cursor is shown on the screen. + * The cursor start off displayed, but can be turned off. + * SDL_ShowCursor() returns 1 if the cursor was being displayed + * before the call, or 0 if it was not. You can query the current + * state by passing a 'toggle' value of -1. + */ +extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); + +/* Used as a mask when testing buttons in buttonstate + Button 1: Left mouse button + Button 2: Middle mouse button + Button 3: Right mouse button + Button 4: Mouse wheel up (may also be a real button) + Button 5: Mouse wheel down (may also be a real button) + */ +#define SDL_BUTTON(X) (1 << ((X)-1)) +#define SDL_BUTTON_LEFT 1 +#define SDL_BUTTON_MIDDLE 2 +#define SDL_BUTTON_RIGHT 3 +#define SDL_BUTTON_WHEELUP 4 +#define SDL_BUTTON_WHEELDOWN 5 +#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT) +#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE) +#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT) + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_mouse_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_mutex.h ./win32/dependencies/sdl/SDL_mutex.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_mutex.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_mutex.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,162 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_mutex_h +#define _SDL_mutex_h + +/* Functions to provide thread synchronization primitives + + These are independent of the other SDL routines. +*/ + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Synchronization functions which can time out return this value + if they time out. +*/ +#define SDL_MUTEX_TIMEDOUT 1 + +/* This is the timeout value which corresponds to never time out */ +#define SDL_MUTEX_MAXWAIT (~(Uint32)0) + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Mutex functions */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* The SDL mutex structure, defined in SDL_mutex.c */ +struct SDL_mutex; +typedef struct SDL_mutex SDL_mutex; + +/* Create a mutex, initialized unlocked */ +extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void); + +/* Lock the mutex (Returns 0, or -1 on error) */ +#define SDL_LockMutex(m) SDL_mutexP(m) +extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex); + +/* Unlock the mutex (Returns 0, or -1 on error) + It is an error to unlock a mutex that has not been locked by + the current thread, and doing so results in undefined behavior. + */ +#define SDL_UnlockMutex(m) SDL_mutexV(m) +extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex); + +/* Destroy a mutex */ +extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex); + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Semaphore functions */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* The SDL semaphore structure, defined in SDL_sem.c */ +struct SDL_semaphore; +typedef struct SDL_semaphore SDL_sem; + +/* Create a semaphore, initialized with value, returns NULL on failure. */ +extern DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value); + +/* Destroy a semaphore */ +extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem); + +/* This function suspends the calling thread until the semaphore pointed + * to by sem has a positive count. It then atomically decreases the semaphore + * count. + */ +extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem); + +/* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds, + SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error. +*/ +extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem); + +/* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if + the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in + the allotted time, and -1 on error. + On some platforms this function is implemented by looping with a delay + of 1 ms, and so should be avoided if possible. +*/ +extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms); + +/* Atomically increases the semaphore's count (not blocking), returns 0, + or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem); + +/* Returns the current count of the semaphore */ +extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem); + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Condition variable functions */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* The SDL condition variable structure, defined in SDL_cond.c */ +struct SDL_cond; +typedef struct SDL_cond SDL_cond; + +/* Create a condition variable */ +extern DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void); + +/* Destroy a condition variable */ +extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond); + +/* Restart one of the threads that are waiting on the condition variable, + returns 0 or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond); + +/* Restart all threads that are waiting on the condition variable, + returns 0 or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond); + +/* Wait on the condition variable, unlocking the provided mutex. + The mutex must be locked before entering this function! + The mutex is re-locked once the condition variable is signaled. + Returns 0 when it is signaled, or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut); + +/* Waits for at most 'ms' milliseconds, and returns 0 if the condition + variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not + signaled in the allotted time, and -1 on error. + On some platforms this function is implemented by looping with a delay + of 1 ms, and so should be avoided if possible. +*/ +extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_mutex_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_name.h ./win32/dependencies/sdl/SDL_name.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_name.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_name.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,11 @@ + +#ifndef _SDLname_h_ +#define _SDLname_h_ + +#if defined(__STDC__) || defined(__cplusplus) +#define NeedFunctionPrototypes 1 +#endif + +#define SDL_NAME(X) SDL_##X + +#endif /* _SDLname_h_ */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_opengl.h ./win32/dependencies/sdl/SDL_opengl.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_opengl.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_opengl.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,6551 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This is a simple file to encapsulate the OpenGL API headers */ + +#include "SDL_config.h" + +#ifdef __WIN32__ +#define WIN32_LEAN_AND_MEAN +#ifndef NOMINMAX +#define NOMINMAX /* Don't defined min() and max() */ +#endif +#include +#endif +#ifndef NO_SDL_GLEXT +#define __glext_h_ /* Don't let gl.h include glext.h */ +#endif +#if defined(__MACOSX__) +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ +#elif defined(__MACOS__) +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ +#else +#include /* Header File For The OpenGL Library */ +#include /* Header File For The GLU Library */ +#endif +#ifndef NO_SDL_GLEXT +#undef __glext_h_ +#endif + +/* This file taken from "GLext.h" from the Jeff Molofee OpenGL tutorials. + It is included here because glext.h is not available on some systems. + If you don't want this version included, simply define "NO_SDL_GLEXT" + */ +#ifndef NO_SDL_GLEXT +#if !defined(__glext_h_) && !defined(GL_GLEXT_LEGACY) +#define __glext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2004 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: This software was created using the +** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has +** not been independently verified as being compliant with the OpenGL(R) +** version 1.2.1 Specification. +*/ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glext.h last updated 2005/06/20 */ +/* Current version at http://oss.sgi.com/projects/ogl-sample/registry/ */ +#define GL_GLEXT_VERSION 29 + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_RESCALE_NORMAL 0x803A +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#define GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE +#define GL_FOG_COORD GL_FOG_COORDINATE +#define GL_CURRENT_FOG_COORD GL_CURRENT_FOG_COORDINATE +#define GL_FOG_COORD_ARRAY_TYPE GL_FOG_COORDINATE_ARRAY_TYPE +#define GL_FOG_COORD_ARRAY_STRIDE GL_FOG_COORDINATE_ARRAY_STRIDE +#define GL_FOG_COORD_ARRAY_POINTER GL_FOG_COORDINATE_ARRAY_POINTER +#define GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING +#define GL_SRC0_RGB GL_SOURCE0_RGB +#define GL_SRC1_RGB GL_SOURCE1_RGB +#define GL_SRC2_RGB GL_SOURCE2_RGB +#define GL_SRC0_ALPHA GL_SOURCE0_ALPHA +#define GL_SRC1_ALPHA GL_SOURCE1_ALPHA +#define GL_SRC2_ALPHA GL_SOURCE2_ALPHA +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_COORDS 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_ARB_multitexture +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +#endif + +#ifndef GL_ARB_multisample +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +#endif + +#ifndef GL_ARB_texture_env_add +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif + +#ifndef GL_ARB_texture_compression +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif + +#ifndef GL_ARB_point_parameters +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + +#ifndef GL_ARB_shadow +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif + +#ifndef GL_ARB_window_pos +#endif + +#ifndef GL_ARB_vertex_program +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +#endif + +#ifndef GL_ARB_fragment_program +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +#endif + +#ifndef GL_ARB_shader_objects +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +#ifndef GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif + +#ifndef GL_EXT_abgr +#define GL_ABGR_EXT 0x8000 +#endif + +#ifndef GL_EXT_blend_color +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +#endif + +#ifndef GL_EXT_texture +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif + +#ifndef GL_EXT_texture3D +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +#endif + +#ifndef GL_EXT_subtexture +#endif + +#ifndef GL_EXT_copy_texture +#endif + +#ifndef GL_EXT_histogram +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +#endif + +#ifndef GL_EXT_convolution +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +#endif + +#ifndef GL_SGI_color_matrix +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif + +#ifndef GL_SGI_color_table +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +#endif + +#ifndef GL_SGIS_texture4D +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif + +#ifndef GL_EXT_cmyka +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif + +#ifndef GL_EXT_texture_object +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif + +#ifndef GL_SGIS_multisample +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif + +#ifndef GL_EXT_vertex_array +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +#endif + +#ifndef GL_EXT_misc_attribute +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif + +#ifndef GL_SGIX_shadow +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif + +#ifndef GL_EXT_blend_logic_op +#endif + +#ifndef GL_SGIX_interlace +#define GL_INTERLACE_SGIX 0x8094 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif + +#ifndef GL_SGIS_texture_select +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif + +#ifndef GL_EXT_point_parameters +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +#endif + +#ifndef GL_SGIX_instruments +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif + +#ifndef GL_SGIX_framezoom +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#endif + +#ifndef GL_FfdMaskSGIX +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +#endif + +#ifndef GL_SGIX_flush_raster +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif + +#ifndef GL_HP_image_transform +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif + +#ifndef GL_INGR_palette_buffer +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif + +#ifndef GL_EXT_color_subtable +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_LIST_PRIORITY_SGIX 0x8182 +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif + +#ifndef GL_EXT_index_texture +#endif + +#ifndef GL_EXT_index_material +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +#endif + +#ifndef GL_EXT_index_func +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +#endif + +#ifndef GL_WIN_phong_shading +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif + +#ifndef GL_WIN_specular_fog +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif + +#ifndef GL_EXT_light_texture +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +/* reuse GL_FRAGMENT_DEPTH_EXT */ +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif + +#ifndef GL_SGIX_impact_pixel_texture +#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 +#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 +#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 +#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 +#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 +#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 +#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A +#endif + +#ifndef GL_EXT_bgra +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif + +#ifndef GL_SGIX_async +#define GL_ASYNC_MARKER_SGIX 0x8329 +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif + +#ifndef GL_INTEL_texture_scissor +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +#endif + +#ifndef GL_HP_occlusion_test +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif + +#ifndef GL_EXT_secondary_color +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +#endif + +#ifndef GL_EXT_multi_draw_arrays +#endif + +#ifndef GL_EXT_fog_coord +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_FOG_SCALE_SGIX 0x81FC +#define GL_FOG_SCALE_VALUE_SGIX 0x81FD +#endif + +#ifndef GL_SUNX_constant_data +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +#endif + +#ifndef GL_SUN_global_alpha +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +#endif + +#ifndef GL_SUN_triangle_list +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +#endif + +#ifndef GL_SUN_vertex +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +#endif + +#ifndef GL_INGR_color_clamp +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INTERLACE_READ_INGR 0x8568 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif + +#ifndef GL_EXT_texture_cube_map +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif + +#ifndef GL_EXT_texture_env_add +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT GL_MODELVIEW +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +#endif + +#ifndef GL_NV_register_combiners +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +/* reuse GL_TEXTURE0_ARB */ +/* reuse GL_TEXTURE1_ARB */ +/* reuse GL_ZERO */ +/* reuse GL_NONE */ +/* reuse GL_FOG */ +#endif + +#ifndef GL_NV_fog_distance +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +/* reuse GL_EYE_PLANE */ +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif + +#ifndef GL_NV_blend_square +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif + +#ifndef GL_MESA_resize_buffers +#endif + +#ifndef GL_MESA_window_pos +#endif + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_CULL_VERTEX_IBM 103050 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +#endif + +#ifndef GL_SGIX_subsample +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif + +#ifndef GL_SGI_depth_pass_instrument +#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 +#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 +#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif + +#ifndef GL_3DFX_tbuffer +#endif + +#ifndef GL_EXT_multisample +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif + +#ifndef GL_SGIX_resample +#define GL_PACK_RESAMPLE_SGIX 0x842C +#define GL_UNPACK_RESAMPLE_SGIX 0x842D +#define GL_RESAMPLE_REPLICATE_SGIX 0x842E +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif + +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + +#ifndef GL_NV_evaluators +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +#endif + +#ifndef GL_NV_texture_compression_vtc +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif + +#ifndef GL_NV_texture_shader +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV +#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV +#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif + +#ifndef GL_NV_vertex_program +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif + +#ifndef GL_OML_interlace +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif + +#ifndef GL_OML_subsample +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif + +#ifndef GL_OML_resample +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +#endif + +#ifndef GL_ATI_element_array +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +#endif + +#ifndef GL_SUN_mesh_array +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_DEPTH_CLAMP_NV 0x864F +#endif + +#ifndef GL_NV_occlusion_query +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +#endif + +#ifndef GL_NV_point_sprite +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif + +#ifndef GL_NV_vertex_program1_1 +#endif + +#ifndef GL_EXT_shadow_funcs +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif + +#ifndef GL_APPLE_element_array +#define GL_ELEMENT_ARRAY_APPLE 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x876A +#endif + +#ifndef GL_APPLE_fence +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_YCBCR_422_APPLE 0x85B9 +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +#ifndef GL_S3_s3tc +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif + +#ifndef GL_ATI_texture_float +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif + +#ifndef GL_NV_float_buffer +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif + +#ifndef GL_NV_fragment_program +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +#endif + +#ifndef GL_NV_half_float +#define GL_HALF_FLOAT_NV 0x140B +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +#endif + +#ifndef GL_NV_primitive_restart +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif + +#ifndef GL_NV_vertex_program2 +#endif + +#ifndef GL_ATI_map_object_buffer +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#endif + +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_BLEND_EQUATION_RGB_EXT GL_BLEND_EQUATION +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +#endif + +#ifndef GL_MESA_pack_invert +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif + +#ifndef GL_NV_fragment_program_option +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif + +#ifndef GL_NV_vertex_program2_option +/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ +/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ +#endif + +#ifndef GL_NV_vertex_program3 +/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#endif + +#ifndef GL_GREMEDY_string_marker +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; /* native character */ +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for handling shader object handles and program/shader text */ +typedef char GLcharARB; /* native character */ +typedef unsigned int GLhandleARB; /* shader object handle */ +#endif + +/* GL types for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); +GLAPI void APIENTRY glBlendEquation (GLenum); +GLAPI void APIENTRY glDrawRangeElements (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTable (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTable (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glColorSubTable (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTable (GLenum, GLsizei, GLint, GLint, GLsizei); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterf (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteri (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilter (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +GLAPI void APIENTRY glGetHistogram (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmax (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogram (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmax (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogram (GLenum); +GLAPI void APIENTRY glResetMinmax (GLenum); +GLAPI void APIENTRY glTexImage3D (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum); +GLAPI void APIENTRY glClientActiveTexture (GLenum); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum, const GLshort *); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *); +GLAPI void APIENTRY glSampleCoverage (GLclampf, GLboolean); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glFogCoordf (GLfloat); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *); +GLAPI void APIENTRY glFogCoordd (GLdouble); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointer (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glMultiDrawArrays (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElements (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +GLAPI void APIENTRY glPointParameterf (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfv (GLenum, const GLfloat *); +GLAPI void APIENTRY glPointParameteri (GLenum, GLint); +GLAPI void APIENTRY glPointParameteriv (GLenum, const GLint *); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3i (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *); +GLAPI void APIENTRY glSecondaryColor3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3us (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointer (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glWindowPos2d (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos2f (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos2i (GLint, GLint); +GLAPI void APIENTRY glWindowPos2iv (const GLint *); +GLAPI void APIENTRY glWindowPos2s (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *); +GLAPI void APIENTRY glWindowPos3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos3i (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3iv (const GLint *); +GLAPI void APIENTRY glWindowPos3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueries (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQuery (GLuint); +GLAPI void APIENTRY glBeginQuery (GLenum, GLuint); +GLAPI void APIENTRY glEndQuery (GLenum); +GLAPI void APIENTRY glGetQueryiv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint, GLenum, GLuint *); +GLAPI void APIENTRY glBindBuffer (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffers (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffers (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint); +GLAPI void APIENTRY glBufferData (GLenum, GLsizeiptr, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubData (GLenum, GLintptr, GLsizeiptr, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubData (GLenum, GLintptr, GLsizeiptr, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointerv (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum, GLenum); +GLAPI void APIENTRY glDrawBuffers (GLsizei, const GLenum *); +GLAPI void APIENTRY glStencilOpSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum, GLenum, GLint, GLuint); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum, GLuint); +GLAPI void APIENTRY glAttachShader (GLuint, GLuint); +GLAPI void APIENTRY glBindAttribLocation (GLuint, GLuint, const GLchar *); +GLAPI void APIENTRY glCompileShader (GLuint); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum); +GLAPI void APIENTRY glDeleteProgram (GLuint); +GLAPI void APIENTRY glDeleteShader (GLuint); +GLAPI void APIENTRY glDetachShader (GLuint, GLuint); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint); +GLAPI void APIENTRY glGetActiveAttrib (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetActiveUniform (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetAttachedShaders (GLuint, GLsizei, GLsizei *, GLuint *); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetProgramiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderSource (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetUniformfv (GLuint, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformiv (GLuint, GLint, GLint *); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgram (GLuint); +GLAPI GLboolean APIENTRY glIsShader (GLuint); +GLAPI void APIENTRY glLinkProgram (GLuint); +GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *); +GLAPI void APIENTRY glUseProgram (GLuint); +GLAPI void APIENTRY glUniform1f (GLint, GLfloat); +GLAPI void APIENTRY glUniform2f (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3f (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4f (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1i (GLint, GLint); +GLAPI void APIENTRY glUniform2i (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3i (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4i (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glValidateProgram (GLuint); +GLAPI void APIENTRY glVertexAttrib1d (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1f (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1s (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2d (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2f (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2s (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3d (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3f (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3s (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4d (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4f (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4s (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointer (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum, const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#endif + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLclampf, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); +#endif + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#endif + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#endif + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvARB (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint, const GLbyte *); +GLAPI void APIENTRY glWeightsvARB (GLint, const GLshort *); +GLAPI void APIENTRY glWeightivARB (GLint, const GLint *); +GLAPI void APIENTRY glWeightfvARB (GLint, const GLfloat *); +GLAPI void APIENTRY glWeightdvARB (GLint, const GLdouble *); +GLAPI void APIENTRY glWeightubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glWeightusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glWeightuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glWeightPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexBlendARB (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#endif + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#endif + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iARB (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos2sARB (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos3sARB (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#endif + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glProgramStringARB (GLenum, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBindProgramARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenProgramsARB (GLsizei, GLuint *); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringARB (GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#endif + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffersARB (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint); +GLAPI void APIENTRY glBufferDataARB (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint); +GLAPI void APIENTRY glBeginQueryARB (GLenum, GLuint); +GLAPI void APIENTRY glEndQueryARB (GLenum); +GLAPI void APIENTRY glGetQueryivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB, GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB, GLhandleARB); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB); +GLAPI void APIENTRY glUniform1fARB (GLint, GLfloat); +GLAPI void APIENTRY glUniform2fARB (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3fARB (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4fARB (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1iARB (GLint, GLint); +GLAPI void APIENTRY glUniform2iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3iARB (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4iARB (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB, GLenum, GLint *); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB, const GLcharARB *); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB, GLint, GLint *); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB, GLuint, const GLcharARB *); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB, const GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +#endif + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#endif + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#endif + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#endif + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#endif + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum, GLenum, GLsizei, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogramEXT (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmaxEXT (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogramEXT (GLenum); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#endif + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif + +#ifndef GL_EXT_color_matrix +#define GL_EXT_color_matrix 1 +#endif + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTableSGI (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum, GLint); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum, const GLint *); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum, GLint *); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#endif + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#endif + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindTextureEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei, const GLuint *, const GLclampf *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#endif + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#endif + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint); +GLAPI void APIENTRY glColorPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glDrawArraysEXT (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei, GLsizei, const GLboolean *); +GLAPI void APIENTRY glGetPointervEXT (GLenum, GLvoid* *); +GLAPI void APIENTRY glIndexPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glNormalPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#endif + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#endif + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#endif + +#ifndef GL_SGIX_texture_select +#define GL_SGIX_texture_select 1 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum, GLint); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#endif + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei, GLint *); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#endif + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); +GLAPI void APIENTRY glDeformSGIX (GLbitfield); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#endif + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#endif + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum, GLenum, GLint); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#endif + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum, GLsizei, GLint, GLint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glGetColorTableEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glListParameterfSGIX (GLuint, GLenum, GLfloat); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint, GLenum, const GLfloat *); +GLAPI void APIENTRY glListParameteriSGIX (GLuint, GLenum, GLint); +GLAPI void APIENTRY glListParameterivSGIX (GLuint, GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#endif + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint, GLsizei); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum, GLdouble *); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum, GLenum); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum, GLint); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum, const GLint *); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glLightEnviSGIX (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#endif + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#endif + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum); +GLAPI void APIENTRY glTextureLightEXT (GLenum); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#endif + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#endif + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint, GLsizei); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum, const GLvoid* *); +GLAPI void APIENTRY glColorPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint, GLenum, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +#endif + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum, GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#endif + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *); +GLAPI void APIENTRY glTangent3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *); +GLAPI void APIENTRY glTangent3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *); +GLAPI void APIENTRY glTangent3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *); +GLAPI void APIENTRY glTangent3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *); +GLAPI void APIENTRY glBinormal3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *); +GLAPI void APIENTRY glBinormal3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *); +GLAPI void APIENTRY glTangentPointerEXT (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_SGIX_fog_scale 1 +#endif + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#endif + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#endif + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum, GLsizei, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat, GLfloat, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#endif + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); +#endif + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#endif + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#endif + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#endif + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#endif + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iMESA (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iMESA (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos4iMESA (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *, const GLint *, const GLsizei *, GLsizei, GLint); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *, const GLsizei *, GLenum, const GLvoid* const *, GLsizei, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint, const GLboolean* *, GLint); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glVertexPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#endif + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#endif + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#endif + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean, GLboolean, GLboolean, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#endif + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFencesNV (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint); +GLAPI void APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFinishFenceNV (GLuint); +GLAPI void APIENTRY glSetFenceNV (GLuint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLint, GLint, GLboolean, const GLvoid *); +GLAPI void APIENTRY glMapParameterivNV (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMapParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLboolean, GLvoid *); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glEvalMapsNV (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#endif + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#endif + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindProgramNV (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glExecuteProgramNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGenProgramsNV (GLsizei, GLuint *); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum, GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetProgramivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringNV (GLuint, GLenum, GLubyte *); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint); +GLAPI void APIENTRY glLoadProgramNV (GLenum, GLuint, GLsizei, const GLubyte *); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum, GLuint, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum, GLuint, GLuint, const GLfloat *); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glTrackMatrixNV (GLenum, GLuint, GLenum, GLenum); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint, GLsizei, const GLubyte *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#endif + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#endif + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#endif + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum, const GLint *); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum, GLint *); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glSampleMapATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum, GLint); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei, const GLvoid *, GLenum); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint, GLuint, GLsizei, const GLvoid *, GLenum); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint); +GLAPI void APIENTRY glArrayObjectATI (GLenum, GLint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint); +GLAPI void APIENTRY glShaderOp1EXT (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp2EXT (GLenum, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp3EXT (GLenum, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSwizzleEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glWriteMaskEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glInsertComponentEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glExtractComponentEXT (GLuint, GLuint, GLuint); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glSetInvariantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glVariantbvEXT (GLuint, const GLbyte *); +GLAPI void APIENTRY glVariantsvEXT (GLuint, const GLshort *); +GLAPI void APIENTRY glVariantivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVariantfvEXT (GLuint, const GLfloat *); +GLAPI void APIENTRY glVariantdvEXT (GLuint, const GLdouble *); +GLAPI void APIENTRY glVariantubvEXT (GLuint, const GLubyte *); +GLAPI void APIENTRY glVariantusvEXT (GLuint, const GLushort *); +GLAPI void APIENTRY glVariantuivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVariantPointerEXT (GLuint, GLenum, GLuint, const GLvoid *); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum, GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint, GLenum); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint, GLenum, GLvoid* *); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum, GLshort); +GLAPI void APIENTRY glVertexStream1svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream1iATI (GLenum, GLint); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream1fATI (GLenum, GLfloat); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream1dATI (GLenum, GLdouble); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream2sATI (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream2svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream2iATI (GLenum, GLint, GLint); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream2fATI (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream2dATI (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream4sATI (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream4svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream4iATI (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream4fATI (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream4dATI (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glNormalStream3bATI (GLenum, GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum, const GLbyte *); +GLAPI void APIENTRY glNormalStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glNormalStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glNormalStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glNormalStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glNormalStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum, GLint); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum, GLuint, GLuint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#endif + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glPointParameterivNV (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#endif + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#endif + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, GLint, GLsizei); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum, const GLint *, const GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, const GLint *, const GLsizei *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum, GLuint); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#endif + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +/* This is really a WGL extension, but defines some associated GL enums. + * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. + */ +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#endif + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#endif + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#endif + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint, GLsizei, const GLubyte *, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint, GLsizei, const GLubyte *, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint, GLsizei, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint, GLsizei, const GLubyte *, const GLdouble *); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint, GLsizei, const GLubyte *, GLfloat *); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint, GLsizei, const GLubyte *, GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint, GLsizei, const GLhalfNV *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum, GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#endif + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#endif + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum, GLenum, GLint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint, GLint, GLenum, GLboolean, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd, GLclampd); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#endif + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#endif + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei, GLuint *); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum, GLenum, GLint *); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei, GLuint *); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#endif + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif +#endif /* NO_SDL_GLEXT */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_platform.h ./win32/dependencies/sdl/SDL_platform.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_platform.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_platform.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,104 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Try to get a standard set of platform defines */ + +#ifndef _SDL_platform_h +#define _SDL_platform_h + +#if defined(_AIX) +#undef __AIX__ +#define __AIX__ 1 +#endif +#if defined(AMIGA) || defined(__AMIGA) || defined(__amigados__) +#undef __AMIGA__ +#define __AMIGA__ 1 +#endif +#if defined(__BEOS__) +#undef __BEOS__ +#define __BEOS__ 1 +#endif +#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__) +#undef __BSDI__ +#define __BSDI__ 1 +#endif +#if defined(_arch_dreamcast) +#undef __DREAMCAST__ +#define __DREAMCAST__ 1 +#endif +#if defined(__FreeBSD__) || defined(__DragonFly__) +#undef __FREEBSD__ +#define __FREEBSD__ 1 +#endif +#if defined(hpux) || defined(__hpux) || defined(__hpux__) +#undef __HPUX__ +#define __HPUX__ 1 +#endif +#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE) +#undef __IRIX__ +#define __IRIX__ 1 +#endif +#if defined(linux) || defined(__linux) || defined(__linux__) +#undef __LINUX__ +#define __LINUX__ 1 +#endif +#if defined(__APPLE__) +#undef __MACOSX__ +#define __MACOSX__ 1 +#elif defined(macintosh) +#undef __MACOS__ +#define __MACOS__ 1 +#endif +#if defined(__NetBSD__) +#undef __NETBSD__ +#define __NETBSD__ 1 +#endif +#if defined(__OpenBSD__) +#undef __OPENBSD__ +#define __OPENBSD__ 1 +#endif +#if defined(__OS2__) +#undef __OS2__ +#define __OS2__ 1 +#endif +#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE) +#undef __OSF__ +#define __OSF__ 1 +#endif +#if defined(__QNXNTO__) +#undef __QNXNTO__ +#define __QNXNTO__ 1 +#endif +#if defined(riscos) || defined(__riscos) || defined(__riscos__) +#undef __RISCOS__ +#define __RISCOS__ 1 +#endif +#if defined(__SVR4) +#undef __SOLARIS__ +#define __SOLARIS__ 1 +#endif +#if defined(WIN32) || defined(_WIN32) +#undef __WIN32__ +#define __WIN32__ 1 +#endif + +#endif /* _SDL_platform_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_quit.h ./win32/dependencies/sdl/SDL_quit.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_quit.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_quit.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,50 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL quit event handling */ + +#ifndef _SDL_quit_h +#define _SDL_quit_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +/* + An SDL_QUITEVENT is generated when the user tries to close the application + window. If it is ignored or filtered out, the window will remain open. + If it is not ignored or filtered, it is queued normally and the window + is allowed to close. When the window is closed, screen updates will + complete, but have no effect. + + SDL_Init() installs signal handlers for SIGINT (keyboard interrupt) + and SIGTERM (system termination request), if handlers do not already + exist, that generate SDL_QUITEVENT events as well. There is no way + to determine the cause of an SDL_QUITEVENT, but setting a signal + handler in your application will override the default generation of + quit events for that signal. +*/ + +/* There are no functions directly affecting the quit event */ +#define SDL_QuitRequested() \ + (SDL_PumpEvents(), SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUITMASK)) + +#endif /* _SDL_quit_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_rwops.h ./win32/dependencies/sdl/SDL_rwops.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_rwops.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_rwops.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,139 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This file provides a general interface for SDL to read and write + data sources. It can easily be extended to files, memory, etc. +*/ + +#ifndef _SDL_rwops_h +#define _SDL_rwops_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* This is the read/write operation structure -- very basic */ + +typedef struct SDL_RWops { + /* Seek to 'offset' relative to whence, one of stdio's whence values: + SEEK_SET, SEEK_CUR, SEEK_END + Returns the final offset in the data source. + */ + int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence); + + /* Read up to 'num' objects each of size 'objsize' from the data + source to the area pointed at by 'ptr'. + Returns the number of objects read, or -1 if the read failed. + */ + int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); + + /* Write exactly 'num' objects each of size 'objsize' from the area + pointed at by 'ptr' to data source. + Returns 'num', or -1 if the write failed. + */ + int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num); + + /* Close and free an allocated SDL_FSops structure */ + int (SDLCALL *close)(struct SDL_RWops *context); + + Uint32 type; + union { +#ifdef __WIN32__ + struct { + int append; + void* h; + } win32io; +#endif +#ifdef HAVE_STDIO_H + struct { + int autoclose; + FILE *fp; + } stdio; +#endif + struct { + Uint8 *base; + Uint8 *here; + Uint8 *stop; + } mem; + struct { + void *data1; + } unknown; + } hidden; + +} SDL_RWops; + + +/* Functions to create SDL_RWops structures from various data sources */ + +extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode); + +#ifdef HAVE_STDIO_H +extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose); +#endif + +extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size); +extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size); + +extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void); +extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area); + +#define RW_SEEK_SET 0 /* Seek from the beginning of data */ +#define RW_SEEK_CUR 1 /* Seek relative to current read point */ +#define RW_SEEK_END 2 /* Seek relative to the end of data */ + +/* Macros to easily read and write from an SDL_RWops structure */ +#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence) +#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR) +#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n) +#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n) +#define SDL_RWclose(ctx) (ctx)->close(ctx) + + +/* Read an item of the specified endianness and return in native format */ +extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src); +extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src); +extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src); +extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src); +extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src); +extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src); + +/* Write an item of native format to the specified endianness */ +extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value); +extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value); +extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value); +extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value); +extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value); +extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_rwops_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_stdinc.h ./win32/dependencies/sdl/SDL_stdinc.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_stdinc.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_stdinc.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,584 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This is a general header that includes C language support */ + +#ifndef _SDL_stdinc_h +#define _SDL_stdinc_h + +#include "SDL_config.h" + + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#if defined(STDC_HEADERS) +# include +# include +# include +#else +# if defined(HAVE_STDLIB_H) +# include +# elif defined(HAVE_MALLOC_H) +# include +# endif +# if defined(HAVE_STDDEF_H) +# include +# endif +# if defined(HAVE_STDARG_H) +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H) +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#if defined(HAVE_INTTYPES_H) +# include +#elif defined(HAVE_STDINT_H) +# include +#endif +#ifdef HAVE_CTYPE_H +# include +#endif +#ifdef HAVE_ICONV_H +# include +#endif + +/* The number of elements in an array */ +#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) +#define SDL_TABLESIZE(table) SDL_arraysize(table) + +/* Basic data types */ +typedef enum SDL_bool { + SDL_FALSE = 0, + SDL_TRUE = 1 +} SDL_bool; + +typedef int8_t Sint8; +typedef uint8_t Uint8; +typedef int16_t Sint16; +typedef uint16_t Uint16; +typedef int32_t Sint32; +typedef uint32_t Uint32; + +#ifdef SDL_HAS_64BIT_TYPE +typedef int64_t Sint64; +typedef uint64_t Uint64; +#else +/* This is really just a hack to prevent the compiler from complaining */ +typedef struct { + Uint32 hi; + Uint32 lo; +} Uint64, Sint64; +#endif + +/* Make sure the types really have the right sizes */ +#define SDL_COMPILE_TIME_ASSERT(name, x) \ + typedef int SDL_dummy_ ## name[(x) * 2 - 1] + +SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); +SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); +SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); +SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); +SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); +SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); +SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); +SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); + +/* Check to make sure enums are the size of ints, for structure packing. + For both Watcom C/C++ and Borland C/C++ the compiler option that makes + enums having the size of an int must be enabled. + This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). +*/ +/* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ +#ifdef __MWERKS__ +#pragma enumsalwaysint on +#endif + +typedef enum { + DUMMY_ENUM_VALUE +} SDL_DUMMY_ENUM; + +SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); + + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_MALLOC +#define SDL_malloc malloc +#else +extern DECLSPEC void * SDLCALL SDL_malloc(size_t size); +#endif + +#ifdef HAVE_CALLOC +#define SDL_calloc calloc +#else +extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size); +#endif + +#ifdef HAVE_REALLOC +#define SDL_realloc realloc +#else +extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size); +#endif + +#ifdef HAVE_FREE +#define SDL_free free +#else +extern DECLSPEC void SDLCALL SDL_free(void *mem); +#endif + +#if defined(HAVE_ALLOCA) && !defined(alloca) +# if defined(HAVE_ALLOCA_H) +# include +# elif defined(__GNUC__) +# define alloca __builtin_alloca +# elif defined(_MSC_VER) +# include +# define alloca _alloca +# elif defined(__WATCOMC__) +# include +# elif defined(__AIX__) + #pragma alloca +# elif defined(__MRC__) + void *alloca (unsigned); +# else + char *alloca (); +# endif +#endif +#ifdef HAVE_ALLOCA +#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count) +#define SDL_stack_free(data) +#else +#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*count) +#define SDL_stack_free(data) SDL_free(data) +#endif + +#ifdef HAVE_GETENV +#define SDL_getenv getenv +#else +extern DECLSPEC char * SDLCALL SDL_getenv(const char *name); +#endif + +#ifdef HAVE_PUTENV +#define SDL_putenv putenv +#else +extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); +#endif + +#ifdef HAVE_QSORT +#define SDL_qsort qsort +#else +extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, + int (*compare)(const void *, const void *)); +#endif + +#ifdef HAVE_ABS +#define SDL_abs abs +#else +#define SDL_abs(X) ((X) < 0 ? -(X) : (X)) +#endif + +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) + +#ifdef HAVE_CTYPE_H +#define SDL_isdigit(X) isdigit(X) +#define SDL_isspace(X) isspace(X) +#define SDL_toupper(X) toupper(X) +#define SDL_tolower(X) tolower(X) +#else +#define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9')) +#define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n')) +#define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X)) +#define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X)) +#endif + +#ifdef HAVE_MEMSET +#define SDL_memset memset +#else +extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len); +#endif + +#if defined(__GNUC__) && defined(i386) +#define SDL_memset4(dst, val, len) \ +do { \ + int u0, u1, u2; \ + __asm__ __volatile__ ( \ + "cld\n\t" \ + "rep ; stosl\n\t" \ + : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ + : "0" (dst), "1" (val), "2" ((Uint32)(len)) \ + : "memory" ); \ +} while(0) +#endif +#ifndef SDL_memset4 +#define SDL_memset4(dst, val, len) \ +do { \ + unsigned _count = (len); \ + unsigned _n = (_count + 3) / 4; \ + Uint32 *_p = (Uint32 *)(dst); \ + Uint32 _val = (val); \ + switch (_count % 4) { \ + case 0: do { *_p++ = _val; \ + case 3: *_p++ = _val; \ + case 2: *_p++ = _val; \ + case 1: *_p++ = _val; \ + } while ( --_n ); \ + } \ +} while(0) +#endif + +#if defined(__GNUC__) && defined(i386) +#define SDL_memcpy(dst, src, len) \ +do { \ + int u0, u1, u2; \ + __asm__ __volatile__ ( \ + "cld\n\t" \ + "rep ; movsl\n\t" \ + "testb $2,%b4\n\t" \ + "je 1f\n\t" \ + "movsw\n" \ + "1:\ttestb $1,%b4\n\t" \ + "je 2f\n\t" \ + "movsb\n" \ + "2:" \ + : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ + : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \ + : "memory" ); \ +} while(0) +#endif +#ifndef SDL_memcpy +#ifdef HAVE_MEMCPY +#define SDL_memcpy memcpy +#elif defined(HAVE_BCOPY) +#define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) +#else +extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); +#endif +#endif + +#if defined(__GNUC__) && defined(i386) +#define SDL_memcpy4(dst, src, len) \ +do { \ + int ecx, edi, esi; \ + __asm__ __volatile__ ( \ + "cld\n\t" \ + "rep ; movsl" \ + : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ + : "0" ((unsigned)(len)), "1" (dst), "2" (src) \ + : "memory" ); \ +} while(0) +#endif +#ifndef SDL_memcpy4 +#define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2) +#endif + +#if defined(__GNUC__) && defined(i386) +#define SDL_revcpy(dst, src, len) \ +do { \ + int u0, u1, u2; \ + char *dstp = (char *)(dst); \ + char *srcp = (char *)(src); \ + int n = (len); \ + if ( n >= 4 ) { \ + __asm__ __volatile__ ( \ + "std\n\t" \ + "rep ; movsl\n\t" \ + : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ + : "0" (n >> 2), \ + "1" (dstp+(n-4)), "2" (srcp+(n-4)) \ + : "memory" ); \ + } \ + switch (n & 3) { \ + case 3: dstp[2] = srcp[2]; \ + case 2: dstp[1] = srcp[1]; \ + case 1: dstp[0] = srcp[0]; \ + break; \ + default: \ + break; \ + } \ +} while(0) +#endif +#ifndef SDL_revcpy +extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len); +#endif + +#ifdef HAVE_MEMMOVE +#define SDL_memmove memmove +#elif defined(HAVE_BCOPY) +#define SDL_memmove(d, s, n) bcopy((s), (d), (n)) +#else +#define SDL_memmove(dst, src, len) \ +do { \ + if ( dst < src ) { \ + SDL_memcpy(dst, src, len); \ + } else { \ + SDL_revcpy(dst, src, len); \ + } \ +} while(0) +#endif + +#ifdef HAVE_MEMCMP +#define SDL_memcmp memcmp +#else +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); +#endif + +#ifdef HAVE_STRLEN +#define SDL_strlen strlen +#else +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); +#endif + +#ifdef HAVE_STRLCPY +#define SDL_strlcpy strlcpy +#else +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); +#endif + +#ifdef HAVE_STRLCAT +#define SDL_strlcat strlcat +#else +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); +#endif + +#ifdef HAVE_STRDUP +#define SDL_strdup strdup +#else +extern DECLSPEC char * SDLCALL SDL_strdup(const char *string); +#endif + +#ifdef HAVE__STRREV +#define SDL_strrev _strrev +#else +extern DECLSPEC char * SDLCALL SDL_strrev(char *string); +#endif + +#ifdef HAVE__STRUPR +#define SDL_strupr _strupr +#else +extern DECLSPEC char * SDLCALL SDL_strupr(char *string); +#endif + +#ifdef HAVE__STRLWR +#define SDL_strlwr _strlwr +#else +extern DECLSPEC char * SDLCALL SDL_strlwr(char *string); +#endif + +#ifdef HAVE_STRCHR +#define SDL_strchr strchr +#elif defined(HAVE_INDEX) +#define SDL_strchr index +#else +extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c); +#endif + +#ifdef HAVE_STRRCHR +#define SDL_strrchr strrchr +#elif defined(HAVE_RINDEX) +#define SDL_strrchr rindex +#else +extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c); +#endif + +#ifdef HAVE_STRSTR +#define SDL_strstr strstr +#else +extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle); +#endif + +#ifdef HAVE_ITOA +#define SDL_itoa itoa +#else +#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) +#endif + +#ifdef HAVE__LTOA +#define SDL_ltoa _ltoa +#else +extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix); +#endif + +#ifdef HAVE__UITOA +#define SDL_uitoa _uitoa +#else +#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) +#endif + +#ifdef HAVE__ULTOA +#define SDL_ultoa _ultoa +#else +extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix); +#endif + +#ifdef HAVE_STRTOL +#define SDL_strtol strtol +#else +extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base); +#endif + +#ifdef HAVE_STRTOUL +#define SDL_strtoul strtoul +#else +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base); +#endif + +#ifdef SDL_HAS_64BIT_TYPE + +#ifdef HAVE__I64TOA +#define SDL_lltoa _i64toa +#else +extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix); +#endif + +#ifdef HAVE__UI64TOA +#define SDL_ulltoa _ui64toa +#else +extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix); +#endif + +#ifdef HAVE_STRTOLL +#define SDL_strtoll strtoll +#else +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base); +#endif + +#ifdef HAVE_STRTOULL +#define SDL_strtoull strtoull +#else +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base); +#endif + +#endif /* SDL_HAS_64BIT_TYPE */ + +#ifdef HAVE_STRTOD +#define SDL_strtod strtod +#else +extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); +#endif + +#ifdef HAVE_ATOI +#define SDL_atoi atoi +#else +#define SDL_atoi(X) SDL_strtol(X, NULL, 0) +#endif + +#ifdef HAVE_ATOF +#define SDL_atof atof +#else +#define SDL_atof(X) SDL_strtod(X, NULL) +#endif + +#ifdef HAVE_STRCMP +#define SDL_strcmp strcmp +#else +extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); +#endif + +#ifdef HAVE_STRNCMP +#define SDL_strncmp strncmp +#else +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); +#endif + +#ifdef HAVE_STRCASECMP +#define SDL_strcasecmp strcasecmp +#elif defined(HAVE__STRICMP) +#define SDL_strcasecmp _stricmp +#else +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); +#endif + +#ifdef HAVE_STRNCASECMP +#define SDL_strncasecmp strncasecmp +#elif defined(HAVE__STRNICMP) +#define SDL_strncasecmp _strnicmp +#else +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen); +#endif + +#ifdef HAVE_SSCANF +#define SDL_sscanf sscanf +#else +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); +#endif + +#ifdef HAVE_SNPRINTF +#define SDL_snprintf snprintf +#else +extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); +#endif + +#ifdef HAVE_VSNPRINTF +#define SDL_vsnprintf vsnprintf +#else +extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); +#endif + +/* The SDL implementation of iconv() returns these error codes */ +#define SDL_ICONV_ERROR (size_t)-1 +#define SDL_ICONV_E2BIG (size_t)-2 +#define SDL_ICONV_EILSEQ (size_t)-3 +#define SDL_ICONV_EINVAL (size_t)-4 + +#ifdef HAVE_ICONV +#define SDL_iconv_t iconv_t +#define SDL_iconv_open iconv_open +#define SDL_iconv_close iconv_close +extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +#else +typedef struct _SDL_iconv_t *SDL_iconv_t; +extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode); +extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); +extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +#endif +/* This function converts a string between encodings in one pass, returning a + string that must be freed with SDL_free() or NULL on error. +*/ +extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft); +#define SDL_iconv_utf8_ascii(S) SDL_iconv_string("ASCII", "UTF-8", S, SDL_strlen(S)+1) +#define SDL_iconv_utf8_latin1(S) SDL_iconv_string("LATIN1", "UTF-8", S, SDL_strlen(S)+1) +#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1) +#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1) + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_stdinc_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_syswm.h ./win32/dependencies/sdl/SDL_syswm.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_syswm.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_syswm.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,210 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Include file for SDL custom system window manager hooks */ + +#ifndef _SDL_syswm_h +#define _SDL_syswm_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_version.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Your application has access to a special type of event 'SDL_SYSWMEVENT', + which contains window-manager specific information and arrives whenever + an unhandled window event occurs. This event is ignored by default, but + you can enable it with SDL_EventState() +*/ +#ifdef SDL_PROTOTYPES_ONLY +struct SDL_SysWMinfo; +typedef struct SDL_SysWMinfo SDL_SysWMinfo; +#else + +/* This is the structure for custom window manager events */ +#if defined(SDL_VIDEO_DRIVER_X11) +#if defined(__APPLE__) && defined(__MACH__) +/* conflicts with Quickdraw.h */ +#define Cursor X11Cursor +#endif + +#include +#include + +#if defined(__APPLE__) && defined(__MACH__) +/* matches the re-define above */ +#undef Cursor +#endif + +/* These are the various supported subsystems under UNIX */ +typedef enum { + SDL_SYSWM_X11 +} SDL_SYSWM_TYPE; + +/* The UNIX custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + SDL_SYSWM_TYPE subsystem; + union { + XEvent xevent; + } event; +}; + +/* The UNIX custom window manager information structure. + When this structure is returned, it holds information about which + low level system it is using, and will be one of SDL_SYSWM_TYPE. + */ +typedef struct SDL_SysWMinfo { + SDL_version version; + SDL_SYSWM_TYPE subsystem; + union { + struct { + Display *display; /* The X11 display */ + Window window; /* The X11 display window */ + /* These locking functions should be called around + any X11 functions using the display variable. + They lock the event thread, so should not be + called around event functions or from event filters. + */ + void (*lock_func)(void); + void (*unlock_func)(void); + + /* Introduced in SDL 1.0.2 */ + Window fswindow; /* The X11 fullscreen window */ + Window wmwindow; /* The X11 managed input window */ + } x11; + } info; +} SDL_SysWMinfo; + +#elif defined(SDL_VIDEO_DRIVER_NANOX) +#include + +/* The generic custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + int data; +}; + +/* The windows custom window manager information structure */ +typedef struct SDL_SysWMinfo { + SDL_version version ; + GR_WINDOW_ID window ; /* The display window */ +} SDL_SysWMinfo; + +#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI) +#define WIN32_LEAN_AND_MEAN +#include + +/* The windows custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + HWND hwnd; /* The window for the message */ + UINT msg; /* The type of message */ + WPARAM wParam; /* WORD message parameter */ + LPARAM lParam; /* LONG message parameter */ +}; + +/* The windows custom window manager information structure */ +typedef struct SDL_SysWMinfo { + SDL_version version; + HWND window; /* The Win32 display window */ + HGLRC hglrc; /* The OpenGL context, if any */ +} SDL_SysWMinfo; + +#elif defined(SDL_VIDEO_DRIVER_RISCOS) + +/* RISC OS custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + int eventCode; /* The window for the message */ + int pollBlock[64]; +}; + +/* The RISC OS custom window manager information structure */ +typedef struct SDL_SysWMinfo { + SDL_version version; + int wimpVersion; /* Wimp version running under */ + int taskHandle; /* The RISC OS task handle */ + int window; /* The RISC OS display window */ +} SDL_SysWMinfo; + +#elif defined(SDL_VIDEO_DRIVER_PHOTON) +#include +#include + +/* The QNX custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + int data; +}; + +/* The QNX custom window manager information structure */ +typedef struct SDL_SysWMinfo { + SDL_version version; + int data; +} SDL_SysWMinfo; + +#else + +/* The generic custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + int data; +}; + +/* The generic custom window manager information structure */ +typedef struct SDL_SysWMinfo { + SDL_version version; + int data; +} SDL_SysWMinfo; + +#endif /* video driver type */ + +#endif /* SDL_PROTOTYPES_ONLY */ + +/* Function prototypes */ +/* + * This function gives you custom hooks into the window manager information. + * It fills the structure pointed to by 'info' with custom information and + * returns 1 if the function is implemented. If it's not implemented, or + * the version member of the 'info' structure is invalid, it returns 0. + * + * You typically use this function like this: + * SDL_SysWMInfo info; + * SDL_VERSION(&info.version); + * if ( SDL_GetWMInfo(&info) ) { ... } + */ +extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_syswm_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_thread.h ./win32/dependencies/sdl/SDL_thread.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_thread.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_thread.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,119 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_thread_h +#define _SDL_thread_h + +/* Header for the SDL thread management routines + + These are independent of the other SDL routines. +*/ + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +/* Thread synchronization primitives */ +#include "SDL_mutex.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* The SDL thread structure, defined in SDL_thread.c */ +struct SDL_Thread; +typedef struct SDL_Thread SDL_Thread; + +/* Create a thread */ +#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__) +/* + We compile SDL into a DLL on OS/2. This means, that it's the DLL which + creates a new thread for the calling process with the SDL_CreateThread() + API. There is a problem with this, that only the RTL of the SDL.DLL will + be initialized for those threads, and not the RTL of the calling application! + To solve this, we make a little hack here. + We'll always use the caller's _beginthread() and _endthread() APIs to + start a new thread. This way, if it's the SDL.DLL which uses this API, + then the RTL of SDL.DLL will be used to create the new thread, and if it's + the application, then the RTL of the application will be used. + So, in short: + Always use the _beginthread() and _endthread() of the calling runtime library! +*/ +#define SDL_PASSED_BEGINTHREAD_ENDTHREAD +#ifndef _WIN32_WCE +#include /* This has _beginthread() and _endthread() defined! */ +#endif + +#ifdef __OS2__ +typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg); +typedef void (*pfnSDL_CurrentEndThread)(void); +#elif __GNUC__ +typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall *func)(void *), void *arg, + unsigned, unsigned *threadID); +typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +#else +typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall *func)(void *), void *arg, + unsigned, unsigned *threadID); +typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +#endif + +extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); + +#ifdef __OS2__ +#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread) +#elif defined(_WIN32_WCE) +#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL) +#else +#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex) +#endif +#else +extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data); +#endif + +/* Get the 32-bit thread identifier for the current thread */ +extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void); + +/* Get the 32-bit thread identifier for the specified thread, + equivalent to SDL_ThreadID() if the specified thread is NULL. + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread *thread); + +/* Wait for a thread to finish. + The return code for the thread function is placed in the area + pointed to by 'status', if 'status' is not NULL. + */ +extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status); + +/* Forcefully kill a thread without worrying about its state */ +extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread *thread); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_thread_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_timer.h ./win32/dependencies/sdl/SDL_timer.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_timer.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_timer.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,115 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_timer_h +#define _SDL_timer_h + +/* Header for the SDL time management routines */ + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* This is the OS scheduler timeslice, in milliseconds */ +#define SDL_TIMESLICE 10 + +/* This is the maximum resolution of the SDL timer on all platforms */ +#define TIMER_RESOLUTION 10 /* Experimentally determined */ + +/* Get the number of milliseconds since the SDL library initialization. + * Note that this value wraps if the program runs for more than ~49 days. + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); + +/* Wait a specified number of milliseconds before returning */ +extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); + +/* Function prototype for the timer callback function */ +typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); + +/* Set a callback to run after the specified number of milliseconds has + * elapsed. The callback function is passed the current timer interval + * and returns the next timer interval. If the returned value is the + * same as the one passed in, the periodic alarm continues, otherwise a + * new alarm is scheduled. If the callback returns 0, the periodic alarm + * is cancelled. + * + * To cancel a currently running timer, call SDL_SetTimer(0, NULL); + * + * The timer callback function may run in a different thread than your + * main code, and so shouldn't call any functions from within itself. + * + * The maximum resolution of this timer is 10 ms, which means that if + * you request a 16 ms timer, your callback will run approximately 20 ms + * later on an unloaded system. If you wanted to set a flag signaling + * a frame update at 30 frames per second (every 33 ms), you might set a + * timer for 30 ms: + * SDL_SetTimer((33/10)*10, flag_update); + * + * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init(). + * + * Under UNIX, you should not use raise or use SIGALRM and this function + * in the same program, as it is implemented using setitimer(). You also + * should not use this function in multi-threaded applications as signals + * to multi-threaded apps have undefined behavior in some implementations. + * + * This function returns 0 if successful, or -1 if there was an error. + */ +extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback); + +/* New timer API, supports multiple timers + * Written by Stephane Peter + */ + +/* Function prototype for the new timer callback function. + * The callback function is passed the current timer interval and returns + * the next timer interval. If the returned value is the same as the one + * passed in, the periodic alarm continues, otherwise a new alarm is + * scheduled. If the callback returns 0, the periodic alarm is cancelled. + */ +typedef Uint32 (SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param); + +/* Definition of the timer ID type */ +typedef struct _SDL_TimerID *SDL_TimerID; + +/* Add a new timer to the pool of timers already running. + Returns a timer ID, or NULL when an error occurs. + */ +extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); + +/* Remove one of the multiple timers knowing its ID. + * Returns a boolean value indicating success. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_timer_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_types.h ./win32/dependencies/sdl/SDL_types.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_types.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_types.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,24 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* DEPRECATED */ +#include "SDL_stdinc.h" diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_version.h ./win32/dependencies/sdl/SDL_version.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_version.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_version.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,85 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This header defines the current SDL version */ + +#ifndef _SDL_version_h +#define _SDL_version_h + +#include "SDL_stdinc.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL +*/ +#define SDL_MAJOR_VERSION 1 +#define SDL_MINOR_VERSION 2 +#define SDL_PATCHLEVEL 10 + +typedef struct SDL_version { + Uint8 major; + Uint8 minor; + Uint8 patch; +} SDL_version; + +/* This macro can be used to fill a version structure with the compile-time + * version of the SDL library. + */ +#define SDL_VERSION(X) \ +{ \ + (X)->major = SDL_MAJOR_VERSION; \ + (X)->minor = SDL_MINOR_VERSION; \ + (X)->patch = SDL_PATCHLEVEL; \ +} + +/* This macro turns the version numbers into a numeric value: + (1,2,3) -> (1203) + This assumes that there will never be more than 100 patchlevels +*/ +#define SDL_VERSIONNUM(X, Y, Z) \ + ((X)*1000 + (Y)*100 + (Z)) + +/* This is the version number macro for the current SDL version */ +#define SDL_COMPILEDVERSION \ + SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) + +/* This macro will evaluate to true if compiled with SDL at least X.Y.Z */ +#define SDL_VERSION_ATLEAST(X, Y, Z) \ + (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) + +/* This function gets the version of the dynamically linked SDL library. + it should NOT be used to fill a version structure, instead you should + use the SDL_Version() macro. + */ +extern DECLSPEC const SDL_version * SDLCALL SDL_Linked_Version(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_version_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_video.h ./win32/dependencies/sdl/SDL_video.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/SDL_video.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/SDL_video.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,889 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* Header file for access to the SDL raw framebuffer window */ + +#ifndef _SDL_video_h +#define _SDL_video_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_rwops.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Transparency definitions: These define alpha as the opacity of a surface */ +#define SDL_ALPHA_OPAQUE 255 +#define SDL_ALPHA_TRANSPARENT 0 + +/* Useful data types */ +typedef struct SDL_Rect { + Sint16 x, y; + Uint16 w, h; +} SDL_Rect; + +typedef struct SDL_Color { + Uint8 r; + Uint8 g; + Uint8 b; + Uint8 unused; +} SDL_Color; +#define SDL_Colour SDL_Color + +typedef struct SDL_Palette { + int ncolors; + SDL_Color *colors; +} SDL_Palette; + +/* Everything in the pixel format structure is read-only */ +typedef struct SDL_PixelFormat { + SDL_Palette *palette; + Uint8 BitsPerPixel; + Uint8 BytesPerPixel; + Uint8 Rloss; + Uint8 Gloss; + Uint8 Bloss; + Uint8 Aloss; + Uint8 Rshift; + Uint8 Gshift; + Uint8 Bshift; + Uint8 Ashift; + Uint32 Rmask; + Uint32 Gmask; + Uint32 Bmask; + Uint32 Amask; + + /* RGB color key information */ + Uint32 colorkey; + /* Alpha value information (per-surface alpha) */ + Uint8 alpha; +} SDL_PixelFormat; + +/* This structure should be treated as read-only, except for 'pixels', + which, if not NULL, contains the raw pixel data for the surface. +*/ +typedef struct SDL_Surface { + Uint32 flags; /* Read-only */ + SDL_PixelFormat *format; /* Read-only */ + int w, h; /* Read-only */ + Uint16 pitch; /* Read-only */ + void *pixels; /* Read-write */ + int offset; /* Private */ + + /* Hardware-specific surface info */ + struct private_hwdata *hwdata; + + /* clipping information */ + SDL_Rect clip_rect; /* Read-only */ + Uint32 unused1; /* for binary compatibility */ + + /* Allow recursive locks */ + Uint32 locked; /* Private */ + + /* info for fast blit mapping to other surfaces */ + struct SDL_BlitMap *map; /* Private */ + + /* format version, bumped at every change to invalidate blit maps */ + unsigned int format_version; /* Private */ + + /* Reference count -- used when freeing surface */ + int refcount; /* Read-mostly */ +} SDL_Surface; + +/* These are the currently supported flags for the SDL_surface */ +/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */ +#define SDL_SWSURFACE 0x00000000 /* Surface is in system memory */ +#define SDL_HWSURFACE 0x00000001 /* Surface is in video memory */ +#define SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */ +/* Available for SDL_SetVideoMode() */ +#define SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */ +#define SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */ +#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */ +#define SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */ +#define SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */ +#define SDL_OPENGLBLIT 0x0000000A /* Create an OpenGL rendering context and use it for blitting */ +#define SDL_RESIZABLE 0x00000010 /* This video mode may be resized */ +#define SDL_NOFRAME 0x00000020 /* No window caption or edge frame */ +/* Used internally (read-only) */ +#define SDL_HWACCEL 0x00000100 /* Blit uses hardware acceleration */ +#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */ +#define SDL_RLEACCELOK 0x00002000 /* Private flag */ +#define SDL_RLEACCEL 0x00004000 /* Surface is RLE encoded */ +#define SDL_SRCALPHA 0x00010000 /* Blit uses source alpha blending */ +#define SDL_PREALLOC 0x01000000 /* Surface uses preallocated memory */ + +/* Evaluates to true if the surface needs to be locked before access */ +#define SDL_MUSTLOCK(surface) \ + (surface->offset || \ + ((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0)) + +/* typedef for private surface blitting functions */ +typedef int (*SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect, + struct SDL_Surface *dst, SDL_Rect *dstrect); + + +/* Useful for determining the video hardware capabilities */ +typedef struct SDL_VideoInfo { + Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */ + Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */ + Uint32 UnusedBits1 :6; + Uint32 UnusedBits2 :1; + Uint32 blit_hw :1; /* Flag: Accelerated blits HW --> HW */ + Uint32 blit_hw_CC :1; /* Flag: Accelerated blits with Colorkey */ + Uint32 blit_hw_A :1; /* Flag: Accelerated blits with Alpha */ + Uint32 blit_sw :1; /* Flag: Accelerated blits SW --> HW */ + Uint32 blit_sw_CC :1; /* Flag: Accelerated blits with Colorkey */ + Uint32 blit_sw_A :1; /* Flag: Accelerated blits with Alpha */ + Uint32 blit_fill :1; /* Flag: Accelerated color fill */ + Uint32 UnusedBits3 :16; + Uint32 video_mem; /* The total amount of video memory (in K) */ + SDL_PixelFormat *vfmt; /* Value: The format of the video surface */ + int current_w; /* Value: The current video mode width */ + int current_h; /* Value: The current video mode height */ +} SDL_VideoInfo; + + +/* The most common video overlay formats. + For an explanation of these pixel formats, see: + http://www.webartz.com/fourcc/indexyuv.htm + + For information on the relationship between color spaces, see: + http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html + */ +#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ +#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ +#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ +#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ +#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ + +/* The YUV hardware video overlay */ +typedef struct SDL_Overlay { + Uint32 format; /* Read-only */ + int w, h; /* Read-only */ + int planes; /* Read-only */ + Uint16 *pitches; /* Read-only */ + Uint8 **pixels; /* Read-write */ + + /* Hardware-specific surface info */ + struct private_yuvhwfuncs *hwfuncs; + struct private_yuvhwdata *hwdata; + + /* Special flags */ + Uint32 hw_overlay :1; /* Flag: This overlay hardware accelerated? */ + Uint32 UnusedBits :31; +} SDL_Overlay; + + +/* Public enumeration for setting the OpenGL window attributes. */ +typedef enum { + SDL_GL_RED_SIZE, + SDL_GL_GREEN_SIZE, + SDL_GL_BLUE_SIZE, + SDL_GL_ALPHA_SIZE, + SDL_GL_BUFFER_SIZE, + SDL_GL_DOUBLEBUFFER, + SDL_GL_DEPTH_SIZE, + SDL_GL_STENCIL_SIZE, + SDL_GL_ACCUM_RED_SIZE, + SDL_GL_ACCUM_GREEN_SIZE, + SDL_GL_ACCUM_BLUE_SIZE, + SDL_GL_ACCUM_ALPHA_SIZE, + SDL_GL_STEREO, + SDL_GL_MULTISAMPLEBUFFERS, + SDL_GL_MULTISAMPLESAMPLES, + SDL_GL_ACCELERATED_VISUAL, + SDL_GL_SWAP_CONTROL +} SDL_GLattr; + +/* flags for SDL_SetPalette() */ +#define SDL_LOGPAL 0x01 +#define SDL_PHYSPAL 0x02 + +/* Function prototypes */ + +/* These functions are used internally, and should not be used unless you + * have a specific need to specify the video driver you want to use. + * You should normally use SDL_Init() or SDL_InitSubSystem(). + * + * SDL_VideoInit() initializes the video subsystem -- sets up a connection + * to the window manager, etc, and determines the current video mode and + * pixel format, but does not initialize a window or graphics mode. + * Note that event handling is activated by this routine. + * + * If you use both sound and video in your application, you need to call + * SDL_Init() before opening the sound device, otherwise under Win32 DirectX, + * you won't be able to set full-screen display modes. + */ +extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags); +extern DECLSPEC void SDLCALL SDL_VideoQuit(void); + +/* This function fills the given character buffer with the name of the + * video driver, and returns a pointer to it if the video driver has + * been initialized. It returns NULL if no driver has been initialized. + */ +extern DECLSPEC char * SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen); + +/* + * This function returns a pointer to the current display surface. + * If SDL is doing format conversion on the display surface, this + * function returns the publicly visible surface, not the real video + * surface. + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_GetVideoSurface(void); + +/* + * This function returns a read-only pointer to information about the + * video hardware. If this is called before SDL_SetVideoMode(), the 'vfmt' + * member of the returned structure will contain the pixel format of the + * "best" video mode. + */ +extern DECLSPEC const SDL_VideoInfo * SDLCALL SDL_GetVideoInfo(void); + +/* + * Check to see if a particular video mode is supported. + * It returns 0 if the requested mode is not supported under any bit depth, + * or returns the bits-per-pixel of the closest available mode with the + * given width and height. If this bits-per-pixel is different from the + * one used when setting the video mode, SDL_SetVideoMode() will succeed, + * but will emulate the requested bits-per-pixel with a shadow surface. + * + * The arguments to SDL_VideoModeOK() are the same ones you would pass to + * SDL_SetVideoMode() + */ +extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags); + +/* + * Return a pointer to an array of available screen dimensions for the + * given format and video flags, sorted largest to smallest. Returns + * NULL if there are no dimensions available for a particular format, + * or (SDL_Rect **)-1 if any dimension is okay for the given format. + * + * If 'format' is NULL, the mode list will be for the format given + * by SDL_GetVideoInfo()->vfmt + */ +extern DECLSPEC SDL_Rect ** SDLCALL SDL_ListModes(SDL_PixelFormat *format, Uint32 flags); + +/* + * Set up a video mode with the specified width, height and bits-per-pixel. + * + * If 'bpp' is 0, it is treated as the current display bits per pixel. + * + * If SDL_ANYFORMAT is set in 'flags', the SDL library will try to set the + * requested bits-per-pixel, but will return whatever video pixel format is + * available. The default is to emulate the requested pixel format if it + * is not natively available. + * + * If SDL_HWSURFACE is set in 'flags', the video surface will be placed in + * video memory, if possible, and you may have to call SDL_LockSurface() + * in order to access the raw framebuffer. Otherwise, the video surface + * will be created in system memory. + * + * If SDL_ASYNCBLIT is set in 'flags', SDL will try to perform rectangle + * updates asynchronously, but you must always lock before accessing pixels. + * SDL will wait for updates to complete before returning from the lock. + * + * If SDL_HWPALETTE is set in 'flags', the SDL library will guarantee + * that the colors set by SDL_SetColors() will be the colors you get. + * Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all + * of the colors exactly the way they are requested, and you should look + * at the video surface structure to determine the actual palette. + * If SDL cannot guarantee that the colors you request can be set, + * i.e. if the colormap is shared, then the video surface may be created + * under emulation in system memory, overriding the SDL_HWSURFACE flag. + * + * If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set + * a fullscreen video mode. The default is to create a windowed mode + * if the current graphics system has a window manager. + * If the SDL library is able to set a fullscreen video mode, this flag + * will be set in the surface that is returned. + * + * If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up + * two surfaces in video memory and swap between them when you call + * SDL_Flip(). This is usually slower than the normal single-buffering + * scheme, but prevents "tearing" artifacts caused by modifying video + * memory while the monitor is refreshing. It should only be used by + * applications that redraw the entire screen on every update. + * + * If SDL_RESIZABLE is set in 'flags', the SDL library will allow the + * window manager, if any, to resize the window at runtime. When this + * occurs, SDL will send a SDL_VIDEORESIZE event to you application, + * and you must respond to the event by re-calling SDL_SetVideoMode() + * with the requested size (or another size that suits the application). + * + * If SDL_NOFRAME is set in 'flags', the SDL library will create a window + * without any title bar or frame decoration. Fullscreen video modes have + * this flag set automatically. + * + * This function returns the video framebuffer surface, or NULL if it fails. + * + * If you rely on functionality provided by certain video flags, check the + * flags of the returned surface to make sure that functionality is available. + * SDL will fall back to reduced functionality if the exact flags you wanted + * are not available. + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_SetVideoMode + (int width, int height, int bpp, Uint32 flags); + +/* + * Makes sure the given list of rectangles is updated on the given screen. + * If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire + * screen. + * These functions should not be called while 'screen' is locked. + */ +extern DECLSPEC void SDLCALL SDL_UpdateRects + (SDL_Surface *screen, int numrects, SDL_Rect *rects); +extern DECLSPEC void SDLCALL SDL_UpdateRect + (SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h); + +/* + * On hardware that supports double-buffering, this function sets up a flip + * and returns. The hardware will wait for vertical retrace, and then swap + * video buffers before the next video surface blit or lock will return. + * On hardware that doesn not support double-buffering, this is equivalent + * to calling SDL_UpdateRect(screen, 0, 0, 0, 0); + * The SDL_DOUBLEBUF flag must have been passed to SDL_SetVideoMode() when + * setting the video mode for this function to perform hardware flipping. + * This function returns 0 if successful, or -1 if there was an error. + */ +extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface *screen); + +/* + * Set the gamma correction for each of the color channels. + * The gamma values range (approximately) between 0.1 and 10.0 + * + * If this function isn't supported directly by the hardware, it will + * be emulated using gamma ramps, if available. If successful, this + * function returns 0, otherwise it returns -1. + */ +extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); + +/* + * Set the gamma translation table for the red, green, and blue channels + * of the video hardware. Each table is an array of 256 16-bit quantities, + * representing a mapping between the input and output for that channel. + * The input is the index into the array, and the output is the 16-bit + * gamma value at that index, scaled to the output color precision. + * + * You may pass NULL for any of the channels to leave it unchanged. + * If the call succeeds, it will return 0. If the display driver or + * hardware does not support gamma translation, or otherwise fails, + * this function will return -1. + */ +extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue); + +/* + * Retrieve the current values of the gamma translation tables. + * + * You must pass in valid pointers to arrays of 256 16-bit quantities. + * Any of the pointers may be NULL to ignore that channel. + * If the call succeeds, it will return 0. If the display driver or + * hardware does not support gamma translation, or otherwise fails, + * this function will return -1. + */ +extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue); + +/* + * Sets a portion of the colormap for the given 8-bit surface. If 'surface' + * is not a palettized surface, this function does nothing, returning 0. + * If all of the colors were set as passed to SDL_SetColors(), it will + * return 1. If not all the color entries were set exactly as given, + * it will return 0, and you should look at the surface palette to + * determine the actual color palette. + * + * When 'surface' is the surface associated with the current display, the + * display colormap will be updated with the requested colors. If + * SDL_HWPALETTE was set in SDL_SetVideoMode() flags, SDL_SetColors() + * will always return 1, and the palette is guaranteed to be set the way + * you desire, even if the window colormap has to be warped or run under + * emulation. + */ +extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface *surface, + SDL_Color *colors, int firstcolor, int ncolors); + +/* + * Sets a portion of the colormap for a given 8-bit surface. + * 'flags' is one or both of: + * SDL_LOGPAL -- set logical palette, which controls how blits are mapped + * to/from the surface, + * SDL_PHYSPAL -- set physical palette, which controls how pixels look on + * the screen + * Only screens have physical palettes. Separate change of physical/logical + * palettes is only possible if the screen has SDL_HWPALETTE set. + * + * The return value is 1 if all colours could be set as requested, and 0 + * otherwise. + * + * SDL_SetColors() is equivalent to calling this function with + * flags = (SDL_LOGPAL|SDL_PHYSPAL). + */ +extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags, + SDL_Color *colors, int firstcolor, + int ncolors); + +/* + * Maps an RGB triple to an opaque pixel value for a given pixel format + */ +extern DECLSPEC Uint32 SDLCALL SDL_MapRGB + (SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b); + +/* + * Maps an RGBA quadruple to a pixel value for a given pixel format + */ +extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(SDL_PixelFormat *format, + Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/* + * Maps a pixel value into the RGB components for a given pixel format + */ +extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, + Uint8 *r, Uint8 *g, Uint8 *b); + +/* + * Maps a pixel value into the RGBA components for a given pixel format + */ +extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, + Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/* + * Allocate and free an RGB surface (must be called after SDL_SetVideoMode) + * If the depth is 4 or 8 bits, an empty palette is allocated for the surface. + * If the depth is greater than 8 bits, the pixel format is set using the + * flags '[RGB]mask'. + * If the function runs out of memory, it will return NULL. + * + * The 'flags' tell what kind of surface to create. + * SDL_SWSURFACE means that the surface should be created in system memory. + * SDL_HWSURFACE means that the surface should be created in video memory, + * with the same format as the display surface. This is useful for surfaces + * that will not change much, to take advantage of hardware acceleration + * when being blitted to the display surface. + * SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with + * this surface, but you must always lock it before accessing the pixels. + * SDL will wait for current blits to finish before returning from the lock. + * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits. + * If the hardware supports acceleration of colorkey blits between + * two surfaces in video memory, SDL will try to place the surface in + * video memory. If this isn't possible or if there is no hardware + * acceleration available, the surface will be placed in system memory. + * SDL_SRCALPHA means that the surface will be used for alpha blits and + * if the hardware supports hardware acceleration of alpha blits between + * two surfaces in video memory, to place the surface in video memory + * if possible, otherwise it will be placed in system memory. + * If the surface is created in video memory, blits will be _much_ faster, + * but the surface format must be identical to the video surface format, + * and the only way to access the pixels member of the surface is to use + * the SDL_LockSurface() and SDL_UnlockSurface() calls. + * If the requested surface actually resides in video memory, SDL_HWSURFACE + * will be set in the flags member of the returned surface. If for some + * reason the surface could not be placed in video memory, it will not have + * the SDL_HWSURFACE flag set, and will be created in system memory instead. + */ +#define SDL_AllocSurface SDL_CreateRGBSurface +extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurface + (Uint32 flags, int width, int height, int depth, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); +extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, + int width, int height, int depth, int pitch, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); +extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface); + +/* + * SDL_LockSurface() sets up a surface for directly accessing the pixels. + * Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write + * to and read from 'surface->pixels', using the pixel format stored in + * 'surface->format'. Once you are done accessing the surface, you should + * use SDL_UnlockSurface() to release it. + * + * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates + * to 0, then you can read and write to the surface at any time, and the + * pixel format of the surface will not change. In particular, if the + * SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you + * will not need to lock the display surface before accessing it. + * + * No operating system or library calls should be made between lock/unlock + * pairs, as critical system locks may be held during this time. + * + * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked. + */ +extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface); +extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface); + +/* + * Load a surface from a seekable SDL data source (memory or file.) + * If 'freesrc' is non-zero, the source will be closed after being read. + * Returns the new surface, or NULL if there was an error. + * The new surface should be freed with SDL_FreeSurface(). + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc); + +/* Convenience macro -- load a surface from a file */ +#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1) + +/* + * Save a surface to a seekable SDL data source (memory or file.) + * If 'freedst' is non-zero, the source will be closed after being written. + * Returns 0 if successful or -1 if there was an error. + */ +extern DECLSPEC int SDLCALL SDL_SaveBMP_RW + (SDL_Surface *surface, SDL_RWops *dst, int freedst); + +/* Convenience macro -- save a surface to a file */ +#define SDL_SaveBMP(surface, file) \ + SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1) + +/* + * Sets the color key (transparent pixel) in a blittable surface. + * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), + * 'key' will be the transparent pixel in the source image of a blit. + * SDL_RLEACCEL requests RLE acceleration for the surface if present, + * and removes RLE acceleration if absent. + * If 'flag' is 0, this function clears any current color key. + * This function returns 0, or -1 if there was an error. + */ +extern DECLSPEC int SDLCALL SDL_SetColorKey + (SDL_Surface *surface, Uint32 flag, Uint32 key); + +/* + * This function sets the alpha value for the entire surface, as opposed to + * using the alpha component of each pixel. This value measures the range + * of transparency of the surface, 0 being completely transparent to 255 + * being completely opaque. An 'alpha' value of 255 causes blits to be + * opaque, the source pixels copied to the destination (the default). Note + * that per-surface alpha can be combined with colorkey transparency. + * + * If 'flag' is 0, alpha blending is disabled for the surface. + * If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface. + * OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the + * surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed. + * + * The 'alpha' parameter is ignored for surfaces that have an alpha channel. + */ +extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha); + +/* + * Sets the clipping rectangle for the destination surface in a blit. + * + * If the clip rectangle is NULL, clipping will be disabled. + * If the clip rectangle doesn't intersect the surface, the function will + * return SDL_FALSE and blits will be completely clipped. Otherwise the + * function returns SDL_TRUE and blits to the surface will be clipped to + * the intersection of the surface area and the clipping rectangle. + * + * Note that blits are automatically clipped to the edges of the source + * and destination surfaces. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect); + +/* + * Gets the clipping rectangle for the destination surface in a blit. + * 'rect' must be a pointer to a valid rectangle which will be filled + * with the correct values. + */ +extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect); + +/* + * Creates a new surface of the specified format, and then copies and maps + * the given surface to it so the blit of the converted surface will be as + * fast as possible. If this function fails, it returns NULL. + * + * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those + * semantics. You can also pass SDL_RLEACCEL in the flags parameter and + * SDL will try to RLE accelerate colorkey and alpha blits in the resulting + * surface. + * + * This function is used internally by SDL_DisplayFormat(). + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface + (SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags); + +/* + * This performs a fast blit from the source surface to the destination + * surface. It assumes that the source and destination rectangles are + * the same size. If either 'srcrect' or 'dstrect' are NULL, the entire + * surface (src or dst) is copied. The final blit rectangles are saved + * in 'srcrect' and 'dstrect' after all clipping is performed. + * If the blit is successful, it returns 0, otherwise it returns -1. + * + * The blit function should not be called on a locked surface. + * + * The blit semantics for surfaces with and without alpha and colorkey + * are defined as follows: + * + * RGBA->RGB: + * SDL_SRCALPHA set: + * alpha-blend (using alpha-channel). + * SDL_SRCCOLORKEY ignored. + * SDL_SRCALPHA not set: + * copy RGB. + * if SDL_SRCCOLORKEY set, only copy the pixels matching the + * RGB values of the source colour key, ignoring alpha in the + * comparison. + * + * RGB->RGBA: + * SDL_SRCALPHA set: + * alpha-blend (using the source per-surface alpha value); + * set destination alpha to opaque. + * SDL_SRCALPHA not set: + * copy RGB, set destination alpha to source per-surface alpha value. + * both: + * if SDL_SRCCOLORKEY set, only copy the pixels matching the + * source colour key. + * + * RGBA->RGBA: + * SDL_SRCALPHA set: + * alpha-blend (using the source alpha channel) the RGB values; + * leave destination alpha untouched. [Note: is this correct?] + * SDL_SRCCOLORKEY ignored. + * SDL_SRCALPHA not set: + * copy all of RGBA to the destination. + * if SDL_SRCCOLORKEY set, only copy the pixels matching the + * RGB values of the source colour key, ignoring alpha in the + * comparison. + * + * RGB->RGB: + * SDL_SRCALPHA set: + * alpha-blend (using the source per-surface alpha value). + * SDL_SRCALPHA not set: + * copy RGB. + * both: + * if SDL_SRCCOLORKEY set, only copy the pixels matching the + * source colour key. + * + * If either of the surfaces were in video memory, and the blit returns -2, + * the video memory was lost, so it should be reloaded with artwork and + * re-blitted: + while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) { + while ( SDL_LockSurface(image) < 0 ) + Sleep(10); + -- Write image pixels to image->pixels -- + SDL_UnlockSurface(image); + } + * This happens under DirectX 5.0 when the system switches away from your + * fullscreen application. The lock will also fail until you have access + * to the video memory again. + */ +/* You should call SDL_BlitSurface() unless you know exactly how SDL + blitting works internally and how to use the other blit functions. +*/ +#define SDL_BlitSurface SDL_UpperBlit + +/* This is the public blit function, SDL_BlitSurface(), and it performs + rectangle validation and clipping before passing it to SDL_LowerBlit() +*/ +extern DECLSPEC int SDLCALL SDL_UpperBlit + (SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect); +/* This is a semi-private blit function and it performs low-level surface + blitting only. +*/ +extern DECLSPEC int SDLCALL SDL_LowerBlit + (SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect); + +/* + * This function performs a fast fill of the given rectangle with 'color' + * The given rectangle is clipped to the destination surface clip area + * and the final fill rectangle is saved in the passed in pointer. + * If 'dstrect' is NULL, the whole surface will be filled with 'color' + * The color should be a pixel of the format used by the surface, and + * can be generated by the SDL_MapRGB() function. + * This function returns 0 on success, or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_FillRect + (SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); + +/* + * This function takes a surface and copies it to a new surface of the + * pixel format and colors of the video framebuffer, suitable for fast + * blitting onto the display surface. It calls SDL_ConvertSurface() + * + * If you want to take advantage of hardware colorkey or alpha blit + * acceleration, you should set the colorkey and alpha value before + * calling this function. + * + * If the conversion fails or runs out of memory, it returns NULL + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormat(SDL_Surface *surface); + +/* + * This function takes a surface and copies it to a new surface of the + * pixel format and colors of the video framebuffer (if possible), + * suitable for fast alpha blitting onto the display surface. + * The new surface will always have an alpha channel. + * + * If you want to take advantage of hardware colorkey or alpha blit + * acceleration, you should set the colorkey and alpha value before + * calling this function. + * + * If the conversion fails or runs out of memory, it returns NULL + */ +extern DECLSPEC SDL_Surface * SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *surface); + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* YUV video surface overlay functions */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* This function creates a video output overlay + Calling the returned surface an overlay is something of a misnomer because + the contents of the display surface underneath the area where the overlay + is shown is undefined - it may be overwritten with the converted YUV data. +*/ +extern DECLSPEC SDL_Overlay * SDLCALL SDL_CreateYUVOverlay(int width, int height, + Uint32 format, SDL_Surface *display); + +/* Lock an overlay for direct access, and unlock it when you are done */ +extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay *overlay); +extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay *overlay); + +/* Blit a video overlay to the display surface. + The contents of the video surface underneath the blit destination are + not defined. + The width and height of the destination rectangle may be different from + that of the overlay, but currently only 2x scaling is supported. +*/ +extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect); + +/* Free a video overlay */ +extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay *overlay); + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* OpenGL support functions. */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Dynamically load an OpenGL library, or the default one if path is NULL + * + * If you do this, you need to retrieve all of the GL functions used in + * your program from the dynamic library using SDL_GL_GetProcAddress(). + */ +extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path); + +/* + * Get the address of a GL function + */ +extern DECLSPEC void * SDLCALL SDL_GL_GetProcAddress(const char* proc); + +/* + * Set an attribute of the OpenGL subsystem before intialization. + */ +extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); + +/* + * Get an attribute of the OpenGL subsystem from the windowing + * interface, such as glX. This is of course different from getting + * the values from SDL's internal OpenGL subsystem, which only + * stores the values you request before initialization. + * + * Developers should track the values they pass into SDL_GL_SetAttribute + * themselves if they want to retrieve these values. + */ +extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int* value); + +/* + * Swap the OpenGL buffers, if double-buffering is supported. + */ +extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void); + +/* + * Internal functions that should not be called unless you have read + * and understood the source code for these functions. + */ +extern DECLSPEC void SDLCALL SDL_GL_UpdateRects(int numrects, SDL_Rect* rects); +extern DECLSPEC void SDLCALL SDL_GL_Lock(void); +extern DECLSPEC void SDLCALL SDL_GL_Unlock(void); + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* These functions allow interaction with the window manager, if any. */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Sets/Gets the title and icon text of the display window (UTF-8 encoded) + */ +extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title, const char *icon); +extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon); + +/* + * Sets the icon for the display window. + * This function must be called before the first call to SDL_SetVideoMode(). + * It takes an icon surface, and a mask in MSB format. + * If 'mask' is NULL, the entire icon surface will be used as the icon. + */ +extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); + +/* + * This function iconifies the window, and returns 1 if it succeeded. + * If the function succeeds, it generates an SDL_APPACTIVE loss event. + * This function is a noop and returns 0 in non-windowed environments. + */ +extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void); + +/* + * Toggle fullscreen mode without changing the contents of the screen. + * If the display surface does not require locking before accessing + * the pixel information, then the memory pointers will not change. + * + * If this function was able to toggle fullscreen mode (change from + * running in a window to fullscreen, or vice-versa), it will return 1. + * If it is not implemented, or fails, it returns 0. + * + * The next call to SDL_SetVideoMode() will set the mode fullscreen + * attribute based on the flags parameter - if SDL_FULLSCREEN is not + * set, then the display will be windowed by default where supported. + * + * This is currently only implemented in the X11 video driver. + */ +extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface *surface); + +/* + * This function allows you to set and query the input grab state of + * the application. It returns the new input grab state. + */ +typedef enum { + SDL_GRAB_QUERY = -1, + SDL_GRAB_OFF = 0, + SDL_GRAB_ON = 1, + SDL_GRAB_FULLSCREEN /* Used internally */ +} SDL_GrabMode; +/* + * Grabbing means that the mouse is confined to the application window, + * and nearly all keyboard input is passed directly to the application, + * and not interpreted by a window manager, if any. + */ +extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode); + +/* Not in public API at the moment - do not use! */ +extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_video_h */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/begin_code.h ./win32/dependencies/sdl/begin_code.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/begin_code.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/begin_code.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,150 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2004 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This file sets things up for C dynamic library function definitions, + static inlined functions, and structures aligned at 4-byte alignment. + If you don't like ugly C preprocessor code, don't look at this file. :) +*/ + +/* This shouldn't be nested -- included it around code only. */ +#ifdef _begin_code_h +#error Nested inclusion of begin_code.h +#endif +#define _begin_code_h + +/* Some compilers use a special export keyword */ +#ifndef DECLSPEC +# if defined(__BEOS__) +# if defined(__GNUC__) +# define DECLSPEC __declspec(dllexport) +# else +# define DECLSPEC __declspec(export) +# endif +# elif defined(__WIN32__) +# ifdef __BORLANDC__ +# ifdef BUILD_SDL +# define DECLSPEC +# else +# define DECLSPEC __declspec(dllimport) +# endif +# else +# define DECLSPEC __declspec(dllexport) +# endif +# elif defined(__OS2__) +# ifdef __WATCOMC__ +# ifdef BUILD_SDL +# define DECLSPEC __declspec(dllexport) +# else +# define DECLSPEC +# endif +# else +# define DECLSPEC +# endif +# else +# if defined(__GNUC__) && __GNUC__ >= 4 +# define DECLSPEC __attribute__ ((visibility("default"))) +# else +# define DECLSPEC +# endif +# endif +#endif + +/* By default SDL uses the C calling convention */ +#ifndef SDLCALL +#if defined(__WIN32__) && !defined(__GNUC__) +#define SDLCALL __cdecl +#else +#ifdef __OS2__ +/* But on OS/2, we use the _System calling convention */ +/* to be compatible with every compiler */ +#define SDLCALL _System +#else +#define SDLCALL +#endif +#endif +#endif /* SDLCALL */ + +/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ +#ifdef __SYMBIAN32__ +#undef DECLSPEC +#define DECLSPEC +#endif /* __SYMBIAN32__ */ + +/* Force structure packing at 4 byte alignment. + This is necessary if the header is included in code which has structure + packing set to an alternate value, say for loading structures from disk. + The packing is reset to the previous value in close_code.h + */ +#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) +#ifdef _MSC_VER +#pragma warning(disable: 4103) +#endif +#ifdef __BORLANDC__ +#pragma nopackwarning +#endif +#pragma pack(push,4) +#elif (defined(__MWERKS__) && defined(__MACOS__)) +#pragma options align=mac68k4byte +#pragma enumsalwaysint on +#endif /* Compiler needs structure packing set */ + +/* Set up compiler-specific options for inlining functions */ +#ifndef SDL_INLINE_OKAY +#ifdef __GNUC__ +#define SDL_INLINE_OKAY +#else +/* Add any special compiler-specific cases here */ +#if defined(_MSC_VER) || defined(__BORLANDC__) || \ + defined(__DMC__) || defined(__SC__) || \ + defined(__WATCOMC__) || defined(__LCC__) || \ + defined(__DECC) +#ifndef __inline__ +#define __inline__ __inline +#endif +#define SDL_INLINE_OKAY +#else +#if !defined(__MRC__) && !defined(_SGI_SOURCE) +#define __inline__ inline +#define SDL_INLINE_OKAY +#endif /* Not a funky compiler */ +#endif /* Visual C++ */ +#endif /* GNU C */ +#endif /* SDL_INLINE_OKAY */ + +/* If inlining isn't supported, remove "__inline__", turning static + inlined functions into static functions (resulting in code bloat + in all files which include the offending header files) +*/ +#ifndef SDL_INLINE_OKAY +#define __inline__ +#endif + +/* Apparently this is needed by several Windows compilers */ +#if !defined(__MACH__) +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif /* NULL */ +#endif /* ! Mac OS X - breaks precompiled headers */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/close_code.h ./win32/dependencies/sdl/close_code.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/sdl/close_code.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/sdl/close_code.h 2006-06-25 04:59:05 +0900 @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2004 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This file reverses the effects of begin_code.h and should be included + after you finish any function and structure declarations in your headers +*/ + +#undef _begin_code_h + +/* Reset structure packing at previous byte alignment */ +#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__) +#ifdef __BORLANDC__ +#pragma nopackwarning +#endif +#if (defined(__MWERKS__) && defined(__MACOS__)) +#pragma options align=reset +#pragma enumsalwaysint reset +#else +#pragma pack(pop) +#endif +#endif /* Compiler needs structure packing set */ + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/.cvsignore ./win32/dependencies/zlib/.cvsignore --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/.cvsignore 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/.cvsignore 2006-05-14 01:42:49 +0900 @@ -0,0 +1,3 @@ +zlib.vcproj.A2.Spacy.user +debug +release \ No newline at end of file diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/adler32.c ./win32/dependencies/zlib/adler32.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/adler32.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/adler32.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,149 @@ +/* adler32.c -- compute the Adler-32 checksum of a data stream + * Copyright (C) 1995-2004 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: adler32.c,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +#define BASE 65521UL /* largest prime smaller than 65536 */ +#define NMAX 5552 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ + +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +/* use NO_DIVIDE if your processor does not do division in hardware */ +#ifdef NO_DIVIDE +# define MOD(a) \ + do { \ + if (a >= (BASE << 16)) a -= (BASE << 16); \ + if (a >= (BASE << 15)) a -= (BASE << 15); \ + if (a >= (BASE << 14)) a -= (BASE << 14); \ + if (a >= (BASE << 13)) a -= (BASE << 13); \ + if (a >= (BASE << 12)) a -= (BASE << 12); \ + if (a >= (BASE << 11)) a -= (BASE << 11); \ + if (a >= (BASE << 10)) a -= (BASE << 10); \ + if (a >= (BASE << 9)) a -= (BASE << 9); \ + if (a >= (BASE << 8)) a -= (BASE << 8); \ + if (a >= (BASE << 7)) a -= (BASE << 7); \ + if (a >= (BASE << 6)) a -= (BASE << 6); \ + if (a >= (BASE << 5)) a -= (BASE << 5); \ + if (a >= (BASE << 4)) a -= (BASE << 4); \ + if (a >= (BASE << 3)) a -= (BASE << 3); \ + if (a >= (BASE << 2)) a -= (BASE << 2); \ + if (a >= (BASE << 1)) a -= (BASE << 1); \ + if (a >= BASE) a -= BASE; \ + } while (0) +# define MOD4(a) \ + do { \ + if (a >= (BASE << 4)) a -= (BASE << 4); \ + if (a >= (BASE << 3)) a -= (BASE << 3); \ + if (a >= (BASE << 2)) a -= (BASE << 2); \ + if (a >= (BASE << 1)) a -= (BASE << 1); \ + if (a >= BASE) a -= BASE; \ + } while (0) +#else +# define MOD(a) a %= BASE +# define MOD4(a) a %= BASE +#endif + +/* ========================================================================= */ +uLong ZEXPORT adler32(adler, buf, len) + uLong adler; + const Bytef *buf; + uInt len; +{ + unsigned long sum2; + unsigned n; + + /* split Adler-32 into component sums */ + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; + + /* in case user likes doing a byte at a time, keep it fast */ + if (len == 1) { + adler += buf[0]; + if (adler >= BASE) + adler -= BASE; + sum2 += adler; + if (sum2 >= BASE) + sum2 -= BASE; + return adler | (sum2 << 16); + } + + /* initial Adler-32 value (deferred check for len == 1 speed) */ + if (buf == Z_NULL) + return 1L; + + /* in case short lengths are provided, keep it somewhat fast */ + if (len < 16) { + while (len--) { + adler += *buf++; + sum2 += adler; + } + if (adler >= BASE) + adler -= BASE; + MOD4(sum2); /* only added so many BASE's */ + return adler | (sum2 << 16); + } + + /* do length NMAX blocks -- requires just one modulo operation */ + while (len >= NMAX) { + len -= NMAX; + n = NMAX / 16; /* NMAX is divisible by 16 */ + do { + DO16(buf); /* 16 sums unrolled */ + buf += 16; + } while (--n); + MOD(adler); + MOD(sum2); + } + + /* do remaining bytes (less than NMAX, still just one modulo) */ + if (len) { /* avoid modulos if none remaining */ + while (len >= 16) { + len -= 16; + DO16(buf); + buf += 16; + } + while (len--) { + adler += *buf++; + sum2 += adler; + } + MOD(adler); + MOD(sum2); + } + + /* return recombined sums */ + return adler | (sum2 << 16); +} + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off_t len2; +{ + unsigned long sum1; + unsigned long sum2; + unsigned rem; + + /* the derivation of this formula is left as an exercise for the reader */ + rem = (unsigned)(len2 % BASE); + sum1 = adler1 & 0xffff; + sum2 = rem * sum1; + MOD(sum2); + sum1 += (adler2 & 0xffff) + BASE - 1; + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; + if (sum1 > BASE) sum1 -= BASE; + if (sum1 > BASE) sum1 -= BASE; + if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); + if (sum2 > BASE) sum2 -= BASE; + return sum1 | (sum2 << 16); +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/compress.c ./win32/dependencies/zlib/compress.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/compress.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/compress.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,79 @@ +/* compress.c -- compress a memory buffer + * Copyright (C) 1995-2003 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: compress.c,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; + int level; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; +#ifdef MAXSEG_64K + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; +#endif + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = deflateInit(&stream, level); + if (err != Z_OK) return err; + + err = deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + deflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = deflateEnd(&stream); + return err; +} + +/* =========================================================================== + */ +int ZEXPORT compress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); +} + +/* =========================================================================== + If the default memLevel or windowBits for deflateInit() is changed, then + this function needs to be updated. + */ +uLong ZEXPORT compressBound (sourceLen) + uLong sourceLen; +{ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/crc32.c ./win32/dependencies/zlib/crc32.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/crc32.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/crc32.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,423 @@ +/* crc32.c -- compute the CRC-32 of a data stream + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Thanks to Rodney Brown for his contribution of faster + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing + * tables for updating the shift register in one step with three exclusive-ors + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + */ + +/* @(#) $Id: crc32.c,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +/* + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore + protection on the static variables used to control the first-use generation + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should + first call get_crc_table() to initialize the tables before allowing more than + one thread to use crc32(). + */ + +#ifdef MAKECRCH +# include +# ifndef DYNAMIC_CRC_TABLE +# define DYNAMIC_CRC_TABLE +# endif /* !DYNAMIC_CRC_TABLE */ +#endif /* MAKECRCH */ + +#include "zutil.h" /* for STDC and FAR definitions */ + +#define local static + +/* Find a four-byte integer type for crc32_little() and crc32_big(). */ +#ifndef NOBYFOUR +# ifdef STDC /* need ANSI C limits.h to determine sizes */ +# include +# define BYFOUR +# if (UINT_MAX == 0xffffffffUL) + typedef unsigned int u4; +# else +# if (ULONG_MAX == 0xffffffffUL) + typedef unsigned long u4; +# else +# if (USHRT_MAX == 0xffffffffUL) + typedef unsigned short u4; +# else +# undef BYFOUR /* can't find a four-byte integer type! */ +# endif +# endif +# endif +# endif /* STDC */ +#endif /* !NOBYFOUR */ + +/* Definitions for doing the crc four data bytes at a time. */ +#ifdef BYFOUR +# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \ + (((w)&0xff00)<<8)+(((w)&0xff)<<24)) + local unsigned long crc32_little OF((unsigned long, + const unsigned char FAR *, unsigned)); + local unsigned long crc32_big OF((unsigned long, + const unsigned char FAR *, unsigned)); +# define TBLS 8 +#else +# define TBLS 1 +#endif /* BYFOUR */ + +/* Local functions for crc concatenation */ +local unsigned long gf2_matrix_times OF((unsigned long *mat, + unsigned long vec)); +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); + +#ifdef DYNAMIC_CRC_TABLE + +local volatile int crc_table_empty = 1; +local unsigned long FAR crc_table[TBLS][256]; +local void make_crc_table OF((void)); +#ifdef MAKECRCH + local void write_table OF((FILE *, const unsigned long FAR *)); +#endif /* MAKECRCH */ +/* + Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. If we call the above polynomial p, and represent a byte as the + polynomial q, also with the lowest power in the most significant bit (so the + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, + where a mod b means the remainder after dividing a by b. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + The first table is simply the CRC of all possible eight bit values. This is + all the information needed to generate CRCs on data a byte at a time for all + combinations of CRC register values and incoming bytes. The remaining tables + allow for word-at-a-time CRC calculation for both big-endian and little- + endian machines, where a word is four bytes. +*/ +local void make_crc_table() +{ + unsigned long c; + int n, k; + unsigned long poly; /* polynomial exclusive-or pattern */ + /* terms of polynomial defining this crc (except x^32): */ + static volatile int first = 1; /* flag to limit concurrent making */ + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + /* See if another task is already doing this (not thread-safe, but better + than nothing -- significantly reduces duration of vulnerability in + case the advice about DYNAMIC_CRC_TABLE is ignored) */ + if (first) { + first = 0; + + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ + poly = 0UL; + for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) + poly |= 1UL << (31 - p[n]); + + /* generate a crc for every 8-bit value */ + for (n = 0; n < 256; n++) { + c = (unsigned long)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[0][n] = c; + } + +#ifdef BYFOUR + /* generate crc for each value followed by one, two, and three zeros, + and then the byte reversal of those as well as the first table */ + for (n = 0; n < 256; n++) { + c = crc_table[0][n]; + crc_table[4][n] = REV(c); + for (k = 1; k < 4; k++) { + c = crc_table[0][c & 0xff] ^ (c >> 8); + crc_table[k][n] = c; + crc_table[k + 4][n] = REV(c); + } + } +#endif /* BYFOUR */ + + crc_table_empty = 0; + } + else { /* not first */ + /* wait for the other guy to finish (not efficient, but rare) */ + while (crc_table_empty) + ; + } + +#ifdef MAKECRCH + /* write out CRC tables to crc32.h */ + { + FILE *out; + + out = fopen("crc32.h", "w"); + if (out == NULL) return; + fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); + fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); + fprintf(out, "local const unsigned long FAR "); + fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); + write_table(out, crc_table[0]); +# ifdef BYFOUR + fprintf(out, "#ifdef BYFOUR\n"); + for (k = 1; k < 8; k++) { + fprintf(out, " },\n {\n"); + write_table(out, crc_table[k]); + } + fprintf(out, "#endif\n"); +# endif /* BYFOUR */ + fprintf(out, " }\n};\n"); + fclose(out); + } +#endif /* MAKECRCH */ +} + +#ifdef MAKECRCH +local void write_table(out, table) + FILE *out; + const unsigned long FAR *table; +{ + int n; + + for (n = 0; n < 256; n++) + fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], + n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); +} +#endif /* MAKECRCH */ + +#else /* !DYNAMIC_CRC_TABLE */ +/* ======================================================================== + * Tables of CRC-32s of all single-byte values, made by make_crc_table(). + */ +#include "crc32.h" +#endif /* DYNAMIC_CRC_TABLE */ + +/* ========================================================================= + * This function can be used by asm versions of crc32() + */ +const unsigned long FAR * ZEXPORT get_crc_table() +{ +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + return (const unsigned long FAR *)crc_table; +} + +/* ========================================================================= */ +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 + +/* ========================================================================= */ +unsigned long ZEXPORT crc32(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + if (buf == Z_NULL) return 0UL; + +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + +#ifdef BYFOUR + if (sizeof(void *) == sizeof(ptrdiff_t)) { + u4 endian; + + endian = 1; + if (*((unsigned char *)(&endian))) + return crc32_little(crc, buf, len); + else + return crc32_big(crc, buf, len); + } +#endif /* BYFOUR */ + crc = crc ^ 0xffffffffUL; + while (len >= 8) { + DO8; + len -= 8; + } + if (len) do { + DO1; + } while (--len); + return crc ^ 0xffffffffUL; +} + +#ifdef BYFOUR + +/* ========================================================================= */ +#define DOLIT4 c ^= *buf4++; \ + c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ + crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 + +/* ========================================================================= */ +local unsigned long crc32_little(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = (u4)crc; + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + while (len >= 32) { + DOLIT32; + len -= 32; + } + while (len >= 4) { + DOLIT4; + len -= 4; + } + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + } while (--len); + c = ~c; + return (unsigned long)c; +} + +/* ========================================================================= */ +#define DOBIG4 c ^= *++buf4; \ + c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ + crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 + +/* ========================================================================= */ +local unsigned long crc32_big(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = REV((u4)crc); + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + buf4--; + while (len >= 32) { + DOBIG32; + len -= 32; + } + while (len >= 4) { + DOBIG4; + len -= 4; + } + buf4++; + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + } while (--len); + c = ~c; + return (unsigned long)(REV(c)); +} + +#endif /* BYFOUR */ + +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ + +/* ========================================================================= */ +local unsigned long gf2_matrix_times(mat, vec) + unsigned long *mat; + unsigned long vec; +{ + unsigned long sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* ========================================================================= */ +local void gf2_matrix_square(square, mat) + unsigned long *square; + unsigned long *mat; +{ + int n; + + for (n = 0; n < GF2_DIM; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off_t len2; +{ + int n; + unsigned long row; + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ + + /* degenerate case */ + if (len2 == 0) + return crc1; + + /* put operator for one zero bit in odd */ + odd[0] = 0xedb88320L; /* CRC-32 polynomial */ + row = 1; + for (n = 1; n < GF2_DIM; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* apply len2 zeros to crc1 (first square will put the operator for one + zero byte, eight zero bits, in even) */ + do { + /* apply zeros operator for this bit of len2 */ + gf2_matrix_square(even, odd); + if (len2 & 1) + crc1 = gf2_matrix_times(even, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + if (len2 == 0) + break; + + /* another iteration of the loop with odd and even swapped */ + gf2_matrix_square(odd, even); + if (len2 & 1) + crc1 = gf2_matrix_times(odd, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + } while (len2 != 0); + + /* return combined crc */ + crc1 ^= crc2; + return crc1; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/crc32.h ./win32/dependencies/zlib/crc32.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/crc32.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/crc32.h 2006-05-13 06:27:36 +0900 @@ -0,0 +1,441 @@ +/* crc32.h -- tables for rapid CRC calculation + * Generated automatically by crc32.c + */ + +local const unsigned long FAR crc_table[TBLS][256] = +{ + { + 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, + 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, + 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, + 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, + 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, + 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, + 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, + 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, + 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, + 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, + 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, + 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, + 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, + 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, + 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, + 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, + 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, + 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, + 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, + 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, + 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, + 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, + 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, + 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, + 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, + 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, + 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, + 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, + 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, + 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, + 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, + 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, + 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, + 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, + 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, + 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, + 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, + 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, + 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, + 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, + 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, + 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, + 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, + 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, + 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, + 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, + 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, + 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, + 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, + 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, + 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, + 0x2d02ef8dUL +#ifdef BYFOUR + }, + { + 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, + 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, + 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, + 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, + 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, + 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, + 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, + 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, + 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, + 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, + 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, + 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, + 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, + 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, + 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, + 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, + 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, + 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, + 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, + 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, + 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, + 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, + 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, + 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, + 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, + 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, + 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, + 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, + 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, + 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, + 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, + 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, + 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, + 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, + 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, + 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, + 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, + 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, + 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, + 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, + 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, + 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, + 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, + 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, + 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, + 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, + 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, + 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, + 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, + 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, + 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, + 0x9324fd72UL + }, + { + 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, + 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, + 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, + 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, + 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, + 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, + 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, + 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, + 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, + 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, + 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, + 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, + 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, + 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, + 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, + 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, + 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, + 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, + 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, + 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, + 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, + 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, + 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, + 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, + 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, + 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, + 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, + 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, + 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, + 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, + 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, + 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, + 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, + 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, + 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, + 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, + 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, + 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, + 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, + 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, + 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, + 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, + 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, + 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, + 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, + 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, + 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, + 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, + 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, + 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, + 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, + 0xbe9834edUL + }, + { + 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, + 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, + 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, + 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, + 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, + 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, + 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, + 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, + 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, + 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, + 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, + 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, + 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, + 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, + 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, + 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, + 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, + 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, + 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, + 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, + 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, + 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, + 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, + 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, + 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, + 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, + 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, + 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, + 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, + 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, + 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, + 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, + 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, + 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, + 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, + 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, + 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, + 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, + 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, + 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, + 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, + 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, + 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, + 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, + 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, + 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, + 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, + 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, + 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, + 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, + 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, + 0xde0506f1UL + }, + { + 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, + 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, + 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, + 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, + 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, + 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, + 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, + 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, + 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, + 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, + 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, + 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, + 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, + 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, + 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, + 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, + 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, + 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, + 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, + 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, + 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, + 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, + 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, + 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, + 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, + 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, + 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, + 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, + 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, + 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, + 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, + 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, + 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, + 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, + 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, + 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, + 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, + 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, + 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, + 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, + 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, + 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, + 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, + 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, + 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, + 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, + 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, + 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, + 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, + 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, + 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, + 0x8def022dUL + }, + { + 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, + 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, + 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, + 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, + 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, + 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, + 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, + 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, + 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, + 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, + 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, + 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, + 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, + 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, + 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, + 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, + 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, + 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, + 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, + 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, + 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, + 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, + 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, + 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, + 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, + 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, + 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, + 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, + 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, + 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, + 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, + 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, + 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, + 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, + 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, + 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, + 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, + 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, + 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, + 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, + 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, + 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, + 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, + 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, + 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, + 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, + 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, + 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, + 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, + 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, + 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, + 0x72fd2493UL + }, + { + 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, + 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, + 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, + 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, + 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, + 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, + 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, + 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, + 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, + 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, + 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, + 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, + 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, + 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, + 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, + 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, + 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, + 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, + 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, + 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, + 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, + 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, + 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, + 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, + 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, + 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, + 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, + 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, + 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, + 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, + 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, + 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, + 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, + 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, + 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, + 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, + 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, + 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, + 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, + 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, + 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, + 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, + 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, + 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, + 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, + 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, + 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, + 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, + 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, + 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, + 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, + 0xed3498beUL + }, + { + 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, + 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, + 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, + 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, + 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, + 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, + 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, + 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, + 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, + 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, + 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, + 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, + 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, + 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, + 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, + 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, + 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, + 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, + 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, + 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, + 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, + 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, + 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, + 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, + 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, + 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, + 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, + 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, + 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, + 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, + 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, + 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, + 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, + 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, + 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, + 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, + 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, + 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, + 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, + 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, + 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, + 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, + 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, + 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, + 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, + 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, + 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, + 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, + 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, + 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, + 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, + 0xf10605deUL +#endif + } +}; diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/deflate.c ./win32/dependencies/zlib/deflate.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/deflate.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/deflate.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,1736 @@ +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGEMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many people for bug reports and testing. + * + * REFERENCES + * + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". + * Available in http://www.ietf.org/rfc/rfc1951.txt + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + */ + +/* @(#) $Id: deflate.c,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +#include "deflate.h" + +const char deflate_copyright[] = + " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* =========================================================================== + * Function prototypes. + */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + +local void fill_window OF((deflate_state *s)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +#ifndef FASTEST +local block_state deflate_slow OF((deflate_state *s, int flush)); +#endif +local void lm_init OF((deflate_state *s)); +local void putShortMSB OF((deflate_state *s, uInt b)); +local void flush_pending OF((z_streamp strm)); +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); +#ifndef FASTEST +#ifdef ASMV + void match_init OF((void)); /* asm code initialization */ + uInt longest_match OF((deflate_state *s, IPos cur_match)); +#else +local uInt longest_match OF((deflate_state *s, IPos cur_match)); +#endif +#endif +local uInt longest_match_fast OF((deflate_state *s, IPos cur_match)); + +#ifdef DEBUG +local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); +#endif + +/* =========================================================================== + * Local data + */ + +#define NIL 0 +/* Tail of hash chains */ + +#ifndef TOO_FAR +# define TOO_FAR 4096 +#endif +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +typedef struct config_s { + ush good_length; /* reduce lazy search above this match length */ + ush max_lazy; /* do not perform lazy search above this match length */ + ush nice_length; /* quit search above this match length */ + ush max_chain; + compress_func func; +} config; + +#ifdef FASTEST +local const config configuration_table[2] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ +#else +local const config configuration_table[10] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ +/* 2 */ {4, 5, 16, 8, deflate_fast}, +/* 3 */ {4, 6, 32, 32, deflate_fast}, + +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ +/* 5 */ {8, 16, 32, 32, deflate_slow}, +/* 6 */ {8, 16, 128, 128, deflate_slow}, +/* 7 */ {8, 32, 128, 256, deflate_slow}, +/* 8 */ {32, 128, 258, 1024, deflate_slow}, +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ +#endif + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +#ifndef NO_DUMMY_DECL +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ +#endif + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) + + +/* =========================================================================== + * Insert string str in the dictionary and set match_head to the previous head + * of the hash chain (the most recent string with same hash key). Return + * the previous length of the hash chain. + * If this file is compiled with -DFASTEST, the compression level is forced + * to 1, and no hash chains are maintained. + * IN assertion: all calls to to INSERT_STRING are made with consecutive + * input characters and the first MIN_MATCH bytes of str are valid + * (except for the last MIN_MATCH-1 bytes of the input file). + */ +#ifdef FASTEST +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#else +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#endif + +/* =========================================================================== + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). + * prev[] will be initialized on the fly. + */ +#define CLEAR_HASH(s) \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + +/* ========================================================================= */ +int ZEXPORT deflateInit_(strm, level, version, stream_size) + z_streamp strm; + int level; + const char *version; + int stream_size; +{ + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, version, stream_size); + /* To do: ignore strm->next_in if we use it as window */ +} + +/* ========================================================================= */ +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size) + z_streamp strm; + int level; + int method; + int windowBits; + int memLevel; + int strategy; + const char *version; + int stream_size; +{ + deflate_state *s; + int wrap = 1; + static const char my_version[] = ZLIB_VERSION; + + ushf *overlay; + /* We overlay pending_buf and d_buf+l_buf. This works since the average + * output size for (length,distance) codes is <= 24 bits. + */ + + if (version == Z_NULL || version[0] != my_version[0] || + stream_size != sizeof(z_stream)) { + return Z_VERSION_ERROR; + } + if (strm == Z_NULL) return Z_STREAM_ERROR; + + strm->msg = Z_NULL; + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + + if (windowBits < 0) { /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } +#ifdef GZIP + else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } +#endif + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; + + s->wrap = wrap; + s->gzhead = Z_NULL; + s->w_bits = windowBits; + s->w_size = 1 << s->w_bits; + s->w_mask = s->w_size - 1; + + s->hash_bits = memLevel + 7; + s->hash_size = 1 << s->hash_bits; + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); + + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + s->pending_buf = (uchf *) overlay; + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || + s->pending_buf == Z_NULL) { + s->status = FINISH_STATE; + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + deflateEnd (strm); + return Z_MEM_ERROR; + } + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + + s->level = level; + s->strategy = strategy; + s->method = (Byte)method; + + return deflateReset(strm); +} + +/* ========================================================================= */ +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) + z_streamp strm; + const Bytef *dictionary; + uInt dictLength; +{ + deflate_state *s; + uInt length = dictLength; + uInt n; + IPos hash_head = 0; + + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || + strm->state->wrap == 2 || + (strm->state->wrap == 1 && strm->state->status != INIT_STATE)) + return Z_STREAM_ERROR; + + s = strm->state; + if (s->wrap) + strm->adler = adler32(strm->adler, dictionary, dictLength); + + if (length < MIN_MATCH) return Z_OK; + if (length > MAX_DIST(s)) { + length = MAX_DIST(s); + dictionary += dictLength - length; /* use the tail of the dictionary */ + } + zmemcpy(s->window, dictionary, length); + s->strstart = length; + s->block_start = (long)length; + + /* Insert all strings in the hash table (except for the last two bytes). + * s->lookahead stays null, so s->ins_h will be recomputed at the next + * call of fill_window. + */ + s->ins_h = s->window[0]; + UPDATE_HASH(s, s->ins_h, s->window[1]); + for (n = 0; n <= length - MIN_MATCH; n++) { + INSERT_STRING(s, n, hash_head); + } + if (hash_head) hash_head = 0; /* to make compiler happy */ + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateReset (strm) + z_streamp strm; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { + return Z_STREAM_ERROR; + } + + strm->total_in = strm->total_out = 0; + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ + strm->data_type = Z_UNKNOWN; + + s = (deflate_state *)strm->state; + s->pending = 0; + s->pending_out = s->pending_buf; + + if (s->wrap < 0) { + s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ + } + s->status = s->wrap ? INIT_STATE : BUSY_STATE; + strm->adler = +#ifdef GZIP + s->wrap == 2 ? crc32(0L, Z_NULL, 0) : +#endif + adler32(0L, Z_NULL, 0); + s->last_flush = Z_NO_FLUSH; + + _tr_init(s); + lm_init(s); + + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateSetHeader (strm, head) + z_streamp strm; + gz_headerp head; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (strm->state->wrap != 2) return Z_STREAM_ERROR; + strm->state->gzhead = head; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePrime (strm, bits, value) + z_streamp strm; + int bits; + int value; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + strm->state->bi_valid = bits; + strm->state->bi_buf = (ush)(value & ((1 << bits) - 1)); + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateParams(strm, level, strategy) + z_streamp strm; + int level; + int strategy; +{ + deflate_state *s; + compress_func func; + int err = Z_OK; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + func = configuration_table[s->level].func; + + if (func != configuration_table[level].func && strm->total_in != 0) { + /* Flush the last buffer: */ + err = deflate(strm, Z_PARTIAL_FLUSH); + } + if (s->level != level) { + s->level = level; + s->max_lazy_match = configuration_table[level].max_lazy; + s->good_match = configuration_table[level].good_length; + s->nice_match = configuration_table[level].nice_length; + s->max_chain_length = configuration_table[level].max_chain; + } + s->strategy = strategy; + return err; +} + +/* ========================================================================= */ +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) + z_streamp strm; + int good_length; + int max_lazy; + int nice_length; + int max_chain; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + s->good_match = good_length; + s->max_lazy_match = max_lazy; + s->nice_match = nice_length; + s->max_chain_length = max_chain; + return Z_OK; +} + +/* ========================================================================= + * For the default windowBits of 15 and memLevel of 8, this function returns + * a close to exact, as well as small, upper bound on the compressed size. + * They are coded as constants here for a reason--if the #define's are + * changed, then this function needs to be changed as well. The return + * value for 15 and 8 only works for those exact settings. + * + * For any setting other than those defaults for windowBits and memLevel, + * the value returned is a conservative worst case for the maximum expansion + * resulting from using fixed blocks instead of stored blocks, which deflate + * can emit on compressed data for some combinations of the parameters. + * + * This function could be more sophisticated to provide closer upper bounds + * for every combination of windowBits and memLevel, as well as wrap. + * But even the conservative upper bound of about 14% expansion does not + * seem onerous for output buffer allocation. + */ +uLong ZEXPORT deflateBound(strm, sourceLen) + z_streamp strm; + uLong sourceLen; +{ + deflate_state *s; + uLong destLen; + + /* conservative upper bound */ + destLen = sourceLen + + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11; + + /* if can't get parameters, return conservative bound */ + if (strm == Z_NULL || strm->state == Z_NULL) + return destLen; + + /* if not default parameters, return conservative bound */ + s = strm->state; + if (s->w_bits != 15 || s->hash_bits != 8 + 7) + return destLen; + + /* default settings: return tight bound for that case */ + return compressBound(sourceLen); +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +local void putShortMSB (s, b) + deflate_state *s; + uInt b; +{ + put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b & 0xff)); +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->next_out buffer and copying into it. + * (See also read_buf()). + */ +local void flush_pending(strm) + z_streamp strm; +{ + unsigned len = strm->state->pending; + + if (len > strm->avail_out) len = strm->avail_out; + if (len == 0) return; + + zmemcpy(strm->next_out, strm->state->pending_out, len); + strm->next_out += len; + strm->state->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + strm->state->pending -= len; + if (strm->state->pending == 0) { + strm->state->pending_out = strm->state->pending_buf; + } +} + +/* ========================================================================= */ +int ZEXPORT deflate (strm, flush) + z_streamp strm; + int flush; +{ + int old_flush; /* value of flush param for previous deflate call */ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + flush > Z_FINISH || flush < 0) { + return Z_STREAM_ERROR; + } + s = strm->state; + + if (strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0) || + (s->status == FINISH_STATE && flush != Z_FINISH)) { + ERR_RETURN(strm, Z_STREAM_ERROR); + } + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + + s->strm = strm; /* just in case */ + old_flush = s->last_flush; + s->last_flush = flush; + + /* Write the header */ + if (s->status == INIT_STATE) { +#ifdef GZIP + if (s->wrap == 2) { + strm->adler = crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (s->gzhead == NULL) { + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, OS_CODE); + s->status = BUSY_STATE; + } + else { + put_byte(s, (s->gzhead->text ? 1 : 0) + + (s->gzhead->hcrc ? 2 : 0) + + (s->gzhead->extra == Z_NULL ? 0 : 4) + + (s->gzhead->name == Z_NULL ? 0 : 8) + + (s->gzhead->comment == Z_NULL ? 0 : 16) + ); + put_byte(s, (Byte)(s->gzhead->time & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, s->gzhead->os & 0xff); + if (s->gzhead->extra != NULL) { + put_byte(s, s->gzhead->extra_len & 0xff); + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); + } + if (s->gzhead->hcrc) + strm->adler = crc32(strm->adler, s->pending_buf, + s->pending); + s->gzindex = 0; + s->status = EXTRA_STATE; + } + } + else +#endif + { + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; + uInt level_flags; + + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) + level_flags = 0; + else if (s->level < 6) + level_flags = 1; + else if (s->level == 6) + level_flags = 2; + else + level_flags = 3; + header |= (level_flags << 6); + if (s->strstart != 0) header |= PRESET_DICT; + header += 31 - (header % 31); + + s->status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s->strstart != 0) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + strm->adler = adler32(0L, Z_NULL, 0); + } + } +#ifdef GZIP + if (s->status == EXTRA_STATE) { + if (s->gzhead->extra != NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) + break; + } + put_byte(s, s->gzhead->extra[s->gzindex]); + s->gzindex++; + } + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (s->gzindex == s->gzhead->extra_len) { + s->gzindex = 0; + s->status = NAME_STATE; + } + } + else + s->status = NAME_STATE; + } + if (s->status == NAME_STATE) { + if (s->gzhead->name != NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->name[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) { + s->gzindex = 0; + s->status = COMMENT_STATE; + } + } + else + s->status = COMMENT_STATE; + } + if (s->status == COMMENT_STATE) { + if (s->gzhead->comment != NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->comment[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) + s->status = HCRC_STATE; + } + else + s->status = HCRC_STATE; + } + if (s->status == HCRC_STATE) { + if (s->gzhead->hcrc) { + if (s->pending + 2 > s->pending_buf_size) + flush_pending(strm); + if (s->pending + 2 <= s->pending_buf_size) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + strm->adler = crc32(0L, Z_NULL, 0); + s->status = BUSY_STATE; + } + } + else + s->status = BUSY_STATE; + } +#endif + + /* Flush as much pending output as possible */ + if (s->pending != 0) { + flush_pending(strm); + if (strm->avail_out == 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s->last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm->avail_in == 0 && flush <= old_flush && + flush != Z_FINISH) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s->status == FINISH_STATE && strm->avail_in != 0) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm->avail_in != 0 || s->lookahead != 0 || + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + + bstate = (*(configuration_table[s->level].func))(s, flush); + + if (bstate == finish_started || bstate == finish_done) { + s->status = FINISH_STATE; + } + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate == block_done) { + if (flush == Z_PARTIAL_FLUSH) { + _tr_align(s); + } else { /* FULL_FLUSH or SYNC_FLUSH */ + _tr_stored_block(s, (char*)0, 0L, 0); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush == Z_FULL_FLUSH) { + CLEAR_HASH(s); /* forget history */ + } + } + flush_pending(strm); + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + Assert(strm->avail_out > 0, "bug2"); + + if (flush != Z_FINISH) return Z_OK; + if (s->wrap <= 0) return Z_STREAM_END; + + /* Write the trailer */ +#ifdef GZIP + if (s->wrap == 2) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); + put_byte(s, (Byte)(strm->total_in & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); + } + else +#endif + { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ + return s->pending != 0 ? Z_OK : Z_STREAM_END; +} + +/* ========================================================================= */ +int ZEXPORT deflateEnd (strm) + z_streamp strm; +{ + int status; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + + status = strm->state->status; + if (status != INIT_STATE && + status != EXTRA_STATE && + status != NAME_STATE && + status != COMMENT_STATE && + status != HCRC_STATE && + status != BUSY_STATE && + status != FINISH_STATE) { + return Z_STREAM_ERROR; + } + + /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); + TRY_FREE(strm, strm->state->window); + + ZFREE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state. + * To simplify the source, this is not supported for 16-bit MSDOS (which + * doesn't have enough memory anyway to duplicate compression states). + */ +int ZEXPORT deflateCopy (dest, source) + z_streamp dest; + z_streamp source; +{ +#ifdef MAXSEG_64K + return Z_STREAM_ERROR; +#else + deflate_state *ds; + deflate_state *ss; + ushf *overlay; + + + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { + return Z_STREAM_ERROR; + } + + ss = source->state; + + zmemcpy(dest, source, sizeof(z_stream)); + + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; + zmemcpy(ds, ss, sizeof(deflate_state)); + ds->strm = dest; + + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + ds->pending_buf = (uchf *) overlay; + + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || + ds->pending_buf == Z_NULL) { + deflateEnd (dest); + return Z_MEM_ERROR; + } + /* following zmemcpy do not work for 16-bit MSDOS */ + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); + zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + + ds->l_desc.dyn_tree = ds->dyn_ltree; + ds->d_desc.dyn_tree = ds->dyn_dtree; + ds->bl_desc.dyn_tree = ds->bl_tree; + + return Z_OK; +#endif /* MAXSEG_64K */ +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local int read_buf(strm, buf, size) + z_streamp strm; + Bytef *buf; + unsigned size; +{ + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, strm->next_in, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, strm->next_in, len); + } +#endif + zmemcpy(buf, strm->next_in, len); + strm->next_in += len; + strm->total_in += len; + + return (int)len; +} + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init (s) + deflate_state *s; +{ + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +#ifndef FASTEST +#ifdef ASMV + match_init(); /* initialize the asm code */ +#endif +#endif +} + +#ifndef FASTEST +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +#ifndef ASMV +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or + * match.S. The code will be functionally equivalent. + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + unsigned chain_length = s->max_chain_length;/* max hash chain length */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + int best_len = s->prev_length; /* best match length so far */ + int nice_match = s->nice_match; /* stop if match long enough */ + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? + s->strstart - (IPos)MAX_DIST(s) : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + Posf *prev = s->prev; + uInt wmask = s->w_mask; + +#ifdef UNALIGNED_OK + /* Compare two bytes at a time. Note: this is not always beneficial. + * Try with and without -DUNALIGNED_OK to check. + */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan+best_len-1); +#else + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end = scan[best_len]; +#endif + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s->prev_length >= s->good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + Assert(cur_match < s->strstart, "no future"); + match = s->window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) + /* This code assumes sizeof(unsigned short) == 2. Do not use + * UNALIGNED_OK if your compiler uses a different size. + */ + if (*(ushf*)(match+best_len-1) != scan_end || + *(ushf*)match != scan_start) continue; + + /* It is not necessary to compare scan[2] and match[2] since they are + * always equal when the other bytes match, given that the hash keys + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at + * strstart+3, +5, ... up to strstart+257. We check for insufficient + * lookahead only every 4th comparison; the 128th check will be made + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is + * necessary to put more guard bytes at the end of the window, or + * to check more often for insufficient lookahead. + */ + Assert(scan[2] == match[2], "scan[2]?"); + scan++, match++; + do { + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + scan < strend); + /* The funny "do {}" generates better code on most compilers */ + + /* Here, scan <= window+strstart+257 */ + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + if (*scan == *match) scan++; + + len = (MAX_MATCH - 1) - (int)(strend-scan); + scan = strend - (MAX_MATCH-1); + +#else /* UNALIGNED_OK */ + + if (match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + +#endif /* UNALIGNED_OK */ + + if (len > best_len) { + s->match_start = cur_match; + best_len = len; + if (len >= nice_match) break; +#ifdef UNALIGNED_OK + scan_end = *(ushf*)(scan+best_len-1); +#else + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; +#endif + } + } while ((cur_match = prev[cur_match & wmask]) > limit + && --chain_length != 0); + + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; + return s->lookahead; +} +#endif /* ASMV */ +#endif /* FASTEST */ + +/* --------------------------------------------------------------------------- + * Optimized version for level == 1 or strategy == Z_RLE only + */ +local uInt longest_match_fast(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + Assert(cur_match < s->strstart, "no future"); + + match = s->window + cur_match; + + /* Return failure if the match length is less than 2: + */ + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match += 2; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + + if (len < MIN_MATCH) return MIN_MATCH - 1; + + s->match_start = cur_match; + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; +} + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +local void check_match(s, start, match, length) + deflate_state *s; + IPos start, match; + int length; +{ + /* check that the match is indeed a match */ + if (zmemcmp(s->window + match, + s->window + start, length) != EQUAL) { + fprintf(stderr, " start %u, match %u, length %d\n", + start, match, length); + do { + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); + } while (--length != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { + fprintf(stderr,"\\[%d,%d]", start-match, length); + do { putc(s->window[start++], stderr); } while (--length != 0); + } +} +#else +# define check_match(s, start, match, length) +#endif /* DEBUG */ + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(s) + deflate_state *s; +{ + register unsigned n, m; + register Posf *p; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + /* %%% avoid this when Z_RLE */ + n = s->hash_size; + p = &s->head[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); + + n = wsize; +#ifndef FASTEST + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); +#endif + more += wsize; + } + if (s->strm->avail_in == 0) return; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead >= MIN_MATCH) { + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK_ONLY(s, eof) { \ + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (eof)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} + +/* Same but force premature exit if necessary. */ +#define FLUSH_BLOCK(s, eof) { \ + FLUSH_BLOCK_ONLY(s, eof); \ + if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \ +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +local block_state deflate_stored(s, flush) + deflate_state *s; + int flush; +{ + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + ulg max_block_size = 0xffff; + ulg max_start; + + if (max_block_size > s->pending_buf_size - 5) { + max_block_size = s->pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s->lookahead <= 1) { + + Assert(s->strstart < s->w_size+MAX_DIST(s) || + s->block_start >= (long)s->w_size, "slide too late"); + + fill_window(s); + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; + + if (s->lookahead == 0) break; /* flush the current block */ + } + Assert(s->block_start >= 0L, "block gone"); + + s->strstart += s->lookahead; + s->lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + max_start = s->block_start + max_block_size; + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s->lookahead = (uInt)(s->strstart - max_start); + s->strstart = (uInt)max_start; + FLUSH_BLOCK(s, 0); + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { + FLUSH_BLOCK(s, 0); + } + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +local block_state deflate_fast(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head = NIL; /* head of the hash chain */ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ +#ifdef FASTEST + if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || + (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { + s->match_length = longest_match_fast (s, hash_head); + } +#else + if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { + s->match_length = longest_match (s, hash_head); + } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { + s->match_length = longest_match_fast (s, hash_head); + } +#endif + /* longest_match() or longest_match_fast() sets match_start */ + } + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->match_start, s->match_length); + + _tr_tally_dist(s, s->strstart - s->match_start, + s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ +#ifndef FASTEST + if (s->match_length <= s->max_insert_length && + s->lookahead >= MIN_MATCH) { + s->match_length--; /* string at strstart already in table */ + do { + s->strstart++; + INSERT_STRING(s, s->strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s->match_length != 0); + s->strstart++; + } else +#endif + { + s->strstart += s->match_length; + s->match_length = 0; + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +#ifndef FASTEST +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +local block_state deflate_slow(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head = NIL; /* head of hash chain */ + int bflush; /* set if current block must be flushed */ + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + */ + s->prev_length = s->match_length, s->prev_match = s->match_start; + s->match_length = MIN_MATCH-1; + + if (hash_head != NIL && s->prev_length < s->max_lazy_match && + s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { + s->match_length = longest_match (s, hash_head); + } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { + s->match_length = longest_match_fast (s, hash_head); + } + /* longest_match() or longest_match_fast() sets match_start */ + + if (s->match_length <= 5 && (s->strategy == Z_FILTERED +#if TOO_FAR <= 32767 + || (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR) +#endif + )) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s->match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + check_match(s, s->strstart-1, s->prev_match, s->prev_length); + + _tr_tally_dist(s, s->strstart -1 - s->prev_match, + s->prev_length - MIN_MATCH, bflush); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s->lookahead -= s->prev_length-1; + s->prev_length -= 2; + do { + if (++s->strstart <= max_insert) { + INSERT_STRING(s, s->strstart, hash_head); + } + } while (--s->prev_length != 0); + s->match_available = 0; + s->match_length = MIN_MATCH-1; + s->strstart++; + + if (bflush) FLUSH_BLOCK(s, 0); + + } else if (s->match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + if (bflush) { + FLUSH_BLOCK_ONLY(s, 0); + } + s->strstart++; + s->lookahead--; + if (s->strm->avail_out == 0) return need_more; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s->match_available = 1; + s->strstart++; + s->lookahead--; + } + } + Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s->match_available) { + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + s->match_available = 0; + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} +#endif /* FASTEST */ + +#if 0 +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +local block_state deflate_rle(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + uInt run; /* length of run */ + uInt max; /* maximum length of run */ + uInt prev; /* byte at distance one to match */ + Bytef *scan; /* scan for end of run */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest encodable run. + */ + if (s->lookahead < MAX_MATCH) { + fill_window(s); + if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + run = 0; + if (s->strstart > 0) { /* if there is a previous byte, that is */ + max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; + scan = s->window + s->strstart - 1; + prev = *scan++; + do { + if (*scan++ != prev) + break; + } while (++run < max); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (run >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, run); + _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); + s->lookahead -= run; + s->strstart += run; + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} +#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/deflate.h ./win32/dependencies/zlib/deflate.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/deflate.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/deflate.h 2006-05-13 06:27:36 +0900 @@ -0,0 +1,331 @@ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2004 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: deflate.h,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +#ifndef DEFLATE_H +#define DEFLATE_H + +#include "zutil.h" + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer creation by deflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip encoding + should be left enabled. */ +#ifndef NO_GZIP +# define GZIP +#endif + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Bytef *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Bytef *pending_out; /* next pending byte to output to the stream */ + uInt pending; /* nb of bytes in the pending buffer */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + uInt gzindex; /* where in extra, name, or comment */ + Byte method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Bytef *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to supress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + int last_eob_len; /* bit length of EOB code for last block */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + + /* in trees.c */ +void _tr_init OF((deflate_state *s)); +int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); +void _tr_align OF((deflate_state *s)); +void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch _length_code[]; + extern uch _dist_code[]; +#else + extern const uch _length_code[]; + extern const uch _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif /* DEFLATE_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/gzio.c ./win32/dependencies/zlib/gzio.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/gzio.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/gzio.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,1026 @@ +/* gzio.c -- IO on .gz files + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. + */ + +/* @(#) $Id: gzio.c,v 1.1 2006/05/12 21:27:36 spacy51 Exp $ */ + +#include + +#include "zutil.h" + +#ifdef NO_DEFLATE /* for compatibility with old definition */ +# define NO_GZCOMPRESS +#endif + +#ifndef NO_DUMMY_DECL +struct internal_state {int dummy;}; /* for buggy compilers */ +#endif + +#ifndef Z_BUFSIZE +# ifdef MAXSEG_64K +# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */ +# else +# define Z_BUFSIZE 16384 +# endif +#endif +#ifndef Z_PRINTF_BUFSIZE +# define Z_PRINTF_BUFSIZE 4096 +#endif + +#ifdef __MVS__ +# pragma map (fdopen , "\174\174FDOPEN") + FILE *fdopen(int, const char *); +#endif + +#ifndef STDC +extern voidp malloc OF((uInt size)); +extern void free OF((voidpf ptr)); +#endif + +#define ALLOC(size) malloc(size) +#define TRYFREE(p) {if (p) free(p);} + +static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ + +/* gzip flag byte */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define RESERVED 0xE0 /* bits 5..7: reserved */ + +typedef struct gz_stream { + z_stream stream; + int z_err; /* error code for last stream operation */ + int z_eof; /* set if end of input file */ + FILE *file; /* .gz file */ + Byte *inbuf; /* input buffer */ + Byte *outbuf; /* output buffer */ + uLong crc; /* crc32 of uncompressed data */ + char *msg; /* error message */ + char *path; /* path name for debugging only */ + int transparent; /* 1 if input file is not a .gz file */ + char mode; /* 'w' or 'r' */ + z_off_t start; /* start of compressed data in file (header skipped) */ + z_off_t in; /* bytes into deflate or inflate */ + z_off_t out; /* bytes out of deflate or inflate */ + int back; /* one character push-back */ + int last; /* true if push-back is last character */ +} gz_stream; + + +local gzFile gz_open OF((const char *path, const char *mode, int fd)); +local int do_flush OF((gzFile file, int flush)); +local int get_byte OF((gz_stream *s)); +local void check_header OF((gz_stream *s)); +local int destroy OF((gz_stream *s)); +local void putLong OF((FILE *file, uLong x)); +local uLong getLong OF((gz_stream *s)); + +/* =========================================================================== + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb"). The file is given either by file descriptor + or path name (if fd == -1). + gz_open returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). +*/ +local gzFile gz_open (path, mode, fd) + const char *path; + const char *mode; + int fd; +{ + int err; + int level = Z_DEFAULT_COMPRESSION; /* compression level */ + int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ + char *p = (char*)mode; + gz_stream *s; + char fmode[80]; /* copy of mode, without the compression level */ + char *m = fmode; + + if (!path || !mode) return Z_NULL; + + s = (gz_stream *)ALLOC(sizeof(gz_stream)); + if (!s) return Z_NULL; + + s->stream.zalloc = (alloc_func)0; + s->stream.zfree = (free_func)0; + s->stream.opaque = (voidpf)0; + s->stream.next_in = s->inbuf = Z_NULL; + s->stream.next_out = s->outbuf = Z_NULL; + s->stream.avail_in = s->stream.avail_out = 0; + s->file = NULL; + s->z_err = Z_OK; + s->z_eof = 0; + s->in = 0; + s->out = 0; + s->back = EOF; + s->crc = crc32(0L, Z_NULL, 0); + s->msg = NULL; + s->transparent = 0; + + s->path = (char*)ALLOC(strlen(path)+1); + if (s->path == NULL) { + return destroy(s), (gzFile)Z_NULL; + } + strcpy(s->path, path); /* do this early for debugging */ + + s->mode = '\0'; + do { + if (*p == 'r') s->mode = 'r'; + if (*p == 'w' || *p == 'a') s->mode = 'w'; + if (*p >= '0' && *p <= '9') { + level = *p - '0'; + } else if (*p == 'f') { + strategy = Z_FILTERED; + } else if (*p == 'h') { + strategy = Z_HUFFMAN_ONLY; + } else if (*p == 'R') { + strategy = Z_RLE; + } else { + *m++ = *p; /* copy the mode */ + } + } while (*p++ && m != fmode + sizeof(fmode)); + if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; + + if (s->mode == 'w') { +#ifdef NO_GZCOMPRESS + err = Z_STREAM_ERROR; +#else + err = deflateInit2(&(s->stream), level, + Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy); + /* windowBits is passed < 0 to suppress zlib header */ + + s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); +#endif + if (err != Z_OK || s->outbuf == Z_NULL) { + return destroy(s), (gzFile)Z_NULL; + } + } else { + s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); + + err = inflateInit2(&(s->stream), -MAX_WBITS); + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are + * present after the compressed stream. + */ + if (err != Z_OK || s->inbuf == Z_NULL) { + return destroy(s), (gzFile)Z_NULL; + } + } + s->stream.avail_out = Z_BUFSIZE; + + errno = 0; + s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); + + if (s->file == NULL) { + return destroy(s), (gzFile)Z_NULL; + } + if (s->mode == 'w') { + /* Write a very simple .gz header: + */ + fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], + Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); + s->start = 10L; + /* We use 10L instead of ftell(s->file) to because ftell causes an + * fflush on some systems. This version of the library doesn't use + * start anyway in write mode, so this initialization is not + * necessary. + */ + } else { + check_header(s); /* skip the .gz header */ + s->start = ftell(s->file) - s->stream.avail_in; + } + + return (gzFile)s; +} + +/* =========================================================================== + Opens a gzip (.gz) file for reading or writing. +*/ +gzFile ZEXPORT gzopen (path, mode) + const char *path; + const char *mode; +{ + return gz_open (path, mode, -1); +} + +/* =========================================================================== + Associate a gzFile with the file descriptor fd. fd is not dup'ed here + to mimic the behavio(u)r of fdopen. +*/ +gzFile ZEXPORT gzdopen (fd, mode) + int fd; + const char *mode; +{ + char name[46]; /* allow for up to 128-bit integers */ + + if (fd < 0) return (gzFile)Z_NULL; + sprintf(name, "", fd); /* for debugging */ + + return gz_open (name, mode, fd); +} + +/* =========================================================================== + * Update the compression level and strategy + */ +int ZEXPORT gzsetparams (file, level, strategy) + gzFile file; + int level; + int strategy; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + /* Make room to allow flushing */ + if (s->stream.avail_out == 0) { + + s->stream.next_out = s->outbuf; + if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { + s->z_err = Z_ERRNO; + } + s->stream.avail_out = Z_BUFSIZE; + } + + return deflateParams (&(s->stream), level, strategy); +} + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ +local int get_byte(s) + gz_stream *s; +{ + if (s->z_eof) return EOF; + if (s->stream.avail_in == 0) { + errno = 0; + s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); + if (s->stream.avail_in == 0) { + s->z_eof = 1; + if (ferror(s->file)) s->z_err = Z_ERRNO; + return EOF; + } + s->stream.next_in = s->inbuf; + } + s->stream.avail_in--; + return *(s->stream.next_in)++; +} + +/* =========================================================================== + Check the gzip header of a gz_stream opened for reading. Set the stream + mode to transparent if the gzip magic header is not present; set s->err + to Z_DATA_ERROR if the magic header is present but the rest of the header + is incorrect. + IN assertion: the stream s has already been created sucessfully; + s->stream.avail_in is zero for the first time, but may be non-zero + for concatenated .gz files. +*/ +local void check_header(s) + gz_stream *s; +{ + int method; /* method byte */ + int flags; /* flags byte */ + uInt len; + int c; + + /* Assure two bytes in the buffer so we can peek ahead -- handle case + where first byte of header is at the end of the buffer after the last + gzip segment */ + len = s->stream.avail_in; + if (len < 2) { + if (len) s->inbuf[0] = s->stream.next_in[0]; + errno = 0; + len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); + if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; + s->stream.avail_in += len; + s->stream.next_in = s->inbuf; + if (s->stream.avail_in < 2) { + s->transparent = s->stream.avail_in; + return; + } + } + + /* Peek ahead to check the gzip magic header */ + if (s->stream.next_in[0] != gz_magic[0] || + s->stream.next_in[1] != gz_magic[1]) { + s->transparent = 1; + return; + } + s->stream.avail_in -= 2; + s->stream.next_in += 2; + + /* Check the rest of the gzip header */ + method = get_byte(s); + flags = get_byte(s); + if (method != Z_DEFLATED || (flags & RESERVED) != 0) { + s->z_err = Z_DATA_ERROR; + return; + } + + /* Discard time, xflags and OS code: */ + for (len = 0; len < 6; len++) (void)get_byte(s); + + if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ + len = (uInt)get_byte(s); + len += ((uInt)get_byte(s))<<8; + /* len is garbage if EOF but the loop below will quit anyway */ + while (len-- != 0 && get_byte(s) != EOF) ; + } + if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ + while ((c = get_byte(s)) != 0 && c != EOF) ; + } + if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ + while ((c = get_byte(s)) != 0 && c != EOF) ; + } + if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ + for (len = 0; len < 2; len++) (void)get_byte(s); + } + s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; +} + + /* =========================================================================== + * Cleanup then free the given gz_stream. Return a zlib error code. + Try freeing in the reverse order of allocations. + */ +local int destroy (s) + gz_stream *s; +{ + int err = Z_OK; + + if (!s) return Z_STREAM_ERROR; + + TRYFREE(s->msg); + + if (s->stream.state != NULL) { + if (s->mode == 'w') { +#ifdef NO_GZCOMPRESS + err = Z_STREAM_ERROR; +#else + err = deflateEnd(&(s->stream)); +#endif + } else if (s->mode == 'r') { + err = inflateEnd(&(s->stream)); + } + } + if (s->file != NULL && fclose(s->file)) { +#ifdef ESPIPE + if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ +#endif + err = Z_ERRNO; + } + if (s->z_err < 0) err = s->z_err; + + TRYFREE(s->inbuf); + TRYFREE(s->outbuf); + TRYFREE(s->path); + TRYFREE(s); + return err; +} + +/* =========================================================================== + Reads the given number of uncompressed bytes from the compressed file. + gzread returns the number of bytes actually read (0 for end of file). +*/ +int ZEXPORT gzread (file, buf, len) + gzFile file; + voidp buf; + unsigned len; +{ + gz_stream *s = (gz_stream*)file; + Bytef *start = (Bytef*)buf; /* starting point for crc computation */ + Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ + + if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; + + if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; + if (s->z_err == Z_STREAM_END) return 0; /* EOF */ + + next_out = (Byte*)buf; + s->stream.next_out = (Bytef*)buf; + s->stream.avail_out = len; + + if (s->stream.avail_out && s->back != EOF) { + *next_out++ = s->back; + s->stream.next_out++; + s->stream.avail_out--; + s->back = EOF; + s->out++; + start++; + if (s->last) { + s->z_err = Z_STREAM_END; + return 1; + } + } + + while (s->stream.avail_out != 0) { + + if (s->transparent) { + /* Copy first the lookahead bytes: */ + uInt n = s->stream.avail_in; + if (n > s->stream.avail_out) n = s->stream.avail_out; + if (n > 0) { + zmemcpy(s->stream.next_out, s->stream.next_in, n); + next_out += n; + s->stream.next_out = next_out; + s->stream.next_in += n; + s->stream.avail_out -= n; + s->stream.avail_in -= n; + } + if (s->stream.avail_out > 0) { + s->stream.avail_out -= + (uInt)fread(next_out, 1, s->stream.avail_out, s->file); + } + len -= s->stream.avail_out; + s->in += len; + s->out += len; + if (len == 0) s->z_eof = 1; + return (int)len; + } + if (s->stream.avail_in == 0 && !s->z_eof) { + + errno = 0; + s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); + if (s->stream.avail_in == 0) { + s->z_eof = 1; + if (ferror(s->file)) { + s->z_err = Z_ERRNO; + break; + } + } + s->stream.next_in = s->inbuf; + } + s->in += s->stream.avail_in; + s->out += s->stream.avail_out; + s->z_err = inflate(&(s->stream), Z_NO_FLUSH); + s->in -= s->stream.avail_in; + s->out -= s->stream.avail_out; + + if (s->z_err == Z_STREAM_END) { + /* Check CRC and original size */ + s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); + start = s->stream.next_out; + + if (getLong(s) != s->crc) { + s->z_err = Z_DATA_ERROR; + } else { + (void)getLong(s); + /* The uncompressed length returned by above getlong() may be + * different from s->out in case of concatenated .gz files. + * Check for such files: + */ + check_header(s); + if (s->z_err == Z_OK) { + inflateReset(&(s->stream)); + s->crc = crc32(0L, Z_NULL, 0); + } + } + } + if (s->z_err != Z_OK || s->z_eof) break; + } + s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); + + if (len == s->stream.avail_out && + (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)) + return -1; + return (int)(len - s->stream.avail_out); +} + + +/* =========================================================================== + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ +int ZEXPORT gzgetc(file) + gzFile file; +{ + unsigned char c; + + return gzread(file, &c, 1) == 1 ? c : -1; +} + + +/* =========================================================================== + Push one byte back onto the stream. +*/ +int ZEXPORT gzungetc(c, file) + int c; + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF; + s->back = c; + s->out--; + s->last = (s->z_err == Z_STREAM_END); + if (s->last) s->z_err = Z_OK; + s->z_eof = 0; + return c; +} + + +/* =========================================================================== + Reads bytes from the compressed file until len-1 characters are + read, or a newline character is read and transferred to buf, or an + end-of-file condition is encountered. The string is then terminated + with a null character. + gzgets returns buf, or Z_NULL in case of error. + + The current implementation is not optimized at all. +*/ +char * ZEXPORT gzgets(file, buf, len) + gzFile file; + char *buf; + int len; +{ + char *b = buf; + if (buf == Z_NULL || len <= 0) return Z_NULL; + + while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ; + *buf = '\0'; + return b == buf && len > 0 ? Z_NULL : b; +} + + +#ifndef NO_GZCOMPRESS +/* =========================================================================== + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of bytes actually written (0 in case of error). +*/ +int ZEXPORT gzwrite (file, buf, len) + gzFile file; + voidpc buf; + unsigned len; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + s->stream.next_in = (Bytef*)buf; + s->stream.avail_in = len; + + while (s->stream.avail_in != 0) { + + if (s->stream.avail_out == 0) { + + s->stream.next_out = s->outbuf; + if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { + s->z_err = Z_ERRNO; + break; + } + s->stream.avail_out = Z_BUFSIZE; + } + s->in += s->stream.avail_in; + s->out += s->stream.avail_out; + s->z_err = deflate(&(s->stream), Z_NO_FLUSH); + s->in -= s->stream.avail_in; + s->out -= s->stream.avail_out; + if (s->z_err != Z_OK) break; + } + s->crc = crc32(s->crc, (const Bytef *)buf, len); + + return (int)(len - s->stream.avail_in); +} + + +/* =========================================================================== + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). +*/ +#ifdef STDC +#include + +int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) +{ + char buf[Z_PRINTF_BUFSIZE]; + va_list va; + int len; + + buf[sizeof(buf) - 1] = 0; + va_start(va, format); +#ifdef NO_vsnprintf +# ifdef HAS_vsprintf_void + (void)vsprintf(buf, format, va); + va_end(va); + for (len = 0; len < sizeof(buf); len++) + if (buf[len] == 0) break; +# else + len = vsprintf(buf, format, va); + va_end(va); +# endif +#else +# ifdef HAS_vsnprintf_void + (void)vsnprintf(buf, sizeof(buf), format, va); + va_end(va); + len = strlen(buf); +# else + len = vsnprintf(buf, sizeof(buf), format, va); + va_end(va); +# endif +#endif + if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0) + return 0; + return gzwrite(file, buf, (unsigned)len); +} +#else /* not ANSI C */ + +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + gzFile file; + const char *format; + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; +{ + char buf[Z_PRINTF_BUFSIZE]; + int len; + + buf[sizeof(buf) - 1] = 0; +#ifdef NO_snprintf +# ifdef HAS_sprintf_void + sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + for (len = 0; len < sizeof(buf); len++) + if (buf[len] == 0) break; +# else + len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#else +# ifdef HAS_snprintf_void + snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + len = strlen(buf); +# else + len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#endif + if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0) + return 0; + return gzwrite(file, buf, len); +} +#endif + +/* =========================================================================== + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ +int ZEXPORT gzputc(file, c) + gzFile file; + int c; +{ + unsigned char cc = (unsigned char) c; /* required for big endian systems */ + + return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1; +} + + +/* =========================================================================== + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ +int ZEXPORT gzputs(file, s) + gzFile file; + const char *s; +{ + return gzwrite(file, (char*)s, (unsigned)strlen(s)); +} + + +/* =========================================================================== + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. +*/ +local int do_flush (file, flush) + gzFile file; + int flush; +{ + uInt len; + int done = 0; + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + s->stream.avail_in = 0; /* should be zero already anyway */ + + for (;;) { + len = Z_BUFSIZE - s->stream.avail_out; + + if (len != 0) { + if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { + s->z_err = Z_ERRNO; + return Z_ERRNO; + } + s->stream.next_out = s->outbuf; + s->stream.avail_out = Z_BUFSIZE; + } + if (done) break; + s->out += s->stream.avail_out; + s->z_err = deflate(&(s->stream), flush); + s->out -= s->stream.avail_out; + + /* Ignore the second of two consecutive flushes: */ + if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; + + /* deflate has finished flushing only when it hasn't used up + * all the available space in the output buffer: + */ + done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); + + if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; + } + return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; +} + +int ZEXPORT gzflush (file, flush) + gzFile file; + int flush; +{ + gz_stream *s = (gz_stream*)file; + int err = do_flush (file, flush); + + if (err) return err; + fflush(s->file); + return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; +} +#endif /* NO_GZCOMPRESS */ + +/* =========================================================================== + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error. + SEEK_END is not implemented, returns error. + In this version of the library, gzseek can be extremely slow. +*/ +z_off_t ZEXPORT gzseek (file, offset, whence) + gzFile file; + z_off_t offset; + int whence; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || whence == SEEK_END || + s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) { + return -1L; + } + + if (s->mode == 'w') { +#ifdef NO_GZCOMPRESS + return -1L; +#else + if (whence == SEEK_SET) { + offset -= s->in; + } + if (offset < 0) return -1L; + + /* At this point, offset is the number of zero bytes to write. */ + if (s->inbuf == Z_NULL) { + s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ + if (s->inbuf == Z_NULL) return -1L; + zmemzero(s->inbuf, Z_BUFSIZE); + } + while (offset > 0) { + uInt size = Z_BUFSIZE; + if (offset < Z_BUFSIZE) size = (uInt)offset; + + size = gzwrite(file, s->inbuf, size); + if (size == 0) return -1L; + + offset -= size; + } + return s->in; +#endif + } + /* Rest of function is for reading only */ + + /* compute absolute position */ + if (whence == SEEK_CUR) { + offset += s->out; + } + if (offset < 0) return -1L; + + if (s->transparent) { + /* map to fseek */ + s->back = EOF; + s->stream.avail_in = 0; + s->stream.next_in = s->inbuf; + if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; + + s->in = s->out = offset; + return offset; + } + + /* For a negative seek, rewind and use positive seek */ + if (offset >= s->out) { + offset -= s->out; + } else if (gzrewind(file) < 0) { + return -1L; + } + /* offset is now the number of bytes to skip. */ + + if (offset != 0 && s->outbuf == Z_NULL) { + s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); + if (s->outbuf == Z_NULL) return -1L; + } + if (offset && s->back != EOF) { + s->back = EOF; + s->out++; + offset--; + if (s->last) s->z_err = Z_STREAM_END; + } + while (offset > 0) { + int size = Z_BUFSIZE; + if (offset < Z_BUFSIZE) size = (int)offset; + + size = gzread(file, s->outbuf, (uInt)size); + if (size <= 0) return -1L; + offset -= size; + } + return s->out; +} + +/* =========================================================================== + Rewinds input file. +*/ +int ZEXPORT gzrewind (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'r') return -1; + + s->z_err = Z_OK; + s->z_eof = 0; + s->back = EOF; + s->stream.avail_in = 0; + s->stream.next_in = s->inbuf; + s->crc = crc32(0L, Z_NULL, 0); + if (!s->transparent) (void)inflateReset(&s->stream); + s->in = 0; + s->out = 0; + return fseek(s->file, s->start, SEEK_SET); +} + +/* =========================================================================== + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. +*/ +z_off_t ZEXPORT gztell (file) + gzFile file; +{ + return gzseek(file, 0L, SEEK_CUR); +} + +/* =========================================================================== + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ +int ZEXPORT gzeof (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + /* With concatenated compressed files that can have embedded + * crc trailers, z_eof is no longer the only/best indicator of EOF + * on a gz_stream. Handle end-of-stream error explicitly here. + */ + if (s == NULL || s->mode != 'r') return 0; + if (s->z_eof) return 1; + return s->z_err == Z_STREAM_END; +} + +/* =========================================================================== + Returns 1 if reading and doing so transparently, otherwise zero. +*/ +int ZEXPORT gzdirect (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'r') return 0; + return s->transparent; +} + +/* =========================================================================== + Outputs a long in LSB order to the given file +*/ +local void putLong (file, x) + FILE *file; + uLong x; +{ + int n; + for (n = 0; n < 4; n++) { + fputc((int)(x & 0xff), file); + x >>= 8; + } +} + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets z_err in case + of error. +*/ +local uLong getLong (s) + gz_stream *s; +{ + uLong x = (uLong)get_byte(s); + int c; + + x += ((uLong)get_byte(s))<<8; + x += ((uLong)get_byte(s))<<16; + c = get_byte(s); + if (c == EOF) s->z_err = Z_DATA_ERROR; + x += ((uLong)c)<<24; + return x; +} + +/* =========================================================================== + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. +*/ +int ZEXPORT gzclose (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL) return Z_STREAM_ERROR; + + if (s->mode == 'w') { +#ifdef NO_GZCOMPRESS + return Z_STREAM_ERROR; +#else + if (do_flush (file, Z_FINISH) != Z_OK) + return destroy((gz_stream*)file); + + putLong (s->file, s->crc); + putLong (s->file, (uLong)(s->in & 0xffffffff)); +#endif + } + return destroy((gz_stream*)file); +} + +#ifdef STDC +# define zstrerror(errnum) strerror(errnum) +#else +# define zstrerror(errnum) "" +#endif + +/* =========================================================================== + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ +const char * ZEXPORT gzerror (file, errnum) + gzFile file; + int *errnum; +{ + char *m; + gz_stream *s = (gz_stream*)file; + + if (s == NULL) { + *errnum = Z_STREAM_ERROR; + return (const char*)ERR_MSG(Z_STREAM_ERROR); + } + *errnum = s->z_err; + if (*errnum == Z_OK) return (const char*)""; + + m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); + + if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); + + TRYFREE(s->msg); + s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); + if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR); + strcpy(s->msg, s->path); + strcat(s->msg, ": "); + strcat(s->msg, m); + return (const char*)s->msg; +} + +/* =========================================================================== + Clear the error and end-of-file flags, and do the same for the real file. +*/ +void ZEXPORT gzclearerr (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL) return; + if (s->z_err != Z_STREAM_END) s->z_err = Z_OK; + s->z_eof = 0; + clearerr(s->file); +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/infback.c ./win32/dependencies/zlib/infback.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/infback.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/infback.c 2006-05-13 06:27:36 +0900 @@ -0,0 +1,623 @@ +/* infback.c -- inflate using a call-back interface + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + This code is largely copied from inflate.c. Normally either infback.o or + inflate.o would be linked into an application--not both. The interface + with inffast.c is retained so that optimized assembler-coded versions of + inflate_fast() can be used with either inflate.c or infback.c. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); + +/* + strm provides memory allocation functions in zalloc and zfree, or + Z_NULL to use the library memory allocation functions. + + windowBits is in the range 8..15, and window is a user-supplied + window and output buffer that is 2**windowBits bytes. + */ +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) +z_streamp strm; +int windowBits; +unsigned char FAR *window; +const char *version; +int stream_size; +{ + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL || window == Z_NULL || + windowBits < 8 || windowBits > 15) + return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + state = (struct inflate_state FAR *)ZALLOC(strm, 1, + sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + state->dmax = 32768U; + state->wbits = windowBits; + state->wsize = 1U << windowBits; + state->window = window; + state->write = 0; + state->whave = 0; + return Z_OK; +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +/* Macros for inflateBack(): */ + +/* Load returned state from inflate_fast() */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Set state from registers for inflate_fast() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Assure that some input is available. If input is requested, but denied, + then return a Z_BUF_ERROR from inflateBack(). */ +#define PULL() \ + do { \ + if (have == 0) { \ + have = in(in_desc, &next); \ + if (have == 0) { \ + next = Z_NULL; \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflateBack() + with an error if there is no input available. */ +#define PULLBYTE() \ + do { \ + PULL(); \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflateBack() with + an error. */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Assure that some output space is available, by writing out the window + if it's full. If the write fails, return from inflateBack() with a + Z_BUF_ERROR. */ +#define ROOM() \ + do { \ + if (left == 0) { \ + put = state->window; \ + left = state->wsize; \ + state->whave = left; \ + if (out(out_desc, put, left)) { \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* + strm provides the memory allocation functions and window buffer on input, + and provides information on the unused input on return. For Z_DATA_ERROR + returns, strm will also provide an error message. + + in() and out() are the call-back input and output functions. When + inflateBack() needs more input, it calls in(). When inflateBack() has + filled the window with output, or when it completes with data in the + window, it calls out() to write out the data. The application must not + change the provided input until in() is called again or inflateBack() + returns. The application must not change the window/output buffer until + inflateBack() returns. + + in() and out() are called with a descriptor parameter provided in the + inflateBack() call. This parameter can be a structure that provides the + information required to do the read or write, as well as accumulated + information on the input and output such as totals and check values. + + in() should return zero on failure. out() should return non-zero on + failure. If either in() or out() fails, than inflateBack() returns a + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it + was in() or out() that caused in the error. Otherwise, inflateBack() + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format + error, or Z_MEM_ERROR if it could not allocate memory for the state. + inflateBack() can also return Z_STREAM_ERROR if the input parameters + are not correct, i.e. strm is Z_NULL or the state was not initialized. + */ +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) +z_streamp strm; +in_func in; +void FAR *in_desc; +out_func out; +void FAR *out_desc; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code this; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + /* Check that the strm exists and that the state was initialized */ + if (strm == Z_NULL || strm->state == Z_NULL) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* Reset the state */ + strm->msg = Z_NULL; + state->mode = TYPE; + state->last = 0; + state->whave = 0; + next = strm->next_in; + have = next != Z_NULL ? strm->avail_in : 0; + hold = 0; + bits = 0; + put = state->window; + left = state->wsize; + + /* Inflate until end of block marked as last */ + for (;;) + switch (state->mode) { + case TYPE: + /* determine and dispatch block type */ + if (state->last) { + BYTEBITS(); + state->mode = DONE; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN; /* decode codes */ + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + + case STORED: + /* get and verify stored block length */ + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + + /* copy stored block from input to output */ + while (state->length != 0) { + copy = state->length; + PULL(); + ROOM(); + if (copy > have) copy = have; + if (copy > left) copy = left; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + + case TABLE: + /* get dynamic table entries descriptor */ + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + + /* get code length code lengths (not a typo) */ + state->have = 0; + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + + /* get length and distance code code lengths */ + state->have = 0; + while (state->have < state->nlen + state->ndist) { + for (;;) { + this = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if (this.val < 16) { + NEEDBITS(this.bits); + DROPBITS(this.bits); + state->lens[state->have++] = this.val; + } + else { + if (this.val == 16) { + NEEDBITS(this.bits + 2); + DROPBITS(this.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = (unsigned)(state->lens[state->have - 1]); + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (this.val == 17) { + NEEDBITS(this.bits + 3); + DROPBITS(this.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(this.bits + 7); + DROPBITS(this.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* build code tables */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN; + + case LEN: + /* use inflate_fast() if we have enough input and output */ + if (have >= 6 && left >= 258) { + RESTORE(); + if (state->whave < state->wsize) + state->whave = state->wsize - left; + inflate_fast(strm, state->wsize); + LOAD(); + break; + } + + /* get a literal, length, or end-of-block code */ + for (;;) { + this = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if (this.op && (this.op & 0xf0) == 0) { + last = this; + for (;;) { + this = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + this.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(this.bits); + state->length = (unsigned)this.val; + + /* process literal */ + if (this.op == 0) { + Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", this.val)); + ROOM(); + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + } + + /* process end of block */ + if (this.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + + /* invalid code */ + if (this.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + + /* length code -- get extra bits, if any */ + state->extra = (unsigned)(this.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + + /* get distance code */ + for (;;) { + this = state->distcode[BITS(state->distbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if ((this.op & 0xf0) == 0) { + last = this; + for (;;) { + this = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + this.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(this.bits); + if (this.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)this.val; + + /* get distance extra bits, if any */ + state->extra = (unsigned)(this.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + } + if (state->offset > state->wsize - (state->whave < state->wsize ? + left : 0)) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + + /* copy match from window to output */ + do { + ROOM(); + copy = state->wsize - state->offset; + if (copy < left) { + from = put + copy; + copy = left - copy; + } + else { + from = put - state->offset; + copy = left; + } + if (copy > state->length) copy = state->length; + state->length -= copy; + left -= copy; + do { + *put++ = *from++; + } while (--copy); + } while (state->length != 0); + break; + + case DONE: + /* inflate stream terminated properly -- write leftover output */ + ret = Z_STREAM_END; + if (left < state->wsize) { + if (out(out_desc, state->window, state->wsize - left)) + ret = Z_BUF_ERROR; + } + goto inf_leave; + + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + + default: /* can't happen, but makes compilers happy */ + ret = Z_STREAM_ERROR; + goto inf_leave; + } + + /* Return unused input */ + inf_leave: + strm->next_in = next; + strm->avail_in = have; + return ret; +} + +int ZEXPORT inflateBackEnd(strm) +z_streamp strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffast.c ./win32/dependencies/zlib/inffast.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffast.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inffast.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,318 @@ +/* inffast.c -- fast decoding + * Copyright (C) 1995-2004 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifndef ASMINF + +/* Allow machine dependent optimization for post-increment or pre-increment. + Based on testing to date, + Pre-increment preferred for: + - PowerPC G3 (Adler) + - MIPS R5000 (Randers-Pehrson) + Post-increment preferred for: + - none + No measurable difference: + - Pentium III (Anderson) + - M68060 (Nikl) + */ +#ifdef POSTINC +# define OFF 0 +# define PUP(a) *(a)++ +#else +# define OFF 1 +# define PUP(a) *++(a) +#endif + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ +void inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + unsigned char FAR *in; /* local strm->next_in */ + unsigned char FAR *last; /* while in < last, enough input available */ + unsigned char FAR *out; /* local strm->next_out */ + unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ + unsigned char FAR *end; /* while out < end, enough space available */ +#ifdef INFLATE_STRICT + unsigned dmax; /* maximum distance from zlib header */ +#endif + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned write; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ + unsigned long hold; /* local strm->hold */ + unsigned bits; /* local strm->bits */ + code const FAR *lcode; /* local strm->lencode */ + code const FAR *dcode; /* local strm->distcode */ + unsigned lmask; /* mask for first level of length codes */ + unsigned dmask; /* mask for first level of distance codes */ + code this; /* retrieved table entry */ + unsigned op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + unsigned len; /* match length, unused bytes */ + unsigned dist; /* match distance */ + unsigned char FAR *from; /* where to copy match from */ + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + in = strm->next_in - OFF; + last = in + (strm->avail_in - 5); + out = strm->next_out - OFF; + beg = out - (start - strm->avail_out); + end = out + (strm->avail_out - 257); +#ifdef INFLATE_STRICT + dmax = state->dmax; +#endif + wsize = state->wsize; + whave = state->whave; + write = state->write; + window = state->window; + hold = state->hold; + bits = state->bits; + lcode = state->lencode; + dcode = state->distcode; + lmask = (1U << state->lenbits) - 1; + dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + do { + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + this = lcode[hold & lmask]; + dolen: + op = (unsigned)(this.bits); + hold >>= op; + bits -= op; + op = (unsigned)(this.op); + if (op == 0) { /* literal */ + Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", this.val)); + PUP(out) = (unsigned char)(this.val); + } + else if (op & 16) { /* length base */ + len = (unsigned)(this.val); + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + this = dcode[hold & dmask]; + dodist: + op = (unsigned)(this.bits); + hold >>= op; + bits -= op; + op = (unsigned)(this.op); + if (op & 16) { /* distance base */ + dist = (unsigned)(this.val); + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); +#ifdef INFLATE_STRICT + if (dist > dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + hold >>= op; + bits -= op; + Tracevv((stderr, "inflate: distance %u\n", dist)); + op = (unsigned)(out - beg); /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } + from = window - OFF; + if (write == 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + else if (write < op) { /* wrap around window */ + from += wsize + write - op; + op -= write; + if (op < len) { /* some from end of window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = window - OFF; + if (write < len) { /* some from start of window */ + op = write; + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + } + else { /* contiguous in window */ + from += write - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + while (len > 2) { + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + else { + from = out - dist; /* copy direct from output */ + do { /* minimum length is three */ + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } while (len > 2); + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + } + else if ((op & 64) == 0) { /* 2nd level distance code */ + this = dcode[this.val + (hold & ((1U << op) - 1))]; + goto dodist; + } + else { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + } + else if ((op & 64) == 0) { /* 2nd level length code */ + this = lcode[this.val + (hold & ((1U << op) - 1))]; + goto dolen; + } + else if (op & 32) { /* end-of-block */ + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + else { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + } while (in < last && out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + in -= len; + bits -= len << 3; + hold &= (1U << bits) - 1; + + /* update state and return */ + strm->next_in = in + OFF; + strm->next_out = out + OFF; + strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); + strm->avail_out = (unsigned)(out < end ? + 257 + (end - out) : 257 - (out - end)); + state->hold = hold; + state->bits = bits; + return; +} + +/* + inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): + - Using bit fields for code structure + - Different op definition to avoid & for extra bits (do & for table bits) + - Three separate decoding do-loops for direct, window, and write == 0 + - Special case for distance > 1 copies to do overlapped load and store copy + - Explicit branch predictions (based on measured branch probabilities) + - Deferring match copy and interspersed it with decoding subsequent codes + - Swapping literal/length else + - Swapping window/direct else + - Larger unrolled copy loops (three is about right) + - Moving len -= 3 statement into middle of loop + */ + +#endif /* !ASMINF */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffast.h ./win32/dependencies/zlib/inffast.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffast.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inffast.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,11 @@ +/* inffast.h -- header to use inffast.c + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +void inflate_fast OF((z_streamp strm, unsigned start)); diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffixed.h ./win32/dependencies/zlib/inffixed.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inffixed.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inffixed.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,94 @@ + /* inffixed.h -- table for decoding fixed codes + * Generated automatically by makefixed(). + */ + + /* WARNING: this file should *not* be used by applications. It + is part of the implementation of the compression library and + is subject to change. Applications should only use zlib.h. + */ + + static const code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} + }; + + static const code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} + }; diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inflate.c ./win32/dependencies/zlib/inflate.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inflate.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inflate.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,1368 @@ +/* inflate.c -- zlib decompression + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * Change history: + * + * 1.2.beta0 24 Nov 2002 + * - First version -- complete rewrite of inflate to simplify code, avoid + * creation of window when not needed, minimize use of window when it is + * needed, make inffast.c even faster, implement gzip decoding, and to + * improve code readability and style over the previous zlib inflate code + * + * 1.2.beta1 25 Nov 2002 + * - Use pointers for available input and output checking in inffast.c + * - Remove input and output counters in inffast.c + * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 + * - Remove unnecessary second byte pull from length extra in inffast.c + * - Unroll direct copy to three copies per loop in inffast.c + * + * 1.2.beta2 4 Dec 2002 + * - Change external routine names to reduce potential conflicts + * - Correct filename to inffixed.h for fixed tables in inflate.c + * - Make hbuf[] unsigned char to match parameter type in inflate.c + * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) + * to avoid negation problem on Alphas (64 bit) in inflate.c + * + * 1.2.beta3 22 Dec 2002 + * - Add comments on state->bits assertion in inffast.c + * - Add comments on op field in inftrees.h + * - Fix bug in reuse of allocated window after inflateReset() + * - Remove bit fields--back to byte structure for speed + * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths + * - Change post-increments to pre-increments in inflate_fast(), PPC biased? + * - Add compile time option, POSTINC, to use post-increments instead (Intel?) + * - Make MATCH copy in inflate() much faster for when inflate_fast() not used + * - Use local copies of stream next and avail values, as well as local bit + * buffer and bit count in inflate()--for speed when inflate_fast() not used + * + * 1.2.beta4 1 Jan 2003 + * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings + * - Move a comment on output buffer sizes from inffast.c to inflate.c + * - Add comments in inffast.c to introduce the inflate_fast() routine + * - Rearrange window copies in inflate_fast() for speed and simplification + * - Unroll last copy for window match in inflate_fast() + * - Use local copies of window variables in inflate_fast() for speed + * - Pull out common write == 0 case for speed in inflate_fast() + * - Make op and len in inflate_fast() unsigned for consistency + * - Add FAR to lcode and dcode declarations in inflate_fast() + * - Simplified bad distance check in inflate_fast() + * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new + * source file infback.c to provide a call-back interface to inflate for + * programs like gzip and unzip -- uses window as output buffer to avoid + * window copying + * + * 1.2.beta5 1 Jan 2003 + * - Improved inflateBack() interface to allow the caller to provide initial + * input in strm. + * - Fixed stored blocks bug in inflateBack() + * + * 1.2.beta6 4 Jan 2003 + * - Added comments in inffast.c on effectiveness of POSTINC + * - Typecasting all around to reduce compiler warnings + * - Changed loops from while (1) or do {} while (1) to for (;;), again to + * make compilers happy + * - Changed type of window in inflateBackInit() to unsigned char * + * + * 1.2.beta7 27 Jan 2003 + * - Changed many types to unsigned or unsigned short to avoid warnings + * - Added inflateCopy() function + * + * 1.2.0 9 Mar 2003 + * - Changed inflateBack() interface to provide separate opaque descriptors + * for the in() and out() functions + * - Changed inflateBack() argument and in_func typedef to swap the length + * and buffer address return values for the input function + * - Check next_in and next_out for Z_NULL on entry to inflate() + * + * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifdef MAKEFIXED +# ifndef BUILDFIXED +# define BUILDFIXED +# endif +#endif + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); +local int updatewindow OF((z_streamp strm, unsigned out)); +#ifdef BUILDFIXED + void makefixed OF((void)); +#endif +local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, + unsigned len)); + +int ZEXPORT inflateReset(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + strm->total_in = strm->total_out = state->total = 0; + strm->msg = Z_NULL; + strm->adler = 1; /* to support ill-conceived Java test suite */ + state->mode = HEAD; + state->last = 0; + state->havedict = 0; + state->dmax = 32768U; + state->head = Z_NULL; + state->wsize = 0; + state->whave = 0; + state->write = 0; + state->hold = 0; + state->bits = 0; + state->lencode = state->distcode = state->next = state->codes; + Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +int ZEXPORT inflatePrime(strm, bits, value) +z_streamp strm; +int bits; +int value; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; + value &= (1L << bits) - 1; + state->hold += value << state->bits; + state->bits += bits; + return Z_OK; +} + +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) +z_streamp strm; +int windowBits; +const char *version; +int stream_size; +{ + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL) return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + state = (struct inflate_state FAR *) + ZALLOC(strm, 1, sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + if (windowBits < 0) { + state->wrap = 0; + windowBits = -windowBits; + } + else { + state->wrap = (windowBits >> 4) + 1; +#ifdef GUNZIP + if (windowBits < 48) windowBits &= 15; +#endif + } + if (windowBits < 8 || windowBits > 15) { + ZFREE(strm, state); + strm->state = Z_NULL; + return Z_STREAM_ERROR; + } + state->wbits = (unsigned)windowBits; + state->window = Z_NULL; + return inflateReset(strm); +} + +int ZEXPORT inflateInit_(strm, version, stream_size) +z_streamp strm; +const char *version; +int stream_size; +{ + return inflateInit2_(strm, DEF_WBITS, version, stream_size); +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +#ifdef MAKEFIXED +#include + +/* + Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also + defines BUILDFIXED, so the tables are built on the fly. makefixed() writes + those tables to stdout, which would be piped to inffixed.h. A small program + can simply call makefixed to do this: + + void makefixed(void); + + int main(void) + { + makefixed(); + return 0; + } + + Then that can be linked with zlib built with MAKEFIXED defined and run: + + a.out > inffixed.h + */ +void makefixed() +{ + unsigned low, size; + struct inflate_state state; + + fixedtables(&state); + puts(" /* inffixed.h -- table for decoding fixed codes"); + puts(" * Generated automatically by makefixed()."); + puts(" */"); + puts(""); + puts(" /* WARNING: this file should *not* be used by applications."); + puts(" It is part of the implementation of this library and is"); + puts(" subject to change. Applications should only use zlib.h."); + puts(" */"); + puts(""); + size = 1U << 9; + printf(" static const code lenfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 7) == 0) printf("\n "); + printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, + state.lencode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); + size = 1U << 5; + printf("\n static const code distfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 6) == 0) printf("\n "); + printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, + state.distcode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); +} +#endif /* MAKEFIXED */ + +/* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called + when a window is already in use, or when output has been written during this + inflate call, but the end of the deflate stream has not been reached yet. + It is also called to create a window for dictionary data when a dictionary + is loaded. + + Providing output buffers larger than 32K to inflate() should provide a speed + advantage, since only the last 32K of output is copied to the sliding window + upon return from inflate(), and since all distances after the first 32K of + output will fall in the output data, making match copies simpler and faster. + The advantage may be dependent on the size of the processor's data caches. + */ +local int updatewindow(strm, out) +z_streamp strm; +unsigned out; +{ + struct inflate_state FAR *state; + unsigned copy, dist; + + state = (struct inflate_state FAR *)strm->state; + + /* if it hasn't been done already, allocate space for the window */ + if (state->window == Z_NULL) { + state->window = (unsigned char FAR *) + ZALLOC(strm, 1U << state->wbits, + sizeof(unsigned char)); + if (state->window == Z_NULL) return 1; + } + + /* if window not in use yet, initialize */ + if (state->wsize == 0) { + state->wsize = 1U << state->wbits; + state->write = 0; + state->whave = 0; + } + + /* copy state->wsize or less output bytes into the circular window */ + copy = out - strm->avail_out; + if (copy >= state->wsize) { + zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); + state->write = 0; + state->whave = state->wsize; + } + else { + dist = state->wsize - state->write; + if (dist > copy) dist = copy; + zmemcpy(state->window + state->write, strm->next_out - copy, dist); + copy -= dist; + if (copy) { + zmemcpy(state->window, strm->next_out - copy, copy); + state->write = copy; + state->whave = state->wsize; + } + else { + state->write += dist; + if (state->write == state->wsize) state->write = 0; + if (state->whave < state->wsize) state->whave += dist; + } + } + return 0; +} + +/* Macros for inflate(): */ + +/* check function to use adler32() for zlib or crc32() for gzip */ +#ifdef GUNZIP +# define UPDATE(check, buf, len) \ + (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) +#else +# define UPDATE(check, buf, len) adler32(check, buf, len) +#endif + +/* check macros for header crc */ +#ifdef GUNZIP +# define CRC2(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + check = crc32(check, hbuf, 2); \ + } while (0) + +# define CRC4(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + hbuf[2] = (unsigned char)((word) >> 16); \ + hbuf[3] = (unsigned char)((word) >> 24); \ + check = crc32(check, hbuf, 4); \ + } while (0) +#endif + +/* Load registers with state in inflate() for speed */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Restore state from registers in inflate() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflate() + if there is no input available. */ +#define PULLBYTE() \ + do { \ + if (have == 0) goto inf_leave; \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflate(). */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Reverse the bytes in a 32-bit value */ +#define REVERSE(q) \ + ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ + (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) + +/* + inflate() uses a state machine to process as much input data and generate as + much output data as possible before returning. The state machine is + structured roughly as follows: + + for (;;) switch (state) { + ... + case STATEn: + if (not enough input data or output space to make progress) + return; + ... make progress ... + state = STATEm; + break; + ... + } + + so when inflate() is called again, the same case is attempted again, and + if the appropriate resources are provided, the machine proceeds to the + next state. The NEEDBITS() macro is usually the way the state evaluates + whether it can proceed or should return. NEEDBITS() does the return if + the requested bits are not available. The typical use of the BITS macros + is: + + NEEDBITS(n); + ... do something with BITS(n) ... + DROPBITS(n); + + where NEEDBITS(n) either returns from inflate() if there isn't enough + input left to load n bits into the accumulator, or it continues. BITS(n) + gives the low n bits in the accumulator. When done, DROPBITS(n) drops + the low n bits off the accumulator. INITBITS() clears the accumulator + and sets the number of available bits to zero. BYTEBITS() discards just + enough bits to put the accumulator on a byte boundary. After BYTEBITS() + and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. + + NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return + if there is no input available. The decoding of variable length codes uses + PULLBYTE() directly in order to pull just enough bytes to decode the next + code, and no more. + + Some states loop until they get enough input, making sure that enough + state information is maintained to continue the loop where it left off + if NEEDBITS() returns in the loop. For example, want, need, and keep + would all have to actually be part of the saved state in case NEEDBITS() + returns: + + case STATEw: + while (want < need) { + NEEDBITS(n); + keep[want++] = BITS(n); + DROPBITS(n); + } + state = STATEx; + case STATEx: + + As shown above, if the next state is also the next case, then the break + is omitted. + + A state may also return if there is not enough output space available to + complete that state. Those states are copying stored data, writing a + literal byte, and copying a matching string. + + When returning, a "goto inf_leave" is used to update the total counters, + update the check value, and determine whether any progress has been made + during that inflate() call in order to return the proper return code. + Progress is defined as a change in either strm->avail_in or strm->avail_out. + When there is a window, goto inf_leave will update the window with the last + output written. If a goto inf_leave occurs in the middle of decompression + and there is no window currently, goto inf_leave will create one and copy + output to the window for the next call of inflate(). + + In this implementation, the flush parameter of inflate() only affects the + return code (per zlib.h). inflate() always writes as much as possible to + strm->next_out, given the space available and the provided input--the effect + documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers + the allocation of and copying into a sliding window until necessary, which + provides the effect documented in zlib.h for Z_FINISH when the entire input + stream available. So the only thing the flush parameter actually does is: + when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it + will return Z_BUF_ERROR if it has not reached the end of the stream. + */ + +int ZEXPORT inflate(strm, flush) +z_streamp strm; +int flush; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned in, out; /* save starting available input and output */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code this; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ +#ifdef GUNZIP + unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ +#endif + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0)) + return Z_STREAM_ERROR; + + state = (struct inflate_state FAR *)strm->state; + if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ + LOAD(); + in = have; + out = left; + ret = Z_OK; + for (;;) + switch (state->mode) { + case HEAD: + if (state->wrap == 0) { + state->mode = TYPEDO; + break; + } + NEEDBITS(16); +#ifdef GUNZIP + if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ + state->check = crc32(0L, Z_NULL, 0); + CRC2(state->check, hold); + INITBITS(); + state->mode = FLAGS; + break; + } + state->flags = 0; /* expect zlib header */ + if (state->head != Z_NULL) + state->head->done = -1; + if (!(state->wrap & 1) || /* check if zlib header allowed */ +#else + if ( +#endif + ((BITS(8) << 8) + (hold >> 8)) % 31) { + strm->msg = (char *)"incorrect header check"; + state->mode = BAD; + break; + } + if (BITS(4) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + DROPBITS(4); + len = BITS(4) + 8; + if (len > state->wbits) { + strm->msg = (char *)"invalid window size"; + state->mode = BAD; + break; + } + state->dmax = 1U << len; + Tracev((stderr, "inflate: zlib header ok\n")); + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = hold & 0x200 ? DICTID : TYPE; + INITBITS(); + break; +#ifdef GUNZIP + case FLAGS: + NEEDBITS(16); + state->flags = (int)(hold); + if ((state->flags & 0xff) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + if (state->flags & 0xe000) { + strm->msg = (char *)"unknown header flags set"; + state->mode = BAD; + break; + } + if (state->head != Z_NULL) + state->head->text = (int)((hold >> 8) & 1); + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = TIME; + case TIME: + NEEDBITS(32); + if (state->head != Z_NULL) + state->head->time = hold; + if (state->flags & 0x0200) CRC4(state->check, hold); + INITBITS(); + state->mode = OS; + case OS: + NEEDBITS(16); + if (state->head != Z_NULL) { + state->head->xflags = (int)(hold & 0xff); + state->head->os = (int)(hold >> 8); + } + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = EXLEN; + case EXLEN: + if (state->flags & 0x0400) { + NEEDBITS(16); + state->length = (unsigned)(hold); + if (state->head != Z_NULL) + state->head->extra_len = (unsigned)hold; + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + } + else if (state->head != Z_NULL) + state->head->extra = Z_NULL; + state->mode = EXTRA; + case EXTRA: + if (state->flags & 0x0400) { + copy = state->length; + if (copy > have) copy = have; + if (copy) { + if (state->head != Z_NULL && + state->head->extra != Z_NULL) { + len = state->head->extra_len - state->length; + zmemcpy(state->head->extra + len, next, + len + copy > state->head->extra_max ? + state->head->extra_max - len : copy); + } + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + state->length -= copy; + } + if (state->length) goto inf_leave; + } + state->length = 0; + state->mode = NAME; + case NAME: + if (state->flags & 0x0800) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->name != Z_NULL && + state->length < state->head->name_max) + state->head->name[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->name = Z_NULL; + state->length = 0; + state->mode = COMMENT; + case COMMENT: + if (state->flags & 0x1000) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->comment != Z_NULL && + state->length < state->head->comm_max) + state->head->comment[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->comment = Z_NULL; + state->mode = HCRC; + case HCRC: + if (state->flags & 0x0200) { + NEEDBITS(16); + if (hold != (state->check & 0xffff)) { + strm->msg = (char *)"header crc mismatch"; + state->mode = BAD; + break; + } + INITBITS(); + } + if (state->head != Z_NULL) { + state->head->hcrc = (int)((state->flags >> 9) & 1); + state->head->done = 1; + } + strm->adler = state->check = crc32(0L, Z_NULL, 0); + state->mode = TYPE; + break; +#endif + case DICTID: + NEEDBITS(32); + strm->adler = state->check = REVERSE(hold); + INITBITS(); + state->mode = DICT; + case DICT: + if (state->havedict == 0) { + RESTORE(); + return Z_NEED_DICT; + } + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = TYPE; + case TYPE: + if (flush == Z_BLOCK) goto inf_leave; + case TYPEDO: + if (state->last) { + BYTEBITS(); + state->mode = CHECK; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN; /* decode codes */ + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + case STORED: + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + state->mode = COPY; + case COPY: + copy = state->length; + if (copy) { + if (copy > have) copy = have; + if (copy > left) copy = left; + if (copy == 0) goto inf_leave; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + break; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + case TABLE: + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + state->have = 0; + state->mode = LENLENS; + case LENLENS: + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + state->have = 0; + state->mode = CODELENS; + case CODELENS: + while (state->have < state->nlen + state->ndist) { + for (;;) { + this = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if (this.val < 16) { + NEEDBITS(this.bits); + DROPBITS(this.bits); + state->lens[state->have++] = this.val; + } + else { + if (this.val == 16) { + NEEDBITS(this.bits + 2); + DROPBITS(this.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = state->lens[state->have - 1]; + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (this.val == 17) { + NEEDBITS(this.bits + 3); + DROPBITS(this.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(this.bits + 7); + DROPBITS(this.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* build code tables */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN; + case LEN: + if (have >= 6 && left >= 258) { + RESTORE(); + inflate_fast(strm, out); + LOAD(); + break; + } + for (;;) { + this = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if (this.op && (this.op & 0xf0) == 0) { + last = this; + for (;;) { + this = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + this.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(this.bits); + state->length = (unsigned)this.val; + if ((int)(this.op) == 0) { + Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", this.val)); + state->mode = LIT; + break; + } + if (this.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + if (this.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + state->extra = (unsigned)(this.op) & 15; + state->mode = LENEXT; + case LENEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + state->mode = DIST; + case DIST: + for (;;) { + this = state->distcode[BITS(state->distbits)]; + if ((unsigned)(this.bits) <= bits) break; + PULLBYTE(); + } + if ((this.op & 0xf0) == 0) { + last = this; + for (;;) { + this = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + this.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(this.bits); + if (this.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)this.val; + state->extra = (unsigned)(this.op) & 15; + state->mode = DISTEXT; + case DISTEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + } +#ifdef INFLATE_STRICT + if (state->offset > state->dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + if (state->offset > state->whave + out - left) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + state->mode = MATCH; + case MATCH: + if (left == 0) goto inf_leave; + copy = out - left; + if (state->offset > copy) { /* copy from window */ + copy = state->offset - copy; + if (copy > state->write) { + copy -= state->write; + from = state->window + (state->wsize - copy); + } + else + from = state->window + (state->write - copy); + if (copy > state->length) copy = state->length; + } + else { /* copy from output */ + from = put - state->offset; + copy = state->length; + } + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = *from++; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; + case LIT: + if (left == 0) goto inf_leave; + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + case CHECK: + if (state->wrap) { + NEEDBITS(32); + out -= left; + strm->total_out += out; + state->total += out; + if (out) + strm->adler = state->check = + UPDATE(state->check, put - out, out); + out = left; + if (( +#ifdef GUNZIP + state->flags ? hold : +#endif + REVERSE(hold)) != state->check) { + strm->msg = (char *)"incorrect data check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: check matches trailer\n")); + } +#ifdef GUNZIP + state->mode = LENGTH; + case LENGTH: + if (state->wrap && state->flags) { + NEEDBITS(32); + if (hold != (state->total & 0xffffffffUL)) { + strm->msg = (char *)"incorrect length check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: length matches trailer\n")); + } +#endif + state->mode = DONE; + case DONE: + ret = Z_STREAM_END; + goto inf_leave; + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + default: + return Z_STREAM_ERROR; + } + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + inf_leave: + RESTORE(); + if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) + if (updatewindow(strm, out)) { + state->mode = MEM; + return Z_MEM_ERROR; + } + in -= strm->avail_in; + out -= strm->avail_out; + strm->total_in += in; + strm->total_out += out; + state->total += out; + if (state->wrap && out) + strm->adler = state->check = + UPDATE(state->check, strm->next_out - out, out); + strm->data_type = state->bits + (state->last ? 64 : 0) + + (state->mode == TYPE ? 128 : 0); + if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) + ret = Z_BUF_ERROR; + return ret; +} + +int ZEXPORT inflateEnd(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->window != Z_NULL) ZFREE(strm, state->window); + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} + +int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) +z_streamp strm; +const Bytef *dictionary; +uInt dictLength; +{ + struct inflate_state FAR *state; + unsigned long id; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->wrap != 0 && state->mode != DICT) + return Z_STREAM_ERROR; + + /* check for correct dictionary id */ + if (state->mode == DICT) { + id = adler32(0L, Z_NULL, 0); + id = adler32(id, dictionary, dictLength); + if (id != state->check) + return Z_DATA_ERROR; + } + + /* copy dictionary to window */ + if (updatewindow(strm, strm->avail_out)) { + state->mode = MEM; + return Z_MEM_ERROR; + } + if (dictLength > state->wsize) { + zmemcpy(state->window, dictionary + dictLength - state->wsize, + state->wsize); + state->whave = state->wsize; + } + else { + zmemcpy(state->window + state->wsize - dictLength, dictionary, + dictLength); + state->whave = dictLength; + } + state->havedict = 1; + Tracev((stderr, "inflate: dictionary set\n")); + return Z_OK; +} + +int ZEXPORT inflateGetHeader(strm, head) +z_streamp strm; +gz_headerp head; +{ + struct inflate_state FAR *state; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; + + /* save header structure */ + state->head = head; + head->done = 0; + return Z_OK; +} + +/* + Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found + or when out of input. When called, *have is the number of pattern bytes + found in order so far, in 0..3. On return *have is updated to the new + state. If on return *have equals four, then the pattern was found and the + return value is how many bytes were read including the last byte of the + pattern. If *have is less than four, then the pattern has not been found + yet and the return value is len. In the latter case, syncsearch() can be + called again with more data and the *have state. *have is initialized to + zero for the first call. + */ +local unsigned syncsearch(have, buf, len) +unsigned FAR *have; +unsigned char FAR *buf; +unsigned len; +{ + unsigned got; + unsigned next; + + got = *have; + next = 0; + while (next < len && got < 4) { + if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) + got++; + else if (buf[next]) + got = 0; + else + got = 4 - got; + next++; + } + *have = got; + return next; +} + +int ZEXPORT inflateSync(strm) +z_streamp strm; +{ + unsigned len; /* number of bytes to look at or looked at */ + unsigned long in, out; /* temporary to save total_in and total_out */ + unsigned char buf[4]; /* to restore bit buffer to byte string */ + struct inflate_state FAR *state; + + /* check parameters */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; + + /* if first time, start search in bit buffer */ + if (state->mode != SYNC) { + state->mode = SYNC; + state->hold <<= state->bits & 7; + state->bits -= state->bits & 7; + len = 0; + while (state->bits >= 8) { + buf[len++] = (unsigned char)(state->hold); + state->hold >>= 8; + state->bits -= 8; + } + state->have = 0; + syncsearch(&(state->have), buf, len); + } + + /* search available input */ + len = syncsearch(&(state->have), strm->next_in, strm->avail_in); + strm->avail_in -= len; + strm->next_in += len; + strm->total_in += len; + + /* return no joy or set up to restart inflate() on a new block */ + if (state->have != 4) return Z_DATA_ERROR; + in = strm->total_in; out = strm->total_out; + inflateReset(strm); + strm->total_in = in; strm->total_out = out; + state->mode = TYPE; + return Z_OK; +} + +/* + Returns true if inflate is currently at the end of a block generated by + Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP + implementation to provide an additional safety check. PPP uses + Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored + block. When decompressing, PPP checks that at the end of input packet, + inflate is waiting for these length bytes. + */ +int ZEXPORT inflateSyncPoint(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + return state->mode == STORED && state->bits == 0; +} + +int ZEXPORT inflateCopy(dest, source) +z_streamp dest; +z_streamp source; +{ + struct inflate_state FAR *state; + struct inflate_state FAR *copy; + unsigned char FAR *window; + unsigned wsize; + + /* check input */ + if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || + source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)source->state; + + /* allocate space */ + copy = (struct inflate_state FAR *) + ZALLOC(source, 1, sizeof(struct inflate_state)); + if (copy == Z_NULL) return Z_MEM_ERROR; + window = Z_NULL; + if (state->window != Z_NULL) { + window = (unsigned char FAR *) + ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); + if (window == Z_NULL) { + ZFREE(source, copy); + return Z_MEM_ERROR; + } + } + + /* copy state */ + zmemcpy(dest, source, sizeof(z_stream)); + zmemcpy(copy, state, sizeof(struct inflate_state)); + if (state->lencode >= state->codes && + state->lencode <= state->codes + ENOUGH - 1) { + copy->lencode = copy->codes + (state->lencode - state->codes); + copy->distcode = copy->codes + (state->distcode - state->codes); + } + copy->next = copy->codes + (state->next - state->codes); + if (window != Z_NULL) { + wsize = 1U << state->wbits; + zmemcpy(window, state->window, wsize); + } + copy->window = window; + dest->state = (struct internal_state FAR *)copy; + return Z_OK; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inflate.h ./win32/dependencies/zlib/inflate.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inflate.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inflate.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,115 @@ +/* inflate.h -- internal inflate state definition + * Copyright (C) 1995-2004 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer decoding by inflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip decoding + should be left enabled. */ +#ifndef NO_GZIP +# define GUNZIP +#endif + +/* Possible inflate modes between inflate() calls */ +typedef enum { + HEAD, /* i: waiting for magic header */ + FLAGS, /* i: waiting for method and flags (gzip) */ + TIME, /* i: waiting for modification time (gzip) */ + OS, /* i: waiting for extra flags and operating system (gzip) */ + EXLEN, /* i: waiting for extra length (gzip) */ + EXTRA, /* i: waiting for extra bytes (gzip) */ + NAME, /* i: waiting for end of file name (gzip) */ + COMMENT, /* i: waiting for end of comment (gzip) */ + HCRC, /* i: waiting for header crc (gzip) */ + DICTID, /* i: waiting for dictionary check value */ + DICT, /* waiting for inflateSetDictionary() call */ + TYPE, /* i: waiting for type bits, including last-flag bit */ + TYPEDO, /* i: same, but skip check to exit inflate on new block */ + STORED, /* i: waiting for stored size (length and complement) */ + COPY, /* i/o: waiting for input or output to copy stored block */ + TABLE, /* i: waiting for dynamic block table lengths */ + LENLENS, /* i: waiting for code length code lengths */ + CODELENS, /* i: waiting for length/lit and distance code lengths */ + LEN, /* i: waiting for length/lit code */ + LENEXT, /* i: waiting for length extra bits */ + DIST, /* i: waiting for distance code */ + DISTEXT, /* i: waiting for distance extra bits */ + MATCH, /* o: waiting for output space to copy string */ + LIT, /* o: waiting for output space to write literal */ + CHECK, /* i: waiting for 32-bit check value */ + LENGTH, /* i: waiting for 32-bit length (gzip) */ + DONE, /* finished check, done -- remain here until reset */ + BAD, /* got a data error -- remain here until reset */ + MEM, /* got an inflate() memory error -- remain here until reset */ + SYNC /* looking for synchronization bytes to restart inflate() */ +} inflate_mode; + +/* + State transitions between above modes - + + (most modes can go to the BAD or MEM mode -- not shown for clarity) + + Process header: + HEAD -> (gzip) or (zlib) + (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME + NAME -> COMMENT -> HCRC -> TYPE + (zlib) -> DICTID or TYPE + DICTID -> DICT -> TYPE + Read deflate blocks: + TYPE -> STORED or TABLE or LEN or CHECK + STORED -> COPY -> TYPE + TABLE -> LENLENS -> CODELENS -> LEN + Read deflate codes: + LEN -> LENEXT or LIT or TYPE + LENEXT -> DIST -> DISTEXT -> MATCH -> LEN + LIT -> LEN + Process trailer: + CHECK -> LENGTH -> DONE + */ + +/* state maintained between inflate() calls. Approximately 7K bytes. */ +struct inflate_state { + inflate_mode mode; /* current inflate mode */ + int last; /* true if processing last block */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + int havedict; /* true if dictionary provided */ + int flags; /* gzip header method and flags (0 if zlib) */ + unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ + unsigned long check; /* protected copy of check value */ + unsigned long total; /* protected copy of output count */ + gz_headerp head; /* where to save gzip header information */ + /* sliding window */ + unsigned wbits; /* log base 2 of requested window size */ + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned write; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if needed */ + /* bit accumulator */ + unsigned long hold; /* input bit accumulator */ + unsigned bits; /* number of bits in "in" */ + /* for string and stored block copying */ + unsigned length; /* literal or length of data to copy */ + unsigned offset; /* distance back to copy string from */ + /* for table and code decoding */ + unsigned extra; /* extra bits needed */ + /* fixed and dynamic code tables */ + code const FAR *lencode; /* starting table for length/literal codes */ + code const FAR *distcode; /* starting table for distance codes */ + unsigned lenbits; /* index bits for lencode */ + unsigned distbits; /* index bits for distcode */ + /* dynamic table building */ + unsigned ncode; /* number of code length code lengths */ + unsigned nlen; /* number of length code lengths */ + unsigned ndist; /* number of distance code lengths */ + unsigned have; /* number of code lengths in lens[] */ + code FAR *next; /* next available space in codes[] */ + unsigned short lens[320]; /* temporary storage for code lengths */ + unsigned short work[288]; /* work area for code table building */ + code codes[ENOUGH]; /* space for code tables */ +}; diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inftrees.c ./win32/dependencies/zlib/inftrees.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inftrees.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inftrees.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,329 @@ +/* inftrees.c -- generate Huffman trees for efficient decoding + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" + +#define MAXBITS 15 + +const char inflate_copyright[] = + " inflate 1.2.3 Copyright 1995-2005 Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* + Build a set of tables to decode the provided canonical Huffman code. + The code lengths are lens[0..codes-1]. The result starts at *table, + whose indices are 0..2^bits-1. work is a writable array of at least + lens shorts, which is used as a work area. type is the type of code + to be generated, CODES, LENS, or DISTS. On return, zero is success, + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table + on return points to the next available entry's address. bits is the + requested root table index bits, and on return it is the actual root + table index bits. It will differ if the request is greater than the + longest code or if it is less than the shortest code. + */ +int inflate_table(type, lens, codes, table, bits, work) +codetype type; +unsigned short FAR *lens; +unsigned codes; +code FAR * FAR *table; +unsigned FAR *bits; +unsigned short FAR *work; +{ + unsigned len; /* a code's length in bits */ + unsigned sym; /* index of code symbols */ + unsigned min, max; /* minimum and maximum code lengths */ + unsigned root; /* number of index bits for root table */ + unsigned curr; /* number of index bits for current table */ + unsigned drop; /* code bits to drop for sub-table */ + int left; /* number of prefix codes available */ + unsigned used; /* code entries in table used */ + unsigned huff; /* Huffman code */ + unsigned incr; /* for incrementing code, index */ + unsigned fill; /* index for replicating entries */ + unsigned low; /* low bits for current root entry */ + unsigned mask; /* mask for low root bits */ + code this; /* table entry for duplication */ + code FAR *next; /* next available space in table */ + const unsigned short FAR *base; /* base value table to use */ + const unsigned short FAR *extra; /* extra bits table to use */ + int end; /* use base and extra for symbol > end */ + unsigned short count[MAXBITS+1]; /* number of codes of each length */ + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196}; + static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577, 0, 0}; + static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64}; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) + count[len] = 0; + for (sym = 0; sym < codes; sym++) + count[lens[sym]]++; + + /* bound code lengths, force root to be within code lengths */ + root = *bits; + for (max = MAXBITS; max >= 1; max--) + if (count[max] != 0) break; + if (root > max) root = max; + if (max == 0) { /* no symbols to code at all */ + this.op = (unsigned char)64; /* invalid code marker */ + this.bits = (unsigned char)1; + this.val = (unsigned short)0; + *(*table)++ = this; /* make a table to force an error */ + *(*table)++ = this; + *bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min <= MAXBITS; min++) + if (count[min] != 0) break; + if (root < min) root = min; + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) return -1; /* over-subscribed */ + } + if (left > 0 && (type == CODES || max != 1)) + return -1; /* incomplete set */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + count[len]; + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked when a LENS table is being made + against the space in *table, ENOUGH, minus the maximum space needed by + the worst case distance code, MAXD. This should never happen, but the + sufficiency of ENOUGH has not been proven exhaustively, hence the check. + This assumes that when type == LENS, bits == 9. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base -= 257; + extra = lext; + extra -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize state for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = *table; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = (unsigned)(-1); /* trigger new sub-table when len > root */ + used = 1U << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if (type == LENS && used >= ENOUGH - MAXD) + return 1; + + /* process all codes and make table entries */ + for (;;) { + /* create table entry */ + this.bits = (unsigned char)(len - drop); + if ((int)(work[sym]) < end) { + this.op = (unsigned char)0; + this.val = work[sym]; + } + else if ((int)(work[sym]) > end) { + this.op = (unsigned char)(extra[work[sym]]); + this.val = base[work[sym]]; + } + else { + this.op = (unsigned char)(32 + 64); /* end of block */ + this.val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1U << (len - drop); + fill = 1U << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + next[(huff >> drop) + fill] = this; + } while (fill != 0); + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) == 0) { + if (len == max) break; + len = lens[work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) != low) { + /* if first time, transition to sub-tables */ + if (drop == 0) + drop = root; + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = (int)(1 << curr); + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) break; + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1U << curr; + if (type == LENS && used >= ENOUGH - MAXD) + return 1; + + /* point entry in root table to sub-table */ + low = huff & mask; + (*table)[low].op = (unsigned char)curr; + (*table)[low].bits = (unsigned char)root; + (*table)[low].val = (unsigned short)(next - *table); + } + } + + /* + Fill in rest of table for incomplete codes. This loop is similar to the + loop above in incrementing huff for table indices. It is assumed that + len is equal to curr + drop, so there is no loop needed to increment + through high index bits. When the current sub-table is filled, the loop + drops back to the root table to fill in any remaining entries there. + */ + this.op = (unsigned char)64; /* invalid code marker */ + this.bits = (unsigned char)(len - drop); + this.val = (unsigned short)0; + while (huff != 0) { + /* when done with sub-table, drop back to root table */ + if (drop != 0 && (huff & mask) != low) { + drop = 0; + len = root; + next = *table; + this.bits = (unsigned char)len; + } + + /* put invalid code marker in table */ + next[huff >> drop] = this; + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + } + + /* set return parameters */ + *table += used; + *bits = root; + return 0; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inftrees.h ./win32/dependencies/zlib/inftrees.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/inftrees.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/inftrees.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,55 @@ +/* inftrees.h -- header to use inftrees.c + * Copyright (C) 1995-2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Structure for decoding tables. Each entry provides either the + information needed to do the operation requested by the code that + indexed that table entry, or it provides a pointer to another + table that indexes more bits of the code. op indicates whether + the entry is a pointer to another table, a literal, a length or + distance, an end-of-block, or an invalid code. For a table + pointer, the low four bits of op is the number of index bits of + that table. For a length or distance, the low four bits of op + is the number of extra bits to get after the code. bits is + the number of bits in this code or part of the code to drop off + of the bit buffer. val is the actual byte to output in the case + of a literal, the base length or distance, or the offset from + the current table to the next table. Each entry is four bytes. */ +typedef struct { + unsigned char op; /* operation, extra bits, table bits */ + unsigned char bits; /* bits in this part of the code */ + unsigned short val; /* offset in table or code value */ +} code; + +/* op values as set by inflate_table(): + 00000000 - literal + 0000tttt - table link, tttt != 0 is the number of table index bits + 0001eeee - length or distance, eeee is the number of extra bits + 01100000 - end of block + 01000000 - invalid code + */ + +/* Maximum size of dynamic tree. The maximum found in a long but non- + exhaustive search was 1444 code structures (852 for length/literals + and 592 for distances, the latter actually the result of an + exhaustive search). The true maximum is not known, but the value + below is more than safe. */ +#define ENOUGH 2048 +#define MAXD 592 + +/* Type of code to build for inftable() */ +typedef enum { + CODES, + LENS, + DISTS +} codetype; + +extern int inflate_table OF((codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work)); diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/trees.c ./win32/dependencies/zlib/trees.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/trees.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/trees.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,1219 @@ +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1995-2005 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in a compressed form which is itself + * a Huffman encoding of the lengths of all the code strings (in + * ascending order by source values). The actual code strings are + * reconstructed from the lengths in the inflate process, as described + * in the deflate specification. + * + * REFERENCES + * + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + */ + +/* @(#) $Id: trees.c,v 1.1 2006/05/12 21:27:37 spacy51 Exp $ */ + +/* #define GEN_TREES_H */ + +#include "deflate.h" + +#ifdef DEBUG +# include +#endif + +/* =========================================================================== + * Constants + */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ + = {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}; + +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ + = {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}; + +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +local const uch bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +#define Buf_size (8 * 2*sizeof(char)) +/* Number of bits used within bi_buf. (bi_buf might be implemented on + * more than 16 bits on some systems.) + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ + +#if defined(GEN_TREES_H) || !defined(STDC) +/* non ANSI compilers may not accept trees.h */ + +local ct_data static_ltree[L_CODES+2]; +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +local ct_data static_dtree[D_CODES]; +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +uch _dist_code[DIST_CODE_LEN]; +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +uch _length_code[MAX_MATCH-MIN_MATCH+1]; +/* length code for each normalized match length (0 == MIN_MATCH) */ + +local int base_length[LENGTH_CODES]; +/* First normalized length for each code (0 = MIN_MATCH) */ + +local int base_dist[D_CODES]; +/* First normalized distance for each code (0 = distance of 1) */ + +#else +# include "trees.h" +#endif /* GEN_TREES_H */ + +struct static_tree_desc_s { + const ct_data *static_tree; /* static tree or NULL */ + const intf *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ +}; + +local static_tree_desc static_l_desc = +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; + +local static_tree_desc static_d_desc = +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; + +local static_tree_desc static_bl_desc = +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; + +/* =========================================================================== + * Local (static) routines in this file. + */ + +local void tr_static_init OF((void)); +local void init_block OF((deflate_state *s)); +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); +local void build_tree OF((deflate_state *s, tree_desc *desc)); +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local int build_bl_tree OF((deflate_state *s)); +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, + int blcodes)); +local void compress_block OF((deflate_state *s, ct_data *ltree, + ct_data *dtree)); +local void set_data_type OF((deflate_state *s)); +local unsigned bi_reverse OF((unsigned value, int length)); +local void bi_windup OF((deflate_state *s)); +local void bi_flush OF((deflate_state *s)); +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, + int header)); + +#ifdef GEN_TREES_H +local void gen_trees_header OF((void)); +#endif + +#ifndef DEBUG +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(s, c, tree) \ + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } +#endif + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +#ifdef DEBUG +local void send_bits OF((deflate_state *s, int value, int length)); + +local void send_bits(s, value, length) + deflate_state *s; + int value; /* value to send */ + int length; /* number of bits */ +{ + Tracevv((stderr," l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + s->bits_sent += (ulg)length; + + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (s->bi_valid > (int)Buf_size - length) { + s->bi_buf |= (value << s->bi_valid); + put_short(s, s->bi_buf); + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_valid += length - Buf_size; + } else { + s->bi_buf |= value << s->bi_valid; + s->bi_valid += length; + } +} +#else /* !DEBUG */ + +#define send_bits(s, value, length) \ +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (val << s->bi_valid);\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} +#endif /* DEBUG */ + + +/* the arguments must not have side effects */ + +/* =========================================================================== + * Initialize the various 'constant' tables. + */ +local void tr_static_init() +{ +#if defined(GEN_TREES_H) || !defined(STDC) + static int static_init_done = 0; + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + if (static_init_done) return; + + /* For some embedded targets, global variables are not initialized: */ + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = (uch)code; + } + } + Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse((unsigned)n, 5); + } + static_init_done = 1; + +# ifdef GEN_TREES_H + gen_trees_header(); +# endif +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ +} + +/* =========================================================================== + * Genererate the file trees.h describing the static trees. + */ +#ifdef GEN_TREES_H +# ifndef DEBUG +# include +# endif + +# define SEPARATOR(i, last, width) \ + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) + +void gen_trees_header() +{ + FILE *header = fopen("trees.h", "w"); + int i; + + Assert (header != NULL, "Can't open trees.h"); + fprintf(header, + "/* header created automatically with -DGEN_TREES_H */\n\n"); + + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); + for (i = 0; i < L_CODES+2; i++) { + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); + } + + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); + } + + fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); + for (i = 0; i < DIST_CODE_LEN; i++) { + fprintf(header, "%2u%s", _dist_code[i], + SEPARATOR(i, DIST_CODE_LEN-1, 20)); + } + + fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { + fprintf(header, "%2u%s", _length_code[i], + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); + } + + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); + for (i = 0; i < LENGTH_CODES; i++) { + fprintf(header, "%1u%s", base_length[i], + SEPARATOR(i, LENGTH_CODES-1, 20)); + } + + fprintf(header, "local const int base_dist[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "%5u%s", base_dist[i], + SEPARATOR(i, D_CODES-1, 10)); + } + + fclose(header); +} +#endif /* GEN_TREES_H */ + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +void _tr_init(s) + deflate_state *s; +{ + tr_static_init(); + + s->l_desc.dyn_tree = s->dyn_ltree; + s->l_desc.stat_desc = &static_l_desc; + + s->d_desc.dyn_tree = s->dyn_dtree; + s->d_desc.stat_desc = &static_d_desc; + + s->bl_desc.dyn_tree = s->bl_tree; + s->bl_desc.stat_desc = &static_bl_desc; + + s->bi_buf = 0; + s->bi_valid = 0; + s->last_eob_len = 8; /* enough lookahead for inflate */ +#ifdef DEBUG + s->compressed_len = 0L; + s->bits_sent = 0L; +#endif + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(s) + deflate_state *s; +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->last_lit = s->matches = 0; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(s, tree, top) \ +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m, depth) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +local void pqdownheap(s, tree, k) + deflate_state *s; + ct_data *tree; /* the tree to restore */ + int k; /* node to move down */ +{ + int v = s->heap[k]; + int j = k << 1; /* left son of k */ + while (j <= s->heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s->heap_len && + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s->heap[j], s->depth)) break; + + /* Exchange v with the smallest son */ + s->heap[k] = s->heap[j]; k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s->heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +local void gen_bitlen(s, desc) + deflate_state *s; + tree_desc *desc; /* the tree descriptor */ +{ + ct_data *tree = desc->dyn_tree; + int max_code = desc->max_code; + const ct_data *stree = desc->stat_desc->static_tree; + const intf *extra = desc->stat_desc->extra_bits; + int base = desc->stat_desc->extra_base; + int max_length = desc->stat_desc->max_length; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ + + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + n = s->heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) bits = max_length, overflow++; + tree[n].Len = (ush)bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) continue; /* not a leaf node */ + + s->bl_count[bits]++; + xbits = 0; + if (n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + s->opt_len += (ulg)f * (bits + xbits); + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); + } + if (overflow == 0) return; + + Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s->bl_count[bits] == 0) bits--; + s->bl_count[bits]--; /* move one leaf down the tree */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = s->bl_count[bits]; + while (n != 0) { + m = s->heap[--h]; + if (m > max_code) continue; + if ((unsigned) tree[m].Len != (unsigned) bits) { + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s->opt_len += ((long)bits - (long)tree[m].Len) + *(long)tree[m].Freq; + tree[m].Len = (ush)bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes (tree, max_code, bl_count) + ct_data *tree; /* the tree to decorate */ + int max_code; /* largest code with non zero frequency */ + ushf *bl_count; /* number of codes at each bit length */ +{ + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; + const ct_data *stree = desc->stat_desc->static_tree; + int elems = desc->stat_desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s->heap_len = 0, s->heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + s->heap[++(s->heap_len)] = max_code = n; + s->depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s->heap_len < 2) { + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + tree[node].Freq = 1; + s->depth[node] = 0; + s->opt_len--; if (stree) s->static_len -= stree[node].Len; + /* node is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + pqremove(s, tree, n); /* n = node of least frequency */ + m = s->heap[SMALLEST]; /* m = node of next least frequency */ + + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ + s->heap[--(s->heap_max)] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? + s->depth[n] : s->depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush)node; +#ifdef DUMP_BL_TREE + if (tree == s->bl_tree) { + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + s->heap[SMALLEST] = node++; + pqdownheap(s, tree, SMALLEST); + + } while (s->heap_len >= 2); + + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, (tree_desc *)desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes ((ct_data *)tree, max_code, s->bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +local void scan_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (ush)0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + s->bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) s->bl_tree[curlen].Freq++; + s->bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + s->bl_tree[REPZ_3_10].Freq++; + } else { + s->bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +local void send_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen == 0) max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(s, curlen, s->bl_tree); count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +local int build_bl_tree(s) + deflate_state *s; +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, (tree_desc *)(&(s->bl_desc))); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; + } + /* Update opt_len to include the bit length tree and counts */ + s->opt_len += 3*(max_blindex+1) + 5+5+4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +local void send_all_trees(s, lcodes, dcodes, blcodes) + deflate_state *s; + int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + int rank; /* index in bl_order */ + + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Send a stored block + */ +void _tr_stored_block(s, buf, stored_len, eof) + deflate_state *s; + charf *buf; /* input block */ + ulg stored_len; /* length of input block */ + int eof; /* true if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ +#ifdef DEBUG + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; + s->compressed_len += (stored_len + 4) << 3; +#endif + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + * The current inflate code requires 9 bits of lookahead. If the + * last two codes for the previous block (real code plus EOB) were coded + * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode + * the last real code. In this case we send two empty static blocks instead + * of one. (There are no problems if the previous block is stored or fixed.) + * To simplify the code, we assume the worst case of last real code encoded + * on one bit only. + */ +void _tr_align(s) + deflate_state *s; +{ + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif + bi_flush(s); + /* Of the 10 bits for the empty block, we have already sent + * (10 - bi_valid) bits. The lookahead for the last real code (before + * the EOB of the previous block) was thus at least one plus the length + * of the EOB plus what we have just sent of the empty static block. + */ + if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; +#endif + bi_flush(s); + } + s->last_eob_len = 7; +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +void _tr_flush_block(s, buf, stored_len, eof) + deflate_state *s; + charf *buf; /* input block, or NULL if too old */ + ulg stored_len; /* length of input block */ + int eof; /* true if this is the last block for a file */ +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s->level > 0) { + + /* Check if the file is binary or text */ + if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN) + set_data_type(s); + + /* Construct the literal and distance trees */ + build_tree(s, (tree_desc *)(&(s->l_desc))); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + + build_tree(s, (tree_desc *)(&(s->d_desc))); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s->opt_len+3+7)>>3; + static_lenb = (s->static_len+3+7)>>3; + + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); + + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; + + } else { + Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + +#ifdef FORCE_STORED + if (buf != (char*)0) { /* force stored block */ +#else + if (stored_len+4 <= opt_lenb && buf != (char*)0) { + /* 4: two words for the lengths */ +#endif + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, eof); + +#ifdef FORCE_STATIC + } else if (static_lenb >= 0) { /* force static trees */ +#else + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { +#endif + send_bits(s, (STATIC_TREES<<1)+eof, 3); + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->static_len; +#endif + } else { + send_bits(s, (DYN_TREES<<1)+eof, 3); + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + max_blindex+1); + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->opt_len; +#endif + } + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (eof) { + bi_windup(s); +#ifdef DEBUG + s->compressed_len += 7; /* align on byte boundary */ +#endif + } + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + s->compressed_len-7*eof)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +int _tr_tally (s, dist, lc) + deflate_state *s; + unsigned dist; /* distance of matched string */ + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + s->d_buf[s->last_lit] = (ush)dist; + s->l_buf[s->last_lit++] = (uch)lc; + if (dist == 0) { + /* lc is the unmatched char */ + s->dyn_ltree[lc].Freq++; + } else { + s->matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush)dist < (ush)MAX_DIST(s) && + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; + s->dyn_dtree[d_code(dist)].Freq++; + } + +#ifdef TRUNCATE_BLOCK + /* Try to guess if it is profitable to stop the current block here */ + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg)s->last_lit*8L; + ulg in_length = (ulg)((long)s->strstart - s->block_start); + int dcode; + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += (ulg)s->dyn_dtree[dcode].Freq * + (5L+extra_dbits[dcode]); + } + out_length >>= 3; + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + s->last_lit, in_length, out_length, + 100L - out_length*100L/in_length)); + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; + } +#endif + return (s->last_lit == s->lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(s, ltree, dtree) + deflate_state *s; + ct_data *ltree; /* literal tree */ + ct_data *dtree; /* distance tree */ +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->last_lit != 0) do { + dist = s->d_buf[lx]; + lc = s->l_buf[lx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + "pendingBuf overflow"); + + } while (lx < s->last_lit); + + send_code(s, END_BLOCK, ltree); + s->last_eob_len = ltree[END_BLOCK].Len; +} + +/* =========================================================================== + * Set the data type to BINARY or TEXT, using a crude approximation: + * set it to Z_TEXT if all symbols are either printable characters (33 to 255) + * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local void set_data_type(s) + deflate_state *s; +{ + int n; + + for (n = 0; n < 9; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + if (n == 9) + for (n = 14; n < 32; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY; +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +local unsigned bi_reverse(code, len) + unsigned code; /* the value to invert */ + int len; /* its bit length */ +{ + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(s) + deflate_state *s; +{ + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(s) + deflate_state *s; +{ + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +local void copy_block(s, buf, len, header) + deflate_state *s; + charf *buf; /* the input data */ + unsigned len; /* its length */ + int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + s->last_eob_len = 8; /* enough lookahead for inflate */ + + if (header) { + put_short(s, (ush)len); + put_short(s, (ush)~len); +#ifdef DEBUG + s->bits_sent += 2*16; +#endif + } +#ifdef DEBUG + s->bits_sent += (ulg)len<<3; +#endif + while (len--) { + put_byte(s, *buf++); + } +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/trees.h ./win32/dependencies/zlib/trees.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/trees.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/trees.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,128 @@ +/* header created automatically with -DGEN_TREES_H */ + +local const ct_data static_ltree[L_CODES+2] = { +{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, +{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, +{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, +{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, +{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, +{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, +{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, +{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, +{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, +{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, +{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, +{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, +{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, +{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, +{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, +{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, +{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, +{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, +{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, +{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, +{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, +{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, +{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, +{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, +{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, +{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, +{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, +{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, +{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, +{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, +{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, +{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, +{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, +{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, +{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, +{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, +{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, +{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, +{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, +{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, +{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, +{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, +{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, +{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, +{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, +{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, +{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, +{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, +{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, +{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, +{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, +{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, +{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, +{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, +{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, +{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, +{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, +{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} +}; + +local const ct_data static_dtree[D_CODES] = { +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} +}; + +const uch _dist_code[DIST_CODE_LEN] = { + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 +}; + +const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 +}; + +local const int base_length[LENGTH_CODES] = { +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 +}; + +local const int base_dist[D_CODES] = { + 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 +}; + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/uncompr.c ./win32/dependencies/zlib/uncompr.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/uncompr.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/uncompr.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,61 @@ +/* uncompr.c -- decompress a memory buffer + * Copyright (C) 1995-2003 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: uncompr.c,v 1.1 2006/05/12 21:27:37 spacy51 Exp $ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ +int ZEXPORT uncompress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; + + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + err = inflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + inflateEnd(&stream); + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) + return Z_DATA_ERROR; + return err; + } + *destLen = stream.total_out; + + err = inflateEnd(&stream); + return err; +} diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zconf.h ./win32/dependencies/zlib/zconf.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zconf.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/zconf.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,332 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zconf.h,v 1.1 2006/05/12 21:27:37 spacy51 Exp $ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + */ +#ifdef Z_PREFIX +# define deflateInit_ z_deflateInit_ +# define deflate z_deflate +# define deflateEnd z_deflateEnd +# define inflateInit_ z_inflateInit_ +# define inflate z_inflate +# define inflateEnd z_inflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateSetDictionary z_deflateSetDictionary +# define deflateCopy z_deflateCopy +# define deflateReset z_deflateReset +# define deflateParams z_deflateParams +# define deflateBound z_deflateBound +# define deflatePrime z_deflatePrime +# define inflateInit2_ z_inflateInit2_ +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateCopy z_inflateCopy +# define inflateReset z_inflateReset +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# define uncompress z_uncompress +# define adler32 z_adler32 +# define crc32 z_crc32 +# define get_crc_table z_get_crc_table +# define zError z_zError + +# define alloc_func z_alloc_func +# define free_func z_free_func +# define in_func z_in_func +# define out_func z_out_func +# define Byte z_Byte +# define uInt z_uInt +# define uLong z_uLong +# define Bytef z_Bytef +# define charf z_charf +# define intf z_intf +# define uIntf z_uIntf +# define uLongf z_uLongf +# define voidpf z_voidpf +# define voidp z_voidp +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ +# include /* for off_t */ +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# define z_off_t off_t +#endif +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif +#ifndef z_off_t +# define z_off_t long +#endif + +#if defined(__OS400__) +# define NO_vsnprintf +#endif + +#if defined(__MVS__) +# define NO_vsnprintf +# ifdef FAR +# undef FAR +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) +# pragma map(deflateInit_,"DEIN") +# pragma map(deflateInit2_,"DEIN2") +# pragma map(deflateEnd,"DEEND") +# pragma map(deflateBound,"DEBND") +# pragma map(inflateInit_,"ININ") +# pragma map(inflateInit2_,"ININ2") +# pragma map(inflateEnd,"INEND") +# pragma map(inflateSync,"INSY") +# pragma map(inflateSetDictionary,"INSEDI") +# pragma map(compressBound,"CMBND") +# pragma map(inflate_table,"INTABL") +# pragma map(inflate_fast,"INFA") +# pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zlib.h ./win32/dependencies/zlib/zlib.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zlib.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/zlib.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,1357 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.3, July 18th, 2005 + + Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.3" +#define ZLIB_VERNUM 0x1230 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms will be added later and will have the same + stream interface. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never + crash even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. + If zalloc and zfree are set to Z_NULL, deflateInit updates them to + use default allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at + all (the input data is simply copied a block at a time). + Z_DEFAULT_COMPRESSION requests a default compromise between speed and + compression (currently equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if level is not a valid compression level, + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). + msg is set to null if there is no error message. deflateInit does not + perform any compression: this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce some + output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumualte before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In particular + avail_in is zero after the call if enough output space has been provided + before the call.) Flushing may degrade compression for some compression + algorithms and so it should be used only when necessary. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + the value returned by deflateBound (see below). If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the exact + value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller. msg is set to null if there is no error + message. inflateInit does not perform any decompression apart from reading + the zlib header if present: this will be done by inflate(). (So next_in and + avail_in may be modified, but next_out and avail_out are unchanged.) +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, + Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() stop + if and when it gets to the next deflate block boundary. When decoding the + zlib or gzip format, this will cause inflate() to return immediately after + the header and before the first block. When doing a raw inflate, inflate() + will go ahead and process the first block, and will return when it gets to + the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 + if inflate() is currently decoding the last block in the deflate stream, + plus 128 if inflate() returned immediately after decoding an end-of-block + code or decoding the complete header up to just before the first byte of the + deflate stream. The end-of-block will not be indicated until all of the + uncompressed data from that block has been written to strm->next_out. The + number of unused bits may in general be greater than seven, except when + bit 7 of data_type is set, in which case the number of unused bits will be + less than eight. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster approach + may be used for the single inflate() call. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the only effect of the flush parameter in this implementation + is on the return value of inflate(), as noted below, or when it returns early + because Z_BLOCK is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the adler32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the adler32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() will decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically. Any information + contained in the gzip header is not retained, so applications that need that + information should instead use raw inflate, see inflateInit2() below, or + inflateBack() and perform their own processing of the gzip header and + trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may then + call inflateSync() to look for a good compression block if a partial recovery + of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by + the caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), + no header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but + is slow and reduces compression ratio; memLevel=9 uses maximum memory + for optimal speed. The default value is 8. See zconf.h for total memory + usage as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as + Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy + parameter only affects the compression ratio but not the correctness of the + compressed output even if it is not set appropriately. Z_FIXED prevents the + use of dynamic Huffman codes, allowing for a simpler decoder for special + applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid + method). msg is set to null if there is no error message. deflateInit2 does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any + call of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size in + deflate or deflate2. Thus the strings most likely to be useful should be + put at the end of the dictionary, not at the front. In addition, the + current implementation of deflate will use at most the window size minus + 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different + strategy. If the compression level is changed, the input available so far + is compressed with the old level (and may be flushed); the new level will + take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() + or deflateInit2(). This would be used to allocate an output buffer + for deflation in a single pass, and so would be called before deflate(). +*/ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the + bits leftover from a previous deflate stream when appending to it. As such, + this function can only be used for raw deflate, and must be used before the + first deflate() call after a deflateInit2() or deflateReset(). bits must be + less than or equal to 16, and that many of the least significant bits of + value will be inserted in the output. + + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is + a crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg + is set to null if there is no error message. inflateInit2 does not perform + any decompression apart from reading the zlib header if present: this will + be done by inflate(). (So next_in and avail_in may be modified, but next_out + and avail_out are unchanged.) +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been found, + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success + case, the application may save the current current value of total_in which + indicates where valid compressed data was found. In the error case, the + application may repeatedly call inflateSync, providing more input each time, + until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. + The stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK can be used to + force inflate() to return immediately after header processing is complete + and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When + any of extra, name, or comment are not Z_NULL and the respective field is + not present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the paramaters are invalid, Z_MEM_ERROR if the internal state could not + be allocated, or Z_VERSION_ERROR if the version of the library does not + match the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free + the allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects + only the raw deflate stream to decompress. This is different from the + normal behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format + error in the deflate stream (in which case strm->msg is set to indicate the + nature of the error), or Z_STREAM_ERROR if the stream was not properly + initialized. In the case of Z_BUF_ERROR, an input or output error can be + distinguished using strm->next_in which will be Z_NULL only if in() returned + an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to + out() returning non-zero. (in() will always be called before out(), so + strm->next_in is assured to be defined if out() returns non-zero.) Note + that inflateBack() cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the + basic stream-oriented functions. To simplify the interface, some + default options are assumed (compression level and memory usage, + standard memory allocation functions). The source code of these + utility functions can easily be modified if you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be at least the value returned + by compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + This function can be used to compress a whole file at once if the + input file is mmap'ed. + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before + a compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. +*/ + + +typedef voidp gzFile; + +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb") but can also include a compression level + ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for + Huffman only compression as in "wb1h", or 'R' for run-length encoding + as in "wb1R". (See the description of deflateInit2 for more information + about the strategy parameter.) + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). */ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen() associates a gzFile with the file descriptor fd. File + descriptors are obtained from calls like open, dup, creat, pipe or + fileno (in the file has been previously opened with fopen). + The mode parameter is as in gzopen. + The next call of gzclose on the returned gzFile will also close the + file descriptor fd, just like fclose(fdopen(fd), mode) closes the file + descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). + gzdopen returns NULL if there was insufficient memory to allocate + the (de)compression state. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. + If the input file was not in gzip format, gzread copies the given number + of bytes into the buffer. + gzread returns the number of uncompressed bytes actually read (0 for + end of file, -1 for error). */ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes actually written + (0 in case of error). +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). The number of + uncompressed bytes written is limited to 4095. The caller should assure that + this limit is not exceeded. If it is exceeded, then gzprintf() will return + return an error (0) with nothing written. In this case, there may also be a + buffer overflow with unpredictable consequences, which is possible only if + zlib was compiled with the insecure functions sprintf() or vsprintf() + because the secure snprintf() or vsnprintf() functions were not available. +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or + a newline character is read and transferred to buf, or an end-of-file + condition is encountered. The string is then terminated with a null + character. + gzgets returns buf, or Z_NULL in case of error. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read again later. + Only one character of push-back is allowed. gzungetc() returns the + character pushed, or -1 on failure. gzungetc() will fail if a + character has been pushed but not read yet, or if c is -1. The pushed + character will be discarded if the stream is repositioned with gzseek() + or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. The return value is the zlib + error number (see function gzerror below). gzflush returns Z_OK if + the flush parameter is Z_FINISH and all output could be flushed. + gzflush should be called only when strictly necessary because it can + degrade compression. +*/ + +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); +/* + Sets the starting position for the next gzread or gzwrite on the + given compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +/* + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns 1 if file is being read directly without decompression, otherwise + zero. +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. The return value is the zlib + error number (see function gzerror below). +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the + compression library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); +/* + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is NULL, this function returns the required initial + value for the for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + +/* + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + + +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; /* hack for buggy compilers */ +#endif + +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zlib.vcproj ./win32/dependencies/zlib/zlib.vcproj --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zlib.vcproj 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/zlib.vcproj 2006-08-24 07:13:30 +0900 @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zutil.c ./win32/dependencies/zlib/zutil.c --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zutil.c 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/zutil.c 2006-05-13 06:27:37 +0900 @@ -0,0 +1,318 @@ +/* zutil.c -- target dependent utility functions for the compression library + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zutil.c,v 1.1 2006/05/12 21:27:37 spacy51 Exp $ */ + +#include "zutil.h" + +#ifndef NO_DUMMY_DECL +struct internal_state {int dummy;}; /* for buggy compilers */ +#endif + +const char * const z_errmsg[10] = { +"need dictionary", /* Z_NEED_DICT 2 */ +"stream end", /* Z_STREAM_END 1 */ +"", /* Z_OK 0 */ +"file error", /* Z_ERRNO (-1) */ +"stream error", /* Z_STREAM_ERROR (-2) */ +"data error", /* Z_DATA_ERROR (-3) */ +"insufficient memory", /* Z_MEM_ERROR (-4) */ +"buffer error", /* Z_BUF_ERROR (-5) */ +"incompatible version",/* Z_VERSION_ERROR (-6) */ +""}; + + +const char * ZEXPORT zlibVersion() +{ + return ZLIB_VERSION; +} + +uLong ZEXPORT zlibCompileFlags() +{ + uLong flags; + + flags = 0; + switch (sizeof(uInt)) { + case 2: break; + case 4: flags += 1; break; + case 8: flags += 2; break; + default: flags += 3; + } + switch (sizeof(uLong)) { + case 2: break; + case 4: flags += 1 << 2; break; + case 8: flags += 2 << 2; break; + default: flags += 3 << 2; + } + switch (sizeof(voidpf)) { + case 2: break; + case 4: flags += 1 << 4; break; + case 8: flags += 2 << 4; break; + default: flags += 3 << 4; + } + switch (sizeof(z_off_t)) { + case 2: break; + case 4: flags += 1 << 6; break; + case 8: flags += 2 << 6; break; + default: flags += 3 << 6; + } +#ifdef DEBUG + flags += 1 << 8; +#endif +#if defined(ASMV) || defined(ASMINF) + flags += 1 << 9; +#endif +#ifdef ZLIB_WINAPI + flags += 1 << 10; +#endif +#ifdef BUILDFIXED + flags += 1 << 12; +#endif +#ifdef DYNAMIC_CRC_TABLE + flags += 1 << 13; +#endif +#ifdef NO_GZCOMPRESS + flags += 1L << 16; +#endif +#ifdef NO_GZIP + flags += 1L << 17; +#endif +#ifdef PKZIP_BUG_WORKAROUND + flags += 1L << 20; +#endif +#ifdef FASTEST + flags += 1L << 21; +#endif +#ifdef STDC +# ifdef NO_vsnprintf + flags += 1L << 25; +# ifdef HAS_vsprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_vsnprintf_void + flags += 1L << 26; +# endif +# endif +#else + flags += 1L << 24; +# ifdef NO_snprintf + flags += 1L << 25; +# ifdef HAS_sprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_snprintf_void + flags += 1L << 26; +# endif +# endif +#endif + return flags; +} + +#ifdef DEBUG + +# ifndef verbose +# define verbose 0 +# endif +int z_verbose = verbose; + +void z_error (m) + char *m; +{ + fprintf(stderr, "%s\n", m); + exit(1); +} +#endif + +/* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +const char * ZEXPORT zError(err) + int err; +{ + return ERR_MSG(err); +} + +#if defined(_WIN32_WCE) + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. + */ + int errno = 0; +#endif + +#ifndef HAVE_MEMCPY + +void zmemcpy(dest, source, len) + Bytef* dest; + const Bytef* source; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = *source++; /* ??? to be unrolled */ + } while (--len != 0); +} + +int zmemcmp(s1, s2, len) + const Bytef* s1; + const Bytef* s2; + uInt len; +{ + uInt j; + + for (j = 0; j < len; j++) { + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + } + return 0; +} + +void zmemzero(dest, len) + Bytef* dest; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = 0; /* ??? to be unrolled */ + } while (--len != 0); +} +#endif + + +#ifdef SYS16BIT + +#ifdef __TURBOC__ +/* Turbo C in 16-bit mode */ + +# define MY_ZCALLOC + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use zcfree(). + */ + +#define MAX_PTR 10 +/* 10*64K = 640K */ + +local int next_ptr = 0; + +typedef struct ptr_table_s { + voidpf org_ptr; + voidpf new_ptr; +} ptr_table; + +local ptr_table table[MAX_PTR]; +/* This table is used to remember the original form of pointers + * to large buffers (64K). Such pointers are normalized with a zero offset. + * Since MSDOS is not a preemptive multitasking OS, this table is not + * protected from concurrent access. This hack doesn't work anyway on + * a protected system like OS/2. Use Microsoft C instead. + */ + +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + voidpf buf = opaque; /* just to make some compilers happy */ + ulg bsize = (ulg)items*size; + + /* If we allocate less than 65520 bytes, we assume that farmalloc + * will return a usable pointer which doesn't have to be normalized. + */ + if (bsize < 65520L) { + buf = farmalloc(bsize); + if (*(ush*)&buf != 0) return buf; + } else { + buf = farmalloc(bsize + 16L); + } + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + table[next_ptr].org_ptr = buf; + + /* Normalize the pointer to seg:0 */ + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; + *(ush*)&buf = 0; + table[next_ptr++].new_ptr = buf; + return buf; +} + +void zcfree (voidpf opaque, voidpf ptr) +{ + int n; + if (*(ush*)&ptr != 0) { /* object < 64K */ + farfree(ptr); + return; + } + /* Find the original pointer */ + for (n = 0; n < next_ptr; n++) { + if (ptr != table[n].new_ptr) continue; + + farfree(table[n].org_ptr); + while (++n < next_ptr) { + table[n-1] = table[n]; + } + next_ptr--; + return; + } + ptr = opaque; /* just to make some compilers happy */ + Assert(0, "zcfree: ptr not found"); +} + +#endif /* __TURBOC__ */ + + +#ifdef M_I86 +/* Microsoft C in 16-bit mode */ + +# define MY_ZCALLOC + +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) +# define _halloc halloc +# define _hfree hfree +#endif + +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + return _halloc((long)items, size); +} + +void zcfree (voidpf opaque, voidpf ptr) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + _hfree(ptr); +} + +#endif /* M_I86 */ + +#endif /* SYS16BIT */ + + +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ + +#ifndef STDC +extern voidp malloc OF((uInt size)); +extern voidp calloc OF((uInt items, uInt size)); +extern void free OF((voidpf ptr)); +#endif + +voidpf zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : + (voidpf)calloc(items, size); +} + +void zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + free(ptr); + if (opaque) return; /* make compiler happy */ +} + +#endif /* MY_ZCALLOC */ diff -urN ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zutil.h ./win32/dependencies/zlib/zutil.h --- ../VisualBoyAdvance-1.7.2/win32/dependencies/zlib/zutil.h 1970-01-01 09:00:00 +0900 +++ ./win32/dependencies/zlib/zutil.h 2006-05-13 06:27:37 +0900 @@ -0,0 +1,269 @@ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: zutil.h,v 1.1 2006/05/12 21:27:37 spacy51 Exp $ */ + +#ifndef ZUTIL_H +#define ZUTIL_H + +#define ZLIB_INTERNAL +#include "zlib.h" + +#ifdef STDC +# ifndef _WIN32_WCE +# include +# endif +# include +# include +#endif +#ifdef NO_ERRNO_H +# ifdef _WIN32_WCE + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. We rename it to + * avoid conflict with other libraries that use the same workaround. + */ +# define errno z_errno +# endif + extern int errno; +#else +# ifndef _WIN32_WCE +# include +# endif +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) +# define OS_CODE 0x00 +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +# ifdef M_I86 + #include +# endif +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#ifdef WIN32 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ +# define OS_CODE 0x0b +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0f +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) +# if defined(_WIN32_WCE) +# define fdopen(fd,mode) NULL /* No fdopen() */ +# ifndef _PTRDIFF_T_DEFINED + typedef int ptrdiff_t; +# define _PTRDIFF_T_DEFINED +# endif +# else +# define fdopen(fd,type) _fdopen(fd,type) +# endif +#endif + + /* common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#if defined(__CYGWIN__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#ifndef HAVE_VSNPRINTF +# ifdef MSDOS + /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), + but for now we just assume it doesn't. */ +# define NO_vsnprintf +# endif +# ifdef __TURBOC__ +# define NO_vsnprintf +# endif +# ifdef WIN32 + /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ +# if !defined(vsnprintf) && !defined(NO_vsnprintf) +# define vsnprintf _vsnprintf +# endif +# endif +# ifdef __SASC +# define NO_vsnprintf +# endif +#endif +#ifdef VMS +# define NO_vsnprintf +#endif + +#if defined(pyr) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); + extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); + extern void zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int z_verbose; + extern void z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + + +voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); +void zcfree OF((voidpf opaque, voidpf ptr)); + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* ZUTIL_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/xfile.h ./win32/include/cximage/xfile.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/xfile.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/xfile.h 1970-01-01 09:00:00 +0900 @@ -1,64 +0,0 @@ -/* - * File: xfile.h - * Purpose: General Purpose File Class - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxFile (c) 11/May/2002 Davide Pizzolato - www.xdp.it - * CxFile version 2.00 23/Aug/2002 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Chris Shearer Cooper for new features, enhancements and bugfixes - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__xfile_h) -#define __xfile_h - -#ifdef WIN32 - #include -#endif - -#include -#include - -#include "ximadefs.h" - -class DLL_EXP CxFile -{ -public: - CxFile(void) { }; - virtual ~CxFile() { }; - - virtual bool Close() = 0; - virtual size_t Read(void *buffer, size_t size, size_t count) = 0; - virtual size_t Write(const void *buffer, size_t size, size_t count) = 0; - virtual bool Seek(long offset, int origin) = 0; - virtual long Tell() = 0; - virtual long Size() = 0; - virtual bool Flush() = 0; - virtual bool Eof() = 0; - virtual long Error() = 0; - virtual bool PutC(unsigned char c) - { - // Default implementation - size_t nWrote = Write(&c, 1, 1); - return (bool)(nWrote == 1); - } - virtual long GetC() = 0; -}; - -#endif //__xfile_h diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximabmp.h ./win32/include/cximage/ximabmp.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximabmp.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximabmp.h 1970-01-01 09:00:00 +0900 @@ -1,94 +0,0 @@ -/* - * File: ximabmp.h - * Purpose: BMP Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes - * - * original CImageBMP and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ - -#if !defined(__ximaBMP_h) -#define __ximaBMP_h - -#include "ximage.h" - -const int RLE_COMMAND = 0; -const int RLE_ENDOFLINE = 0; -const int RLE_ENDOFBITMAP = 1; -const int RLE_DELTA = 2; - -#if !defined(BI_RLE8) - #define BI_RLE8 1L -#endif -#if !defined(BI_RLE4) - #define BI_RLE4 2L -#endif - -#if CXIMAGE_SUPPORT_BMP - -class CxImageBMP: public CxImage -{ -public: - CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {}; - - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE - -protected: - bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib); -}; - -#define BFT_ICON 0x4349 /* 'IC' */ -#define BFT_BITMAP 0x4d42 /* 'BM' */ -#define BFT_CURSOR 0x5450 /* 'PT' */ - -#ifndef WIDTHBYTES -#define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ -#endif - -#define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n)) -#define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount) - -#define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ - ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \ - : (lpbi)->biSizeImage) - -#define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ - ? (int)(1 << (int)(lpbi)->biBitCount) \ - : (int)(lpbi)->biClrUsed) - -#define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ - (lpbi)->biSizeImage = DibSizeImage(lpbi); \ - if ((lpbi)->biClrUsed == 0) \ - (lpbi)->biClrUsed = DibNumColors(lpbi); \ - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximadefs.h ./win32/include/cximage/ximadefs.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximadefs.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximadefs.h 1970-01-01 09:00:00 +0900 @@ -1,165 +0,0 @@ -#if !defined(__ximadefs_h) -#define __ximadefs_h - -#if defined(_AFXDLL)||defined(_USRDLL) - #define DLL_EXP __declspec(dllexport) -#elif defined(_MSC_VER)&&(_MSC_VER<1200) - #define DLL_EXP __declspec(dllimport) -#else - #define DLL_EXP -#endif - -#if CXIMAGE_SUPPORT_JP2 || CXIMAGE_SUPPORT_JPC || CXIMAGE_SUPPORT_PGX || CXIMAGE_SUPPORT_PNM || CXIMAGE_SUPPORT_RAS - #define CXIMAGE_SUPPORT_JASPER 1 -#else - #define CXIMAGE_SUPPORT_JASPER 0 -#endif - -#if CXIMAGE_SUPPORT_DSP -#undef CXIMAGE_SUPPORT_TRANSFORMATION - #define CXIMAGE_SUPPORT_TRANSFORMATION 1 -#endif - -#if CXIMAGE_SUPPORT_TRANSFORMATION || CXIMAGE_SUPPORT_TIF || CXIMAGE_SUPPORT_TGA || CXIMAGE_SUPPORT_BMP || CXIMAGE_SUPPORT_WINDOWS - #define CXIMAGE_SUPPORT_BASICTRANSFORMATIONS 1 -#endif - -#if CXIMAGE_SUPPORT_WINCE - #undef CXIMAGE_SUPPORT_WMF - #define CXIMAGE_SUPPORT_WMF 0 - #undef CXIMAGE_SUPPORT_WINDOWS - #define CXIMAGE_SUPPORT_WINDOWS 0 -#endif - -#ifndef WIN32 - #undef CXIMAGE_SUPPORT_WINDOWS - #define CXIMAGE_SUPPORT_WINDOWS 0 -#endif - -#ifndef min -#define min(a,b) (((a)<(b))?(a):(b)) -#endif -#ifndef max -#define max(a,b) (((a)>(b))?(a):(b)) -#endif - - -#ifdef WIN32 -#include -//#include -#endif - -#include -#include - - -#ifdef __BORLANDC__ -#define _complex complex -#define _cabs cabs -#endif - - -#ifndef WIN32 - -#include -#include -#include - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef unsigned int UINT; - -typedef DWORD COLORREF; -typedef unsigned int HANDLE; -typedef void* HRGN; - -#define BOOL bool -#define TRUE true -#define FALSE false - -typedef struct tagRECT -{ - long left; - long top; - long right; - long bottom; -} RECT; - -typedef struct tagPOINT -{ - long x; - long y; -} POINT; - -typedef struct tagRGBQUAD { - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; - BYTE rgbReserved; -} RGBQUAD; - -#pragma pack(1) - -typedef struct tagBITMAPINFOHEADER{ - DWORD biSize; - long biWidth; - long biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - long biXPelsPerMeter; - long biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; -} BITMAPINFOHEADER; - -typedef struct tagBITMAPFILEHEADER { - WORD bfType; - DWORD bfSize; - WORD bfReserved1; - WORD bfReserved2; - DWORD bfOffBits; -} BITMAPFILEHEADER; - -typedef struct tagBITMAPCOREHEADER { - DWORD bcSize; - WORD bcWidth; - WORD bcHeight; - WORD bcPlanes; - WORD bcBitCount; -} BITMAPCOREHEADER; - -typedef struct tagRGBTRIPLE { - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; -} RGBTRIPLE; - -#pragma pack() - -#define BI_RGB 0L -#define BI_RLE8 1L -#define BI_RLE4 2L -#define BI_BITFIELDS 3L - -#define GetRValue(rgb) ((BYTE)(rgb)) -#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) -#define GetBValue(rgb) ((BYTE)((rgb)>>16)) -#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) - -#ifndef _COMPLEX_DEFINED - -typedef struct tagcomplex { - double x,y; -} _complex; - -#endif - -#define _cabs(c) sqrt(c.x*c.x+c.y*c.y) - -#endif - - -#endif //__ximadefs diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximage.h ./win32/include/cximage/ximage.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximage.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximage.h 1970-01-01 09:00:00 +0900 @@ -1,547 +0,0 @@ -/* - * File: ximage.h - * Purpose: General Purpose Image Class - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * original CImage and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__CXIMAGE_H) -#define __CXIMAGE_H - -#if _MSC_VER > 1000 -#pragma once -#endif - -///////////////////////////////////////////////////////////////////////////// -// CxImage supported features -#define CXIMAGE_SUPPORT_ALPHA 1 -#define CXIMAGE_SUPPORT_SELECTION 0 -#define CXIMAGE_SUPPORT_TRANSFORMATION 0 -#define CXIMAGE_SUPPORT_DSP 0 -#define CXIMAGE_SUPPORT_LAYERS 0 - -#define CXIMAGE_SUPPORT_DECODE 1 -#define CXIMAGE_SUPPORT_ENCODE 0 // -#define CXIMAGE_SUPPORT_WINDOWS 1 -#define CXIMAGE_SUPPORT_WINCE 0 // - -///////////////////////////////////////////////////////////////////////////// -// CxImage supported formats -#define CXIMAGE_SUPPORT_BMP 1 -#define CXIMAGE_SUPPORT_GIF 0 -#define CXIMAGE_SUPPORT_JPG 1 -#define CXIMAGE_SUPPORT_PNG 1 -#define CXIMAGE_SUPPORT_MNG 0 -#define CXIMAGE_SUPPORT_ICO 0 -#define CXIMAGE_SUPPORT_TIF 0 -#define CXIMAGE_SUPPORT_TGA 0 -#define CXIMAGE_SUPPORT_PCX 0 -#define CXIMAGE_SUPPORT_WBMP 0 -#define CXIMAGE_SUPPORT_WMF 0 -#define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2 -#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm - -#define CXIMAGE_SUPPORT_JP2 0 -#define CXIMAGE_SUPPORT_JPC 0 -#define CXIMAGE_SUPPORT_PGX 0 -#define CXIMAGE_SUPPORT_PNM 0 -#define CXIMAGE_SUPPORT_RAS 0 - -///////////////////////////////////////////////////////////////////////////// - -#include // For UNICODE support -#include "xfile.h" -#include "xiofile.h" -#include "xmemfile.h" - -#include "ximadefs.h" // adjust some #define - -///////////////////////////////////////////////////////////////////////////// -// CxImage formats enumerator -enum ENUM_CXIMAGE_FORMATS{ -CXIMAGE_FORMAT_UNKNOWN, -#if CXIMAGE_SUPPORT_BMP -CXIMAGE_FORMAT_BMP, -#endif -#if CXIMAGE_SUPPORT_GIF -CXIMAGE_FORMAT_GIF, -#endif -#if CXIMAGE_SUPPORT_JPG -CXIMAGE_FORMAT_JPG, -#endif -#if CXIMAGE_SUPPORT_PNG -CXIMAGE_FORMAT_PNG, -#endif -#if CXIMAGE_SUPPORT_MNG -CXIMAGE_FORMAT_MNG, -#endif -#if CXIMAGE_SUPPORT_ICO -CXIMAGE_FORMAT_ICO, -#endif -#if CXIMAGE_SUPPORT_TIF -CXIMAGE_FORMAT_TIF, -#endif -#if CXIMAGE_SUPPORT_TGA -CXIMAGE_FORMAT_TGA, -#endif -#if CXIMAGE_SUPPORT_PCX -CXIMAGE_FORMAT_PCX, -#endif -#if CXIMAGE_SUPPORT_WBMP -CXIMAGE_FORMAT_WBMP, -#endif -#if CXIMAGE_SUPPORT_WMF -CXIMAGE_FORMAT_WMF, -#endif -#if CXIMAGE_SUPPORT_J2K -CXIMAGE_FORMAT_J2K, -#endif -#if CXIMAGE_SUPPORT_JBG -CXIMAGE_FORMAT_JBG, -#endif -#if CXIMAGE_SUPPORT_JP2 -CXIMAGE_FORMAT_JP2, -#endif -#if CXIMAGE_SUPPORT_JPC -CXIMAGE_FORMAT_JPC, -#endif -#if CXIMAGE_SUPPORT_PGX -CXIMAGE_FORMAT_PGX, -#endif -#if CXIMAGE_SUPPORT_PNM -CXIMAGE_FORMAT_PNM, -#endif -#if CXIMAGE_SUPPORT_RAS -CXIMAGE_FORMAT_RAS, -#endif -CMAX_IMAGE_FORMATS -}; - -//color to grey mapping -//#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000) -#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10) - -struct rgb_color { BYTE r,g,b; }; - - -// text placement data -// members must be initialized with the InitTextInfo(&this) function. -typedef struct DLL_EXP tagCxTextInfo -{ - char text[4096]; // text - LOGFONT lfont; // font and codepage data - COLORREF fcolor; // foreground color - long align; // DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text - BYTE opaque; // text has background or hasn't. Default is true. - // data for background (ignored if .opaque==FALSE) - COLORREF bcolor; // background color - float b_opacity; // opacity value for background between 0.0-1.0 Default is 0. (opaque) - BYTE b_outline; // outline width for background (zero: no outline) - BYTE b_round; // rounding radius for background rectangle. % of the height, between 0-50. Default is 10. - // (backgr. always has a frame: width = 3 pixel + 10% of height by default.) -} CXTEXTINFO; - -///////////////////////////////////////////////////////////////////////////// -// CxImage class -///////////////////////////////////////////////////////////////////////////// -class DLL_EXP CxImage -{ -//extensible information collector -typedef struct tagCxImageInfo { - DWORD dwEffWidth; //DWORD aligned scan line width - BYTE* pImage; //THE IMAGE BITS - CxImage* pGhost; //if this is a ghost, pGhost points to the body - CxImage* pParent; //if this is a layer, pParent points to the body - DWORD dwType; //original image format - char szLastError[256]; //debugging - long nProgress; //monitor - long nEscape; //escape - long nBkgndIndex; //used for GIF, PNG, MNG - RGBQUAD nBkgndColor; //used for RGB transparency - BYTE nQuality; //used for JPEG - BYTE nScale; //used for JPEG - long nFrame; //used for TIF, GIF, MNG : actual frame - long nNumFrames; //used for TIF, GIF, MNG : total number of frames - DWORD dwFrameDelay; //used for GIF, MNG - long xDPI; //horizontal resolution - long yDPI; //vertical resolution - RECT rSelectionBox; //bounding rectangle - BYTE nAlphaMax; //max opacity (fade) - bool bAlphaPaletteEnabled; //true if alpha values in the palette are enabled. - bool bEnabled; //enables the painting functions - long xOffset; - long yOffset; - DWORD dwCodecOption; //for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg - RGBQUAD last_c; //for GetNearestIndex optimization - BYTE last_c_index; - bool last_c_isvalid; - long nNumLayers; - DWORD dwFlags; // 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags - -} CXIMAGEINFO; - -public: - //constructors - CxImage(DWORD imagetype = 0); - CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); - CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); - CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR -// CxImage(const char * filename, DWORD imagetype); - CxImage(FILE * stream, DWORD imagetype); - CxImage(CxFile * stream, DWORD imagetype); - CxImage(BYTE * buffer, DWORD size, DWORD imagetype); - virtual ~CxImage() { Destroy(); }; - CxImage& operator = (const CxImage&); - - //initializzation - void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); - bool Destroy(); - void Clear(BYTE bval=0); - void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); - bool Transfer(CxImage &from); - bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); - bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); - - //Attributes - long GetSize(); - BYTE* GetBits(DWORD row = 0); - BYTE GetColorType(); - void* GetDIB() const {return pDib;} - DWORD GetHeight() const {return head.biHeight;} - DWORD GetWidth() const {return head.biWidth;} - DWORD GetEffWidth() const {return info.dwEffWidth;} - DWORD GetNumColors() const {return head.biClrUsed;} - WORD GetBpp() const {return head.biBitCount;} - DWORD GetType() const {return info.dwType;} - char* GetLastError() {return info.szLastError;} - const TCHAR* GetVersion(); - - DWORD GetFrameDelay() const {return info.dwFrameDelay;} - void SetFrameDelay(DWORD d) {info.dwFrameDelay=d;} - - void GetOffset(long *x,long *y) {*x=info.xOffset; *y=info.yOffset;} - void SetOffset(long x,long y) {info.xOffset=x; info.yOffset=y;} - - BYTE GetJpegQuality() const {return info.nQuality;} - void SetJpegQuality(BYTE q) {info.nQuality = q;} - - // used for scaling down during JPEG decoding valid numbers are 1, 2, 4, 8 - BYTE GetJpegScale() const {return info.nScale;} - void SetJpegScale(BYTE q) {info.nScale = q;} - - long GetXDPI() const {return info.xDPI;} - long GetYDPI() const {return info.yDPI;} - void SetXDPI(long dpi); - void SetYDPI(long dpi); - - DWORD GetClrImportant() const {return head.biClrImportant;} - void SetClrImportant(DWORD ncolors = 0); - - long GetProgress() const {return info.nProgress;} - long GetEscape() const {return info.nEscape;} - void SetProgress(long p) {info.nProgress = p;} - void SetEscape(long i) {info.nEscape = i;} - - long GetTransIndex() const {return info.nBkgndIndex;} - RGBQUAD GetTransColor(); - void SetTransIndex(long idx) {info.nBkgndIndex = idx;} - void SetTransColor(RGBQUAD rgb) {rgb.rgbReserved=0; info.nBkgndColor = rgb;} - bool IsTransparent() const {return info.nBkgndIndex>=0;} // - - DWORD GetCodecOption() const {return info.dwCodecOption;} - void SetCodecOption(DWORD opt) {info.dwCodecOption = opt;} - - DWORD GetFlags() const {return info.dwFlags;} - void SetFlags(DWORD flags, bool bLockReservedFlags = true); - - //void* GetUserData() const {return info.pUserData;} - //void SetUserData(void* pUserData) {info.pUserData = pUserData;} - - //palette operations - bool IsGrayScale(); - bool IsIndexed() {return head.biClrUsed!=0;} - DWORD GetPaletteSize(); - RGBQUAD* GetPalette() const; - RGBQUAD GetPaletteColor(BYTE idx); - bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b); - BYTE GetNearestIndex(RGBQUAD c); - void BlendPalette(COLORREF cr,long perc); - void SetGrayPalette(); - void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b); - void SetPalette(RGBQUAD* pPal,DWORD nColors=256); - void SetPalette(rgb_color *rgb,DWORD nColors=256); - void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0); - void SetPaletteColor(BYTE idx, RGBQUAD c); - void SetPaletteColor(BYTE idx, COLORREF cr); - void SwapIndex(BYTE idx1, BYTE idx2); - void SetStdPalette(); - - //pixel operations - bool IsInside(long x, long y); - bool IsTransparent(long x,long y); - RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true); - BYTE GetPixelIndex(long x,long y); - BYTE GetPixelGray(long x, long y); - void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false); - void SetPixelColor(long x,long y,COLORREF cr); - void SetPixelIndex(long x,long y,BYTE i); - void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false); - void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr); - - - //painting operations -#if CXIMAGE_SUPPORT_WINCE - long Blt(HDC pDC, long x=0, long y=0); -#endif -#if CXIMAGE_SUPPORT_WINDOWS - HBITMAP MakeBitmap(HDC hdc = NULL); - HANDLE CopyToHandle(); - bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard) - bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource - bool CreateFromHICON(HICON hico); - long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0); - long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL) { return Draw(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pClipRect); } - long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY); - long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY) { return Stretch(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); } - long Tile(HDC hdc, RECT *rc); - long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1); - long Draw2(HDC hdc, const RECT& rect) { return Draw2(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } - //long DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); - long DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); - // extensions - long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false ); - void InitTextInfo( CXTEXTINFO *txt ); -#endif //CXIMAGE_SUPPORT_WINDOWS - - // file operations -#if CXIMAGE_SUPPORT_DECODE -#ifdef WIN32 - //bool Load(LPCWSTR filename, DWORD imagetype=0); - bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL); -#endif - // For UNICODE support: char -> TCHAR - bool Load(const TCHAR* filename, DWORD imagetype=0); - //bool Load(const char * filename, DWORD imagetype=0); - bool Decode(FILE * hFile, DWORD imagetype); - bool Decode(CxFile * hFile, DWORD imagetype); - bool Decode(BYTE * buffer, DWORD size, DWORD imagetype); -#endif //CXIMAGE_SUPPORT_DECODE - -#if CXIMAGE_SUPPORT_ENCODE -protected: - bool EncodeSafeCheck(CxFile *hFile); -public: -#ifdef WIN32 - //bool Save(LPCWSTR filename, DWORD imagetype=0); -#endif - // For UNICODE support: char -> TCHAR - bool Save(const TCHAR* filename, DWORD imagetype=0); - //bool Save(const char * filename, DWORD imagetype=0); - bool Encode(FILE * hFile, DWORD imagetype); - bool Encode(CxFile * hFile, DWORD imagetype); - bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype); - bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype); - bool Encode(BYTE * &buffer, long &size, DWORD imagetype); -#endif //CXIMAGE_SUPPORT_ENCODE - - //misc. - bool IsValid() const {return pDib!=0;} - bool IsEnabled() const {return info.bEnabled;} - void Enable(bool enable=true){info.bEnabled=enable;} - - // frame operations - long GetNumFrames() const {return info.nNumFrames;} - long GetFrame() const {return info.nFrame;} - void SetFrame(long nFrame) {info.nFrame=nFrame;} - -#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS - bool GrayScale(); - bool Flip(); - bool Mirror(); - bool Negative(); - bool RotateLeft(CxImage* iDst = NULL); - bool RotateRight(CxImage* iDst = NULL); -#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS - -#if CXIMAGE_SUPPORT_TRANSFORMATION - // image operations - bool Rotate(float angle, CxImage* iDst = NULL); - bool Rotate180(CxImage* iDst = NULL); - bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL); - bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0); - bool IncreaseBpp(DWORD nbit); - bool Dither(long method = 0); - bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL); - bool Crop(const RECT& rect, CxImage* iDst = NULL) { return Crop(rect.left, rect.top, rect.right, rect.bottom, iDst); } - bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL); - bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0); - bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0); - bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); - bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); - bool CircleTransform(int type,long rmax=0,float Koeff=1.0f); - -protected: - float b3spline(float x); -public: -#endif //CXIMAGE_SUPPORT_TRANSFORMATION - -#if CXIMAGE_SUPPORT_DSP - bool Contour(); - bool HistogramStretch(long method = 0); - bool HistogramEqualize(); - bool HistogramNormalize(); - bool HistogramRoot(); - bool HistogramLog(); - long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0); - bool Jitter(long radius=2); - bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0); - bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0); - bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true); - bool Noise(long level); - bool Median(long Ksize=3); - bool Gamma(float gamma); - bool ShiftRGB(long r, long g, long b); - bool Threshold(BYTE level); - bool Colorize(BYTE hue, BYTE sat); - bool Light(long brightness, long contrast = 0); - float Mean(); - bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset); - bool Erode(long Ksize=2); - bool Dilate(long Ksize=2); - void HuePalette(float correction=1); - enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend }; - void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0); - void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset); - bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0); - bool Lut(BYTE* pLut); - bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0); - -protected: - bool IsPowerof2(long x); - bool FFT(int dir,int m,double *x,double *y); - bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2); - bool RepairChannel(CxImage *ch, float radius); - // - int gen_convolve_matrix (float radius, float **cmatrix_p); - float* gen_lookup_table (float *cmatrix, int cmatrix_length); - void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes); -public: - //color conversion utilities - bool SplitRGB(CxImage* r,CxImage* g,CxImage* b); - bool SplitYUV(CxImage* y,CxImage* u,CxImage* v); - bool SplitHSL(CxImage* h,CxImage* s,CxImage* l); - bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q); - bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z); - bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k); - RGBQUAD HSLtoRGB(COLORREF cHSLColor); - RGBQUAD RGBtoHSL(RGBQUAD lRGBColor); - RGBQUAD HSLtoRGB(RGBQUAD lHSLColor); - RGBQUAD YUVtoRGB(RGBQUAD lYUVColor); - RGBQUAD RGBtoYUV(RGBQUAD lRGBColor); - RGBQUAD YIQtoRGB(RGBQUAD lYIQColor); - RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor); - RGBQUAD XYZtoRGB(RGBQUAD lXYZColor); - RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor); -#endif //CXIMAGE_SUPPORT_DSP - RGBQUAD RGBtoRGBQUAD(COLORREF cr); - COLORREF RGBQUADtoRGB (RGBQUAD c); - -#if CXIMAGE_SUPPORT_SELECTION - //selection - bool SelectionClear(); - bool SelectionCreate(); - bool SelectionDelete(); - bool SelectionInvert(); - bool SelectionAddRect(RECT r); - bool SelectionAddEllipse(RECT r); - bool SelectionAddPolygon(POINT *points, long npoints); - bool SelectionAddColor(RGBQUAD c); - bool SelectionAddPixel(int x, int y); - bool SelectionCopy(CxImage &from); - bool SelectionIsInside(long x, long y); - bool SelectionIsValid(){return pSelection!=0;} - void SelectionGetBox(RECT& r){memcpy(&r,&info.rSelectionBox,sizeof(RECT));} - bool SelectionToHRGN(HRGN& region); -#endif //CXIMAGE_SUPPORT_SELECTION - -#if CXIMAGE_SUPPORT_ALPHA - //Alpha - void AlphaClear(); - void AlphaCreate(); - void AlphaDelete(); - void AlphaInvert(); - bool AlphaMirror(); - bool AlphaFlip(); - bool AlphaCopy(CxImage &from); - bool AlphaSplit(CxImage *dest); - void AlphaStrip(); - void AlphaSet(BYTE level); - bool AlphaSet(CxImage &from); - void AlphaSet(long x,long y,BYTE level); - BYTE AlphaGet(long x,long y); - BYTE AlphaGetMax() const {return info.nAlphaMax;} - void AlphaSetMax(BYTE nAlphaMax) {info.nAlphaMax=nAlphaMax;} - bool AlphaIsValid(){return pAlpha!=0;} - BYTE* AlphaGetBits() const {return pAlpha;} - - void AlphaPaletteClear(); - void AlphaPaletteEnable(bool enable=true){info.bAlphaPaletteEnabled=enable;} - bool AlphaPaletteIsEnabled(){return info.bAlphaPaletteEnabled;} - bool AlphaPaletteIsValid(); - bool AlphaPaletteSplit(CxImage *dest); -#endif //CXIMAGE_SUPPORT_ALPHA - -#if CXIMAGE_SUPPORT_LAYERS - bool LayerCreate(long position = -1); - bool LayerDelete(long position = -1); - void LayerDeleteAll(); - CxImage* GetLayer(long position); - CxImage* GetParent() const {return info.pParent;} - long GetNumLayers() const {return info.nNumLayers;} -#endif //CXIMAGE_SUPPORT_LAYERS - -protected: - void Startup(DWORD imagetype = 0); - void CopyInfo(const CxImage &src); - void Ghost(CxImage *src); - void RGBtoBGR(BYTE *buffer, int length); - float HueToRGB(float n1,float n2, float hue); - void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp); - static int CompareColors(const void *elem1, const void *elem2); - - void* pDib; //contains the header, the palette, the pixels - BITMAPINFOHEADER head; //standard header - CXIMAGEINFO info; //extended information - BYTE* pSelection; //selected region - BYTE* pAlpha; //alpha channel - CxImage** pLayers; //generic layers -}; -//////////////////////////////////////////////////////////////////////////// - -#define CXIMAGE_MAX_MEMORY 256000000 - -#define CXIMAGE_ERR_NOFILE "null file handler" -#define CXIMAGE_ERR_NOIMAGE "null image!!!" -//////////////////////////////////////////////////////////////////////////// -#endif // !defined(__CXIMAGE_H) diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximagif.h ./win32/include/cximage/ximagif.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximagif.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximagif.h 1970-01-01 09:00:00 +0900 @@ -1,262 +0,0 @@ -/* - * File: ximagif.h - * Purpose: GIF Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageGIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes - * - * original CImageGIF and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * 6/15/97 Randy Spann: Added GIF87a writing support - * R.Spann@ConnRiver.net - * - * DECODE.C - An LZW decoder for GIF - * Copyright (C) 1987, by Steven A. Bennett - * Copyright (C) 1994, C++ version by Alejandro Aguilar Sierra - * - * In accordance with the above, I want to credit Steve Wilhite who wrote - * the code which this is heavily inspired by... - * - * GIF and 'Graphics Interchange Format' are trademarks (tm) of - * Compuserve, Incorporated, an H&R Block Company. - * - * Release Notes: This file contains a decoder routine for GIF images - * which is similar, structurally, to the original routine by Steve Wilhite. - * It is, however, somewhat noticably faster in most cases. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ - -#if !defined(__ximaGIF_h) -#define __ximaGIF_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_GIF - -typedef short int code_int; - -/* Various error codes used by decoder */ -#define OUT_OF_MEMORY -10 -#define BAD_CODE_SIZE -20 -#define READ_ERROR -1 -#define WRITE_ERROR -2 -#define OPEN_ERROR -3 -#define CREATE_ERROR -4 -#define MAX_CODES 4095 -#define GIFBUFTAM 16384 -#define TRANSPARENCY_CODE 0xF9 - -//LZW GIF Image compression -#define MAXBITSCODES 12 -#define HSIZE 5003 /* 80% occupancy */ -#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) -#define HashTabOf(i) htab[i] -#define CodeTabOf(i) codetab[i] - - -class CImageIterator; -class DLL_EXP CxImageGIF: public CxImage -{ -#pragma pack(1) - -typedef struct tag_gifgce{ - BYTE transpcolflag:1; - BYTE userinputflag:1; - BYTE dispmeth:3; - BYTE res:3; - WORD delaytime; - BYTE transpcolindex; -} struct_gifgce; - -typedef struct tag_dscgif{ /* Logic Screen Descriptor */ - char header[6]; /* Firma and version */ - WORD scrwidth; - WORD scrheight; - char pflds; - char bcindx; - char pxasrat; -} struct_dscgif; - -typedef struct tag_image{ /* Image Descriptor */ - WORD l; - WORD t; - WORD w; - WORD h; - BYTE pf; -} struct_image; - -typedef struct tag_TabCol{ /* Tabla de colores */ - short colres; /* color resolution */ - short sogct; /* size of global color table */ - rgb_color paleta[256]; /* paleta */ -} struct_TabCol; - -typedef struct tag_RLE{ - int rl_pixel; - int rl_basecode; - int rl_count; - int rl_table_pixel; - int rl_table_max; - int just_cleared; - int out_bits; - int out_bits_init; - int out_count; - int out_bump; - int out_bump_init; - int out_clear; - int out_clear_init; - int max_ocodes; - int code_clear; - int code_eof; - unsigned int obuf; - int obits; - unsigned char oblock[256]; - int oblen; -} struct_RLE; -#pragma pack() - -public: - CxImageGIF(): CxImage(CXIMAGE_FORMAT_GIF) {m_loops=0; m_dispmeth=0; m_comment[0]='\0';} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_GIF);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_GIF);} - - bool Decode(CxFile * fp); - bool Decode(FILE *fp) { CxIOFile file(fp); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * fp); - bool Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false); - bool Encode(FILE *fp) { CxIOFile file(fp); return Encode(&file); } - bool Encode(FILE *fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false) - { CxIOFile file(fp); return Encode(&file, pImages, pagecount, bLocalColorMap); } -#endif // CXIMAGE_SUPPORT_ENCODE - - void SetLoops(int loops); - long GetLoops(); - void SetComment(const char* sz_comment_in); - void GetComment(char* sz_comment_out); - void SetDisposalMethod(int dm); - long GetDisposalMethod(); - -protected: - bool DecodeExtension(CxFile *fp); - void EncodeHeader(CxFile *fp); - void EncodeLoopExtension(CxFile *fp); - void EncodeExtension(CxFile *fp); - void EncodeBody(CxFile *fp, bool bLocalColorMap = false); - void EncodeComment(CxFile *fp); - bool EncodeRGB(CxFile *fp); - void GifMix(CxImage & imgsrc2, long lxOffset, long lyOffset); - - struct_gifgce gifgce; - - int curx, cury; - long CountDown; - unsigned long cur_accum; - int cur_bits; - int interlaced, iypos, istep, iheight, ipass; - int ibf; - int ibfmax; - BYTE buf[GIFBUFTAM + 1]; -// Implementation - int GifNextPixel (); - void Putword (int w, CxFile* fp ); - void compressNONE (int init_bits, CxFile* outfile); - void compressLZW (int init_bits, CxFile* outfile); - void output (code_int code ); - void cl_hash (long hsize); - void char_out (int c); - void flush_char (); - short init_exp(short size); - short get_next_code(CxFile*); - short decoder(CxFile*, CImageIterator* iter, short linewidth, int &bad_code_count); - int get_byte(CxFile*); - int out_line(CImageIterator* iter, unsigned char *pixels, int linelen); - int get_num_frames(CxFile *f,struct_TabCol* TabColSrc); - - short curr_size; /* The current code size */ - short clear; /* Value for a clear code */ - short ending; /* Value for a ending code */ - short newcodes; /* First available code */ - short top_slot; /* Highest code for current size */ - short slot; /* Last read code */ - - /* The following static variables are used - * for seperating out codes */ - short navail_bytes; /* # bytes left in block */ - short nbits_left; /* # bits left in current BYTE */ - BYTE b1; /* Current BYTE */ - BYTE byte_buff[257]; /* Current block */ - BYTE *pbytes; /* Pointer to next BYTE in block */ - /* The reason we have these seperated like this instead of using - * a structure like the original Wilhite code did, is because this - * stuff generally produces significantly faster code when compiled... - * This code is full of similar speedups... (For a good book on writing - * C for speed or for space optomisation, see Efficient C by Tom Plum, - * published by Plum-Hall Associates...) - */ - BYTE stack[MAX_CODES + 1]; /* Stack for storing pixels */ - BYTE suffix[MAX_CODES + 1]; /* Suffix table */ - WORD prefix[MAX_CODES + 1]; /* Prefix linked list */ - -//LZW GIF Image compression routines - long htab [HSIZE]; - unsigned short codetab [HSIZE]; - int n_bits; /* number of bits/code */ - code_int maxcode; /* maximum code, given n_bits */ - code_int free_ent; /* first unused entry */ - int clear_flg; - int g_init_bits; - CxFile* g_outfile; - int ClearCode; - int EOFCode; - - int a_count; - char accum[256]; - - char m_comment[256]; - int m_loops; - int m_dispmeth; - -//RLE compression routines - void compressRLE( int init_bits, CxFile* outfile); - void rle_clear(struct_RLE* rle); - void rle_flush(struct_RLE* rle); - void rle_flush_withtable(int count, struct_RLE* rle); - void rle_flush_clearorrep(int count, struct_RLE* rle); - void rle_flush_fromclear(int count,struct_RLE* rle); - void rle_output_plain(int c,struct_RLE* rle); - void rle_reset_out_clear(struct_RLE* rle); - unsigned int rle_compute_triangle_count(unsigned int count, unsigned int nrepcodes); - unsigned int rle_isqrt(unsigned int x); - void rle_write_block(struct_RLE* rle); - void rle_block_out(unsigned char c, struct_RLE* rle); - void rle_block_flush(struct_RLE* rle); - void rle_output(int val, struct_RLE* rle); - void rle_output_flush(struct_RLE* rle); -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximaico.h ./win32/include/cximage/ximaico.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximaico.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximaico.h 1970-01-01 09:00:00 +0900 @@ -1,71 +0,0 @@ -/* - * File: ximaico.h - * Purpose: ICON Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageICO (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Parts of the code come from FreeImage 2 - * Design and implementation by Floris van den Berg - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaICO_h) -#define __ximaICO_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_ICO - -class CxImageICO: public CxImage -{ -typedef struct tagIconDirectoryEntry { - BYTE bWidth; - BYTE bHeight; - BYTE bColorCount; - BYTE bReserved; - WORD wPlanes; - WORD wBitCount; - DWORD dwBytesInRes; - DWORD dwImageOffset; -} ICONDIRENTRY; - -typedef struct tagIconDir { - WORD idReserved; - WORD idType; - WORD idCount; -} ICONHEADER; - -public: - CxImageICO(): CxImage(CXIMAGE_FORMAT_ICO) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximaiter.h ./win32/include/cximage/ximaiter.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximaiter.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximaiter.h 1970-01-01 09:00:00 +0900 @@ -1,252 +0,0 @@ -/* - * File: ImaIter.h - * Purpose: Declaration of the Platform Independent Image Base Class - * Author: Alejandro Aguilar Sierra - * Created: 1995 - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * 07/08/2001 Davide Pizzolato - www.xdp.it - * - removed slow loops - * - added safe checks - * - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ - -#if !defined(__ImaIter_h) -#define __ImaIter_h - -#include "ximage.h" -#include "ximadefs.h" - -class CImageIterator -{ -friend class CxImage; -protected: - int Itx, Ity; // Counters - int Stepx, Stepy; - BYTE* IterImage; // Image pointer - CxImage *ima; -public: - // Constructors - CImageIterator ( void ); - CImageIterator ( CxImage *image ); - operator CxImage* (); - - // Iterators - BOOL ItOK (); - void Reset (); - void Upset (); - void SetRow(BYTE *buf, int n); - void GetRow(BYTE *buf, int n); - BYTE GetByte( ) { return IterImage[Itx]; } - void SetByte(BYTE b) { IterImage[Itx] = b; } - BYTE* GetRow(void); - BYTE* GetRow(int n); - BOOL NextRow(); - BOOL PrevRow(); - BOOL NextByte(); - BOOL PrevByte(); - - void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; } - void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; } - BOOL NextStep(); - BOOL PrevStep(); - - void SetY(int y); /* AD - for interlace */ - int GetY() {return Ity;} - BOOL GetCol(BYTE* pCol, DWORD x); - BOOL SetCol(BYTE* pCol, DWORD x); -}; - -///////////////////////////////////////////////////////////////////// -inline -CImageIterator::CImageIterator(void) -{ - ima = 0; - IterImage = 0; - Itx = Ity = 0; - Stepx = Stepy = 0; -} -///////////////////////////////////////////////////////////////////// -inline -CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl) -{ - if (ima) IterImage = ima->GetBits(); - Itx = Ity = 0; - Stepx = Stepy = 0; -} -///////////////////////////////////////////////////////////////////// -inline -CImageIterator::operator CxImage* () -{ - return ima; -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::ItOK () -{ - if (ima) return ima->IsInside(Itx, Ity); - else return FALSE; -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::Reset() -{ - if (ima) IterImage = ima->GetBits(); - else IterImage=0; - Itx = Ity = 0; -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::Upset() -{ - Itx = 0; - Ity = ima->GetHeight()-1; - IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1); -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::NextRow() -{ - if (++Ity >= (int)ima->GetHeight()) return 0; - IterImage += ima->GetEffWidth(); - return 1; -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::PrevRow() -{ - if (--Ity < 0) return 0; - IterImage -= ima->GetEffWidth(); - return 1; -} -/* AD - for interlace */ -inline void CImageIterator::SetY(int y) -{ - if ((y < 0) || (y > (int)ima->GetHeight())) return; - Ity = y; - IterImage = ima->GetBits() + ima->GetEffWidth()*y; -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::SetRow(BYTE *buf, int n) -{ - if (n<0) n = (int)ima->GetEffWidth(); - else n = min(n,(int)ima->GetEffWidth()); - - if (IterImage) memcpy(IterImage,buf,n); -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::GetRow(BYTE *buf, int n) -{ - if ((buf!=NULL)&&(n>0)) memcpy(buf,IterImage,n); -} -///////////////////////////////////////////////////////////////////// -inline BYTE* CImageIterator::GetRow() -{ - return IterImage; -} -///////////////////////////////////////////////////////////////////// -inline BYTE* CImageIterator::GetRow(int n) -{ - SetY(n); - return IterImage; -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::NextByte() -{ - if (++Itx < (int)ima->GetEffWidth()) return 1; - else - if (++Ity < (int)ima->GetHeight()){ - IterImage += ima->GetEffWidth(); - Itx = 0; - return 1; - } else - return 0; -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::PrevByte() -{ - if (--Itx >= 0) return 1; - else - if (--Ity >= 0){ - IterImage -= ima->GetEffWidth(); - Itx = 0; - return 1; - } else - return 0; -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::NextStep() -{ - Itx += Stepx; - if (Itx < (int)ima->GetEffWidth()) return 1; - else { - Ity += Stepy; - if (Ity < (int)ima->GetHeight()){ - IterImage += ima->GetEffWidth(); - Itx = 0; - return 1; - } else - return 0; - } -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::PrevStep() -{ - Itx -= Stepx; - if (Itx >= 0) return 1; - else { - Ity -= Stepy; - if (Ity >= 0 && Ity < (int)ima->GetHeight()) { - IterImage -= ima->GetEffWidth(); - Itx = 0; - return 1; - } else - return 0; - } -} -///////////////////////////////////////////////////////////////////// -inline BOOL CImageIterator::GetCol(BYTE* pCol, DWORD x) -{ - if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth())) - return 0; - DWORD h = ima->GetHeight(); - DWORD line = ima->GetEffWidth(); - BYTE bytes = ima->GetBpp()>>3; - BYTE* pSrc; - for (DWORD y=0;yGetBits(y) + x*bytes; - for (BYTE w=0;wGetBpp()<8)||(x>=ima->GetWidth())) - return 0; - DWORD h = ima->GetHeight(); - DWORD line = ima->GetEffWidth(); - BYTE bytes = ima->GetBpp()>>3; - BYTE* pSrc; - for (DWORD y=0;yGetBits(y) + x*bytes; - for (BYTE w=0;wobj_) jas_free(stream->obj_); - stream->obj_ = pFile; - stream->ops_->close_ = JasClose; - stream->ops_->read_ = JasRead; - stream->ops_->seek_ = JasSeek; - stream->ops_->write_ = JasWrite; - } - static int JasRead(jas_stream_obj_t *obj, char *buf, int cnt) - { return ((CxFile*)obj)->Read(buf,1,cnt); } - static int JasWrite(jas_stream_obj_t *obj, char *buf, int cnt) - { return ((CxFile*)obj)->Write(buf,1,cnt); } - static long JasSeek(jas_stream_obj_t *obj, long offset, int origin) - { return ((CxFile*)obj)->Seek(offset,origin); } - static int JasClose(jas_stream_obj_t *obj) - { return 1; } - }; - -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximajbg.h ./win32/include/cximage/ximajbg.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximajbg.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximajbg.h 1970-01-01 09:00:00 +0900 @@ -1,60 +0,0 @@ -/* - * File: ximajbg.h - * Purpose: JBG Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageJBG (c) 18/Aug/2002 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * based on LIBJBG Copyright (c) 2002, Markus Kuhn - All rights reserved. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaJBG_h) -#define __ximaJBG_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_JBG - -extern "C" { -#include "../jbig/jbig.h" -}; - -class CxImageJBG: public CxImage -{ -public: - CxImageJBG(): CxImage(CXIMAGE_FORMAT_JBG) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JBG);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JBG);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE -protected: - static void jbig_data_out(BYTE *buffer, unsigned int len, void *file) - {((CxFile*)file)->Write(buffer,len,1);} -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximajpg.h ./win32/include/cximage/ximajpg.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximajpg.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximajpg.h 1970-01-01 09:00:00 +0900 @@ -1,321 +0,0 @@ -/* - * File: ximajpg.h - * Purpose: JPG Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes - * - * Special thanks to Chris Shearer Cooper for CxFileJpg tips & code - * - * EXIF support based on jhead-1.8 by Matthias Wandel - * - * original CImageJPG and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * This software is based in part on the work of the Independent JPEG Group. - * Copyright (C) 1991-1998, Thomas G. Lane. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaJPEG_h) -#define __ixmaJPEG_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_JPG - -#define CXIMAGEJPG_SUPPORT_EXIF 1 - -extern "C" { - #include "../jpeg/jpeglib.h" - #include "../jpeg/jerror.h" -} - -class DLL_EXP CxImageJPG: public CxImage -{ -public: - CxImageJPG(); - ~CxImageJPG() {}; - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE - -/* - * EXIF support based on jhead-1.8 by Matthias Wandel - */ - -#if CXIMAGEJPG_SUPPORT_EXIF - -#define MAX_COMMENT 1000 -#define MAX_SECTIONS 20 - -typedef struct tag_ExifInfo { - char Version [5]; - char CameraMake [32]; - char CameraModel [40]; - char DateTime [20]; - int Height, Width; - int Orientation; - int IsColor; - int Process; - int FlashUsed; - float FocalLength; - float ExposureTime; - float ApertureFNumber; - float Distance; - float CCDWidth; - float ExposureBias; - int Whitebalance; - int MeteringMode; - int ExposureProgram; - int ISOequivalent; - int CompressionLevel; - float FocalplaneXRes; - float FocalplaneYRes; - float FocalplaneUnits; - float Xresolution; - float Yresolution; - float ResolutionUnit; - float Brightness; - char Comments[MAX_COMMENT]; - - unsigned char * ThumbnailPointer; /* Pointer at the thumbnail */ - unsigned ThumbnailSize; /* Size of thumbnail. */ - - bool IsExif; -} EXIFINFO; - -//-------------------------------------------------------------------------- -// JPEG markers consist of one or more 0xFF bytes, followed by a marker -// code byte (which is not an FF). Here are the marker codes of interest -// in this program. (See jdmarker.c for a more complete list.) -//-------------------------------------------------------------------------- - -#define M_SOF0 0xC0 // Start Of Frame N -#define M_SOF1 0xC1 // N indicates which compression process -#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 // Start Of Image (beginning of datastream) -#define M_EOI 0xD9 // End Of Image (end of datastream) -#define M_SOS 0xDA // Start Of Scan (begins compressed data) -#define M_JFIF 0xE0 // Jfif marker -#define M_EXIF 0xE1 // Exif marker -#define M_COM 0xFE // COMment - -class CxExifInfo -{ - -typedef struct tag_Section_t{ - BYTE* Data; - int Type; - unsigned Size; -} Section_t; - -public: - EXIFINFO* m_exifinfo; - char m_szLastError[256]; - CxExifInfo(EXIFINFO* info = NULL); - ~CxExifInfo(); - bool DecodeExif(CxFile * hFile); -protected: - bool process_EXIF(unsigned char * CharBuf, unsigned int length); - void process_COM (const BYTE * Data, int length); - void process_SOFn (const BYTE * Data, int marker); - int Get16u(void * Short); - int Get16m(void * Short); - long Get32s(void * Long); - unsigned long Get32u(void * Long); - double ConvertAnyFormat(void * ValuePtr, int Format); - bool ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, - EXIFINFO * const pInfo, unsigned char ** const LastExifRefdP); - int ExifImageWidth; - int MotorolaOrder; - Section_t Sections[MAX_SECTIONS]; - int SectionsRead; - bool freeinfo; -}; - - EXIFINFO m_exifinfo; - bool DecodeExif(CxFile * hFile); - bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); } - -#endif //CXIMAGEJPG_SUPPORT_EXIF - -//////////////////////////////////////////////////////////////////////////////////////// -////////////////////// C x F i l e J p g //////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - -// thanks to Chris Shearer Cooper -class CxFileJpg : public jpeg_destination_mgr, public jpeg_source_mgr - { -public: - enum { eBufSize = 4096 }; - - CxFileJpg(CxFile* pFile) - { - m_pFile = pFile; - - init_destination = InitDestination; - empty_output_buffer = EmptyOutputBuffer; - term_destination = TermDestination; - - init_source = InitSource; - fill_input_buffer = FillInputBuffer; - skip_input_data = SkipInputData; - resync_to_restart = jpeg_resync_to_restart; // use default method - term_source = TermSource; - next_input_byte = NULL; //* => next byte to read from buffer - bytes_in_buffer = 0; //* # of bytes remaining in buffer - - m_pBuffer = new unsigned char[eBufSize]; - } - ~CxFileJpg() - { - delete [] m_pBuffer; - } - - static void InitDestination(j_compress_ptr cinfo) - { - CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; - pDest->next_output_byte = pDest->m_pBuffer; - pDest->free_in_buffer = eBufSize; - } - - static boolean EmptyOutputBuffer(j_compress_ptr cinfo) - { - CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; - if (pDest->m_pFile->Write(pDest->m_pBuffer,1,eBufSize)!=(size_t)eBufSize) - ERREXIT(cinfo, JERR_FILE_WRITE); - pDest->next_output_byte = pDest->m_pBuffer; - pDest->free_in_buffer = eBufSize; - return TRUE; - } - - static void TermDestination(j_compress_ptr cinfo) - { - CxFileJpg* pDest = (CxFileJpg*)cinfo->dest; - size_t datacount = eBufSize - pDest->free_in_buffer; - /* Write any data remaining in the buffer */ - if (datacount > 0) { - if (!pDest->m_pFile->Write(pDest->m_pBuffer,1,datacount)) - ERREXIT(cinfo, JERR_FILE_WRITE); - } - pDest->m_pFile->Flush(); - /* Make sure we wrote the output file OK */ - if (pDest->m_pFile->Error()) ERREXIT(cinfo, JERR_FILE_WRITE); - return; - } - - static void InitSource(j_decompress_ptr cinfo) - { - CxFileJpg* pSource = (CxFileJpg*)cinfo->src; - pSource->m_bStartOfFile = TRUE; - } - - static boolean FillInputBuffer(j_decompress_ptr cinfo) - { - size_t nbytes; - CxFileJpg* pSource = (CxFileJpg*)cinfo->src; - nbytes = pSource->m_pFile->Read(pSource->m_pBuffer,1,eBufSize); - if (nbytes <= 0){ - if (pSource->m_bStartOfFile) //* Treat empty input file as fatal error - ERREXIT(cinfo, JERR_INPUT_EMPTY); - WARNMS(cinfo, JWRN_JPEG_EOF); - // Insert a fake EOI marker - pSource->m_pBuffer[0] = (JOCTET) 0xFF; - pSource->m_pBuffer[1] = (JOCTET) JPEG_EOI; - nbytes = 2; - } - pSource->next_input_byte = pSource->m_pBuffer; - pSource->bytes_in_buffer = nbytes; - pSource->m_bStartOfFile = FALSE; - return TRUE; - } - - static void SkipInputData(j_decompress_ptr cinfo, long num_bytes) - { - CxFileJpg* pSource = (CxFileJpg*)cinfo->src; - if (num_bytes > 0){ - while (num_bytes > (long)pSource->bytes_in_buffer){ - num_bytes -= (long)pSource->bytes_in_buffer; - FillInputBuffer(cinfo); - // note we assume that fill_input_buffer will never return FALSE, - // so suspension need not be handled. - } - pSource->next_input_byte += (size_t) num_bytes; - pSource->bytes_in_buffer -= (size_t) num_bytes; - } - } - - static void TermSource(j_decompress_ptr cinfo) - { - return; - } -protected: - CxFile *m_pFile; - unsigned char *m_pBuffer; - bool m_bStartOfFile; -}; - -public: - enum CODEC_OPTION - { - ENCODE_BASELINE = 0x1, - ENCODE_ARITHMETIC = 0x2, - ENCODE_GRAYSCALE = 0x4, - ENCODE_OPTIMIZE = 0x8, - ENCODE_PROGRESSIVE = 0x10, - ENCODE_LOSSLESS = 0x20, - ENCODE_SMOOTHING = 0x40, - DECODE_GRAYSCALE = 0x80, - DECODE_QUANTIZE = 0x100, - DECODE_DITHER = 0x200, - DECODE_ONEPASS = 0x400, - DECODE_NOSMOOTH = 0x800 - }; - - int m_nPredictor; - int m_nPointTransform; - int m_nSmoothing; - int m_nQuantize; - J_DITHER_MODE m_nDither; - -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximamng.h ./win32/include/cximage/ximamng.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximamng.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximamng.h 1970-01-01 09:00:00 +0900 @@ -1,102 +0,0 @@ -/* - * File: ximamng.h - * Purpose: Declaration of the MNG Image Class - * Author: Davide Pizzolato - www.xdp.it - * Created: 2001 - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageMNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Frank Haug for suggestions and code. - * - * original mng.cpp code created by Nikolaus Brennig, November 14th, 2000. - * - * LIBMNG Copyright (c) 2000,2001 Gerard Juyn (gerard@libmng.com) - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ - -#if !defined(__ximaMNG_h) -#define __ximaMNG_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_MNG - -//#define MNG_NO_CMS -#define MNG_SUPPORT_DISPLAY -#define MNG_SUPPORT_READ -#define MNG_SUPPORT_WRITE -#define MNG_ACCESS_CHUNKS -#define MNG_STORE_CHUNKS - -extern "C" { -#include "../mng/libmng.h" -#include "../mng/libmng_data.h" -} - -//unsigned long _stdcall RunMNGThread(void *lpParam); - -typedef struct tagmngstuff -{ - CxFile *file; - BYTE *image; - HANDLE thread; - mng_uint32 delay; - mng_uint32 width; - mng_uint32 height; - mng_uint32 effwdt; - mng_int16 bpp; - mng_bool animation; - mng_bool animation_enabled; - float speed; - long nBkgndIndex; - RGBQUAD nBkgndColor; -} mngstuff; - -class CxImageMNG: public CxImage -{ -public: - CxImageMNG(); - ~CxImageMNG(); - - bool Load(const char * imageFileName); - bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_MNG);} - - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE - - long Resume(); - void SetSpeed(float speed); - - mng_handle hmng; - mngstuff mnginfo; -protected: - void WritePNG(mng_handle hMNG, int Frame, int FrameCount ); - void SetCallbacks(mng_handle mng); -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximapcx.h ./win32/include/cximage/ximapcx.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximapcx.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximapcx.h 1970-01-01 09:00:00 +0900 @@ -1,80 +0,0 @@ -/* - * File: ximapcx.h - * Purpose: PCX Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImagePCX (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Parts of the code come from Paintlib - * Copyright (c) 1996-1998 Ulrich von Zadow - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaPCX_h) -#define __ximaPCX_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_PCX - -class CxImagePCX: public CxImage -{ -// PCX Image File -#pragma pack(1) -typedef struct tagPCXHEADER -{ - char Manufacturer; // always 0X0A - char Version; // version number - char Encoding; // always 1 - char BitsPerPixel; // color bits - WORD Xmin, Ymin; // image origin - WORD Xmax, Ymax; // image dimensions - WORD Hres, Vres; // resolution values - BYTE ColorMap[16][3]; // color palette - char Reserved; - char ColorPlanes; // color planes - WORD BytesPerLine; // line buffer size - WORD PaletteType; // grey or color palette - char Filter[58]; -} PCXHEADER; -#pragma pack() - -public: - CxImagePCX(): CxImage(CXIMAGE_FORMAT_PCX) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PCX);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PCX);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE -protected: - void PCX_PlanesToPixels(BYTE * pixels, BYTE * bitplanes, short bytesperline, short planes, short bitsperpixel); - void PCX_UnpackPixels(BYTE * pixels, BYTE * bitplanes, short bytesperline, short planes, short bitsperpixel); - void PCX_PackPixels(const long p,BYTE &c, BYTE &n, CxFile &f); - void PCX_PackPlanes(BYTE* buff, const long size, CxFile &f); - void PCX_PixelsToPlanes(BYTE* raw, long width, BYTE* buf, long plane); -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximapng.h ./win32/include/cximage/ximapng.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximapng.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximapng.h 1970-01-01 09:00:00 +0900 @@ -1,90 +0,0 @@ -/* - * File: ximapng.h - * Purpose: PNG Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes - * - * original CImagePNG and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * libpng version 1.2.1 - December 12, 2001 - * Copyright (c) 1998-2001 Glenn Randers-Pehrson - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaPNG_h) -#define __ximaPNG_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_PNG - -extern "C" { -#include "../png/png.h" -} - -class CxImagePNG: public CxImage -{ -public: - CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE - -protected: - void ima_png_error(png_struct *png_ptr, char *message); - void expand2to4bpp(BYTE* prow); - - static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) - { - CxFile* hFile = (CxFile*)png_ptr->io_ptr; - if (hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error"); - } - - static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) - { - CxFile* hFile = (CxFile*)png_ptr->io_ptr; - if (hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error"); - } - - static void user_flush_data(png_structp png_ptr) - { - CxFile* hFile = (CxFile*)png_ptr->io_ptr; - if (!hFile->Flush()) png_error(png_ptr, "Flush Error"); - } - static void user_error_fn(png_structp png_ptr,png_const_charp error_msg) - { - strncpy((char*)png_ptr->error_ptr,error_msg,255); - longjmp(png_ptr->jmpbuf, 1); - } -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximatga.h ./win32/include/cximage/ximatga.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximatga.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximatga.h 1970-01-01 09:00:00 +0900 @@ -1,77 +0,0 @@ -/* - * File: ximatga.h - * Purpose: TARGA Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageTGA (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Parts of the code come from Paintlib - * Copyright (c) 1996-1998 Ulrich von Zadow - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaTGA_h) -#define __ximaTGA_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_TGA - -class CxImageTGA: public CxImage -{ -#pragma pack(1) -typedef struct tagTgaHeader -{ - BYTE IdLength; // Image ID Field Length - BYTE CmapType; // Color Map Type - BYTE ImageType; // Image Type - - WORD CmapIndex; // First Entry Index - WORD CmapLength; // Color Map Length - BYTE CmapEntrySize; // Color Map Entry Size - - WORD X_Origin; // X-origin of Image - WORD Y_Origin; // Y-origin of Image - WORD ImageWidth; // Image Width - WORD ImageHeight; // Image Height - BYTE PixelDepth; // Pixel Depth - BYTE ImagDesc; // Image Descriptor -} TGAHEADER; -#pragma pack() - -public: - CxImageTGA(): CxImage(CXIMAGE_FORMAT_TGA) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TGA);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TGA);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE -protected: - BYTE ExpandCompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, BYTE rleLeftover); - void ExpandUncompressedLine(BYTE* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int width, int y, int xoffset); -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximatif.h ./win32/include/cximage/ximatif.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximatif.h 2004-02-29 22:07:01 +0900 +++ ./win32/include/cximage/ximatif.h 1970-01-01 09:00:00 +0900 @@ -1,85 +0,0 @@ -/* - * File: ximatif.h - * Purpose: TIFF Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageTIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes - * - * Special thanks to Abe for MultiPageTIFF code. - * - * Parts of the code come from FreeImage 2 - * Design and implementation by - * - Floris van den Berg (flvdberg@wxs.nl) - * - Hervé Drolon (drolon@iut.univ-lehavre.fr) - * - Markus Loibl (markus.loibl@epost.de) - * - Luca Piergentili (l.pierge@terra.es) - * - * LibTIFF is: - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ - - - -#if !defined(__ximatif_h) -#define __ximatif_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_TIF - -#include "../tiff/tiffio.h" - -class DLL_EXP CxImageTIF: public CxImage -{ -public: - CxImageTIF(): CxImage(CXIMAGE_FORMAT_TIF) {m_tif2=NULL; m_multipage=false; m_pages=0;} - ~CxImageTIF(); - - TIFF* TIFFOpenEx(CxFile * hFile); - void TIFFCloseEx(TIFF* tif); - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TIF);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TIF);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile, bool bAppend=false); - bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount); - bool Encode(FILE *hFile, bool bAppend=false) { CxIOFile file(hFile); return Encode(&file,bAppend); } - bool Encode(FILE *hFile, CxImage ** pImages, int pagecount) - { CxIOFile file(hFile); return Encode(&file, pImages, pagecount); } -#endif // CXIMAGE_SUPPORT_ENCODE - -protected: - void TileToStrip(uint8* out, uint8* in, uint32 rows, uint32 cols, int outskew, int inskew); - bool EncodeBody(TIFF *m_tif, bool multipage=false, int page=0, int pagecount=0); - TIFF *m_tif2; - bool m_multipage; - int m_pages; -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximawbmp.h ./win32/include/cximage/ximawbmp.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximawbmp.h 2004-02-29 22:07:02 +0900 +++ ./win32/include/cximage/ximawbmp.h 1970-01-01 09:00:00 +0900 @@ -1,60 +0,0 @@ -/* - * File: ximawbmp.h - * Purpose: WBMP Image Class Loader and Writer - */ -/* === C R E D I T S & D I S C L A I M E R S ============== - * CxImageWBMP (c) 12/Jul/2002 Davide Pizzolato - www.xdp.it - * Permission is given by the author to freely redistribute and include - * this code in any program as long as this credit is given where due. - * - * CxImage version 5.99a 08/Feb/2004 - * See the file history.htm for the complete bugfix and news report. - * - * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES - * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE - * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED - * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT - * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY - * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL - * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. - * - * Use at your own risk! - * ========================================================== - */ -#if !defined(__ximaWBMP_h) -#define __ximaWBMP_h - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_WBMP - -class CxImageWBMP: public CxImage -{ -#pragma pack(1) -typedef struct tagWbmpHeader -{ - BYTE Type; // 0 - BYTE FixHeader; // 0 - BYTE ImageWidth; // Image Width - BYTE ImageHeight; // Image Height -} WBMPHEADER; -#pragma pack() -public: - CxImageWBMP(): CxImage(CXIMAGE_FORMAT_WBMP) {} - -// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_WBMP);} -// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_WBMP);} - bool Decode(CxFile * hFile); - bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE -}; - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximawmf.h ./win32/include/cximage/ximawmf.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/ximawmf.h 2004-02-29 22:07:02 +0900 +++ ./win32/include/cximage/ximawmf.h 1970-01-01 09:00:00 +0900 @@ -1,154 +0,0 @@ -/* -********************************************************************* - * File: ximawmf.h - * Purpose: Windows Metafile Class Loader and Writer - * Author: Volker Horch - vhorch@gmx.de - * created: 13-Jun-2002 -********************************************************************* - */ - -/* -********************************************************************* - Notes by Author: -********************************************************************* - - Limitations: - ============ - - a) Transparency: - - A Metafile is vector graphics, which has transparency by design. - This class always converts into a Bitmap format. Transparency is - supported, but there is no good way to find out, which parts - of the Metafile are transparent. There are two ways how we can - handle this: - - - Clear the Background of the Bitmap with the background color - you like (i have used COLOR_WINDOW) and don't support transparency. - - below #define XMF_SUPPORT_TRANSPARENCY 0 - #define XMF_COLOR_BACK RGB(Background color you like) - - - Clear the Background of the Bitmap with a very unusual color - (which one ?) and use this color as the transparent color - - below #define XMF_SUPPORT_TRANSPARENCY 1 - #define XMF_COLOR_TRANSPARENT_R ... - #define XMF_COLOR_TRANSPARENT_G ... - #define XMF_COLOR_TRANSPARENT_B ... - - b) Resolution - - Once we have converted the Metafile into a Bitmap and we zoom in - or out, the image may not look very good. If we still had the - original Metafile, zooming would produce good results always. - - c) Size - - Although the filesize of a Metafile may be very small, it might - produce a Bitmap with a bombastic size. Assume you have a Metafile - with an image size of 6000*4000, which contains just one Metafile - record ((e.g. a line from (0,0) to (6000, 4000)). The filesize - of this Metafile would be let's say 100kB. If we convert it to - a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume - about 68MB of memory. - - I have choosen, to limit the size of the Bitmap to max. - screensize, to avoid memory problems. - - If you want something else, - modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below - -********************************************************************* -*/ - -#ifndef _XIMAWMF_H -#define _XIMAWMF_H - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS - -class CxImageWMF: public CxImage -{ - -#pragma pack(1) - -typedef struct tagRECT16 -{ - short int left; - short int top; - short int right; - short int bottom; -} RECT16; - -// taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources) -typedef struct tagMETAFILEHEADER -{ - DWORD key; // always 0x9ac6cdd7 - WORD reserved1; // reserved = 0 - RECT16 bbox; // bounding rectangle in metafile units as defined in "inch" - WORD inch; // number of metafile units per inch (should be < 1440) - DWORD reserved2; // reserved = 0 - WORD checksum; // sum of the first 10 WORDS (using XOR operator) -} METAFILEHEADER; - -#pragma pack() - -public: - CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { } - - bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0); - bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0) - { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); } - -#if CXIMAGE_SUPPORT_ENCODE - bool Encode(CxFile * hFile); - bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } -#endif // CXIMAGE_SUPPORT_ENCODE - -protected: - void ShrinkMetafile(int &cx, int &cy); - BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader); - HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader); - HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh); - -}; - -#define METAFILEKEY 0x9ac6cdd7L - -// Background color definition (if no transparency). see Notes above -#define XMF_COLOR_BACK GetSysColor(COLOR_WINDOW) -// alternatives -//#define XMF_COLOR_BACK RGB(192, 192, 192) // lite gray -//#define XMF_COLOR_BACK RGB( 0, 0, 0) // black -//#define XMF_COLOR_BACK RGB(255, 255, 255) // white - - -// transparency support. see Notes above -#define XMF_SUPPORT_TRANSPARENCY 0 -#define XMF_COLOR_TRANSPARENT_R 211 -#define XMF_COLOR_TRANSPARENT_G 121 -#define XMF_COLOR_TRANSPARENT_B 112 -// don't change -#define XMF_COLOR_TRANSPARENT RGB (XMF_COLOR_TRANSPARENT_R, \ - XMF_COLOR_TRANSPARENT_G, \ - XMF_COLOR_TRANSPARENT_B) -// don't change -#define XMF_RGBQUAD_TRANSPARENT XMF_COLOR_TRANSPARENT_B, \ - XMF_COLOR_TRANSPARENT_G, \ - XMF_COLOR_TRANSPARENT_R, \ - 0 -// max. size. see Notes above -// alternatives -//#define XMF_MAXSIZE_CX (GetSystemMetrics(SM_CXSCREEN)-10) -//#define XMF_MAXSIZE_CY (GetSystemMetrics(SM_CYSCREEN)-50) -//#define XMF_MAXSIZE_CX (2*GetSystemMetrics(SM_CXSCREEN)/3) -//#define XMF_MAXSIZE_CY (2*GetSystemMetrics(SM_CYSCREEN)/3) -#define XMF_MAXSIZE_CX 4000 -#define XMF_MAXSIZE_CY 4000 - - -#endif - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/xiofile.h ./win32/include/cximage/xiofile.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/xiofile.h 2004-02-29 22:07:02 +0900 +++ ./win32/include/cximage/xiofile.h 1970-01-01 09:00:00 +0900 @@ -1,112 +0,0 @@ -#if !defined(__xiofile_h) -#define __xiofile_h - -#include "xfile.h" - -class DLL_EXP CxIOFile : public CxFile - { -public: - CxIOFile(FILE* fp = NULL) - { - m_fp = fp; - m_bCloseFile = (bool)(fp==0); - } - - ~CxIOFile() - { - Close(); - } -////////////////////////////////////////////////////////// - bool Open(const char *filename, const char *mode) - { - if (m_fp) return false; // Can't re-open without closing first - - m_fp = fopen(filename, mode); - if (!m_fp) return false; - - m_bCloseFile = true; - - return true; - } -////////////////////////////////////////////////////////// - virtual bool Close() - { - int iErr = 0; - if ( (m_fp) && (m_bCloseFile) ){ - iErr = fclose(m_fp); - m_fp = NULL; - } - return (bool)(iErr==0); - } -////////////////////////////////////////////////////////// - virtual size_t Read(void *buffer, size_t size, size_t count) - { - if (!m_fp) return 0; - return fread(buffer, size, count, m_fp); - } -////////////////////////////////////////////////////////// - virtual size_t Write(const void *buffer, size_t size, size_t count) - { - if (!m_fp) return 0; - return fwrite(buffer, size, count, m_fp); - } -////////////////////////////////////////////////////////// - virtual bool Seek(long offset, int origin) - { - if (!m_fp) return false; - return (bool)(fseek(m_fp, offset, origin) == 0); - } -////////////////////////////////////////////////////////// - virtual long Tell() - { - if (!m_fp) return 0; - return ftell(m_fp); - } -////////////////////////////////////////////////////////// - virtual long Size() - { - if (!m_fp) return -1; - long pos,size; - pos = ftell(m_fp); - fseek(m_fp, 0, SEEK_END); - size = ftell(m_fp); - fseek(m_fp, pos,SEEK_SET); - return size; - } -////////////////////////////////////////////////////////// - virtual bool Flush() - { - if (!m_fp) return false; - return (bool)(fflush(m_fp) == 0); - } -////////////////////////////////////////////////////////// - virtual bool Eof() - { - if (!m_fp) return true; - return (bool)(feof(m_fp) != 0); - } -////////////////////////////////////////////////////////// - virtual long Error() - { - if (!m_fp) return -1; - return ferror(m_fp); - } -////////////////////////////////////////////////////////// - virtual bool PutC(unsigned char c) - { - if (!m_fp) return false; - return (bool)(fputc(c, m_fp) == c); - } -////////////////////////////////////////////////////////// - virtual long GetC() - { - if (!m_fp) return EOF; - return getc(m_fp); - } -////////////////////////////////////////////////////////// -protected: - FILE *m_fp; - bool m_bCloseFile; - }; - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/cximage/xmemfile.h ./win32/include/cximage/xmemfile.h --- ../VisualBoyAdvance-1.7.2/win32/include/cximage/xmemfile.h 2004-02-29 22:07:02 +0900 +++ ./win32/include/cximage/xmemfile.h 1970-01-01 09:00:00 +0900 @@ -1,69 +0,0 @@ -#if !defined(__xmemfile_h) -#define __xmemfile_h - -#include "xfile.h" - -////////////////////////////////////////////////////////// -class DLL_EXP CxMemFile : public CxFile - { -public: - CxMemFile(BYTE* pBuffer = NULL, DWORD size = 0) - { - m_pBuffer = pBuffer; - m_Position = 0; - m_Size = m_Edge = size; - m_bFreeOnClose = (bool)(pBuffer==0); - } -////////////////////////////////////////////////////////// - ~CxMemFile() - { - Close(); - } -////////////////////////////////////////////////////////// - virtual bool Close() - { - if ( (m_pBuffer) && (m_bFreeOnClose) ){ - free(m_pBuffer); - m_pBuffer = NULL; - m_Size = 0; - } - return true; - } -////////////////////////////////////////////////////////// - bool Open() - { - if (m_pBuffer) return false; // Can't re-open without closing first - - m_Position = m_Size = m_Edge = 0; - m_pBuffer=(BYTE*)malloc(0); - m_bFreeOnClose = true; - - return (m_pBuffer!=0); - } -////////////////////////////////////////////////////////// -BYTE* GetBuffer(bool bDetachBuffer = true) { m_bFreeOnClose = !bDetachBuffer; return m_pBuffer;} -////////////////////////////////////////////////////////// - virtual size_t Read(void *buffer, size_t size, size_t count); - virtual size_t Write(const void *buffer, size_t size, size_t count); - virtual bool Seek(long offset, int origin); - virtual long Tell(); - virtual long Size(); - virtual bool Flush(); - virtual bool Eof(); - virtual long Error(); - virtual bool PutC(unsigned char c); - virtual long GetC(); - -protected: - void Alloc(DWORD nBytes); - void Free(); - -protected: - BYTE* m_pBuffer; - DWORD m_Size; - bool m_bFreeOnClose; - long m_Position; //current position - long m_Edge; //buffer size - }; - -#endif diff -urN ../VisualBoyAdvance-1.7.2/win32/include/png/png.h ./win32/include/png/png.h --- ../VisualBoyAdvance-1.7.2/win32/include/png/png.h 2002-10-20 22:03:13 +0900 +++ ./win32/include/png/png.h 1970-01-01 09:00:00 +0900 @@ -1,3156 +0,0 @@ - -/* png.h - header file for PNG reference library - * - * libpng version 1.2.0 - September 1, 2001 - * Copyright (c) 1998-2001 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * Authors and maintainers: - * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat - * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.2.0 - September 1, 2001: Glenn - * See also "Contributing Authors", below. - * - * Note about libpng version numbers: - * - * Due to various miscommunications, unforeseen code incompatibilities - * and occasional factors outside the authors' control, version numbering - * on the library has not always been consistent and straightforward. - * The following table summarizes matters since version 0.89c, which was - * the first widely used release: - * - * source png.h png.h shared-lib - * version string int version - * ------- ------ ----- ---------- - * 0.89c "1.0 beta 3" 0.89 89 1.0.89 - * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] - * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] - * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] - * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] - * 0.97c 0.97 97 2.0.97 - * 0.98 0.98 98 2.0.98 - * 0.99 0.99 98 2.0.99 - * 0.99a-m 0.99 99 2.0.99 - * 1.00 1.00 100 2.1.0 [100 should be 10000] - * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] - * 1.0.1 png.h string is 10001 2.1.0 - * 1.0.1a-e identical to the 10002 from here on, the shared library - * 1.0.2 source version) 10002 is 2.V where V is the source code - * 1.0.2a-b 10003 version, except as noted. - * 1.0.3 10003 - * 1.0.3a-d 10004 - * 1.0.4 10004 - * 1.0.4a-f 10005 - * 1.0.5 (+ 2 patches) 10005 - * 1.0.5a-d 10006 - * 1.0.5e-r 10100 (not source compatible) - * 1.0.5s-v 10006 (not binary compatible) - * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) - * 1.0.6d-f 10007 (still binary incompatible) - * 1.0.6g 10007 - * 1.0.6h 10007 10.6h (testing xy.z so-numbering) - * 1.0.6i 10007 10.6i - * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) - * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) - * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) - * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) - * 1.0.7 1 10007 (still compatible) - * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 - * 1.0.8rc1 1 10008 2.1.0.8rc1 - * 1.0.8 1 10008 2.1.0.8 - * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 - * 1.0.9rc1 1 10009 2.1.0.9rc1 - * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 - * 1.0.9rc2 1 10009 2.1.0.9rc2 - * 1.0.9 1 10009 2.1.0.9 - * 1.0.10beta1 1 10010 2.1.0.10beta1 - * 1.0.10rc1 1 10010 2.1.0.10rc1 - * 1.0.10 1 10010 2.1.0.10 - * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 - * 1.0.11rc1 1 10011 2.1.0.11rc1 - * 1.0.11 1 10011 2.1.0.11 - * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 - * 1.0.12rc1 2 10012 2.1.0.12rc1 - * 1.0.12 2 10012 2.1.0.12 - * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) - * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 - * 1.2.0beta3-4 3 10200 3.1.2.0beta3-4 - * - * Henceforth the source version will match the shared-library major - * and minor numbers; the shared-library major version number will be - * used for changes in backward compatibility, as it is intended. The - * PNG_LIBPNG_VER macro, which is not used within libpng but is available - * for applications, is an unsigned integer of the form xyyzz corresponding - * to the source version x.y.z (leading zeros in y and z). Beta versions - * were given the previous public release number plus a letter, until - * version 1.0.6j; from then on they were given the upcoming public - * release number plus "betaNN" or "rcN". - * - * Binary incompatibility exists only when applications make direct access - * to the info_ptr or png_ptr members through png.h, and the compiled - * application is loaded with a different version of the library. - * - * DLLNUM will change each time there are forward or backward changes - * in binary compatibility (e.g., when a new feature is added). - * - * See libpng.txt or libpng.3 for more information. The PNG specification - * is available as RFC 2083 - * and as a W3C Recommendation - */ - -/* - * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - * - * If you modify libpng you may insert additional notices immediately following - * this sentence. - * - * libpng versions 1.0.7, July 1, 2000, through 1.2.0, September 1, 2001, are - * Copyright (c) 2000, 2001 Glenn Randers-Pehrson, and are - * distributed according to the same disclaimer and license as libpng-1.0.6 - * with the following individuals added to the list of Contributing Authors - * - * Simon-Pierre Cadieux - * Eric S. Raymond - * Gilles Vollant - * - * and with the following additions to the disclaimer: - * - * There is no warranty against interference with your enjoyment of the - * library or against infringement. There is no warranty that our - * efforts or the library will fulfill any of your particular purposes - * or needs. This library is provided with all faults, and the entire - * risk of satisfactory quality, performance, accuracy, and effort is with - * the user. - * - * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are - * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson - * Distributed according to the same disclaimer and license as libpng-0.96, - * with the following individuals added to the list of Contributing Authors: - * - * Tom Lane - * Glenn Randers-Pehrson - * Willem van Schaik - * - * libpng versions 0.89, June 1996, through 0.96, May 1997, are - * Copyright (c) 1996, 1997 Andreas Dilger - * Distributed according to the same disclaimer and license as libpng-0.88, - * with the following individuals added to the list of Contributing Authors: - * - * John Bowler - * Kevin Bracey - * Sam Bushell - * Magnus Holmgren - * Greg Roelofs - * Tom Tanner - * - * libpng versions 0.5, May 1995, through 0.88, January 1996, are - * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - * - * For the purposes of this copyright and license, "Contributing Authors" - * is defined as the following set of individuals: - * - * Andreas Dilger - * Dave Martindale - * Guy Eric Schalnat - * Paul Schmidt - * Tim Wegner - * - * The PNG Reference Library is supplied "AS IS". The Contributing Authors - * and Group 42, Inc. disclaim all warranties, expressed or implied, - * including, without limitation, the warranties of merchantability and of - * fitness for any purpose. The Contributing Authors and Group 42, Inc. - * assume no liability for direct, indirect, incidental, special, exemplary, - * or consequential damages, which may result from the use of the PNG - * Reference Library, even if advised of the possibility of such damage. - * - * Permission is hereby granted to use, copy, modify, and distribute this - * source code, or portions hereof, for any purpose, without fee, subject - * to the following restrictions: - * - * 1. The origin of this source code must not be misrepresented. - * - * 2. Altered versions must be plainly marked as such and - * must not be misrepresented as being the original source. - * - * 3. This Copyright notice may not be removed or altered from - * any source or altered source distribution. - * - * The Contributing Authors and Group 42, Inc. specifically permit, without - * fee, and encourage the use of this source code as a component to - * supporting the PNG file format in commercial products. If you use this - * source code in a product, acknowledgment is not required but would be - * appreciated. - */ - -/* - * A "png_get_copyright" function is available, for convenient use in "about" - * boxes and the like: - * - * printf("%s",png_get_copyright(NULL)); - * - * Also, the PNG logo (in PNG format, of course) is supplied in the - * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). - */ - -/* - * Libpng is OSI Certified Open Source Software. OSI Certified is a - * certification mark of the Open Source Initiative. - */ - -/* - * The contributing authors would like to thank all those who helped - * with testing, bug fixes, and patience. This wouldn't have been - * possible without all of you. - * - * Thanks to Frank J. T. Wojcik for helping with the documentation. - */ - -/* - * Y2K compliance in libpng: - * ========================= - * - * September 1, 2001 - * - * Since the PNG Development group is an ad-hoc body, we can't make - * an official declaration. - * - * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.2.0 are Y2K compliant. It is my belief that earlier - * versions were also Y2K compliant. - * - * Libpng only has three year fields. One is a 2-byte unsigned integer - * that will hold years up to 65535. The other two hold the date in text - * format, and will hold years up to 9999. - * - * The integer is - * "png_uint_16 year" in png_time_struct. - * - * The strings are - * "png_charp time_buffer" in png_struct and - * "near_time_buffer", which is a local character string in png.c. - * - * There are seven time-related functions: - * png.c: png_convert_to_rfc_1123() in png.c - * (formerly png_convert_to_rfc_1152() in error) - * png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c - * png_convert_from_time_t() in pngwrite.c - * png_get_tIME() in pngget.c - * png_handle_tIME() in pngrutil.c, called in pngread.c - * png_set_tIME() in pngset.c - * png_write_tIME() in pngwutil.c, called in pngwrite.c - * - * All handle dates properly in a Y2K environment. The - * png_convert_from_time_t() function calls gmtime() to convert from system - * clock time, which returns (year - 1900), which we properly convert to - * the full 4-digit year. There is a possibility that applications using - * libpng are not passing 4-digit years into the png_convert_to_rfc_1123() - * function, or that they are incorrectly passing only a 2-digit year - * instead of "year - 1900" into the png_convert_from_struct_tm() function, - * but this is not under our control. The libpng documentation has always - * stated that it works with 4-digit years, and the APIs have been - * documented as such. - * - * The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned - * integer to hold the year, and can hold years as large as 65535. - * - * zlib, upon which libpng depends, is also Y2K compliant. It contains - * no date-related code. - * - * Glenn Randers-Pehrson - * libpng maintainer - * PNG Development Group - */ - -#ifndef PNG_H -#define PNG_H - -/* This is not the place to learn how to use libpng. The file libpng.txt - * describes how to use libpng, and the file example.c summarizes it - * with some code on which to build. This file is useful for looking - * at the actual function definitions and structure components. - */ - -/* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.2.0" - -#define PNG_LIBPNG_VER_SONUM 3 -#define PNG_LIBPNG_VER_DLLNUM %DLLNUM% - -/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ -#define PNG_LIBPNG_VER_MAJOR 1 -#define PNG_LIBPNG_VER_MINOR 2 -#define PNG_LIBPNG_VER_RELEASE 0 -/* This should match the numeric part of the final component of - * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ - -#define PNG_LIBPNG_VER_BUILD 0 - -#define PNG_LIBPNG_BUILD_ALPHA 1 -#define PNG_LIBPNG_BUILD_BETA 2 -#define PNG_LIBPNG_BUILD_RC 3 -#define PNG_LIBPNG_BUILD_STABLE 4 -#define PNG_LIBPNG_BUILD_TYPEMASK 7 -#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with STABLE only */ -#define PNG_LIBPNG_BUILD_TYPE 4 - -/* Careful here. At one time, Guy wanted to use 082, but that would be octal. - * We must not include leading zeros. - * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only - * version 1.0.0 was mis-numbered 100 instead of 10000). From - * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10200 /* 1.2.0 */ - -#ifndef PNG_VERSION_INFO_ONLY - -/* include the compression library's header */ -#include "zlib.h" - -/* include all user configurable info, including optional assembler routines */ -#include "pngconf.h" - -/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* This file is arranged in several sections. The first section contains - * structure and type definitions. The second section contains the external - * library functions, while the third has the internal library functions, - * which applications aren't expected to use directly. - */ - -/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */ -#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) -/* Version information for C files, stored in png.c. This had better match - * the version above. - */ -#ifdef PNG_USE_GLOBAL_ARRAYS -PNG_EXPORT_VAR (const char) png_libpng_ver[18]; - /* need room for 99.99.99beta99z*/ -#else -#define png_libpng_ver png_get_header_ver(NULL) -#endif - -#ifdef PNG_USE_GLOBAL_ARRAYS -/* This was removed in version 1.0.5c */ -/* Structures to facilitate easy interlacing. See png.c for more details */ -PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7]; -PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7]; -PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7]; -PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7]; -PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7]; -PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7]; -#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW -PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7]; -#endif -/* This isn't currently used. If you need it, see png.c for more details. -PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7]; -*/ -#endif - -#endif /* PNG_NO_EXTERN */ - -/* Three color definitions. The order of the red, green, and blue, (and the - * exact size) is not important, although the size of the fields need to - * be png_byte or png_uint_16 (as defined below). - */ -typedef struct png_color_struct -{ - png_byte red; - png_byte green; - png_byte blue; -} png_color; -typedef png_color FAR * png_colorp; -typedef png_color FAR * FAR * png_colorpp; - -typedef struct png_color_16_struct -{ - png_byte index; /* used for palette files */ - png_uint_16 red; /* for use in red green blue files */ - png_uint_16 green; - png_uint_16 blue; - png_uint_16 gray; /* for use in grayscale files */ -} png_color_16; -typedef png_color_16 FAR * png_color_16p; -typedef png_color_16 FAR * FAR * png_color_16pp; - -typedef struct png_color_8_struct -{ - png_byte red; /* for use in red green blue files */ - png_byte green; - png_byte blue; - png_byte gray; /* for use in grayscale files */ - png_byte alpha; /* for alpha channel files */ -} png_color_8; -typedef png_color_8 FAR * png_color_8p; -typedef png_color_8 FAR * FAR * png_color_8pp; - -/* - * The following two structures are used for the in-core representation - * of sPLT chunks. - */ -typedef struct png_sPLT_entry_struct -{ - png_uint_16 red; - png_uint_16 green; - png_uint_16 blue; - png_uint_16 alpha; - png_uint_16 frequency; -} png_sPLT_entry; -typedef png_sPLT_entry FAR * png_sPLT_entryp; -typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp; - -/* When the depth of the sPLT palette is 8 bits, the color and alpha samples - * occupy the LSB of their respective members, and the MSB of each member - * is zero-filled. The frequency member always occupies the full 16 bits. - */ - -typedef struct png_sPLT_struct -{ - png_charp name; /* palette name */ - png_byte depth; /* depth of palette samples */ - png_sPLT_entryp entries; /* palette entries */ - png_int_32 nentries; /* number of palette entries */ -} png_sPLT_t; -typedef png_sPLT_t FAR * png_sPLT_tp; -typedef png_sPLT_t FAR * FAR * png_sPLT_tpp; - -#ifdef PNG_TEXT_SUPPORTED -/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, - * and whether that contents is compressed or not. The "key" field - * points to a regular zero-terminated C string. The "text", "lang", and - * "lang_key" fields can be regular C strings, empty strings, or NULL pointers. - * However, the * structure returned by png_get_text() will always contain - * regular zero-terminated C strings (possibly empty), never NULL pointers, - * so they can be safely used in printf() and other string-handling functions. - */ -typedef struct png_text_struct -{ - int compression; /* compression value: - -1: tEXt, none - 0: zTXt, deflate - 1: iTXt, none - 2: iTXt, deflate */ - png_charp key; /* keyword, 1-79 character description of "text" */ - png_charp text; /* comment, may be an empty string (ie "") - or a NULL pointer */ - png_size_t text_length; /* length of the text string */ -#ifdef PNG_iTXt_SUPPORTED - png_size_t itxt_length; /* length of the itxt string */ - png_charp lang; /* language code, 0-79 characters - or a NULL pointer */ - png_charp lang_key; /* keyword translated UTF-8 string, 0 or more - chars or a NULL pointer */ -#endif -} png_text; -typedef png_text FAR * png_textp; -typedef png_text FAR * FAR * png_textpp; -#endif - -/* Supported compression types for text in PNG files (tEXt, and zTXt). - * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ -#define PNG_TEXT_COMPRESSION_NONE_WR -3 -#define PNG_TEXT_COMPRESSION_zTXt_WR -2 -#define PNG_TEXT_COMPRESSION_NONE -1 -#define PNG_TEXT_COMPRESSION_zTXt 0 -#define PNG_ITXT_COMPRESSION_NONE 1 -#define PNG_ITXT_COMPRESSION_zTXt 2 -#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */ - -/* png_time is a way to hold the time in an machine independent way. - * Two conversions are provided, both from time_t and struct tm. There - * is no portable way to convert to either of these structures, as far - * as I know. If you know of a portable way, send it to me. As a side - * note - PNG has always been Year 2000 compliant! - */ -typedef struct png_time_struct -{ - png_uint_16 year; /* full year, as in, 1995 */ - png_byte month; /* month of year, 1 - 12 */ - png_byte day; /* day of month, 1 - 31 */ - png_byte hour; /* hour of day, 0 - 23 */ - png_byte minute; /* minute of hour, 0 - 59 */ - png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ -} png_time; -typedef png_time FAR * png_timep; -typedef png_time FAR * FAR * png_timepp; - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) -/* png_unknown_chunk is a structure to hold queued chunks for which there is - * no specific support. The idea is that we can use this to queue - * up private chunks for output even though the library doesn't actually - * know about their semantics. - */ -typedef struct png_unknown_chunk_t -{ - png_byte name[5]; - png_byte *data; - png_size_t size; - - /* libpng-using applications should NOT directly modify this byte. */ - png_byte location; /* mode of operation at read time */ -} -png_unknown_chunk; -typedef png_unknown_chunk FAR * png_unknown_chunkp; -typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; -#endif - -/* png_info is a structure that holds the information in a PNG file so - * that the application can find out the characteristics of the image. - * If you are reading the file, this structure will tell you what is - * in the PNG file. If you are writing the file, fill in the information - * you want to put into the PNG file, then call png_write_info(). - * The names chosen should be very close to the PNG specification, so - * consult that document for information about the meaning of each field. - * - * With libpng < 0.95, it was only possible to directly set and read the - * the values in the png_info_struct, which meant that the contents and - * order of the values had to remain fixed. With libpng 0.95 and later, - * however, there are now functions that abstract the contents of - * png_info_struct from the application, so this makes it easier to use - * libpng with dynamic libraries, and even makes it possible to use - * libraries that don't have all of the libpng ancillary chunk-handing - * functionality. - * - * In any case, the order of the parameters in png_info_struct should NOT - * be changed for as long as possible to keep compatibility with applications - * that use the old direct-access method with png_info_struct. - * - * The following members may have allocated storage attached that should be - * cleaned up before the structure is discarded: palette, trans, text, - * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, - * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these - * are automatically freed when the info structure is deallocated, if they were - * allocated internally by libpng. This behavior can be changed by means - * of the png_data_freer() function. - * - * More allocation details: all the chunk-reading functions that - * change these members go through the corresponding png_set_* - * functions. A function to clear these members is available: see - * png_free_data(). The png_set_* functions do not depend on being - * able to point info structure members to any of the storage they are - * passed (they make their own copies), EXCEPT that the png_set_text - * functions use the same storage passed to them in the text_ptr or - * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns - * functions do not make their own copies. - */ -typedef struct png_info_struct -{ - /* the following are necessary for every PNG file */ - png_uint_32 width; /* width of image in pixels (from IHDR) */ - png_uint_32 height; /* height of image in pixels (from IHDR) */ - png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ - png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */ - png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ - png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ - png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ - png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ - png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ - /* The following three should have been named *_method not *_type */ - png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ - png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ - png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ - - /* The following is informational only on read, and not used on writes. */ - png_byte channels; /* number of data channels per pixel (1, 2, 3, 4)*/ - png_byte pixel_depth; /* number of bits per pixel */ - png_byte spare_byte; /* to align the data, and for future use */ - png_byte signature[8]; /* magic bytes read by libpng from start of file */ - - /* The rest of the data is optional. If you are reading, check the - * valid field to see if the information in these are valid. If you - * are writing, set the valid field to those chunks you want written, - * and initialize the appropriate fields below. - */ - -#if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) - /* The gAMA chunk describes the gamma characteristics of the system - * on which the image was created, normally in the range [1.0, 2.5]. - * Data is valid if (valid & PNG_INFO_gAMA) is non-zero. - */ - float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */ -#endif - -#if defined(PNG_sRGB_SUPPORTED) - /* GR-P, 0.96a */ - /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */ - png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */ -#endif - -#if defined(PNG_TEXT_SUPPORTED) - /* The tEXt, and zTXt chunks contain human-readable textual data in - * uncompressed, compressed, and optionally compressed forms, respectively. - * The data in "text" is an array of pointers to uncompressed, - * null-terminated C strings. Each chunk has a keyword that describes the - * textual data contained in that chunk. Keywords are not required to be - * unique, and the text string may be empty. Any number of text chunks may - * be in an image. - */ - int num_text; /* number of comments read/to write */ - int max_text; /* current size of text array */ - png_textp text; /* array of comments read/to write */ -#endif /* PNG_TEXT_SUPPORTED */ - -#if defined(PNG_tIME_SUPPORTED) - /* The tIME chunk holds the last time the displayed image data was - * modified. See the png_time struct for the contents of this struct. - */ - png_time mod_time; -#endif - -#if defined(PNG_sBIT_SUPPORTED) - /* The sBIT chunk specifies the number of significant high-order bits - * in the pixel data. Values are in the range [1, bit_depth], and are - * only specified for the channels in the pixel data. The contents of - * the low-order bits is not specified. Data is valid if - * (valid & PNG_INFO_sBIT) is non-zero. - */ - png_color_8 sig_bit; /* significant bits in color channels */ -#endif - -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ -defined(PNG_READ_BACKGROUND_SUPPORTED) - /* The tRNS chunk supplies transparency data for paletted images and - * other image types that don't need a full alpha channel. There are - * "num_trans" transparency values for a paletted image, stored in the - * same order as the palette colors, starting from index 0. Values - * for the data are in the range [0, 255], ranging from fully transparent - * to fully opaque, respectively. For non-paletted images, there is a - * single color specified that should be treated as fully transparent. - * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. - */ - png_bytep trans; /* transparent values for paletted image */ - png_color_16 trans_values; /* transparent color for non-palette image */ -#endif - -#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - /* The bKGD chunk gives the suggested image background color if the - * display program does not have its own background color and the image - * is needs to composited onto a background before display. The colors - * in "background" are normally in the same color space/depth as the - * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. - */ - png_color_16 background; -#endif - -#if defined(PNG_oFFs_SUPPORTED) - /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards - * and downwards from the top-left corner of the display, page, or other - * application-specific co-ordinate space. See the PNG_OFFSET_ defines - * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. - */ - png_int_32 x_offset; /* x offset on page */ - png_int_32 y_offset; /* y offset on page */ - png_byte offset_unit_type; /* offset units type */ -#endif - -#if defined(PNG_pHYs_SUPPORTED) - /* The pHYs chunk gives the physical pixel density of the image for - * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ - * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. - */ - png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ - png_uint_32 y_pixels_per_unit; /* vertical pixel density */ - png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ -#endif - -#if defined(PNG_hIST_SUPPORTED) - /* The hIST chunk contains the relative frequency or importance of the - * various palette entries, so that a viewer can intelligently select a - * reduced-color palette, if required. Data is an array of "num_palette" - * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) - * is non-zero. - */ - png_uint_16p hist; -#endif - -#ifdef PNG_cHRM_SUPPORTED - /* The cHRM chunk describes the CIE color characteristics of the monitor - * on which the PNG was created. This data allows the viewer to do gamut - * mapping of the input image to ensure that the viewer sees the same - * colors in the image as the creator. Values are in the range - * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero. - */ -#ifdef PNG_FLOATING_POINT_SUPPORTED - float x_white; - float y_white; - float x_red; - float y_red; - float x_green; - float y_green; - float x_blue; - float y_blue; -#endif -#endif - -#if defined(PNG_pCAL_SUPPORTED) - /* The pCAL chunk describes a transformation between the stored pixel - * values and original physical data values used to create the image. - * The integer range [0, 2^bit_depth - 1] maps to the floating-point - * range given by [pcal_X0, pcal_X1], and are further transformed by a - * (possibly non-linear) transformation function given by "pcal_type" - * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ - * defines below, and the PNG-Group's PNG extensions document for a - * complete description of the transformations and how they should be - * implemented, and for a description of the ASCII parameter strings. - * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. - */ - png_charp pcal_purpose; /* pCAL chunk description string */ - png_int_32 pcal_X0; /* minimum value */ - png_int_32 pcal_X1; /* maximum value */ - png_charp pcal_units; /* Latin-1 string giving physical units */ - png_charpp pcal_params; /* ASCII strings containing parameter values */ - png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ - png_byte pcal_nparams; /* number of parameters given in pcal_params */ -#endif - -/* New members added in libpng-1.0.6 */ -#ifdef PNG_FREE_ME_SUPPORTED - png_uint_32 free_me; /* flags items libpng is responsible for freeing */ -#endif - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - /* storage for unknown chunks that the library doesn't recognize. */ - png_unknown_chunkp unknown_chunks; - png_size_t unknown_chunks_num; -#endif - -#if defined(PNG_iCCP_SUPPORTED) - /* iCCP chunk data. */ - png_charp iccp_name; /* profile name */ - png_charp iccp_profile; /* International Color Consortium profile data */ - /* Note to maintainer: should be png_bytep */ - png_uint_32 iccp_proflen; /* ICC profile data length */ - png_byte iccp_compression; /* Always zero */ -#endif - -#if defined(PNG_sPLT_SUPPORTED) - /* data on sPLT chunks (there may be more than one). */ - png_sPLT_tp splt_palettes; - png_uint_32 splt_palettes_num; -#endif - -#if defined(PNG_sCAL_SUPPORTED) - /* The sCAL chunk describes the actual physical dimensions of the - * subject matter of the graphic. The chunk contains a unit specification - * a byte value, and two ASCII strings representing floating-point - * values. The values are width and height corresponsing to one pixel - * in the image. This external representation is converted to double - * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero. - */ - png_byte scal_unit; /* unit of physical scale */ -#ifdef PNG_FLOATING_POINT_SUPPORTED - double scal_pixel_width; /* width of one pixel */ - double scal_pixel_height; /* height of one pixel */ -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED - png_charp scal_s_width; /* string containing height */ - png_charp scal_s_height; /* string containing width */ -#endif -#endif - -#if defined(PNG_INFO_IMAGE_SUPPORTED) - /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */ - /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ - png_bytepp row_pointers; /* the image bits */ -#endif - -#if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED) - png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */ -#endif - -#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED) - png_fixed_point int_x_white; - png_fixed_point int_y_white; - png_fixed_point int_x_red; - png_fixed_point int_y_red; - png_fixed_point int_x_green; - png_fixed_point int_y_green; - png_fixed_point int_x_blue; - png_fixed_point int_y_blue; -#endif - -} png_info; - -typedef png_info FAR * png_infop; -typedef png_info FAR * FAR * png_infopp; - -/* Maximum positive integer used in PNG is (2^31)-1 */ -#define PNG_MAX_UINT ((png_uint_32)0x7fffffffL) - -/* These describe the color_type field in png_info. */ -/* color type masks */ -#define PNG_COLOR_MASK_PALETTE 1 -#define PNG_COLOR_MASK_COLOR 2 -#define PNG_COLOR_MASK_ALPHA 4 - -/* color types. Note that not all combinations are legal */ -#define PNG_COLOR_TYPE_GRAY 0 -#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) -#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) -#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) -#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) -/* aliases */ -#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA -#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA - -/* This is for compression type. PNG 1.0-1.2 only define the single type. */ -#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */ -#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE - -/* This is for filter type. PNG 1.0-1.2 only define the single type. */ -#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */ -#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */ -#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE - -/* These are for the interlacing type. These values should NOT be changed. */ -#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */ -#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */ -#define PNG_INTERLACE_LAST 2 /* Not a valid value */ - -/* These are for the oFFs chunk. These values should NOT be changed. */ -#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */ -#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */ -#define PNG_OFFSET_LAST 2 /* Not a valid value */ - -/* These are for the pCAL chunk. These values should NOT be changed. */ -#define PNG_EQUATION_LINEAR 0 /* Linear transformation */ -#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */ -#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */ -#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */ -#define PNG_EQUATION_LAST 4 /* Not a valid value */ - -/* These are for the sCAL chunk. These values should NOT be changed. */ -#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */ -#define PNG_SCALE_METER 1 /* meters per pixel */ -#define PNG_SCALE_RADIAN 2 /* radians per pixel */ -#define PNG_SCALE_LAST 3 /* Not a valid value */ - -/* These are for the pHYs chunk. These values should NOT be changed. */ -#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */ -#define PNG_RESOLUTION_METER 1 /* pixels/meter */ -#define PNG_RESOLUTION_LAST 2 /* Not a valid value */ - -/* These are for the sRGB chunk. These values should NOT be changed. */ -#define PNG_sRGB_INTENT_PERCEPTUAL 0 -#define PNG_sRGB_INTENT_RELATIVE 1 -#define PNG_sRGB_INTENT_SATURATION 2 -#define PNG_sRGB_INTENT_ABSOLUTE 3 -#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */ - -/* This is for text chunks */ -#define PNG_KEYWORD_MAX_LENGTH 79 - -/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ -#define PNG_MAX_PALETTE_LENGTH 256 - -/* These determine if an ancillary chunk's data has been successfully read - * from the PNG header, or if the application has filled in the corresponding - * data in the info_struct to be written into the output file. The values - * of the PNG_INFO_ defines should NOT be changed. - */ -#define PNG_INFO_gAMA 0x0001 -#define PNG_INFO_sBIT 0x0002 -#define PNG_INFO_cHRM 0x0004 -#define PNG_INFO_PLTE 0x0008 -#define PNG_INFO_tRNS 0x0010 -#define PNG_INFO_bKGD 0x0020 -#define PNG_INFO_hIST 0x0040 -#define PNG_INFO_pHYs 0x0080 -#define PNG_INFO_oFFs 0x0100 -#define PNG_INFO_tIME 0x0200 -#define PNG_INFO_pCAL 0x0400 -#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ -#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ -#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ -#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ -#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */ - -/* This is used for the transformation routines, as some of them - * change these values for the row. It also should enable using - * the routines for other purposes. - */ -typedef struct png_row_info_struct -{ - png_uint_32 width; /* width of row */ - png_uint_32 rowbytes; /* number of bytes in row */ - png_byte color_type; /* color type of row */ - png_byte bit_depth; /* bit depth of row */ - png_byte channels; /* number of channels (1, 2, 3, or 4) */ - png_byte pixel_depth; /* bits per pixel (depth * channels) */ -} png_row_info; - -typedef png_row_info FAR * png_row_infop; -typedef png_row_info FAR * FAR * png_row_infopp; - -/* These are the function types for the I/O functions and for the functions - * that allow the user to override the default I/O functions with his or her - * own. The png_error_ptr type should match that of user-supplied warning - * and error functions, while the png_rw_ptr type should match that of the - * user read/write data functions. - */ -typedef struct png_struct_def png_struct; -typedef png_struct FAR * png_structp; - -typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp)); -typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t)); -typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp)); -typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32, - int)); -typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32, - int)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop)); -typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop)); -typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep, - png_uint_32, int)); -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_LEGACY_SUPPORTED) -typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp, - png_row_infop, png_bytep)); -#endif - -#if defined(PNG_USER_CHUNKS_SUPPORTED) -typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp)); -#endif -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) -typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); -#endif - -/* Transform masks for the high-level interface */ -#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ -#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ -#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ -#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ -#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ -#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ -#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ -#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ -#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ -#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ -#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ -#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ -#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */ - -/* Flags for MNG supported features */ -#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 -#define PNG_FLAG_MNG_FILTER_64 0x04 -#define PNG_ALL_MNG_FEATURES 0x05 - -typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t)); -typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp)); - -/* The structure that holds the information to read and write PNG files. - * The only people who need to care about what is inside of this are the - * people who will be modifying the library for their own special needs. - * It should NOT be accessed directly by an application, except to store - * the jmp_buf. - */ - -struct png_struct_def -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf jmpbuf; /* used in png_error */ -#endif - png_error_ptr error_fn; /* function for printing errors and aborting */ - png_error_ptr warning_fn; /* function for printing warnings */ - png_voidp error_ptr; /* user supplied struct for error functions */ - png_rw_ptr write_data_fn; /* function for writing output data */ - png_rw_ptr read_data_fn; /* function for reading input data */ - png_voidp io_ptr; /* ptr to application struct for I/O functions*/ - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) - png_user_transform_ptr read_user_transform_fn; /* user read transform */ -#endif - -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - png_user_transform_ptr write_user_transform_fn; /* user write transform */ -#endif - -/* These were added in libpng-1.0.2 */ -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - png_voidp user_transform_ptr; /* user supplied struct for user transform */ - png_byte user_transform_depth; /* bit depth of user transformed pixels */ - png_byte user_transform_channels; /* channels in user transformed pixels */ -#endif -#endif - - png_uint_32 mode; /* tells us where we are in the PNG file */ - png_uint_32 flags; /* flags indicating various things to libpng */ - png_uint_32 transformations; /* which transformations to perform */ - - z_stream zstream; /* pointer to decompression structure (below) */ - png_bytep zbuf; /* buffer for zlib */ - png_size_t zbuf_size; /* size of zbuf */ - int zlib_level; /* holds zlib compression level */ - int zlib_method; /* holds zlib compression method */ - int zlib_window_bits; /* holds zlib compression window bits */ - int zlib_mem_level; /* holds zlib compression memory level */ - int zlib_strategy; /* holds zlib compression strategy */ - - png_uint_32 width; /* width of image in pixels */ - png_uint_32 height; /* height of image in pixels */ - png_uint_32 num_rows; /* number of rows in current pass */ - png_uint_32 usr_width; /* width of row at start of write */ - png_uint_32 rowbytes; /* size of row in bytes */ - png_uint_32 irowbytes; /* size of current interlaced row in bytes */ - png_uint_32 iwidth; /* width of current interlaced row in pixels */ - png_uint_32 row_number; /* current row in interlace pass */ - png_bytep prev_row; /* buffer to save previous (unfiltered) row */ - png_bytep row_buf; /* buffer to save current (unfiltered) row */ - png_bytep sub_row; /* buffer to save "sub" row when filtering */ - png_bytep up_row; /* buffer to save "up" row when filtering */ - png_bytep avg_row; /* buffer to save "avg" row when filtering */ - png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ - png_row_info row_info; /* used for transformation routines */ - - png_uint_32 idat_size; /* current IDAT size for read */ - png_uint_32 crc; /* current chunk CRC value */ - png_colorp palette; /* palette from the input file */ - png_uint_16 num_palette; /* number of color entries in palette */ - png_uint_16 num_trans; /* number of transparency values */ - png_byte chunk_name[5]; /* null-terminated name of current chunk */ - png_byte compression; /* file compression type (always 0) */ - png_byte filter; /* file filter type (always 0) */ - png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ - png_byte pass; /* current interlace pass (0 - 6) */ - png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ - png_byte color_type; /* color type of file */ - png_byte bit_depth; /* bit depth of file */ - png_byte usr_bit_depth; /* bit depth of users row */ - png_byte pixel_depth; /* number of bits per pixel */ - png_byte channels; /* number of channels in file */ - png_byte usr_channels; /* channels at start of write */ - png_byte sig_bytes; /* magic bytes read/written from start of file */ - -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) -#ifdef PNG_LEGACY_SUPPORTED - png_byte filler; /* filler byte for pixel expansion */ -#else - png_uint_16 filler; /* filler bytes for pixel expansion */ -#endif -#endif - -#if defined(PNG_bKGD_SUPPORTED) - png_byte background_gamma_type; -# ifdef PNG_FLOATING_POINT_SUPPORTED - float background_gamma; -# endif - png_color_16 background; /* background color in screen gamma space */ -# if defined(PNG_READ_GAMMA_SUPPORTED) - png_color_16 background_1; /* background normalized to gamma 1.0 */ -# endif /* PNG_READ_GAMMA && PNG_bKGD_SUPPORTED */ -#endif /* PNG_bKGD_SUPPORTED */ - -#if defined(PNG_WRITE_FLUSH_SUPPORTED) - png_flush_ptr output_flush_fn;/* Function for flushing output */ - png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ - png_uint_32 flush_rows; /* number of rows written since last flush */ -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - int gamma_shift; /* number of "insignificant" bits 16-bit gamma */ -#ifdef PNG_FLOATING_POINT_SUPPORTED - float gamma; /* file gamma value */ - float screen_gamma; /* screen gamma value (display_exponent) */ -#endif -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - png_bytep gamma_table; /* gamma table for 8-bit depth files */ - png_bytep gamma_from_1; /* converts from 1.0 to screen */ - png_bytep gamma_to_1; /* converts from file to 1.0 */ - png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ - png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ - png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) - png_color_8 sig_bit; /* significant bits in each available channel */ -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) - png_color_8 shift; /* shift for significant bit tranformation */ -#endif - -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ - || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - png_bytep trans; /* transparency values for paletted files */ - png_color_16 trans_values; /* transparency values for non-paletted files */ -#endif - - png_read_status_ptr read_row_fn; /* called after each row is decoded */ - png_write_status_ptr write_row_fn; /* called after each row is encoded */ -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED - png_progressive_info_ptr info_fn; /* called after header data fully read */ - png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */ - png_progressive_end_ptr end_fn; /* called after image is complete */ - png_bytep save_buffer_ptr; /* current location in save_buffer */ - png_bytep save_buffer; /* buffer for previously read data */ - png_bytep current_buffer_ptr; /* current location in current_buffer */ - png_bytep current_buffer; /* buffer for recently used data */ - png_uint_32 push_length; /* size of current input chunk */ - png_uint_32 skip_length; /* bytes to skip in input data */ - png_size_t save_buffer_size; /* amount of data now in save_buffer */ - png_size_t save_buffer_max; /* total size of save_buffer */ - png_size_t buffer_size; /* total amount of available input data */ - png_size_t current_buffer_size; /* amount of data now in current_buffer */ - int process_mode; /* what push library is currently doing */ - int cur_palette; /* current push library palette index */ - -# if defined(PNG_TEXT_SUPPORTED) - png_size_t current_text_size; /* current size of text input data */ - png_size_t current_text_left; /* how much text left to read in input */ - png_charp current_text; /* current text chunk buffer */ - png_charp current_text_ptr; /* current location in current_text */ -# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */ - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -/* for the Borland special 64K segment handler */ - png_bytepp offset_table_ptr; - png_bytep offset_table; - png_uint_16 offset_table_number; - png_uint_16 offset_table_count; - png_uint_16 offset_table_count_free; -#endif - -#if defined(PNG_READ_DITHER_SUPPORTED) - png_bytep palette_lookup; /* lookup table for dithering */ - png_bytep dither_index; /* index translation for palette files */ -#endif - -#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED) - png_uint_16p hist; /* histogram */ -#endif - -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) - png_byte heuristic_method; /* heuristic for row filter selection */ - png_byte num_prev_filters; /* number of weights for previous rows */ - png_bytep prev_filters; /* filter type(s) of previous row(s) */ - png_uint_16p filter_weights; /* weight(s) for previous line(s) */ - png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ - png_uint_16p filter_costs; /* relative filter calculation cost */ - png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ -#endif - -#if defined(PNG_TIME_RFC1123_SUPPORTED) - png_charp time_buffer; /* String to hold RFC 1123 time text */ -#endif - -/* New members added in libpng-1.0.6 */ - -#ifdef PNG_FREE_ME_SUPPORTED - png_uint_32 free_me; /* flags items libpng is responsible for freeing */ -#endif - -#if defined(PNG_USER_CHUNKS_SUPPORTED) - png_voidp user_chunk_ptr; - png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ -#endif - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - int num_chunk_list; - png_bytep chunk_list; -#endif - -/* New members added in libpng-1.0.3 */ -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - png_byte rgb_to_gray_status; - /* These were changed from png_byte in libpng-1.0.6 */ - png_uint_16 rgb_to_gray_red_coeff; - png_uint_16 rgb_to_gray_green_coeff; - png_uint_16 rgb_to_gray_blue_coeff; -#endif - -/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ -#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ - defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ - defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) -/* changed from png_byte to png_uint_32 at version 1.2.0 */ - png_uint_32 mng_features_permitted; -#endif - -/* New member added in libpng-1.0.7 */ -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - png_fixed_point int_gamma; -#endif - -/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ -#if defined(PNG_MNG_FEATURES_SUPPORTED) - png_byte filter_type; -#endif - -#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD) -/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */ - png_uint_32 row_buf_size; -#endif - -/* New members added in libpng-1.2.0 */ -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) - png_byte mmx_bitdepth_threshold; - png_uint_32 mmx_rowbytes_threshold; - png_uint_32 asm_flags; -#endif - -/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ -#ifdef PNG_USER_MEM_SUPPORTED - png_voidp mem_ptr; /* user supplied struct for mem functions */ - png_malloc_ptr malloc_fn; /* function for allocating memory */ - png_free_ptr free_fn; /* function for freeing memory */ -#endif - - png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ - -}; - - -/* This prevents a compiler error in png_get_copyright() in png.c if png.c - and png.h are both at version 1.2.0 - */ -typedef png_structp version_1_2_0; - -typedef png_struct FAR * FAR * png_structpp; - -/* Here are the function definitions most commonly used. This is not - * the place to find out how to use libpng. See libpng.txt for the - * full explanation, see example.c for the summary. This just provides - * a simple one line description of the use of each function. - */ - -/* Returns the version number of the library */ -extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void)); - -/* Tell lib we have already handled the first magic bytes. - * Handling more than 8 bytes from the beginning of the file is an error. - */ -extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, - int num_bytes)); - -/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a - * PNG file. Returns zero if the supplied bytes match the 8-byte PNG - * signature, and non-zero otherwise. Having num_to_check == 0 or - * start > 7 will always fail (ie return non-zero). - */ -extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, - png_size_t num_to_check)); - -/* Simple signature checking function. This is the same as calling - * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). - */ -extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num)); - -/* Allocate and initialize png_ptr struct for reading, and any other memory. */ -extern PNG_EXPORT(png_structp,png_create_read_struct) - PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn)); - -/* Allocate and initialize png_ptr struct for writing, and any other memory */ -extern PNG_EXPORT(png_structp,png_create_write_struct) - PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn)); - -extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size) - PNGARG((png_structp png_ptr)); - -extern PNG_EXPORT(void,png_set_compression_buffer_size) - PNGARG((png_structp png_ptr, png_uint_32 size)); - -/* Reset the compression stream */ -extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); - -/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ -#ifdef PNG_USER_MEM_SUPPORTED -extern PNG_EXPORT(png_structp,png_create_read_struct_2) - PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn)); -extern PNG_EXPORT(png_structp,png_create_write_struct_2) - PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn)); -#endif - -/* Write a PNG chunk - size, type, (optional) data, CRC. */ -extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, - png_bytep chunk_name, png_bytep data, png_size_t length)); - -/* Write the start of a PNG chunk - length and chunk name. */ -extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr, - png_bytep chunk_name, png_uint_32 length)); - -/* Write the data of a PNG chunk started with png_write_chunk_start(). */ -extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); - -/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ -extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); - -/* Allocate and initialize the info structure */ -extern PNG_EXPORT(png_infop,png_create_info_struct) - PNGARG((png_structp png_ptr)); - -/* Initialize the info structure (old interface - DEPRECATED) */ -extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)); -#define png_info_init(info_ptr) png_info_init_3(&info_ptr, sizeof(png_info)); -extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, - png_size_t png_info_struct_size)); - -/* Writes all the PNG information before the image. */ -extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, - png_infop info_ptr)); -extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* read the information before the actual image data. */ -extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -#if defined(PNG_TIME_RFC1123_SUPPORTED) -extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) - PNGARG((png_structp png_ptr, png_timep ptime)); -#endif - -#if !defined(_WIN32_WCE) -/* "time.h" functions are not supported on WindowsCE */ -#if defined(PNG_WRITE_tIME_SUPPORTED) -/* convert from a struct tm to png_time */ -extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, - struct tm FAR * ttime)); - -/* convert from time_t to png_time. Uses gmtime() */ -extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, - time_t ttime)); -#endif /* PNG_WRITE_tIME_SUPPORTED */ -#endif /* _WIN32_WCE */ - -#if defined(PNG_READ_EXPAND_SUPPORTED) -/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ -extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -/* Use blue, green, red order for pixels. */ -extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) -/* Expand the grayscale to 24-bit RGB if necessary. */ -extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) -/* Reduce RGB to grayscale. */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr, - int error_action, double red, double green )); -#endif -extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr, - int error_action, png_fixed_point red, png_fixed_point green )); -extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp - png_ptr)); -#endif - -extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth, - png_colorp palette)); - -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) -/* Add a filler byte to 24-bit RGB images. */ -extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, - png_uint_32 filler, int flags)); -/* The values of the PNG_FILLER_ defines should NOT be changed */ -#define PNG_FILLER_BEFORE 0 -#define PNG_FILLER_AFTER 1 -#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ - -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Swap bytes in 16-bit depth files. */ -extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) -/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ -extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) -/* Swap packing order of pixels in bytes. */ -extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) -/* Converts files to legal bit depths. */ -extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr, - png_color_8p true_bits)); -#endif - -#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ - defined(PNG_WRITE_INTERLACING_SUPPORTED) -/* Have the code handle the interlacing. Returns the number of passes. */ -extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -/* Invert monochrome files */ -extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) -/* Handle alpha and tRNS by replacing with a background color. */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, - png_color_16p background_color, int background_gamma_code, - int need_expand, double background_gamma)); -#endif -#define PNG_BACKGROUND_GAMMA_UNKNOWN 0 -#define PNG_BACKGROUND_GAMMA_SCREEN 1 -#define PNG_BACKGROUND_GAMMA_FILE 2 -#define PNG_BACKGROUND_GAMMA_UNIQUE 3 -#endif - -#if defined(PNG_READ_16_TO_8_SUPPORTED) -/* strip the second byte of information from a 16-bit depth file. */ -extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_DITHER_SUPPORTED) -/* Turn on dithering, and reduce the palette to the number of colors available. */ -extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr, - png_colorp palette, int num_palette, int maximum_colors, - png_uint_16p histogram, int full_dither)); -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) -/* Handle gamma correction. Screen_gamma=(display_exponent) */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, - double screen_gamma, double default_file_gamma)); -#endif -#endif - -#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ - defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) -/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */ -/* Deprecated and will be removed. Use png_permit_mng_features() instead. */ -extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr, - int empty_plte_permitted)); -#endif - -#if defined(PNG_WRITE_FLUSH_SUPPORTED) -/* Set how many lines between output flushes - 0 for no flushing */ -extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows)); -/* Flush the current PNG output buffer */ -extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr)); -#endif - -/* optional update palette with requested transformations */ -extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); - -/* optional call to update the users info structure */ -extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* read a one or more rows of image data.*/ -extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, - png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); - -/* read a row of data.*/ -extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, - png_bytep row, - png_bytep display_row)); - -/* read the whole image into memory at once. */ -extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, - png_bytepp image)); - -/* write a row of image data */ -extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr, - png_bytep row)); - -/* write a few rows of image data */ -extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, - png_bytepp row, png_uint_32 num_rows)); - -/* write the image data */ -extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, - png_bytepp image)); - -/* writes the end of the PNG file. */ -extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* read the end of the PNG file. */ -extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* free any memory associated with the png_info_struct */ -extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr, - png_infopp info_ptr_ptr)); - -/* free any memory associated with the png_struct and the png_info_structs */ -extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp - png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); - -/* free all memory used by the read (old method - NOT DLL EXPORTED) */ -extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr, - png_infop end_info_ptr)); - -/* free any memory associated with the png_struct and the png_info_structs */ -extern PNG_EXPORT(void,png_destroy_write_struct) - PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); - -/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */ -extern void png_write_destroy_info PNGARG((png_infop info_ptr)); - -/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ -extern void png_write_destroy PNGARG((png_structp png_ptr)); - -/* set the libpng method of handling chunk CRC errors */ -extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, - int crit_action, int ancil_action)); - -/* Values for png_set_crc_action() to say how to handle CRC errors in - * ancillary and critical chunks, and whether to use the data contained - * therein. Note that it is impossible to "discard" data in a critical - * chunk. For versions prior to 0.90, the action was always error/quit, - * whereas in version 0.90 and later, the action for CRC errors in ancillary - * chunks is warn/discard. These values should NOT be changed. - * - * value action:critical action:ancillary - */ -#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ -#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ -#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ -#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ -#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ -#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ - -/* These functions give the user control over the scan-line filtering in - * libpng and the compression methods used by zlib. These functions are - * mainly useful for testing, as the defaults should work with most users. - * Those users who are tight on memory or want faster performance at the - * expense of compression can modify them. See the compression library - * header file (zlib.h) for an explination of the compression functions. - */ - -/* set the filtering method(s) used by libpng. Currently, the only valid - * value for "method" is 0. - */ -extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, - int filters)); - -/* Flags for png_set_filter() to say which filters to use. The flags - * are chosen so that they don't conflict with real filter types - * below, in case they are supplied instead of the #defined constants. - * These values should NOT be changed. - */ -#define PNG_NO_FILTERS 0x00 -#define PNG_FILTER_NONE 0x08 -#define PNG_FILTER_SUB 0x10 -#define PNG_FILTER_UP 0x20 -#define PNG_FILTER_AVG 0x40 -#define PNG_FILTER_PAETH 0x80 -#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ - PNG_FILTER_AVG | PNG_FILTER_PAETH) - -/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. - * These defines should NOT be changed. - */ -#define PNG_FILTER_VALUE_NONE 0 -#define PNG_FILTER_VALUE_SUB 1 -#define PNG_FILTER_VALUE_UP 2 -#define PNG_FILTER_VALUE_AVG 3 -#define PNG_FILTER_VALUE_PAETH 4 -#define PNG_FILTER_VALUE_LAST 5 - -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */ -/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ - * defines, either the default (minimum-sum-of-absolute-differences), or - * the experimental method (weighted-minimum-sum-of-absolute-differences). - * - * Weights are factors >= 1.0, indicating how important it is to keep the - * filter type consistent between rows. Larger numbers mean the current - * filter is that many times as likely to be the same as the "num_weights" - * previous filters. This is cumulative for each previous row with a weight. - * There needs to be "num_weights" values in "filter_weights", or it can be - * NULL if the weights aren't being specified. Weights have no influence on - * the selection of the first row filter. Well chosen weights can (in theory) - * improve the compression for a given image. - * - * Costs are factors >= 1.0 indicating the relative decoding costs of a - * filter type. Higher costs indicate more decoding expense, and are - * therefore less likely to be selected over a filter with lower computational - * costs. There needs to be a value in "filter_costs" for each valid filter - * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't - * setting the costs. Costs try to improve the speed of decompression without - * unduly increasing the compressed image size. - * - * A negative weight or cost indicates the default value is to be used, and - * values in the range [0.0, 1.0) indicate the value is to remain unchanged. - * The default values for both weights and costs are currently 1.0, but may - * change if good general weighting/cost heuristics can be found. If both - * the weights and costs are set to 1.0, this degenerates the WEIGHTED method - * to the UNWEIGHTED method, but with added encoding time/computation. - */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, - int heuristic_method, int num_weights, png_doublep filter_weights, - png_doublep filter_costs)); -#endif -#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ - -/* Heuristic used for row filter selection. These defines should NOT be - * changed. - */ -#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ -#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ -#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ -#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ - -/* Set the library compression level. Currently, valid values range from - * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 - * (0 - no compression, 9 - "maximal" compression). Note that tests have - * shown that zlib compression levels 3-6 usually perform as well as level 9 - * for PNG images, and do considerably fewer caclulations. In the future, - * these values may not correspond directly to the zlib compression levels. - */ -extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr, - int level)); - -extern PNG_EXPORT(void,png_set_compression_mem_level) - PNGARG((png_structp png_ptr, int mem_level)); - -extern PNG_EXPORT(void,png_set_compression_strategy) - PNGARG((png_structp png_ptr, int strategy)); - -extern PNG_EXPORT(void,png_set_compression_window_bits) - PNGARG((png_structp png_ptr, int window_bits)); - -extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, - int method)); - -/* These next functions are called for input/output, memory, and error - * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, - * and call standard C I/O routines such as fread(), fwrite(), and - * fprintf(). These functions can be made to use other I/O routines - * at run time for those applications that need to handle I/O in a - * different manner by calling png_set_???_fn(). See libpng.txt for - * more information. - */ - -#if !defined(PNG_NO_STDIO) -/* Initialize the input/output for the PNG file to the default functions. */ -extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)); -#endif - -/* Replace the (error and abort), and warning functions with user - * supplied functions. If no messages are to be printed you must still - * write and use replacement functions. The replacement error_fn should - * still do a longjmp to the last setjmp location if you are using this - * method of error handling. If error_fn or warning_fn is NULL, the - * default function will be used. - */ - -extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr, - png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); - -/* Return the user pointer associated with the error functions */ -extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr)); - -/* Replace the default data output functions with a user supplied one(s). - * If buffered output is not used, then output_flush_fn can be set to NULL. - * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time - * output_flush_fn will be ignored (and thus can be NULL). - */ -extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr, - png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); - -/* Replace the default data input function with a user supplied one. */ -extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr, - png_voidp io_ptr, png_rw_ptr read_data_fn)); - -/* Return the user pointer associated with the I/O functions */ -extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr)); - -extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr, - png_read_status_ptr read_row_fn)); - -extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, - png_write_status_ptr write_row_fn)); - -#ifdef PNG_USER_MEM_SUPPORTED -/* Replace the default memory allocation functions with user supplied one(s). */ -extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, - png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); -/* Return the user pointer associated with the memory functions */ -extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr)); -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_LEGACY_SUPPORTED) -extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp - png_ptr, png_user_transform_ptr read_user_transform_fn)); -#endif - -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_LEGACY_SUPPORTED) -extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp - png_ptr, png_user_transform_ptr write_user_transform_fn)); -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_LEGACY_SUPPORTED) -extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp - png_ptr, png_voidp user_transform_ptr, int user_transform_depth, - int user_transform_channels)); -/* Return the user pointer associated with the user transform functions */ -extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr) - PNGARG((png_structp png_ptr)); -#endif - -#ifdef PNG_USER_CHUNKS_SUPPORTED -extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, - png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); -extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp - png_ptr)); -#endif - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -/* Sets the function callbacks for the push reader, and a pointer to a - * user-defined structure available to the callback functions. - */ -extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr, - png_voidp progressive_ptr, - png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, - png_progressive_end_ptr end_fn)); - -/* returns the user pointer associated with the push read functions */ -extern PNG_EXPORT(png_voidp,png_get_progressive_ptr) - PNGARG((png_structp png_ptr)); - -/* function to be called when data becomes available */ -extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); - -/* function that combines rows. Not very much different than the - * png_combine_row() call. Is this even used????? - */ -extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, - png_bytep old_row, png_bytep new_row)); -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, - png_uint_32 size)); - -/* frees a pointer allocated by png_malloc() */ -extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); - -/* Free data that was allocated internally */ -extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 free_me, int num)); -#ifdef PNG_FREE_ME_SUPPORTED -/* Reassign responsibility for freeing existing data, whether allocated - * by libpng or by the application */ -extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, - png_infop info_ptr, int freer, png_uint_32 mask)); -#endif -/* assignments for png_data_freer */ -#define PNG_DESTROY_WILL_FREE_DATA 1 -#define PNG_SET_WILL_FREE_DATA 1 -#define PNG_USER_WILL_FREE_DATA 2 -/* Flags for png_ptr->free_me and info_ptr->free_me */ -#define PNG_FREE_HIST 0x0008 -#define PNG_FREE_ICCP 0x0010 -#define PNG_FREE_SPLT 0x0020 -#define PNG_FREE_ROWS 0x0040 -#define PNG_FREE_PCAL 0x0080 -#define PNG_FREE_SCAL 0x0100 -#define PNG_FREE_UNKN 0x0200 -#define PNG_FREE_LIST 0x0400 -#define PNG_FREE_PLTE 0x1000 -#define PNG_FREE_TRNS 0x2000 -#define PNG_FREE_TEXT 0x4000 -#define PNG_FREE_ALL 0x7fff -#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ - -#ifdef PNG_USER_MEM_SUPPORTED -extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, - png_uint_32 size)); -extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, - png_voidp ptr)); -#endif - -extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr, - png_voidp s1, png_voidp s2, png_uint_32 size)); - -extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr, - png_voidp s1, int value, png_uint_32 size)); - -#if defined(USE_FAR_KEYWORD) /* memory model conversion function */ -extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, - int check)); -#endif /* USE_FAR_KEYWORD */ - -/* Fatal error in PNG image of libpng - can't continue */ -extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, - png_const_charp error)); - -/* The same, but the chunk name is prepended to the error string. */ -extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, - png_const_charp error)); - -/* Non-fatal error in libpng. Can continue, but may have a problem. */ -extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, - png_const_charp message)); - -/* Non-fatal error in libpng, chunk name is prepended to message. */ -extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, - png_const_charp message)); - -/* The png_set_ functions are for storing values in the png_info_struct. - * Similarly, the png_get_ calls are used to read values from the - * png_info_struct, either storing the parameters in the passed variables, or - * setting pointers into the png_info_struct where the data is stored. The - * png_get_ functions return a non-zero value if the data was available - * in info_ptr, or return zero and do not change any of the parameters if the - * data was not available. - * - * These functions should be used instead of directly accessing png_info - * to avoid problems with future changes in the size and internal layout of - * png_info_struct. - */ -/* Returns "flag" if chunk data is valid in info_ptr. */ -extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr, -png_infop info_ptr, png_uint_32 flag)); - -/* Returns number of bytes needed to hold a transformed row. */ -extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -#if defined(PNG_INFO_IMAGE_SUPPORTED) -/* Returns row_pointers, which is an array of pointers to scanlines that was -returned from png_read_png(). */ -extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr, -png_infop info_ptr)); -/* Set row_pointers, which is an array of pointers to scanlines for use -by png_write_png(). */ -extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytepp row_pointers)); -#endif - -/* Returns number of color channels in image. */ -extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -#ifdef PNG_EASY_ACCESS_SUPPORTED -/* Returns image width in pixels. */ -extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image height in pixels. */ -extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image bit_depth. */ -extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image color_type. */ -extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image filter_type. */ -extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image interlace_type. */ -extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image compression_type. */ -extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns image resolution in pixels per meter, from pHYs chunk data. */ -extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -/* Returns pixel aspect ratio, computed from pHYs chunk data. */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -#endif - -/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ -extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp -png_ptr, png_infop info_ptr)); - -#endif /* PNG_EASY_ACCESS_SUPPORTED */ - -/* Returns pointer to signature string read from PNG header */ -extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr, -png_infop info_ptr)); - -#if defined(PNG_bKGD_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_color_16p *background)); -#endif - -#if defined(PNG_bKGD_SUPPORTED) -extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_color_16p background)); -#endif - -#if defined(PNG_cHRM_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr, - png_infop info_ptr, double *white_x, double *white_y, double *red_x, - double *red_y, double *green_x, double *green_y, double *blue_x, - double *blue_y)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point - *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y, - png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point - *int_blue_x, png_fixed_point *int_blue_y)); -#endif -#endif - -#if defined(PNG_cHRM_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr, - png_infop info_ptr, double white_x, double white_y, double red_x, - double red_y, double green_x, double green_y, double blue_x, double blue_y)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); -#endif -#endif - -#if defined(PNG_gAMA_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, - png_infop info_ptr, double *file_gamma)); -#endif -extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_file_gamma)); -#endif - -#if defined(PNG_gAMA_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, - png_infop info_ptr, double file_gamma)); -#endif -extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_file_gamma)); -#endif - -#if defined(PNG_hIST_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_16p *hist)); -#endif - -#if defined(PNG_hIST_SUPPORTED) -extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_16p hist)); -#endif - -extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, - int *bit_depth, int *color_type, int *interlace_method, - int *compression_method, int *filter_method)); - -extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_method, int compression_method, - int filter_method)); - -#if defined(PNG_oFFs_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, - int *unit_type)); -#endif - -#if defined(PNG_oFFs_SUPPORTED) -extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, - int unit_type)); -#endif - -#if defined(PNG_pCAL_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, - int *type, int *nparams, png_charp *units, png_charpp *params)); -#endif - -#if defined(PNG_pCAL_SUPPORTED) -extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, - int type, int nparams, png_charp units, png_charpp params)); -#endif - -#if defined(PNG_pHYs_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); -#endif - -#if defined(PNG_pHYs_SUPPORTED) -extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); -#endif - -extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_colorp *palette, int *num_palette)); - -extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_colorp palette, int num_palette)); - -#if defined(PNG_sBIT_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_color_8p *sig_bit)); -#endif - -#if defined(PNG_sBIT_SUPPORTED) -extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_color_8p sig_bit)); -#endif - -#if defined(PNG_sRGB_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *intent)); -#endif - -#if defined(PNG_sRGB_SUPPORTED) -extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr, - png_infop info_ptr, int intent)); -extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, - png_infop info_ptr, int intent)); -#endif - -#if defined(PNG_iCCP_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charpp name, int *compression_type, - png_charpp profile, png_uint_32 *proflen)); - /* Note to maintainer: profile should be png_bytepp */ -#endif - -#if defined(PNG_iCCP_SUPPORTED) -extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charp name, int compression_type, - png_charp profile, png_uint_32 proflen)); - /* Note to maintainer: profile should be png_bytep */ -#endif - -#if defined(PNG_sPLT_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_sPLT_tpp entries)); -#endif - -#if defined(PNG_sPLT_SUPPORTED) -extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_sPLT_tp entries, int nentries)); -#endif - -#if defined(PNG_TEXT_SUPPORTED) -/* png_get_text also returns the number of text chunks in *num_text */ -extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_textp *text_ptr, int *num_text)); -#endif - -/* - * Note while png_set_text() will accept a structure whose text, - * language, and translated keywords are NULL pointers, the structure - * returned by png_get_text will always contain regular - * zero-terminated C strings. They might be empty strings but - * they will never be NULL pointers. - */ - -#if defined(PNG_TEXT_SUPPORTED) -extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_textp text_ptr, int num_text)); -#endif - -#if defined(PNG_tIME_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_timep *mod_time)); -#endif - -#if defined(PNG_tIME_SUPPORTED) -extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_timep mod_time)); -#endif - -#if defined(PNG_tRNS_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytep *trans, int *num_trans, - png_color_16p *trans_values)); -#endif - -#if defined(PNG_tRNS_SUPPORTED) -extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_bytep trans, int num_trans, - png_color_16p trans_values)); -#endif - -#if defined(PNG_tRNS_SUPPORTED) -#endif - -#if defined(PNG_sCAL_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *unit, double *width, double *height)); -#else -#ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); -#endif -#endif -#endif /* PNG_sCAL_SUPPORTED */ - -#if defined(PNG_sCAL_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, int unit, double width, double height)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, - png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); -#endif -#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) -/* provide a list of chunks and how they are to be handled, if the built-in - handling or default unknown chunk handling is not desired. Any chunks not - listed will be handled in the default manner. The IHDR and IEND chunks - must not be listed. - keep = 0: follow default behavour - = 1: do not keep - = 2: keep only if safe-to-copy - = 3: keep even if unsafe-to-copy -*/ -extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp - png_ptr, int keep, png_bytep chunk_list, int num_chunks)); -extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)); -extern PNG_EXPORT(void, png_set_unknown_chunk_location) - PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location)); -extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp - png_ptr, png_infop info_ptr, png_unknown_chunkpp entries)); -#endif - -/* Png_free_data() will turn off the "valid" flag for anything it frees. - If you need to turn it off for a chunk that your application has freed, - you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */ -extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr, - png_infop info_ptr, int mask)); - -#if defined(PNG_INFO_IMAGE_SUPPORTED) -/* The "params" pointer is currently not used and is for future expansion. */ -extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr, - png_infop info_ptr, - int transforms, - png_voidp params)); -extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, - png_infop info_ptr, - int transforms, - png_voidp params)); -#endif - -/* Define PNG_DEBUG at compile time for debugging information. Higher - * numbers for PNG_DEBUG mean more debugging information. This has - * only been added since version 0.95 so it is not implemented throughout - * libpng yet, but more support will be added as needed. - */ -#ifdef PNG_DEBUG -#if (PNG_DEBUG > 0) -#if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) -#include -#if (PNG_DEBUG > 1) -#define png_debug(l,m) _RPT0(_CRT_WARN,m) -#define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1) -#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2) -#endif -#else /* PNG_DEBUG_FILE || !_MSC_VER */ -#ifndef PNG_DEBUG_FILE -#define PNG_DEBUG_FILE stderr -#endif /* PNG_DEBUG_FILE */ -#if (PNG_DEBUG > 1) -#define png_debug(l,m) \ -{ \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ -} -#define png_debug1(l,m,p1) \ -{ \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ -} -#define png_debug2(l,m,p1,p2) \ -{ \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ -} -#endif /* (PNG_DEBUG > 1) */ -#endif /* _MSC_VER */ -#endif /* (PNG_DEBUG > 0) */ -#endif /* PNG_DEBUG */ -#ifndef png_debug -#define png_debug(l, m) -#endif -#ifndef png_debug1 -#define png_debug1(l, m, p1) -#endif -#ifndef png_debug2 -#define png_debug2(l, m, p1, p2) -#endif - -extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void)); - -extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); - -#ifdef PNG_MNG_FEATURES_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp - png_ptr, png_uint_32 mng_features_permitted)); -#endif - -/* Added to version 1.2.0 */ -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) -#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */ -#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */ -#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04 -#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08 -#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10 -#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20 -#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40 -#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80 -#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */ - -#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ - | PNG_ASM_FLAG_MMX_READ_INTERLACE \ - | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ - | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ - | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ - | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ) -#define PNG_MMX_WRITE_FLAGS ( 0 ) - -#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \ - | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \ - | PNG_MMX_READ_FLAGS \ - | PNG_MMX_WRITE_FLAGS ) - -#define PNG_SELECT_READ 1 -#define PNG_SELECT_WRITE 2 - - -/* pngget.c */ -extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask) - PNGARG((int flag_select, int *compilerID)); - -/* pngget.c */ -extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask) - PNGARG((int flag_select)); - -/* pngget.c */ -extern PNG_EXPORT(png_uint_32,png_get_asm_flags) - PNGARG((png_structp png_ptr)); - -/* pngget.c */ -extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold) - PNGARG((png_structp png_ptr)); - -/* pngget.c */ -extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold) - PNGARG((png_structp png_ptr)); - -/* pngset.c */ -extern PNG_EXPORT(void,png_set_asm_flags) - PNGARG((png_structp png_ptr, png_uint_32 asm_flags)); - -/* pngset.c */ -extern PNG_EXPORT(void,png_set_mmx_thresholds) - PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold, - png_uint_32 mmx_rowbytes_threshold)); - -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ - -/* png.c, pnggccrd.c, or pngvcrd.c */ -extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); - -/* Strip the prepended error numbers ("#nnn ") from error and warning - * messages before passing them to the error or warning handler. */ -#ifdef PNG_ERROR_NUMBERS_SUPPORTED -extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp - png_ptr, png_uint_32 strip_mode)); -#endif - -/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */ - -#define PNG_HEADER_VERSION_STRING \ - " libpng version 1.2.0 - September 1, 2001 (header)\n" - -#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED -/* With these routines we avoid an integer divide, which will be slower on - * most machines. However, it does take more operations than the corresponding - * divide method, so it may be slower on a few RISC systems. There are two - * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. - * - * Note that the rounding factors are NOT supposed to be the same! 128 and - * 32768 are correct for the NODIV code; 127 and 32767 are correct for the - * standard method. - * - * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] - */ - - /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ - -# define png_composite(composite, fg, alpha, bg) \ - { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \ - + (png_uint_16)(bg)*(png_uint_16)(255 - \ - (png_uint_16)(alpha)) + (png_uint_16)128); \ - (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } - -# define png_composite_16(composite, fg, alpha, bg) \ - { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \ - + (png_uint_32)(bg)*(png_uint_32)(65535L - \ - (png_uint_32)(alpha)) + (png_uint_32)32768L); \ - (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } - -#else /* standard method using integer division */ - -# define png_composite(composite, fg, alpha, bg) \ - (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ - (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ - (png_uint_16)127) / 255) - -# define png_composite_16(composite, fg, alpha, bg) \ - (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ - (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ - (png_uint_32)32767) / (png_uint_32)65535L) - -#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ - -/* These next functions are used internally in the code. They generally - * shouldn't be used unless you are writing code to add or replace some - * functionality in libpng. More information about most functions can - * be found in the files where the functions are located. - */ - -#if defined(PNG_INTERNAL) - -/* Various modes of operation. Note that after an init, mode is set to - * zero automatically when the structure is created. - */ -#define PNG_HAVE_IHDR 0x01 -#define PNG_HAVE_PLTE 0x02 -#define PNG_HAVE_IDAT 0x04 -#define PNG_AFTER_IDAT 0x08 -#define PNG_HAVE_IEND 0x10 -#define PNG_HAVE_gAMA 0x20 -#define PNG_HAVE_cHRM 0x40 -#define PNG_HAVE_sRGB 0x80 -#define PNG_HAVE_CHUNK_HEADER 0x100 -#define PNG_WROTE_tIME 0x200 -#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 -#define PNG_BACKGROUND_IS_GRAY 0x800 -#define PNG_HAVE_PNG_SIGNATURE 0x1000 - -/* flags for the transformations the PNG library does on the image data */ -#define PNG_BGR 0x0001 -#define PNG_INTERLACE 0x0002 -#define PNG_PACK 0x0004 -#define PNG_SHIFT 0x0008 -#define PNG_SWAP_BYTES 0x0010 -#define PNG_INVERT_MONO 0x0020 -#define PNG_DITHER 0x0040 -#define PNG_BACKGROUND 0x0080 -#define PNG_BACKGROUND_EXPAND 0x0100 - /* 0x0200 unused */ -#define PNG_16_TO_8 0x0400 -#define PNG_RGBA 0x0800 -#define PNG_EXPAND 0x1000 -#define PNG_GAMMA 0x2000 -#define PNG_GRAY_TO_RGB 0x4000 -#define PNG_FILLER 0x8000L -#define PNG_PACKSWAP 0x10000L -#define PNG_SWAP_ALPHA 0x20000L -#define PNG_STRIP_ALPHA 0x40000L -#define PNG_INVERT_ALPHA 0x80000L -#define PNG_USER_TRANSFORM 0x100000L -#define PNG_RGB_TO_GRAY_ERR 0x200000L -#define PNG_RGB_TO_GRAY_WARN 0x400000L -#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ - -/* flags for png_create_struct */ -#define PNG_STRUCT_PNG 0x0001 -#define PNG_STRUCT_INFO 0x0002 - -/* Scaling factor for filter heuristic weighting calculations */ -#define PNG_WEIGHT_SHIFT 8 -#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) -#define PNG_COST_SHIFT 3 -#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) - -/* flags for the png_ptr->flags rather than declaring a byte for each one */ -#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 -#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 -#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 -#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 -#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 -#define PNG_FLAG_ZLIB_FINISHED 0x0020 -#define PNG_FLAG_ROW_INIT 0x0040 -#define PNG_FLAG_FILLER_AFTER 0x0080 -#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 -#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 -#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 -#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 -#define PNG_FLAG_FREE_PLTE 0x1000 -#define PNG_FLAG_FREE_TRNS 0x2000 -#define PNG_FLAG_FREE_HIST 0x4000 -#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L -#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L -#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L -#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L -#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L - -/* For use in png_set_keep_unknown, png_handle_as_unknown */ -#define HANDLE_CHUNK_AS_DEFAULT 0 -#define HANDLE_CHUNK_NEVER 1 -#define HANDLE_CHUNK_IF_SAFE 2 -#define HANDLE_CHUNK_ALWAYS 3 - -#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ - PNG_FLAG_CRC_ANCILLARY_NOWARN) - -#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ - PNG_FLAG_CRC_CRITICAL_IGNORE) - -#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ - PNG_FLAG_CRC_CRITICAL_MASK) - -/* save typing and make code easier to understand */ -#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ - abs((int)((c1).green) - (int)((c2).green)) + \ - abs((int)((c1).blue) - (int)((c2).blue))) - -/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */ -#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) -/* place to hold the signature string for a PNG file. */ -#ifdef PNG_USE_GLOBAL_ARRAYS - PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8]; -#else -#define png_sig png_sig_bytes(NULL) -#endif -#endif /* PNG_NO_EXTERN */ - -/* Constant strings for known chunk types. If you need to add a chunk, - * define the name here, and add an invocation of the macro in png.c and - * wherever it's needed. - */ -#define PNG_IHDR const png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} -#define PNG_IDAT const png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} -#define PNG_IEND const png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} -#define PNG_PLTE const png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} -#define PNG_bKGD const png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} -#define PNG_cHRM const png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} -#define PNG_gAMA const png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} -#define PNG_hIST const png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} -#define PNG_iCCP const png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} -#define PNG_iTXt const png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} -#define PNG_oFFs const png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} -#define PNG_pCAL const png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} -#define PNG_sCAL const png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} -#define PNG_pHYs const png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} -#define PNG_sBIT const png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} -#define PNG_sPLT const png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} -#define PNG_sRGB const png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} -#define PNG_tEXt const png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} -#define PNG_tIME const png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} -#define PNG_tRNS const png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} -#define PNG_zTXt const png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} - -#ifdef PNG_USE_GLOBAL_ARRAYS -PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_iTXt[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_sCAL[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_sPLT[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5]; -PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5]; -#endif /* PNG_USE_GLOBAL_ARRAYS */ - - -/* Inline macros to do direct reads of bytes from the input buffer. These - * require that you are using an architecture that uses PNG byte ordering - * (MSB first) and supports unaligned data storage. I think that PowerPC - * in big-endian mode and 680x0 are the only ones that will support this. - * The x86 line of processors definitely do not. The png_get_int_32() - * routine also assumes we are using two's complement format for negative - * values, which is almost certainly true. - */ -#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED) -# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED) -# define png_get_int_32(buf) ( *((png_int_32p) (buf))) -# endif -# define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) -# define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) -#else -# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED) -PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf)); -# endif -PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf)); -PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf)); -#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ - -/* Initialize png_ptr struct for reading, and allocate any other memory. - * (old interface - DEPRECATED - use png_create_read_struct instead). - */ -extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr)); -#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ - PNG_LIBPNG_VER_STRING, sizeof(png_struct)); -extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, - png_const_charp user_png_ver, png_size_t png_struct_size)); -extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, - png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t - png_info_size)); - -/* Initialize png_ptr struct for writing, and allocate any other memory. - * (old interface - DEPRECATED - use png_create_write_struct instead). - */ -extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr)); -#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ - PNG_LIBPNG_VER_STRING, sizeof(png_struct)); -extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, - png_const_charp user_png_ver, png_size_t png_struct_size)); -extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, - png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t - png_info_size)); - -/* Allocate memory for an internal libpng struct */ -PNG_EXTERN png_voidp png_create_struct PNGARG((int type)); - -/* Free memory from internal libpng struct */ -PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); - -PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr - malloc_fn, png_voidp mem_ptr)); -PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, - png_free_ptr free_fn, png_voidp mem_ptr)); - -/* Free any memory that info_ptr points to and reset struct. */ -PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* Function to allocate memory for zlib. */ -PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size)); - -/* Function to free memory for zlib */ -PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); - -/* Reset the CRC variable */ -PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); - -/* Write the "data" buffer to whatever output you are using. */ -PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -/* Read data from whatever input you are using into the "data" buffer */ -PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -/* Read bytes into buf, and update png_ptr->crc */ -PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, - png_size_t length)); - -/* Decompress data in a chunk that uses compression */ -#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ - defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) -PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr, - int comp_type, png_charp chunkdata, png_size_t chunklength, - png_size_t prefix_length, png_size_t *data_length)); -#endif - -/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ -PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); - -/* Read the CRC from the file and compare it to the libpng calculated CRC */ -PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); - -/* Calculate the CRC over a section of data. Note that we are only - * passing a maximum of 64K on systems that have this as a memory limit, - * since this is the maximum buffer size we can specify. - */ -PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr, - png_size_t length)); - -#if defined(PNG_WRITE_FLUSH_SUPPORTED) -PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); -#endif - -/* Place a 32-bit number into a buffer in PNG byte order (big-endian). - * The only currently known PNG chunks that use signed numbers are - * the ancillary extension chunks, oFFs and pCAL. - */ -PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i)); - -#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) -PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i)); -#endif - -/* Place a 16-bit number into a buffer in PNG byte order. - * The parameter is declared unsigned int, not png_uint_16, - * just to avoid potential problems on pre-ANSI C compilers. - */ -PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i)); - -/* simple function to write the signature */ -PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr)); - -/* write various chunks */ - -/* Write the IHDR chunk, and update the png_struct with the necessary - * information. - */ -PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, - png_uint_32 height, - int bit_depth, int color_type, int compression_method, int filter_method, - int interlace_method)); - -PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette, - png_uint_32 num_pal)); - -PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); - -#if defined(PNG_WRITE_gAMA_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point - file_gamma)); -#endif -#endif - -#if defined(PNG_WRITE_sBIT_SUPPORTED) -PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit, - int color_type)); -#endif - -#if defined(PNG_WRITE_cHRM_SUPPORTED) -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, - double white_x, double white_y, - double red_x, double red_y, double green_x, double green_y, - double blue_x, double blue_y)); -#endif -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, - png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); -#endif -#endif - -#if defined(PNG_WRITE_sRGB_SUPPORTED) -PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, - int intent)); -#endif - -#if defined(PNG_WRITE_iCCP_SUPPORTED) -PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, - png_charp name, int compression_type, - png_charp profile, int proflen)); - /* Note to maintainer: profile should be png_bytep */ -#endif - -#if defined(PNG_WRITE_sPLT_SUPPORTED) -PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, - png_sPLT_tp palette)); -#endif - -#if defined(PNG_WRITE_tRNS_SUPPORTED) -PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans, - png_color_16p values, int number, int color_type)); -#endif - -#if defined(PNG_WRITE_bKGD_SUPPORTED) -PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, - png_color_16p values, int color_type)); -#endif - -#if defined(PNG_WRITE_hIST_SUPPORTED) -PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist, - int num_hist)); -#endif - -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, - png_charp key, png_charpp new_key)); -#endif - -#if defined(PNG_WRITE_tEXt_SUPPORTED) -PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key, - png_charp text, png_size_t text_len)); -#endif - -#if defined(PNG_WRITE_zTXt_SUPPORTED) -PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key, - png_charp text, png_size_t text_len, int compression)); -#endif - -#if defined(PNG_WRITE_iTXt_SUPPORTED) -PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, - int compression, png_charp key, png_charp lang, png_charp lang_key, - png_charp text)); -#endif - -#if defined(PNG_WRITE_oFFs_SUPPORTED) -PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, - png_int_32 x_offset, png_int_32 y_offset, int unit_type)); -#endif - -#if defined(PNG_WRITE_pCAL_SUPPORTED) -PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, - png_int_32 X0, png_int_32 X1, int type, int nparams, - png_charp units, png_charpp params)); -#endif - -#if defined(PNG_WRITE_pHYs_SUPPORTED) -PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, - png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, - int unit_type)); -#endif - -#if defined(PNG_WRITE_tIME_SUPPORTED) -PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, - png_timep mod_time)); -#endif - -#if defined(PNG_WRITE_sCAL_SUPPORTED) -#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) -PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr, - int unit, double width, double height)); -#else -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, - int unit, png_charp width, png_charp height)); -#endif -#endif -#endif - -/* Called when finished processing a row of data */ -PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); - -/* Internal use only. Called before first row of data */ -PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); - -#if defined(PNG_READ_GAMMA_SUPPORTED) -PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr)); -#endif - -/* combine a row of data, dealing with alpha, etc. if requested */ -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, - int mask)); - -#if defined(PNG_READ_INTERLACING_SUPPORTED) -/* expand an interlaced row */ -/* OLD pre-1.0.9 interface: -PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass, png_uint_32 transformations)); - */ -PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)); -#endif - -/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ - -#if defined(PNG_WRITE_INTERLACING_SUPPORTED) -/* grab pixels out of a row for an interlaced pass */ -PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass)); -#endif - -/* unfilter a row */ -PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, - png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter)); - -/* Choose the best filter to use and filter the row data */ -PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, - png_row_infop row_info)); - -/* Write out the filtered row. */ -PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr, - png_bytep filtered_row)); -/* finish a row while reading, dealing with interlacing passes, etc. */ -PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); - -/* initialize the row buffers, etc. */ -PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); -/* optional call to update the users info structure */ -PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* these are the functions that do the transformations */ -#if defined(PNG_READ_FILLER_SUPPORTED) -PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 filler, png_uint_32 flags)); -#endif - -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ - defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 flags)); -#endif - -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) -PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) -PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop - row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) -PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_READ_PACK_SUPPORTED) -PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) -PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row, - png_color_8p sig_bits)); -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_16_TO_8_SUPPORTED) -PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_READ_DITHER_SUPPORTED) -PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info, - png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup)); - -# if defined(PNG_CORRECT_PALETTE_SUPPORTED) -PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, - png_colorp palette, int num_palette)); -# endif -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row)); -#endif - -#if defined(PNG_WRITE_PACK_SUPPORTED) -PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 bit_depth)); -#endif - -#if defined(PNG_WRITE_SHIFT_SUPPORTED) -PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row, - png_color_8p bit_depth)); -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) -PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, - png_color_16p trans_values, png_color_16p background, - png_color_16p background_1, - png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, - png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, - png_uint_16pp gamma_16_to_1, int gamma_shift)); -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) -PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row, - png_bytep gamma_table, png_uint_16pp gamma_16_table, - int gamma_shift)); -#endif - -#if defined(PNG_READ_EXPAND_SUPPORTED) -PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, - png_bytep row, png_colorp palette, png_bytep trans, int num_trans)); -PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, - png_bytep row, png_color_16p trans_value)); -#endif - -/* The following decodes the appropriate chunks, and does error correction, - * then calls the appropriate callback for the chunk if it is valid. - */ - -/* decode the IHDR chunk */ -PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); - -#if defined(PNG_READ_bKGD_SUPPORTED) -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_cHRM_SUPPORTED) -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_gAMA_SUPPORTED) -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_hIST_SUPPORTED) -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_iCCP_SUPPORTED) -extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_iCCP_SUPPORTED */ - -#if defined(PNG_READ_iTXt_SUPPORTED) -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_oFFs_SUPPORTED) -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_pCAL_SUPPORTED) -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_pHYs_SUPPORTED) -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_sBIT_SUPPORTED) -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_sCAL_SUPPORTED) -PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_sPLT_SUPPORTED) -extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_sPLT_SUPPORTED */ - -#if defined(PNG_READ_sRGB_SUPPORTED) -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_tEXt_SUPPORTED) -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_tIME_SUPPORTED) -PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_tRNS_SUPPORTED) -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#if defined(PNG_READ_zTXt_SUPPORTED) -PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -PNG_EXTERN int png_handle_as_unknown PNGARG((png_structp png_ptr, png_bytep - chunk_name)); -#endif - -PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); - -PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, - png_bytep chunk_name)); - -/* handle the transformations for reading and writing */ -PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr)); - -PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, - png_uint_32 length)); -PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t length)); -PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); -PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); -#if defined(PNG_READ_tEXt_SUPPORTED) -PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif -#if defined(PNG_READ_zTXt_SUPPORTED) -PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif -#if defined(PNG_READ_iTXt_SUPPORTED) -PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -#ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) -/* png.c */ /* PRIVATE */ -PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr)); -#endif -/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ - -#endif /* PNG_INTERNAL */ - -#ifdef __cplusplus -} -#endif - -#endif /* PNG_VERSION_INFO_ONLY */ -/* do not put anything past this line */ -#endif /* PNG_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/include/png/pngasmrd.h ./win32/include/png/pngasmrd.h --- ../VisualBoyAdvance-1.7.2/win32/include/png/pngasmrd.h 2002-10-20 22:03:13 +0900 +++ ./win32/include/png/pngasmrd.h 1970-01-01 09:00:00 +0900 @@ -1,11 +0,0 @@ -/* pngasmrd.h - assembler version of utilities to read a PNG file - * - * libpng 1.2.0 - September 1, 2001 - * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 2001 Glenn Randers-Pehrson - * - */ - -/* This file is obsolete in libpng-1.0.9 and later; its contents now appear - * at the end of pngconf.h. - */ diff -urN ../VisualBoyAdvance-1.7.2/win32/include/png/pngconf.h ./win32/include/png/pngconf.h --- ../VisualBoyAdvance-1.7.2/win32/include/png/pngconf.h 2002-10-20 22:03:13 +0900 +++ ./win32/include/png/pngconf.h 1970-01-01 09:00:00 +0900 @@ -1,1322 +0,0 @@ -/* pngconf.h - machine configurable file for libpng - * - * libpng 1.2.0 - September 1, 2001 - * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2001 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - */ - -/* Any machine specific code is near the front of this file, so if you - * are configuring libpng for a machine, you may want to read the section - * starting here down to where it starts to typedef png_color, png_text, - * and png_info. - */ - -#ifndef PNGCONF_H -#define PNGCONF_H - -/* This is the size of the compression buffer, and thus the size of - * an IDAT chunk. Make this whatever size you feel is best for your - * machine. One of these will be allocated per png_struct. When this - * is full, it writes the data to the disk, and does some other - * calculations. Making this an extremely small size will slow - * the library down, but you may want to experiment to determine - * where it becomes significant, if you are concerned with memory - * usage. Note that zlib allocates at least 32Kb also. For readers, - * this describes the size of the buffer available to read the data in. - * Unless this gets smaller than the size of a row (compressed), - * it should not make much difference how big this is. - */ - -#ifndef PNG_ZBUF_SIZE -# define PNG_ZBUF_SIZE 8192 -#endif - -/* Enable if you want a write-only libpng */ - -#ifndef PNG_NO_READ_SUPPORTED -# define PNG_READ_SUPPORTED -#endif - -/* Enable if you want a read-only libpng */ - -#ifndef PNG_NO_WRITE_SUPPORTED -# define PNG_WRITE_SUPPORTED -#endif - -/* Enabled by default in 1.2.0. You can disable this if you don't need to - support PNGs that are embedded in MNG datastreams */ -#ifndef PNG_NO_MNG_FEATURES -# ifndef PNG_MNG_FEATURES_SUPPORTED -# define PNG_MNG_FEATURES_SUPPORTED -# endif -#endif - -#ifndef PNG_NO_FLOATING_POINT_SUPPORTED -# ifndef PNG_FLOATING_POINT_SUPPORTED -# define PNG_FLOATING_POINT_SUPPORTED -# endif -#endif - -/* If you are running on a machine where you cannot allocate more - * than 64K of memory at once, uncomment this. While libpng will not - * normally need that much memory in a chunk (unless you load up a very - * large file), zlib needs to know how big of a chunk it can use, and - * libpng thus makes sure to check any memory allocation to verify it - * will fit into memory. -#define PNG_MAX_MALLOC_64K - */ -#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) -# define PNG_MAX_MALLOC_64K -#endif - -/* Special munging to support doing things the 'cygwin' way: - * 'Normal' png-on-win32 defines/defaults: - * PNG_BUILD_DLL -- building dll - * PNG_USE_DLL -- building an application, linking to dll - * (no define) -- building static library, or building an - * application and linking to the static lib - * 'Cygwin' defines/defaults: - * PNG_BUILD_DLL -- building the dll - * (no define) -- building an application, linking to the dll - * PNG_STATIC -- building the static lib, or building an application - * that links to the static lib. - * ALL_STATIC -- building various static libs, or building an application - * that links to the static libs. - * Thus, - * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and - * this bit of #ifdefs will define the 'correct' config variables based on - * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but - * unnecessary. - * - * Also, the precedence order is: - * ALL_STATIC (since we can't #undef something outside our namespace) - * PNG_BUILD_DLL - * PNG_STATIC - * (nothing) == PNG_USE_DLL - */ -#if defined(__CYGWIN__) -# if defined(ALL_STATIC) -# if defined(PNG_BUILD_DLL) -# undef PNG_BUILD_DLL -# endif -# if defined(PNG_USE_DLL) -# undef PNG_USE_DLL -# endif -# if defined(PNG_DLL) -# undef PNG_DLL -# endif -# if !defined(PNG_STATIC) -# define PNG_STATIC -# endif -# else -# if defined (PNG_BUILD_DLL) -# if defined(PNG_STATIC) -# undef PNG_STATIC -# endif -# if defined(PNG_USE_DLL) -# undef PNG_USE_DLL -# endif -# if !defined(PNG_DLL) -# define PNG_DLL -# endif -# else -# if defined(PNG_STATIC) -# if defined(PNG_USE_DLL) -# undef PNG_USE_DLL -# endif -# if defined(PNG_DLL) -# undef PNG_DLL -# endif -# else -# if !defined(PNG_USE_DLL) -# define PNG_USE_DLL -# endif -# if !defined(PNG_DLL) -# define PNG_DLL -# endif -# endif -# endif -# endif -#endif - -/* This protects us against compilers that run on a windowing system - * and thus don't have or would rather us not use the stdio types: - * stdin, stdout, and stderr. The only one currently used is stderr - * in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will - * prevent these from being compiled and used. #defining PNG_NO_STDIO - * will also prevent these, plus will prevent the entire set of stdio - * macros and functions (FILE *, printf, etc.) from being compiled and used, - * unless (PNG_DEBUG > 0) has been #defined. - * - * #define PNG_NO_CONSOLE_IO - * #define PNG_NO_STDIO - */ - -#if defined(_WIN32_WCE) -# include - /* Console I/O functions are not supported on WindowsCE */ -# define PNG_NO_CONSOLE_IO -# ifdef PNG_DEBUG -# undef PNG_DEBUG -# endif -#endif - -#ifdef PNG_BUILD_DLL -# ifndef PNG_CONSOLE_IO_SUPPORTED -# ifndef PNG_NO_CONSOLE_IO -# define PNG_NO_CONSOLE_IO -# endif -# endif -#endif - -# ifdef PNG_NO_STDIO -# ifndef PNG_NO_CONSOLE_IO -# define PNG_NO_CONSOLE_IO -# endif -# ifdef PNG_DEBUG -# if (PNG_DEBUG > 0) -# include -# endif -# endif -# else -# if !defined(_WIN32_WCE) -/* "stdio.h" functions are not supported on WindowsCE */ -# include -# endif -# endif - -/* This macro protects us against machines that don't have function - * prototypes (ie K&R style headers). If your compiler does not handle - * function prototypes, define this macro and use the included ansi2knr. - * I've always been able to use _NO_PROTO as the indicator, but you may - * need to drag the empty declaration out in front of here, or change the - * ifdef to suit your own needs. - */ -#ifndef PNGARG - -#ifdef OF /* zlib prototype munger */ -# define PNGARG(arglist) OF(arglist) -#else - -#ifdef _NO_PROTO -# define PNGARG(arglist) () -#else -# define PNGARG(arglist) arglist -#endif /* _NO_PROTO */ - -#endif /* OF */ - -#endif /* PNGARG */ - -/* Try to determine if we are compiling on a Mac. Note that testing for - * just __MWERKS__ is not good enough, because the Codewarrior is now used - * on non-Mac platforms. - */ -#ifndef MACOS -# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ - defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) -# define MACOS -# endif -#endif - -/* enough people need this for various reasons to include it here */ -#if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) -# include -#endif - -#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) -# define PNG_SETJMP_SUPPORTED -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* This is an attempt to force a single setjmp behaviour on Linux. If - * the X config stuff didn't define _BSD_SOURCE we wouldn't need this. - */ - -# ifdef __linux__ -# ifdef _BSD_SOURCE -# define PNG_SAVE_BSD_SOURCE -# undef _BSD_SOURCE -# endif -# ifdef _SETJMP_H - __png.h__ already includes setjmp.h; - __dont__ include it again.; -# endif -# endif /* __linux__ */ - - /* include setjmp.h for error handling */ -# include - -# ifdef __linux__ -# ifdef PNG_SAVE_BSD_SOURCE -# define _BSD_SOURCE -# undef PNG_SAVE_BSD_SOURCE -# endif -# endif /* __linux__ */ -#endif /* PNG_SETJMP_SUPPORTED */ - -#ifdef BSD -# include -#else -# include -#endif - -/* Other defines for things like memory and the like can go here. */ -#ifdef PNG_INTERNAL - -#include - -/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which - * aren't usually used outside the library (as far as I know), so it is - * debatable if they should be exported at all. In the future, when it is - * possible to have run-time registry of chunk-handling functions, some of - * these will be made available again. -#define PNG_EXTERN extern - */ -#define PNG_EXTERN - -/* Other defines specific to compilers can go here. Try to keep - * them inside an appropriate ifdef/endif pair for portability. - */ - -#if defined(PNG_FLOATING_POINT_SUPPORTED) -# if defined(MACOS) - /* We need to check that hasn't already been included earlier - * as it seems it doesn't agree with , yet we should really use - * if possible. - */ -# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) -# include -# endif -# else -# include -# endif -# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) - /* Amiga SAS/C: We must include builtin FPU functions when compiling using - * MATH=68881 - */ -# include -# endif -#endif - -/* Codewarrior on NT has linking problems without this. */ -#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) -# define PNG_ALWAYS_EXTERN -#endif - -/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not - * stdlib.h like it should (I think). Or perhaps this is a C++ - * "feature"? - */ -#ifdef __TURBOC__ -# include -# include "alloc.h" -#endif - -#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ - defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) -# include -#endif - -/* This controls how fine the dithering gets. As this allocates - * a largish chunk of memory (32K), those who are not as concerned - * with dithering quality can decrease some or all of these. - */ -#ifndef PNG_DITHER_RED_BITS -# define PNG_DITHER_RED_BITS 5 -#endif -#ifndef PNG_DITHER_GREEN_BITS -# define PNG_DITHER_GREEN_BITS 5 -#endif -#ifndef PNG_DITHER_BLUE_BITS -# define PNG_DITHER_BLUE_BITS 5 -#endif - -/* This controls how fine the gamma correction becomes when you - * are only interested in 8 bits anyway. Increasing this value - * results in more memory being used, and more pow() functions - * being called to fill in the gamma tables. Don't set this value - * less then 8, and even that may not work (I haven't tested it). - */ - -#ifndef PNG_MAX_GAMMA_8 -# define PNG_MAX_GAMMA_8 11 -#endif - -/* This controls how much a difference in gamma we can tolerate before - * we actually start doing gamma conversion. - */ -#ifndef PNG_GAMMA_THRESHOLD -# define PNG_GAMMA_THRESHOLD 0.05 -#endif - -#endif /* PNG_INTERNAL */ - -/* The following uses const char * instead of char * for error - * and warning message functions, so some compilers won't complain. - * If you do not want to use const, define PNG_NO_CONST here. - */ - -#ifndef PNG_NO_CONST -# define PNG_CONST const -#else -# define PNG_CONST -#endif - -/* The following defines give you the ability to remove code from the - * library that you will not be using. I wish I could figure out how to - * automate this, but I can't do that without making it seriously hard - * on the users. So if you are not using an ability, change the #define - * to and #undef, and that part of the library will not be compiled. If - * your linker can't find a function, you may want to make sure the - * ability is defined here. Some of these depend upon some others being - * defined. I haven't figured out all the interactions here, so you may - * have to experiment awhile to get everything to compile. If you are - * creating or using a shared library, you probably shouldn't touch this, - * as it will affect the size of the structures, and this will cause bad - * things to happen if the library and/or application ever change. - */ - -/* Any features you will not be using can be undef'ed here */ - -/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user - * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS - * on the compile line, then pick and choose which ones to define without - * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED - * if you only want to have a png-compliant reader/writer but don't need - * any of the extra transformations. This saves about 80 kbytes in a - * typical installation of the library. (PNG_NO_* form added in version - * 1.0.1c, for consistency) - */ - -/* The size of the png_text structure changed in libpng-1.0.6 when - * iTXt is supported. It is turned off by default, to support old apps - * that malloc the png_text structure instead of calling png_set_text() - * and letting libpng malloc it. It will be turned on by default in - * libpng-1.3.0. - */ - -#ifndef PNG_iTXt_SUPPORTED -# ifndef PNG_READ_iTXt_SUPPORTED -# define PNG_NO_READ_iTXt -# endif -# ifndef PNG_WRITE_iTXt_SUPPORTED -# define PNG_NO_WRITE_iTXt -# endif -#endif - -/* The following support, added after version 1.0.0, can be turned off here en - * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility - * with old applications that require the length of png_struct and png_info - * to remain unchanged. - */ - -#ifdef PNG_LEGACY_SUPPORTED -# define PNG_NO_FREE_ME -# define PNG_NO_READ_UNKNOWN_CHUNKS -# define PNG_NO_WRITE_UNKNOWN_CHUNKS -# define PNG_NO_READ_USER_CHUNKS -# define PNG_NO_READ_iCCP -# define PNG_NO_WRITE_iCCP -# define PNG_NO_READ_iTXt -# define PNG_NO_WRITE_iTXt -# define PNG_NO_READ_sCAL -# define PNG_NO_WRITE_sCAL -# define PNG_NO_READ_sPLT -# define PNG_NO_WRITE_sPLT -# define PNG_NO_INFO_IMAGE -# define PNG_NO_READ_RGB_TO_GRAY -# define PNG_NO_READ_USER_TRANSFORM -# define PNG_NO_WRITE_USER_TRANSFORM -# define PNG_NO_USER_MEM -# define PNG_NO_READ_EMPTY_PLTE -# define PNG_NO_MNG_FEATURES -# define PNG_NO_FIXED_POINT_SUPPORTED -#endif - -/* Ignore attempt to turn off both floating and fixed point support */ -#if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ - !defined(PNG_NO_FIXED_POINT_SUPPORTED) -# define PNG_FIXED_POINT_SUPPORTED -#endif - -#ifndef PNG_NO_FREE_ME -# define PNG_FREE_ME_SUPPORTED -#endif - -#if defined(PNG_READ_SUPPORTED) - -#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ - !defined(PNG_NO_READ_TRANSFORMS) -# define PNG_READ_TRANSFORMS_SUPPORTED -#endif - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -# ifndef PNG_NO_READ_EXPAND -# define PNG_READ_EXPAND_SUPPORTED -# endif -# ifndef PNG_NO_READ_SHIFT -# define PNG_READ_SHIFT_SUPPORTED -# endif -# ifndef PNG_NO_READ_PACK -# define PNG_READ_PACK_SUPPORTED -# endif -# ifndef PNG_NO_READ_BGR -# define PNG_READ_BGR_SUPPORTED -# endif -# ifndef PNG_NO_READ_SWAP -# define PNG_READ_SWAP_SUPPORTED -# endif -# ifndef PNG_NO_READ_PACKSWAP -# define PNG_READ_PACKSWAP_SUPPORTED -# endif -# ifndef PNG_NO_READ_INVERT -# define PNG_READ_INVERT_SUPPORTED -# endif -# ifndef PNG_NO_READ_DITHER -# define PNG_READ_DITHER_SUPPORTED -# endif -# ifndef PNG_NO_READ_BACKGROUND -# define PNG_READ_BACKGROUND_SUPPORTED -# endif -# ifndef PNG_NO_READ_16_TO_8 -# define PNG_READ_16_TO_8_SUPPORTED -# endif -# ifndef PNG_NO_READ_FILLER -# define PNG_READ_FILLER_SUPPORTED -# endif -# ifndef PNG_NO_READ_GAMMA -# define PNG_READ_GAMMA_SUPPORTED -# endif -# ifndef PNG_NO_READ_GRAY_TO_RGB -# define PNG_READ_GRAY_TO_RGB_SUPPORTED -# endif -# ifndef PNG_NO_READ_SWAP_ALPHA -# define PNG_READ_SWAP_ALPHA_SUPPORTED -# endif -# ifndef PNG_NO_READ_INVERT_ALPHA -# define PNG_READ_INVERT_ALPHA_SUPPORTED -# endif -# ifndef PNG_NO_READ_STRIP_ALPHA -# define PNG_READ_STRIP_ALPHA_SUPPORTED -# endif -# ifndef PNG_NO_READ_USER_TRANSFORM -# define PNG_READ_USER_TRANSFORM_SUPPORTED -# endif -# ifndef PNG_NO_READ_RGB_TO_GRAY -# define PNG_READ_RGB_TO_GRAY_SUPPORTED -# endif -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ - -#if !defined(PNG_NO_PROGRESSIVE_READ) && \ - !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */ -# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ -#endif /* about interlacing capability! You'll */ - /* still have interlacing unless you change the following line: */ - -#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */ - -#ifndef PNG_NO_READ_COMPOSITE_NODIV -# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ -# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ -# endif -#endif - -/* Deprecated, will be removed from version 2.0.0. - Use PNG_MNG_FEATURES_SUPPORTED instead. */ -#ifndef PNG_NO_READ_EMPTY_PLTE -# define PNG_READ_EMPTY_PLTE_SUPPORTED -#endif - -#endif /* PNG_READ_SUPPORTED */ - -#if defined(PNG_WRITE_SUPPORTED) - -# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ - !defined(PNG_NO_WRITE_TRANSFORMS) -# define PNG_WRITE_TRANSFORMS_SUPPORTED -#endif - -#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -# ifndef PNG_NO_WRITE_SHIFT -# define PNG_WRITE_SHIFT_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_PACK -# define PNG_WRITE_PACK_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_BGR -# define PNG_WRITE_BGR_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_SWAP -# define PNG_WRITE_SWAP_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_PACKSWAP -# define PNG_WRITE_PACKSWAP_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_INVERT -# define PNG_WRITE_INVERT_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_FILLER -# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */ -# endif -# ifndef PNG_NO_WRITE_SWAP_ALPHA -# define PNG_WRITE_SWAP_ALPHA_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_INVERT_ALPHA -# define PNG_WRITE_INVERT_ALPHA_SUPPORTED -# endif -# ifndef PNG_NO_WRITE_USER_TRANSFORM -# define PNG_WRITE_USER_TRANSFORM_SUPPORTED -# endif -#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -# ifndef PNG_NO_USER_TRANSFORM_PTR -# define PNG_USER_TRANSFORM_PTR_SUPPORTED -# endif -#endif - -#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant - encoders, but can cause trouble - if left undefined */ - -#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ - defined(PNG_FLOATING_POINT_SUPPORTED) -# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED -#endif - -#ifndef PNG_NO_ERROR_NUMBERS -#define PNG_ERROR_NUMBERS_SUPPORTED -#endif - -#ifndef PNG_NO_WRITE_FLUSH -# define PNG_WRITE_FLUSH_SUPPORTED -#endif - -/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ -#ifndef PNG_NO_WRITE_EMPTY_PLTE -# define PNG_WRITE_EMPTY_PLTE_SUPPORTED -#endif - -#endif /* PNG_WRITE_SUPPORTED */ - -#ifndef PNG_NO_STDIO -# define PNG_TIME_RFC1123_SUPPORTED -#endif - -/* This adds extra functions in pngget.c for accessing data from the - * info pointer (added in version 0.99) - * png_get_image_width() - * png_get_image_height() - * png_get_bit_depth() - * png_get_color_type() - * png_get_compression_type() - * png_get_filter_type() - * png_get_interlace_type() - * png_get_pixel_aspect_ratio() - * png_get_pixels_per_meter() - * png_get_x_offset_pixels() - * png_get_y_offset_pixels() - * png_get_x_offset_microns() - * png_get_y_offset_microns() - */ -#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED) -# define PNG_EASY_ACCESS_SUPPORTED -#endif - -/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 - even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined */ -#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) -# ifndef PNG_ASSEMBLER_CODE_SUPPORTED -# define PNG_ASSEMBLER_CODE_SUPPORTED -# endif -# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) -# define PNG_MMX_CODE_SUPPORTED -# endif -#endif - -/* If you are sure that you don't need thread safety and you are compiling - with PNG_USE_PNGCCRD for an MMX application, you can define this for - faster execution. See pnggccrd.c. -#define PNG_THREAD_UNSAFE_OK -*/ - -#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) -# define PNG_USER_MEM_SUPPORTED -#endif - -/* These are currently experimental features, define them if you want */ - -/* very little testing */ -/* -#ifdef PNG_READ_SUPPORTED -# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED -# define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED -# endif -#endif -*/ - -/* This is only for PowerPC big-endian and 680x0 systems */ -/* some testing */ -/* -#ifdef PNG_READ_SUPPORTED -# ifndef PNG_PNG_READ_BIG_ENDIAN_SUPPORTED -# define PNG_READ_BIG_ENDIAN_SUPPORTED -# endif -#endif -*/ - -/* Buggy compilers (e.g., gcc 2.7.2.2) need this */ -/* -#define PNG_NO_POINTER_INDEXING -*/ - -/* These functions are turned off by default, as they will be phased out. */ -/* -#define PNG_USELESS_TESTS_SUPPORTED -#define PNG_CORRECT_PALETTE_SUPPORTED -*/ - -/* Any chunks you are not interested in, you can undef here. The - * ones that allocate memory may be expecially important (hIST, - * tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info - * a bit smaller. - */ - -#if defined(PNG_READ_SUPPORTED) && \ - !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ - !defined(PNG_NO_READ_ANCILLARY_CHUNKS) -# define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED -#endif - -#if defined(PNG_WRITE_SUPPORTED) && \ - !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ - !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) -# define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED -#endif - -#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED - -#ifdef PNG_NO_READ_TEXT -# define PNG_NO_READ_iTXt -# define PNG_NO_READ_tEXt -# define PNG_NO_READ_zTXt -#endif -#ifndef PNG_NO_READ_bKGD -# define PNG_READ_bKGD_SUPPORTED -# define PNG_bKGD_SUPPORTED -#endif -#ifndef PNG_NO_READ_cHRM -# define PNG_READ_cHRM_SUPPORTED -# define PNG_cHRM_SUPPORTED -#endif -#ifndef PNG_NO_READ_gAMA -# define PNG_READ_gAMA_SUPPORTED -# define PNG_gAMA_SUPPORTED -#endif -#ifndef PNG_NO_READ_hIST -# define PNG_READ_hIST_SUPPORTED -# define PNG_hIST_SUPPORTED -#endif -#ifndef PNG_NO_READ_iCCP -# define PNG_READ_iCCP_SUPPORTED -# define PNG_iCCP_SUPPORTED -#endif -#ifndef PNG_NO_READ_iTXt -# define PNG_READ_iTXt_SUPPORTED -# define PNG_iTXt_SUPPORTED -#endif -#ifndef PNG_NO_READ_oFFs -# define PNG_READ_oFFs_SUPPORTED -# define PNG_oFFs_SUPPORTED -#endif -#ifndef PNG_NO_READ_pCAL -# define PNG_READ_pCAL_SUPPORTED -# define PNG_pCAL_SUPPORTED -#endif -#ifndef PNG_NO_READ_sCAL -# define PNG_READ_sCAL_SUPPORTED -# define PNG_sCAL_SUPPORTED -#endif -#ifndef PNG_NO_READ_pHYs -# define PNG_READ_pHYs_SUPPORTED -# define PNG_pHYs_SUPPORTED -#endif -#ifndef PNG_NO_READ_sBIT -# define PNG_READ_sBIT_SUPPORTED -# define PNG_sBIT_SUPPORTED -#endif -#ifndef PNG_NO_READ_sPLT -# define PNG_READ_sPLT_SUPPORTED -# define PNG_sPLT_SUPPORTED -#endif -#ifndef PNG_NO_READ_sRGB -# define PNG_READ_sRGB_SUPPORTED -# define PNG_sRGB_SUPPORTED -#endif -#ifndef PNG_NO_READ_tEXt -# define PNG_READ_tEXt_SUPPORTED -# define PNG_tEXt_SUPPORTED -#endif -#ifndef PNG_NO_READ_tIME -# define PNG_READ_tIME_SUPPORTED -# define PNG_tIME_SUPPORTED -#endif -#ifndef PNG_NO_READ_tRNS -# define PNG_READ_tRNS_SUPPORTED -# define PNG_tRNS_SUPPORTED -#endif -#ifndef PNG_NO_READ_zTXt -# define PNG_READ_zTXt_SUPPORTED -# define PNG_zTXt_SUPPORTED -#endif -#ifndef PNG_NO_READ_UNKNOWN_CHUNKS -# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED -# define PNG_UNKNOWN_CHUNKS_SUPPORTED -# endif -# ifndef PNG_NO_HANDLE_AS_UNKNOWN -# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED -# endif -#endif -#if !defined(PNG_NO_READ_USER_CHUNKS) && \ - defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) -# define PNG_READ_USER_CHUNKS_SUPPORTED -# define PNG_USER_CHUNKS_SUPPORTED -# ifdef PNG_NO_READ_UNKNOWN_CHUNKS -# undef PNG_NO_READ_UNKNOWN_CHUNKS -# endif -# ifdef PNG_NO_HANDLE_AS_UNKNOWN -# undef PNG_NO_HANDLE_AS_UNKNOWN -# endif -#endif -#ifndef PNG_NO_READ_OPT_PLTE -# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ -#endif /* optional PLTE chunk in RGB and RGBA images */ -#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \ - defined(PNG_READ_zTXt_SUPPORTED) -# define PNG_READ_TEXT_SUPPORTED -# define PNG_TEXT_SUPPORTED -#endif - -#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */ - -#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED - -#ifdef PNG_NO_WRITE_TEXT -# define PNG_NO_WRITE_iTXt -# define PNG_NO_WRITE_tEXt -# define PNG_NO_WRITE_zTXt -#endif -#ifndef PNG_NO_WRITE_bKGD -# define PNG_WRITE_bKGD_SUPPORTED -# ifndef PNG_bKGD_SUPPORTED -# define PNG_bKGD_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_cHRM -# define PNG_WRITE_cHRM_SUPPORTED -# ifndef PNG_cHRM_SUPPORTED -# define PNG_cHRM_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_gAMA -# define PNG_WRITE_gAMA_SUPPORTED -# ifndef PNG_gAMA_SUPPORTED -# define PNG_gAMA_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_hIST -# define PNG_WRITE_hIST_SUPPORTED -# ifndef PNG_hIST_SUPPORTED -# define PNG_hIST_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_iCCP -# define PNG_WRITE_iCCP_SUPPORTED -# ifndef PNG_iCCP_SUPPORTED -# define PNG_iCCP_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_iTXt -# define PNG_WRITE_iTXt_SUPPORTED -# ifndef PNG_iTXt_SUPPORTED -# define PNG_iTXt_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_oFFs -# define PNG_WRITE_oFFs_SUPPORTED -# ifndef PNG_oFFs_SUPPORTED -# define PNG_oFFs_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_pCAL -# define PNG_WRITE_pCAL_SUPPORTED -# ifndef PNG_pCAL_SUPPORTED -# define PNG_pCAL_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_sCAL -# define PNG_WRITE_sCAL_SUPPORTED -# ifndef PNG_sCAL_SUPPORTED -# define PNG_sCAL_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_pHYs -# define PNG_WRITE_pHYs_SUPPORTED -# ifndef PNG_pHYs_SUPPORTED -# define PNG_pHYs_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_sBIT -# define PNG_WRITE_sBIT_SUPPORTED -# ifndef PNG_sBIT_SUPPORTED -# define PNG_sBIT_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_sPLT -# define PNG_WRITE_sPLT_SUPPORTED -# ifndef PNG_sPLT_SUPPORTED -# define PNG_sPLT_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_sRGB -# define PNG_WRITE_sRGB_SUPPORTED -# ifndef PNG_sRGB_SUPPORTED -# define PNG_sRGB_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_tEXt -# define PNG_WRITE_tEXt_SUPPORTED -# ifndef PNG_tEXt_SUPPORTED -# define PNG_tEXt_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_tIME -# define PNG_WRITE_tIME_SUPPORTED -# ifndef PNG_tIME_SUPPORTED -# define PNG_tIME_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_tRNS -# define PNG_WRITE_tRNS_SUPPORTED -# ifndef PNG_tRNS_SUPPORTED -# define PNG_tRNS_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_zTXt -# define PNG_WRITE_zTXt_SUPPORTED -# ifndef PNG_zTXt_SUPPORTED -# define PNG_zTXt_SUPPORTED -# endif -#endif -#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS -# define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED -# define PNG_UNKNOWN_CHUNKS_SUPPORTED -# endif -# ifndef PNG_NO_HANDLE_AS_UNKNOWN -# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED -# endif -# endif -#endif -#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ - defined(PNG_WRITE_zTXt_SUPPORTED) -# define PNG_WRITE_TEXT_SUPPORTED -# ifndef PNG_TEXT_SUPPORTED -# define PNG_TEXT_SUPPORTED -# endif -#endif - -#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ - -/* Turn this off to disable png_read_png() and - * png_write_png() and leave the row_pointers member - * out of the info structure. - */ -#ifndef PNG_NO_INFO_IMAGE -# define PNG_INFO_IMAGE_SUPPORTED -#endif - -/* need the time information for reading tIME chunks */ -#if defined(PNG_tIME_SUPPORTED) -# if !defined(_WIN32_WCE) - /* "time.h" functions are not supported on WindowsCE */ -# include -# endif -#endif - -/* Some typedefs to get us started. These should be safe on most of the - * common platforms. The typedefs should be at least as large as the - * numbers suggest (a png_uint_32 must be at least 32 bits long), but they - * don't have to be exactly that size. Some compilers dislike passing - * unsigned shorts as function parameters, so you may be better off using - * unsigned int for png_uint_16. Likewise, for 64-bit systems, you may - * want to have unsigned int for png_uint_32 instead of unsigned long. - */ - -typedef unsigned long png_uint_32; -typedef long png_int_32; -typedef unsigned short png_uint_16; -typedef short png_int_16; -typedef unsigned char png_byte; - -/* This is usually size_t. It is typedef'ed just in case you need it to - change (I'm not sure if you will or not, so I thought I'd be safe) */ -typedef size_t png_size_t; - -/* The following is needed for medium model support. It cannot be in the - * PNG_INTERNAL section. Needs modification for other compilers besides - * MSC. Model independent support declares all arrays and pointers to be - * large using the far keyword. The zlib version used must also support - * model independent data. As of version zlib 1.0.4, the necessary changes - * have been made in zlib. The USE_FAR_KEYWORD define triggers other - * changes that are needed. (Tim Wegner) - */ - -/* Separate compiler dependencies (problem here is that zlib.h always - defines FAR. (SJT) */ -#ifdef __BORLANDC__ -# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) -# define LDATA 1 -# else -# define LDATA 0 -# endif - /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ -# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) -# define PNG_MAX_MALLOC_64K -# if (LDATA != 1) -# ifndef FAR -# define FAR __far -# endif -# define USE_FAR_KEYWORD -# endif /* LDATA != 1 */ - /* Possibly useful for moving data out of default segment. - * Uncomment it if you want. Could also define FARDATA as - * const if your compiler supports it. (SJT) -# define FARDATA FAR - */ -# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ -#endif /* __BORLANDC__ */ - - -/* Suggest testing for specific compiler first before testing for - * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, - * making reliance oncertain keywords suspect. (SJT) - */ - -/* MSC Medium model */ -#if defined(FAR) -# if defined(M_I86MM) -# define USE_FAR_KEYWORD -# define FARDATA FAR -# include -# endif -#endif - -/* SJT: default case */ -#ifndef FAR -# define FAR -#endif - -/* At this point FAR is always defined */ -#ifndef FARDATA -# define FARDATA -#endif - -/* Typedef for floating-point numbers that are converted - to fixed-point with a multiple of 100,000, e.g., int_gamma */ -typedef png_int_32 png_fixed_point; - -/* Add typedefs for pointers */ -typedef void FAR * png_voidp; -typedef png_byte FAR * png_bytep; -typedef png_uint_32 FAR * png_uint_32p; -typedef png_int_32 FAR * png_int_32p; -typedef png_uint_16 FAR * png_uint_16p; -typedef png_int_16 FAR * png_int_16p; -typedef PNG_CONST char FAR * png_const_charp; -typedef char FAR * png_charp; -typedef png_fixed_point FAR * png_fixed_point_p; - -#ifndef PNG_NO_STDIO -#if defined(_WIN32_WCE) -typedef HANDLE png_FILE_p; -#else -typedef FILE * png_FILE_p; -#endif -#endif - -#ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * png_doublep; -#endif - -/* Pointers to pointers; i.e. arrays */ -typedef png_byte FAR * FAR * png_bytepp; -typedef png_uint_32 FAR * FAR * png_uint_32pp; -typedef png_int_32 FAR * FAR * png_int_32pp; -typedef png_uint_16 FAR * FAR * png_uint_16pp; -typedef png_int_16 FAR * FAR * png_int_16pp; -typedef PNG_CONST char FAR * FAR * png_const_charpp; -typedef char FAR * FAR * png_charpp; -typedef png_fixed_point FAR * FAR * png_fixed_point_pp; -#ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * FAR * png_doublepp; -#endif - -/* Pointers to pointers to pointers; i.e., pointer to array */ -typedef char FAR * FAR * FAR * png_charppp; - -/* libpng typedefs for types in zlib. If zlib changes - * or another compression library is used, then change these. - * Eliminates need to change all the source files. - */ -typedef charf * png_zcharp; -typedef charf * FAR * png_zcharpp; -typedef z_stream FAR * png_zstreamp; - -/* - * Define PNG_BUILD_DLL if the module being built is a Windows - * LIBPNG DLL. - * - * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. - * It is equivalent to Microsoft predefined macro _DLL that is - * automatically defined when you compile using the share - * version of the CRT (C Run-Time library) - * - * The cygwin mods make this behavior a little different: - * Define PNG_BUILD_DLL if you are building a dll for use with cygwin - * Define PNG_STATIC if you are building a static library for use with cygwin, - * -or- if you are building an application that you want to link to the - * static library. - * PNG_USE_DLL is defined by default (no user action needed) unless one of - * the other flags is defined. - */ - -#if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) -# define PNG_DLL -#endif -/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. - * When building a static lib, default to no GLOBAL ARRAYS, but allow - * command-line override - */ -#if defined(__CYGWIN__) -# if !defined(PNG_STATIC) -# if defined(PNG_USE_GLOBAL_ARRAYS) -# undef PNG_USE_GLOBAL_ARRAYS -# endif -# if !defined(PNG_USE_LOCAL_ARRAYS) -# define PNG_USE_LOCAL_ARRAYS -# endif -# else -# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) -# if defined(PNG_USE_GLOBAL_ARRAYS) -# undef PNG_USE_GLOBAL_ARRAYS -# endif -# endif -# endif -# if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) -# define PNG_USE_LOCAL_ARRAYS -# endif -#endif - -/* Do not use global arrays (helps with building DLL's) - * They are no longer used in libpng itself, since version 1.0.5c, - * but might be required for some pre-1.0.5c applications. - */ -#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) -# if defined(PNG_NO_GLOBAL_ARRAYS) || (defined(__GNUC__) && defined(PNG_DLL)) -# define PNG_USE_LOCAL_ARRAYS -# else -# define PNG_USE_GLOBAL_ARRAYS -# endif -#endif - - -#ifndef PNGAPI - -#if defined(__MINGW32__) || defined(__CYGWIN__) && !defined(PNG_MODULEDEF) -# ifndef PNG_NO_MODULEDEF -# define PNG_NO_MODULEDEF -# endif -#endif - -#if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF) -# define PNG_IMPEXP -#endif - -#if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \ - (( defined(_Windows) || defined(_WINDOWS) || \ - defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \ - ) && !defined(__CYGWIN__)) - -# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) -# define PNGAPI __cdecl -# else -# define PNGAPI _cdecl -# endif - -# if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \ - 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */) -# define PNG_IMPEXP -# endif - -# if !defined(PNG_IMPEXP) - -# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol -# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol - - /* Borland/Microsoft */ -# if defined(_MSC_VER) || defined(__BORLANDC__) -# if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) -# define PNG_EXPORT PNG_EXPORT_TYPE1 -# else -# define PNG_EXPORT PNG_EXPORT_TYPE2 -# if defined(PNG_BUILD_DLL) -# define PNG_IMPEXP __export -# else -# define PNG_IMPEXP /*__import*/ /* doesn't exist AFAIK in - VC++*/ -# endif /* Exists in Borland C++ for - C++ classes (== huge) */ -# endif -# endif - -# if !defined(PNG_IMPEXP) -# if defined(PNG_BUILD_DLL) -# define PNG_IMPEXP __declspec(dllexport) -# else -# define PNG_IMPEXP __declspec(dllimport) -# endif -# endif -# endif /* PNG_IMPEXP */ -#else /* !(DLL || non-cygwin WINDOWS) */ -# if defined(__CYGWIN__) && !defined(PNG_DLL) -# if !defined(PNG_IMPEXP) -# define PNG_IMPEXP -# endif -# define PNGAPI __cdecl -# else -# if (defined(__IBMC__) || defined(IBMCPP__)) && defined(__OS2__) -# define PNGAPI _System -# define PNG_IMPEXP -# else -# if 0 /* ... other platforms, with other meanings */ -# else -# define PNGAPI -# define PNG_IMPEXP -# endif -# endif -# endif -#endif -#endif - -#ifndef PNGAPI -# define PNGAPI -#endif -#ifndef PNG_IMPEXP -# define PNG_IMPEXP -#endif - -#ifndef PNG_EXPORT -# define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol -#endif - -#ifdef PNG_USE_GLOBAL_ARRAYS -# ifndef PNG_EXPORT_VAR -# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type -# endif -#endif - -/* User may want to use these so they are not in PNG_INTERNAL. Any library - * functions that are passed far data must be model independent. - */ - -#ifndef PNG_ABORT -# define PNG_ABORT() abort() -#endif - -#ifdef PNG_SETJMP_SUPPORTED -# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) -#else -# define png_jmpbuf(png_ptr) \ - (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) -#endif - -#if defined(USE_FAR_KEYWORD) /* memory model independent fns */ -/* use this to make far-to-near assignments */ -# define CHECK 1 -# define NOCHECK 0 -# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) -# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) -# define png_strcpy _fstrcpy -# define png_strlen _fstrlen -# define png_memcmp _fmemcmp /* SJT: added */ -# define png_memcpy _fmemcpy -# define png_memset _fmemset -#else /* use the usual functions */ -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strcpy strcpy -# define png_strlen strlen -# define png_memcmp memcmp /* SJT: added */ -# define png_memcpy memcpy -# define png_memset memset -#endif -/* End of memory model independent support */ - -/* Just a little check that someone hasn't tried to define something - * contradictory. - */ -#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K) -# undef PNG_ZBUF_SIZE -# define PNG_ZBUF_SIZE 65536 -#endif - -#ifdef PNG_READ_SUPPORTED -/* Prior to libpng-1.0.9, this block was in pngasmrd.h */ -#if defined(PNG_INTERNAL) - -/* These are the default thresholds before the MMX code kicks in; if either - * rowbytes or bitdepth is below the threshold, plain C code is used. These - * can be overridden at runtime via the png_set_mmx_thresholds() call in - * libpng 1.2.0 and later. The values below were chosen by Intel. - */ - -#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT -# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */ -#endif -#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT -# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */ -#endif - -/* Set this in the makefile for VC++ on Pentium, not here. */ -/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c . - * MMX will be detected at run time and used if present. - */ -#ifdef PNG_USE_PNGVCRD -# define PNG_HAVE_ASSEMBLER_COMBINE_ROW -# define PNG_HAVE_ASSEMBLER_READ_INTERLACE -# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW -#endif - -/* Set this in the makefile for gcc/as on Pentium, not here. */ -/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c . - * MMX will be detected at run time and used if present. - */ -#ifdef PNG_USE_PNGGCCRD -# define PNG_HAVE_ASSEMBLER_COMBINE_ROW -# define PNG_HAVE_ASSEMBLER_READ_INTERLACE -# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW -#endif -/* - see pnggccrd.c for info about what is currently enabled */ - -#endif /* PNG_INTERNAL */ -#endif /* PNG_READ_SUPPORTED */ - -#endif /* PNGCONF_H */ - diff -urN ../VisualBoyAdvance-1.7.2/win32/include/zlib/zconf.h ./win32/include/zlib/zconf.h --- ../VisualBoyAdvance-1.7.2/win32/include/zlib/zconf.h 2002-10-20 22:03:13 +0900 +++ ./win32/include/zlib/zconf.h 1970-01-01 09:00:00 +0900 @@ -1,279 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) zconf.h,v 1.1 2002/10/20 13:03:13 forgotten Exp */ - -#ifndef _ZCONF_H -#define _ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - */ -#ifdef Z_PREFIX -# define deflateInit_ z_deflateInit_ -# define deflate z_deflate -# define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ -# define inflate z_inflate -# define inflateEnd z_inflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateSetDictionary z_deflateSetDictionary -# define deflateCopy z_deflateCopy -# define deflateReset z_deflateReset -# define deflateParams z_deflateParams -# define inflateInit2_ z_inflateInit2_ -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateReset z_inflateReset -# define compress z_compress -# define compress2 z_compress2 -# define uncompress z_uncompress -# define adler32 z_adler32 -# define crc32 z_crc32 -# define get_crc_table z_get_crc_table - -# define Byte z_Byte -# define uInt z_uInt -# define uLong z_uLong -# define Bytef z_Bytef -# define charf z_charf -# define intf z_intf -# define uIntf z_uIntf -# define uLongf z_uLongf -# define voidpf z_voidpf -# define voidp z_voidp -#endif - -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif -#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) -# ifndef __32BIT__ -# define __32BIT__ -# endif -#endif -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#if defined(MSDOS) && !defined(__32BIT__) -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) -# define STDC -#endif -#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) -# ifndef STDC -# define STDC -# endif -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const -# endif -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Old Borland C incorrectly complains about missing returns: */ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) -# define NEED_DUMMY_RETURN -#endif - - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -#endif -#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) -# ifndef __32BIT__ -# define SMALL_MEDIUM -# define FAR _far -# endif -#endif - -/* Compile with -DZLIB_DLL for Windows DLL support */ -#if defined(ZLIB_DLL) -# if defined(_WINDOWS) || defined(WINDOWS) -# ifdef FAR -# undef FAR -# endif -# include -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR _cdecl _export -# endif -# endif -# if defined (__BORLANDC__) -# if (__BORLANDC__ >= 0x0500) && defined (WIN32) -# include -# define ZEXPORT __declspec(dllexport) WINAPI -# define ZEXPORTRVA __declspec(dllexport) WINAPIV -# else -# if defined (_Windows) && defined (__DLL__) -# define ZEXPORT _export -# define ZEXPORTVA _export -# endif -# endif -# endif -#endif - -#if defined (__BEOS__) -# if defined (ZLIB_DLL) -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -#endif - -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif -#ifndef ZEXTERN -# define ZEXTERN extern -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(MACOS) && !defined(TARGET_OS_MAC) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#ifdef HAVE_UNISTD_H -# include /* for off_t */ -# include /* for SEEK_* and off_t */ -# define z_off_t off_t -#endif -#ifndef SEEK_SET -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif -#ifndef z_off_t -# define z_off_t long -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) -# pragma map(deflateInit_,"DEIN") -# pragma map(deflateInit2_,"DEIN2") -# pragma map(deflateEnd,"DEEND") -# pragma map(inflateInit_,"ININ") -# pragma map(inflateInit2_,"ININ2") -# pragma map(inflateEnd,"INEND") -# pragma map(inflateSync,"INSY") -# pragma map(inflateSetDictionary,"INSEDI") -# pragma map(inflate_blocks,"INBL") -# pragma map(inflate_blocks_new,"INBLNE") -# pragma map(inflate_blocks_free,"INBLFR") -# pragma map(inflate_blocks_reset,"INBLRE") -# pragma map(inflate_codes_free,"INCOFR") -# pragma map(inflate_codes,"INCO") -# pragma map(inflate_fast,"INFA") -# pragma map(inflate_flush,"INFLU") -# pragma map(inflate_mask,"INMA") -# pragma map(inflate_set_dictionary,"INSEDI2") -# pragma map(inflate_copyright,"INCOPY") -# pragma map(inflate_trees_bits,"INTRBI") -# pragma map(inflate_trees_dynamic,"INTRDY") -# pragma map(inflate_trees_fixed,"INTRFI") -# pragma map(inflate_trees_free,"INTRFR") -#endif - -#endif /* _ZCONF_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/include/zlib/zlib.h ./win32/include/zlib/zlib.h --- ../VisualBoyAdvance-1.7.2/win32/include/zlib/zlib.h 2002-10-20 22:03:13 +0900 +++ ./win32/include/zlib/zlib.h 1970-01-01 09:00:00 +0900 @@ -1,893 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.1.3, July 9th, 1998 - - Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef _ZLIB_H -#define _ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.1.3" - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output - (providing more output space) before each call. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: ascii or binary */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -/* Allowed flush values; see deflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_ASCII 1 -#define Z_UNKNOWN 2 -/* Possible values of the data_type field */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - 0.1% larger than avail_in plus 12 bytes. If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may some - introduce some output latency (reading input without producing any output) - except when forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much - output as possible to the output buffer. The flushing behavior of inflate is - not specified for values of the flush parameter other than Z_SYNC_FLUSH - and Z_FINISH, but the current implementation actually flushes as much output - as possible anyway. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster routine - may be used for the single inflate() call. - - If a preset dictionary is needed at this point (see inflateSetDictionary - below), inflate sets strm-adler to the adler32 checksum of the - dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise - it sets strm->adler to the adler32 checksum of all output produced - so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or - an error code as described below. At the end of the stream, inflate() - checks that its computed adler32 checksum is equal to that saved by the - compressor and returns Z_STREAM_END only if the checksum is correct. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect - adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent - (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if no progress is possible or if there was not - enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR - case, the application may then call inflateSync to look for a good - compression block. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match). Filtered data consists mostly of small values with a - somewhat random distribution. In this case, the compression algorithm is - tuned to compress them better. The effect of Z_FILTERED is to force more - Huffman coding and less string matching; it is somewhat intermediate - between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects - the compression ratio but not the correctness of the compressed output even - if it is not set appropriately. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. - - Upon return of this function, strm->adler is set to the Adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The Adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. If a compressed stream with a larger window size is given as - input, inflate() will return with the error code Z_DATA_ERROR instead of - trying to allocate a larger window. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative - memLevel). msg is set to null if there is no error message. inflateInit2 - does not perform any decompression apart from reading the zlib header if - present: this will be done by inflate(). (So next_in and avail_in may be - modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the Adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect Adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - - - /* utility functions */ - -/* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least 0.1% larger than - sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the - compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ - - -typedef voidp gzFile; - -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); -/* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h". (See the description - of deflateInit2 for more information about the strategy parameter.) - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - const voidp buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. -*/ - -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); -/* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); -/* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) - - -#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; /* hack for buggy compilers */ -#endif - -ZEXTERN const char * ZEXPORT zError OF((int err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* _ZLIB_H */ diff -urN ../VisualBoyAdvance-1.7.2/win32/include/zlib/zutil.h ./win32/include/zlib/zutil.h --- ../VisualBoyAdvance-1.7.2/win32/include/zlib/zutil.h 2004-01-18 08:07:32 +0900 +++ ./win32/include/zlib/zutil.h 1970-01-01 09:00:00 +0900 @@ -1,220 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id: zutil.h,v 1.2 2004/01/17 23:07:32 kxu Exp $ */ - -#ifndef _Z_UTIL_H -#define _Z_UTIL_H - -#include - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = (char*)ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#ifdef MSDOS -# define OS_CODE 0x00 -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -#endif - -#ifdef WIN32 /* Window 95 & Windows NT */ -# define OS_CODE 0x0b -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0F -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) -# define fdopen(fd,type) _fdopen(fd,type) -#endif - - - /* Common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#ifdef HAVE_STRERROR - extern char *strerror OF((int)); -# define zstrerror(errnum) strerror(errnum) -#else -# define zstrerror(errnum) "" -#endif - -#if defined(pyr) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - extern void zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int z_verbose; - extern void z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - - -typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, - uInt len)); -voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); -void zcfree OF((voidpf opaque, voidpf ptr)); - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -#endif /* _Z_UTIL_H */ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/CxImage.lib and ./win32/lib/win32/CxImage.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/jpeg.lib and ./win32/lib/win32/jpeg.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/libpng.lib and ./win32/lib/win32/libpng.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/libpngMD.lib and ./win32/lib/win32/libpngMD.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/zlib.lib and ./win32/lib/win32/zlib.lib differ Binary files ../VisualBoyAdvance-1.7.2/win32/lib/win32/zlibMD.lib and ./win32/lib/win32/zlibMD.lib differ diff -urN ../VisualBoyAdvance-1.7.2/win32/vba_vs2005.sln ./win32/vba_vs2005.sln --- ../VisualBoyAdvance-1.7.2/win32/vba_vs2005.sln 1970-01-01 09:00:00 +0900 +++ ./win32/vba_vs2005.sln 2006-08-25 21:28:38 +0900 @@ -0,0 +1,67 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vba_vs2005", "vba_vs2005.vcproj", "{EAD25A86-E6DB-4258-8875-197930F28F6A}" + ProjectSection(ProjectDependencies) = postProject + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092} = {B938FBD9-C7F9-4BF7-8C27-68865D1FA092} + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE} = {DB5C12E9-BCD3-4517-8708-475C0D1D88CE} + {96E945F7-0377-48DA-A5F8-1C192DE9F25F} = {96E945F7-0377-48DA-A5F8-1C192DE9F25F} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "dependencies\zlib\zlib.vcproj", "{B938FBD9-C7F9-4BF7-8C27-68865D1FA092}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "dependencies\libpng\libpng.vcproj", "{96E945F7-0377-48DA-A5F8-1C192DE9F25F}" + ProjectSection(ProjectDependencies) = postProject + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092} = {B938FBD9-C7F9-4BF7-8C27-68865D1FA092} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cximage", "dependencies\cximage\cximage.vcproj", "{DB5C12E9-BCD3-4517-8708-475C0D1D88CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + MFC_Debug|Win32 = MFC_Debug|Win32 + MFC_Release|Win32 = MFC_Release|Win32 + SDL_Debug|Win32 = SDL_Debug|Win32 + SDL_Release|Win32 = SDL_Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EAD25A86-E6DB-4258-8875-197930F28F6A}.MFC_Debug|Win32.ActiveCfg = MFC_Debug|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.MFC_Debug|Win32.Build.0 = MFC_Debug|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.MFC_Release|Win32.ActiveCfg = MFC_Release|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.MFC_Release|Win32.Build.0 = MFC_Release|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.SDL_Debug|Win32.ActiveCfg = SDL_Debug|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.SDL_Debug|Win32.Build.0 = SDL_Debug|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.SDL_Release|Win32.ActiveCfg = SDL_Release|Win32 + {EAD25A86-E6DB-4258-8875-197930F28F6A}.SDL_Release|Win32.Build.0 = SDL_Release|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.MFC_Debug|Win32.ActiveCfg = Debug|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.MFC_Debug|Win32.Build.0 = Debug|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.MFC_Release|Win32.ActiveCfg = Release|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.MFC_Release|Win32.Build.0 = Release|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.SDL_Debug|Win32.ActiveCfg = Debug|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.SDL_Debug|Win32.Build.0 = Debug|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.SDL_Release|Win32.ActiveCfg = Release|Win32 + {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}.SDL_Release|Win32.Build.0 = Release|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.MFC_Debug|Win32.ActiveCfg = Debug|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.MFC_Debug|Win32.Build.0 = Debug|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.MFC_Release|Win32.ActiveCfg = Release|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.MFC_Release|Win32.Build.0 = Release|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.SDL_Debug|Win32.ActiveCfg = Debug|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.SDL_Debug|Win32.Build.0 = Debug|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.SDL_Release|Win32.ActiveCfg = Release|Win32 + {96E945F7-0377-48DA-A5F8-1C192DE9F25F}.SDL_Release|Win32.Build.0 = Release|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.MFC_Debug|Win32.ActiveCfg = Debug|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.MFC_Debug|Win32.Build.0 = Debug|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.MFC_Release|Win32.ActiveCfg = Release|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.MFC_Release|Win32.Build.0 = Release|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.SDL_Debug|Win32.ActiveCfg = Debug|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.SDL_Debug|Win32.Build.0 = Debug|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.SDL_Release|Win32.ActiveCfg = Release|Win32 + {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.SDL_Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + AMDCaProjectFile = + EndGlobalSection +EndGlobal diff -urN ../VisualBoyAdvance-1.7.2/win32/vba_vs2005.vcproj ./win32/vba_vs2005.vcproj --- ../VisualBoyAdvance-1.7.2/win32/vba_vs2005.vcproj 1970-01-01 09:00:00 +0900 +++ ./win32/vba_vs2005.vcproj 2006-08-25 22:30:15 +0900 @@ -0,0 +1,4866 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +