uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

heap.tal (1205B)


      1 (
      2 	heap functions
      3 
      4 	The heap is an area of memory that is written from the bottom up. These
      5 	are a few convenience functions to do that writing.
      6 
      7 	There is a global short called "heap" that must be written to before using
      8 	these functions, otherwise the zero page and program memory could be
      9 	overwritten.
     10 
     11 	A simple program could use all unallocated memory for the heap like so:
     12 
     13 		|0100 @reset
     14 			;my-heap ;heap STA2
     15 
     16 			(the rest of your code)
     17 
     18 		@my-heap
     19 
     20 	Note that if there is a risk that the heap may overflow its bounds, it is
     21 	strongly recommended to check where it is writing to. ";heap LDA2" will
     22 	tell you where the next byte is written.
     23 )
     24 
     25 @heap $2
     26 
     27 @append-heap-byte ( byte -- )
     28 	,heap LDR2 ( byte heap* )
     29 	INC2k ,heap STR2
     30 	STA
     31 	JMP2r
     32 
     33 @append-heap-short ( short^ -- )
     34 	,heap LDR2 ( short^ heap* )
     35 	INC2k INC2 ,heap STR2
     36 	STA2
     37 	JMP2r
     38 
     39 @append-heap-string ( string* -- )
     40 	( copies a null-terminated string onto the heap, including the null )
     41 	STH2 ,heap LDR2 ( heap* / string* )
     42 	#01 JMP ( skip past INC2r )
     43 
     44 	&loop
     45 	INC2r ( heap* / string* )
     46 	LDAkr DUPr STH2k STAr ( heap* / string* byte )
     47 	INC2
     48 	LITr f7 JCNr ( f7 is the value ",&loop" would produce )
     49 	POP2r ( heap* )
     50 	,heap STR2
     51 	JMP2r
     52