Wimp10 115 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > Wimp10

;;-----------------------------------------------------------------------------
;; Icon border plotting routines / Window Border plotting routines
;;-----------------------------------------------------------------------------

;;-----------------------------------------------------------------------------
;; getborder - attempt to parse the validation string for the border number
;; and the highlight value.
;;
;; in   R1 = icon flags
;;      R3 -> validation string
;; out  R0 = border number to be used (always valid!)
;;      [border_type] => type of border to plot
;;      [border_highlight] => border highlight colour
;;-----------------------------------------------------------------------------

Kevin Bracey's avatar
Kevin Bracey committed
32
getborder EntryS "R2,R4-R5"
Neil Turton's avatar
Neil Turton committed
33 34 35 36

        Debug   bo,"getborder: icon flags, vstring, caller ",R1,R3,R14

        MOV     R4,#border_normal
Kevin Bracey's avatar
Kevin Bracey committed
37
        MOV     R5,#3                   ; default values
Neil Turton's avatar
Neil Turton committed
38

39
        TST     R1,#if_text
Neil Turton's avatar
Neil Turton committed
40 41 42
        TSTNE   R1,#if_indirected
        BEQ     %FT11                   ; if not indirected + text then ignore
;
Robert Sprowson's avatar
Robert Sprowson committed
43
        AcceptLoosePointer_NegOrZero R3,-1
Ben Avison's avatar
Ben Avison committed
44 45 46 47 48
        CMP     R3,R3,ASR #31           ; is there a validation specified?
        BEQ     %10                     ; if not valid then skip
        MOV     R2,#WimpValidation_Border
        BL      findcommand
        BNE     %10                     ; if not present then skip
Neil Turton's avatar
Neil Turton committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
;
        BL      getnumber               ; get the border number
        MOV     R4,R0                   ; Defaults to zero
;
        LDRB    R14,[R3],#1             ; and then the next character
        TEQ     R14,#","
        BLEQ    getnumber               ; if its a comma, ie. following number get the highligt colour
        MOVEQ   R5,R0
10
        [ slabinout
        CMP     R4,#1
        BNE     %FT11
        TST     R1,#if_sprite
        BEQ     %FT11
        LDR     R4,two_sprite_save
;        EOR     R4,R4,R1                ; have flags been muddled with?
        TST     R4,#is_inverted
        MOVNE   R4,#2
        MOVEQ   R4,#1
        ]
11
70 71 72 73
      [ true
        CMP     R4, #border_max         ; trap undefined cases immediately
        MOVHS   R4, #0
      ]
Neil Turton's avatar
Neil Turton committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        STR     R4,border_type
        STR     R5,border_highlight     ; setup the border + its highlight colour

        Debug   bo,"type,highlight",R4,R5

        MOV     R0,R4                   ; => border being used
        EXITS


;;-----------------------------------------------------------------------------
;; Adjust a set of co-ordinates based on the border size specified in R0.
;;
;; in   R0 = border type
;;      R1 = flags for icon
;;      x0-y1 => bounding box to be adjusted
;; out  R0 corrupt
;;      x0-y0 => snapped to inside of bounding box
;;-----------------------------------------------------------------------------

93
adjustforborder Entry "R1"
Neil Turton's avatar
Neil Turton committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

        TST     R1,#if_border           ; does the icon have a border?
        EXIT    EQ                      ; return if not

        TEQ     R0,#border_editable
        TEQNE   R0,#border_normal       ; this icons need an extra pixel removing
        LDREQ   R14,dx
        ADDEQ   x0,x0,R14
        SUBEQ   x1,x1,R14
        LDREQ   R14,dy
        ADDEQ   y0,y0,R14
        SUBEQ   y1,y1,R14               ; adjust by a single pixel borderness

        ADR     R1,sizetables
        LDRB    R0,[R1,R0]              ; get adjustment factor
        BL      adjust_bbox             ; snap to grid and then adjust by value in R0

Kevin Bracey's avatar
Kevin Bracey committed
111
        EXIT                            ; haven't corrupted C or V
Neil Turton's avatar
Neil Turton committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

sizetables      =  0,4,4,8,8,4,12,8

        ASSERT  ?sizetables =border_max


;;-----------------------------------------------------------------------------
;; various slab plotting routines.
;;
;; in   R1 = flags for icon
;;      x0-y1 => bounding box of the icon
;; out  -
;;-----------------------------------------------------------------------------

plot_slabin
        ADR     R3,ct_in
        B       plot_slab               ; draw 'slabbed in' region

plot_slabout
        ADR     R3,ct_out
        B       plot_slab               ; draw 'slabbed out' region

134
plot_editable Entry
Neil Turton's avatar
Neil Turton committed
135 136 137 138 139

        BL      plot_slabin             ; first slab
        ADR     R3,ct_grey
        BL      plot_slab

140 141 142 143
      [ TrueIcon2
        BL      icon_fg
        BL      hollowrectangle
      |
Neil Turton's avatar
Neil Turton committed
144 145 146
        TST     R1,#is_shaded           ; Icon disabled?
        BNE     %FT10                   ; Yes then no black border

147
        MOV     R0,#sc_black
Neil Turton's avatar
Neil Turton committed
148 149 150
        BL      int_setcolour           ; then a rectangle that is in black
        BL      hollowrectangle
10
151
      ]
Neil Turton's avatar
Neil Turton committed
152 153 154 155 156 157 158
        LDR     R0,dx
        ADD     x0,x0,R0
        SUB     x1,x1,R0
        LDR     R0,dy
        ADD     y0,y0,R0
        SUB     y1,y1,R0                ; acount for missing single pixel border (black jobbie)

Kevin Bracey's avatar
Kevin Bracey committed
159
        EXIT
Neil Turton's avatar
Neil Turton committed
160

161
plot_ridge Entry
Neil Turton's avatar
Neil Turton committed
162 163 164 165 166 167

        ADR     R3,ct_outshallow        ; ridge is made from two slabs, slab out and then in
        BL      plot_slab
        ADR     R3,ct_inshallow
        BL      plot_slab

Kevin Bracey's avatar
Kevin Bracey committed
168
        EXIT
Neil Turton's avatar
Neil Turton committed
169

170
plot_channel Entry
Neil Turton's avatar
Neil Turton committed
171 172 173 174 175 176

        ADR     R3,ct_inshallow         ; channel made from two slabs, slab in, slab out
        BL      plot_slab
        ADR     R3,ct_outshallow
        BL      plot_slab

Kevin Bracey's avatar
Kevin Bracey committed
177
        EXIT
Neil Turton's avatar
Neil Turton committed
178

179
plot_default Entry
Neil Turton's avatar
Neil Turton committed
180 181 182 183 184 185 186

        BL      plot_slabin             ; slab in
        ADR     R3,ct_cream
        BL      plot_slab               ; cream moat

        BL      plot_action             ; followed by an action button

Kevin Bracey's avatar
Kevin Bracey committed
187
        EXIT
Neil Turton's avatar
Neil Turton committed
188

Kevin Bracey's avatar
Kevin Bracey committed
189
plot_action
Neil Turton's avatar
Neil Turton committed
190 191

        TST     R1,#is_inverted
Kevin Bracey's avatar
Kevin Bracey committed
192 193
        BEQ     plot_slabout            ; action buttons are simply slabbed out
        BNE     plot_slabin
Neil Turton's avatar
Neil Turton committed
194 195 196 197 198 199 200 201 202 203 204 205 206



;;-----------------------------------------------------------------------------
;; plot_slab - plot a slab around the specified region using a colour table
;; supplied.
;;
;; in   R3 -> colour table
;;      x0-y1 co-ordinates to put the slab at
;; out  x0-y1 updated to reflect new bounding box
;;      R0-R3 preserved
;;-----------------------------------------------------------------------------

207
plot_slab Entry "R0-R4"
Neil Turton's avatar
Neil Turton committed
208 209 210

        BL      snap_coords             ; ensure snapped to a nice boundary

