mirror of
https://github.com/cc65/cc65.git
synced 2025-04-04 21:33:30 +00:00
Make the stuff compile
git-svn-id: svn://svn.cc65.org/cc65/trunk@2445 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
73941d8f48
commit
03560318ef
1
libsrc/zlib/.cvsignore
Normal file
1
libsrc/zlib/.cvsignore
Normal file
@ -0,0 +1 @@
|
||||
uncompress.s
|
42
libsrc/zlib/Makefile
Normal file
42
libsrc/zlib/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# Makefile for the zlib subdirectory of the cc65 runtime library
|
||||
#
|
||||
|
||||
.SUFFIXES: .o .s .c
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Rules
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) $(CFLAGS) $<
|
||||
@$(AS) -g -o $@ $(AFLAGS) $(*).s
|
||||
|
||||
%.o: %.s
|
||||
@$(AS) -g -o $@ $(AFLAGS) $<
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Object files
|
||||
|
||||
C_OBJS = uncompress.o
|
||||
|
||||
|
||||
S_OBJS = adler32.o \
|
||||
crc32.o \
|
||||
inflatemem.o
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Targets
|
||||
|
||||
.PHONY: all clean zap
|
||||
|
||||
all: $(C_OBJS) $(S_OBJS)
|
||||
|
||||
clean:
|
||||
@rm -f *~
|
||||
@rm -f $(C_OBJS:.o=.s)
|
||||
@rm -f $(C_OBJS)
|
||||
@rm -f $(S_OBJS)
|
||||
|
||||
zap: clean
|
||||
|
@ -1,85 +1,85 @@
|
||||
;
|
||||
; Piotr Fusik, 18.11.2001
|
||||
;
|
||||
; unsigned long __fastcall__ adler32 (unsigned long adler, unsigned char* buf,
|
||||
; unsigned len);
|
||||
;
|
||||
|
||||
.export _adler32
|
||||
|
||||
.import incsp2, incsp4, popax, popeax
|
||||
.importzp sreg, ptr1, ptr2, tmp1
|
||||
|
||||
BASE = 65521 ; largest prime smaller than 65536
|
||||
|
||||
_adler32:
|
||||
; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;
|
||||
tay
|
||||
beq @L1
|
||||
inx
|
||||
@L1: sta ptr2
|
||||
stx ptr2+1
|
||||
; ptr1 = buf
|
||||
jsr popax
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
; if (buf == NULL) return 1L;
|
||||
ora ptr1+1
|
||||
beq @L0
|
||||
; s1 = adler & 0xFFFF; s2 = adler >> 16;
|
||||
jsr popeax
|
||||
; if (len == 0) return adler;
|
||||
ldy ptr2
|
||||
bne @L2
|
||||
ldy ptr2+1
|
||||
beq @RET
|
||||
@L2: ldy #0
|
||||
; s1 += *ptr++; if (s1 >= BASE) s1 -= BASE;
|
||||
@L3: clc
|
||||
adc (ptr1),y
|
||||
bcc @L4
|
||||
inx
|
||||
beq @L5 ; C flag is set
|
||||
@L4: cpx #>BASE
|
||||
bcc @L6
|
||||
cmp #<BASE
|
||||
bcc @L6
|
||||
inx ; ldx #0
|
||||
@L5: sbc #<BASE ; C flag is set
|
||||
clc
|
||||
@L6: sta tmp1
|
||||
; s2 += s1; if (s2 >= BASE) s2 -= BASE;
|
||||
adc sreg ; C flag is clear
|
||||
sta sreg
|
||||
txa
|
||||
adc sreg+1
|
||||
sta sreg+1
|
||||
bcs @L7
|
||||
cmp #>BASE
|
||||
bcc @L8
|
||||
lda sreg
|
||||
cmp #<BASE
|
||||
bcc @L8
|
||||
@L7: lda sreg
|
||||
sbc #<BASE ; C flag is set
|
||||
sta sreg
|
||||
lda sreg+1
|
||||
sbc #>BASE
|
||||
sta sreg+1
|
||||
@L8: lda tmp1
|
||||
iny
|
||||
bne @L9
|
||||
inc ptr1+1
|
||||
@L9: dec ptr2
|
||||
bne @L3
|
||||
dec ptr2+1
|
||||
bne @L3
|
||||
; return (s2 << 16) | s1;
|
||||
@RET: rts
|
||||
|
||||
; return 1L
|
||||
@L0: sta sreg
|
||||
sta sreg+1
|
||||
lda #1
|
||||
; ignore adler
|
||||
jmp incsp4
|
||||
;
|
||||
; Piotr Fusik, 18.11.2001
|
||||
;
|
||||
; unsigned long __fastcall__ adler32 (unsigned long adler, unsigned char* buf,
|
||||
; unsigned len);
|
||||
;
|
||||
|
||||
.export _adler32
|
||||
|
||||
.import incsp2, incsp4, popax, popeax
|
||||
.importzp sreg, ptr1, ptr2, tmp1
|
||||
|
||||
BASE = 65521 ; largest prime smaller than 65536
|
||||
|
||||
_adler32:
|
||||
; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;
|
||||
tay
|
||||
beq @L1
|
||||
inx
|
||||
@L1: sta ptr2
|
||||
stx ptr2+1
|
||||
; ptr1 = buf
|
||||
jsr popax
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
; if (buf == NULL) return 1L;
|
||||
ora ptr1+1
|
||||
beq @L0
|
||||
; s1 = adler & 0xFFFF; s2 = adler >> 16;
|
||||
jsr popeax
|
||||
; if (len == 0) return adler;
|
||||
ldy ptr2
|
||||
bne @L2
|
||||
ldy ptr2+1
|
||||
beq @RET
|
||||
@L2: ldy #0
|
||||
; s1 += *ptr++; if (s1 >= BASE) s1 -= BASE;
|
||||
@L3: clc
|
||||
adc (ptr1),y
|
||||
bcc @L4
|
||||
inx
|
||||
beq @L5 ; C flag is set
|
||||
@L4: cpx #>BASE
|
||||
bcc @L6
|
||||
cmp #<BASE
|
||||
bcc @L6
|
||||
inx ; ldx #0
|
||||
@L5: sbc #<BASE ; C flag is set
|
||||
clc
|
||||
@L6: sta tmp1
|
||||
; s2 += s1; if (s2 >= BASE) s2 -= BASE;
|
||||
adc sreg ; C flag is clear
|
||||
sta sreg
|
||||
txa
|
||||
adc sreg+1
|
||||
sta sreg+1
|
||||
bcs @L7
|
||||
cmp #>BASE
|
||||
bcc @L8
|
||||
lda sreg
|
||||
cmp #<BASE
|
||||
bcc @L8
|
||||
@L7: lda sreg
|
||||
sbc #<BASE ; C flag is set
|
||||
sta sreg
|
||||
lda sreg+1
|
||||
sbc #>BASE
|
||||
sta sreg+1
|
||||
@L8: lda tmp1
|
||||
iny
|
||||
bne @L9
|
||||
inc ptr1+1
|
||||
@L9: dec ptr2
|
||||
bne @L3
|
||||
dec ptr2+1
|
||||
bne @L3
|
||||
; return (s2 << 16) | s1;
|
||||
@RET: rts
|
||||
|
||||
; return 1L
|
||||
@L0: sta sreg
|
||||
sta sreg+1
|
||||
lda #1
|
||||
; ignore adler
|
||||
jmp incsp4
|
||||
|
@ -1,134 +1,134 @@
|
||||
;
|
||||
; Piotr Fusik, 14.11.2001
|
||||
;
|
||||
; unsigned long __fastcall__ crc32 (unsigned long crc, unsigned char* buf,
|
||||
; unsigned len);
|
||||
;
|
||||
|
||||
.export _crc32
|
||||
|
||||
.import compleax, incsp2, incsp4, popax, popeax
|
||||
.importzp sreg, ptr1, ptr2, tmp1, tmp2
|
||||
|
||||
POLYNOMIAL = $EDB88320
|
||||
|
||||
make_table:
|
||||
ldx #0
|
||||
@L1: lda #0
|
||||
sta tmp2
|
||||
sta sreg
|
||||
sta sreg+1
|
||||
ldy #8
|
||||
txa
|
||||
@L2: sta tmp1
|
||||
lsr a
|
||||
bcc @L3
|
||||
lda sreg+1
|
||||
lsr a
|
||||
eor #(POLYNOMIAL>>24)&$FF
|
||||
sta sreg+1
|
||||
lda sreg
|
||||
ror a
|
||||
eor #(POLYNOMIAL>>16)&$FF
|
||||
sta sreg
|
||||
lda tmp2
|
||||
ror a
|
||||
eor #(POLYNOMIAL>>8)&$FF
|
||||
sta tmp2
|
||||
lda tmp1
|
||||
ror a
|
||||
eor #POLYNOMIAL&$FF
|
||||
bcs @L4 ; branch always
|
||||
@L3: rol a
|
||||
lsr sreg+1
|
||||
ror sreg
|
||||
ror tmp2
|
||||
ror a
|
||||
@L4: dey
|
||||
bne @L2
|
||||
sta table_0,x
|
||||
lda tmp2
|
||||
sta table_1,x
|
||||
lda sreg
|
||||
sta table_2,x
|
||||
lda sreg+1
|
||||
sta table_3,x
|
||||
inx
|
||||
bne @L1
|
||||
inc table_initialised
|
||||
RET:
|
||||
rts
|
||||
|
||||
_crc32:
|
||||
; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;
|
||||
tay
|
||||
beq @L1
|
||||
inx
|
||||
@L1: sta ptr2
|
||||
stx ptr2+1
|
||||
; ptr1 = buf
|
||||
jsr popax
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
; if (buf == NULL) return 0;
|
||||
ora ptr1+1
|
||||
beq @L0
|
||||
; if (!tables_initialised) make_tables();
|
||||
lda table_initialised
|
||||
bne @dont_make
|
||||
jsr make_table
|
||||
@dont_make:
|
||||
; eax = crc
|
||||
jsr popeax
|
||||
; if (len == 0) return crc;
|
||||
ldy ptr2
|
||||
bne @L2
|
||||
ldy ptr2+1
|
||||
beq RET
|
||||
@L2:
|
||||
; eax = ~crc
|
||||
jsr compleax
|
||||
stx tmp2
|
||||
ldy #0
|
||||
; crc = (crc >> 8) ^ table[(crc & 0xff) ^ *p++];
|
||||
@L3: eor (ptr1),y
|
||||
tax
|
||||
lda table_0,x
|
||||
eor tmp2
|
||||
sta tmp1
|
||||
lda table_1,x
|
||||
eor sreg
|
||||
sta tmp2
|
||||
lda table_2,x
|
||||
eor sreg+1
|
||||
sta sreg
|
||||
lda table_3,x
|
||||
sta sreg+1
|
||||
lda tmp1
|
||||
iny
|
||||
bne @L4
|
||||
inc ptr1+1
|
||||
@L4: dec ptr2
|
||||
bne @L3
|
||||
dec ptr2+1
|
||||
bne @L3
|
||||
ldx tmp2
|
||||
jmp compleax
|
||||
|
||||
; return 0L
|
||||
@L0: sta sreg
|
||||
sta sreg+1
|
||||
; ignore crc
|
||||
jmp incsp4
|
||||
|
||||
.data
|
||||
table_initialised:
|
||||
.byte 0
|
||||
|
||||
.bss
|
||||
table_0: .res 256
|
||||
table_1: .res 256
|
||||
table_2: .res 256
|
||||
table_3: .res 256
|
||||
|
||||
|
||||
;
|
||||
; Piotr Fusik, 14.11.2001
|
||||
;
|
||||
; unsigned long __fastcall__ crc32 (unsigned long crc, unsigned char* buf,
|
||||
; unsigned len);
|
||||
;
|
||||
|
||||
.export _crc32
|
||||
|
||||
.import compleax, incsp2, incsp4, popax, popeax
|
||||
.importzp sreg, ptr1, ptr2, tmp1, tmp2
|
||||
|
||||
POLYNOMIAL = $EDB88320
|
||||
|
||||
make_table:
|
||||
ldx #0
|
||||
@L1: lda #0
|
||||
sta tmp2
|
||||
sta sreg
|
||||
sta sreg+1
|
||||
ldy #8
|
||||
txa
|
||||
@L2: sta tmp1
|
||||
lsr a
|
||||
bcc @L3
|
||||
lda sreg+1
|
||||
lsr a
|
||||
eor #(POLYNOMIAL>>24)&$FF
|
||||
sta sreg+1
|
||||
lda sreg
|
||||
ror a
|
||||
eor #(POLYNOMIAL>>16)&$FF
|
||||
sta sreg
|
||||
lda tmp2
|
||||
ror a
|
||||
eor #(POLYNOMIAL>>8)&$FF
|
||||
sta tmp2
|
||||
lda tmp1
|
||||
ror a
|
||||
eor #POLYNOMIAL&$FF
|
||||
bcs @L4 ; branch always
|
||||
@L3: rol a
|
||||
lsr sreg+1
|
||||
ror sreg
|
||||
ror tmp2
|
||||
ror a
|
||||
@L4: dey
|
||||
bne @L2
|
||||
sta table_0,x
|
||||
lda tmp2
|
||||
sta table_1,x
|
||||
lda sreg
|
||||
sta table_2,x
|
||||
lda sreg+1
|
||||
sta table_3,x
|
||||
inx
|
||||
bne @L1
|
||||
inc table_initialised
|
||||
RET:
|
||||
rts
|
||||
|
||||
_crc32:
|
||||
; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;
|
||||
tay
|
||||
beq @L1
|
||||
inx
|
||||
@L1: sta ptr2
|
||||
stx ptr2+1
|
||||
; ptr1 = buf
|
||||
jsr popax
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
; if (buf == NULL) return 0;
|
||||
ora ptr1+1
|
||||
beq @L0
|
||||
; if (!tables_initialised) make_tables();
|
||||
lda table_initialised
|
||||
bne @dont_make
|
||||
jsr make_table
|
||||
@dont_make:
|
||||
; eax = crc
|
||||
jsr popeax
|
||||
; if (len == 0) return crc;
|
||||
ldy ptr2
|
||||
bne @L2
|
||||
ldy ptr2+1
|
||||
beq RET
|
||||
@L2:
|
||||
; eax = ~crc
|
||||
jsr compleax
|
||||
stx tmp2
|
||||
ldy #0
|
||||
; crc = (crc >> 8) ^ table[(crc & 0xff) ^ *p++];
|
||||
@L3: eor (ptr1),y
|
||||
tax
|
||||
lda table_0,x
|
||||
eor tmp2
|
||||
sta tmp1
|
||||
lda table_1,x
|
||||
eor sreg
|
||||
sta tmp2
|
||||
lda table_2,x
|
||||
eor sreg+1
|
||||
sta sreg
|
||||
lda table_3,x
|
||||
sta sreg+1
|
||||
lda tmp1
|
||||
iny
|
||||
bne @L4
|
||||
inc ptr1+1
|
||||
@L4: dec ptr2
|
||||
bne @L3
|
||||
dec ptr2+1
|
||||
bne @L3
|
||||
ldx tmp2
|
||||
jmp compleax
|
||||
|
||||
; return 0L
|
||||
@L0: sta sreg
|
||||
sta sreg+1
|
||||
; ignore crc
|
||||
jmp incsp4
|
||||
|
||||
.data
|
||||
table_initialised:
|
||||
.byte 0
|
||||
|
||||
.bss
|
||||
table_0: .res 256
|
||||
table_1: .res 256
|
||||
table_2: .res 256
|
||||
table_3: .res 256
|
||||
|
||||
|
||||
|
@ -1,36 +1,36 @@
|
||||
/*
|
||||
* uncompress.c
|
||||
*
|
||||
* Piotr Fusik, 18.11.2001
|
||||
*/
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
int uncompress (char* dest, unsigned* destLen,
|
||||
const char* source, unsigned sourceLen)
|
||||
{
|
||||
unsigned len;
|
||||
unsigned char* ptr;
|
||||
unsigned long csum;
|
||||
/* source[0]: Compression method and flags
|
||||
bits 0 to 3: Compression method (must be Z_DEFLATED)
|
||||
bits 4 to 7: Compression info (must be <= 7)
|
||||
source[1]: Flags
|
||||
bits 0 to 4: Check bits
|
||||
bit 5: Preset dictionary (not supported, sorry)
|
||||
bits 6 to 7: Compression level
|
||||
*/
|
||||
if ((source[0] & 0x8f) != Z_DEFLATED || source[1] & 0x20)
|
||||
return Z_DATA_ERROR;
|
||||
if ((((unsigned) source[0] << 8) | (unsigned char) source[1]) % 31)
|
||||
return Z_DATA_ERROR;
|
||||
*destLen = len = inflatemem(dest, source + 2);
|
||||
ptr = (unsigned char*) source + sourceLen - 4;
|
||||
csum = adler32(adler32(0L, Z_NULL, 0), dest, len);
|
||||
if ((unsigned char) csum != ptr[3]
|
||||
|| (unsigned char) (csum >> 8) != ptr[2]
|
||||
|| (unsigned char) (csum >> 16) != ptr[1]
|
||||
|| (unsigned char) (csum >> 24) != ptr[0])
|
||||
return Z_DATA_ERROR;
|
||||
return Z_OK;
|
||||
}
|
||||
/*
|
||||
* uncompress.c
|
||||
*
|
||||
* Piotr Fusik, 18.11.2001
|
||||
*/
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
int uncompress (char* dest, unsigned* destLen,
|
||||
const char* source, unsigned sourceLen)
|
||||
{
|
||||
unsigned len;
|
||||
unsigned char* ptr;
|
||||
unsigned long csum;
|
||||
/* source[0]: Compression method and flags
|
||||
bits 0 to 3: Compression method (must be Z_DEFLATED)
|
||||
bits 4 to 7: Compression info (must be <= 7)
|
||||
source[1]: Flags
|
||||
bits 0 to 4: Check bits
|
||||
bit 5: Preset dictionary (not supported, sorry)
|
||||
bits 6 to 7: Compression level
|
||||
*/
|
||||
if ((source[0] & 0x8f) != Z_DEFLATED || source[1] & 0x20)
|
||||
return Z_DATA_ERROR;
|
||||
if ((((unsigned) source[0] << 8) | (unsigned char) source[1]) % 31)
|
||||
return Z_DATA_ERROR;
|
||||
*destLen = len = inflatemem(dest, source + 2);
|
||||
ptr = (unsigned char*) source + sourceLen - 4;
|
||||
csum = adler32(adler32(0L, Z_NULL, 0), dest, len);
|
||||
if ((unsigned char) csum != ptr[3]
|
||||
|| (unsigned char) (csum >> 8) != ptr[2]
|
||||
|| (unsigned char) (csum >> 16) != ptr[1]
|
||||
|| (unsigned char) (csum >> 24) != ptr[0])
|
||||
return Z_DATA_ERROR;
|
||||
return Z_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user