; ; File generated by cc65 v 2.11.0 ; .fopt compiler,"cc65 v 2.11.0" .setcpu "6502" .smart on .autoimport on .case on .debuginfo on .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 .macpack longbranch .dbg file, "realloc.c", 4656, 1103497761 .dbg file, "../../include/stdlib.h", 5287, 1122210074 .dbg file, "../../include/string.h", 4676, 1116364269 .dbg file, "../../include/stddef.h", 2974, 1061022172 .dbg file, "../../include/_heap.h", 1145, 1103497778 .import _malloc .export _realloc .import _free .import _memcpy .import __heapptr .import __heapend ; --------------------------------------------------------------- ; void* __fastcall__ realloc (void*, unsigned int) ; --------------------------------------------------------------- .segment "CODE" .proc _realloc .segment "CODE" ; ; { ; .dbg line, "realloc.c", 43 jsr pushax ; ; if (!block) { ; .dbg line, "realloc.c", 51 ldy #$0A jsr subysp ldy #$0D lda (sp),y dey ora (sp),y bne L0003 ; ; return malloc (size); ; .dbg line, "realloc.c", 53 dey jsr ldaxysp jsr _malloc jmp L0002 ; ; if (size == 0) { ; .dbg line, "realloc.c", 57 L0003: ldy #$0A lda (sp),y iny ora (sp),y bne L0007 ; ; free (block); ; .dbg line, "realloc.c", 59 ldy #$0D jsr ldaxysp jsr _free ; ; return 0; ; .dbg line, "realloc.c", 60 ldx #$00 txa jmp L0002 ; ; size += HEAP_ADMIN_SPACE; ; .dbg line, "realloc.c", 64 L0007: dey ldx #$00 lda #$04 jsr addeqysp ; ; if (size < sizeof (struct freeblock)) { ; .dbg line, "realloc.c", 65 ldy #$0B lda (sp),y cmp #$00 bne L0011 dey lda (sp),y cmp #$06 L0011: bcs L000F ; ; size = sizeof (struct freeblock); ; .dbg line, "realloc.c", 66 ldx #$00 lda #$06 ldy #$0A jsr staxysp ; ; b = (((struct usedblock*) block) - 1)->start; ; .dbg line, "realloc.c", 74 L000F: ldy #$0D jsr ldaxysp sec sbc #$04 bcs L0018 dex L0018: ldy #$03 jsr ldaxidx ldy #$08 jsr staxysp ; ; oldsize = b->size; ; .dbg line, "realloc.c", 75 ldy #$01 jsr ldaxidx ldy #$04 jsr staxysp ; ; diff = size - oldsize; ; .dbg line, "realloc.c", 78 ldy #$0D jsr pushwysp ldy #$07 jsr ldaxysp jsr tossubax ldy #$00 jsr staxysp ; ; if (((unsigned) b) + oldsize == ((unsigned) _heapptr)) { ; .dbg line, "realloc.c", 81 ldy #$08 lda (sp),y clc ldy #$04 adc (sp),y pha ldy #$09 lda (sp),y ldy #$05 adc (sp),y tax pla jsr pushax lda __heapptr ldx __heapptr+1 jsr tosicmp bne L0024 ; ; newhptr = ((unsigned) _heapptr) + diff; ; .dbg line, "realloc.c", 83 lda __heapptr ldx __heapptr+1 sta ptr1 stx ptr1+1 ldy #$01 jsr ldaxysp clc adc ptr1 sta ptr1 txa adc ptr1+1 tax lda ptr1 ldy #$02 jsr staxysp ; ; if (newhptr <= ((unsigned) _heapend)) { ; .dbg line, "realloc.c", 84 jsr pushax lda __heapend ldx __heapend+1 jsr tosicmp beq L0040 bcs L0024 ; ; _heapptr = (unsigned*) newhptr; ; .dbg line, "realloc.c", 86 L0040: ldy #$03 jsr ldaxysp sta __heapptr stx __heapptr+1 ; ; b->size = size; ; .dbg line, "realloc.c", 87 ldy #$09 jsr ldaxysp sta ptr1 stx ptr1+1 ldy #$0B jsr ldaxysp ldy #$00 sta (ptr1),y iny txa sta (ptr1),y ; ; b->start = b; ; .dbg line, "realloc.c", 88 ldy #$09 jsr ldaxysp sta sreg stx sreg+1 ldy #$09 jsr ldaxysp ldy #$02 sta (sreg),y iny txa sta (sreg),y ; ; return block; ; .dbg line, "realloc.c", 89 ldy #$0D jmp L003F ; ; if (newblock = malloc (size)) { ; .dbg line, "realloc.c", 96 L0024: ldy #$0B jsr ldaxysp jsr _malloc ldy #$06 jsr staxysp stx tmp1 ora tmp1 beq L002E ; ; oldsize -= HEAP_ADMIN_SPACE; ; .dbg line, "realloc.c", 99 ldx #$00 lda #$04 tay jsr subeqysp ; ; if (size > oldsize) { ; .dbg line, "realloc.c", 104 ldy #$0D jsr pushwysp ldy #$07 jsr ldaxysp jsr tosicmp bcc L0034 beq L0034 ; ; size = oldsize; ; .dbg line, "realloc.c", 105 ldy #$05 jsr ldaxysp ldy #$0A jsr staxysp ; ; memcpy (newblock, block, size); ; .dbg line, "realloc.c", 109 L0034: ldy #$09 jsr pushwysp ldy #$11 jsr pushwysp ldy #$0F jsr ldaxysp jsr _memcpy ; ; free (block); ; .dbg line, "realloc.c", 110 ldy #$0D jsr ldaxysp jsr _free ; ; return newblock; ; .dbg line, "realloc.c", 112 L002E: ldy #$07 L003F: jsr ldaxysp ; ; } ; .dbg line, "realloc.c", 113 L0002: ldy #$0E jmp addysp .dbg line .endproc