Kevin Bracey's avatar
Kevin Bracey committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
      [ fixslabalignment
        SUB     x1,x1,#1
        SUB     y1,y1,#1                ; adjust x1 and y1 to be inclusive

        ASSERT  :INDEX:dy - :INDEX:dx = 4
        ADR     R14,dx
        LDMIA   R14,{R0,R4}             ; get dx and dy
        TEQ     R0,#2
        TEQEQ   R4,#4
        BEQ     plot_slab_24

        CMP     R0,R4
        MOVLT   R4,R0                   ; R4 = smaller of dx and dy

        BL      render_bbox             ; plot first rectangle (at given coordinates)

        MOV     R0,#1
        BL      adjust_bbox             ; adjust the bounding box to cover reduced area

        CMP     R4,#1
        BLEQ    render_bbox             ; then fill again (but only if EX0 or EY0)

        MOV     R0,#1
        BL      adjust_bbox             ; adjust again
        BL      render_bbox             ; then fill again

        MOVEQ   R0,#1
        BLEQ    adjust_bbox             ; fill final line if hires
        BLEQ    render_bbox

        MOVEQ   R0,#1
        MOVNE   R0,#2
        BL      adjust_bbox             ; and finally return with adjust bounding box

        ADD     x1,x1,#1                ; adjust X1,Y1 to be exclusive again
        ADD     y1,y1,#1
      |
Neil Turton's avatar
Neil Turton committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
        LDR     R0,dx                   ; adjust X1,Y1 not to be inclusive
        SUB     x1,x1,R0
        LDR     R1,dy
        SUB     y1,y1,R0

        BL      render_bbox             ; plot first rectangle (at given coordinates)
        MOV     R0,#2
        BL      adjust_bbox             ; adjust the bounding box to cover reduced area

        BL      render_bbox             ; then fill again
        MOV     R0,#2
        BL      adjust_bbox             ; and finally return with adjust bounding box

        LDR     R0,dx                   ; adjust X1,Y1 not to be inclusive
        ADD     x1,x1,R0
        LDR     R1,dy
        ADD     y1,y1,R0
Kevin Bracey's avatar
Kevin Bracey committed
265
      ]
Neil Turton's avatar
Neil Turton committed
266

Kevin Bracey's avatar
Kevin Bracey committed
267
        EXIT
Neil Turton's avatar
Neil Turton committed
268

Kevin Bracey's avatar
Kevin Bracey committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
      [ fixslabalignment

;; special case of plot_slab for good, old-fashioned rectangular pixel modes.
;; It draws the bottom left and top right corners a bit more nicely
plot_slab_24
        MOV     R0,#2
        BL      adjust_bbox             ; draw inner line first
        BL      render_bbox
        MOV     R0,#-2
        BL      adjust_bbox
        BL      render_bbox             ; then outer line
        MOV     R0,#4
        BL      adjust_bbox             ; adjust final bounding box
        ADD     x1,x1,#1
        ADD     y1,y1,#1                ; restore original x1,y1
Kevin Bracey's avatar
Kevin Bracey committed
284
        EXIT
Kevin Bracey's avatar
Kevin Bracey committed
285 286
      ]

Neil Turton's avatar
Neil Turton committed
287 288 289 290 291 292 293 294 295 296 297

;;-----------------------------------------------------------------------------
;; snap_coords - snap coordinates to suitable OS unit boundaries for this
;;
;; in   x0-y1 => co-ordinates to align to a nice boundary
;; out  x0-y1 => co-ordinates having been aligned
;;-----------------------------------------------------------------------------

snap_coords
        LDR     R0,dx_1
        BIC     x0,x0,R0                ; align X0 back to nice grid point
Kevin Bracey's avatar
Kevin Bracey committed
298
      [ :LNOT:fixslabalignment
Neil Turton's avatar
Neil Turton committed
299
        ADD     x1,x1,R0
Kevin Bracey's avatar
Kevin Bracey committed
300
      ]
Neil Turton's avatar
Neil Turton committed
301 302 303 304
        BIC     x1,x1,R0                ; align X1 out to the next grid point

        LDR     R0,dy_1
        BIC     y0,y0,R0                ; align Y0 back to nice grid point
Kevin Bracey's avatar
Kevin Bracey committed
305
      [ :LNOT:fixslabalignment
Neil Turton's avatar
Neil Turton committed
306
        ADD     y1,y1,R0
Kevin Bracey's avatar
Kevin Bracey committed
307
      ]
Neil Turton's avatar
Neil Turton committed
308 309
        BIC     y1,y1,R0                ; align Y1 out to the next grid point

Kevin Bracey's avatar
Kevin Bracey committed
310
        MOV     PC,LR
Neil Turton's avatar
Neil Turton committed
311 312 313 314 315


;;-----------------------------------------------------------------------------
;; adjust_bbox - adjust all four co-ordinates by the specified value.
;;
316
;; in   R0 = adjustment factor in OS_Units
Neil Turton's avatar
Neil Turton committed
317 318 319 320 321 322 323 324 325
;;      x0-y1 => co-ordinates to massarge
;; out  x0-y1 => co-ordinates suitable tinkered with
;;-----------------------------------------------------------------------------

adjust_bbox ROUT
        ADD     x0,x0,R0                ; adjust x0,y0
        ADD     y0,y0,R0
        SUB     x1,x1,R0                ; adjust x1,y1
        SUB     y1,y1,R0
Kevin Bracey's avatar
Kevin Bracey committed
326
        MOV     PC,LR                   ; have preserved flags
Neil Turton's avatar
Neil Turton committed
327 328 329 330 331 332 333 334 335 336 337


;;-----------------------------------------------------------------------------
;; render_bbox - draw a rectangle around the specified co-ordinates, using the
;; byte array of colours for each of the four sides.
;;
;; in   R3 -> colour table (array)
;;      R4-R7 co-ordinates x0-y1.
;; out  -
;;-----------------------------------------------------------------------------

Kevin Bracey's avatar
Kevin Bracey committed
338
render_bbox EntryS "R3"
Neil Turton's avatar
Neil Turton committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353

        MOV     R0,#4
        MOV     R1,x0
        MOV     R2,y0
        SWI     XOS_Plot                ; attempt to move to the bottom left

        MOV     R1,x1
        BL      render_line             ; plot along the bottom
        MOV     R2,y1
        BL      render_line             ; then up the right
        MOV     R1,x0
        BL      render_line             ; back across the top
        MOV     R2,y0
        BL      render_line             ; and then down back to the start

Kevin Bracey's avatar
Kevin Bracey committed
354
        EXITS                           ; must preserve flags
Neil Turton's avatar
Neil Turton committed
355 356 357 358 359 360 361 362 363

;..............................................................................

; render_line - plot line to specified user co-ordinates

; in    R1,R2 = co-ordinates
;       R3 -> byte containing colour to be used
; out   R3 -> next colour byte to be used

364
render_line Entry
Neil Turton's avatar
Neil Turton committed
365

366 367 368 369 370 371 372 373 374
      [ TrueIcon2
        LDR     R0, [R3], #4            ; get the line colour to be used
        LDR     R0, [wsptr, R0]
        Push    "R2-R4"
        LDR     R3, ditheringflag       ; set foreground
        MOV     R4, #0                  ; overwrite colour
        SWI     XColourTrans_SetGCOL
        Pull    "R2-R4"
      |
Neil Turton's avatar
Neil Turton committed
375 376
        LDRB    R0,[R3],#1              ; get the line colour to be used
        BL      int_setcolour           ; convert from the Wimp colour to suitable for screen
377
      ]
Neil Turton's avatar
Neil Turton committed
378 379 380
        MOV     R0,#&25
        SWI     XOS_Plot                ; and then plot the relevant line section

Kevin Bracey's avatar
Kevin Bracey committed
381
        EXIT
Neil Turton's avatar
Neil Turton committed
382 383 384 385 386 387


;;-----------------------------------------------------------------------------
;; Define constants relating to the borders.
;;-----------------------------------------------------------------------------

