Commit 9e67a19e authored by Jeffrey Lee's avatar Jeffrey Lee

Add initial version of ZLib module

Detail:
  This is a clone of RISCOS Ltd's ZLib module, produced by reading the documentation available on their website
  At the moment the module is still in development, but once finished it should be functionaly equivalent to their module from the users perspective
  In reality the module is based around a newer version of zlib (1.2.5 + tweaks) than the version RISCOS Ltd are believed to be using (1.1.4 + double-free fix)
Admin:
  Compiles but entirely untested.
  Error messages need sorting out, and there are plenty of TODO's in the sources which will need sorting before the module can be put to use.


Version 0.01. Tagged as 'ZLib-0_01'
parent a9992041
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine standalone
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine clean
remove rm.DbgMess
stripdepnd
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine export
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine all THROWBACK=-throwback
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine all THROWBACK=-throwback DEBUG=TRUE
| Copyright (c) 2012, RISC OS Open Ltd
| All rights reserved.
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
| * Redistributions of source code must retain the above copyright
| notice, this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of RISC OS Open Ltd nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
| POSSIBILITY OF SUCH DAMAGE.
|
Dir <Obey$Dir>
amu_machine rom
hdr/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
cmhg/** gitlab-language=cmhg linguist-language=cmhg linguist-detectable=true
#
# Copyright (c) 2012, RISC OS Open Ltd
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of RISC OS Open Ltd nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Makefile for ZLib module
#
# $Id$
DEBUG ?= FALSE
ifeq ($(DEBUG),TRUE)
CFLAGS += -DDEBUGLIB
CMHGFLAGS += -DDEBUGLIB
LIBS = ${DEBUGLIBS} ${NET5LIBS}
endif
COMPONENT = ZLib
OBJS = cmodule
CMHGFILE = modhead
HDRS =
ASMHDRS = ZLib
LIBS += C:zlib.o.zlibzm
CINCLUDES = -Itbox:
CFLAGS += -ff -wp -wc
CMHGDEFINES = -DCOMPONENT=${COMPONENT}
CMHGDEPENDS = cmodule
RAMCDEFINES = -DSTANDALONE
RES_OBJ = # fudge
include CModule
# Dynamic dependencies:
/* (0.00)
/* (0.01)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.00
#define Module_MajorVersion_CMHG 0.01
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 04 Feb 2012
#define Module_MajorVersion "0.00"
#define Module_Version 0
#define Module_MajorVersion "0.01"
#define Module_Version 1
#define Module_MinorVersion ""
#define Module_Date "04 Feb 2012"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "ZLib"
#define Module_ComponentPath "bsd/RiscOS/Sources/Programmer/ZLib"
#define Module_FullVersion "0.00"
#define Module_HelpVersion "0.00 (04 Feb 2012)"
#define Module_LibraryVersionInfo "0:0"
#define Module_FullVersion "0.01"
#define Module_HelpVersion "0.01 (04 Feb 2012)"
#define Module_LibraryVersionInfo "0:1"
/*
*Copyright(c)2012, RISC OS Open Ltd
*Allrightsreserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of RISC OS Open Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "modhead.h"
#include "swis.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include "Global/RISCOS.h"
#include "Global/Services.h"
#include "DebugLib/DebugLib.h"
#include "globals.h"
void *private_word;
#define ERROR(X) (_kernel_oserror *) ("\0\0\0\0" X)
_kernel_oserror* module_init (const char *cmd_tail, int podule_base, void *pw)
{
(void) cmd_tail;
(void) podule_base;
(void) pw;
/* set up debugging */
debug_initialise(Module_Title, "", "");
debug_set_device(DADEBUG_OUTPUT);
debug_set_unbuffered_files(TRUE);
private_word = pw;
return NULL;
}
_kernel_oserror *module_final(int fatal, int podule, void *pw)
{
(void) fatal;
(void) podule;
(void) pw;
/* TODO - Complain if stuff still active? */
return NULL;
}
static _kernel_oserror *do_gzopen(_kernel_swi_regs *r)
{
/* This is a mess */
const char *mode = (const char *) r->r[1];
char newmode[strlen(mode)+1];
char *c = newmode;
bool AC = false;
bool reading = false;
_kernel_oserror *e = NULL;
while(*mode)
{
if(*mode == 'R')
{
/* Use 'R' to trigger read/write of RISC OS metadata, like ROL's version does. This means there's no way of requesting RLE compression using the SWI interface. */
AC = true;
mode++;
}
if(*mode == 'r')
{
/* Make a note of whether we're reading or writing */
reading = true;
}
if(*mode)
{
*c++ = *mode++;
}
}
*c = 0;
/* Open the file */
gzFile file = gzopen((const char *) r->r[0], newmode);
r->r[0] = (int) file;
if(!file || !AC)
return NULL;
/* Read/write header */
gz_header header;
memset(&header, 0, sizeof(header));
if(reading)
{
/* Allocate some space for the extra field; assume 1K is enough */
Bytef *extra = (Bytef *) malloc(1024);
if(!extra)
{
/* Oh, crumbs */
gzclose(file);
e = ERROR("Out of memory!");
return e;
}
header.extra = extra;
header.extra_max = 1024;
if(gzgetheader(file, &header) < 0)
{
gzclose(file);
free(extra);
e = ERROR("Failed reading header");
return e;
}
/* Scan for 'AC' subfield */
int remain = header.extra_len;
Bytef *b = extra;
while(remain >= 4)
{
Bytef si1 = *b++;
Bytef si2 = *b++;
unsigned short len = *b++;
len += (*b++)<<8;
remain -= 4;
if((si1 == 'A') && (si2 == 'C') && (len >= 28) && (remain >= 16))
{
/* We found it! */
memcpy(&r->r[2],b,16);
int temp = r->r[4];
r->r[4] = r->r[5];
r->r[5] = temp;
break;
}
else
{
b += len;
remain -= len;
}
}
free(extra);
}
else
{
/* Construct the field on the stack */
int field[8];
field[0] = 0x001c4341;
field[1] = r->r[2];
field[2] = r->r[3];
field[3] = r->r[5];
field[4] = r->r[4];
field[5] = 0;
field[6] = 0;
field[7] = 0;
/* Fill in the main header */
header.extra = (Bytef *) field;
header.extra_len = 32;
header.os = 0xd;
if(gzputheader(file, &header) < 0)
{
gzclose(file);
e = ERROR("Failed writing header");
return e;
}
}
return NULL;
}
_kernel_oserror *module_swis(int swi_offset, _kernel_swi_regs *r, void *pw)
{
(void) pw;
int flags;
int ret;
z_streamp stream;
switch(swi_offset)
{
case ZLib_Compress:
flags = r->r[0];
if(flags & ~COMPRESS_VALID_FLAGS)
return ERROR("Invalid ZLib_Compress flag");
if(flags & COMPRESS_FLAG_RETURNWORKSPACE)
{
r->r[0] = sizeof(z_stream);
if(r->r[1] != -1)
{
r->r[1] = (int) compressBound((uLong) r->r[1]);
}
return NULL;
}
stream = (z_streamp) r->r[1];
if(!(flags & COMPRESS_FLAG_CONTINUE))
{
stream->zalloc = NULL;
stream->zfree = NULL;
stream->opaque = NULL;
ret = deflateInit(stream,9); /* Assume best compression wanted? */
if(ret)
{
return ERROR("ZLib error");
}
/* TODO - workspace binding flag */
}
stream->next_in = (Bytef *) r->r[2];
stream->avail_in = (uInt) r->r[3];
stream->next_out = (Bytef *) r->r[4];
stream->avail_out = (uInt) r->r[5];
ret = deflate(stream,(flags & COMPRESS_FLAG_MOREREMAINING?0:Z_FINISH)); /* TODO - Only specify Z_FINISH if no input data? */
r->r[2] = (int) stream->next_in;
r->r[3] = (int) stream->avail_in;
r->r[4] = (int) stream->next_out;
r->r[5] = (int) stream->avail_out;
switch(ret)
{
case Z_OK:
case Z_BUF_ERROR:
r->r[0] = (r->r[2]?COMPRESS_NEED_OUTPUT:COMPRESS_NEED_INPUT); /* TODO - May be wrong for Z_OK */
return NULL;
case Z_STREAM_END:
r->r[0] = COMPRESS_COMPLETE;
deflateEnd(stream);
return NULL;
default:
return ERROR("ZLib error");
}
case ZLib_Decompress:
flags = r->r[0];
if(flags & ~DECOMPRESS_VALID_FLAGS)
return ERROR("Invalid ZLib_Decompress flag");
if(flags & DECOMPRESS_FLAG_RETURNWORKSPACE)
{
r->r[0] = sizeof(z_stream);
r->r[1] = -1; /* Fairly certain it's impossible/impractical to calculate this */
return NULL;
}
stream = (z_streamp) r->r[1];
if(!(flags & DECOMPRESS_FLAG_CONTINUE))
{
stream->zalloc = NULL;
stream->zfree = NULL;
stream->opaque = NULL;
ret = inflateInit(stream);
if(ret)
{
return ERROR("ZLib error");
}
/* TODO - workspace binding flag */
}
stream->next_in = (Bytef *) r->r[2];
stream->avail_in = (uInt) r->r[3];
stream->next_out = (Bytef *) r->r[4];
stream->avail_out = (uInt) r->r[5];
ret = deflate(stream,((flags & DECOMPRESS_FLAG_MOREREMAINING) && !(flags & DECOMPRESS_FLAG_ASSUMEWILLFIT)?0:Z_FINISH)); /* TODO - ROL docs are vague for whether ASSUMEWILLFIT actually does anything */
r->r[2] = (int) stream->next_in;
r->r[3] = (int) stream->avail_in;
r->r[4] = (int) stream->next_out;
r->r[5] = (int) stream->avail_out;
switch(ret)
{
case Z_OK:
case Z_BUF_ERROR:
r->r[0] = (r->r[2]?DECOMPRESS_NEED_OUTPUT:DECOMPRESS_NEED_INPUT); /* TODO - May be wrong for Z_OK */
return NULL;
case Z_STREAM_END:
r->r[0] = DECOMPRESS_COMPLETE;
inflateEnd(stream);
return NULL;
default:
return ERROR("ZLib error");
}
case ZLib_CRC32:
r->r[0] = (int) crc32((uLong) r->r[0], (const Bytef *) r->r[1], (uInt) (r->r[2]-r->r[1]));
return NULL;
case ZLib_Adler32:
r->r[0] = (int) adler32((uLong) r->r[0], (const Bytef *) r->r[1], (uInt) (r->r[2]-r->r[1]));
return NULL;
case ZLib_Version:
r->r[0] = (int) zlib_version;
return NULL;
case ZLib_ZCompress:
r->r[0] = compress((Bytef *) r->r[0], (uLongf *) &r->r[1], (const Bytef *) r->r[2], (uLong) r->r[3]);
return NULL;
case ZLib_ZCompress2:
r->r[0] = compress2((Bytef *) r->r[0], (uLongf *) &r->r[1], (const Bytef *) r->r[2], (uLong) r->r[3], r->r[4]);
return NULL;
case ZLib_ZUncompress:
r->r[0] = uncompress((Bytef *) r->r[0], (uLongf *) &r->r[1], (const Bytef *) r->r[2], (uLong) r->r[3]);
return NULL;
case ZLib_DeflateInit:
r->r[0] = deflateInit_((z_streamp) r->r[0], r->r[1], (const char *) r->r[2], r->r[3]);
return NULL;
case ZLib_InflateInit:
r->r[0] = inflateInit_((z_streamp) r->r[0], (const char *) r->r[1], r->r[2]);
return NULL;
case ZLib_DeflateInit2:
r->r[0] = deflateInit2_((z_streamp) r->r[0], r->r[1], r->r[2], r->r[3], r->r[4], r->r[5], (const char *) r->r[6], r->r[7]);
return NULL;
case ZLib_InflateInit2:
r->r[0] = inflateInit2_((z_streamp) r->r[0], r->r[1], (const char *) r->r[2], r->r[3]);
return NULL;
case ZLib_Deflate:
r->r[0] = deflate((z_streamp) r->r[0], r->r[1]);
return NULL;
case ZLib_DeflateEnd:
r->r[0] = deflateEnd((z_streamp) r->r[0]);
return NULL;
case ZLib_Inflate:
r->r[0] = inflate((z_streamp) r->r[0], r->r[1]);
return NULL;
case ZLib_InflateEnd:
r->r[0] = inflateEnd((z_streamp) r->r[0]);
return NULL;
case ZLib_DeflateSetDictionary:
r->r[0] = deflateSetDictionary((z_streamp) r->r[0], (const Bytef *) r->r[1], (uInt) r->r[2]);
return NULL;
case ZLib_DeflateCopy:
r->r[0] = deflateCopy((z_streamp) r->r[0], (z_streamp) r->r[1]);
return NULL;
case ZLib_DeflateReset:
r->r[0] = deflateReset((z_streamp) r->r[0]);
return NULL;
case ZLib_DeflateParams:
r->r[0] = deflateParams((z_streamp) r->r[0], r->r[1], r->r[2]);
return NULL;
case ZLib_InflateSetDictionary:
r->r[0] = inflateSetDictionary((z_streamp) r->r[0], (const Bytef *) r->r[1], (uInt) r->r[2]);
return NULL;
case ZLib_InflateSync:
r->r[0] = inflateSync((z_streamp) r->r[0]);
return NULL;
case ZLib_InflateReset:
r->r[0] = inflateReset((z_streamp) r->r[0]);
return NULL;
case ZLib_GZOpen:
return do_gzopen(r);
case ZLib_GZRead:
r->r[0] = gzread((gzFile) r->r[0], (voidp) r->r[1], r->r[2]);
return NULL;
case ZLib_GZWrite:
r->r[0] = gzwrite((gzFile) r->r[0], (const voidp) r->r[1], r->r[2]);
return NULL;
case ZLib_GZFlush:
r->r[0] = gzflush((gzFile) r->r[0], r->r[1]);
return NULL;
case ZLib_GZClose:
r->r[0] = gzclose((gzFile) r->r[0]);
/* TODO - Set filetype to &F89 */
return NULL;
case ZLib_GZError:
/* TODO - Is R1 correct? */
r->r[0] = (int) gzerror((gzFile) r->r[0], &r->r[1]);
return NULL;
case ZLib_GZSeek:
/* TODO - Translate R2? */
r->r[0] = (int) gzseek((gzFile) r->r[0], (z_off_t) r->r[1], r->r[2]);
return NULL;
case ZLib_GZTell:
r->r[0] = (int) gztell((gzFile) r->r[0]);
return NULL;
case ZLib_GZEOF:
r->r[0] = (int) gzeof((gzFile) r->r[0]);
return NULL;
case ZLib_TaskAssociate:
return ERROR("Unimplemented"); /* TODO! Need to listen out for Service_WimpCloseDown? How to be sure that stream memory is available so we can free it? Free internal_state manually? Or construct fake stream? Could be dangerous, *End() functions check state. And what if custom alloc/free in use? */
default:
return ERROR("No such SWI");
}
}
; Copyright (c) 2012, RISC OS Open Ltd
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name of RISC OS Open Ltd nor the names of its contributors
; may be used to endorse or promote products derived from this software
; without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
;
#include "Global/RISCOS.h"
#include "Global/Services.h"
#include "../VersionNum"
initialisation-code: module_init
finalisation-code: module_final
title-string: COMPONENT
help-string: COMPONENT Module_MajorVersion_CMHG
date-string: Module_Date_CMHG
swi-chunk-base-number: 0x53ac0
swi-handler-code: module_swis
swi-decoding-table: ZLib,
Compress,
Decompress,
CRC32,
Adler32,
Version,
ZCompress,
ZCompress2,
ZUncompress,
DeflateInit,
InflateInit,
DeflateInit2,
InflateInit2,
Deflate,
DeflateEnd,