;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.5.1 #1058 (Jul 15 2005)
; This file generated Fri Jul 15 02:53:54 2005
;--------------------------------------------------------
	.module malloc
	.optsdcc -mz80
	
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl __sdcc_heap_init
	.globl _malloc
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
;  ram data
;--------------------------------------------------------
	.area _DATA
;--------------------------------------------------------
; overlayable items in  ram 
;--------------------------------------------------------
	.area _OVERLAY
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area _CODE
	.area _GSINIT
	.area _GSFINAL
	.area _GSINIT
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area _HOME
	.area _CODE
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area _CODE
;malloc.c:51: _sdcc_heap_init(void)
;	genLabel
;	genFunction
;	---------------------------------
; Function _sdcc_heap_init
; ---------------------------------
__sdcc_heap_init_start::
__sdcc_heap_init:
;malloc.c:53: MEMHEADER *pbase = &_sdcc_heap_start;
;malloc.c:54: unsigned int size = &_sdcc_heap_end - (char *)pbase;
;	genMinus
	ld	a,#<__sdcc_heap_end
	sub	a,#<__sdcc_heap_start
	ld	c,a
	ld	a,#>__sdcc_heap_end
	sbc	a,#>__sdcc_heap_start
	ld	b,a
;	genAssign
;	(registers are the same)
;malloc.c:56: pbase->next = (MEMHEADER *)((char *)pbase + size - HEADER_SIZE);
;	genPlus
;	Can't optimise plus by inc, falling back to the normal way
	ld	hl,#__sdcc_heap_start
	add	hl,bc
	ld	c,l
	ld	b,h
;	genMinus
	ld	a,c
	add	a,#0xFA
	ld	c,a
	ld	a,b
	adc	a,#0xFF
	ld	b,a
;	genAssign (pointer)
;	isBitvar = 0
	ld	hl,#__sdcc_heap_start
	ld	(hl),c
	inc	hl
	ld	(hl),b
;malloc.c:57: pbase->next->next = NULL; //And mark it as last
;	genCast
;	genAssign (pointer)
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	(hl),#0x00
	inc	hl
	ld	(hl),#0x00
;malloc.c:58: pbase->prev       = NULL; //and mark first as first
;	genPlus
;	genPlusIncr
	ld	bc,#__sdcc_heap_start + 2
;	genAssign (pointer)
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	(hl),#0x00
	inc	hl
	ld	(hl),#0x00
;malloc.c:59: pbase->len        = 0;    //Empty and ready.
;	genPlus
;	genPlusIncr
	ld	bc,#__sdcc_heap_start + 4
;	genAssign (pointer)
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	(hl),#0x00
	inc	hl
	ld	(hl),#0x00
;	genLabel
00101$:
;	genEndFunction
	ret
__sdcc_heap_init_end::
;malloc.c:63: malloc (unsigned int size)
;	genLabel
;	genFunction
;	---------------------------------
; Function malloc
; ---------------------------------
_malloc_start::
_malloc:
	push	ix
	ld	ix,#0
	add	ix,sp
	ld	hl,#-6
	add	hl,sp
	ld	sp,hl
;malloc.c:69: if (size>(0xFFFF-HEADER_SIZE))
;	genCmpGt
;	AOP_STK for 
	ld	a,#0xF9
	sub	a,4(ix)
	ld	a,#0xFF
	sbc	a,5(ix)
	jp	nc,00102$
;malloc.c:71: return NULL; //To prevent overflow in next line
;	genRet
; Dump of IC_LEFT: type AOP_LIT size 2
	ld	hl,#0x0000
	jp	00117$
;	genLabel
00102$:
;malloc.c:74: size += HEADER_SIZE; //We need a memory for header too
;	genPlus
;	AOP_STK for 
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,4(ix)
	add	a,#0x06
	ld	4(ix),a
	ld	a,5(ix)
	adc	a,#0x00
	ld	5(ix),a
;malloc.c:75: current_header = &_sdcc_heap_start;
;	genAssign
;	AOP_STK for _malloc_current_header_1_1
	ld	-2(ix),#<__sdcc_heap_start
	ld	-1(ix),#>__sdcc_heap_start
;malloc.c:124: }
;malloc.c:79: while (1)
;	genLabel
00108$:
;malloc.c:88: if ((((unsigned int)current_header->next) -
;	genPointerGet
;	AOP_STK for _malloc_current_header_1_1
	ld	l,-2(ix)
	ld	h,-1(ix)
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
;	genCast
;	AOP_STK for _malloc__1_0
	ld	-6(ix),e
	ld	-5(ix),d
;malloc.c:89: ((unsigned int)current_header) -
;	genCast
;	AOP_STK for _malloc_current_header_1_1
	ld	c,-2(ix)
	ld	b,-1(ix)
;	genMinus
;	AOP_STK for _malloc__1_0
	ld	a,-6(ix)
	sub	a,c
	ld	-6(ix),a
	ld	a,-5(ix)
	sbc	a,b
	ld	-5(ix),a
;malloc.c:90: current_header->len) >= size)
;	genPlus
;	AOP_STK for _malloc_current_header_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,#0x04
	ld	c,a
	ld	a,-1(ix)
	adc	a,#0x00
	ld	b,a
;	genPointerGet
	ld	l,c
	ld	h,b
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genMinus
;	AOP_STK for _malloc__1_0
	ld	a,-6(ix)
	sub	a,c
	ld	c,a
	ld	a,-5(ix)
	sbc	a,b
	ld	b,a
;	genCmpLt
;	AOP_STK for 
	ld	a,c
	sub	a,4(ix)
	ld	a,b
	sbc	a,5(ix)
	jp	c,00104$
