; ; stracc.s ; ; String accululator management ; ; © 1995 Straylight ; ;----- Standard header ------------------------------------------------------ GET libs:header GET libs:swis GET libs:stream ;----- External dependencies ------------------------------------------------ GET sh.anchor GET sh.mem ;----- Main code ------------------------------------------------------------ AREA |TermScrip$$Code|,CODE,READONLY ; --- stracc_ensure --- ; ; On entry: -- ; ; On exit: R0 == address of string to use ; R1 == offset of string from stracc, in upper 24 bits ; ; Use: Ensures tha there are at least 256 bytes available in stracc, ; and then returns a pointer to them. EXPORT stracc_ensure stracc_ensure ROUT STMFD R13!,{R2-R4,R14} ;Stack registers ADR R0,tsc_stracc ;Point to the data LDMIA R0,{R0,R2,R3} ;Load out the data SUB R1,R3,R2 ;Look at how much is left CMP R1,#256 ;Is there at least 256? BLT %f00 ;No -- get some more 05 LDR R0,[R0] ;Point to the block ADD R0,R0,R2 ;Point at memory to use MOV R1,R2,LSL #8 ;Return offset to use LDMFD R13!,{R2-R4,PC}^ ;Return to caller 00 LDR R4,tsc_currAnchor ;Load the current anchor LDR R14,[R4,#0] ;Bop WimpExtention SUB R10,R10,R14 ;Convert R10 to offset ADD R3,R3,#512 ;No -- add on some then MOV R1,R3 ;Put this size in R1 BL mem_realloc ;Reallocate the memory STR R3,tsc_straccSize ;And store the new size LDR R14,[R4,#0] ;Bop WimpExtention ADD R10,R10,R14 ;Turn R10 into address B %b05 ;And leap back again LTORG ; --- stracc_added --- ; ; On entry: R0 == rvalue of string added ; ; On exit: -- ; ; Use: Informs stracc that a new string has been added. EXPORT stracc_added stracc_added ROUT STMFD R13!,{R14} ;Save registers AND R14,R0,#&FF ;Get the string length ADD R14,R14,R0,LSR #8 ;Add on the offset STR R14,tsc_straccPtr ;Store the new pointer LDMFD R13!,{PC}^ ;Return to caller LTORG ; --- stracc_free --- ; ; On entry: R0 == rvalue of string no longer needed ; ; On exit: -- ; ; Use: Tells stracc that a string is no longer needed. EXPORT stracc_free stracc_free ROUT STMFD R13!,{R0-R4,R14} ;Stack registers AND R14,R0,#&FF ;Get the string length MOV R4,R0,LSR #8 ;Get the new offset ADR R14,tsc_stracc ;Point to the stracc data LDMIA R14,{R0,R2,R3} ;Load out the data STR R4,tsc_straccPtr ;Store new offset SUB R14,R3,R4 ;Get free space size SUBS R14,R14,#512 ;Calc amount to take off LDMLEFD R13!,{R0-R4,PC}^ ;And return to caller SUB R1,R3,R14 ;Work out new block size LDR R4,tsc_currAnchor ;Load the current anchor LDR R14,[R4,#0] ;Bop WimpExtention SUB R10,R10,R14 ;Convert R10 to offset BL mem_realloc ;Reallocate as appropriate STR R1,tsc_straccSize ;Store the new size LDR R14,[R4,#0] ;Bop WimpExtention ADD R10,R10,R14 ;Convert R10 to address LDMFD R13!,{R0-R4,PC}^ ;And return to caller LTORG ;----- That's all, folks ---------------------------------------------------- END