4 ; String accululator management
9 ;----- Standard header ------------------------------------------------------
16 ;----- External dependencies ------------------------------------------------
22 ;----- Main code ------------------------------------------------------------
24 AREA |TermScrip$$Code|,CODE,READONLY
26 ; --- stracc_ensure ---
30 ; On exit: R0 == address of string to use
31 ; R1 == offset of string from stracc, in upper 24 bits
33 ; Use: Ensures tha there are at least 256 bytes available in stracc,
34 ; and then returns a pointer to them.
39 STMFD R13!,{R2-R4,R14} ;Stack registers
40 ADR R0,sail_stracc ;Point to the data
41 LDMIB R0,{R0,R2,R3} ;Load out the data
42 SUB R1,R3,R2 ;Look at how much is left
43 CMP R1,#256 ;Is there at least 256?
44 BLT %f00 ;No -- get some more
45 05 ADD R0,R0,R2 ;Point at memory to use
46 MOV R1,R2,LSL #8 ;Return offset to use
47 LDMFD R13!,{R2-R4,PC}^ ;Return to caller
49 00 LDR R4,sail_currAnchor ;Load the current anchor
50 LDR R14,[R4,#0] ;This is an indirection!
51 SUB R10,R10,R14 ;Convert R10 to offset
52 ADD R3,R3,#512 ;Add on some room
53 MOV R1,R3 ;We need this in R1
54 ADR R0,sail_straccStack ;Point to the anchor
55 BL mem_realloc ;Reallocate the memory
56 STR R3,sail_straccSize ;And store the new size
57 LDR R0,[R4,#0] ;It's still an indirection
58 ADD R10,R10,R0 ;Turn R10 into address
59 B %b05 ;And leap back again
63 ; --- stracc_added ---
65 ; On entry: R0 == rvalue of string added
69 ; Use: Informs stracc that a new string has been added.
74 STMFD R13!,{R14} ;Save registers
75 AND R14,R0,#&FF ;Get the string length
76 ADD R14,R14,R0,LSR #8 ;Add on the offset
77 STR R14,sail_straccPtr ;Store the new pointer
78 LDMFD R13!,{PC}^ ;Return to caller
84 ; On entry: R0 == rvalue of string no longer needed
88 ; Use: Tells stracc that a string is no longer needed.
93 STMFD R13!,{R0-R4,R14} ;Stack registers
94 AND R14,R0,#&FF ;Get the string length
95 MOV R4,R0,LSR #8 ;Get the new offset
96 ADR R14,sail_stracc ;Point to the stracc data
97 LDMIA R14,{R0,R2,R3} ;Load out the data
98 STR R4,sail_straccPtr ;Store new offset
99 SUB R14,R3,R4 ;Get free space size
100 SUBS R14,R14,#512 ;Calc amount to take off
101 LDMLEFD R13!,{R0-R4,PC}^ ;And return to caller
103 SUB R1,R3,R14 ;Work out new block size
104 LDR R4,sail_currAnchor ;Load the current anchor
105 LDR R14,[R4,#0] ;Indirection alert
106 SUB R10,R10,R14 ;Convert R10 to offset
107 ADR R0,sail_straccStack ;Point to the anchor
108 BL mem_realloc ;Reallocate as appropriate
109 STR R1,sail_straccSize ;Store the new size
110 LDR R14,[R4,#0] ;Indirection
111 ADD R10,R10,R14 ;Convert R10 to address
112 LDMFD R13!,{R0-R4,PC}^ ;And return to caller
116 ;----- That's all, folks ----------------------------------------------------