2017-10-21 23:40:19 +00:00
|
|
|
mcopy mm.macros
|
|
|
|
****************************************************************
|
|
|
|
*
|
|
|
|
* Calloc - Allocate memory from a pool and set it to 0.
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* bytes - number of bytes to allocate
|
|
|
|
* useGlobalPool - should the memory come from the global
|
|
|
|
* (or local) pool
|
|
|
|
*
|
|
|
|
* Outputs:
|
|
|
|
* ptr - points to the first byte of the allocated memory
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
*
|
2017-07-15 00:45:40 +00:00
|
|
|
Calloc start cc
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
ptr equ 0 pointer to reserved memory
|
|
|
|
|
|
|
|
subroutine (2:bytes),4
|
|
|
|
|
|
|
|
ph2 bytes reserve the memory
|
|
|
|
jsl Malloc
|
|
|
|
sta ptr save the pointer to the memory
|
|
|
|
stx ptr+2
|
|
|
|
lda bytes if there are an odd number of bytes then
|
|
|
|
tay
|
|
|
|
lsr a
|
|
|
|
bcc lb1
|
|
|
|
short M zero the first byte
|
|
|
|
lda #0
|
|
|
|
dey
|
|
|
|
sta [ptr],Y
|
|
|
|
long M
|
|
|
|
lb1 tyx done if there are no more bytes
|
|
|
|
beq lb4
|
|
|
|
lda #0
|
|
|
|
dey branch if the next word is the zeroth
|
|
|
|
dey
|
|
|
|
beq lb3
|
|
|
|
lb2 sta [ptr],Y zero full words
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
bne lb2
|
|
|
|
lb3 sta [ptr] zero the last word
|
|
|
|
|
|
|
|
lb4 return 4:ptr return the pointer
|
|
|
|
end
|
|
|
|
|
|
|
|
****************************************************************
|
|
|
|
*
|
|
|
|
* GCalloc - Allocate and clear memory from the global pool.
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* bytes - number of bytes to allocate
|
|
|
|
*
|
|
|
|
* Outputs:
|
|
|
|
* ptr - points to the first byte of the allocated memory
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
*
|
2017-07-15 00:45:40 +00:00
|
|
|
GCalloc start cc
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
ptr equ 0 pointer to reserved memory
|
|
|
|
|
|
|
|
subroutine (2:bytes),4
|
|
|
|
|
|
|
|
ph2 bytes reserve the memory
|
|
|
|
jsl GMalloc
|
|
|
|
sta ptr save the pointer to the memory
|
|
|
|
stx ptr+2
|
|
|
|
lda bytes if there are an odd number of bytes then
|
|
|
|
tay
|
|
|
|
lsr a
|
|
|
|
bcc lb1
|
|
|
|
short M zero the first byte
|
|
|
|
lda #0
|
|
|
|
dey
|
|
|
|
sta [ptr],Y
|
|
|
|
long M
|
|
|
|
lb1 tyx done if there are no more bytes
|
|
|
|
beq lb4
|
|
|
|
lda #0
|
|
|
|
dey branch if the next word is the zeroth
|
|
|
|
dey
|
|
|
|
beq lb3
|
|
|
|
lb2 sta [ptr],Y zero full words
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
bne lb2
|
|
|
|
lb3 sta [ptr] zero the last word
|
|
|
|
|
|
|
|
lb4 return 4:ptr return the pointer
|
|
|
|
end
|
|
|
|
|
|
|
|
****************************************************************
|
|
|
|
*
|
|
|
|
* Malloc - Allocate memory from a pool.
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* bytes - number of bytes to allocate
|
|
|
|
* useGlobalPool - should the memory come from the global
|
|
|
|
* (or local) pool
|
|
|
|
*
|
|
|
|
* Outputs:
|
|
|
|
* ptr - points to the first byte of the allocated memory
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
*
|
2017-07-15 00:45:40 +00:00
|
|
|
Malloc start cc
|
2017-10-21 23:40:19 +00:00
|
|
|
|
2017-07-15 00:45:40 +00:00
|
|
|
lda |useGlobalPool
|
2017-10-21 23:40:19 +00:00
|
|
|
jne GMalloc
|
|
|
|
jmp LMalloc
|
|
|
|
end
|