chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / s / coords
1 ;
2 ; coords.s
3 ;
4 ; Messing about with lines and boxes
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Steel library.
12 ;
13 ; Steel is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Steel is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Steel.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard stuff -------------------------------------------------------
28
29                 GET     libs:header
30
31 ;----- Exported routines ----------------------------------------------------
32
33                 AREA    |C$$Code|,CODE,READONLY
34
35 ; --- coords_x_toscreen ---
36 ;
37 ; On entry:     a1 == abscissa to convert
38 ;               a2 == pointer to block of window coordinates
39 ; On exit:      a1 == a converted abscissa
40
41                 EXPORT  coords_x_toscreen
42 coords_x_toscreen
43                 LDR     a3,[a2,#0]              ;Get x0 from coords block
44                 LDR     a4,[a2,#16]             ;Get xsc from coords block
45                 SUB     a3,a3,a4                ;Get translation offset
46                 ADD     a1,a1,a3                ;Convert to screen coords
47                 MOVS    pc,lr                   ;Return to caller
48
49 ; --- coords_y_toscreen ---
50 ;
51 ; On entry:     a1 == ordinate to convert
52 ;               a2 == pointer to block of window coordinates
53 ; On exit:      a1 == a converted ordinate
54
55                 EXPORT  coords_y_toscreen
56 coords_y_toscreen
57                 ADD     a2,a2,#12               ;Find y1
58                 LDMIA   a2,{a3,a4,ip}           ;Get y1 and ysc (a4 not used)
59                 SUB     a3,a3,ip                ;Get translation offset
60                 ADD     a1,a1,a3                ;Convert to screen coords
61                 MOVS    pc,lr                   ;Return to caller
62
63 ; --- coords_x_toworkarea ---
64 ;
65 ; On entry:     a1 == abscissa to convert
66 ;               a2 == pointer to block of window coordinates
67 ; On exit:      a1 == a converted abscissa
68
69                 EXPORT  coords_x_toworkarea
70 coords_x_toworkarea
71                 LDR     a3,[a2,#0]              ;Get x0 from coords block
72                 LDR     a4,[a2,#16]             ;Get xsc from coords block
73                 SUB     a3,a3,a4                ;Get translation offset
74                 SUB     a1,a1,a3                ;Convert to window coords
75                 MOVS    pc,lr                   ;Return to caller
76
77 ; --- coords_y_toworkarea ---
78 ;
79 ; On entry:     a1 == ordinate to convert
80 ;               a2 == pointer to block of window coordinates
81 ; On exit:      a1 == a converted ordinate
82
83                 EXPORT  coords_y_toworkarea
84 coords_y_toworkarea
85                 ADD     a2,a2,#12               ;Find y1
86                 LDMIA   a2,{a3,a4,ip}           ;Get y1 and ysc (a4 not used)
87                 SUB     a3,a3,ip                ;Get translation offset
88                 SUB     a1,a1,a3                ;Convert to window coords
89                 MOVS    pc,lr                   ;Return to caller
90
91 ; --- coords_box_toscreen ---
92 ;
93 ; On entry:     a1 == pointer to box to convert
94 ;               a2 == pointer to coordinates block
95
96                 EXPORT  coords_box_toscreen
97 coords_box_toscreen
98                 STMFD   sp!,{v1,lr}
99                 LDR     a3,[a2,#0]              ;Get x0 from coords block
100                 ADD     a2,a2,#12               ;Point to y1
101                 LDMIA   a2,{a2,a4,v1}           ;Get y1 and scroll position
102                 SUB     a3,a3,a4                ;Get the x translation offset
103                 SUB     a2,a2,v1                ;Get the y translation offset
104                 LDMIA   a1,{a4,v1,ip,lr}
105                 ADD     a4,a4,a3
106                 ADD     v1,v1,a2
107                 ADD     ip,ip,a3
108                 ADD     lr,lr,a2
109                 STMIA   a1,{a4,v1,ip,lr}
110                 LDMFD   sp!,{v1,pc}^
111
112 ; --- coords_box_toworkarea ---
113 ;
114 ; On entry:     a1 == pointer to box to convert
115 ;               a2 == pointer to coordinates block
116
117                 EXPORT  coords_box_toworkarea
118 coords_box_toworkarea
119                 STMFD   sp!,{v1,lr}
120                 LDR     a3,[a2,#0]              ;Get x0 from coords block
121                 ADD     a2,a2,#12               ;Point to y1
122                 LDMIA   a2,{a2,a4,v1}           ;Get y1 and scroll position
123                 SUB     a3,a3,a4                ;Get the x translation offset
124                 SUB     a2,a2,v1                ;Get the y translation offset
125                 LDMIA   a1,{a4,v1,ip,lr}
126                 SUB     a4,a4,a3
127                 SUB     v1,v1,a2
128                 SUB     ip,ip,a3
129                 SUB     lr,lr,a2
130                 STMIA   a1,{a4,v1,ip,lr}
131                 LDMFD   sp!,{v1,pc}^
132
133 ; --- coords_point_toscreen ---
134 ;
135 ; On entry:     a1 == pointer to box to convert
136 ;               a2 == pointer to coordinates block
137
138                 EXPORT  coords_point_toscreen
139 coords_point_toscreen
140                 LDR     a3,[a2,#0]              ;Get x0 from coords block
141                 ADD     a2,a2,#12               ;Point to y1
142                 LDMIA   a2,{a2,a4,ip}           ;Get y1 and scroll position
143                 SUB     a3,a3,a4                ;Get the x translation offset
144                 SUB     a2,a2,ip                ;Get the y translation offset
145                 LDMIA   a1,{a4,ip}
146                 ADD     a4,a4,a3
147                 ADD     ip,ip,a2
148                 STMIA   a1,{a4,ip}
149                 MOVS    pc,lr
150
151 ; --- coords_point_toworkarea ---
152 ;
153 ; On entry:     a1 == pointer to box to convert
154 ;               a2 == pointer to coordinates block
155
156                 EXPORT  coords_point_toworkarea
157 coords_point_toworkarea
158                 LDR     a3,[a2,#0]              ;Get x0 from coords block
159                 ADD     a2,a2,#12               ;Point to y1
160                 LDMIA   a2,{a2,a4,ip}           ;Get y1 and scroll position
161                 SUB     a3,a3,a4                ;Get the x translation offset
162                 SUB     a2,a2,ip                ;Get the y translation offset
163                 LDMIA   a1,{a4,ip}
164                 SUB     a4,a4,a3
165                 SUB     ip,ip,a2
166                 STMIA   a1,{a4,ip}
167                 MOVS    pc,lr
168
169 ; --- coords_withinbox ---
170 ;
171 ; On entry:     a1 == pointer to a silly point structure
172 ;               a2 == pointer to a slightly more sensible box structure
173 ; On exit:      a1 == 1 if the point is inside the box
174
175                 EXPORT  coords_withinbox
176 coords_withinbox
177                 STMFD   sp!,{lr}                ;Save the link -- we need it
178                 LDMIA   a1,{a3,a4}              ;Get the point coordinates
179                 LDMIA   a2,{a1,a2,ip,lr}        ;Get the box coordinates
180                 CMP     a1,a3                   ;The magic cascaded condition
181                 CMPLE   a2,a4
182                 CMPLE   a3,ip
183                 CMPLE   a4,lr
184                 MOVLE   a1,#1                   ;If it succeeded, return TRUE
185                 MOVGT   a1,#0                   ;If not return FALSE
186                 LDMFD   sp!,{pc}^
187
188 ; --- coords_offsetbox ---
189 ;
190 ; On entry:     a1 == pointer to input box to mangle
191 ;               a2 == x offset to mangle by
192 ;               a3 == y offset to mangle by
193 ;               a4 == where to put the mangled bits
194
195                 EXPORT  coords_offsetbox
196 coords_offsetbox
197                 STMFD   sp!,{v1,lr}             ;Save some registers
198                 LDMIA   a1,{a1,v1,ip,lr}        ;Get the box coordinates
199                 ADD     a1,a1,a2
200                 ADD     v1,v1,a3
201                 ADD     ip,ip,a2
202                 ADD     lr,lr,a3
203                 STMIA   a4,{a1,v1,ip,lr}        ;Save the adjusted coords
204                 LDMFD   sp!,{v1,pc}^
205
206 ; --- coords_intersects ---
207 ;
208 ; On entry:     a1 == pointer to box structure containing the line
209 ;               a2 == pointer to box structure containing the rectangle
210 ;               a3 == the `width' of the line (ho-hum)
211 ; On exit:      a1 == 0 if it didn't, 1 if it did
212 ;
213 ; This implementation is a really yukky hack, and doesn't test whether the
214 ; line intersects at all, but it's good enough for jazz...
215
216                 EXPORT  coords_intersects
217 coords_intersects
218                 STMFD   sp!,{v1,v2,lr}          ;Save some registers
219                 LDMIA   a1,{a4,v1,v2,ip}        ;Get the line coordinates
220
221                 ; --- Sort coordinates properly ---
222
223                 CMP     a4,v2                   ;Sort the x coordinates
224                 EORGT   a4,a4,v2
225                 EORGT   v2,v2,a4
226                 EORGT   a4,a4,v2
227                 CMP     v1,ip                   ;Sort the y coordinates
228                 EORGT   v1,v1,ip
229                 EORGT   ip,ip,v1
230                 EORGT   v1,v1,ip
231
232                 ; --- `Widen' the line ---
233
234                 SUB     a4,a4,a3
235                 SUB     v1,v1,a3
236                 ADD     v2,v2,a3
237                 ADD     ip,ip,a3
238
239                 ; --- Now get the rectangle and compare ---
240
241                 LDMIA   a2,{a1-a3,lr}
242                 CMP     a4,a3
243                 CMPLE   v1,lr
244                 CMPLE   a1,v2
245                 CMPLE   a2,ip
246                 MOVLE   a1,#1
247                 MOVGT   a1,#0
248                 LDMFD   sp!,{v1,v2,pc}^
249
250 ; --- coords_boxesoverlap ---
251 ;
252 ; On entry:     a1,a2 == pointers to boxes
253 ; On exit:      a1 == 1 if boxes overlap, 0 otherwise
254
255                 EXPORT  coords_boxesoverlap
256 coords_boxesoverlap
257                 STMFD   sp!,{v1,v2,lr}          ;Save registers
258                 LDMIA   a1,{a3,a4,ip,lr}        ;Get coordinates of box 1
259                 LDMIA   a2,{a1,a2,v1,v2}        ;Get coordinates of box 2
260                 CMP     a3,v1                   ;Shhh.... it's a secret
261                 CMPLE   a4,v2
262                 CMPLE   a1,ip
263                 CMPLE   a2,lr
264                 MOVLE   a1,#1                   ;If intersection, return TRUE
265                 MOVGT   a1,#0                   ;Otherwise return FALSE
266                 LDMFD   sp!,{v1,v2,pc}^         ;Return to caller
267
268 ;----- That's all, folks ----------------------------------------------------
269
270                 END