Initial revision
[ssr] / StraySrc / Sculptrix / sculptrix / s / rules
1 ;
2 ; rules.s
3 ;
4 ; Draws horizontal and vertical rules for Sculptrix borders
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sculptrix.
12 ;
13 ; Sculptrix 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 ; Sculptrix 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 Sculptrix. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 GET libs:stream
33
34 ;----- The main idea --------------------------------------------------------
35 ;
36 ; In the new version of Sculptrix, we define border types in terms of
37 ; a collection of rules, which may be horizontal and vertical. The positions
38 ; of these rules relative to the icon, and their colours, are determined
39 ; by a `border definition', which is parsed elsewhere. This calls the
40 ; rule drawing routines through a standardised interface.
41 ;
42 ; On entry to a rule routine, the colour has already been set up, through
43 ; a call to Wimp_SetColour, or similar. Coordinates for the rule to plot
44 ; are passed in R3-R6, although all the registers may not have sensible
45 ; values. Values of dx, dy, and `start' are passed in R7, R8, and R9
46 ; respectively.
47
48 ;----- Main code ------------------------------------------------------------
49
50 AREA |Module$$Code|,CODE,READONLY
51
52 ; --- rule_left ---
53 ;
54 ; On entry: R3 == left hand side of the icon
55 ; R4 == bottom y position
56 ; R5 == unused
57 ; R6 == top y position
58 ; R7 == pixel width
59 ; R8 == pixel height
60 ; R9 == start position for mitring
61 ;
62 ; On exit: R0-R6 corrupted
63 ;
64 ; Use: Plots a vertical rule in the current colour.
65
66 EXPORT rule_left
67 rule_left ROUT
68
69 STMFD R13!,{R14} ;Save some registers
70
71 MOV R0,#move+abs ;Move cursor absolute
72 SUB R1,R3,#4 ;Get the x position sorted
73 SUB R2,R4,#4 ;And the y position
74 SWI XOS_Plot ;Move the graphics cursor
75
76 MOV R0,#rectfill+abs+fore ;Now do the rectangle fill
77 SUB R1,R3,R7 ;Find the x limit
78 SUB R2,R6,R8 ;And the y limit
79 ADD R2,R2,#4 ;Provide some overlap
80 SWI XOS_Plot ;Do that, please
81
82 LDMFD R13!,{PC}^ ;And return to caller
83
84 LTORG
85
86 ; --- rule_right ---
87 ;
88 ; On entry: R3 == unused
89 ; R4 == bottom y position
90 ; R5 == right hand side of the icon
91 ; R6 == top y position
92 ; R7 == pixel width
93 ; R8 == pixel height
94 ; R9 == start position for mitring
95 ;
96 ; On exit: R0-R6 corrupted
97 ;
98 ; Use: Plots a vertical rule in the current colour.
99
100 EXPORT rule_right
101 rule_right ROUT
102
103 STMFD R13!,{R14} ;Save some registers
104
105 MOV R0,#move+abs ;Move cursor absolute
106 MOV R1,R5 ;Get the x position sorted
107 SUB R2,R4,#4 ;And the y position
108 SWI XOS_Plot ;Move the graphics cursor
109
110 MOV R0,#rectfill+abs+fore ;Now do the rectangle fill
111 SUB R1,R5,R7 ;Find the x limit
112 ADD R1,R1,#4 ;Move over, for niceness
113 SUB R2,R6,R8 ;And the y limit
114 ADD R2,R2,#4 ;Provide some overlap
115 SWI XOS_Plot ;Do that, please
116
117 LDMFD R13!,{PC}^ ;And return to caller
118
119 LTORG
120
121 ; --- rule_top ---
122 ;
123 ; On entry: R3 == left hand side of the icon
124 ; R4 == unused
125 ; R5 == right hand side of the icon
126 ; R6 == top y position
127 ; R7 == pixel width
128 ; R8 == pixel height
129 ; R9 == start position for mitring
130 ;
131 ; On exit: R0-R6 corrupted
132 ;
133 ; Use: Plots a horizontal rule in the current colour.
134
135 EXPORT rule_top
136 rule_top ROUT
137
138 STMFD R13!,{R14} ;Save return address
139
140 ; --- Set up for the loop ---
141
142 ADD R4,R6,#4 ;A limit for the loop
143 SUB R5,R5,R7 ;Step back a pixel
144 ADD R5,R5,R9 ;And move on one too
145
146 ; --- Now do the plotting ---
147
148 00 MOV R0,#move+abs ;Move cursor absolute
149 SUB R1,R3,#4 ;Get the x position
150 MOV R2,R6 ;And the y position
151 SWI XOS_Plot ;Go and do that then
152 MOV R0,#line+abs+fore ;Draw line absolute
153 MOV R1,R5 ;Get the x limit value
154 MOV R2,R6 ;And the old y position
155 SWI XOS_Plot ;Go and do that, please
156
157 ADD R5,R5,R8 ;Extend the mitring
158 ADD R6,R6,R8 ;Move up by a pixel
159 CMP R6,R4 ;Have we reached the end?
160 BLT %b00 ;No -- look back then
161
162 LDMFD R13!,{PC}^ ;And return to caller
163
164 LTORG
165
166 ; --- rule_bottom ---
167 ;
168 ; On entry: R3 == left hand side of the icon
169 ; R4 == unused
170 ; R5 == right hand side of the icon
171 ; R6 == top y position
172 ; R7 == pixel width
173 ; R8 == pixel height
174 ; R9 == start position for mitring
175 ;
176 ; On exit: R0-R6 corrupted
177 ;
178 ; Use: Plots a horizontal rule in the current colour.
179
180 EXPORT rule_bottom
181 rule_bottom ROUT
182
183 STMFD R13!,{R14} ;Save return address
184
185 ; --- Set up for the loop ---
186
187 SUB R6,R4,R8 ;Drop down a pixel to start
188 SUB R4,R4,#4 ;A limit for the loop
189 SUB R3,R3,R9 ;And move on one too
190 SUBS R14,R7,R8 ;Which pixel size is bigger?
191 ADDPL R3,R3,R14 ;Bodge for flattened modes
192 SUB R5,R5,R7 ;Sort out right hand side
193
194 ; --- Now do the plotting ---
195
196 00 MOV R0,#move+abs ;Move cursor absolute
197 MOV R1,R3 ;Get the x position
198 MOV R2,R6 ;And the y position
199 SWI XOS_Plot ;Go and do that then
200 MOV R0,#line+abs+fore ;Draw line absolute
201 ADD R1,R5,#4 ;Get the x limit value
202 MOV R2,R6 ;And the old y position
203 SWI XOS_Plot ;Go and do that, please
204
205 SUB R3,R3,R8 ;Extend the mitring
206 SUB R6,R6,R8 ;Move up by a pixel
207 CMP R6,R4 ;Have we reached the end?
208 BGE %b00 ;No -- look back then
209
210 LDMFD R13!,{PC}^ ;And return to caller
211
212 LTORG
213
214 ; --- rule_pTop ---
215 ;
216 ; On entry: R3 == left hand side of the icon
217 ; R4 == unused
218 ; R5 == right hand side of the icon
219 ; R6 == top y position
220 ; R7 == pixel width
221 ; R8 == pixel height
222 ; R9 == start position for mitring
223 ;
224 ; On exit: R0-R6 corrupted
225 ;
226 ; Use: Plots a horizontal rule in the current colour, without
227 ; mitring.
228
229 EXPORT rule_pTop
230 rule_pTop ROUT
231
232 STMFD R13!,{R14} ;Save return address
233
234 MOV R0,#move+abs ;Move cursor absolute
235 SUB R1,R3,#4 ;Sort out left hand side
236 MOV R2,R6 ;And the y position
237 SWI XOS_Plot ;Move the cursor
238
239 MOV R0,#rectfill+abs+fore ;Plot the rectangle
240 SUB R1,R5,R7 ;Sort out the overhang
241 ADD R1,R1,#4 ;And add some overlap
242 SUB R2,R6,R8 ;Set the y position
243 ADD R2,R2,#4 ;Move up a little
244 SWI XOS_Plot ;And plot the rectangle
245
246 LDMFD R13!,{PC}^ ;And return to caller
247
248 LTORG
249
250 ; --- rule_pBottom ---
251 ;
252 ; On entry: R3 == left hand side of the icon
253 ; R4 == unused
254 ; R5 == right hand side of the icon
255 ; R6 == top y position
256 ; R7 == pixel width
257 ; R8 == pixel height
258 ; R9 == start position for mitring
259 ;
260 ; On exit: R0-R6 corrupted
261 ;
262 ; Use: Plots a horizontal rule in the current colour, without
263 ; mitring.
264
265 EXPORT rule_pBottom
266 rule_pBottom ROUT
267
268 STMFD R13!,{R14} ;Save return address
269
270 MOV R0,#move+abs ;Move cursor absolute
271 SUB R1,R3,#4 ;Sort out left hand side
272 SUB R2,R4,#4 ;And the y position
273 SWI XOS_Plot ;Move the cursor
274
275 MOV R0,#rectfill+abs+fore ;Plot the rectangle
276 SUB R1,R5,R7 ;Sort out the overhang
277 ADD R1,R1,#4 ;And add some overlap
278 SUB R2,R4,R8 ;Set the y position
279 SWI XOS_Plot ;And plot the rectangle
280
281 LDMFD R13!,{PC}^ ;And return to caller
282
283 LTORG
284
285 ; --- rule_border ---
286 ;
287 ; On entry: R3 == left hand side of the icon
288 ; R4 == bottom edge of icon
289 ; R5 == right hand side of the icon
290 ; R6 == top y position
291 ; R7 == pixel width
292 ; R8 == pixel height
293 ; R9 == start position for mitring
294 ;
295 ; On exit: R0-R6 corrupted
296 ;
297 ; Use: Fills the icon in, and plots a border around it, using the
298 ; current foreground and background colours.
299
300 EXPORT rule_border
301 rule_border ROUT
302
303 STMFD R13!,{R14} ;Save return address
304
305 ; --- Fill in the background ---
306 ;
307 ; We plot /within/ the border, to ensure that there's no
308 ; flicker.
309
310 MOV R0,#move+abs ;Move cursor absolute
311 ADD R1,R3,R7 ;Move slightly inwards
312 ADD R2,R4,R8 ;Move slightly upwards
313 SWI XOS_Plot ;Do the plotting
314
315 MOV R0,#rectfill+abs+back ;Plot rectangle in background
316 SUB R1,R5,R7,LSL #1 ;Move inwards from right
317 SUB R2,R6,R8,LSL #1 ;And downwards from top
318 SWI XOS_Plot ;Do the rectangle now
319
320 ; --- Plot the border around the edge ---
321
322 MOV R0,#move+abs ;Move cursor absolute
323 MOV R1,R3 ;Start on the left
324 MOV R2,R4 ;And at the bottom
325 SWI XOS_Plot ;Move the cursor
326
327 MOV R0,#line+abs+fore ;Draw line absolute
328 MOV R1,R3 ;Stay on the left
329 SUB R2,R6,R8 ;Move to the top
330 SWI XOS_Plot ;Draw the line
331
332 MOV R0,#line+abs+fore ;Draw line absolute
333 SUB R1,R5,R7 ;Move to the right
334 SUB R2,R6,R8 ;Stay at the top
335 SWI XOS_Plot ;Draw the line
336
337 MOV R0,#line+abs+fore ;Draw line absolute
338 SUB R1,R5,R7 ;Stay on the right
339 MOV R2,R4 ;Move to the bottom
340 SWI XOS_Plot ;Draw the line
341
342 MOV R0,#line+abs+fore ;Draw line absolute
343 MOV R1,R3 ;Move to the left
344 MOV R2,R4 ;Stay at the bottom
345 SWI XOS_Plot ;Draw the line
346
347 LDMFD R13!,{PC}^ ;Return when done
348
349 LTORG
350
351 ;----- Plot codes -----------------------------------------------------------
352
353 rel EQU 0
354 abs EQU 4
355
356 move EQU 0
357 line EQU 0
358 rectfill EQU 96
359
360 fore EQU 1
361 back EQU 3
362
363 ;----- That's all, folks ----------------------------------------------------
364
365 END