388 389 390 391 392 393 394 395 396 397 398
  [ TrueIcon2

ct_in
ct_inshallow    DCD     :INDEX: truefacecolour, :INDEX: truefacecolour, :INDEX: trueoppcolour,  :INDEX: trueoppcolour
ct_out
ct_outshallow   DCD     :INDEX: trueoppcolour,  :INDEX: trueoppcolour,  :INDEX: truefacecolour, :INDEX: truefacecolour
ct_cream
ct_grey         DCD     :INDEX: truewellcolour, :INDEX: truewellcolour, :INDEX: truewellcolour, :INDEX: truewellcolour

  |

399 400 401 402 403 404 405 406 407 408 409
    [ NCErrorBox
ct_in           = sc_darkgrey,      sc_darkgrey,      sc_verydarkgrey,  sc_verydarkgrey
ct_out          = sc_verydarkgrey,  sc_verydarkgrey,  sc_darkgrey,      sc_darkgrey
    |
ct_in           = sc_white,         sc_white,         sc_middarkgrey,   sc_middarkgrey
ct_out          = sc_middarkgrey,   sc_middarkgrey,   sc_white,         sc_white
    ]
ct_inshallow    = sc_white,         sc_white,         sc_lightgrey,     sc_lightgrey
ct_outshallow   = sc_lightgrey,     sc_lightgrey,     sc_white,         sc_white
ct_cream        = sc_cream,         sc_cream,         sc_cream,         sc_cream
ct_grey         = sc_verylightgrey, sc_verylightgrey, sc_verylightgrey, sc_verylightgrey
Neil Turton's avatar
Neil Turton committed
410 411

                ALIGN
412
  ]
Neil Turton's avatar
Neil Turton committed
413 414 415 416 417

;;-----------------------------------------------------------------------------
;; Handle replaceable window gadgets, this is simply a set of sprites which
;; can be used to replace all the window bits and bobs within the system.
;;
418 419
;; Tools are allowed to give two states; normal + pressed, though for some the
;; pressed state is omitted (eg. the scroll bar wells).
420
;;
421 422 423
;; All gadgets must be defined with the same palette and same mode, mixing is not
;; allowed.  Sprites are allowed to have mode suffix to allow different
;; EX EY factors to be supported.
424 425 426 427
;;
;; Tools sprite designers can optionally provide a set of precalculated translation
;; tables to map the toolsprites onto the standard 16 Wimp colours. Each table is
;; containerised as a sprite, but really it's just a translation table in disguise.
Neil Turton's avatar
Neil Turton committed
428 429
;;-----------------------------------------------------------------------------

430 431 432
tablebasename
        DCB     "table_1?", 0           ; Like background tiles, table_<wimpcolour>
        ALIGN
Neil Turton's avatar
Neil Turton committed
433 434 435 436

;;-----------------------------------------------------------------------------
;; Define the list of sprites and its workspace for the caching block.
;;
437 438
;; The table describes the sprite name and which information is important, such
;; as its width + depth.
Neil Turton's avatar
Neil Turton committed
439 440 441 442 443 444
;;
;;-----------------------------------------------------------------------------

spritetable

        ^ 0
445 446 447 448 449 450 451 452
        AddIcon back,,"bicon", back_width, title_height
        AddIcon close,,"cicon", close_width, title_height
        AddIcon toggle,,"ticon", vscroll_width, title_height
        AddIcon toggle1,,"ticon1", vscroll_width, title_height
        AddIcon size,,"sicon", vscroll_width, hscroll_height
      [ IconiseButton
        AddIcon iconise,,"iicon", iconise_width, title_height
      ]
453

454 455 456 457
        AddIcon up,,"uicon", vscroll_width, up_height
        AddIcon down,,"dicon", vscroll_width, down_height
        AddIcon right,,"ricon", right_width, hscroll_height
        AddIcon left,,"licon", left_width, hscroll_height
Neil Turton's avatar
Neil Turton committed
458

459 460 461 462
        AddIcon tbarlcap,,,title_left,title_height
        AddIcon tbarmidt,,,title_sectionwidth,title_topheight
        AddIcon tbarmidb,,,title_sectionwidth,title_bottomheight
        AddIcon tbarrcap,,,title_right,title_height
Neil Turton's avatar
Neil Turton committed
463

464 465
        AddIcon vwelltcap,no,,vscroll_width,vscroll_top
        AddIcon vwellt,no,,vscroll_width,vscroll_topfill
Neil Turton's avatar
Neil Turton committed
466

467 468 469
        AddIcon vbart,,,vscroll_width,vscroll_blobtop
        AddIcon vbarmid,,,vscroll_width,vscroll_blobfill
        AddIcon vbarb,,,vscroll_width,vscroll_blobbottom
Neil Turton's avatar
Neil Turton committed
470

471 472
        AddIcon vwellb,no,,vscroll_width,vscroll_bottomfill
        AddIcon vwellbcap,no,,vscroll_width,vscroll_bottom
Neil Turton's avatar
Neil Turton committed
473

474 475
        AddIcon hwelllcap,no,,hscroll_left,hscroll_height
        AddIcon hwelll,no,,hscroll_leftfill,hscroll_height
Neil Turton's avatar
Neil Turton committed
476

477 478 479
        AddIcon hbarl,,,hscroll_blobleft,hscroll_height
        AddIcon hbarmid,,,hscroll_blob,hscroll_height
        AddIcon hbarr,,,hscroll_blobright,hscroll_height
Neil Turton's avatar
Neil Turton committed
480

481 482
        AddIcon hwellr,no,,hscroll_rightfill,hscroll_height
        AddIcon hwellrcap,no,,hscroll_right,hscroll_height
Neil Turton's avatar
Neil Turton committed
483

Kevin Bracey's avatar
Kevin Bracey committed
484
      [ hvblip
485 486
        AddIcon hblip,,,hscroll_blipwidth,hscroll_height
        AddIcon vblip,,,vscroll_width,vscroll_blipheight
Neil Turton's avatar
Neil Turton committed
487 488 489 490
      ]

; this must always be the *LAST* sprite in the list!

491
        AddIcon blank,no,"blicon",vscroll_width,hscroll_height
Neil Turton's avatar
Neil Turton committed
492 493 494 495 496 497 498 499 500 501 502

        ALIGN

toolcachesize   * :INDEX: @


