; ; stracc.s ; ; String accululator management ; ; © 1995 Straylight ; ;----- Standard header ------------------------------------------------------ GET libs:header GET libs:swis GET libs:stream ;----- External dependencies ------------------------------------------------ GET sapphire:flex GET sh.anchor ;----- 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,sail_stracc ;Point to the data LDMIB 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 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,sail_currAnchor ;Load the current anchor LDR R14,[R4,#0] ;This is an indirection! SUB R10,R10,R14 ;Convert R10 to offset ADD R3,R3,#512 ;Add on some room MOV R1,R3 ;We need this in R1 ADR R0,sail_straccStack ;Point to the anchor BL mem_realloc ;Reallocate the memory STR R3,sail_straccSize ;And store the new size LDR R0,[R4,#0] ;It's still an indirection ADD R10,R10,R0 ;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,sail_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,sail_stracc ;Point to the stracc data LDMIA R14,{R0,R2,R3} ;Load out the data STR R4,sail_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,sail_currAnchor ;Load the current anchor LDR R14,[R4,#0] ;Indirection alert SUB R10,R10,R14 ;Convert R10 to offset ADR R0,sail_straccStack ;Point to the anchor BL mem_realloc ;Reallocate as appropriate STR R1,sail_straccSize ;Store the new size LDR R14,[R4,#0] ;Indirection ADD R10,R10,R14 ;Convert R10 to address LDMFD R13!,{R0-R4,PC}^ ;And return to caller LTORG ;----- That's all, folks ---------------------------------------------------- END