home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Allocate 16*a bytes on the stack, and leave a deallocate pointer
- ; on TOS. Thus "pop h | sphl" will deallocate. A maximum of 4096
- ; bytes can be allocated (a=0 means 256). Remember to round up byte
- ; requirements to the next multiple of 16, or use sbcalloc entry.
- ; For more do the following in line:
- ; mvi a,0
- ; call salloc; 1st 4k
- ; pop h; dealloc ptr, destroy hl
- ; mvi a,extra; part from 4096 to 8192
- ; call salloc
- ; xthl; save dealloc to 1st part
- ; At exit sp+2 is the lowest byte of the allocated memory.
- ; and carry is reset.
- ; a,f, (sp)
- .salloc::
- push b
- push d
- push h
- ora a; check for 0=256*16=4096
- cma
- mov l,a
- mvi h,0ffh
- inx h; so 0 in results in ff00h
- jnz sallo1
- dcr h; when we need a borrow
- sallo1: dad h
- dad h
- dad h
- dad h; 16* space requested
- xchg
- lxi h,8; allow for call & 3 pushes
- dad sp; present sp
- xchg
- dad d; hl points to new stk top, de old
- sphl; adjust stack.
- push d; save deallocate marker
- xchg
- mvi b,4
- sallo2: dcx h; copy ret adr. and saved regs to
- mov d,m; new stack top area
- dcx h
- mov e,m
- push d
- dcr b
- jnz sallo2
- pop h
- pop d
- pop b
- cmc; carry was set from before
- ret; with sp pointing to dealloc byte
- φⁿ