4 ; Messing about with lines and boxes
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Steel library.
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)
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.
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.
27 ;----- Standard stuff -------------------------------------------------------
31 ;----- Exported routines ----------------------------------------------------
33 AREA |C$$Code|,CODE,READONLY
35 ; --- coords_x_toscreen ---
37 ; On entry: a1 == abscissa to convert
38 ; a2 == pointer to block of window coordinates
39 ; On exit: a1 == a converted abscissa
41 EXPORT 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
49 ; --- coords_y_toscreen ---
51 ; On entry: a1 == ordinate to convert
52 ; a2 == pointer to block of window coordinates
53 ; On exit: a1 == a converted ordinate
55 EXPORT 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
63 ; --- coords_x_toworkarea ---
65 ; On entry: a1 == abscissa to convert
66 ; a2 == pointer to block of window coordinates
67 ; On exit: a1 == a converted abscissa
69 EXPORT 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
77 ; --- coords_y_toworkarea ---
79 ; On entry: a1 == ordinate to convert
80 ; a2 == pointer to block of window coordinates
81 ; On exit: a1 == a converted ordinate
83 EXPORT 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
91 ; --- coords_box_toscreen ---
93 ; On entry: a1 == pointer to box to convert
94 ; a2 == pointer to coordinates block
96 EXPORT coords_box_toscreen
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}
109 STMIA a1,{a4,v1,ip,lr}
112 ; --- coords_box_toworkarea ---
114 ; On entry: a1 == pointer to box to convert
115 ; a2 == pointer to coordinates block
117 EXPORT coords_box_toworkarea
118 coords_box_toworkarea
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}
130 STMIA a1,{a4,v1,ip,lr}
133 ; --- coords_point_toscreen ---
135 ; On entry: a1 == pointer to box to convert
136 ; a2 == pointer to coordinates block
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
151 ; --- coords_point_toworkarea ---
153 ; On entry: a1 == pointer to box to convert
154 ; a2 == pointer to coordinates block
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
169 ; --- coords_withinbox ---
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
175 EXPORT 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
184 MOVLE a1,#1 ;If it succeeded, return TRUE
185 MOVGT a1,#0 ;If not return FALSE
188 ; --- coords_offsetbox ---
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
195 EXPORT coords_offsetbox
197 STMFD sp!,{v1,lr} ;Save some registers
198 LDMIA a1,{a1,v1,ip,lr} ;Get the box coordinates
203 STMIA a4,{a1,v1,ip,lr} ;Save the adjusted coords
206 ; --- coords_intersects ---
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
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...
216 EXPORT coords_intersects
218 STMFD sp!,{v1,v2,lr} ;Save some registers
219 LDMIA a1,{a4,v1,v2,ip} ;Get the line coordinates
221 ; --- Sort coordinates properly ---
223 CMP a4,v2 ;Sort the x coordinates
227 CMP v1,ip ;Sort the y coordinates
232 ; --- `Widen' the line ---
239 ; --- Now get the rectangle and compare ---
248 LDMFD sp!,{v1,v2,pc}^
250 ; --- coords_boxesoverlap ---
252 ; On entry: a1,a2 == pointers to boxes
253 ; On exit: a1 == 1 if boxes overlap, 0 otherwise
255 EXPORT 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
264 MOVLE a1,#1 ;If intersection, return TRUE
265 MOVGT a1,#0 ;Otherwise return FALSE
266 LDMFD sp!,{v1,v2,pc}^ ;Return to caller
268 ;----- That's all, folks ----------------------------------------------------