]> git.sur5r.net Git - cc65/blobdiff - libsrc/zlib/crc32.s
don't use constructor to setup runtime stack
[cc65] / libsrc / zlib / crc32.s
index d47e92f10ce9e2297fe28a258c6e884aa0ff07b9..61f64c3cf71084ab92e60ef5390974e19c5f090d 100644 (file)
-;\r
-; Piotr Fusik, 14.11.2001\r
-;\r
-; unsigned long __fastcall__ crc32 (unsigned long crc, unsigned char* buf,\r
-;                                   unsigned len);\r
-;\r
-\r
-       .export _crc32\r
-\r
-       .import         compleax, incsp2, incsp4, popax, popeax\r
-       .importzp       sreg, ptr1, ptr2, tmp1, tmp2\r
-\r
-POLYNOMIAL     =       $EDB88320\r
-\r
-make_table:\r
-       ldx     #0\r
-@L1:   lda     #0\r
-       sta     tmp2\r
-       sta     sreg\r
-       sta     sreg+1\r
-       ldy     #8\r
-       txa\r
-@L2:   sta     tmp1\r
-       lsr     a\r
-       bcc     @L3\r
-       lda     sreg+1\r
-       lsr     a\r
-       eor     #(POLYNOMIAL>>24)&$FF\r
-       sta     sreg+1\r
-       lda     sreg\r
-       ror     a\r
-       eor     #(POLYNOMIAL>>16)&$FF\r
-       sta     sreg\r
-       lda     tmp2\r
-       ror     a\r
-       eor     #(POLYNOMIAL>>8)&$FF\r
-       sta     tmp2\r
-       lda     tmp1\r
-       ror     a\r
-       eor     #POLYNOMIAL&$FF\r
-       bcs     @L4     ; branch always\r
-@L3:   rol     a\r
-       lsr     sreg+1\r
-       ror     sreg\r
-       ror     tmp2\r
-       ror     a\r
-@L4:   dey\r
-       bne     @L2\r
-       sta     table_0,x\r
-       lda     tmp2\r
-       sta     table_1,x\r
-       lda     sreg\r
-       sta     table_2,x\r
-       lda     sreg+1\r
-       sta     table_3,x\r
-       inx\r
-       bne     @L1\r
-       inc     table_initialised\r
-RET:\r
-       rts\r
-\r
-_crc32:\r
-; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;\r
-       tay\r
-       beq     @L1\r
-       inx\r
-@L1:   sta     ptr2\r
-       stx     ptr2+1\r
-; ptr1 = buf\r
-       jsr     popax\r
-       sta     ptr1\r
-       stx     ptr1+1\r
-; if (buf == NULL) return 0;\r
-       ora     ptr1+1\r
-       beq     @L0\r
-; if (!tables_initialised) make_tables();\r
-       lda     table_initialised\r
-       bne     @dont_make\r
-       jsr     make_table\r
-@dont_make:\r
-; eax = crc\r
-       jsr     popeax\r
-; if (len == 0) return crc;\r
-       ldy     ptr2\r
-       bne     @L2\r
-       ldy     ptr2+1\r
-       beq     RET\r
-@L2:\r
-; eax = ~crc\r
-       jsr     compleax\r
-       stx     tmp2\r
-       ldy     #0\r
-; crc = (crc >> 8) ^ table[(crc & 0xff) ^ *p++];\r
-@L3:   eor     (ptr1),y\r
-       tax\r
-       lda     table_0,x\r
-       eor     tmp2\r
-       sta     tmp1\r
-       lda     table_1,x\r
-       eor     sreg\r
-       sta     tmp2\r
-       lda     table_2,x\r
-       eor     sreg+1\r
-       sta     sreg\r
-       lda     table_3,x\r
-       sta     sreg+1\r
-       lda     tmp1\r
-       iny\r
-       bne     @L4\r
-       inc     ptr1+1\r
-@L4:   dec     ptr2\r
-       bne     @L3\r
-       dec     ptr2+1\r
-       bne     @L3\r
-       ldx     tmp2\r
-       jmp     compleax\r
-\r
-; return 0L\r
-@L0:   sta     sreg\r
-       sta     sreg+1\r
-; ignore crc\r
-       jmp     incsp4\r
-\r
-               .data\r
-table_initialised:\r
-               .byte   0\r
-\r
-               .bss\r
-table_0:       .res    256\r
-table_1:       .res    256\r
-table_2:       .res    256\r
-table_3:       .res    256\r
-\r
-\r
+;
+; 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
+
+