Coding : malloc & free

Malloc & free are available for kernel commands only (for instance).

You must include orix macro header and call MALLOC macro : MALLOC(size)

#include "src/include/macro.h"
; Declare ZP (there is 4 16 bits ZP adress, in the future, this 4 adress in ZP will be save when multitasking will be available)
#define MALLOC_PTR1 ZP_APP_PTR1
#define MALLOC_PTR1_SAVE ZP_APP_PTR2 ; used to do free memory at the end, you can avoid this, because Orix will flush your malloc chunks when your program stops, but it's better when your program get more and more memory :)
 
MALLOC(1000) ; Malloc 1000 bytes (macro)
; at this step A & Y contains the pointer
; store pointer in ZP
sta MALLOC_PTR1
sty MALLOC_PTR1
sta MALLOC_PTR1_SAVE
sty MALLOC_PTR1_SAVE
 
ldy #$00
lda #65 ; store A in the adress
sta(MALLOC_PTR1),y
 
; And let's free :)

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*