; ; mem.s ; ; Generic memory allocation for TermScript ; ; © 1995 Straylight ; ;----- Standard Header ------------------------------------------------------ GET libs:header GET libs:swis GET libs:stream ;----- External dependencies ------------------------------------------------ GET sh.errNum GET sh.error ;----- Main code ------------------------------------------------------------ AREA |TermScript$$Code|,CODE,READONLY ; --- mem_alloc --- ; ; On entry: R0 == size of block to allocate ; ; On exit: R0 == pointer to anchor for that block ; May return an error ; ; Use: Tries to allocate a block of memory, and returns a pointer ; to the anchor for that block. All very unusual really, ; but we blame Wimp_Extension which allocates anchors for ; you in an utterley horrible way. EXPORT mem_alloc mem_alloc ROUT ; --- For now, we will use the RMA --- STMFD R13!,{R1-R3,R14} ADD R3,R0,#4 MOV R0,#6 SWI XOS_Module BVS %99mem_alloc ADD R3,R2,#4 STR R3,[R2,#0] MOV R0,R2 LDMFD R13!,{R1-R3,PC}^ 99mem_alloc MOV R0,#err_noMem B error_report LTORG ; --- mem_free --- ; ; On entry: R0 == anchor of the block to free ; ; On exit: -- ; ; Use: Frees the block. EXPORT mem_free mem_free ROUT STMFD R13!,{R0-R2,R14} LDR R2,[R0,#0] SUB R2,R2,#4 MOV R0,#7 SWI OS_Module LDMFD R13!,{R0-R2,PC}^ LTORG ; --- mem_realloc --- ; ; On entry: R0 == pointer to block anchor ; R1 == new size requested ; ; On exit: May return an error ; ; Use: Resizes a block EXPORT mem_realloc mem_realloc ROUT MOV R0,#err_realloc B error_report LTORG ;----- That's all, folks ---------------------------------------------------- END