Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sail / _s / stracc
1 ;
2 ; stracc.s
3 ;
4 ; String accululator management
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 GET libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18 GET sh.anchor
19 GET sh.mem
20
21 ;----- Main code ------------------------------------------------------------
22
23 AREA |TermScrip$$Code|,CODE,READONLY
24
25 ; --- stracc_ensure ---
26 ;
27 ; On entry: --
28 ;
29 ; On exit: R0 == address of string to use
30 ; R1 == offset of string from stracc, in upper 24 bits
31 ;
32 ; Use: Ensures tha there are at least 256 bytes available in stracc,
33 ; and then returns a pointer to them.
34
35 EXPORT stracc_ensure
36 stracc_ensure ROUT
37
38 STMFD R13!,{R2-R4,R14} ;Stack registers
39 ADR R0,tsc_stracc ;Point to the data
40 LDMIA R0,{R0,R2,R3} ;Load out the data
41 SUB R1,R3,R2 ;Look at how much is left
42 CMP R1,#256 ;Is there at least 256?
43 BLT %f00 ;No -- get some more
44 05 LDR R0,[R0] ;Point to the block
45 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
48
49 00 LDR R4,tsc_currAnchor ;Load the current anchor
50 LDR R14,[R4,#0] ;Bop WimpExtention
51 SUB R10,R10,R14 ;Convert R10 to offset
52 ADD R3,R3,#512 ;No -- add on some then
53 MOV R1,R3 ;Put this size in R1
54 BL mem_realloc ;Reallocate the memory
55 STR R3,tsc_straccSize ;And store the new size
56 LDR R14,[R4,#0] ;Bop WimpExtention
57 ADD R10,R10,R14 ;Turn R10 into address
58 B %b05 ;And leap back again
59
60 LTORG
61
62 ; --- stracc_added ---
63 ;
64 ; On entry: R0 == rvalue of string added
65 ;
66 ; On exit: --
67 ;
68 ; Use: Informs stracc that a new string has been added.
69
70 EXPORT stracc_added
71 stracc_added ROUT
72
73 STMFD R13!,{R14} ;Save registers
74 AND R14,R0,#&FF ;Get the string length
75 ADD R14,R14,R0,LSR #8 ;Add on the offset
76 STR R14,tsc_straccPtr ;Store the new pointer
77 LDMFD R13!,{PC}^ ;Return to caller
78
79 LTORG
80
81 ; --- stracc_free ---
82 ;
83 ; On entry: R0 == rvalue of string no longer needed
84 ;
85 ; On exit: --
86 ;
87 ; Use: Tells stracc that a string is no longer needed.
88
89 EXPORT stracc_free
90 stracc_free ROUT
91
92 STMFD R13!,{R0-R4,R14} ;Stack registers
93 AND R14,R0,#&FF ;Get the string length
94 MOV R4,R0,LSR #8 ;Get the new offset
95 ADR R14,tsc_stracc ;Point to the stracc data
96 LDMIA R14,{R0,R2,R3} ;Load out the data
97 STR R4,tsc_straccPtr ;Store new offset
98 SUB R14,R3,R4 ;Get free space size
99 SUBS R14,R14,#512 ;Calc amount to take off
100 LDMLEFD R13!,{R0-R4,PC}^ ;And return to caller
101
102 SUB R1,R3,R14 ;Work out new block size
103 LDR R4,tsc_currAnchor ;Load the current anchor
104 LDR R14,[R4,#0] ;Bop WimpExtention
105 SUB R10,R10,R14 ;Convert R10 to offset
106 BL mem_realloc ;Reallocate as appropriate
107 STR R1,tsc_straccSize ;Store the new size
108 LDR R14,[R4,#0] ;Bop WimpExtention
109 ADD R10,R10,R14 ;Convert R10 to address
110 LDMFD R13!,{R0-R4,PC}^ ;And return to caller
111
112 LTORG
113
114 ;----- That's all, folks ----------------------------------------------------
115
116 END