;;-----------------------------------------------------------------------------
;; Attempt to build a list of the active icons within the system, this is used
;; for scanning through and replacing the various gadgets.  We attempt to
;; setup the caching list.
;;
Kevin Bracey's avatar
Kevin Bracey committed
503 504
;; NB: The tool sprites temporarily become part of the list of active
;;     sprites - avoid *IconSpriting any borders files.
Neil Turton's avatar
Neil Turton committed
505 506 507 508 509 510 511 512 513 514
;;
;; in   [tool_list] -> current tool list / =0 for none
;;      [tool_area] -> tool sprite area / =0 for none (don't build list)
;;      [dx/dy] => pixel sizes
;;      [xborder/yborder] = default border sizes to be used
;; out  [tool_list] -> new tool list
;;      [tool_plotparams] => suitable plotting parameters for sprites
;;      ... lots of others redefined to make plotting work
;;-----------------------------------------------------------------------------

Kevin Bracey's avatar
Kevin Bracey committed
515
maketoollist EntryS "R1-R11"
Neil Turton's avatar
Neil Turton committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538

        Debug   tools,"Make tool list called =>",#tool_area,#tool_list,R14

        [ debugnk
        MOV R0,SP
        Debug   nk,"Make tool list called =>",#tool_area,#tool_list,R14,R0
        ]
;
        LDRB    R0,yborder
        LDRB    R1,xborder
        BL      default_params          ; default the parameters to border sizes

; if no list defined then drop back to a set of defaults for the current set
; of VDU style glyphs.


        LDR     R2,tool_area            ; still none?

        Debug   nk,"Tool area",R2

        TEQ     R2,#0
        BEQ     %FT45                   ; No then jump

539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
      [ ToolTables

; look for any custom translation tables

        SUB     R13,R13,#12             ; space for "table_99"+0
        MOV     R4,#0                   ; bitmap of found wimp colours
        MOV     R5,#15                  ; wimp colour loop counter
        ADRL    R6,ttt_masterset
02
        ADR     R0,tablebasename
        MOV     R1,R13
        BL      copy0
        CMP     R5,#10                  ; numbery bit
        ADDCS   R0,R5,#'0' - 10
        STRCSB  R0,[R1,#-1]!
        ADDCC   R0,R5,#'0'
        STRCCB  R0,[R1,#-2]!
        MOV     R0,#0
        STRB    R0,[R1,#1]              ; terminate

        LDR     R0,=&100+SpriteReason_SelectSprite
        ADRL    R1,tool_areaCB
        MOV     R2,R13
        SWI     XOS_SpriteOp
        MOVVC   R0,#1                   ; hit
        ORRVC   R4,R4,R0,LSL R5
        LDRVC   R1,[R2,#spImage]
        ADDVC   R2,R2,R1
        MOVVS   R2,#0                   ; miss
        STR     R2,[R6,R5,LSL #2]       ; start of containerised 256x4 translation table

        SUBS    R5,R5,#1
        BPL     %BT02

; consider the results

        ADD     R13,R13,#12
        MOVS    R0,R4,LSL #16
        BEQ     %FT05                   ; we aint got naffin

        TST     R4,#1:SHL:2
        BLEQ    freetoolarea
        BEQ     %FT45                   ; need 'table_2' for tinting, can't use these tools
05
      ]
Neil Turton's avatar
Neil Turton committed
584 585 586 587 588 589 590
;..............................................................................
;
; attempt to work out the sizes of the various sprites and their modifications to
; the existing borders.

; work out which suffix to apply to sprite names

591 592 593 594 595 596 597 598 599 600 601 602
        MOV     R6,#1
        MOV     R10,#'0'

        MOV     R0,#-1
        MOV     R1,#VduExt_XEigFactor
        SWI     XOS_ReadModeVariable
        ADD     R5,R10,R6,LSL R2

        MOV     R1,#VduExt_YEigFactor
        SWI     XOS_ReadModeVariable
        ADD     R6,R10,R6,LSL R2

603 604 605 606 607 608
      [ :LNOT: Sprites11
        TEQ     R5,#'1'
        TEQNE   R6,#'1'
        MOVEQ   R5,#'2'
        MOVEQ   R6,#'2'                 ; '1y' or 'x1' -> '22'
      ]
609 610 611 612 613 614 615 616 617 618 619 620 621
        TEQ     R6,#'2'
        TEQNE   R6,#'4'
        TEQEQ   R5,#'2'
        BNE     %FT05                   ; if not '22' or '24' then no mono alternative suffix

        MOV     R1,#VduExt_Log2BPP
        SWI     XOS_ReadModeVariable
        TEQ     R2,#0
        BNE     %FT05                   ; not mono
        TEQ     R6,#'4'
        MOVEQ   R5,#'0'
        MOVEQ   R6,#0                   ; '24' -> '0'
        MOVNE   R6,#'3'                 ; '22' -> '23'
Neil Turton's avatar
Neil Turton committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
05
        ORR     R10,R5,R6,LSL #8        ; combine to make a postfix
;
; now attempt to sort out the sprites to be used
;
        MOV     R0,#-1
        STRB    R0,addtoolstolist       ; flag as adding tools into the list
        BL      freelist
;
        MOV     R0,#area_Wimp
        STR     R0,thisCBptr            ; reference to the Wimps sprite block
;
        LDR     R2,tool_list
        LDR     R3,=toolcachesize       ; -> list / size
;
Kevin Bracey's avatar
Kevin Bracey committed
637
        TEQ     R2,#0                   ; has the list buffer been setup yet?
Neil Turton's avatar
Neil Turton committed
638
        BNE     %FT07
639
        ADRL    R14,tool_list_backup
Neil Turton's avatar
Neil Turton committed
640 641 642 643 644 645 646 647 648 649 650
        LDR     R2,[R14]                ; this is a constant size so try and reuse
        CMP     R2,#0
        STRNE   R2,tool_list

        Debug   nk,"Tool list Backup",R2

        BNE     %FT07

        MOV     R0,#ModHandReason_Claim
        BL      XROS_Module
        STRVC   R2,tool_list
651
        ADRVCL  R14,tool_list_backup
Neil Turton's avatar
Neil Turton committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
        STRVC   R2,[R14]

        EXITS   VS                      ; return if it fails to claim
;
07
        MOV     R0,#0
        MOV     R1,#0                   ; Set tool sizes to 0 == undefined
        STRB    R1,spritecachevalid
        BL      default_params

        ADD     R3,R3,R2                ; -> end of list
        ADRL    R8,spritetable          ; -> list of sprite names
        MOV     R9,R2                   ; -> list to fill in
10
        SUBS    R14,R3,R9
        BEQ     %FT40                   ; finished the list so tidy up and exit
;
        Debuga  tools,"Block pointer =",R9
        DebugS  tools,", name ",R8
;
        SUB     SP,SP,#16               ; allocate some space for the name
        MOV     R4,SP
;
        STR     R4,spritename           ; -> buffer to be used
        STR     R4,lengthflags
15
        LDRB    R14,[R8],#1
        TEQ     R14,#0
        STRNEB  R14,[R4],#1
        BNE     %BT15                   ; copy sprite name to a RAM buffer
;
        ADD     R8,R8,#3
        BIC     R8,R8,#3                ; align name pointer to word boundary
;
        STRB    R10,[R4]
        MOVS    R14,R10,LSR #8
        STRB    R14,[R4,#1]
        MOVNE   R14,#0
        STRNEB  R14,[R4,#2]             ; attach a suitable postfix
691

Neil Turton's avatar
Neil Turton committed
692
        ; this uses different approach to cut down on 'sprite not found'
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715

        LDRB    R14,spritecachevalid
        TEQ     R14,#0
        BNE     %FT04
        BL      cachespriteaddress      ; try with postfix
        BVC     %FT07                   ; list exists and postfixed sprite found

        LDR     R14,list_at
        CMP     R14,R14,ASR #31
        BEQ     %FT03
        BL      cachetoolspriteaddress  ; list exists, try other or no postfixes
        B       %FT07

03      MOV     R14,#1
        STRB    R14,spritecachevalid    ; remember there's no list for next toolsprite
04      LDR     R14,thisCBptr
        Push    "R14"
        ADRL    R14,tool_areaCB
        STR     R14,thisCBptr
        BL      cachespriteaddress
        BLVS    cachetoolspriteaddress
        Pull    "R14"
        STR     R14,thisCBptr
Neil Turton's avatar
Neil Turton committed
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
07
        ADD     SP,SP,#16
        ADDVS   R8,R8,#4*2
        BVS     %FT30                   ; if not found then skip
;
        Debug   tools,"Found at",R2
;
        Push    "R2-R3"
;
        MOV     R0,#SpriteReason_ReadSpriteSize +&200
        LDR     R1,tool_area
        SWI     XOS_SpriteOp            ; assume it works as sprite already found
;
        SUBS    R3,R3,#1
        MOVMI   R3,#0
        SUBS    R4,R4,#1
        MOVMI   R4,#0                   ; always returns an extra pixel - unhelpful!
733 734 735
;
      [ TrueIcon3
        ; If these are the ROM toolsprites, assume all tools are unmasked
Ben Avison's avatar
Ben Avison committed
736 737 738 739 740
        LDR     R0,ROMstart
        LDR     R14,ROMend
        CMP     R1,R0
        CMPHS   R14,R1
        BHS     %FT66
741
      ]
Kevin Bracey's avatar
Kevin Bracey committed
742
;
Robert Sprowson's avatar
Robert Sprowson committed
743 744 745 746
        TEQ     R5,#1
        LDREQ   R5,[sp]
        ORREQ   R5,R5,#1
        STREQ   R5,[sp]                 ; store mask status
747
66
Neil Turton's avatar
Neil Turton committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
        MOV     R0,R6
        MOV     R1,#VduExt_XEigFactor
        SWI     XOS_ReadModeVariable
        MOVCC   R5,R3,LSL R2            ; get OS unit width
        MOVCC   R1,#VduExt_YEigFactor
        SWICC   XOS_ReadModeVariable
        MOVCC   R4,R4,LSL R2            ; get OS unit height
        MOVCS   R0,#0
        STRCS   R0,[SP]                 ; if mode invalid then sprite not found
        ADDCS   R8,R8,#4*2
        BCS     %FT20
;
        LDMIA   R8!,{R0,R1}             ; offsets to modifing the width / height suitably
        Debug   tools,"Offsets to modify (width,height) =>",R0,R1,R5,R4
;
        CMP     R0,#0
        LDRGT   R2,[wsptr,R0]           ; update the width if its bigger
        CMPGT   R5,R2
        STRGT   R5,[wsptr,R0]
;
        CMP     R1,#0
        LDRGT   R2,[wsptr,R1]           ; update the height if its bigger
        CMPGT   R4,R2
        STRGT   R4,[wsptr,R1]
20
        Pull    "R2-R3"
30      STR     R2,[R9],#4
        B       %BT10                   ; loop back until entire list as been scanned

; Set default sizes for undefined tools

40
780
      [ UTF8
781
        BL      read_current_alphabet
782 783
        BEQ     %FT88
      ]
Neil Turton's avatar
Neil Turton committed
784 785 786 787 788
        LDR     LR,back_width
        TEQ     LR,#0                   ; Back tool defined?
        ADREQL  R0,initvdustring2
        MOVEQ   R1,#endvdustring2-initvdustring2
        SWIEQ   XOS_WriteN              ; No then re-define glyphs
789
88
Neil Turton's avatar
Neil Turton committed
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
        LDRB    R1,yborder
        LDR     LR,title_height
        TEQ     LR,#0
        STREQ   R1,title_height
        LDR     LR,up_height
        TEQ     LR,#0
        STREQ   R1,up_height
        LDR     LR,down_height
        TEQ     LR,#0
        STREQ   R1,down_height
        LDR     LR,hscroll_height
        TEQ     LR,#0
        STREQ   R1,hscroll_height
;
        LDRB    R1,xborder
        LDR     LR,vscroll_width
        TEQ     LR,#0
        STREQ   R1,vscroll_width
        LDR     LR,back_width
        TEQ     LR,#0
        STREQ   R1,back_width
        LDR     LR,close_width
        TEQ     LR,#0
        STREQ   R1,close_width
Kevin Bracey's avatar
Kevin Bracey committed
814
      [ IconiseButton
Robert Sprowson's avatar
Robert Sprowson committed
815 816 817
        LDR     LR,iconise_width
        TEQ     LR,#0
        STREQ   R1,iconise_width
Kevin Bracey's avatar
Kevin Bracey committed
818
      ]
Neil Turton's avatar
Neil Turton committed
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
        LDR     LR,left_width
        TEQ     LR,#0
        STREQ   R1,left_width
        LDR     LR,right_width
        TEQ     LR,#0
        STREQ   R1,right_width

        MOV     R0,#0
        STRB    R0,addtoolstolist       ; remake list without tools present
        BL      freelist
;
; calculate a suitable pixel translation table for for the sprites,
; assume that R2 -> suitable sprite which describes the characteristics
; of all the other sprites being plotted.
;
Robert Sprowson's avatar
Robert Sprowson committed
834
        BIC     R2,R2,#1                ; strip our mask bit
Neil Turton's avatar
Neil Turton committed
835 836 837
        STR     R2,spritename
        MOV     R2,#0
        STR     R2,lengthflags          ; [spritename] is absolute
838 839 840 841
      [ TrueIcon3
        STRB    R2,tinted_tool          ; tinting off, incase the last window drawn was
                                        ; tinted before dropping to the CLI for *TOOLSPRITES
      ]
Neil Turton's avatar
Neil Turton committed
842 843
;
        BL      freetooltrans           ; release tool translation table
844
        BL      cachetoolspritedata     ; attempt to build a suitable pixtrans table
Neil Turton's avatar
Neil Turton committed
845 846 847 848 849 850 851
;
        BVC     %FT42
        ; a failure here usually means that we can't even allocate a pix table
        ; due to lack of memory. We have to free the lot!
        BL      freetoolarea
        EXITS
42
852 853 854 855 856
      [ Medusa
        MOV     R1, #8+32               ; Plot masked with wide tables by default
      |
        MOV     R1, #8                  ; Plot masked by default
      ]
Neil Turton's avatar
Neil Turton committed
857
      [ fastborders
858 859
        LDRB    R0,tsprite_needsfactors ; do we need to do translation
        TEQ     R0,#0
Neil Turton's avatar
Neil Turton committed
860 861 862
        LDREQ   R0,=&200+SpriteReason_PutSpriteUserCoords
        LDRNE   R0,=&200+SpriteReason_PutSpriteScaled
        ADRNEL  R2,tool_scalingblk
863
        LDRNE   R3,tpixtable_at
Neil Turton's avatar
Neil Turton committed
864 865 866
        MOVEQ   R3,#0
      |
        LDR     R0,=&200+SpriteReason_PutSpriteScaled
867
      [ TrueIcon3
868
        LDR     R14, tool_area
Ben Avison's avatar
Ben Avison committed
869 870
        LDR     R2, ROMstart
        LDR     R3, ROMend
871 872 873 874
        CMP     R14, R2
        CMPHS   R3, R14
      [ Medusa
        MOVHS   R1, #0+32               ; pretend ROM toolsprites are unmasked
875
      |
876 877
        MOVHS   R1, #0
      ]
878
      ]
Neil Turton's avatar
Neil Turton committed
879
        ADRL    R2,tool_scalingblk
880
        LDR     R3,tpixtable_at
Neil Turton's avatar
Neil Turton committed
881 882 883
      ]
;
        ASSERT  tool_maskop = tool_plotop+4
884 885
        ASSERT  tool_scaling = tool_maskop+4
        ASSERT  tool_transtable = tool_scaling+4
Neil Turton's avatar
Neil Turton committed
886 887 888
        ASSERT  ?tool_scalingblk = 4*4
;
        ADRL    R14,tool_plotparams
Neil Turton's avatar
Neil Turton committed
889
        STMIA   R14,{R0-R3}             ; setup a parameter block
Neil Turton's avatar
Neil Turton committed
890
;
891 892 893
      [ :LNOT: fastborders
        TEQ     R3,#0                   ; not needed with fastborders set
      ]
Neil Turton's avatar
Neil Turton committed
894
      [ ChildWindows
895
        ADR     R14,tsprite_factors
Neil Turton's avatar
Neil Turton committed
896 897 898 899
        LDMIA   R14,{R3,R4,R5,R6}
        ADRL    R14,tool_scalingblk
        STMIA   R14,{R3,R4,R5,R6}        ; take a copy of the scaling block (even if the tools don't always need it)
      |
Neil Turton's avatar
Neil Turton committed
900
      [ fastborders
901
        ADRNE   R14,tsprite_factors
Neil Turton's avatar
Neil Turton committed
902 903 904
        LDMNEIA R14,{R3,R4,R5,R6}
        STMNEIA R2,{R3,R4,R5,R6}        ; take a copy of the scaling block
      |
905
        ADR     R14,tsprite_factors
Neil Turton's avatar
Neil Turton committed
906 907 908
        LDMIA   R14,{R3,R4,R5,R6}
        STMIA   R2,{R3,R4,R5,R6}        ; take a copy of the scaling block
      ]
Neil Turton's avatar
Neil Turton committed
909
      ]
Neil Turton's avatar
Neil Turton committed
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960

;
; calculate values + an OS unit for correct tessalation.
;
45      LDR     R0,title_height
        LDR     R1,dy
        ADD     R0,R0,R1
        STR     R0,title_height1        ; title_height1 = dy + title_height
;
        LDR     R0,hscroll_height
        ADD     R0,R0,R1
        STR     R0,hscroll_height1      ; hscroll_height1 = dx + hscroll_height
;
        LDR     R1,dx
        LDR     R0,vscroll_width
        ADD     R0,R0,R1
        STR     R0,vscroll_width1       ; vscroll_width1 = dx + vscroll_width
;
; now work out the information needed for the scroll bars.
;
        LDR     R0,left_width
        LDR     R1,xypixelsize
        ADD     R14,R0,R1,LSL #1
        STRB    R14,scroll_mxborder     ; gap at start of a horizontal scroll bar
;
        LDR     R0,up_height
        ADD     R14,R0,R1,LSL #1
        STRB    R14,scroll_myborder     ; gap at start of vertical scroll bar
;
        MOV     R14,R1,LSL #1
        STRB    R14,scroll_endmargin    ; border at end of scroll bars
;
 [ True
;        ADD     R14,R1,R1,LSL #4
        ADD     R14,R1,#32              ; 32 os units for scrollbar
 |
        ADD     R14,R1,R1,LSL #1
 ]
        STRB    R14,scroll_minlength    ; when min length gets imposed
;
        LDRB    R1,scroll_endmargin
        ADD     R14,R14,R1,LSL #1
        STRB    R14,scroll_minxbar
        STRB    R14,scroll_minybar      ; min length of scroll bars
;
        MOV     R14,#8                  ; this one is constant = defines distance of non-changing borders
        STRB    R14,scroll_sidemargin
;
        EXITS
        LTORG

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
;..............................................................................
; cachetoolspriteaddress
;
; [spritename], [thisCBptr], [lengthflags] as for cachespriteaddress
; in:  R4 -> resolution suffix
;      R10 = first suffix tried (and failed)
; out: R2 -> sprite

cachetoolspriteaddress
        Push    "R14"
        MOV     R14,#&FF
        AND     R5,R14,R10
        AND     R6,R14,R10,LSR #8
        SUBS    R5,R5,#'0'
        SUB     R6,R6,#'0'
        MOVEQ   R5,#2
        MOVEQ   R6,#8                   ; pretend '0' was '28' so we try '24' next
        TEQ     R6,#3
        MOVEQ   R6,#4                   ; pretend '23' was '24' so we try '22' next

05      CMP     R5,R6
        MOVLO   R5,R5,LSL#1
        MOVHI   R6,R6,LSL#1
        BNE     %FT06                   ; after rectangular pixels, try next squarer version

        TEQ     R5,#1
        MOVEQ   R5,#2
        MOVEQ   R6,#2                   ; after '11', try '22'
        MOVNE   R5,#-'0'                ; after any other square pixels, try without suffix

06      ADD     R14,R5,#'0'
        STRB    R14,[R4]
        ADD     R14,R6,#'0'
        STRB    R14,[R4,#1]
        BL      cachespriteaddress
        Pull    "PC", VC                ; success
        TEQ     R5,#0
        BPL     %BT05                   ; try next suffix
        Pull    "PC"                    ; total failure, exit with V set

Neil Turton's avatar
Neil Turton committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
;..............................................................................

; defaultparams - modify the default parameters ready for further calculations

; in    R0 = vertical size to be stored
;       R1 = horizontal size to be stored
; out   -

default_params
        STR     R0,title_height         ; height based parameters
        STR     R0,up_height
        STR     R0,down_height
        STR     R0,hscroll_height
;
        STR     R1,vscroll_width        ; width based paramaters
        STR     R1,back_width
        STR     R1,close_width
Kevin Bracey's avatar
Kevin Bracey committed
1018
      [ IconiseButton
Robert Sprowson's avatar
Robert Sprowson committed
1019
        STR     R1,iconise_width
Kevin Bracey's avatar
Kevin Bracey committed
1020
      ]
Neil Turton's avatar
Neil Turton committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
        STR     R1,left_width
        STR     R1,right_width
;
        MOV     R0,#0
        STR     R0,title_sectionwidth   ; reset constants for the title bar
        STR     R0,title_left
        STR     R0,title_right
        STR     R0,title_topheight
        STR     R0,title_bottomheight
;
        STR     R0,vscroll_top          ; and vscroll
        STR     R0,vscroll_topfill
        STR     R0,vscroll_blobtop
        STR     R0,vscroll_blobfill
        STR     R0,vscroll_blobbottom
        STR     R0,vscroll_bottomfill
        STR     R0,vscroll_bottom
;
        STR     R0,hscroll_left         ; finally the hscroll
        STR     R0,hscroll_leftfill
        STR     R0,hscroll_blobleft
        STR     R0,hscroll_blob
        STR     R0,hscroll_blobright
        STR     R0,hscroll_rightfill
        STR     R0,hscroll_right
;
Kevin Bracey's avatar
Kevin Bracey committed
1047
      [ hvblip
Neil Turton's avatar
Neil Turton committed
1048 1049 1050 1051
        STR     R0,hscroll_blipwidth
        STR     R0,vscroll_blipheight
      ]

Kevin Bracey's avatar
Kevin Bracey committed
1052
        MOV     PC,LR
Neil Turton's avatar
Neil Turton committed
1053

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
  [ ToolTables
;;-----------------------------------------------------------------------------
;; make an active set of translation tables from the master set for this mode
;;
;; in    [ttt_masterset] have master tables, at least 'table_2' must exist
;; out   [ttt_activeset] updated
;;       V set R0 -> error, else corrupt
;;------------------------------------------------------------------------------

mastertoactive ROUT
        Push    "R1-R8,LR"
        ADRL    R6,ttt_masterset
        MOV     R1,#0
        MOV     R0,#15
05
        LDR     R14,[R6,R0,LSL #2]
        TEQ     R14,#0
        ADDNE   R1,R1,#1
        SUBS    R0,R0,#1
        BPL     %BT05

        LDR     R5,log2bpp              ; bpp 0,1,2,3,4,5
        CMP     R5,#4
        MOVCC   R7,#256
        MOVEQ   R7,#512
        MOVHI   R7,#1024                ; => bytes per table entry
        MUL     R3,R1,R7                ; => bytes for all the tables present

        LDR     R2,ttt_activeset_at
        TEQ     R2,#0
        BEQ     %FT15                   ; none claimed yet

        CMP     R5,#5
        LDRNE   R14,ttt_activeset_size
        MOVEQ   R14,#0                  ; 32bpp, no copies needed, force a free
        CMP     R14,R3
        BCS     %FT20                   ; big enough
10
        MOV     R14,#0
        STR     R14,ttt_activeset_at
        MOV     R0,#ModHandReason_Free
        BL      XROS_Module             ; too small, free old one
15
        CMP     R5,#5
        BEQ     %FT20                   ; 32bpp, no copies needed, skip the claim
        MOV     R0,#ModHandReason_Claim
        STR     R3,ttt_activeset_size
        BL      XROS_Module
        Pull    "R1-R8,PC",VS
        STR     R2,ttt_activeset_at
20
        ADRL    R4,ttt_activeset
        MOV     R3,#15                  ; for each master table present, generate user table
25
        ; R1=colour number to convert (0-255)
        ; R2->base of storage for user tables
        ; R3=wimp colour (0-15)
        ; R4->table of user pointers
        ; R5=log2bpp
        ; R6->table of master pointers
        ; R7=size of 1 user table in bytes
        ; R8->base of master table for this wimp colour
        LDR     R8,[R6,R3,LSL #2]
        CMP     R8,#0                   ; master table absent?
        CMPNE   R5,#5                   ; or 32bpp mode?
        STREQ   R8,[R4,R3,LSL #2]
        BEQ     %FT35

        MOV     R1, #255
30
        LDR     R0,[R8,R1,LSL #2]
        MOV     R0,R0,ROR #24           ; xBGR->BGRx
        SWI     XColourTrans_ReturnColourNumber
        CMP     R5,#4                   ; 16bpp is 2B/entry, others are 1
        STRCCB  R0,[R2,R1]
        ADDEQ   R14,R2,R1,LSL #1
        STREQB  R0,[R14,#0]
        MOVEQ   R0,R0,LSR #8
        STREQB  R0,[R14,#1]
        SUBS    R1,R1,#1
        BPL     %BT30

        STR     R2,[R4,R3,LSL #2]       ; point at the table just made
        ADD     R2,R2,R7                ; move storage along
35
        SUBS    R3,R3,#1                ; next wimp colour
        BPL     %BT25

        CLRV
        Pull    "R1-R8,PC"

;;-----------------------------------------------------------------------------
;; colour match the tool to a standard colour
;;
;; in    R1 = &BBGGRR00 true colour (or 4 bit wimp colour when not TrueIcon3)
;; out   R7 -> translation table to use
;;------------------------------------------------------------------------------

colourmatchtool
        Push    "R2-R3,LR"
        ADRL    R3,ttt_activeset
        LDR     R7,[R3,#ttt_table2]     ; Presence of 'table_2' implies custom translations
        TEQ     R7,#0
        LDREQ   R7,tool_transtable      ; Use generic translation table
        Pull    "R2-R3,PC",EQ

        STR     R1,ttt_lastlookup       ; remember last request incase ColourTrans invalidates everything
    [ TrueIcon3
        BL      getpalpointer           ; R14 -> active 16 entry palette
        MOV     R2,#15
10
        LDR     R7,[R14,R2,LSL #2]
        TEQ     R1,R7
        BNE     %FT15
        LDR     R7,[R3,R2,LSL #2]
        TEQ     R7,#0
        Pull    "R2-R3,PC",NE           ; Is a standard colour & have a custom translation
15
        SUBS    R2,R2,#1
        BPL     %BT10

        LDRB    R2,tinted_tool          ; Non standard, or no table, maybe tint it?
        TEQ     R2,#0
        LDREQ   R7,[R3,#ttt_table2]     ; Not a tinting candidate, use 'table_2'
        Pull    "R2-R3,PC",EQ

        Push    "R0-R1"                 ; Make a temporary tinting table

      [ Medusa
        LDR     R1,log2bpp              ; bpp 0,1,2,3,4,5
        CMP     R1,#4
        MOVCC   R1,#256
        MOVEQ   R1,#512
        MOVHI   R1,#1024                ; => bytes per table entry
      |
        MOV     R1,#256
      ]
        LDR     R2,tpixtable_at
        LDR     R3,tpixtable_size
        TEQ     R2,#0
        BEQ     %FT20
        CMP     R3,R1                   ; Is what's there already big enough?
        BCS     %FT25
        MOV     R0,#0
        STR     R0,tpixtable_at
        MOV     R0,#ModHandReason_Free
        BL      XROS_Module
20
        MOV     R3,R1
        MOV     R0,#ModHandReason_Claim
        BL      XROS_Module
        MOVVS   R7,#0                   ; Out of memory, and no tpixtable! Use nothing
        Pull    "R0-R3,PC",VS
25
        STR     R2,tpixtable_at
        STR     R2,tool_transtable
        STR     R3,tpixtable_size

        ADRL    R3,ttt_masterset
        LDR     R7,[R3,#ttt_table2]     ; Use master 'table_2' as basis

        MOV     R1,#255
        LDR     R3,log2bpp
        ; R1=colour number to convert (0-255)
        ; R2->base of tinted translation table
        ; R3=log2bpp
        ; R7->base of master table 2
30
        LDR     R0,[R7,R1,LSL #2]       ; solid (0) -> transparent (255)
        MOV     R0,R0,ROR #24           ; &AABBGGRR -> &BBGGRRAA
        BL      bgr0_to_y
        ORR     R0,R0,R0,LSL #8         ; &0000YYYY
        ORR     R0,R0,R0,LSL #16        ; &YYYYYYYY
        BL      tintfunc
        SWI     XColourTrans_ReturnColourNumber
      [ Medusa
        CMP     R3,#4                   ; 32bpp is 4B/entry, 16bpp is 2B/entry, others are 1
        STRCCB  R0,[R2,R1]
        ADDEQ   R14,R2,R1,LSL #1
        STREQB  R0,[R14,#0]
        MOVEQ   R0,R0,LSR #8
        STREQB  R0,[R14,#1]
        STRHI   R0,[R2,R1,LSL #2]
      |
        STRB    R0,[R1,R1]              ; No wide translation tables
      ]
        SUBS    R1,R1,#1
        BPL     %BT30

        MOV     R7,R2                   ; Use table just made
        Pull    "R0-R3,PC"
    |
        LDR     R7,[R3,R1,LSL #2]       ; Direct lookup wimp colour
        TEQ     R7,#0
        LDREQ   R7,[R3,#ttt_table2]     ; No specific table, use 'table_2'
        Pull    "R2-R3,PC"
    ]
  ]
Neil Turton's avatar
Neil Turton committed
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272

;;-----------------------------------------------------------------------------
;; free the tool sprites list (if defined)
;;
;; in    [tool_list] -> list / =0 for undefined
;; out   [tool_list] = 0
;;------------------------------------------------------------------------------

freetoollist ROUT
        Push    "R0,R2,LR"

        [ false
; don't free the area as its size is constant, just mark as invalid.
        MOV     R0,#ModHandReason_Free
        LDR     R2,tool_list            ; -> tool list
        TEQ     R2,#0
        BLNE   XROS_Module              ; release it (ignorning errors)
        ]
;
        MOV     R2,#0
        STR     R2,tool_list            ; free the tool list
Kevin Bracey's avatar
Kevin Bracey committed
1273 1274
        CLRV
        Pull    "R0,R2,PC"
Neil Turton's avatar
Neil Turton committed
1275 1276 1277 1278 1279


;;-----------------------------------------------------------------------------
;; Free the translation table associated with the tool plotting routines.
;;
1280 1281
;; in   [tpixtable_at] -> table / =0 for none
;; out  [tpixtable_at] = 0 (block released)
Neil Turton's avatar
Neil Turton committed
1282 1283 1284 1285 1286 1287
;;-----------------------------------------------------------------------------

freetooltrans ROUT

        MOV     R1,R14
;
1288
        LDR     R2,tpixtable_at
Neil Turton's avatar
Neil Turton committed
1289 1290 1291 1292 1293
        CMP     R2,#0                   ; has a table been defined yet?
        MOVNE   R0,#ModHandReason_Free
        BLNE   XROS_Module              ; if so then release - ignore errors
;
        MOV     R0,#0
1294
        STR     R0,tpixtable_at
Neil Turton's avatar
Neil Turton committed
1295
        STR     R0,tool_transtable
1296 1297 1298 1299 1300 1301 1302
      [ ToolTables
        LDR     R2,ttt_activeset_at
        STR     R0,ttt_activeset_at
        CMP     R2,#0                   ; have translation tables been supplied in the tool sprites?
        MOVNE   R0,#ModHandReason_Free
        BLNE   XROS_Module
      ]
Neil Turton's avatar
Neil Turton committed
1303
;
Kevin Bracey's avatar
Kevin Bracey committed
1304 1305
        CLRV
        MOV     PC,R1
Neil Turton's avatar
Neil Turton committed
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319


;;-----------------------------------------------------------------------------
;; Free tools area, this attempts to free the tools area owned, even if none
;; is owned the areaCB is reset back to the default 16 byte block.
;;
;; in   [tool_area] -> tool area / =0 undefined
;;      [tool_list] -> tool list / =0 undefined
;; out  R0 corrupt!
;;      [tool_list] = 0
;;      [tool_area] = 0
;;      [tool_areaCB] = default for no sprite pool
;;-----------------------------------------------------------------------------

Kevin Bracey's avatar
Kevin Bracey committed
1320
freetoolarea EntryS "R1-R4"
Neil Turton's avatar
Neil Turton committed
1321 1322 1323 1324 1325 1326 1327

        Debug   tools,"Free tool areas =",#tool_list,#tool_area
;
        MOV     R0,#ModHandReason_Free
;
        LDR     R2,tool_area
        CMP     R2,#0                   ; is there a tools area already?
1328
        BEQ     %FT01
Neil Turton's avatar
Neil Turton committed
1329

Ben Avison's avatar
Ben Avison committed
1330 1331 1332 1333
        LDR     R14,ROMstart            ; it may have started life in ROM
        LDR     R4,ROMend
        CMP     R2,R14
        CMPHS   R4,R2
Neil Turton's avatar
Neil Turton committed
1334

Ben Avison's avatar
Ben Avison committed
1335
        BLLO    XROS_Module             ; attempt to free the buffer (ignore errors)
Neil Turton's avatar
Neil Turton committed
1336
;
Ben Avison's avatar
Ben Avison committed
1337
01      MOV     R0,#0
Neil Turton's avatar
Neil Turton committed
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
        STR     R0,tool_area            ; flag as being released
;
        BL      freetoollist            ; release the tool list (used for finding the sprites)
        BL      freetooltrans           ; release translation tables
;
        ADRL    R0,romsprites
        LDMIA   R0,{R1,R2,R3,R4}
        ADRL    R0,tool_areaCB
        STMIA   R0,{R1,R2,R3,R4}        ; setup default block header
;
        EXITS


;;-----------------------------------------------------------------------------
;; *ToolSprites [<fsp>]
;;
;; Attempt to load a new set of borders for the windows, this routine
;; attempt to locate the sprite file.  If its in ResourceFS then we bind directly
;; to it.
;;-----------------------------------------------------------------------------

1359
ToolSprites_Code Entry "R0"
Neil Turton's avatar
Neil Turton committed
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377

        LDR     wsptr,[R12]
;
        CMP     R1,#0                   ; any parameters specified, if not then back to old glyphs
        MOVEQ   R0,#0
        BL      int_toolsprites         ; otherwise load a different set of the doofers
        BLVC    maketoollist            ; setup the tool list
;
        STRVS   R0,[SP]
        EXIT

;..............................................................................

; load the specified sprite file as a set of window borders.

; in    R0 -> filename to be opened / =0 for default
; out   sprites loaded / link setup

1378
int_toolsprites Entry "R1-R6"
Neil Turton's avatar
Neil Turton committed
1379 1380

        MOVS    R1,R0                   ; if null then use default tools
1381
        ADREQ   R1,default_tools
Neil Turton's avatar
Neil Turton committed
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
;
        DebugS  tools,"ToolSprites =",R1
;
        MOV     R0,#OSFind_ReadFile
        SWI     XOS_Find                ; open the file
        EXIT    VS
;
        MOV     R5,R0                   ; R5 = handle
;
        MOV     R0,#OSArgs_ReadEXT
        MOV     R1,R5
        SWI     XOS_Args                ; get the size of the file
        MOVVC   R6,R2                   ; keep the size somewhere safe
;
        MOVVC   R0,#FSControl_ReadFSHandle
        MOVVC   R1,R5
        SWIVC   XOS_FSControl           ; get the FS handle (ie. its address)
        BVS     %FT90                   ; close the file - reporting the error
;
        Debug   tools,"Handle, Size, FSHandle, FSInfo =",R5,R6,R1,R2
;
        AND     R2,R2,#&FF              ; extract the filing system handle
        TEQ     R2,#fsnumber_resourcefs
        BNE     %FT10                   ; not a ResourceFS so read into memory
;
; R1 -> files memory address (must be accessable)
; R5 = file handle
; R6 = size of the file
;
        Debug   tools,"Binding to ResourceFS block"
05
        BL      freetoolarea            ; release the existing area
        STR     R1,tool_area            ; -> tools in ResourcesFS
;
        ADD     R6,R6,#4
        LDMIA   R1!,{R7-R9}             ; get the next set of bytes
;
        ADD     R6,R6,#4
        ADRL    R0,tool_areaCB
        SUB     R8,R1,R0                ; offset to first sprite (CB +8)
        SUB     R14,R6,#16
        ADD     R9,R8,R14               ; offset to free area (CB +12)
;
        Debug   tools,"Area size, Count, First, Last, Real =",R6,R7,R8,R9,R1
        Debug   tools,"tool_areaCB =>",R0
;
1428
        ASSERT  SpriteAreaCBsize = 4*4
Neil Turton's avatar
Neil Turton committed
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
        STMIA   R0,{R6-R9}              ; store control block
        B       %FT90                   ; and then close up shop

; handle loading the tools from RMA, this involves claiming a suitable
; block and then loading into it.

10      MOV     R0,#ModHandReason_Claim
        MOV     R3,R6
        BL     XROS_Module
        BVS     %FT90                   ; if the claim failed then return
;
        Debug   tools,"RMA buffer at =",R2
;
        Push    "R2"
        MOV     R0,#OSGBPB_ReadFromGiven
        MOV     R1,R5
        MOV     R4,#0
        SWI     XOS_GBPB                ; read from the given block into memory
        Pull    "R2"
;
        MOVVC   R1,R2
        BVC     %BT05                   ; attempt to allocate the area if it worked
;
        DebugE  tools,"Cannot load into the RMA"
;
Kevin Bracey's avatar
Kevin Bracey committed
1454 1455
        SavePSR R14
        Push    "R0,R14"
Neil Turton's avatar
Neil Turton committed
1456 1457 1458
        MOV     R0,#ModHandReason_Free
        BL     XROS_Module              ; free up the temporary block
        Pull    "R0,R14"
Kevin Bracey's avatar
Kevin Bracey committed
1459
        RestPSR R14,,f                  ; restore flags
Neil Turton's avatar
Neil Turton committed
1460
90
Kevin Bracey's avatar
Kevin Bracey committed
1461 1462
        SavePSR R14
        Push    "R0,R14"
Neil Turton's avatar
Neil Turton committed
1463 1464 1465 1466
        MOV     R0,#0
        MOV     R1,R5
        SWI     XOS_Find                ; attempt to close the file
        Pull    "R0,R14"
Kevin Bracey's avatar
Kevin Bracey committed
1467
        RestPSR R14,,f                  ; restoring the flags word
Neil Turton's avatar
Neil Turton committed
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
;
        EXIT

default_tools
        = "WindowManager:Tools",0
        ALIGN


;;-----------------------------------------------------------------------------
;; Handle the modification of a tool icon, this includes clicks and releases.
;;
;; If select/adjust have been released then attempt to de-select the tool
;; icon - if defined, otherwise attempt to highlight it.
;;
;; in   R0,R1 = mouse co-ordinates
;;      R2 = button state
;;      R4 = icon handle
Robert Sprowson's avatar
Robert Sprowson committed
1485 1486 1487
;;      R6 = button attributes
;;      R7 = mouse flag
;;      R8 = old button state
Neil Turton's avatar
Neil Turton committed
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
;;      handle = window handle
;;      [border_iconselected] = tool handle (if applicable)
;;      [border_windowselected] = window handle of tool window
;; out  [border_iconselected] / [border_windowselected] can be modified
;;-----------------------------------------------------------------------------

modifytool

        TST     R2,#button_left+button_right
        BEQ     modifytool_release      ; if either of the buttons released then tidy

        ; flow down into handling clicked on icons

;..............................................................................

; handle the selection of a tool, first check to see if there is a suitable
; sprite for highlighting the icon, otherwise ignore it.

modifytool_clicked

1508
        Entry   "R0,R1,x0-y1,cx0-cy1"
Neil Turton's avatar
Neil Turton committed
1509 1510 1511 1512 1513

        LDR     R14,border_iconselected
        TEQ     R14,R4
        LDREQ   R14,border_windowselected
        TEQEQ   R14,handle              ; check for auto-repeat gadgets (avoids flicker!)
Kevin Bracey's avatar
Kevin Bracey committed