;malloc.c:92: ret = &current_header->mem;
;	genPlus
;	AOP_STK for _malloc_current_header_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,#0x06
	ld	c,a
	ld	a,-1(ix)
	adc	a,#0x00
	ld	b,a
;malloc.c:93: break;
;	genGoto
	jp	00109$
;	genLabel
00104$:
;malloc.c:95: current_header = current_header->next;    //else try next
;	genAssign
;	(registers are the same)
;	genAssign
;	AOP_STK for _malloc_current_header_1_1
	ld	-2(ix),e
	ld	-1(ix),d
;malloc.c:96: if (!current_header->next)
;	genPointerGet
;	AOP_STK for _malloc_current_header_1_1
	ld	l,-2(ix)
	ld	h,-1(ix)
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
;	genIfx
	ld	a,e
	or	a,d
	jp	nz,00108$
;malloc.c:98: ret = NULL;
;	genAssign
	ld	bc,#0x0000
;malloc.c:99: break;
;	genLabel
00109$:
;malloc.c:103: if (ret)
;	genIfx
	ld	a,c
	or	a,b
	jp	z,00116$
;malloc.c:105: if (!current_header->len)
;	genPlus
;	AOP_STK for _malloc_current_header_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,#0x04
	ld	e,a
	ld	a,-1(ix)
	adc	a,#0x00
	ld	d,a
;	genPointerGet
;	AOP_STK for _malloc__1_0
	ld	l,e
	ld	h,d
	ld	a,(hl)
	ld	-6(ix),a
	inc	hl
	ld	a,(hl)
	ld	-5(ix),a
;	genIfx
;	AOP_STK for _malloc__1_0
	ld	a,-6(ix)
	or	a,-5(ix)
	jp	nz,00113$
;malloc.c:107: current_header->len = size; //for first allocation
;	genAssign (pointer)
;	AOP_STK for 
;	isBitvar = 0
	ld	l,e
	ld	h,d
	ld	a,4(ix)
	ld	(hl),a
	inc	hl
	ld	a,5(ix)
	ld	(hl),a
;	genGoto
	jp	00116$
;	genLabel
00113$:
;malloc.c:112: new_header = (MEMHEADER * )((char *)current_header + current_header->len);
;	genPlus
;	AOP_STK for _malloc_current_header_1_1
;	AOP_STK for _malloc__1_0
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,-6(ix)
	ld	e,a
	ld	a,-1(ix)
	adc	a,-5(ix)
	ld	d,a
;	genAssign
;	AOP_STK for _malloc_new_header_1_1
	ld	-4(ix),e
	ld	-3(ix),d
;malloc.c:113: new_header->next = current_header->next; //and plug it into the chain
;	genPointerGet
;	AOP_STK for _malloc_current_header_1_1
	ld	l,-2(ix)
	ld	h,-1(ix)
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genAssign (pointer)
;	AOP_STK for _malloc_new_header_1_1
;	isBitvar = 0
	ld	l,-4(ix)
	ld	h,-3(ix)
	ld	(hl),c
	inc	hl
	ld	(hl),b
;malloc.c:114: new_header->prev = current_header;
;	genPlus
;	AOP_STK for _malloc_new_header_1_1
;	genPlusIncr
	ld	e,-4(ix)
	ld	d,-3(ix)
	inc	de
	inc	de
;	genAssign (pointer)
;	AOP_STK for _malloc_current_header_1_1
;	isBitvar = 0
	ld	l,e
	ld	h,d
	ld	a,-2(ix)
	ld	(hl),a
	inc	hl
	ld	a,-1(ix)
	ld	(hl),a
;malloc.c:115: current_header->next  = new_header;
;	genAssign (pointer)
;	AOP_STK for _malloc_current_header_1_1
;	AOP_STK for _malloc_new_header_1_1
;	isBitvar = 0
	ld	l,-2(ix)
	ld	h,-1(ix)
	ld	a,-4(ix)
	ld	(hl),a
	inc	hl
	ld	a,-3(ix)
	ld	(hl),a
;malloc.c:116: if (new_header->next)
;	genIfx
	ld	a,c
	or	a,b
	jp	z,00111$
;malloc.c:118: new_header->next->prev = new_header;
;	genPointerGet
;	AOP_STK for _malloc_new_header_1_1
	ld	l,-4(ix)
	ld	h,-3(ix)
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
;	genPlus
;	genPlusIncr
	inc	de
	inc	de
;	genAssign (pointer)
;	AOP_STK for _malloc_new_header_1_1
;	isBitvar = 0
	ld	l,e
	ld	h,d
	ld	a,-4(ix)
	ld	(hl),a
	inc	hl
	ld	a,-3(ix)
	ld	(hl),a
;	genLabel
00111$:
;malloc.c:120: new_header->len  = size; //mark as used
;	genPlus
;	AOP_STK for _malloc_new_header_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-4(ix)
	add	a,#0x04
	ld	e,a
	ld	a,-3(ix)
	adc	a,#0x00
	ld	d,a
;	genAssign (pointer)
;	AOP_STK for 
;	isBitvar = 0
	ld	l,e
	ld	h,d
	ld	a,4(ix)
	ld	(hl),a
	inc	hl
	ld	a,5(ix)
	ld	(hl),a
;malloc.c:121: ret = &new_header->mem;
;	genPlus
;	AOP_STK for _malloc_new_header_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-4(ix)
	add	a,#0x06
	ld	c,a
	ld	a,-3(ix)
	adc	a,#0x00
	ld	b,a
;	genLabel
00116$:
;malloc.c:125: return ret;
;	genRet
; Dump of IC_LEFT: type AOP_REG size 2
;	 reg = bc
	ld	l,c
	ld	h,b
;	genLabel
00117$:
;	genEndFunction
	ld	sp,ix
	pop	ix
	ret
_malloc_end::
	.area _CODE
