Initial revision
[ssr] / StraySrc / Sculptrix / sculptrix / s / plot
1 ;
2 ; plot.s
3 ;
4 ; Plots border types
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 ;----- External dependencies ------------------------------------------------
35
36 GET sh.border
37 GET sh.rules
38 GET sh.utils
39 GET sh.vString
40
41 GET sh.wSpace
42
43 ;----- Macros ---------------------------------------------------------------
44
45 MACRO
46 $label DCO $addr
47 $label DCD $addr-{PC}
48 MEND
49
50 ;----- Main code ------------------------------------------------------------
51
52 AREA |Module$$Code|,CODE,READONLY
53
54 ; --- plot_border ---
55 ;
56 ; On entry: R0 == pointer to border type
57 ; R1 == pointer to icon block
58 ; R2,R3 == window origin position
59 ;
60 ; On exit: May return an error
61 ;
62 ; Use: Plots the given border type.
63
64 EXPORT plot_border
65 plot_border ROUT
66
67 STMFD R13!,{R14} ;Save a register
68 AND R14,R0,#&0000FF00 ;Extract the general code
69 CMP R14,#(%10-%00)<<6 ;Check it's in range
70 ADDCC PC,PC,R14,LSR #6 ;Yes -- dispatch it then
71 LDMFD R13!,{PC} ;Otherwise ignore it
72
73 00 B plot__simple ;Plot something simple
74 B plot__group ;Plot a group box
75 B plot__tns ;Plot a text+sprite icon
76 10
77 LTORG
78
79 ; --- plot__simple ---
80 ;
81 ; On entry: R0 == pointer to border type
82 ; R1 == pointer to icon block
83 ; R2,R3 == window origin position
84 ;
85 ; On exit: May return an error
86 ;
87 ; Use: Plots a simple border type.
88
89 plot__simple ROUT
90
91 STMFD R13!,{R4} ;Save some registers
92
93 ; --- Sort out which colour to use ---
94
95 ADR R4,sculpt_colours ;Point to colour tables
96 LDR R14,[R1,#16] ;Load the icon flags
97 EOR R14,R14,#&005F0000 ;Toggle shade and ESG bits
98 TST R14,#&00400000 ;Test the shaded bit
99 TSTNE R14,#&001F0000 ;And then the ESG bits
100 ADDEQ R4,R4,#8 ;If shaded, select table
101 TST R0,#vsFlag_fade ;Is the icon faded?
102 ADDNE R4,R4,#4 ;Yes -- then fade it
103 TST R0,#vsFlag_invert ;Is the icon inverted?
104 ADDNE R4,R4,#1 ;Yes -- invert it
105
106 ; --- Now plot the thing ---
107
108 ADR R14,plot__table ;Point to the table
109 AND R0,R0,#&FF ;Extract the subtype
110 LDR R0,[R14,R0,LSL #2]! ;Load the offset out
111 ADD R0,R14,R0 ;Add on to find the address
112 BL border_plot ;Go and plot it then
113 LDMFD R13!,{R4,PC} ;Return when finished
114
115 plot__table DCO plot__action
116 DCO plot__default
117 DCO plot__ridge
118 DCO plot__write
119 DCO plot__offset
120
121 LTORG
122
123 ; --- plot_group ---
124 ;
125 ; On entry: R0 == pointer to border type
126 ; R1 == pointer to icon block
127 ; R2,R3 == window origin position
128 ; R6 == pointer to group title
129 ;
130 ; On exit: May return an error
131 ;
132 ; Use: Plots a group box.
133
134 EXPORT plot_group
135 plot_group ROUT
136
137 STMFD R13!,{R4-R6,R14} ;Save some registers
138 B %f00 ;And skip on...
139
140 plot__group STMFD R13!,{R4-R6} ;Save some registers
141 ADR R6,sculpt_misc ;Point to string in buffer
142
143 ; --- Sort out the text width ---
144
145 00 MOV R0,R6 ;Point to the text string
146 BL utils_strWidth ;Work out the width, please
147 ADD R5,R0,#16 ;Add some extra each side
148
149 ; --- Work out the group colours ---
150
151 ADR R4,sculpt_groupCol ;Point to group colour table
152 LDR R14,[R1,#16] ;Load the icon flags
153 EOR R14,R14,#&005F0000 ;Toggle shade and ESG bits
154 TST R14,#&00400000 ;Test the shaded bit
155 TSTNE R14,#&001F0000 ;And then the ESG bits
156 ADDEQ R4,R4,#8 ;If shaded, select table
157 LDR R14,sculpt_flags ;Load the flags word
158 TST R14,#scFlag_acorn ;Acorn style group box?
159 ADDNE R4,R4,#1 ;Yes -- invert colours then
160 ADREQ R0,plot__stdGroup ;No -- point to standard rtn
161 ADRNE R0,plot__acnGroup ;Yes -- use Acorn one
162 BL border_plot ;Plot the group box
163 LDMFD R13!,{R4-R6,PC} ;Return when done
164
165 LTORG
166
167 ; --- plot__tns ---
168 ;
169 ; On entry: R0 == pointer to border type
170 ; R1 == pointer to icon block
171 ; R2,R3 == window origin position
172 ;
173 ; On exit: --
174 ;
175 ; Use: Plots a text+sprite icon.
176
177 plot__tns ROUT
178
179 STMFD R13!,{R0-R6} ;Save lots of registers
180 SWI XWimp_PlotIcon ;Plot the sprite
181 BL plot_tnsBBox ;Find the icon bounding box
182 BCC %90plot__tns ;If that failed, return now
183
184 ; --- Now plot the icon ---
185
186 70plot__tns SUB R13,R13,#32 ;Make space for icon block
187 STMIA R13,{R0-R3} ;Save them away, please
188
189 BIC R4,R4,#&00000006 ;Clear border and sprite bits
190 BIC R4,R4,#&00200000 ;Clear selected bit
191
192 MOV R0,#8 ;Get the current font handle
193 SWI XWimp_ReadSysInfo ;Do that, please
194 MOVVS R0,#0 ;If not known, assume none
195 CMP R0,#0 ;Do we have a font?
196 TSTEQ R4,#&60 ;Is the icon anti-aliased?
197 BEQ %80plot__tns ;No -- skip ahead then
198
199 ; --- See if the icon's shaded ---
200 ;
201 ; If it is, fix it so that it looks right. In keeping with
202 ; the WindowManager's simpleminded view of colour selection,
203 ; this just involves clearing some bits.
204
205 MVN R14,R4 ;Invert all the bits, please
206 TST R14,#&00400000 ;Test the shaded bit
207 TSTNE R14,#&001F0000 ;And then the ESG bits
208 BICEQ R4,R4,#&0B000000 ;If shaded, change colour
209
210 ; --- Now fill in the rest of the data ---
211
212 80plot__tns BIC R4,R4,#&00400000 ;Clear shaded bit anyway
213 ADR R5,sculpt_misc ;Point to the text buffer
214 MOV R6,#-1 ;No validation string
215 MOV R14,#1 ;A random string length
216
217 ADD R0,R13,#16 ;Point into the buffer
218 STMIA R0,{R4-R6,R14} ;Store them away
219 MOV R1,R13 ;Point to the icon block
220 SWI XWimp_PlotIcon ;Plot the icon, please
221 ADD R13,R13,#32 ;Restore the stack pointer
222
223 90plot__tns LDMFD R13!,{R0-R6,PC}^ ;Return to caller when done
224
225 LTORG
226
227 ; --- plot_tnsBBox ---
228 ;
229 ; On entry: R1 == pointer to an icon block
230 ;
231 ; On exit: CS if sprite found, and
232 ; R0-R3 == bounding box of icon
233 ; R4 == icon flags word (modified)
234 ; else CC and registers preserved
235 ;
236 ; Use: Works out where the text of the icon ought to be. (Actually
237 ; the box returned is too wide, although this will probably
238 ; be good enough for most purposes.)
239
240 EXPORT plot_tnsBBox
241 plot_tnsBBox ROUT
242
243 STMFD R13!,{R0-R6,R14} ;Save some registers
244
245 LDR R4,[R1,#16] ;Load the icon flags
246 AND R14,R4,#&218 ;Extract the position bits
247 CMP R14,#&010 ;Only vertical centring?
248 BEQ %50plot_tnsBBox ;Yes -- this is trickier
249
250 LDMIA R1,{R0-R3} ;Load the icon data
251
252 ; --- Work out where to put the icon ---
253
254 MOV R14,R14,LSR #3 ;Shift the bits down
255 TST R4,#&200 ;Is it right aligned?
256 EORNE R14,R14,#&44 ;Yes -- move the bit down
257 ADR R6,plot__alignTbl ;Point to a table
258 LDRB R6,[R6,R14] ;Load the entry we want
259 EOR R4,R4,R6,LSL #2 ;And jiggle the bits
260
261 ADR R6,plot__psnTbl ;Point to position table
262 LDRB R6,[R6,R14] ;Load the magic number
263 CMP R6,#1 ;Which is it?
264 ADDEQ R1,R1,R3 ;Centre -- add them up
265 MOVEQ R1,R1,ASR #1 ;Divide by two
266 SUBEQ R1,R1,#18 ;And move down a bit
267 ADDLE R3,R1,#36 ;Bottom -- sort it
268 SUBGT R1,R3,#36 ;Top -- sort it
269
270 B %90plot_tnsBBox ;Return because it worked
271
272 ; --- Handle the sprite data ---
273
274 50plot_tnsBBox MOV R0,#'s' ;Search for an `s' command
275 MOV R2,#0 ;Start from the beginning
276 BL vString_find ;Find the validation string
277 BCC %99plot_tnsBBox ;If not found, ignore it
278
279 ADR R1,sculpt_small ;Point to a buffer
280 ADD R2,R2,#1 ;Skip past the `s'
281 00 LDRB R14,[R2],#1 ;Load a byte
282 CMP R14,#',' ;A different sprite?
283 CMPNE R14,#';' ;A different command?
284 CMPNE R14,#&1F ;Or the end of the string?
285 MOVLS R14,#0 ;Any of them -- take a zero
286 STRB R14,[R1],#1 ;Store that away
287 BHI %b00 ;And keep looping until done
288
289 ; --- Read the sprite information ---
290
291 ADR R2,sculpt_small ;Point to small buffer
292 LDR R1,sculpt_sprArea ;Load the area pointer
293 CMP R1,#1 ;Is this the Wimp area?
294 BEQ %f00 ;Yes -- skip onwards
295
296 MOV R0,#40 ;Read sprite information
297 ORR R0,R0,#&100 ;Set the user area bit
298 SWI XOS_SpriteOp ;Read the information
299 BVC %f01 ;If OK, skip onwards
300
301 00 MOV R0,#40 ;Read sprite information
302 SWI XWimp_SpriteOp ;Read the information
303 BVS %99plot_tnsBBox ;If failed quit now
304
305 ; --- Sort out the sprite width ---
306
307 01 MOV R0,R6 ;Get the sprite mode
308 MOV R1,#4 ;Read the x EIG factor
309 SWI XOS_ReadModeVariable ;Try to do that
310 BVS %99plot_tnsBBox ;If failed quit now
311 BCS %99plot_tnsBBox ;If failed quit now
312 MOV R5,R3,LSL R2 ;Work out the width now
313
314 ; --- Play with the icon data now ---
315
316 LDR R1,[R13,#4] ;Load the icon address
317 LDMIA R1,{R0-R4} ;Load all that information
318 ADD R0,R0,R5 ;Move the left hand side over
319
320 ADD R1,R1,R3 ;Centre -- add them up
321 MOV R1,R1,ASR #1 ;Divide by two
322 SUB R1,R1,#18 ;And move down a bit
323 ADD R3,R1,#36 ;Sort out the upper limit
324
325 ; --- Return to caller ---
326
327 90plot_tnsBBox ADD R13,R13,#20 ;Don't restore R0-R4
328 LDMFD R13!,{R5,R6,R14} ;Restore other registers
329 ORRS PC,R14,#C_flag ;And return C set on exit
330
331 99plot_tnsBBox LDMFD R13!,{R0-R6,R14} ;Restore other registers
332 BICS PC,R14,#C_flag ;And return a failed result
333
334 ; --- Alignment table ---
335 ;
336 ; Each entry contains an EOR mask which should be applied to
337 ; the icon flags for the text icon. In order to make them
338 ; fit into single bytes, they're all shifted right two
339 ; places. This lets me know whether the text needs to be
340 ; centred or whatever in those cases where it's not actually
341 ; obvious from the original flags.
342
343 plot__alignTbl DCB 0,0,0,&80
344 DCB 0,0,&80,&02
345
346 ; --- Position table ---
347 ;
348 ; Each entry contains a value used to position the icon
349 ; vertically. Zero means that the text is at the bottom of
350 ; the icon, one means that it's in the middle, and two means
351 ; that it's at the top.
352
353 plot__psnTbl DCB 0,0,0,1
354 DCB 0,2,1,1
355
356 LTORG
357
358 ;----- Group box routines ---------------------------------------------------
359
360 ; --- plot__stdGroup ---
361
362 plot__stdGroup ROUT
363
364 BCALL plot__gBorder
365 BCALL plot__findPlinth
366 BCALL plot__plinth
367
368 BDARK
369 BLDIY1
370 BSTY1
371 BLDIX0
372 BSTX0
373 BADD 16-4
374 BSTX1
375 BPLOT rule_top
376
377 BLIGHT
378 BLDIY1
379 BADD 8
380 BSTY0
381 BLDIX0
382 BADD 16+4
383 BSKIPT
384 BSTX0
385 BSTX1
386 BPLOT rule_bottom
387
388 BCALL plot__findPlinth
389 BGROUP &17000139
390 BRET
391
392 LTORG
393
394 ; --- plot__acnGroup ---
395
396 plot__acnGroup ROUT
397
398 BCALL plot__gBorder
399
400 BLDIY1
401 BADD 4
402 BSTY0
403 BSTY1
404 BLDIX0
405 BADD 16-4
406 BSTX0
407 BSTX1
408 BDARK
409 BPLOT rule_right
410 BLIGHT
411 BPLOT rule_top
412
413 BLDIX0
414 BADD 16+4
415 BSKIPT
416 BSTX0
417 BSTX1
418 BLIGHT
419 BPLOT rule_left
420 BDARK
421 BPLOT rule_bottom
422
423 BCALL plot__findPlinth
424 BGROUP &17000119
425 BRET
426
427 LTORG
428
429 ; --- plot__gBorder ---
430
431 plot__gBorder ROUT
432
433 BDARK
434 BPLOT rule_left
435 BLIGHT
436 BPLOT rule_right
437 BPLOT rule_bottom
438
439 BCALL plot__stepOut
440 BPLOT rule_left
441 BDARK
442 BPLOT rule_right
443 BPLOT rule_bottom
444
445 BLDIX0
446 BSTX0
447 BADD 16-4
448 BSTX1
449 BLDIY1
450 BSTY1
451 BPLOT rule_pTop
452 BADD 4
453 BSTY1
454 BLDX0
455 BSUB 4
456 BSTX0
457 BLIGHT
458 BPLOT rule_pTop
459
460 BADD 16+4+4
461 BSKIPT
462 BSTX0
463 BLDIX1
464 BADD 4
465 BSTX1
466 BPLOT rule_top
467 BSUB 4
468 BSTX1
469 BLDIY1
470 BSTY1
471 BDARK
472 BPLOT rule_top
473 BRET
474
475 LTORG
476
477 ; --- plot__findPlinth ---
478
479 plot__findPlinth ROUT
480
481 BLDIX0
482 BADD 16
483 BSTX0
484 BSKIPT
485 BSTX1
486 BLDIY1
487 BSUB 20
488 BSTY0
489 BADD 48
490 BSTY1
491 BRET
492
493 LTORG
494
495 ;----- Border definition routines -------------------------------------------
496
497 ; --- plot__plinth ---
498
499 plot__plinth ROUT
500
501 BLIGHT
502 BPLOT rule_left
503 BDARK
504 BPLOT rule_right
505 BPLOT rule_bottom
506 BLIGHT
507 BPLOT rule_top
508 BRET
509
510 LTORG
511
512 ; --- plot__invPlinth ---
513
514 plot__invPlinth ROUT
515
516 BDARK
517 BPLOT rule_left
518 BLIGHT
519 BPLOT rule_right
520 BPLOT rule_bottom
521 BDARK
522 BPLOT rule_top
523 BRET
524
525 LTORG
526
527 ; --- plot__ring ---
528
529 plot__ring ROUT
530
531 BPLOT rule_left
532 BPLOT rule_right
533 BPLOT rule_pTop
534 BPLOT rule_pBottom
535 BRET
536
537 LTORG
538
539 ; --- plot__stepOut ---
540
541 plot__stepOut ROUT
542
543 BLDX0
544 BSUB 4
545 BSTX0
546 BLDY0
547 BSUB 4
548 BSTY0
549 BLDX1
550 BADD 4
551 BSTX1
552 BLDY1
553 BADD 4
554 BSTY1
555 BRET
556
557 LTORG
558
559 ; --- plot__action ---
560
561 plot__action ROUT
562
563 BJMP plot__plinth
564
565 LTORG
566
567 ; --- plot__default ---
568
569 plot__default ROUT
570
571 BCALL plot__plinth
572 BCALL plot__stepOut
573 BINDCOL sculpt_hilight
574 BCALL plot__ring
575 BCALL plot__stepOut
576 BRAW
577 BCALL plot__invPlinth
578 BRET
579
580 LTORG
581
582 ; --- plot__ridge ---
583
584 plot__ridge ROUT
585
586 BCALL plot__invPlinth
587 BCALL plot__stepOut
588 BCALL plot__plinth
589 BRET
590
591 LTORG
592
593 ; --- plot__write ---
594
595 plot__write ROUT
596
597 BCALL plot__stepOut
598 BICON
599 BPLOT rule_border
600 ; BJMP plot__offset ;Redundant
601
602 ; --- plot__offset ---
603
604 plot__offset ROUT
605
606 BLITCOL 1
607 BCALL plot__ring
608 BCALL plot__stepOut
609 BCALL plot__invPlinth
610 BRET
611
612 LTORG
613
614 ;----- That's all, folks ----------------------------------------------------
615
616 END