From 1b0ac8adc97d65c686a48c4375c07907de86be24 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 3 Feb 2008 20:28:48 +0000 Subject: [PATCH] lots of win32 port work git-svn-id: file:///home/notaz/opt/svn/PicoDrive@343 be3aeb3a-fb24-0410-a615-afba39da0efa --- platform/win32/GenaDrive/DSound.cpp | 49 +- platform/win32/GenaDrive/Direct.cpp | 60 +- platform/win32/GenaDrive/Emu.cpp | 10 +- platform/win32/GenaDrive/FileMenu.cpp | 188 ---- platform/win32/GenaDrive/FileMenu.h | 29 - platform/win32/GenaDrive/Font.cpp | 85 -- platform/win32/GenaDrive/GenaDrive.dsp | 308 ------ platform/win32/GenaDrive/GenaDrive.txt | 118 --- platform/win32/GenaDrive/Input.cpp | 51 +- platform/win32/GenaDrive/LightCal.cpp | 102 -- platform/win32/GenaDrive/Loop.cpp | 111 +-- platform/win32/GenaDrive/Main.cpp | 177 +++- platform/win32/GenaDrive/Makefile.vc | 13 +- platform/win32/GenaDrive/Rom.cpp | 143 --- platform/win32/GenaDrive/Unzip.cpp | 109 --- platform/win32/GenaDrive/Unzip.h | 23 - platform/win32/GenaDrive/app.h | 25 +- platform/win32/GenaDrive/readme.txt | 45 + platform/win32/GenaDrive/zconf.h | 323 ------- platform/win32/GenaDrive/zlib.h | 1200 ------------------------ 20 files changed, 303 insertions(+), 2866 deletions(-) delete mode 100644 platform/win32/GenaDrive/FileMenu.cpp delete mode 100644 platform/win32/GenaDrive/FileMenu.h delete mode 100644 platform/win32/GenaDrive/Font.cpp delete mode 100644 platform/win32/GenaDrive/GenaDrive.dsp delete mode 100644 platform/win32/GenaDrive/GenaDrive.txt delete mode 100644 platform/win32/GenaDrive/LightCal.cpp delete mode 100644 platform/win32/GenaDrive/Rom.cpp delete mode 100644 platform/win32/GenaDrive/Unzip.cpp delete mode 100644 platform/win32/GenaDrive/Unzip.h create mode 100644 platform/win32/GenaDrive/readme.txt delete mode 100644 platform/win32/GenaDrive/zconf.h delete mode 100644 platform/win32/GenaDrive/zlib.h diff --git a/platform/win32/GenaDrive/DSound.cpp b/platform/win32/GenaDrive/DSound.cpp index 3a38a8d9..f05d47b2 100644 --- a/platform/win32/GenaDrive/DSound.cpp +++ b/platform/win32/GenaDrive/DSound.cpp @@ -18,7 +18,7 @@ static int LoopBlank() void *mema=NULL,*memb=NULL; DWORD sizea=0,sizeb=0; - LoopBuffer->Lock(0,LoopLen<<2, &mema,&sizea, &memb,&sizeb, 0); + LoopBuffer->Lock(0,LoopLen<<((PicoOpt&8) ? 2 : 1), &mema,&sizea, &memb,&sizeb, 0); if (mema) memset(mema,0,sizea); @@ -47,6 +47,7 @@ int DSoundInit() // Make buffer for the next seg to put into the loop: DSoundNext=(short *)malloc((PsndLen<<2)+64); if (DSoundNext==NULL) return 1; memset(DSoundNext,0,PsndLen<<2); +// dprintf2("p %p\n", DSoundNext); // Create the DirectSound interface: DirectSoundCreate(NULL,&DSound,NULL); @@ -78,23 +79,48 @@ void DSoundExit() if (LoopBuffer) LoopBuffer->Stop(); RELEASE(LoopBuffer) RELEASE(DSound) - free(DSoundNext); DSoundNext=NULL; + DSound=0; + if (DSoundNext) free(DSoundNext); DSoundNext=NULL; } static int WriteSeg() { void *mema=NULL,*memb=NULL; DWORD sizea=0,sizeb=0; + int ret; // Lock the segment at 'LoopWrite' and copy the next segment in - LoopBuffer->Lock(LoopWrite<<((PicoOpt&8) ? 2 : 1),PsndLen<<((PicoOpt&8) ? 2 : 1), &mema,&sizea, &memb,&sizeb, 0); - + ret = LoopBuffer->Lock(LoopWrite<<((PicoOpt&8) ? 2 : 1),PsndLen<<((PicoOpt&8) ? 2 : 1), &mema,&sizea, &memb,&sizeb, 0); + if (ret) dprintf2("LoopBuffer->Lock() failed: %i\n", ret); + if (mema) memcpy(mema,DSoundNext,sizea); // if (memb) memcpy(memb,DSoundNext+sizea,sizeb); if (sizeb != 0) dprintf2("sizeb is not 0! (%i)\n", sizeb); - LoopBuffer->Unlock(mema,sizea, memb,0); + ret = LoopBuffer->Unlock(mema,sizea, memb,0); + if (ret) dprintf2("LoopBuffer->Unlock() failed: %i\n", ret); + + return 0; +} +static int DSoundFake() +{ + static int ticks_old = 0; + int ticks = GetTickCount() * 1000; + int diff; + + diff = ticks - ticks_old; + if (diff >= 0 && diff < 1000000/60) + { + while (diff >= 0 && diff < 1000000/60) + { + Sleep(1); + diff = GetTickCount()*1000 - ticks_old; + } + ticks_old = ticks + 1000000/60; + } + else + ticks_old = ticks; return 0; } @@ -103,7 +129,7 @@ int DSoundUpdate() DWORD play=0; int pos=0; - if (LoopBuffer==NULL) return -1; + if (LoopBuffer==NULL) return DSoundFake(); LoopBuffer->GetCurrentPosition(&play,NULL); pos=play>>((PicoOpt&8) ? 2 : 1); @@ -120,14 +146,3 @@ int DSoundUpdate() return 0; } -void DSoundMute() -{ - if (LoopBuffer==NULL) return; - LoopBuffer->Stop(); -} - -void DSoundUnMute() -{ - if (LoopBuffer==NULL) return; - LoopBuffer->Play(0,0,DSBPLAY_LOOPING); -} diff --git a/platform/win32/GenaDrive/Direct.cpp b/platform/win32/GenaDrive/Direct.cpp index 07e87476..a726acba 100644 --- a/platform/win32/GenaDrive/Direct.cpp +++ b/platform/win32/GenaDrive/Direct.cpp @@ -1,5 +1,6 @@ #include "app.h" +#ifdef USE_D3D // d3d static IDirect3D8 *Direct3D=NULL; IDirect3DDevice8 *Device=NULL; @@ -16,6 +17,7 @@ struct CustomVertex #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) static CustomVertex VertexList[4]; +#endif // ddraw #include @@ -144,7 +146,7 @@ static int DirectClearDDraw(unsigned int colour) static int DirectPresentDDraw() { - int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); + int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, &EmuScreenRect, DDBLT_WAIT, NULL); if (ret) { LOGFAIL(); return 1; } return 0; } @@ -154,6 +156,7 @@ static int DirectPresentDDraw() int DirectInit() { +#if USE_D3D D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE mode; int i,u,ret=0; @@ -242,14 +245,14 @@ fail0: RELEASE(Direct3D) // error("Failed to use Direct3D, trying DirectDraw.."); - +#endif // try DirectDraw return DirectDrawInit(); } void DirectExit() { - //FontExit(); +#ifdef USE_D3D TexScreenExit(); // d3d @@ -257,11 +260,35 @@ void DirectExit() RELEASE(DirectBack) RELEASE(Device) RELEASE(Direct3D) - +#endif DirectExitDDraw(); } +int DirectClear(unsigned int colour) +{ +#ifdef USE_D3D + if (Device != NULL) { + Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0); + return 0; + } +#endif + return DirectClearDDraw(colour); +} + +int DirectPresent() +{ +#ifdef USE_D3D + if (Device != NULL) { + Device->Present(NULL,NULL,NULL,NULL); + return 0; + } +#endif + + return DirectPresentDDraw(); +} + +#ifdef USE_D3D static int MakeVertexList() { struct CustomVertex *vert=NULL,*pv=NULL; @@ -303,24 +330,6 @@ static int MakeVertexList() return 0; } -int DirectClear(unsigned int colour) -{ - if (Device == NULL) - return DirectClearDDraw(colour); - - Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0); - return 0; -} - -int DirectPresent() -{ - if (Device == NULL) - return DirectPresentDDraw(); - - Device->Present(NULL,NULL,NULL,NULL); - return 0; -} - static int SetupMatrices() { D3DXVECTOR3 eye ( 0.0f, 0.0f, 0.0f ); @@ -387,3 +396,10 @@ int DirectScreen() return 0; } +#else +int DirectScreen() +{ + return DirectScreenDDraw(); +} +#endif + diff --git a/platform/win32/GenaDrive/Emu.cpp b/platform/win32/GenaDrive/Emu.cpp index 75f6f698..b7a019c5 100644 --- a/platform/win32/GenaDrive/Emu.cpp +++ b/platform/win32/GenaDrive/Emu.cpp @@ -3,6 +3,8 @@ unsigned short *EmuScreen=NULL; int EmuWidth=320,EmuHeight=224; +RECT EmuScreenRect = { 0, 0, 320, 224 }; + static int EmuScan(unsigned int num, void *sdata); unsigned char *PicoDraw2FB = NULL; @@ -38,16 +40,16 @@ void EmuExit() // Megadrive scanline callback: static int EmuScan(unsigned int num, void *sdata) { - unsigned short *pd=NULL,*end=NULL; + unsigned short *pd=NULL; unsigned short *ps=NULL; if (num>=(unsigned int)EmuHeight) return 0; // Copy scanline to screen buffer: - pd=EmuScreen+(num<<8)+(num<<6); end=pd+320; + pd=EmuScreen+(num<<8)+(num<<6); ps=(unsigned short *)sdata; - do { *pd++=*ps++; } while (pd>8; - - while (pos-height && y>8)) colour=0x00ff40; - - FontSetColour(colour); - FontText(text,x,y); - } - - y+=height; - pos+=strlen(name)+1; // Skip to next string - index++; - } - - return 0; -} - -int FileMenu::scroll(int amount) -{ - int max=0; - - choiceFocus+=amount; - - max=nameCount<<8; - if (choiceFocus<0) choiceFocus=0; - if (choiceFocus>=max) choiceFocus=max-1; - - return 0; -} - -// Get the currently highlighted filename -int FileMenu::getFilePath(char *path) -{ - int focus=0; - int pos=0; - char *name=NULL; - - // Find where the user is focused - focus=choiceFocus>>8; - pos=nameOffset(focus); if (pos<0) return 1; - - name=nameList+pos; - - // Return path and name: - sprintf(path,"%.128s\\%.128s",currentPath,name); - return 0; -} - -// ---------------------------------------------------------------------- -int FileMenu::nameReset() -{ - free(nameList); nameList=NULL; - nameSize=nameMax=nameCount=0; - - return 0; -} - -int FileMenu::nameFind(char *path) -{ - HANDLE find=NULL; - WIN32_FIND_DATA wfd; - - memset(&wfd,0,sizeof(wfd)); - - find=FindFirstFile(path,&wfd); - if (find==INVALID_HANDLE_VALUE) return 1; - - for (;;) - { - nameAdd(wfd.cFileName); // Add the name to the list - - if (FindNextFile(find,&wfd)==0) break; - } - - FindClose(find); - return 0; -} - -int FileMenu::nameAdd(char *entry) -{ - int len=0; - - len=strlen(entry); - // Check we have room for this entry: - if (nameSize+len+1>nameMax) nameSizeUp(); - if (nameSize+len+1>nameMax) return 1; - - // Add entry with zero at the end: - memcpy(nameList+nameSize,entry,len); - nameSize+=len+1; - nameCount++; - - return 0; -} - -int FileMenu::nameSizeUp() -{ - - void *mem=NULL; - int add=256; - - // Allocate more memory for the list: - mem=realloc(nameList,nameMax+add); if (mem==NULL) return 1; - - nameList=(char *)mem; - memset(nameList+nameMax,0,add); // Blank new memory - nameMax+=add; - return 0; -} - -int FileMenu::nameOffset(int index) -{ - int pos=0,i=0; - - while (pos -static XFONT *Font=NULL; - -int FontInit() -{ - XFONT_OpenDefaultFont(&Font); if (Font==NULL) return 1; - - return 0; -} - -void FontExit() -{ -} - -int FontSetColour(unsigned int colour) -{ - Font->SetTextColor(colour); - return 0; -} - -int FontText(WCHAR *text,int dx,int dy) -{ - if (Font==NULL || DirectBack==NULL) return 1; - - Font->TextOut(DirectBack,text,~0U,dx,dy); - return 0; -} - -#endif - - -// ---------------------------------------------------------------------------------- -#ifndef _XBOX - -static ID3DXFont *Font=NULL; -static unsigned int FontColour=0; - -int FontInit() -{ - LOGFONT lf; - - memset(&lf,0,sizeof(lf)); - strcpy(lf.lfFaceName,"Arial"); - lf.lfHeight=24; - D3DXCreateFontIndirect(Device,&lf,&Font); - - return 0; -} - -void FontExit() -{ - RELEASE(Font); -} - -int FontSetColour(unsigned int colour) -{ - FontColour=0xff000000|colour; - return 0; -} - -int FontText(WCHAR *text,int dx,int dy) -{ - RECT rect={0,0,0,0}; - - if (Font==NULL || DirectBack==NULL) return 1; - - Font->Begin(); - rect.left=dx; - rect.top=dy; - rect.right=MainWidth; - rect.bottom=MainHeight; - - Font->DrawTextW(text,-1,&rect,DT_LEFT,FontColour); - Font->End(); - - return 0; -} - -#endif diff --git a/platform/win32/GenaDrive/GenaDrive.dsp b/platform/win32/GenaDrive/GenaDrive.dsp deleted file mode 100644 index 85db328c..00000000 --- a/platform/win32/GenaDrive/GenaDrive.dsp +++ /dev/null @@ -1,308 +0,0 @@ -# Microsoft Developer Studio Project File - Name="GenaDrive" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=GenaDrive - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "GenaDrive.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "GenaDrive.mak" CFG="GenaDrive - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "GenaDrive - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "GenaDrive - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "GenaDrive - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\..\..\Pico" /I ".\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "EMU_M68K" /D "_USE_MZ80" /FR /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x809 /d "NDEBUG" -# ADD RSC /l 0x809 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 gdi32.lib user32.lib advapi32.lib d3d8.lib d3dx8.lib dsound.lib comdlg32.lib /nologo /subsystem:windows /machine:I386 - -!ELSEIF "$(CFG)" == "GenaDrive - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\..\..\Pico" /I ".\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "DEBUG" /D "EMU_M68K" /D "_USE_MZ80" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x809 /d "_DEBUG" -# ADD RSC /l 0x809 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 user32.lib gdi32.lib advapi32.lib d3d8.lib d3dx8.lib dsound.lib comdlg32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "GenaDrive - Win32 Release" -# Name "GenaDrive - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\Emu.cpp -# End Source File -# Begin Source File - -SOURCE=.\GenaDrive.txt -# End Source File -# Begin Source File - -SOURCE=.\Input.cpp -# End Source File -# Begin Source File - -SOURCE=.\LightCal.cpp -# End Source File -# Begin Source File - -SOURCE=.\Loop.cpp -# End Source File -# Begin Source File - -SOURCE=.\Main.cpp -# End Source File -# Begin Source File - -SOURCE=.\Makefile -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\app.h -# End Source File -# End Group -# Begin Group "DirectX" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\Direct.cpp -# End Source File -# Begin Source File - -SOURCE=.\DSound.cpp -# End Source File -# Begin Source File - -SOURCE=.\FileMenu.cpp -# End Source File -# Begin Source File - -SOURCE=.\FileMenu.h -# End Source File -# Begin Source File - -SOURCE=.\Font.cpp -# End Source File -# Begin Source File - -SOURCE=.\TexScreen.cpp -# End Source File -# End Group -# Begin Group "Pico" - -# PROP Default_Filter "" -# Begin Group "sound" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\Pico\sound\driver.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\sn76496.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\sn76496.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\sound.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\sound.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\ym2612.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\sound\ym2612.h -# End Source File -# End Group -# Begin Source File - -SOURCE=..\..\..\Pico\Area.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Cart.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Draw.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Draw2.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Memory.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Misc.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Pico.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Pico.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\PicoInt.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Sek.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\Utils.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\Pico\VideoPort.c -# End Source File -# End Group -# Begin Group "cores" - -# PROP Default_Filter "" -# Begin Group "musashi" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68k.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kconf.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kcpu.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kcpu.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kdasm.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kopac.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kopdm.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kopnz.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kops.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\musashi\m68kops.h -# End Source File -# End Group -# Begin Source File - -SOURCE=..\..\..\cpu\mz80\mz80.obj -# End Source File -# Begin Source File - -SOURCE=..\..\..\cpu\a68k\a68k.obj - -!IF "$(CFG)" == "GenaDrive - Win32 Release" - -!ELSEIF "$(CFG)" == "GenaDrive - Win32 Debug" - -# PROP Exclude_From_Build 1 - -!ENDIF - -# End Source File -# End Group -# End Target -# End Project diff --git a/platform/win32/GenaDrive/GenaDrive.txt b/platform/win32/GenaDrive/GenaDrive.txt deleted file mode 100644 index ad0d8fc4..00000000 --- a/platform/win32/GenaDrive/GenaDrive.txt +++ /dev/null @@ -1,118 +0,0 @@ - -__________________________________________________________________________________________ - - ______ _______ __ _ _______ ______ ______ _____ _ _ _______ - | ____ |______ | \ | |_____| | \ |_____/ | \ / |______ - |_____| |______ | \_| | | |_____/ | \_ __|__ \/ |______ - - G E N A D R I V E - - - GenaDrive is a Genesis / MegaDrive emulator for the XBox. - - - #include - I do not accept responsibility for any effects, adverse or otherwise, that - this code may have on you, your computer, your sanity, your dog... etc. - You can use this software freely as long as you don't use it commercially. -__________________________________________________________________________________________ - - Weird Name? - -GenaDrive is a porn-star emulator, based on legendary porn star Jenna Ja... no not really. -GenaDrive (one word, capital G, capital D), is pronounced "Jen-A-Drive". - -(Think 'MegaDrive' but with 'Gen' instead of 'Meg'.) - -__________________________________________________________________________________________ - -What's New - - v0.004 - * Merged the PicoDrive and GenaDrive 'Pico' directories, with ifdefs for - EMU_C68K (Cyclone) and EMU_A68K. - - v0.003 - Added .SMD support - - v0.002 - First release - -__________________________________________________________________________________________ - - Okay but what is it? - - GenaDrive is a partially-complete MegaDrive emulator for the XBox. It emulates the - hardware of the MegaDrive console on the XBox. Basically, it makes your XBox act like - a MegaDrive. - - It actually uses the same code-base as my Pocket PC 'PicoDrive' emulator, but instead - of an ARM-optimized 68000 emulator it uses (naturally) an Intel-optimized one - A68K - from the MAME project. - -__________________________________________________________________________________________ - - How to use - - Put the emulator (default.xbe) in a directory such as e:\Emulators\GenaDrive\ - Make sure there is a directory e:\Emulators\GenaDrive\Roms - Put your rom images there. - - Run GenaDrive. - If it doesn't work, try running 'xbepatch' on the XBE first to convert it to a retail XBE. - - This is minimal zip support, though there must be no other files in each zip. - - Run the emulator and you will see a list of rom images. Push up/down and press A - to select a rom image. - Click the Right thumbstick in to pause and return to the menu. - - To exit the emulator hold L and R and press Black, or press Back+Start. - - This is just an early version so there's quite a few things missing or not up to scratch, - e.g. sound, z80, joypad 2 - -__________________________________________________________________________________________ - -What's currently emulated: - - 68000 : Yes - - VDP - Scroll A/B : Yes - Line Scroll : Yes - Sprites : Sort of - Window : Not yet - H-Ints/HV Counter : Not yet - - Sound: - Z80 : Not yet (faked) - YM2151 : Not yet - PSG : Not yet - - Compatibility: ~50% ? - -__________________________________________________________________________________________ - -Web page and contact info: - - I (Dave) can be reached at the usual spot, my web-page is: - - http://www.finalburn.com/ - - And my e-mail address is as follows, just change the (atsymbol) to @ - - dev(atsymbol)finalburn.com - - NB - I had to shut down the 'dave' mailbox so it's now 'dev', because the 'dave' - e-mail address was printed everywhere and spambots logged it and spammed it to death! :P - So if you must quote it, please quote it as above... or better yet just link to my webpage. - -Thanks to: - Mike Coates and Darren Olafson once again for A68K - Sam for getting me set up on my XBox! - Charles Macdonald, for researching just about every console ever - MameDev+FBA, for keeping on going and going and going - XPort for loads of great XBox emulators - - ...and anyone else I forgot! - -__________________________________________________________________________________________ diff --git a/platform/win32/GenaDrive/Input.cpp b/platform/win32/GenaDrive/Input.cpp index 77d43586..92abe2b0 100644 --- a/platform/win32/GenaDrive/Input.cpp +++ b/platform/win32/GenaDrive/Input.cpp @@ -91,56 +91,17 @@ static int DeviceRead() if (GetAsyncKeyState('F')) Inp.button[14]=0xff; static int sblobked = 0; - if(!sblobked && GetAsyncKeyState(VK_F6)) { - FILE *PmovFile; - romname[strlen(romname)-3] = 0; - strcat(romname, "mds"); - PmovFile = fopen(romname, "wb"); - if(PmovFile) { - PmovState(5, PmovFile); - fclose(PmovFile); - } - sblobked = 1; - } - else if(!sblobked && GetAsyncKeyState(VK_F9)) { - FILE *PmovFile; - romname[strlen(romname)-3] = 0; - strcat(romname, "mds"); - PmovFile = fopen(romname, "rb"); - if(PmovFile) { - PmovState(6, PmovFile); - fclose(PmovFile); - } - sblobked = 1; - } - else if(!sblobked && GetAsyncKeyState(VK_TAB)) { - PicoReset(0); - sblobked = 1; + if (!sblobked && GetAsyncKeyState(VK_TAB)) { + PicoReset(0); + sblobked = 1; } - else if(!sblobked && GetAsyncKeyState(VK_ESCAPE)) + else if (!sblobked && GetAsyncKeyState(VK_ESCAPE)) { - unsigned char *rom_data; - unsigned int rom_size; - DSoundMute(); - pm_file *rom = 0; - OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); - of.lStructSize = sizeof(OPENFILENAME); - of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0"; - of.lpstrFile = romname; romname[0] = 0; - of.nMaxFile = MAX_PATH; - of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - GetOpenFileName(&of); - rom = pm_open(romname); - DSoundUnMute(); - if(!rom) return 1; - PicoCartLoad(rom, &rom_data, &rom_size); - PicoCartInsert(rom_data, rom_size); - pm_close(rom); + PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 1000, 0); sblobked = 1; } else - sblobked = GetAsyncKeyState(VK_F6) | GetAsyncKeyState(VK_F9) | - GetAsyncKeyState(VK_TAB) | GetAsyncKeyState(VK_ESCAPE); + sblobked = GetAsyncKeyState(VK_TAB) | GetAsyncKeyState(VK_ESCAPE); return 0; } diff --git a/platform/win32/GenaDrive/LightCal.cpp b/platform/win32/GenaDrive/LightCal.cpp deleted file mode 100644 index 0d697d94..00000000 --- a/platform/win32/GenaDrive/LightCal.cpp +++ /dev/null @@ -1,102 +0,0 @@ - -#include "app.h" - -struct Target -{ - int sx,sy; // Onscreen coordinates - int dx,dy; // Device values -}; - -struct Target Targ[2]= -{ - {0,0, 0,0}, - {0,0, 0,0} -}; -static int LightState=0; - -struct Calib -{ - float ax,bx; - float ay,by; -}; -static struct Calib Cal={0.0f,0.0f,0.0f,0.0f}; - -int LightCalReset() -{ - LightState=0; - - memset(Targ,0,sizeof(Targ)); - Targ[0].sx=MainWidth >>1; - Targ[0].sy=MainHeight>>1; - Targ[1].sy=Targ[0].sy-MainHeight*61/160; - Targ[1].sx=Targ[0].sx-MainWidth *61/160; - return 0; -} - -int LightCalUpdate() -{ - int i=0; - struct Target *pt=NULL; - - if (Inp.held[4]==1) LoopMode=3; - - if (Inp.held[8]==1) - { - i=LightState&1; - pt=Targ+i; - - pt->dx=Inp.axis[0]; - pt->dy=Inp.axis[1]; - - if (i==1) - { - int num=0,den=0; - - // rx= a + b*x - work out a and b: - num=Targ[0].sx-Targ[1].sx; - den=Targ[0].dx-Targ[1].dx; - if (den) Cal.bx=(float)num/(float)den; - Cal.ax=(float)Targ[0].sx-Cal.bx*(float)Targ[0].dx; - - num=Targ[0].sy-Targ[1].sy; - den=Targ[0].dy-Targ[1].dy; - if (den) Cal.by=(float)num/(float)den; - Cal.ay=(float)Targ[0].sy-Cal.by*(float)Targ[0].dy; - } - - LightState++; - } - - return 0; -} - -int LightCalRender() -{ - int i=0; - struct Target *pt=NULL; - float fx=0.0f,fy=0.0f; - - DirectClear(0xffffff); - - WCHAR text[80]={0}; - wsprintfW(text,L"LightGun Calibration"); - FontSetColour(0x0000ff); - FontText(text,240,48); - - wsprintfW(text,L"Start to quit, B to call InputLightCal"); - FontSetColour(0x004000); - FontText(text,64,120); - - i=LightState&1; - pt=Targ+i; - FontSetColour(0); - FontText(L"X", pt->sx-8, pt->sy-12); - - fx=Cal.ax+Cal.bx*(float)Inp.axis[0]; - fy=Cal.ay+Cal.by*(float)Inp.axis[1]; - - FontSetColour(0xff0000); - FontText(L"+", (int)fx-8,(int)fy-12); - - return 0; -} diff --git a/platform/win32/GenaDrive/Loop.cpp b/platform/win32/GenaDrive/Loop.cpp index b19539af..2b3704da 100644 --- a/platform/win32/GenaDrive/Loop.cpp +++ b/platform/win32/GenaDrive/Loop.cpp @@ -1,7 +1,7 @@ #include "app.h" //#include "FileMenu.h" -char LoopQuit=0; +char LoopQuit=0,LoopWait=0,LoopWaiting=0; static FILE *DebugFile=NULL; int LoopMode=0; static void UpdateSound(int len); @@ -24,10 +24,10 @@ int LoopInit() //DSoundInit(); ret=EmuInit(); if (ret) return 1; - //FileMenu.init(); LoopMode=8; PicoWriteSound = UpdateSound; + PicoAutoRgnOrder = 0x184; return 0; } @@ -38,9 +38,7 @@ void LoopExit() { dprintf(debugString()); - //FileMenu.exit(); EmuExit(); - DSoundExit(); PsndLen=0; InputExit(); DirectExit(); @@ -50,88 +48,28 @@ void LoopExit() // ---------------------------------------------------------------- -static int DoGame() +static void UpdateSound(int len) { - EmuFrame(); - - if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu - - return 0; + while (DSoundUpdate() > 0) { Sleep(1); } + //while (DSoundUpdate()== 0) { } } -// ---------------------------------------------------------------- -/* -static int MenuUpdate() +static void PostProcess() { - int delta=0; - - if (Inp.repeat[0]) delta-=0x100; - if (Inp.repeat[1]) delta+=0x100; - - if (Inp.button[14]>30) delta-=Inp.button[14]-30; - if (Inp.button[15]>30) delta+=Inp.button[15]-30; - - if (delta) FileMenu.scroll(delta); - - if (Inp.held[8]==1 || Inp.held[10]==1 || Inp.held[4]==1) // A, X or Start + static int lock_to_1_1_prev = 0, is_40_prev = 0; + int is_40 = PicoGetStat(PS_40_CELL); + if (lock_to_1_1) { - //RomFree(); - //FileMenu.getFilePath(RomName); - //RomLoad(); - //LoopMode=8; // Go to game + if (is_40 != is_40_prev || !lock_to_1_1_prev) + PostMessage(FrameWnd, WM_COMMAND, 0x20000 | (is_40 ? 1100 : 1101), 0); } - - if (Inp.held[7]==1) LoopMode=8; // Right thumb = Toggle Menu - - return 0; -} - -static int MenuRender() -{ - WCHAR text[80]={0}; - wsprintfW(text,L"%.40S v%x.%.3x",AppName,PicoVer>>12,PicoVer&0xfff); - FontSetColour(0x60c0ff); - FontText(text,64,48); - - FileMenu.render(); - - return 0; -} -*/ - -// ---------------------------------------------------------------- - -static int ModeUpdate() -{ - if (Inp.held[14] && Inp.held[15] && Inp.held[12]==1) LoopQuit=1; // L+R+black to quit: - if (Inp.button[4]>30 && Inp.button[5]>30) LoopQuit=1; // Start and back to quit - - if (LoopMode==8) { DoGame(); return 0; } - -// if (DSoundNext) memset(DSoundNext,0,PsndLen<<2); - -// if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; } -// if (LoopMode==3) { MenuUpdate(); return 0; } -// if (LoopMode==4) { LightCalUpdate(); return 0; } - - LoopMode=2; // Unknown mode, go to rom menu - return 0; -} - - -static int ModeRender() -{ - DirectScreen(); -// if (LoopMode==3) MenuRender(); -// if (LoopMode==4) LightCalRender(); - - return 0; -} - -static void UpdateSound(int len) -{ - while (DSoundUpdate() > 0) { Sleep(1); } - while (DSoundUpdate()== 0) { } + if (is_40 != is_40_prev) + { + EmuScreenRect.left = is_40 ? 0 : 32; + EmuScreenRect.right = is_40 ? 320 : 256+32; + } + lock_to_1_1_prev = lock_to_1_1; + is_40_prev = is_40; } int LoopCode() @@ -140,14 +78,23 @@ int LoopCode() // Main loop: while (!LoopQuit) { + if (LoopWait) + { + DSoundExit(); + while (!LoopQuit && LoopWait) { LoopWaiting=1; Sleep(100); } + if (LoopQuit) break; + DSoundInit(); + } InputUpdate(); DirectClear(0); - ModeUpdate(); - ModeRender(); + EmuFrame(); + PostProcess(); + DirectScreen(); DirectPresent(); // UpdateSound(); } + DSoundExit(); return 0; } diff --git a/platform/win32/GenaDrive/Main.cpp b/platform/win32/GenaDrive/Main.cpp index f5f41cc3..4fbbf029 100644 --- a/platform/win32/GenaDrive/Main.cpp +++ b/platform/win32/GenaDrive/Main.cpp @@ -3,22 +3,130 @@ #include #include -char *romname; +char *romname=NULL; HWND FrameWnd=NULL; RECT FrameRectMy; +int lock_to_1_1 = 1; int MainWidth=720,MainHeight=480; +static HMENU mdisplay = 0; + +static void UpdateRect() +{ + WINDOWINFO wi; + memset(&wi, 0, sizeof(wi)); + wi.cbSize = sizeof(wi); + GetWindowInfo(FrameWnd, &wi); + FrameRectMy = wi.rcClient; +} + +static void LoadROM(const char *cmdpath) +{ + static char rompath[MAX_PATH] = { 0, }; + static unsigned char *rom_data = NULL; + unsigned char *rom_data_new = NULL; + unsigned int rom_size = 0; + pm_file *rom = NULL; + int oldwait=LoopWait; + int i, ret; + + if (cmdpath) { + strcpy(rompath, cmdpath + (cmdpath[0] == '\"' ? 1 : 0)); + if (rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0; + if (strlen(rompath) > 4) rom = pm_open(rompath); + } + + if (!rom) { + OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); + of.lStructSize = sizeof(OPENFILENAME); + of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0"; + of.lpstrFile = rompath; rompath[0] = 0; + of.nMaxFile = MAX_PATH; + of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + of.hwndOwner = FrameWnd; + if (!GetOpenFileName(&of)) return; + rom = pm_open(rompath); + if (!rom) { error("failed to open ROM"); return; } + } + + ret=PicoCartLoad(rom, &rom_data_new, &rom_size); + pm_close(rom); + if (ret) { + error("failed to load ROM"); + return; + } + + // halt the work thread.. + // just a hack, should've used proper sync. primitives here, but who will use this emu anyway.. + LoopWaiting=0; + LoopWait=1; + for (i = 0; LoopWaiting == 0 && i < 10; i++) Sleep(100); + + PicoCartInsert(rom_data_new, rom_size); + + if (rom_data) free(rom_data); + rom_data = rom_data_new; + romname = rompath; + LoopWait=0; +} + +static int rect_widths[4] = { 320, 256, 640, 512 }; +static int rect_heights[4] = { 224, 224, 448, 448 }; + // Window proc for the frame window: static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { + int i; switch (msg) { case WM_CLOSE: PostQuitMessage(0); return 0; case WM_DESTROY: FrameWnd=NULL; break; // Blank handle case WM_SIZE: case WM_MOVE: - case WM_SIZING: GetWindowRect(hwnd, &FrameRectMy); break; + case WM_SIZING: UpdateRect(); break; + case WM_COMMAND: + switch (LOWORD(wparam)) + { + case 1000: LoadROM(NULL); break; + case 1001: PostQuitMessage(0); return 0; + case 1100: + case 1101: + case 1102: + case 1103: + LoopWait=1; // another sync hack + for (i = 0; !LoopWaiting && i < 10; i++) Sleep(10); + FrameRectMy.right = FrameRectMy.left + rect_widths[wparam&3]; + FrameRectMy.bottom = FrameRectMy.top + rect_heights[wparam&3]; + AdjustWindowRect(&FrameRectMy, WS_OVERLAPPEDWINDOW, 1); + MoveWindow(hwnd, FrameRectMy.left, FrameRectMy.top, + FrameRectMy.right-FrameRectMy.left, FrameRectMy.bottom-FrameRectMy.top, 1); + UpdateRect(); + if (HIWORD(wparam) == 0) { // locally sent + lock_to_1_1=0; + CheckMenuItem(mdisplay, 1104, MF_UNCHECKED); + } + LoopWait=0; + return 0; + case 1104: + lock_to_1_1=!lock_to_1_1; + CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED); + return 0; + case 1200: break; + case 1300: + MessageBox(FrameWnd, "PicoDrive v" VERSION " (c) notaz, 2006-2008\n" + "SVP demo edition\n\n" + "Credits:\n" + "fDave: base code of PicoDrive, GenaDrive (the frontend)\n" + "Chui: Fame/C\n" + "NJ: CZ80\n" + "MAME devs: YM2612 and SN76496 cores\n" + "Stéphane Dallongeville: Gens code, base of Fame/C (C68K), CZ80\n" + "Tasco Deluxe: SVP RE work\n", + "About", 0); + return 0; + } + break; } return DefWindowProc(hwnd,msg,wparam,lparam); @@ -28,6 +136,7 @@ static int FrameInit() { WNDCLASS wc; RECT rect={0,0,0,0}; + HMENU mmain, mfile; int style=0; int left=0,top=0,width=0,height=0; @@ -46,7 +155,7 @@ static int FrameInit() // Adjust size of windows based on borders: style=WS_OVERLAPPEDWINDOW; - AdjustWindowRect(&rect,style,0); + AdjustWindowRect(&rect,style,1); width =rect.right-rect.left; height=rect.bottom-rect.top; @@ -58,13 +167,30 @@ static int FrameInit() left-=width; left>>=1; top-=height; top>>=1; + // Create menu: + mfile = CreateMenu(); + InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1000, "&Load ROM"); + InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1001, "E&xit"); + mdisplay = CreateMenu(); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1100, "320x224"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1101, "256x224"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1102, "640x448"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1103, "512x448"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1104, "Lock to 1:1"); + mmain = CreateMenu(); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mfile, "&File"); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mdisplay, "&Display"); +// InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, 1200, "&Config"); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, 1300, "&About"); + // Create the window: FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE, - left,top,width,height,NULL,NULL,NULL,NULL); + left,top,width,height,NULL,mmain,NULL,NULL); + CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED); ShowWindow(FrameWnd, SW_NORMAL); UpdateWindow(FrameWnd); - GetWindowRect(FrameWnd, &FrameRectMy); + UpdateRect(); return 0; } @@ -83,50 +209,17 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) int ret=0; DWORD tid=0; HANDLE thread=NULL; - unsigned char *rom_data = 0; - unsigned int rom_size = 0; - - static char rompath[MAX_PATH] = { 0, }; - pm_file *rom = NULL; FrameInit(); ret=LoopInit(); if (ret) goto end0; - // notaz: load rom - strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0)); - if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0; - - if(strlen(rompath) > 4) rom = pm_open(rompath); - if(!rom) { - OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); - of.lStructSize = sizeof(OPENFILENAME); - of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0"; - of.lpstrFile = rompath; rompath[0] = 0; - of.nMaxFile = MAX_PATH; - of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - if(!GetOpenFileName(&of)) goto end0; - rom = pm_open(rompath); - if(!rom) goto end0; - } - romname = rompath; - - ret=PicoCartLoad(rom, &rom_data, &rom_size); - pm_close(rom); - if (ret) { - error("failed to load ROM"); - goto end0; - } - - PicoCartInsert(rom_data, rom_size); - - // only now we got the mode (pal/ntsc), so init sound now - ret=DSoundInit(); - if (ret) error("Failed to init DirectSound"); // warning - // Make another thread to run LoopCode(): LoopQuit=0; + LoopWait=1; // wait for ROM to be loaded thread=CreateThread(NULL,0,ThreadCode,NULL,0,&tid); + LoadROM(cmdline); + // Main window loop: for (;;) { @@ -145,8 +238,6 @@ end0: LoopExit(); DestroyWindow(FrameWnd); - free(rom_data); - _CrtDumpMemoryLeaks(); return 0; } diff --git a/platform/win32/GenaDrive/Makefile.vc b/platform/win32/GenaDrive/Makefile.vc index 3a3b44fe..54369a5b 100644 --- a/platform/win32/GenaDrive/Makefile.vc +++ b/platform/win32/GenaDrive/Makefile.vc @@ -10,10 +10,15 @@ CFLAGS=$(CFLAGS) /DEMU_F68K CFLAGS=$(CFLAGS) /D_USE_CZ80 +# debug +#CFLAGS=$(CFLAGS) /Gi + +#LDFLAGS=$(LDFLAGS) /DEBUG + # emu -OBJ = Emu.obj Input.obj Main.obj Direct.obj DSound.obj Loop.obj TexScreen.obj +OBJ = Emu.obj Input.obj Main.obj Direct.obj DSound.obj Loop.obj -# not used: Rom.obj Font.obj FileMenu.obj LightCal.obj +# TexScreen.obj # common #OBJS += platform\common\emu.obj platform\common\menu.obj platform\common\fonts.obj @@ -51,7 +56,9 @@ OBJ = $(OBJ) $(R)cpu\cz80\cz80.obj ALL : PicoDrive.exe PicoDrive.exe : $(OBJ) - link.exe $(LDFLAGS) $(OBJ) gdi32.lib user32.lib advapi32.lib d3d8.lib d3dx8.lib dsound.lib comdlg32.lib ddraw.lib dxguid.lib + link.exe $(LDFLAGS) $(OBJ) gdi32.lib user32.lib advapi32.lib dsound.lib comdlg32.lib ddraw.lib dxguid.lib + +# d3d8.lib d3dx8.lib clean: -del $(OBJ) PicoDrive.exe diff --git a/platform/win32/GenaDrive/Rom.cpp b/platform/win32/GenaDrive/Rom.cpp deleted file mode 100644 index 9192dcf9..00000000 --- a/platform/win32/GenaDrive/Rom.cpp +++ /dev/null @@ -1,143 +0,0 @@ - -#include "app.h" -#include "Unzip.h" - -unsigned char *RomData=NULL; -int RomLen=0; -char RomName[260]=""; - - -static int Byteswap(unsigned char *data,int len) -{ - int i=0; - - if (len<2) return 1; // Too short - - do - { - unsigned short *pd=(unsigned short *)(data+i); - int word=*pd; // Get word - - word=(word<<8)|(word>>8); // Byteswap it - *pd=(unsigned short)word; // Put word - i+=2; - } - while (i+2<=len); - - return 0; -} - -// Interleve a 16k block and byteswap -static int InterleveBlock(unsigned char *dest,unsigned char *src) -{ - int i=0; - for (i=0;i<0x2000;i++) dest[(i<<1) ]=src[ i]; // Odd - for (i=0;i<0x2000;i++) dest[(i<<1)+1]=src[0x2000+i]; // Even - return 0; -} - -// Decode a SMD file -static int DecodeSmd(unsigned char *data,int len) -{ - unsigned char *temp=NULL; - int i=0; - - temp=(unsigned char *)malloc(0x4000); - if (temp==NULL) return 1; - memset(temp,0,0x4000); - - // Interleve each 16k block and shift down by 0x200: - for (i=0; i+0x4200<=len; i+=0x4000) - { - InterleveBlock(temp,data+0x200+i); // Interleve 16k to temporary buffer - memcpy(data+i,temp,0x4000); // Copy back in - } - - free(temp); - return 0; -} - -int RomLoad() -{ - FILE *file=NULL; - char *name=NULL; - int nameLen=0; - int fileLen=0,space=0; - Unzip unzip; - - name=RomName; - - file=fopen(name,"rb"); if (file==NULL) return 1; - - nameLen=strlen(name); - if (stricmp(name+nameLen-4,".zip")==0) unzip.file=file; // Open as zip file - - if (unzip.file) - { - int ret=0; - - ret=unzip.fileOpen(); // Get first entry - if (ret==0) - { - fileLen=unzip.dataLen; // Length of file - // Switch to using the name in the zip file: - name=unzip.name; nameLen=strlen(name); - } - else - { - unzip.file=NULL; - } - - } - else - { - // Find out the length of the file: - fseek(file,0,SEEK_END); fileLen=ftell(file); - fseek(file,0,SEEK_SET); - } - - // Allocate space for it: - space=(fileLen+0x3fff)&~0x3fff; - - RomData=(unsigned char *)malloc(space); - if (RomData==NULL) { fclose(file); return 1; } - memset(RomData,0,space); - - // Read in file: - if (unzip.file) unzip.fileDecode(RomData); - else fread(RomData,1,fileLen,file); - - unzip.fileClose(); - - fclose(file); - unzip.file=file=NULL; - - RomLen=fileLen; - - // Check for SMD: - if ((fileLen&0x3fff)==0x200) - { - // Decode and byteswap: - DecodeSmd(RomData,RomLen); - RomLen-=0x200; - } - else - { - // Just byteswap: - Byteswap(RomData,RomLen); - } - - PicoCartInsert(RomData,RomLen); - - return 0; -} - -void RomFree() -{ -// PicoCartInsert(NULL,0); // Unplug rom - - if (RomData) free(RomData); - RomData=NULL; RomLen=0; - memset(RomName,0,sizeof(RomName)); -} - diff --git a/platform/win32/GenaDrive/Unzip.cpp b/platform/win32/GenaDrive/Unzip.cpp deleted file mode 100644 index d152de99..00000000 --- a/platform/win32/GenaDrive/Unzip.cpp +++ /dev/null @@ -1,109 +0,0 @@ - - -#include "app.h" -#include "Unzip.h" -#include "zlib.h" - -// Decompress a 'deflate' compressed buffer -static int Inflate(unsigned char *dest,int destLen, unsigned char *src,int srcLen) -{ - z_stream stream; - - memset(&stream,0,sizeof(stream)); - - stream.next_in =src; - stream.avail_in =srcLen; - stream.next_out =dest; - stream.avail_out=destLen; - inflateInit2(&stream,-15); - inflate(&stream,Z_FINISH); - inflateEnd(&stream); - - return 0; -} - -static int Get32(unsigned char *src) -{ - return src[0] | (src[1]<<8) | (src[2]<<16) | (src[3]<<24); -} - -// -------------------------------------------------------------- -Unzip::Unzip() -{ - memset(this,0,sizeof(*this)); -} - -int Unzip::gotoFirstFile() -{ - headerPos=0; - return 0; -} - -int Unzip::fileOpen() -{ - int ret=0,okay=0; - - fseek(file,headerPos,SEEK_SET); - - // Read in file entry header: - ret=fread(head,1,sizeof(head),file); - if (ret!=sizeof(head)) return 1; - - // Check header: - if (head[0]=='P' && head[1]=='K' && head[2]==3 && head[3]==4) okay=1; - if (okay==0) return 1; - - // Get compressed and uncompressed sizes: - srcLen =Get32(head+0x12); - dataLen=Get32(head+0x16); - - // Get size of name and extra fields: - nameLen=Get32(head+0x1a); - extraLen=nameLen>>16; nameLen&=0xffff; - - // Read in name: - name=(char *)malloc(nameLen+1); if (name==NULL) return 1; - memset(name,0,nameLen+1); - fread(name,1,nameLen,file); - - // Find position of compressed data in the file - compPos=headerPos+sizeof(head); - compPos+=nameLen+extraLen; - - return 0; -} - -int Unzip::fileClose() -{ - free(name); name=NULL; - - // Go to next header: - headerPos=compPos+srcLen; - - srcLen=dataLen=0; - nameLen=extraLen=0; - - return 0; -} - -int Unzip::fileDecode(unsigned char *data) -{ - unsigned char *src=NULL; - - // Go to compressed data: - fseek(file,compPos,SEEK_SET); - - // Allocate memory: - src=(unsigned char *)malloc(srcLen); - if (src==NULL) { fclose(file); return 1; } - memset(src,0,srcLen); - - // Read in compressed version and decompress - fread(src,1,srcLen,file); - - Inflate(data,dataLen, src,srcLen); - - free(src); src=NULL; srcLen=0; - - return 0; -} diff --git a/platform/win32/GenaDrive/Unzip.h b/platform/win32/GenaDrive/Unzip.h deleted file mode 100644 index 8086b4b4..00000000 --- a/platform/win32/GenaDrive/Unzip.h +++ /dev/null @@ -1,23 +0,0 @@ - - -class Unzip -{ -public: - Unzip(); - FILE *file; // Zip file current open - unsigned char head[0x1e]; // Zip entry header - int dataLen; // Zip entry dest (uncompressed) size - - char *name; // Name of entry - - int gotoFirstFile(); - int fileOpen(); - int fileClose(); - int fileDecode(unsigned char *data); - -private: - int srcLen; // Zip entry source (compressed) size - int nameLen,extraLen; // Length of name field and extra fields - int headerPos; // Position of file entry header (PK... etc) - int compPos; // Position of compressed data -}; diff --git a/platform/win32/GenaDrive/app.h b/platform/win32/GenaDrive/app.h index 12a5ea99..1f0b658a 100644 --- a/platform/win32/GenaDrive/app.h +++ b/platform/win32/GenaDrive/app.h @@ -23,6 +23,7 @@ // Emu.cpp extern unsigned short *EmuScreen; extern int EmuWidth,EmuHeight; +extern RECT EmuScreenRect; int EmuInit(); void EmuExit(); int EmuRomLoad(char *name); @@ -42,13 +43,8 @@ void InputExit(); int InputUpdate(); int InputLightCal(int cx,int cy,int ux,int uy); -// LightCal.cpp -int LightCalReset(); -int LightCalUpdate(); -int LightCalRender(); - // Loop.cpp -extern char LoopQuit; +extern char LoopQuit,LoopWait,LoopWaiting; extern int LoopMode; int LoopInit(); @@ -62,15 +58,9 @@ extern char *romname; extern HWND FrameWnd; extern RECT FrameRectMy; extern int MainWidth,MainHeight; +extern int lock_to_1_1; extern void error(char *text); -// Rom.cpp -extern unsigned char *RomData; -extern int RomLen; -extern char RomName[260]; -int RomLoad(); -void RomFree(); - // -------------------------------------------- // Direct.cpp extern IDirect3DDevice8 *Device; @@ -86,15 +76,6 @@ int DSoundInit(); void DSoundExit(); int DSoundUpdate(); extern short *DSoundNext; // Buffer for next sound data to put in loop -//extern int DSoundSeg; // Seg length in samples -void DSoundMute(); -void DSoundUnMute(); - -// Font.cpp -int FontInit(); -void FontExit(); -int FontSetColour(unsigned int colour); -int FontText(WCHAR *,int,int); // TexScreen.cpp extern IDirect3DTexture8 *TexScreen; diff --git a/platform/win32/GenaDrive/readme.txt b/platform/win32/GenaDrive/readme.txt new file mode 100644 index 00000000..361df0a3 --- /dev/null +++ b/platform/win32/GenaDrive/readme.txt @@ -0,0 +1,45 @@ + +About +----- + +This is a quick windows port of PicoDrive, a Megadrive / Genesis emulator for +handheld devices. It was originally coded having ARM CPU based devices in mind +(most work was done on GP2X version), but there is also a PSP port. + +The sole purpose of this port is to demonstrate my SVP emulation code. This +makes it one of the most minimal emulators out there. If you need more +features, you will have to wait until SVP support is integrated in Kega, Gens +and the likes, as this emu was not meant to compete with them. + +For more info, visit http://notaz.gp2x.de/svp.php + + +Controls +-------- + +These are currently hardcoded, keyboard only: + +Enter: Start +Z: A +X: B +C: C +TAB: (reset) +Esc: (load ROM) +Arrows: D-pad + + +Credits +------- + +A lot of work on making SVP emulation happen was done by Tasco Deluxe, my +stuff is a continuation of his. +The original PicoDrive was written by fDave from finalburn.com + +This PicoDrive version uses bits and pieces of from other projects: + +68k: FAME/C core, by Chui and Stephane Dallongeville (as C68K). +z80: CZ80 by Stephane Dallongeville and modified by NJ. +YM2612 and SN76496 cores: MAME devs. + +Greets to all the sceners and emu authors out there! + diff --git a/platform/win32/GenaDrive/zconf.h b/platform/win32/GenaDrive/zconf.h deleted file mode 100644 index 456de063..00000000 --- a/platform/win32/GenaDrive/zconf.h +++ /dev/null @@ -1,323 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#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 deflatePrime z_deflatePrime -# define deflateParams z_deflateParams -# define deflateBound z_deflateBound -# 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 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 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__)) && !defined(WIN32) -# define WIN32 -#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 tried 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 --git a/platform/win32/GenaDrive/zlib.h b/platform/win32/GenaDrive/zlib.h deleted file mode 100644 index d24cc435..00000000 --- a/platform/win32/GenaDrive/zlib.h +++ /dev/null @@ -1,1200 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.1, November 17th, 2003 - - Copyright (C) 1995-2003 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.1" -#define ZLIB_VERNUM 0x1210 - -/* - 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 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. - - 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. - - This library does not provide any functions to write gzip files in memory. - However such functions could be easily written using zlib's deflate function, - the documentation in the gzip RFC, and the examples in gzio.c. - - 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 -#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_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 (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. - - 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). 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 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). 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 get 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). - - 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. - - 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.) 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 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 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). - - 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 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 inflateBackInit OF((z_stream FAR *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_stream FAR *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_stream FAR *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: QUICKEST -- 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 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 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)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *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 err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ -- 2.39.5