Commit e76eed99 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Initial commit

parents
SOURCES_CXX :=
SOURCES_C :=
DEPS_DIR := $(CORE_DIR)/deps
LIBRETRO_DIR := $(CORE_DIR)/libretro-common
LIBKIRK_DIR := $(DEPS_DIR)/libkirk
MEDNAFEN_DIR := $(CORE_DIR)/mednafen
CORE_EMU_DIR := $(MEDNAFEN_DIR)/psx
RSXGL_DIR := $(CORE_DIR)/rustation-libretro/src
ifeq ($(HAVE_OPENGL), 1)
ifeq ($(GLES), 1)
GLFLAGS := -DHAVE_OPENGLES -DHAVE_OPENGLES2
CFLAGS += $(GLFLAGS)
CXXFLAGS += $(GLFLAGS)
SOURCES_C += $(LIBRETRO_DIR)/glsym/glsym_es2.c
else
GLFLAGS := -DHAVE_OPENGL -DCORE
CFLAGS += $(GLFLAGS)
CXXFLAGS += $(GLFLAGS)
SOURCES_C += $(LIBRETRO_DIR)/glsym/glsym_gl.c
endif
SOURCES_C += $(LIBRETRO_DIR)/glsm/glsm.c \
$(LIBRETRO_DIR)/glsym/rglgen.c
SOURCES_CXX += $(CORE_DIR)/rsx/rsx_lib_gl.cpp
### Rust-to-Cpp translated GL renderer
SOURCES_CXX += \
$(RSXGL_DIR)/renderer/GlRenderer.cpp \
$(RSXGL_DIR)/retrogl/error.cpp \
$(RSXGL_DIR)/retrogl/framebuffer.cpp \
$(RSXGL_DIR)/retrogl/program.cpp \
$(RSXGL_DIR)/retrogl/shader.cpp \
$(RSXGL_DIR)/retrogl/texture.cpp \
$(RSXGL_DIR)/retrogl/vertex.cpp \
$(RSXGL_DIR)/retrogl/retrogl.cpp
endif
INCFLAGS := -I$(CORE_DIR) -I$(MEDNAFEN_DIR) -I$(MEDNAFEN_DIR)/include -I$(MEDNAFEN_DIR)/intl -I$(MEDNAFEN_DIR)/hw_sound -I$(MEDNAFEN_DIR)/hw_cpu -I$(MEDNAFEN_DIR)/hw_misc -I$(LIBRETRO_DIR)/include -I$(DEPS_DIR)/zlib
SOURCES_C += $(DEPS_DIR)/zlib/adler32.c \
$(DEPS_DIR)/zlib/compress.c \
$(DEPS_DIR)/zlib/crc32.c \
$(DEPS_DIR)/zlib/deflate.c \
$(DEPS_DIR)/zlib/gzclose.c \
$(DEPS_DIR)/zlib/gzlib.c \
$(DEPS_DIR)/zlib/gzread.c \
$(DEPS_DIR)/zlib/gzwrite.c \
$(DEPS_DIR)/zlib/inffast.c \
$(DEPS_DIR)/zlib/inflate.c \
$(DEPS_DIR)/zlib/inftrees.c \
$(DEPS_DIR)/zlib/trees.c \
$(DEPS_DIR)/zlib/uncompr.c \
$(DEPS_DIR)/zlib/zutil.c
ifeq ($(HAVE_GRIFFIN),1)
SOURCES_CXX += beetle_psx_griffin.cpp \
$(CORE_EMU_DIR)/dma.cpp \
$(CORE_EMU_DIR)/sio.cpp
SOURCES_C += beetle_psx_griffin_c.c
endif
ifeq ($(DEBUG), 1)
SOURCES_CXX += $(CORE_EMU_DIR)/dis.cpp
endif
ifeq ($(NEED_THREADING), 1)
FLAGS += -DWANT_THREADING -DHAVE_THREADS
endif
ifeq ($(NEED_CRC32), 1)
FLAGS += -DWANT_CRC32
SOURCES_C += $(CORE_DIR)/scrc32.c
endif
ifeq ($(NEED_DEINTERLACER), 1)
FLAGS += -DNEED_DEINTERLACER
endif
ifeq ($(IS_X86), 1)
FLAGS += -DARCH_X86
endif
ifeq ($(NEED_BPP), 8)
FLAGS += -DWANT_8BPP
endif
ifeq ($(NEED_BPP), 16)
FLAGS += -DWANT_16BPP
endif
ifeq ($(NEED_BPP), 32)
FLAGS += -DWANT_32BPP
endif
ifeq ($(WANT_NEW_API), 1)
FLAGS += -DWANT_NEW_API
endif
ifeq ($(NO_COMPUTED_GOTO), 1)
FLAGS += -DNO_COMPUTED_GOTO
endif
ifeq ($(FRONTEND_SUPPORTS_RGB565), 1)
FLAGS += -DFRONTEND_SUPPORTS_RGB565
endif
ifeq ($(NEED_CD), 1)
FLAGS += -DNEED_CD
endif
ifeq ($(NEED_TREMOR), 1)
FLAGS += -DNEED_TREMOR
endif
ifneq ($(HAVE_GRIFFIN), 1)
SOURCES_CXX += \
$(CORE_EMU_DIR)/irq.cpp \
$(CORE_EMU_DIR)/timer.cpp \
$(CORE_EMU_DIR)/dma.cpp \
$(CORE_EMU_DIR)/frontio.cpp \
$(CORE_EMU_DIR)/sio.cpp \
$(CORE_EMU_DIR)/cpu.cpp \
$(CORE_EMU_DIR)/gte.cpp \
$(CORE_EMU_DIR)/cdc.cpp \
$(CORE_EMU_DIR)/spu.cpp \
$(CORE_EMU_DIR)/gpu.cpp \
$(CORE_EMU_DIR)/mdec.cpp \
$(CORE_EMU_DIR)/input/gamepad.cpp \
$(CORE_EMU_DIR)/input/dualanalog.cpp \
$(CORE_EMU_DIR)/input/dualshock.cpp \
$(CORE_EMU_DIR)/input/justifier.cpp \
$(CORE_EMU_DIR)/input/guncon.cpp \
$(CORE_EMU_DIR)/input/negcon.cpp \
$(CORE_EMU_DIR)/input/memcard.cpp \
$(CORE_EMU_DIR)/input/multitap.cpp \
$(CORE_EMU_DIR)/input/mouse.cpp
ifeq ($(HAVE_JIT), 1)
SOURCES_CXX += $(CORE_EMU_DIR)/decomp.cpp
endif
SOURCES_C += $(CORE_DIR)/libretro_cbs.c
ifeq ($(NEED_TREMOR), 1)
SOURCES_C += $(wildcard $(MEDNAFEN_DIR)/tremor/*.c)
endif
ifeq ($(NEED_CD), 1)
SOURCES_CXX += $(MEDNAFEN_DIR)/cdrom/CDAccess.cpp \
$(MEDNAFEN_DIR)/cdrom/CDAccess_Image.cpp \
$(MEDNAFEN_DIR)/cdrom/CDAccess_CCD.cpp \
$(MEDNAFEN_DIR)/cdrom/CDAccess_PBP.cpp \
$(MEDNAFEN_DIR)/cdrom/SimpleFIFO.cpp \
$(MEDNAFEN_DIR)/cdrom/audioreader.cpp \
$(MEDNAFEN_DIR)/cdrom/misc.cpp \
$(MEDNAFEN_DIR)/cdrom/cdromif.cpp
endif
SOURCES_C += \
$(MEDNAFEN_DIR)/cdrom/CDUtility.c \
$(MEDNAFEN_DIR)/cdrom/galois.c \
$(MEDNAFEN_DIR)/cdrom/l-ec.c \
$(MEDNAFEN_DIR)/cdrom/lec.c \
$(MEDNAFEN_DIR)/cdrom/recover-raw.c \
$(MEDNAFEN_DIR)/cdrom/edc_crc32.c
SOURCES_CXX += \
$(MEDNAFEN_DIR)/error.cpp \
$(MEDNAFEN_DIR)/settings.cpp \
$(MEDNAFEN_DIR)/general.cpp \
$(MEDNAFEN_DIR)/FileStream.cpp \
$(MEDNAFEN_DIR)/MemoryStream.cpp \
$(MEDNAFEN_DIR)/Stream.cpp \
$(MEDNAFEN_DIR)/state.cpp \
$(MEDNAFEN_DIR)/mempatcher.cpp \
$(MEDNAFEN_DIR)/video/Deinterlacer.cpp \
$(MEDNAFEN_DIR)/video/surface.cpp \
$(CORE_DIR)/libretro.cpp
SOURCES_C += \
$(MEDNAFEN_DIR)/file.c \
$(CORE_DIR)/rsx/rsx_lib_soft.c \
$(MEDNAFEN_DIR)/md5.c \
$(MEDNAFEN_DIR)/mednafen-endian.c
SOURCES_CXX += $(CORE_DIR)/rsx/rsx_intf.cpp
ifneq ($(STATIC_LINKING), 1)
SOURCES_C += $(LIBRETRO_DIR)/streams/file_stream.c \
$(LIBRETRO_DIR)/string/stdstring.c
SOURCES_C += $(LIBKIRK_DIR)/aes.c \
$(LIBKIRK_DIR)/amctrl.c \
$(LIBKIRK_DIR)/bn.c \
$(LIBKIRK_DIR)/des.c \
$(LIBKIRK_DIR)/ec.c \
$(LIBKIRK_DIR)/kirk_engine.c \
$(LIBKIRK_DIR)/sha1.c
ifeq ($(NEED_THREADING), 1)
SOURCES_C += $(LIBRETRO_DIR)/rthreads/rthreads.c
endif
endif
endif
SOURCES_C += $(LIBRETRO_DIR)/file/retro_stat.c
# Beetle PSX libretro
This is fork of Mednafen PSX. It has been ported to the libretro API.
It currently runs on Linux, OSX and possibly Windows.
## Running
To run this core, the "system directory" must be defined if running in RetroArch.
The PSX BIOS must be placed there, $sysdir/SCPH550{0,1,2} for Japanese, NA and EU regions respectively.
Memory cards will be saved to "save directory", memory card #1 is saved using libretro's standard interface. The rest of memory cards are saved using Mednafen's starndard mechanism. You might have to rename your old
memory cards to gamename.srm. Alternatively you may just rename it from gamename.gamenamehash.0.mcr to gamename.gamenamehash.1.mcr and load them off the corresponding slot.
Core now supports save states. Keep in mind states might result on loss your memorycards if you are careless.
## Loading ISOs
Beetle differs from other PS1 emulators in that it needs a cue-sheets that points to an image file, usually an .iso/.bin file.
If you have e.g. <tt>foo.iso</tt>, you should create a foo.cue, and fill this in:
FILE "foo.iso" BINARY
TRACK 01 MODE1/2352
INDEX 01 00:00:00
After that, you can load the <tt>foo.cue</tt> file as a ROM.
Note that this is a dirty hack and will not work on all games.
Ideally, make sure to use rips that have cue-sheets.
If foo is a multiple-disk game, you should have .cue files for each one, e.g. <tt>foo (Disc 1).cue</tt>, <tt>foo (Disc 2).cue</tt>, <tt>foo (Disc 3).cue</tt>.To take advantage of Beetle's Disk Control feature for disk swapping, an index file should be made.
Open a text file and enter your game's .cue files on it, like this:
foo (Disc 1).cue
foo (Disc 2).cue
foo (Disc 3).cue
Save as foo.m3u and use this file in place of each disk's individual cue sheet.
## Condensing Games
Alternatively to using cue sheets with .bin/.iso files, you can convert your games to .pbp (Playstation Portable update file) to reduce file sizes and neaten up your game folder. If converting a multiple-disk game, all disks should be added to the same .bpb file, rather than making a .m3u file for them.
Most conversion tools will want a single .bin/.iso file for each disk. If your game uses multiple .bin files (tracks) per disk, you will have to mount the cue sheet to a virtual drive and re-burn the images onto a single track before conversion.
Note that RetroArch does not currently have .pbp database due to variability in users' conversion methods. All .pbp games will have to be added to playlists manually.
## Suggested Firmware
- scph5500.bin (8dd7d5296a650fac7319bce665a6a53c)
- scph5501.bin (490f666e1afb15b7362b406ed1cea246)
- scph5502.bin (32736f17079d0b2b7024407c39bd3050)
## Options
* CD Image Cache - Loads the complete image in memory at startup
* PSX Dithering - Enables Dithering
* PSX Initial Scanline - Sets the first scanline to be drawn on screen
* PSX Initial Scanline PAL - Sets the first scanline to be drawn on screen for PAL systems
* PSX Last Scanline - Sets the last scanline to be drawn on screen
* PSX Last Scanline PAL - Sets the last scanline to be drawn on screen for PAL systems
* Dualshock analog toggle - Enables/Disables the analog button from Dualshock controllers, if disabled analogs are always on, if enabled you can toggle it's state with START+SELECT+L1+L2+R1+R2
* Port 1 PSX Enable Multitap - Enables/Disables multitap functionality on port 1
* Port 2 PSX Enable Multitap - Enables/Disables multitap functionality on port 2
#include "mednafen/psx/irq.cpp"
#include "mednafen/psx/timer.cpp"
#include "mednafen/psx/frontio.cpp"
#include "mednafen/psx/cpu.cpp"
#include "mednafen/psx/gte.cpp"
#include "mednafen/psx/dis.cpp"
#include "mednafen/psx/cdc.cpp"
#include "mednafen/psx/spu.cpp"
#include "mednafen/psx/gpu.cpp"
#include "mednafen/psx/mdec.cpp"
#include "mednafen/psx/input/gamepad.cpp"
#include "mednafen/psx/input/dualanalog.cpp"
#include "mednafen/psx/input/dualshock.cpp"
#include "mednafen/psx/input/justifier.cpp"
#include "mednafen/psx/input/guncon.cpp"
#include "mednafen/psx/input/negcon.cpp"
#include "mednafen/psx/input/memcard.cpp"
#include "mednafen/psx/input/multitap.cpp"
#include "mednafen/psx/input/mouse.cpp"
#include "mednafen/error.cpp"
#include "mednafen/settings.cpp"
#include "mednafen/general.cpp"
#include "mednafen/FileStream.cpp"
#include "mednafen/MemoryStream.cpp"
#include "mednafen/Stream.cpp"
#include "mednafen/state.cpp"
#ifdef NEED_CD
#include "mednafen/cdrom/CDAccess.cpp"
#include "mednafen/cdrom/CDAccess_Image.cpp"
#include "mednafen/cdrom/CDAccess_CCD.cpp"
#include "mednafen/cdrom/CDAccess_PBP.cpp"
#include "mednafen/cdrom/SimpleFIFO.cpp"
#include "mednafen/cdrom/audioreader.cpp"
#include "mednafen/cdrom/cdromif.cpp"
#include "mednafen/cdrom/misc.cpp"
#endif
#include "mednafen/mempatcher.cpp"
#include "mednafen/video/Deinterlacer.cpp"
#include "mednafen/video/surface.cpp"
#include "libretro.cpp"
#include "rsx/rsx_intf.cpp"
#include "mednafen/tremor/codebook.c"
#include "mednafen/tremor/floor0.c"
#include "mednafen/tremor/floor1.c"
#include "mednafen/tremor/mdct.c"
#include "mednafen/tremor/registry.c"
#include "mednafen/tremor/mapping0.c"
#include "mednafen/tremor/info.c"
#include "mednafen/tremor/res012.c"
#include "mednafen/tremor/framing.c"
#include "mednafen/tremor/block.c"
#include "mednafen/tremor/sharedbook.c"
#include "mednafen/tremor/synthesis.c"
#include "mednafen/tremor/vorbisfile.c"
#include "mednafen/tremor/bitwise.c"
#include "mednafen/tremor/window.c"
#include "mednafen/file.c"
#include "mednafen/md5.c"
#include "mednafen/mednafen-endian.c"
#include "libretro_cbs.c"
#include "libretro-common/streams/file_stream.c"
#include "libretro-common/rthreads/rthreads.c"
#include "libretro-common/string/stdstring.c"
#include "scrc32.c"
#include "rsx/rsx_lib_soft.c"
#ifdef NEED_CD
#include "mednafen/cdrom/CDUtility.c"
#include "mednafen/cdrom/edc_crc32.c"
#include "mednafen/cdrom/l-ec.c"
#include "mednafen/cdrom/lec.c"
#include "mednafen/cdrom/recover-raw.c"
#include "mednafen/cdrom/galois.c"
#endif
#include "deps/libkirk/aes.c"
#include "deps/libkirk/amctrl.c"
#include "deps/libkirk/bn.c"
#include "deps/libkirk/des.c"
#include "deps/libkirk/ec.c"
#include "deps/libkirk/kirk_engine.c"
#include "deps/libkirk/sha1.c"
#include <jit/jit.h>
#include <stdint.h>
// This is passed as an array of uint32_t
typedef struct state_s {
uint32_t reg[32];
uint32_t pc;
uint32_t hi, lo;
} state_t;
bool decompile(jit_function_t func, jit_value_t state, uint32_t pc, uint32_t inst, bool &branched);
jit_value_t _make_uint(jit_function_t func, uint32_t val) {
return jit_value_create_nint_constant(func, jit_type_uint, val);
}
#define make_uint(val) _make_uint(func, (val))
jit_type_t sig_1, sig_2, sig_3;
void store_memory(int size, uint32_t ptr, uint32_t val) {
}
void call_store_memory(jit_function_t func, int size, jit_value_t ptr, jit_value_t val) {
jit_value_t args[] = {make_uint(size), ptr, val};
jit_insn_call_native(func, 0, (void *) store_memory, sig_3, args, 3, 0);
}
uint32_t load_memory(int size, uint32_t ptr) {
return 0;
}
jit_value_t call_load_memory(jit_function_t func, int size, jit_value_t ptr) {
jit_value_t args[] = {make_uint(size), ptr};
return jit_insn_call_native(func, 0, (void *) load_memory, sig_2, args, 2, 0);
}
uint32_t read_copreg(int cop, int reg) {
return 0;
}
jit_value_t call_read_copreg(jit_function_t func, int cop, int reg) {
jit_value_t args[] = {make_uint(cop), make_uint(reg)};
return jit_insn_call_native(func, 0, (void *) read_copreg, sig_2, args, 2, 0);
}
uint32_t read_copcreg(int cop, int reg) {
return 0;
}
jit_value_t call_read_copcreg(jit_function_t func, int cop, int reg) {
jit_value_t args[] = {make_uint(cop), make_uint(reg)};
return jit_insn_call_native(func, 0, (void *) read_copcreg, sig_2, args, 2, 0);
}
void write_copreg(int cop, int reg, uint32_t val) {
}
void call_write_copreg(jit_function_t func, int cop, int reg, jit_value_t val) {
jit_value_t args[] = {make_uint(cop), make_uint(reg), val};
jit_insn_call_native(func, 0, (void *) write_copreg, sig_3, args, 3, 0);
}
void write_copcreg(int cop, int reg, uint32_t val) {
}
void call_write_copcreg(jit_function_t func, int cop, int reg, jit_value_t val) {
jit_value_t args[] = {make_uint(cop), make_uint(reg), val};
jit_insn_call_native(func, 0, (void *) write_copcreg, sig_3, args, 3, 0);
}
void copfun(int cop, int cofun) {
}
jit_value_t call_copfun(jit_function_t func, int cop, int cofun) {
jit_value_t args[] = {make_uint(cop), make_uint(cofun)};
return jit_insn_call_native(func, 0, (void *) copfun, sig_2, args, 2, 0);
}
int32_t signext(int size, uint32_t imm) {
if(size == 8)
return (int32_t) ((int8_t) ((uint8_t) imm));
else if(size == 16)
return (int32_t) ((int16_t) ((uint16_t) imm));
return (int32_t) imm;
}
jit_value_t call_signext(jit_function_t func, int size, jit_value_t val) {
jit_value_t args[] = {make_uint(size), val};
return jit_insn_call_native(func, 0, (void *) signext, sig_2, args, 2, 0);
}
void syscall(int code) {
}
void call_syscall(jit_function_t func, uint32_t code) {
jit_value_t args[] = {make_uint(code)};
jit_insn_call_native(func, 0, (void *) syscall, sig_1, args, 1, 0);
}
void break_(int code) {
}
void call_break(jit_function_t func, uint32_t code) {
jit_value_t args[] = {make_uint(code)};
jit_insn_call_native(func, 0, (void *) break_, sig_1, args, 1, 0);
}
void branch(uint32_t target) {
}
void call_branch(jit_function_t func, jit_value_t val) {
jit_value_t args[] = {val};
jit_insn_call_native(func, 0, (void *) branch, sig_1, args, 1, 0);
}
void overflow(uint32_t a, uint32_t b, int dir) {
}
void call_overflow(jit_function_t func, jit_value_t a, jit_value_t b, int dir) {
jit_value_t args[] = {a, b, make_uint(dir)};
jit_insn_call_native(func, 0, (void *) overflow, sig_3, args, 3, 0);
}
jit_context_t context;
jit_type_t block_sig;
void init_decompiler() {
context = jit_context_create();
jit_context_build_start(context);
jit_type_t s3params[3];
s3params[0] = jit_type_uint;
s3params[1] = jit_type_uint;
s3params[2] = jit_type_uint;
sig_3 = jit_type_create_signature(jit_abi_cdecl, jit_type_uint, s3params, 3, 1);
jit_type_t sparams[2];
sparams[0] = jit_type_uint;
sparams[1] = jit_type_uint;
sig_2 = jit_type_create_signature(jit_abi_cdecl, jit_type_uint, sparams, 2, 1);
jit_type_t lparams[2];
lparams[0] = jit_type_uint;
sig_1 = jit_type_create_signature(jit_abi_cdecl, jit_type_uint, lparams, 1, 1);
jit_type_t params[1];
params[0] = jit_type_create_pointer(jit_type_uint, 0);
block_sig = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 1, 1);
}
jit_function_t create_function() {
auto func = jit_function_create(context, signature);
auto statevar = jit_value_get_param(func, 0);
decompile(func, statevar, 0xDEADBEE0, 0x0, branched);
return 0;
}
\ No newline at end of file
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zutil.h"
#define local static
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware --
try it both ways to see which is faster */
#ifdef NO_DIVIDE
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
(thank you to John Reiser for pointing this out) */
# define CHOP(a) \
do { \
unsigned long tmp = a >> 16; \
a &= 0xffffUL; \
a += (tmp << 4) - tmp; \
} while (0)
# define MOD28(a) \
do { \
CHOP(a); \
if (a >= BASE) a -= BASE; \
} while (0)
# define MOD(a) \
do { \
CHOP(a); \
MOD28(a); \
} while (0)
# define MOD63(a) \
do { /* this assumes a is not negative */ \
z_off64_t tmp = a >> 32; \
a &= 0xffffffffL; \
a += (tmp << 8) - (tmp << 5) + tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
# define MOD28(a) a %= BASE
# define MOD63(a) a %= BASE
#endif
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long sum2;
unsigned n;
/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];
if (adler >= BASE)
adler -= BASE;
sum2 += adler;
if (sum2 >= BASE)
sum2 -= BASE;
return adler | (sum2 << 16);
}
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
adler += *buf++;
sum2 += adler;
}
if (adler >= BASE)
adler -= BASE;
MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */
do {
DO16(buf); /* 16 sums unrolled */