chiark / gitweb /
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     sapphire:flex
19
20                 GET     sh.anchor
21
22 ;----- Main code ------------------------------------------------------------
23
24                 AREA    |TermScrip$$Code|,CODE,READONLY
25
26 ; --- stracc_ensure ---
27 ;
28 ; On entry:     --
29 ;
30 ; On exit:      R0 == address of string to use
31 ;               R1 == offset of string from stracc, in upper 24 bits
32 ;
33 ; Use:          Ensures tha there are at least 256 bytes available in stracc,
34 ;               and then returns a pointer to them.
35
36                 EXPORT  stracc_ensure
37 stracc_ensure   ROUT
38
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
48
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
60
61                 LTORG
62
63 ; --- stracc_added ---
64 ;
65 ; On entry:     R0 == rvalue of string added
66 ;
67 ; On exit:      --
68 ;
69 ; Use:          Informs stracc that a new string has been added.
70
71                 EXPORT  stracc_added
72 stracc_added    ROUT
73
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
79
80                 LTORG
81
82 ; --- stracc_free ---
83 ;
84 ; On entry:     R0 == rvalue of string no longer needed
85 ;
86 ; On exit:      --
87 ;
88 ; Use:          Tells stracc that a string is no longer needed.
89
90                 EXPORT  stracc_free
91 stracc_free     ROUT
92
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
102
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
113
114                 LTORG
115
116 ;----- That's all, folks ----------------------------------------------------
117
118                 END