diff -BburN zlib-1.1.4/MakeHexArray.pl zlib-1.1.4-palm/MakeHexArray.pl --- zlib-1.1.4/MakeHexArray.pl 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/MakeHexArray.pl 2002-12-09 15:17:58.000000000 -0800 @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +$filename = $ARGV[0]; +$arrayname = $ARGV[1]; + + +open (INPUTFILE, "<$filename") or die "Could not open $filename"; +binmode INPUTFILE; + +$filesize = (stat(INPUTFILE))[7]; + +print "const unsigned char $arrayname" . "[$filesize] __attribute__((aligned(4)))= \n{\n"; + +$linecounter = 0; +read INPUTFILE, $filedata, 1; +printf " 0x%02x", unpack "C", $filedata; + +while (read INPUTFILE, $filedata, 1) +{ + $linecounter++; + if (12 == $linecounter) + { + $linecounter = 0; + printf ",\n 0x%02x", unpack "C", $filedata; + } else + { + printf ", 0x%02x", unpack "C", $filedata; + } +} + +print "\n};\n"; + +close (INPUTFILE); diff -BburN zlib-1.1.4/Makefile zlib-1.1.4-palm/Makefile --- zlib-1.1.4/Makefile 2002-03-11 05:58:30.000000000 -0800 +++ zlib-1.1.4-palm/Makefile 2003-01-09 18:15:20.000000000 -0800 @@ -12,11 +12,17 @@ # To install in $HOME instead of /usr/local, use: # make install prefix=$HOME -CC=cc +%.o: %.S + $(CC) $(CFLAGS) $< -c -o $@ -CFLAGS=-O +#TYPE=palmos-coff +TYPE=palmos + +CC=m68k-$(TYPE)-gcc +#For PalmOS - Leave MAX_WBITS=15 for inflate, but lower for deflate in call +CFLAGS= -O3 -DPALMOS -Wall -DNEWGCC -DASMV -I/usr/local/palmdev/sdk/Incs -I/usr/local/palmdev/sdk/Incs/Core -I/usr/local/palmdev/sdk/Incs/Core/System -I/usr/local/palmdev/sdk/Incs/Core/UI -I/usr/local/palmdev/sdk/Incs/Core/Hardware -I/usr/local/palmdev/sdk/Incs/Core/System/Unix -L/usr/lib #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-g -DDEBUG +#CFLAGS= $(CFLAGS) -g -DDEBUG #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ # -Wstrict-prototypes -Wmissing-prototypes @@ -28,20 +34,52 @@ LIBS=libz.a SHAREDLIB=libz.so -AR=ar rc -RANLIB=ranlib +AR=m68k-$(TYPE)-ar rcs +RANLIB=m68k-$(TYPE)-ranlib TAR=tar SHELL=/bin/sh -prefix = /usr/local +# ARMlet/Simulator DLL stuff + +MAKEHEXARRAY = ./MakeHexArray.pl +ARMCC = arm-elf-gcc +ARMAS = arm-elf-as +ARMLD = arm-elf-ld +ARMOBJCOPY = arm-elf-objcopy +ARMINCDIRS = -I/usr/local/arm-elf-include +ARMLIBDIRS = -L/usr/local/lib/gcc-lib/arm-elf/3.2 -L/usr/local/arm-elf-lib +ARMLIBS = -liberty -lc -lgcc +ARMZLIBFLAGS = -DMY_ZCALLOC -DNO_MEMCPY -DMAXSEG_64K -DARMLET +ARMCFLAGS = -O1 \ + -Wall -Wmissing-prototypes -Wmissing-declarations \ + -nostartfiles \ + -fno-builtin -fPIC -ffixed-r9 \ + -mpic-register=r10 -msingle-pic-base $(ARMINCDIRS) \ + -nostdlib -nostdinc \ + $(ARMZLIBFLAGS) +ARMLDFLAGS = --section-start .text=0 -Map zlib.map --script armletldscript \ + $(ARMLIBDIRS) $(ARMLIBS) +ARMOBJS = zlib_armlet.arm.o deflate.arm.o zutil.arm.o adler32.arm.o \ + inflate.arm.o infblock.arm.o inftrees.arm.o infcodes.arm.o \ + infutil.arm.o inffast.arm.o + +WINCC = i686-pc-cygwin-gcc +WINCFLAGS = -DWINDLL $(ARMZLIBFLAGS) -nostdlib -shared +WINOBJS = zlib_armlet.i686.o deflate.i686.o zutil.i686.o adler32.i686.o \ + inflate.i686.o infblock.i686.o inftrees.i686.o infcodes.i686.o \ + infutil.i686.o inffast.i686.o + +# End ARMlet stuff + +prefix = /usr/local/ exec_prefix = ${prefix} libdir = ${exec_prefix}/lib includedir = ${prefix}/include -OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ - zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o +OBJS = deflate.o zutil.o uncompr.o compress.o \ + inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o -OBJA = +OBJA = adler32.o crc32.o lmatch.o # to use the asm code: make OBJA=match.o TEST_OBJS = example.o minigzip.o @@ -58,7 +96,7 @@ contrib/minizip/[CM]*[pe] contrib/minizip/*.[ch] contrib/minizip/*.[td]?? \ contrib/delphi*/*.??? -all: example minigzip +all: SysZLib.prc zlib_armlet.dll test: all @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ @@ -70,9 +108,7 @@ echo ' *** zlib test FAILED ***'; \ fi -libz.a: $(OBJS) $(OBJA) - $(AR) $@ $(OBJS) $(OBJA) - -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 +#PalmOS System Shared Library match.o: match.S $(CPP) match.S > _match.s @@ -80,6 +116,49 @@ mv _match.o match.o rm -f _match.s +zlib.got: zlib.arm.o + $(ARMOBJCOPY) -j .got -O binary $< $@ + +zlib_armlet_got.h: zlib.got + $(MAKEHEXARRAY) $< zlib_armlet_got > $@ + +SysZLib.c: SysZLib.h zlib_armlet_got.h + +libz.a: $(OBJS) $(OBJA) + $(AR) $@ $(OBJS) $(OBJA) + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 + +libr0000.bin: SysZLib0.o SysZLib.o libz.a + m68k-$(TYPE)-gcc -nostartfiles -T text_64k -o SysZLib $^ + m68k-$(TYPE)-obj-res SysZLib + rm -f {code,pref,data}0000.SysZLib.grc + mv code0001.SysZLib.grc libr0000.bin + +tver0001.bin: + awk 'BEGIN{printf "1.1.4-1\0";}' >tver0001.bin + +SysZLib.prc: libr0000.bin tver0001.bin ARMC03E8.bin + build-prc -L SysZLib.prc "ZLib" ZLib libr0000.bin tver0001.bin ARMC03E8.bin + +# ARMlet/Simulator DLL stuff + +zlib.arm.o: $(ARMOBJS) + $(ARMLD) -e zlib_armlet_dispatch $(ARMLDFLAGS) $(ARMOBJS) -o zlib.arm.o + +ARMC03E8.bin: zlib.arm.o + $(ARMOBJCOPY) -j .text -O binary $< $@ + +zlib_armlet.dll: $(WINOBJS) + $(WINCC) -e _DllMain -shared -nostdlib -o $@ $(WINOBJS) + +%.i686.o: %.c + $(WINCC) $(WINCFLAGS) -c $< -o $@ + +%.arm.o: %.c + $(ARMCC) $(ARMCFLAGS) -c $< -o $@ + +# End ARMlet/Simulator DLL stuff + $(SHAREDLIB).$(VER): $(OBJS) $(LDSHARED) -o $@ $(OBJS) rm -f $(SHAREDLIB) $(SHAREDLIB).1 @@ -123,7 +202,8 @@ clean: rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \ - _match.s maketree + _match.s maketree *.grc SysZLib SysZLib.prc libr0000.bin \ + tver0001.bin *.got *.map *.bin *.dll zlib_armlet_got.h distclean: clean @@ -154,22 +234,3 @@ makedepend -- $(CFLAGS) -- *.[ch] # DO NOT DELETE THIS LINE -- make depend depends on it. - -adler32.o: zlib.h zconf.h -compress.o: zlib.h zconf.h -crc32.o: zlib.h zconf.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -example.o: zlib.h zconf.h -gzio.o: zutil.h zlib.h zconf.h -infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h -infcodes.o: zutil.h zlib.h zconf.h -infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h -inffast.o: infblock.h infcodes.h infutil.h inffast.h -inflate.o: zutil.h zlib.h zconf.h infblock.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h -minigzip.o: zlib.h zconf.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h -uncompr.o: zlib.h zconf.h -zutil.o: zutil.h zlib.h zconf.h diff -BburN zlib-1.1.4/PALMREAD.me zlib-1.1.4-palm/PALMREAD.me --- zlib-1.1.4/PALMREAD.me 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/PALMREAD.me 2002-10-04 18:20:28.000000000 -0700 @@ -0,0 +1,72 @@ +For more information, see the ZLib home page at: + +http://www.info-zip.org/pub/infozip/zlib/ + +Or http://www.palmos.com/devzone for information about Palm. + +1.1.4 update + +I now have integrated the 7.1 patch and use awk to create a version +file, tver0001.bin - this is merely a null terminated string with +"1.1.4-1" in it. + +WHAT IS IMPLEMENTED + +This is now implmented as a Palm System Shared library. You +technically don't need to call open and/or close (and there will be a +problem if a called program unloads the library without verifying the +open count). But you do have to Find and/or Load the library. A +ZSetup and ZTeardown shim is included in the header. See the unzip +routine in boxer (www.palmboxer.com) to see how I use it. + +Everything except gzio - mainly because filestreams aren't used much, +and I do some of this in Boxer, so it could be adapted there. + +Also some of the other internal routines (some of which are disabled +in the source) like state copy or state reset are not available. + +Some routines are now #defined when they were real routines in ZLib +(that just called the more general routine with default parameters). + +Routines have been moved from table entries to lookup routines so that +all constant tables (the only global data) could be put in the text +segment. + +zlib.h has the interface (which is used in boxer and a number of other +routines), but that file itself isn't included by SysZLib.h It also +describes the API in detail. + +It is set for m68k-palmos-gcc flavor tools with SDK 3.5, however the +makefile mods for palmos-coff or earlier Palm SDKs are fairly easy. +(Patches to automate this or for CodeWarrior are welcome). + +I tacked in the Lib reference word into the calls visible in the API. +This was mainly to make the SysZLib.S easier. + +LIMITATIONS & NOTES + +MEM_LEVEL can be up to 8 in a real system, but since you can only +allocate just under 64K using standard palm malloc routines, only up +to 6 is usable for now (requiring 32k). The NUM_BITS similarly is +limited to 13 (8K window, requires 4x or 32K). The larger the slower. +Also the compressor will be much faster with a compression level of 3. +Don't confuse Memory level, Number of Bits, and Compression level - +read the docs. + +It can Inflate anything as long as 32K (plus about 4k) is available +for buffers. + +Note that something other than Z_OK might be returned when it is not a +real error - e.g. if the stream terminates without an EOF tag. You +need to keep calling inflate/deflate until no more data is returned. + +lmatch.S isn't too much faster than a C version, but I altered the +original C file first (*scan++ works faster since it resolves to +(%aX)++, but the original uses pre instead of post increment). + +I un-unrolled the loops in adler32 and crc32, but I have fewer +instructions in my adapted versions per step, so the assembly is still +faster. + +Compression is about 5K/sec with fairly aggressive +parameters. Decompression is about 30K/sec. YMMV. diff -BburN zlib-1.1.4/PceNativeCall.h zlib-1.1.4-palm/PceNativeCall.h --- zlib-1.1.4/PceNativeCall.h 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/PceNativeCall.h 2002-12-09 15:18:14.000000000 -0800 @@ -0,0 +1,113 @@ +/****************************************************************************** + * + * Copyright (c) 2001-2002 Palm, Inc. or its subsidiaries. + * All rights reserved. + * + * File: PceNativeCall.h + * + * Release: Palm OS SDK 5.0 (111823) + * + * Description: + * Headers for native code support + * + * History: + * 11/16/01 bob Created by Bob Ebert + * + *****************************************************************************/ + +#ifndef __PCENATIVECALL_H__ +#define __PCENATIVECALL_H__ + + +#define kPceNativeWantA0 (0x10000000) +#define kPceNativeTrapNoMask (0x00000FFF) + +#define PceNativeTrapNo(sysTrapNo) (sysTrapNo & kPceNativeTrapNoMask) + + +/************************************************************ + * + * FUNCTION: Call68KFuncType + * + * DESCRIPTION: The prototype for callback entry point to + * emulated routines or OS traps, passed to + * NativeFuncType functions. + * + * PARAMETERS: emulStateP -> private to emulator, must be passed + * trapOrFunction -> if <= kPceNativeTrapNoMask, treat + * this as a trap number. Otherwise, treat + * this as a pointer to a 68K function to call. + * argsOnStackP -> pointer to memory to be copied to the + * 68K stack prior to calling the function. + * Normally contains the arguments for the 68K + * code. + * argsSizeAndwantA0 -> the number of bytes from + * argsOnStackP to actually copy to the 68K + * emulator stack. If the function or trap + * returns its result in 68K register A0 + * (when result is a pointer type), AND the + * size with kPceNativeWantA0. + * + * RESULT: returns value from 68K call, either A0 or D0 register. + * + *************************************************************/ +typedef unsigned long Call68KFuncType(const void *emulStateP, unsigned long trapOrFunction, const void *argsOnStackP, unsigned long argsSizeAndwantA0); + + +/************************************************************ + * + * FUNCTION: NativeFuncType + * + * DESCRIPTION: The prototype for native functions called + * from the 68K emulator through PceNativeCall + * + * PARAMETERS: emulStateP -> private to emulator + * userData -> pointer passed through from PceNativeCall + * call68KFuncP -> function to call back into 68K emulated + * routines or OS traps. + * + * RESULT: returns value will be passed back through PceNativeCall. + * + *************************************************************/ +typedef unsigned long NativeFuncType(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP); + + +// only define the trap if we've already got the macros that allow defining traps +// usually result: skip this part when #including this in native source + +#ifdef __CORETRAPS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/************************************************************ + * + * FUNCTION: PceNativeCall + * + * DESCRIPTION: In the ARM emulator, call the passed ARM instructions + * and send through the user data pointer and + * return the result to the 68K caller. + * + * PARAMETERS: nativeFuncP -> pointer to native function to call + * userDataP -> pointer to memory to pass through to function + * + * RESULT: returns the return value from the native function. + * + * NOTE: This trap will be unimplemented on devices that + * are not running a 68K emulator, check the device + * type before calling this function. + * + *************************************************************/ + +UInt32 PceNativeCall(NativeFuncType *nativeFuncP, void *userDataP) + SYS_TRAP(sysTrapPceNativeCall); + +#ifdef __cplusplus +} +#endif + +#endif // __CORETRAPS_H_ + +#endif // __PCENATIVECALL_H__ diff -BburN zlib-1.1.4/README.ARMlet zlib-1.1.4-palm/README.ARMlet --- zlib-1.1.4/README.ARMlet 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/README.ARMlet 2003-01-09 18:12:21.000000000 -0800 @@ -0,0 +1,16 @@ +For more information, read Tom Zerucha's PALMREAD.me document. + +I have started with Tom's Palm OS shared library port of zlib and +upgraded it to include ARM versions of the major zlib functions, +deflate and inflate. These functions will be called when SysZLib.PRC +is running on an ARM device, instead of their 68K equivalents. A +matching x86 DLL is also compiled for testing on the Simulator. I have +not modified the original SysZLib interface, besides adding some new +error codes to SysZLib.h that can be returned by zlib_open, so +existing apps that used SysZLib should still work (but run much faster +on ARM devices!). + +-Justin Clark +Cooperative Computers, Inc. +jclark@coopcomp.com + diff -BburN zlib-1.1.4/SysZLib.c zlib-1.1.4-palm/SysZLib.c --- zlib-1.1.4/SysZLib.c 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/SysZLib.c 2003-01-09 17:43:07.000000000 -0800 @@ -0,0 +1,324 @@ +/* SysZLib.c -- handle opening and closing of the SysZLib shared library, + * and branching into various versions of the ZLib functions + * + * Original version by Tom Zerucha (tz@execpc.com) 2000 + * Revisions and ARMlet support by Justin Clark (jclark@coopcomp.com) 2003 + */ + +#include +#include "PceNativeCall.h" +#include "SysZLib.h" +#include "zlib_armlet_got.h" +#include "zlib_armlet.h" +#include "endianutils.h" + + +/* Location of the SysZLib x86 DLL for the Simulator to use */ +#define SYSZLIB_DLL_NAME "zlib_armlet.dll\0zlib_armlet_dispatch" + + +/* Structure for storing all the global data that SysZLib needs */ +typedef struct SysZLibGlobalsType_s +{ + long got[sizeof(zlib_armlet_got) / sizeof(long)]; /* Adjusted GOT */ + zlib_armlet_params armlet_params; /* Struct for passing params to ARMlet */ + unsigned short refNum; /* Shared library reference number */ + short openCount; /* Number of times the library has been opened */ + MemHandle armletH; /* Handle of the ARM code resource */ + void * armletP; /* Locked pointer to the ARM code resource */ + Boolean useSimulatorDLL; /* Flag indicating we should call the x86 DLL */ + +} SysZLibGlobalsType; + + +/* =========================================================================== + * Set up globals variables if necessary, detect execution environment, and + * keep track of how many times library has been opened. + */ +Err zlib_open (UInt16 ref) +{ + UInt32 processorID; + SysZLibGlobalsType * gP; + UInt32 i; + long * old_got = (long *)zlib_armlet_got; + UInt32 paceVersion; + DmOpenRef dbref; + + /* Check if globals exist already. */ + gP = SysLibTblEntry(ref)->globalsP; + if (gP != NULL) + { + gP->openCount++; + return 0; + } + + /* Create new globals. */ + gP = MemPtrNew (sizeof(SysZLibGlobalsType)); + if (gP == NULL) + return SysZLibErrOutOfMemory; + + MemPtrSetOwner (gP, 0); + gP->openCount = 1; + gP->refNum = ref; + gP->armletH = 0; + gP->armletP = 0; + gP->useSimulatorDLL = 0; + SysLibTblEntry(ref)->globalsP = gP; + + /* Check for ARM or x86 processor. */ + if (!FtrGet(sysFtrCreator, sysFtrNumProcessorID, &processorID)) + { + if (processorID == sysFtrNumProcessorx86) + { + /* We're on x86 */ + gP->useSimulatorDLL = 1; + } + else if (sysFtrNumProcessorIsARM(processorID)) + { + /* Check for PACE. */ + if (!FtrGet('pace', 0, &paceVersion)) + { + /* Find and lock armlet resource. */ + dbref = DmOpenDatabaseByTypeCreator ('libr', 'ZLib', dmModeReadOnly); + gP->armletH = DmGetResource ('ARMC', 1000); + if (gP->armletH) + { + gP->armletP = MemHandleLock (gP->armletH); + + /* Fix the global offset table. */ + for (i = 0; i < sizeof(zlib_armlet_got) / sizeof(long); i++) + { + gP->got[i] = (long)ByteSwap32(old_got[i]) + (long)gP->armletP; + gP->got[i] = ByteSwap32(gP->got[i]); + } + + gP->armlet_params.gotP = gP->got; + } + DmCloseDatabase (dbref); + } + } + } + + return 0; +} + + +/* =========================================================================== + * Decrement open count, clean up globals if count reaches zero, return + * new open count. + */ +Err zlib_close (UInt16 ref, UInt16 *numop) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + if (gP == NULL) + return SysZLibErrNotOpen; + + gP->openCount--; + *numop = gP->openCount; + + if (gP->openCount == 0) + { + /* Cleanup */ + if (gP->armletP) MemPtrUnlock (gP->armletP); + if (gP->armletH) DmReleaseResource (gP->armletH); + MemPtrFree (gP); + SysLibTblEntry(ref)->globalsP = NULL; + } + + return errNone; +} + + +/* ========================================================================= */ +Err zlib_null (UInt16 ref) +{ + return 0; +} + + +/* =========================================================================== + * Prototypes for the 68K versions of the ZLib functions + */ + +#undef deflate +#undef deflateEnd +#undef inflate +#undef inflateEnd + +int deflateInit2_ (unsigned short ref, z_streamp strm, int level, + int method, int windowBits, int memLevel, int strategy, + const char * version, int stream_size); +int deflate (unsigned short ref, z_streamp strm, int flush); +int deflateEnd (unsigned short ref, z_streamp strm); +int inflateInit2_ (unsigned short ref, z_streamp z, int w, + const char * version, int stream_size); +int inflate (unsigned short d, z_streamp z, int f); +int inflateEnd (unsigned short d, z_streamp z); + + +/* =========================================================================== + * The following functions get called by user apps and branch into the + * appropriate version of the actual ZLib functions. + */ +int deflateInit2_SZ (unsigned short ref, z_streamp strm, int level, + int method, int windowBits, int memLevel, int strategy, + const char * version, int stream_size) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_DEFLATEINIT2; + gP->armlet_params.strm = strm; + gP->armlet_params.level = level; + gP->armlet_params.method = method; + gP->armlet_params.windowBits = windowBits; + gP->armlet_params.memLevel = memLevel; + gP->armlet_params.strategy = strategy; + gP->armlet_params.version = (char *)version; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return deflateInit2_ (ref, strm, level, method, windowBits, memLevel, + strategy, version, stream_size); +} + + +/* ========================================================================= */ +int deflateSZ (unsigned short ref, z_streamp strm, int flush) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_DEFLATE; + gP->armlet_params.strm = strm; + gP->armlet_params.flush = flush; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return deflate (ref, strm, flush); +} + + +/* ========================================================================= */ +int deflateEndSZ (unsigned short ref, z_streamp strm) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_DEFLATEEND; + gP->armlet_params.strm = strm; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return deflateEnd (ref, strm); +} + + +/* ========================================================================= */ +int inflateInit2_SZ (unsigned short ref, z_streamp strm, int windowBits, + const char * version, int stream_size) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_INFLATEINIT2; + gP->armlet_params.strm = strm; + gP->armlet_params.windowBits = windowBits; + gP->armlet_params.version = (char *)version; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return inflateInit2_ (ref, strm, windowBits, version, stream_size); +} + + +/* ========================================================================= */ +int inflateSZ (unsigned short ref, z_streamp strm, int flush) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_INFLATE; + gP->armlet_params.strm = strm; + gP->armlet_params.flush = flush; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return inflate (ref, strm, flush); +} + + +/* ========================================================================= */ +int inflateEndSZ (unsigned short ref, z_streamp strm) +{ + SysZLibGlobalsType * gP = SysLibTblEntry(ref)->globalsP; + + if (gP->useSimulatorDLL || gP->armletP) + { + gP->armlet_params.function = ZLAF_INFLATEEND; + gP->armlet_params.strm = strm; + + if (gP->useSimulatorDLL) + { + return PceNativeCall ((NativeFuncType *)SYSZLIB_DLL_NAME, + &(gP->armlet_params)); + } + else + { + return PceNativeCall (gP->armletP, &(gP->armlet_params)); + } + } + + return inflateEnd (ref, strm); +} + diff -BburN zlib-1.1.4/SysZLib.h zlib-1.1.4-palm/SysZLib.h --- zlib-1.1.4/SysZLib.h 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/SysZLib.h 2003-01-09 17:20:28.000000000 -0800 @@ -0,0 +1,176 @@ +/* SysZLib.h -- interface of the 'SysZLib' shared library + * + * Original version by Tom Zerucha (tz@execpc.com) 2000 + * Revisions and ARMlet support by Justin Clark (jclark@coopcomp.com) 2003 + */ + +#ifndef __ZLIB_H__ +#define __ZLIB_H__ + +#define ZLIB_VERSION "1.1.4" + +// #define PALMOS // defined by arg to compiler +#include "zconf.h" + +/* constants */ +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +/* Allowed flush values; see deflate() below for details */ +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_ASCII 1 +#define Z_UNKNOWN 2 +/* Possible values of the data_type field */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +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; + + /* Function declarations */ +Err ZLibOpen(UInt16 refNum) SYS_TRAP(sysLibTrapOpen); +Err ZLibClose(UInt16 refNum, UInt16Ptr numappsP) SYS_TRAP(sysLibTrapClose); +Err ZLibSleep(UInt16 refNum) SYS_TRAP(sysLibTrapSleep); +Err ZLibWake(UInt16 refNum) SYS_TRAP(sysLibTrapWake); + +Err ZLibdeflateinit2(UInt16 refnum, z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, int stream_size) + SYS_TRAP(sysLibTrapCustom); + +Err ZLibdeflate(UInt16 refnum, z_streamp strm, int flush) + SYS_TRAP(sysLibTrapCustom+1); + +Err ZLibdeflateend(UInt16 refnum, z_streamp strm) + SYS_TRAP(sysLibTrapCustom+2); + +Err ZLibinflateinit2(UInt16 refnum, z_streamp strm, + int windowBits, const char *version, int stream_size) + SYS_TRAP(sysLibTrapCustom+3); + +Err ZLibinflate(UInt16 refnum, z_streamp strm, int flush) + SYS_TRAP(sysLibTrapCustom+4); + +Err ZLibinflateend(UInt16 refnum, z_streamp strm) + SYS_TRAP(sysLibTrapCustom+5); + +uLong ZLibcrc32(UInt16 refnum, uLong crc, const Bytef * buf, uInt len) + SYS_TRAP(sysLibTrapCustom+6); + +uLong ZLibadler32(UInt16 refnum, uLong adler, const Bytef * buf, uInt len) + SYS_TRAP(sysLibTrapCustom+7); + +Err ZLibcompress2(UInt16 refnum, Bytef * dest, uLongf * destLen, + const Bytef * source, uLong sourceLen, int level) + SYS_TRAP(sysLibTrapCustom+8); + +Err ZLibuncompress(UInt16 refnum, Bytef * dest, uLongf * destLen, + const Bytef * source, uLong sourceLen) + SYS_TRAP(sysLibTrapCustom+9); + +#ifndef NOZLIBDEFS +UInt16 ZLibRef = 0; +#else +extern UInt16 ZLibRef; +#endif + + +#define ZLSetup !ZLibRef && SysLibFind("Z.lib", &ZLibRef) && SysLibLoad('libr', 'ZLib', &ZLibRef) && SysLibFind("Z.lib", &ZLibRef) && ZLibOpen(ZLibRef) && (ErrFatalDisplay("No ZLib"),0) + +#define ZLTeardown if(ZLibRef){\ + UInt16 zltmp;\ + ZLibClose(ZLibRef,&zltmp);\ + if(!zltmp)\ + SysLibRemove(ZLibRef);\ + ZLibRef = 0;} + + +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + ZLibdeflateinit2((ZLibRef),(strm),(level),(method),(windowBits), \ + (memLevel),(strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + ZLibinflateinit2((ZLibRef), (strm), (windowBits), ZLIB_VERSION, \ + sizeof(z_stream)) + +/* 13 bits requires 32k, Memlevel 6 requires 32k. Each increment doubles + * (for each) +*/ +#define deflateInit(a,b) ZLibdeflateinit2((ZLibRef), a, b, Z_DEFLATED, \ + 13, 6, Z_DEFAULT_STRATEGY, ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit_(a,b,c,d) ZLibdeflateinit2((ZLibRef), a, b, Z_DEFLATED, \ + 13, 6, Z_DEFAULT_STRATEGY, c, d) + +#define inflateInit(a) ZLibinflateinit2((ZLibRef), a, 15, ZLIB_VERSION, \ + sizeof(z_stream)) +#define inflateInit_(a,b,c) ZLibinflateinit2((ZLibRef), a, 15, b, c) + +#define inflate(x,y) ZLibinflate(ZLibRef,x,y) +#define deflate(x,y) ZLibdeflate(ZLibRef,x,y) +#define inflateEnd(x) ZLibinflateend(ZLibRef,x) +#define deflateEnd(x) ZLibdeflateend(ZLibRef,x) +#define crc32(a,b,c) ZLibcrc32(ZLibRef,a,b,c) +#define adler32(a,b,c) ZLibadler32(ZLibRef,a,b,c) + + +/* Error codes returned by zlib_open */ +#define SysZLibErrParam (appErrorClass | 1) +#define SysZLibErrNotOpen (appErrorClass | 2) +#define SysZLibErrStillOpen (appErrorClass | 3) +#define SysZLibErrOutOfMemory (appErrorClass | 4) + + +#endif /* __ZLIB_H__ */ diff -BburN zlib-1.1.4/SysZLib0.S zlib-1.1.4-palm/SysZLib0.S --- zlib-1.1.4/SysZLib0.S 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/SysZLib0.S 2003-01-09 18:28:51.000000000 -0800 @@ -0,0 +1,40 @@ + .text + move.l %a0,%d0 | do I need to preserve A0? + move.l 6(%a7),%a0 + pea table(%pc) | if not I could exg a lot, but this works. + move.l (%a7)+,(%a0)+ + clr.l (%a0) + move.l %d0,%a0 + moveq #0,%d0 + rts + +| dispatch table - note the lack of jump to jump to jumps. Note this +| can be moved to keep this and the entry points within 0..32K + +table: + dc.w name-table +| 1 + dc.w zlib_open-table + dc.w zlib_close-table + dc.w zlib_null-table + dc.w zlib_null-table +| 5 + dc.w deflateInit2_SZ-table + dc.w deflateSZ-table + dc.w deflateEndSZ-table +| 8 + dc.w inflateInit2_SZ-table + dc.w inflateSZ-table + dc.w inflateEndSZ-table +| 11 + dc.w crc32-table + dc.w adler32-table + dc.w compress2-table + dc.w uncompress-table + +name: + .asciz "Z.lib" + .asciz "Palm ZLib adaptation Copyright 2000, Tom Zerucha, tz@execpc.com" + .asciz "ARMlet adaptation by Justin Clark, jclark@coopcomp.com" + .even + diff -BburN zlib-1.1.4/adler32.S zlib-1.1.4-palm/adler32.S --- zlib-1.1.4/adler32.S 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/adler32.S 2002-10-04 18:20:28.000000000 -0700 @@ -0,0 +1,59 @@ + .text + .even + .globl adler32 +adler32: + link.w %a6,#0 + movm.l #0x1c20,-(%sp) + move.l 10(%a6),%d0 + move.l 14(%a6),%a2 + move.w 18(%a6),%d5 + + moveq.l #0,%d4 + moveq.l #0,%d3 + + move.w %d0,%d3 + swap %d0 + move.w %d0,%d4 + + cmp.w #0,%a2 + jbne .L32 + moveq.l #1,%d0 + bra .L31 + +.L23: + move.w %d5,%d0 + cmp.w #5552,%d5 + jbls .L24 + move.w #5552,%d0 +.L24: + sub.w %d0,%d5 + tst.w %d0 + jbeq .L25 + moveq.l #0,%d1 + subq.w #1,%d0 + +.L29: + move.b (%a2)+,%d1 + add.l %d1,%d3 + add.l %d3,%d4 + dbra.w %d0,.L29 +.L25: + divu #65521,%d3 + clr.w %d3 + swap %d3 + + divu #65521,%d4 + clr.w %d4 + swap %d4 + +.L32: + tst.w %d5 + jbne .L23 + + move.w %d4,%d0 + swap %d0 + move.w %d3,%d0 +.L31: + movm.l -16(%a6),#0x438 + unlk %a6 + rts diff -BburN zlib-1.1.4/adler32.c zlib-1.1.4-palm/adler32.c --- zlib-1.1.4/adler32.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/adler32.c 2002-12-09 17:00:22.000000000 -0800 @@ -18,7 +18,8 @@ #define DO16(buf) DO8(buf,0); DO8(buf,8); /* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) +uLong ZEXPORT adler32(d, adler, buf, len) + unsigned short d; uLong adler; const Bytef *buf; uInt len; @@ -32,11 +33,13 @@ while (len > 0) { k = len < NMAX ? len : NMAX; len -= k; +#ifndef PALMOS while (k >= 16) { DO16(buf); buf += 16; k -= 16; } +#endif if (k != 0) do { s1 += *buf++; s2 += s1; diff -BburN zlib-1.1.4/armletldscript zlib-1.1.4-palm/armletldscript --- zlib-1.1.4/armletldscript 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/armletldscript 2002-12-09 15:18:22.000000000 -0800 @@ -0,0 +1,9 @@ +OUTPUT_FORMAT("elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(zlib_armlet_dispatch) + SEARCH_DIR(/usr/local/arm-elf/lib); +SECTIONS +{ + .text 0x00000000 : { *(.text) *(.rodata) *(.rodata.str1.4) } +} + diff -BburN zlib-1.1.4/compress.c zlib-1.1.4-palm/compress.c --- zlib-1.1.4/compress.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/compress.c 2002-10-04 18:20:28.000000000 -0700 @@ -45,17 +45,18 @@ err = deflateInit(&stream, level); if (err != Z_OK) return err; - err = deflate(&stream, Z_FINISH); + err = deflate(0, &stream, Z_FINISH); if (err != Z_STREAM_END) { - deflateEnd(&stream); + deflateEnd(0, &stream); return err == Z_OK ? Z_BUF_ERROR : err; } *destLen = stream.total_out; - err = deflateEnd(&stream); + err = deflateEnd(0, &stream); return err; } +#ifndef PALMOS /* =========================================================================== */ int ZEXPORT compress (dest, destLen, source, sourceLen) @@ -66,3 +67,4 @@ { return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); } +#endif diff -BburN zlib-1.1.4/crc32.S zlib-1.1.4-palm/crc32.S --- zlib-1.1.4/crc32.S 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/crc32.S 2002-10-04 18:20:28.000000000 -0700 @@ -0,0 +1,298 @@ + .file "crc32.c" +gcc2_compiled.: +__gnu_compiled_c: +.text + .even +crc_table: + .long 0 + .long 1996959894 + .long -301047508 + .long -1727442502 + .long 124634137 + .long 1886057615 + .long -379345611 + .long -1637575261 + .long 249268274 + .long 2044508324 + .long -522852066 + .long -1747789432 + .long 162941995 + .long 2125561021 + .long -407360249 + .long -1866523247 + .long 498536548 + .long 1789927666 + .long -205950648 + .long -2067906082 + .long 450548861 + .long 1843258603 + .long -187386543 + .long -2083289657 + .long 325883990 + .long 1684777152 + .long -43845254 + .long -1973040660 + .long 335633487 + .long 1661365465 + .long -99664541 + .long -1928851979 + .long 997073096 + .long 1281953886 + .long -715111964 + .long -1570279054 + .long 1006888145 + .long 1258607687 + .long -770865667 + .long -1526024853 + .long 901097722 + .long 1119000684 + .long -608450090 + .long -1396901568 + .long 853044451 + .long 1172266101 + .long -589951537 + .long -1412350631 + .long 651767980 + .long 1373503546 + .long -925412992 + .long -1076862698 + .long 565507253 + .long 1454621731 + .long -809855591 + .long -1195530993 + .long 671266974 + .long 1594198024 + .long -972236366 + .long -1324619484 + .long 795835527 + .long 1483230225 + .long -1050600021 + .long -1234817731 + .long 1994146192 + .long 31158534 + .long -1731059524 + .long -271249366 + .long 1907459465 + .long 112637215 + .long -1614814043 + .long -390540237 + .long 2013776290 + .long 251722036 + .long -1777751922 + .long -519137256 + .long 2137656763 + .long 141376813 + .long -1855689577 + .long -429695999 + .long 1802195444 + .long 476864866 + .long -2056965928 + .long -228458418 + .long 1812370925 + .long 453092731 + .long -2113342271 + .long -183516073 + .long 1706088902 + .long 314042704 + .long -1950435094 + .long -54949764 + .long 1658658271 + .long 366619977 + .long -1932296973 + .long -69972891 + .long 1303535960 + .long 984961486 + .long -1547960204 + .long -725929758 + .long 1256170817 + .long 1037604311 + .long -1529756563 + .long -740887301 + .long 1131014506 + .long 879679996 + .long -1385723834 + .long -631195440 + .long 1141124467 + .long 855842277 + .long -1442165665 + .long -586318647 + .long 1342533948 + .long 654459306 + .long -1106571248 + .long -921952122 + .long 1466479909 + .long 544179635 + .long -1184443383 + .long -832445281 + .long 1591671054 + .long 702138776 + .long -1328506846 + .long -942167884 + .long 1504918807 + .long 783551873 + .long -1212326853 + .long -1061524307 + .long -306674912 + .long -1698712650 + .long 62317068 + .long 1957810842 + .long -355121351 + .long -1647151185 + .long 81470997 + .long 1943803523 + .long -480048366 + .long -1805370492 + .long 225274430 + .long 2053790376 + .long -468791541 + .long -1828061283 + .long 167816743 + .long 2097651377 + .long -267414716 + .long -2029476910 + .long 503444072 + .long 1762050814 + .long -144550051 + .long -2140837941 + .long 426522225 + .long 1852507879 + .long -19653770 + .long -1982649376 + .long 282753626 + .long 1742555852 + .long -105259153 + .long -1900089351 + .long 397917763 + .long 1622183637 + .long -690576408 + .long -1580100738 + .long 953729732 + .long 1340076626 + .long -776247311 + .long -1497606297 + .long 1068828381 + .long 1219638859 + .long -670225446 + .long -1358292148 + .long 906185462 + .long 1090812512 + .long -547295293 + .long -1469587627 + .long 829329135 + .long 1181335161 + .long -882789492 + .long -1134132454 + .long 628085408 + .long 1382605366 + .long -871598187 + .long -1156888829 + .long 570562233 + .long 1426400815 + .long -977650754 + .long -1296233688 + .long 733239954 + .long 1555261956 + .long -1026031705 + .long -1244606671 + .long 752459403 + .long 1541320221 + .long -1687895376 + .long -328994266 + .long 1969922972 + .long 40735498 + .long -1677130071 + .long -351390145 + .long 1913087877 + .long 83908371 + .long -1782625662 + .long -491226604 + .long 2075208622 + .long 213261112 + .long -1831694693 + .long -438977011 + .long 2094854071 + .long 198958881 + .long -2032938284 + .long -237706686 + .long 1759359992 + .long 534414190 + .long -2118248755 + .long -155638181 + .long 1873836001 + .long 414664567 + .long -2012718362 + .long -15766928 + .long 1711684554 + .long 285281116 + .long -1889165569 + .long -127750551 + .long 1634467795 + .long 376229701 + .long -1609899400 + .long -686959890 + .long 1308918612 + .long 956543938 + .long -1486412191 + .long -799009033 + .long 1231636301 + .long 1047427035 + .long -1362007478 + .long -640263460 + .long 1088359270 + .long 936918000 + .long -1447252397 + .long -558129467 + .long 1202900863 + .long 817233897 + .long -1111625188 + .long -893730166 + .long 1404277552 + .long 615818150 + .long -1160759803 + .long -841546093 + .long 1423857449 + .long 601450431 + .long -1285129682 + .long -1000256840 + .long 1567103746 + .long 711928724 + .long -1274298825 + .long -1022587231 + .long 1510334235 + .long 755167117 + + .even +.globl crc32 +crc32: + link.w %a6,#0 + move.l 10(%a6),%d2 + move.l 14(%a6),%a1 + move.w 18(%a6),%d0 + + cmp.w #0,%a1 + jbne .L47 + moveq.l #0,%d0 + bra .L53 + +.L47: not.l %d2 + tst.w %d0 + jbeq .L48 + subq #1,%d0 + lea crc_table(%pc),%a0 + +.L49: move.b (%a1)+,%d1 + eor.w %d2,%d1 + and.l #0xFF,%d1 + asl.l #2,%d1 + + lsr.l #8,%d2 + move.l (%a0,%d1.l),%d1 + eor.l %d1,%d2 + + dbf %d0,.L49 + +.L48: move.l %d2,%d0 + not.l %d0 + +.L53: unlk %a6 + rts diff -BburN zlib-1.1.4/crc32.c zlib-1.1.4-palm/crc32.c --- zlib-1.1.4/crc32.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/crc32.c 2002-10-04 18:20:28.000000000 -0700 @@ -150,11 +150,13 @@ make_crc_table(); #endif crc = crc ^ 0xffffffffL; +#ifndef PALMOS while (len >= 8) { DO8(buf); len -= 8; } +#endif if (len) do { DO1(buf); } while (--len); diff -BburN zlib-1.1.4/deflate.c zlib-1.1.4-palm/deflate.c --- zlib-1.1.4/deflate.c 2002-03-11 07:00:39.000000000 -0800 +++ zlib-1.1.4-palm/deflate.c 2003-01-09 18:45:36.000000000 -0800 @@ -49,7 +49,11 @@ /* @(#) $Id: zlib114armlet-1.dif,v 1.1.1.1 2003/11/19 03:59:01 seichert Exp $ */ +#if (defined(PALMOS) || defined(ARMLET)) +#include "trees.c" +#else #include "deflate.h" +#endif const char deflate_copyright[] = " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly "; @@ -120,9 +124,14 @@ ush max_lazy; /* do not perform lazy search above this match length */ ush nice_length; /* quit search above this match length */ ush max_chain; - compress_func func; + ush speed; + // compress_func func; } config; +#define deflate_stored 0 +#define deflate_fast 1 +#define deflate_slow 2 + local const config configuration_table[10] = { /* good lazy nice chain */ /* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ @@ -137,6 +146,19 @@ /* 8 */ {32, 128, 258, 1024, deflate_slow}, /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ +#undef deflate_stored +#undef deflate_fast +#undef deflate_slow + +compress_func dfunc(int which) { +switch (which) { + case 1: return deflate_fast; + case 2: return deflate_slow; + default: break; +} +return deflate_stored; +} + /* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different * meaning. @@ -145,7 +167,9 @@ #define EQUAL 0 /* result of memcmp for equal strings */ +#if !(defined(PALMOS) || defined(ARMLET)) struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ +#endif /* =========================================================================== * Update a hash value with the given input byte @@ -186,6 +210,7 @@ s->head[s->hash_size-1] = NIL; \ zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); +#if !(defined(PALMOS) || defined(ARMLET)) /* ========================================================================= */ int ZEXPORT deflateInit_(strm, level, version, stream_size) z_streamp strm; @@ -197,10 +222,12 @@ Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ } +#endif /* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, +int ZEXPORT deflateInit2_(ref, strm, level, method, windowBits, memLevel, strategy, version, stream_size) + unsigned short ref; z_streamp strm; int level; int method; @@ -212,7 +239,7 @@ { deflate_state *s; int noheader = 0; - static const char* my_version = ZLIB_VERSION; + static const char my_version[] = ZLIB_VERSION; ushf *overlay; /* We overlay pending_buf and d_buf+l_buf. This works since the average @@ -274,7 +301,7 @@ if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); + deflateEnd (0, strm); return Z_MEM_ERROR; } s->d_buf = overlay + s->lit_bufsize/sizeof(ush); @@ -284,9 +311,14 @@ s->strategy = strategy; s->method = (Byte)method; + s->l_desc.stat_desc = ZALLOC(strm, 3 , sizeof(static_tree_desc)); + s->d_desc.stat_desc = &s->l_desc.stat_desc[1]; + s->bl_desc.stat_desc = &s->l_desc.stat_desc[2]; + return deflateReset(strm); } +#ifndef ARMLET /* ========================================================================= */ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) z_streamp strm; @@ -302,7 +334,7 @@ strm->state->status != INIT_STATE) return Z_STREAM_ERROR; s = strm->state; - strm->adler = adler32(strm->adler, dictionary, dictLength); + strm->adler = adler32(0, strm->adler, dictionary, dictLength); if (length < MIN_MATCH) return Z_OK; if (length > MAX_DIST(s)) { @@ -327,6 +359,7 @@ if (hash_head) hash_head = 0; /* to make compiler happy */ return Z_OK; } +#endif /* ========================================================================= */ int ZEXPORT deflateReset (strm) @@ -358,6 +391,7 @@ return Z_OK; } +#ifndef ARMLET /* ========================================================================= */ int ZEXPORT deflateParams(strm, level, strategy) z_streamp strm; @@ -377,11 +411,11 @@ if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { return Z_STREAM_ERROR; } - func = configuration_table[s->level].func; + func = dfunc(configuration_table[s->level].speed); - if (func != configuration_table[level].func && strm->total_in != 0) { + if (func != dfunc(configuration_table[level].speed) && strm->total_in != 0) { /* Flush the last buffer: */ - err = deflate(strm, Z_PARTIAL_FLUSH); + err = deflate(0, strm, Z_PARTIAL_FLUSH); } if (s->level != level) { s->level = level; @@ -393,6 +427,7 @@ s->strategy = strategy; return err; } +#endif /* ========================================================================= * Put a short in the pending buffer. The 16-bit value is put in MSB order. @@ -433,7 +468,8 @@ } /* ========================================================================= */ -int ZEXPORT deflate (strm, flush) +int ZEXPORT deflate (ref, strm, flush) + unsigned short ref; z_streamp strm; int flush; { @@ -513,7 +549,7 @@ (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { block_state bstate; - bstate = (*(configuration_table[s->level].func))(s, flush); + bstate = (*(dfunc(configuration_table[s->level].speed)))(s, flush); if (bstate == finish_started || bstate == finish_done) { s->status = FINISH_STATE; @@ -567,7 +603,8 @@ } /* ========================================================================= */ -int ZEXPORT deflateEnd (strm) +int ZEXPORT deflateEnd (ref, strm) + unsigned short ref; z_streamp strm; { int status; @@ -581,6 +618,8 @@ } /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm,strm->state->l_desc.stat_desc); + TRY_FREE(strm, strm->state->pending_buf); TRY_FREE(strm, strm->state->head); TRY_FREE(strm, strm->state->prev); @@ -592,6 +631,7 @@ return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; } +#ifndef ARMLET /* ========================================================================= * Copy the source state to the destination state. * To simplify the source, this is not supported for 16-bit MSDOS (which @@ -601,7 +641,7 @@ z_streamp dest; z_streamp source; { -#ifdef MAXSEG_64K +#if defined(MAXSEG_64K) return Z_STREAM_ERROR; #else deflate_state *ds; @@ -651,6 +691,7 @@ return Z_OK; #endif } +#endif /* =========================================================================== * Read a new buffer from the current input stream, update the adler32 @@ -672,7 +713,7 @@ strm->avail_in -= len; if (!strm->state->noheader) { - strm->adler = adler32(strm->adler, strm->next_in, len); + strm->adler = adler32(0, strm->adler, strm->next_in, len); } zmemcpy(buf, strm->next_in, len); strm->next_in += len; @@ -705,8 +746,10 @@ s->match_available = 0; s->ins_h = 0; #ifdef ASMV +#if !(defined(PALMOS) || defined(ARMLET)) match_init(); /* initialize the asm code */ #endif +#endif } /* =========================================================================== diff -BburN zlib-1.1.4/deflate.h zlib-1.1.4-palm/deflate.h --- zlib-1.1.4/deflate.h 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/deflate.h 2002-12-09 19:44:00.000000000 -0800 @@ -284,13 +284,18 @@ #ifndef DEBUG /* Inline versions of _tr_tally for speed: */ +#if !(defined(PALMOS) || defined(ARMLET)) #if defined(GEN_TREES_H) || !defined(STDC) - extern uch _length_code[]; - extern uch _dist_code[]; + extern uch *_length_code; + extern uch *_dist_code; #else extern const uch _length_code[]; extern const uch _dist_code[]; #endif +#else +extern const uch _dist_code[]; +extern const uch _length_code[]; +#endif # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ diff -BburN zlib-1.1.4/endianutils.h zlib-1.1.4-palm/endianutils.h --- zlib-1.1.4/endianutils.h 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/endianutils.h 2002-12-09 16:43:36.000000000 -0800 @@ -0,0 +1,26 @@ +#ifndef __ENDIANUTILS_H__ +#define __ENDIANUTILS_H__ + +// handy macros for handling endian and alignment issues + +#define ByteSwap16(n) ( ((((unsigned int) n) << 8) & 0xFF00) | \ + ((((unsigned int) n) >> 8) & 0x00FF) ) + +#define ByteSwap32(n) ( ((((unsigned long) n) << 24) & 0xFF000000) | \ + ((((unsigned long) n) << 8) & 0x00FF0000) | \ + ((((unsigned long) n) >> 8) & 0x0000FF00) | \ + ((((unsigned long) n) >> 24) & 0x000000FF) ) + +#define ReadUnaligned32(addr) \ + ( ((((unsigned char *)(addr))[0]) << 24) | \ + ((((unsigned char *)(addr))[1]) << 16) | \ + ((((unsigned char *)(addr))[2]) << 8) | \ + ((((unsigned char *)(addr))[3])) ) + +#define WriteUnaligned32(addr, value) \ + ( ((unsigned char *)(addr))[0] = (unsigned char)((unsigned long)(value) >> 24), \ + ((unsigned char *)(addr))[1] = (unsigned char)((unsigned long)(value) >> 16), \ + ((unsigned char *)(addr))[2] = (unsigned char)((unsigned long)(value) >> 8), \ + ((unsigned char *)(addr))[3] = (unsigned char)((unsigned long)(value)) ) + +#endif // __ENDIANUTILS_H__ diff -BburN zlib-1.1.4/infblock.c zlib-1.1.4-palm/infblock.c --- zlib-1.1.4/infblock.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/infblock.c 2002-10-04 18:20:28.000000000 -0700 @@ -81,7 +81,7 @@ s->bitb = 0; s->read = s->write = s->window; if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); + z->adler = s->check = (*s->checkfn)(0, 0L, (const Bytef *)Z_NULL, 0); Tracev((stderr, "inflate: blocks reset\n")); } @@ -269,7 +269,7 @@ t = s->sub.trees.bb; NEEDBITS(t) - h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]); + h = s->sub.trees.tb + ((uInt)b & inflate_mask(t)); t = h->bits; c = h->base; if (c < 16) @@ -283,7 +283,7 @@ j = c == 18 ? 11 : 3; NEEDBITS(t + i) DUMPBITS(t) - j += (uInt)b & inflate_mask[i]; + j += (uInt)b & inflate_mask(i); DUMPBITS(i) i = s->sub.trees.index; t = s->sub.trees.table; diff -BburN zlib-1.1.4/infcodes.c zlib-1.1.4-palm/infcodes.c --- zlib-1.1.4/infcodes.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/infcodes.c 2002-10-04 18:20:28.000000000 -0700 @@ -121,7 +121,7 @@ case LEN: /* i: get length/literal/eob next */ j = c->sub.code.need; NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + t = c->sub.code.tree + ((uInt)b & inflate_mask(j)); DUMPBITS(t->bits) e = (uInt)(t->exop); if (e == 0) /* literal */ @@ -159,7 +159,7 @@ case LENEXT: /* i: getting length extra (have base) */ j = c->sub.copy.get; NEEDBITS(j) - c->len += (uInt)b & inflate_mask[j]; + c->len += (uInt)b & inflate_mask(j); DUMPBITS(j) c->sub.code.need = c->dbits; c->sub.code.tree = c->dtree; @@ -168,7 +168,7 @@ case DIST: /* i: get distance next */ j = c->sub.code.need; NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + t = c->sub.code.tree + ((uInt)b & inflate_mask(j)); DUMPBITS(t->bits) e = (uInt)(t->exop); if (e & 16) /* distance */ @@ -191,7 +191,7 @@ case DISTEXT: /* i: getting distance extra */ j = c->sub.copy.get; NEEDBITS(j) - c->sub.copy.dist += (uInt)b & inflate_mask[j]; + c->sub.copy.dist += (uInt)b & inflate_mask(j); DUMPBITS(j) Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); c->mode = COPY; diff -BburN zlib-1.1.4/inffast.c zlib-1.1.4-palm/inffast.c --- zlib-1.1.4/inffast.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/inffast.c 2002-10-04 18:20:28.000000000 -0700 @@ -50,8 +50,8 @@ LOAD /* initialize masks */ - ml = inflate_mask[bl]; - md = inflate_mask[bd]; + ml = inflate_mask(bl); + md = inflate_mask(bd); /* do until not enough input or output space for fast loop */ do { /* assume called with m >= 258 && n >= 10 */ @@ -73,7 +73,7 @@ { /* get extra bits for length */ e &= 15; - c = t->base + ((uInt)b & inflate_mask[e]); + c = t->base + ((uInt)b & inflate_mask(e)); DUMPBITS(e) Tracevv((stderr, "inflate: * length %u\n", c)); @@ -87,7 +87,7 @@ /* get extra bits to add to distance base */ e &= 15; GRABBITS(e) /* get extra bits (up to 13) */ - d = t->base + ((uInt)b & inflate_mask[e]); + d = t->base + ((uInt)b & inflate_mask(e)); DUMPBITS(e) Tracevv((stderr, "inflate: * distance %u\n", d)); @@ -133,7 +133,7 @@ else if ((e & 64) == 0) { t += t->base; - e = (t += ((uInt)b & inflate_mask[e]))->exop; + e = (t += ((uInt)b & inflate_mask(e)))->exop; } else { @@ -148,7 +148,7 @@ if ((e & 64) == 0) { t += t->base; - if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) + if ((e = (t += ((uInt)b & inflate_mask(e)))->exop) == 0) { DUMPBITS(t->bits) Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? diff -BburN zlib-1.1.4/inffixed.h zlib-1.1.4-palm/inffixed.h --- zlib-1.1.4/inffixed.h 1998-06-16 04:29:49.000000000 -0700 +++ zlib-1.1.4-palm/inffixed.h 2002-10-04 18:20:28.000000000 -0700 @@ -7,9 +7,9 @@ subject to change. Applications should only use zlib.h. */ -local uInt fixed_bl = 9; -local uInt fixed_bd = 5; -local inflate_huft fixed_tl[] = { +local const uInt fixed_bl = 9; +local const uInt fixed_bd = 5; +local const inflate_huft fixed_tl[] = { {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115}, {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192}, {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160}, @@ -139,7 +139,7 @@ {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191}, {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255} }; -local inflate_huft fixed_td[] = { +local const inflate_huft fixed_td[] = { {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097}, {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385}, {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193}, diff -BburN zlib-1.1.4/inflate.c zlib-1.1.4-palm/inflate.c --- zlib-1.1.4/inflate.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/inflate.c 2003-01-09 18:25:02.000000000 -0800 @@ -64,7 +64,8 @@ } -int ZEXPORT inflateEnd(z) +int ZEXPORT inflateEnd(d, z) + unsigned short d; z_streamp z; { if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) @@ -78,7 +79,8 @@ } -int ZEXPORT inflateInit2_(z, w, version, stream_size) +int ZEXPORT inflateInit2_(d, z, w, version, stream_size) + unsigned short d; z_streamp z; int w; const char *version; @@ -114,17 +116,18 @@ /* set window size */ if (w < 8 || w > 15) { - inflateEnd(z); + inflateEnd(0, z); return Z_STREAM_ERROR; } z->state->wbits = (uInt)w; /* create inflate_blocks state */ - if ((z->state->blocks = - inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) - == Z_NULL) + if ((z->state->blocks = z->state->nowrap ? + inflate_blocks_new(z, NULL , (uInt)1 << w) : + inflate_blocks_new(z, adler32, (uInt)1 << w) + ) == Z_NULL) { - inflateEnd(z); + inflateEnd(0, z); return Z_MEM_ERROR; } Tracev((stderr, "inflate: allocated\n")); @@ -134,7 +137,7 @@ return Z_OK; } - +#if !(defined(PALMOS) || defined(ARMLET)) int ZEXPORT inflateInit_(z, version, stream_size) z_streamp z; const char *version; @@ -142,12 +145,13 @@ { return inflateInit2_(z, DEF_WBITS, version, stream_size); } - +#endif #define NEEDBYTE {if(z->avail_in==0)return r;r=f;} #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) -int ZEXPORT inflate(z, f) +int ZEXPORT inflate(d, z, f) + unsigned short d; z_streamp z; int f; { @@ -285,7 +289,7 @@ if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) return Z_STREAM_ERROR; - if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; + if (adler32(0, 1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; z->adler = 1L; if (length >= ((uInt)1<state->wbits)) diff -BburN zlib-1.1.4/inftrees.c zlib-1.1.4-palm/inftrees.c --- zlib-1.1.4/inftrees.c 2002-03-11 05:18:06.000000000 -0800 +++ zlib-1.1.4-palm/inftrees.c 2002-12-09 17:11:08.000000000 -0800 @@ -448,7 +448,12 @@ #endif *bl = fixed_bl; *bd = fixed_bd; +#if (defined(PALMOS) || defined(ARMLET)) + *tl = (inflate_huft *) fixed_tl; + *td = (inflate_huft *) fixed_td; +#else *tl = fixed_tl; *td = fixed_td; +#endif return Z_OK; } diff -BburN zlib-1.1.4/infutil.c zlib-1.1.4-palm/infutil.c --- zlib-1.1.4/infutil.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/infutil.c 2002-10-04 18:20:28.000000000 -0700 @@ -12,12 +12,14 @@ struct inflate_codes_state {int dummy;}; /* for buggy compilers */ /* And'ing with mask[n] masks the lower n bits */ + +#if 0 uInt inflate_mask[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff }; - +#endif /* copy as much as possible from the sliding window to the output area */ int inflate_flush(s, z, r) @@ -44,7 +46,7 @@ /* update check information */ if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); + z->adler = s->check = (*s->checkfn)(0, s->check, q, n); /* copy as far as end of window */ zmemcpy(p, q, n); @@ -70,7 +72,7 @@ /* update check information */ if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); + z->adler = s->check = (*s->checkfn)(0, s->check, q, n); /* copy */ zmemcpy(p, q, n); diff -BburN zlib-1.1.4/lmatch.S zlib-1.1.4-palm/lmatch.S --- zlib-1.1.4/lmatch.S 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/lmatch.S 2002-10-04 18:20:28.000000000 -0700 @@ -0,0 +1,144 @@ + .file "lmatch.c" +gcc2_compiled.: +__gnu_compiled_c: +.text + .even +.globl longest_match +longest_match: + link.w %a6,#-12 + movm.l #0x1f38,-(%sp) + move.l 8(%a6),%a3 + move.w 12(%a6),%d3 + move.w 76(%a3),%d5 + clr.l %d0 + move.w 68(%a3),%d0 + move.l 32(%a3),%a2 + add.l %d0,%a2 /*JANE2*/ + move.w 74(%a3),%d4 + move.w 86(%a3),%a4 + move.w 26(%a3),%d2 + move.w %d2,%d0 + add.w #-262,%d0 + move.w 68(%a3),%d1 + cmp.w %d1,%d0 + jbcc .L20 + move.w %d1,%d6 + add.w #262,%d6 + sub.w %d2,%d6 + bra .L21 + +.L20: + clr.w %d6 +.L21: + move.l 40(%a3),-4(%a6) + move.w 30(%a3),-6(%a6) + clr.l %d0 + move.w 68(%a3),%d0 + add.l 32(%a3),%d0 /*JANE2*/ + move.l %d0,%d1 + add.l #258,%d1 /*JANE2*/ + move.w %d4,%a0 + move.b -1(%a2,%a0.l),%d7 + move.b (%a0,%a2.l),%d2 + move.w 84(%a3),%d0 + cmp.w 74(%a3),%d0 + jbhi .L22 + lsr.w #2,%d5 +.L22: + move.w 72(%a3),%d0 + cmp.w %a4,%d0 + jbcc .L23 + move.w %d0,%a4 +.L23: + clr.l -10(%a6) + + + +.L37: + move.w %d3,-8(%a6) + + move.l -10(%a6),%a0 + add.l 32(%a3),%a0 + + cmp.b (%a0,%d4.w),%d2 + jbne .L26 + cmp.b -1(%a0,%d4.w),%d7 + jbne .L26 + + move.b (%a0)+,%d0 + cmp.b (%a2),%d0 + jbne .L26 + + move.b (%a0),%d0 + cmp.b 1(%a2),%d0 + jbne .L26 + + addq.l #3,%a2 + addq.l #2,%a0 + + move.l %d1,%a1 + lea (-258,%a1),%a1 + +.L31: + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + cmpm.b (%a0)+,(%a2)+ + jbne .L30 + + cmp.l %a2,%d1 + jbcc .L31 + + +.L30: + add.w #257,%a2 + sub.l %d1,%a2 + move.w %a2,%d0 + + move.l %a1,%a2 + + cmp.w %d0,%d4 + jbge .L26 + + move.w %d3,70(%a3) + move.w %d0,%d4 + cmp.w %a4,%d4 + jbge .L25 + + move.b -1(%a1,%d4.w),%d7 + move.b (%a1,%d4.w),%d2 +.L26: + and.w -6(%a6),%d3 + clr.l %d0 + move.w %d3,%d0 + add.l %d0,%d0 + move.l -4(%a6),%a0 + move.w (%a0,%d0.l),%d3 + cmp.w %d3,%d6 + jbcc .L25 + subq.w #1,%d5 + jbne .L37 + + + +.L25: + move.w 72(%a3),%d1 + move.w %d4,%d0 + cmp.w %d0,%d1 + jbcc .L39 + move.w %d1,%d0 +.L39: + movm.l (%sp)+,#0x1cf8 + unlk %a6 + rts diff -BburN zlib-1.1.4/trees.c zlib-1.1.4-palm/trees.c --- zlib-1.1.4/trees.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/trees.c 2002-12-09 17:27:18.000000000 -0800 @@ -126,20 +126,23 @@ int max_length; /* max bit length for the codes */ }; -local static_tree_desc static_l_desc = +#if !(defined(PALMOS) || defined(ARMLET)) +local const static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local static_tree_desc static_d_desc = +local const static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local static_tree_desc static_bl_desc = +local const static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - +#endif /* =========================================================================== * Local (static) routines in this file. */ +#if !(defined(PALMOS) || defined(ARMLET)) local void tr_static_init OF((void)); +#endif local void init_block OF((deflate_state *s)); local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); @@ -236,9 +239,9 @@ /* =========================================================================== * Initialize the various 'constant' tables. */ +#if defined(GEN_TREES_H) || !defined(STDC) local void tr_static_init() { -#if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ int bits; /* bit counter */ @@ -313,8 +316,9 @@ # ifdef GEN_TREES_H gen_trees_header(); # endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ + } +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ /* =========================================================================== * Genererate the file trees.h describing the static trees. @@ -383,16 +387,37 @@ void _tr_init(s) deflate_state *s; { - tr_static_init(); +static_tree_desc *s1; - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; +// tr_static_init(); + s->l_desc.dyn_tree = s->dyn_ltree; s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; + + s1 = s->l_desc.stat_desc; + + s1->static_tree = static_ltree; + s1->extra_bits = extra_lbits; + s1->extra_base = LITERALS + 1; + s1->elems = L_CODES; + s1->max_length = MAX_BITS; + + s1 = s->d_desc.stat_desc; + + s1->static_tree = static_dtree; + s1->extra_bits = extra_dbits; + s1->extra_base = 0; + s1->elems = D_CODES; + s1->max_length = MAX_BITS; + + s1 = s->bl_desc.stat_desc; + + s1->static_tree = NULL; + s1->extra_bits = extra_blbits; + s1->extra_base = 0; + s1->elems = BL_CODES; + s1->max_length = MAX_BL_BITS; s->bi_buf = 0; s->bi_valid = 0; diff -BburN zlib-1.1.4/trees.h zlib-1.1.4-palm/trees.h --- zlib-1.1.4/trees.h 1998-02-24 04:14:55.000000000 -0800 +++ zlib-1.1.4-palm/trees.h 2002-10-04 18:20:28.000000000 -0700 @@ -70,7 +70,7 @@ {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} }; -const uch _dist_code[DIST_CODE_LEN] = { +const uch _dist_code[512] = { 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, @@ -99,7 +99,7 @@ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 }; -const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { +const uch _length_code[MAX_MATCH-MIN_MATCH+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, diff -BburN zlib-1.1.4/uncompr.c zlib-1.1.4-palm/uncompr.c --- zlib-1.1.4/uncompr.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/uncompr.c 2002-10-04 18:20:29.000000000 -0700 @@ -46,13 +46,13 @@ err = inflateInit(&stream); if (err != Z_OK) return err; - err = inflate(&stream, Z_FINISH); + err = inflate(0, &stream, Z_FINISH); if (err != Z_STREAM_END) { - inflateEnd(&stream); + inflateEnd(0, &stream); return err == Z_OK ? Z_BUF_ERROR : err; } *destLen = stream.total_out; - err = inflateEnd(&stream); + err = inflateEnd(0, &stream); return err; } diff -BburN zlib-1.1.4/zconf.h zlib-1.1.4-palm/zconf.h --- zlib-1.1.4/zconf.h 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/zconf.h 2002-12-09 17:06:48.000000000 -0800 @@ -210,18 +210,22 @@ # define FAR #endif -#if !defined(MACOS) && !defined(TARGET_OS_MAC) +#if !defined(MACOS) && !defined(TARGET_OS_MAC) && !defined(PALMOS) typedef unsigned char Byte; /* 8 bits */ #endif typedef unsigned int uInt; /* 16 bits or more */ typedef unsigned long uLong; /* 32 bits or more */ +#ifdef PALMOS +typedef unsigned char FAR Bytef; +#else #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 +#endif typedef char FAR charf; typedef int FAR intf; typedef uInt FAR uIntf; @@ -276,4 +280,57 @@ # pragma map(inflate_trees_free,"INTRFR") #endif +#ifdef PALMOS +#undef Byte + +#ifndef NEWGCC + +#pragma pack(2) +#include +#include +#include + +#else + +#include +#include + +#endif + +#include +#include + +#define NO_MEMCPY +#define MAXSEG_64K + +extern inline void zmemzero OF((Bytef* dst, uInt num)) +{ + while (num--) + *((char *) dst)++ = 0; +} + +extern inline void zmemcpy OF((Bytef* dst, const Bytef* src, uInt num)) +{ + while (num--) + *((char *) dst)++ = *((char *) src)++; +} + +extern inline int zmemcmp OF((const Bytef* dst, const Bytef* src, uInt num)) +{ + + while (num-- && (*((char *) dst)++ == *((char *) src)++)); + if (num >= 0) + return *--((char *) dst) - *--((char *) src); + else + return 0; +} + +#define inflate_mask(x) (0xffffU >> ( 16 - x )) + +#endif + +#ifdef ARMLET +#define inflate_mask(x) (0xffffU >> ( 16 - x )) +#endif + #endif /* _ZCONF_H */ diff -BburN zlib-1.1.4/zlib.h zlib-1.1.4-palm/zlib.h --- zlib-1.1.4/zlib.h 2002-03-11 05:56:38.000000000 -0800 +++ zlib-1.1.4-palm/zlib.h 2002-12-09 16:47:36.000000000 -0800 @@ -198,7 +198,7 @@ */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate OF((unsigned short d, 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 @@ -276,7 +276,7 @@ */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd OF((unsigned short d, z_streamp strm)); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any @@ -311,7 +311,7 @@ */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate OF((unsigned short d, z_streamp strm, int flush)); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may some @@ -380,7 +380,7 @@ */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd OF((unsigned short d, z_streamp strm)); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any @@ -605,8 +605,12 @@ utility functions can easily be modified if you need special options. */ +#ifndef PALMOS ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)); +#else +#define compress(a,b,c,d) compress2(a,b,c,d, Z_DEFAULT_COMPRESSION); +#endif /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total @@ -818,7 +822,7 @@ compression library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32 OF((unsigned short d, uLong adler, const Bytef *buf, uInt len)); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and @@ -835,7 +839,7 @@ if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32 OF((unsigned short d, 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 @@ -852,8 +856,39 @@ */ + /* various hacks, don't look :) */ +ZEXTERN int ZEXPORT deflateInit2_ OF((unsigned short d, z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); + +ZEXTERN int ZEXPORT inflateInit2_ OF((unsigned short d, z_streamp strm, int windowBits, + const char *version, int stream_size)); + +#ifdef PALMOS + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define deflateInit(a,b) deflateInit2_(0, a,b,Z_DEFLATED, MAX_WBITS,\ + DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, ZLIB_VERSION, sizeof(z_stream) ) + +#define deflateInit_(a,b,c,d) deflateInit2_(0, a,b, Z_DEFLATED, MAX_WBITS, \ + DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, c,d) +#define inflateInit(a) inflateInit2_(0, a, DEF_WBITS, ZLIB_VERSION,\ + sizeof(z_stream)) +#define inflateInit_(a,b,c) inflateInit2_(0, a, DEF_WBITS, b, c) + +#else /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ @@ -861,21 +896,19 @@ const char *version, int stream_size)); ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); + #define deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) #define inflateInit(strm) \ inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) + +#endif + #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + deflateInit2_(0, (strm),(level),(method),(windowBits),(memLevel),\ (strategy), ZLIB_VERSION, sizeof(z_stream)) #define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) + inflateInit2_(0, (strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) diff -BburN zlib-1.1.4/zlib_armlet.c zlib-1.1.4-palm/zlib_armlet.c --- zlib-1.1.4/zlib_armlet.c 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/zlib_armlet.c 2003-01-09 17:13:27.000000000 -0800 @@ -0,0 +1,265 @@ +/* zlib_armlet.c - functions for Palm OS armlet port + * first version by J.Clark (jclark@coopcomp.com) 11/11/02 + */ + +#include "PceNativeCall.h" +#include "endianutils.h" +#include "zlib.h" +#include "zlib_armlet.h" +#include "zutil.h" + + +/* IDs of the various traps we'll want to call from inside the ARMlet */ +#define sysTrapMemPtrNew 0xA013 // from CoreTraps.h +#define sysTrapMemChunkFree 0xA012 + + +/* Structure of data needed to call Palm OS functions through PACE */ +typedef struct pace_info_s +{ + void * emulStateP; + Call68KFuncType * call68KFuncP; + +} pace_info; + + +/* Function prototypes */ +void setr10(void*); +void copy_zstream_to_armlet (z_streamp _s1, z_streamp s2); +void copy_zstream_to_68k (z_streamp s2, z_streamp _s1); + + +/* Prototype for the dispatch function. Different for x86 vs. ARM */ +#ifdef WINDLL +/* x86 version */ +__declspec(dllexport) unsigned long zlib_armlet_dispatch ( + const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP); +#else +/* ARM version */ +unsigned long zlib_armlet_dispatch (const void *emulStateP, + void *userData68KP, Call68KFuncType *call68KFuncP); +#endif + + +/* =========================================================================== + * Extract parameters and call the various ZLib functions + */ +unsigned long zlib_armlet_dispatch (const void *emulStateP, + void *userData68KP, Call68KFuncType *call68KFuncP) +{ + long * gotP = 0; + z_streamp s_68k; + z_stream s_arm; + int flush; + zlib_armlet_params * params = (zlib_armlet_params *)userData68KP; + unsigned long function = ReadUnaligned32(&(params->function)); + unsigned long rval = 0; + long level; + long method; + long windowBits; + long memLevel; + long strategy; + char * version; + pace_info pi; + +#ifndef WINDLL + /* Byte-swap and set the got pointer */ + gotP = (long *) ByteSwap32(params->gotP); + setr10((void *) gotP); +#endif + + /* Make a local ARM-aligned copy of the zstream structure */ + s_68k = (z_streamp)ReadUnaligned32(&(params->strm)); + copy_zstream_to_armlet (s_68k, &s_arm); + + /* Store data needed to call Palm OS functions */ + pi.emulStateP = (void *)emulStateP; + pi.call68KFuncP = call68KFuncP; + + s_arm.zalloc = zcalloc; + s_arm.zfree = zcfree; + s_arm.opaque = (voidpf)π + + /* Setup params and call the various ZLib functions */ + switch (function) + { + case ZLAF_DEFLATEINIT2: + level = ReadUnaligned32(&(params->level)); + method = ReadUnaligned32(&(params->method)); + windowBits = ReadUnaligned32(&(params->windowBits)); + memLevel = ReadUnaligned32(&(params->memLevel)); + strategy = ReadUnaligned32(&(params->strategy)); + version = (char *)ReadUnaligned32(&(params->version)); + rval = deflateInit2_(0, &s_arm, level, method, windowBits, memLevel, + strategy, version, sizeof(z_stream)); + break; + + case ZLAF_DEFLATE: + flush = ReadUnaligned32(&(params->flush)); + rval = deflate (0, &s_arm, flush); + break; + + case ZLAF_DEFLATEEND: + rval = deflateEnd (0, &s_arm); + break; + + case ZLAF_INFLATEINIT2: + windowBits = ReadUnaligned32(&(params->windowBits)); + version = (char *)ReadUnaligned32(&(params->version)); + rval = inflateInit2_(0, &s_arm, windowBits, version, sizeof(z_stream)); + break; + + case ZLAF_INFLATE: + flush = ReadUnaligned32(&(params->flush)); + rval = inflate (0, &s_arm, flush); + break; + + case ZLAF_INFLATEEND: + rval = inflateEnd (0, &s_arm); + break; + } + + copy_zstream_to_68k (&s_arm, s_68k); + + return rval; +} + + +/* =========================================================================== + * Call MemPtrNew to allocate some memory. + */ +voidpf zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + unsigned long sizeLE, sizeBE; + pace_info * pi = (pace_info *)opaque; + + if (opaque) items += size - size; /* make compiler happy */ + + sizeLE = items * size; + sizeBE = ByteSwap32(sizeLE); + + return ((voidpf)((pi->call68KFuncP)( + pi->emulStateP, + PceNativeTrapNo(sysTrapMemPtrNew), + &sizeBE, + 4 | kPceNativeWantA0))); +} + + +/* =========================================================================== + * Call MemPtrFree to free some memory. + */ +void zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + unsigned long ptrBE; + pace_info * pi = (pace_info *)opaque; + + ptrBE = ByteSwap32(ptr); + (pi->call68KFuncP)(pi->emulStateP, PceNativeTrapNo(sysTrapMemChunkFree), + &ptrBE, 4); + if (opaque) return; /* make compiler happy */ +} + + +#define ReadUnaligned16(addr) \ +( ((((unsigned char *)(addr))[0]) << 8) | \ + ((((unsigned char *)(addr))[1])) ) + +#define WriteUnaligned16(addr, value) \ +( ((unsigned char *)(addr))[0] = (unsigned char)((unsigned long)(value) >> 8),\ + ((unsigned char *)(addr))[1] = (unsigned char)((unsigned long)(value)) ) + + +/* Offsets of the various members of the zstream structure, as generated by + * whoever compiled the 68K SysZLib.PRC code (ie m68k-palmos-gcc) + */ +#define ZSTREAM_SIZE 50 +#define OFS_NEXT_IN 0 +#define OFS_AVAIL_IN 4 +#define OFS_TOTAL_IN 6 +#define OFS_NEXT_OUT 10 +#define OFS_AVAIL_OUT 14 +#define OFS_TOTAL_OUT 16 +#define OFS_MSG 20 +#define OFS_STATE 24 +#define OFS_ZALLOC 28 +#define OFS_ZFREE 32 +#define OFS_OPAQUE 36 +#define OFS_DATA_TYPE 40 +#define OFS_ADLER 42 +#define OFS_RESERVED 46 + + +/* =========================================================================== + * Copy a 68K zstream structure into an ARM-aligned one. + */ +void copy_zstream_to_armlet (z_streamp _s1, z_streamp s2) +{ + unsigned char * s1 = (unsigned char *)_s1; + s2->next_in = (Bytef *)ReadUnaligned32(s1+OFS_NEXT_IN); + s2->avail_in = ReadUnaligned16(s1+OFS_AVAIL_IN); + s2->total_in = ReadUnaligned32(s1+OFS_TOTAL_IN); + s2->next_out = (Bytef *)ReadUnaligned32(s1+OFS_NEXT_OUT); + s2->avail_out = ReadUnaligned16(s1+OFS_AVAIL_OUT); + s2->total_out = ReadUnaligned32(s1+OFS_TOTAL_OUT); + s2->msg = (char *)ReadUnaligned32(s1+OFS_MSG); + s2->state = (struct internal_state FAR *)ReadUnaligned32(s1+OFS_STATE); + s2->zalloc = (alloc_func)ReadUnaligned32(s1+OFS_ZALLOC); + s2->zfree = (free_func)ReadUnaligned32(s1+OFS_ZFREE); + s2->opaque = (voidpf)ReadUnaligned32(s1+OFS_OPAQUE); + s2->data_type = ReadUnaligned16(s1+OFS_DATA_TYPE); + s2->adler = ReadUnaligned32(s1+OFS_ADLER); + s2->reserved = ReadUnaligned32(s1+OFS_RESERVED); +} + + +/* =========================================================================== + * Copy an ARM zstream structure back into 68K + */ +void copy_zstream_to_68k (z_streamp s2, z_streamp _s1) +{ + unsigned char * s1 = (unsigned char *)_s1; + WriteUnaligned32(s1+OFS_NEXT_IN, s2->next_in); + WriteUnaligned16(s1+OFS_AVAIL_IN, s2->avail_in); + WriteUnaligned32(s1+OFS_TOTAL_IN, s2->total_in); + WriteUnaligned32(s1+OFS_NEXT_OUT, s2->next_out); + WriteUnaligned16(s1+OFS_AVAIL_OUT, s2->avail_out); + WriteUnaligned32(s1+OFS_TOTAL_OUT, s2->total_out); + WriteUnaligned32(s1+OFS_MSG, s2->msg); + WriteUnaligned32(s1+OFS_STATE, s2->state); + WriteUnaligned32(s1+OFS_ZALLOC, s2->zalloc); + WriteUnaligned32(s1+OFS_ZFREE, s2->zfree); + WriteUnaligned32(s1+OFS_OPAQUE, s2->opaque); + WriteUnaligned16(s1+OFS_DATA_TYPE, s2->data_type); + WriteUnaligned32(s1+OFS_ADLER, s2->adler); + WriteUnaligned32(s1+OFS_RESERVED, s2->reserved); +} + + +/* =========================================================================== + * Main function for x86 DLL + */ +#ifdef WINDLL +int __cdecl DllMain( void * hModule, + unsigned long ul_reason_for_call, + unsigned long lpReserved) +{ + return 1; +} +#endif + + +/* =========================================================================== + * Function to set the r10 register to the GOT + */ +#ifndef WINDLL +void setr10(void* gotP) +{ + asm ("mov r10, r0"); +} +#endif diff -BburN zlib-1.1.4/zlib_armlet.h zlib-1.1.4-palm/zlib_armlet.h --- zlib-1.1.4/zlib_armlet.h 1969-12-31 16:00:00.000000000 -0800 +++ zlib-1.1.4-palm/zlib_armlet.h 2003-01-09 16:54:12.000000000 -0800 @@ -0,0 +1,37 @@ +/* zlib_armlet.h - interface into zlib armlet code + */ + +#ifndef _ZLIB_ARMLET_H +#define _ZLIB_ARMLET_H + + +/* The ZLib functions implemented in the ARMlet */ +#define ZLAF_DEFLATEINIT2 1 +#define ZLAF_DEFLATE 2 +#define ZLAF_DEFLATEEND 3 +#define ZLAF_INFLATEINIT2 4 +#define ZLAF_INFLATE 5 +#define ZLAF_INFLATEEND 6 + + +/* Structure used to pass parameters into the ARMlet */ +typedef struct zlib_armlet_params_s +{ + long * gotP; /* Pointer to the global offset table */ + unsigned long function; /* Index of the ZLib function to be called */ + + /* Parameters to the ZLib functions */ + z_streamp strm; + unsigned long flush; + long windowBits; + char * version; + long level; + long method; + long memLevel; + long strategy; + +} zlib_armlet_params; + + +#endif /* _ZLIB_ARMLET_H */ + diff -BburN zlib-1.1.4/zutil.c zlib-1.1.4-palm/zutil.c --- zlib-1.1.4/zutil.c 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/zutil.c 2002-12-10 11:04:13.000000000 -0800 @@ -13,6 +13,8 @@ extern void exit OF((int)); #endif +#if !(defined(PALMOS) || defined(ARMLET)) + const char *z_errmsg[10] = { "need dictionary", /* Z_NEED_DICT 2 */ "stream end", /* Z_STREAM_END 1 */ @@ -55,6 +57,9 @@ return ERR_MSG(err); } +#endif + +#ifndef PALMOS #ifndef HAVE_MEMCPY @@ -86,11 +91,14 @@ Bytef* dest; uInt len; { - if (len == 0) return; + if (len == 0 || dest == Z_NULL) + return; do { *dest++ = 0; /* ??? to be unrolled */ } while (--len != 0); } + +#endif #endif #ifdef __TURBOC__ @@ -210,8 +218,28 @@ unsigned items; unsigned size; { +#ifndef PALMOS if (opaque) items += size - size; /* make compiler happy */ return (voidpf)calloc(items, size); +#else + voidpf x; + UInt32 free, max; + + x = (voidpf) malloc(items*size); + + if(x == Z_NULL) + { + MemHeapFreeBytes(0, &free, &max); + if(items*size > max) + MemHeapCompact(0); + MemHeapFreeBytes(0, &free, &max); + if(max >= size) + x = (voidpf) malloc(items*size); + } + if(x != Z_NULL) + zmemzero(x,items*size); + return x; +#endif } void zcfree (opaque, ptr) diff -BburN zlib-1.1.4/zutil.h zlib-1.1.4-palm/zutil.h --- zlib-1.1.4/zutil.h 2002-03-11 05:16:01.000000000 -0800 +++ zlib-1.1.4-palm/zutil.h 2003-01-09 12:33:05.000000000 -0800 @@ -15,7 +15,7 @@ #include "zlib.h" -#ifdef STDC +#if defined(STDC) && !defined(PALMOS) # include # include # include @@ -27,7 +27,11 @@ #endif #ifndef local +# ifdef ARMLET +# define local +# else # define local static +# endif #endif /* compile with -Dlocal if your debugger can't find static symbols */ @@ -37,10 +41,14 @@ typedef ush FAR ushf; typedef unsigned long ulg; +#if !(defined(PALMOS) || defined(ARMLET)) extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#else +#define ERR_MSG(err) "" +#endif #define ERR_RETURN(strm,err) \ return (strm->msg = (char*)ERR_MSG(err), (err)) @@ -207,7 +215,7 @@ #endif -typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, +typedef uLong (ZEXPORT *check_func) OF((unsigned short d, uLong check, const Bytef *buf, uInt len)); voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); void zcfree OF((voidpf opaque, voidpf ptr));