NewSWIs 33.7 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
; 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.
;
; > source.NewSWIs

SWIWimp_TextOp
18 19
        MyEntry "TextOp"

Neil Turton's avatar
Neil Turton committed
20
        AND     userblk,R0,#255
21 22
        CMP     userblk,#4
        SETV    HI
Neil Turton's avatar
Neil Turton committed
23 24 25 26 27 28 29
        ADRVSL  R0,ErrorBlock_WimpBadReasonCode
        BVS     ExitWimp
        [ AllowMatrix
        TST     R0,#&20000000
        MOVNE   R14,R6
        MOVEQ   R14,#0
        ]
30 31 32 33 34 35 36 37 38 39 40 41
        CMP     userblk,#1
        [ AllowMatrix
        STRHS   R14,validationstring
        ]
        ADR     R14, %FT90
        BLO     textop_setcolours
        BEQ     textop_gettextwidth
        CMP     userblk,#3
        BLO     textop_painttext
        BEQ     textop_getsplitpoint
        BHI     textop_truncate
90
Neil Turton's avatar
Neil Turton committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55
        B       ExitWimp

textop_setcolours
        Push    lr
        [ outlinefont
        LDR     R3,systemfont
        TEQ     R3,#0
        STRNE   R1,last_fg_gcol
        STRNE   R2,last_bg_gcol
        Pull    PC,NE
        ]
        MOV     R0,R2
        MOV     R3,#128                 ; bg
        MOV     R4,#0
56
        SWI     XColourTrans_SetGCOL
Neil Turton's avatar
Neil Turton committed
57 58
        MOVVC   R0,R1
        MOVVC   R3,#0
59
        SWIVC   XColourTrans_SetGCOL
Neil Turton's avatar
Neil Turton committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

        Pull    PC

textop_painttext
        Push    "lr"

        TST     R0,#&20000000
        LDRNE   R3,redrawhandle
        Abs     R3,R3,NE
        LDRNE   R14,[R3,#w_wax0]
        ADDNE   R4,R4,R14
        LDRNE   R14,[R3,#w_way1]
        ADDNE   R5,R5,R14

        [ outlinefont
        LDR     R3,systemfont
        TEQ     R3,#0
        BEQ     systemfont_paint

        MOV     R2,R1
        MOV     R1,#is_deleted
        MOV     R9,#bignum
82 83 84
      [ CnP
        MOV     R7, #nullptr
      ]
Neil Turton's avatar
Neil Turton committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
        BL      pushfontstring

        LDR     R9,last_fg_gcol
        CMP     R9,#-1
        MOVNE   R9,R9, LSR #8
        ORRNE   R9,R9,#&0E000000
        Push    "R9",NE
        LDRNE   R9,last_bg_gcol
        MOVNE   R9,R9, LSR #8
        MOVNE   R9,R9, LSL #8
        ORRNE   R9,R9,#19               ; set font colours
        Push    "R9",NE
        ADDNE   R7,R7,#8
        SUBNE   R1,R1,#8
        MOVNE   R9,#-1
        STRNE   R9,last_fg_gcol

        TST     R0,#&40000000
        LDRNE   R14,systemfonty1
        SUBNE   R14,R14,#28             ; system font was 28 OS units above baseline
        SUBNE   R5,R5,R14 ,LSR #1

        TST     R0,#&10000000           ; vertically central
        LDRNE   R14,systemfonty1
        SUBNE   R5,R5,R14 ,LSR #1

;        LDRNE   R14,systemfonty0
;        SUBNE   R5,R5,R14 ,LSR #1
;        SUBNE   R5,R5,R14               ; p'=p-(y1-3y2)/2


test_rightjustified
        TST     R0,#&80000000
        BEQ     textop_paintfancy
; right justified
        Push    "R1-R5"
        MOV     R2,#0
        MOV     R3,#bignum
        MOV     R4,#bignum
        SWI     XFont_ScanString
        MOV     R1,R3
        SWI     XFont_ConverttoOS
        MOV     R0,R1
        Pull    "R1-R5"
        SUB     R4,R4,R0                ; R4 was RHS
textop_paintfancy
        MOV     R3,R4
;        LDR     R14,systemfonty0        ; get baseline same as system font
;        ADD     R14,R14,#4
;        SUB     R4,R5,R14
        MOV     R4,R5
        MOV     R2,#16                  ; use OS units

        LDR     R14,dx_1
        BIC     R3,R3,R14
        LDR     R14,dy_1
        ADD     R4,R4,R14               ; round up
        BIC     R4,R4,R14

        SWI     XFont_Paint

        ADD     sp,sp,R7                ; balance stack from pushfontstring
        Pull    "PC"

systemfont_paint

        ]

        TST     R0,#&10000000           ; vertically central
        SUBNE   R5,R5,#16               ; system font is 32 OS units high

        LDR     R14,dx_1
        BIC     R4,R4,R14
        LDR     R14,dy_1
        SUB     R5,R5,R14               ; round down as plotting from top left
        BIC     R5,R5,R14

        TST     R0,#&80000000           ; right justified ?
        BEQ     paint_systemfont
        MOV     R0,#0
        MOV     R7,R1
systemfontlength
        LDRB    R6,[R7],#1
        CMP     R6,#31
Ben Avison's avatar
Ben Avison committed
169 170
        ADDHI   R0,R0,#1
        BHI     systemfontlength
Neil Turton's avatar
Neil Turton committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184
        MOV     R0,R0,LSL #4            ; 16 OS units per char
        SUB     R4,R4,R0
paint_systemfont
        Push    "R1"
        MOV     R1,R4
        ADD     R2,R5,#28               ; top left vs btm left
        MOV     R0,#4                   ; move abbsolute
        SWI     XOS_Plot
        Pull    "R0"
        SWI     XOS_Write0
        Pull    "PC"


textop_gettextwidth
185
        ; RISC OS 4.32 uses flag bit 31 to indicate that bounding box not width is required
Neil Turton's avatar
Neil Turton committed
186 187 188 189
        Push    "lr"

        MOV     R9,#bignum
        CMP     R2,#0
190
        MOVGT   R9,R2
Neil Turton's avatar
Neil Turton committed
191 192 193 194 195 196 197 198

        [ outlinefont
        LDR     R3,systemfont
        TEQ     R3,#0
        BEQ     textop_sysfontwidth

        MOV     R2,R1
        MOV     R1,#is_deleted
199 200 201
      [ CnP
        MOV     R7, #nullptr
      ]
Neil Turton's avatar
Neil Turton committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        BL      pushfontstring
        [ true
        MOV     R2,#0
        MOV     R3,#bignum
        MOV     R4,#bignum
        SWI     XFont_ScanString
        ADD     sp,sp,R7
        MOV     R1,R3
        |
        SWI     XFont_StringBBox                        ; calls scanstring internally
        SUB     R1,R3,R1
        ADD     sp,sp,R7
        ]
        SWI     XFont_ConverttoOS
        MOV     R0,R1
        Pull    "PC"

textop_sysfontwidth
        ]
        MOV     R0,#0

textop_sysfontwidth_loop

        LDRB    R3,[R1],#1
        CMP     R3,#31
Ben Avison's avatar
Ben Avison committed
227 228 229
        ADDHI   R0,R0,#1
        CMPHI   R9,R0
        BHI     textop_sysfontwidth_loop
Neil Turton's avatar
Neil Turton committed
230 231 232
        MOV     R0,R0, LSL #4
        Pull    "PC"

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

textop_getsplitpoint
        ; In:
        ;  r1 -> string
        ;  r2 = width, OS units
        ;  r3 = split character
        ; Out:
        ;  r0 -> split point
        Push    "lr"

      [ outlinefont
        Push    "r3"
        LDR     r3,systemfont
        TEQ     r3,#0
        BEQ     textop_sysfontsplit

        Push    "r1,r2"
        MOV     r9,#bignum
      [ CnP
        MOV     r7,#-1
      ]
        MOV     r2,r1
        MOV     r1,#is_deleted
        BL      pushfontstring

        ADD     r3,r1,r7                ; point above stacked string
        LDMIB   r3,{r1,r8}              ; retrieve original r2,r3
        MOV     r2,#0
        SWI     XFont_Converttopoints

        MOV     r3,#0
        MOV     r4,#0
        MOV     r5,#0
        MOV     r6,#0
        Push    "r3-r6,r8"

        MOV     r5,sp
        MOV     r4,#0
        MOV     r3,r1
        MOV     r2,#1:SHL:5
        ADD     r1,sp,#20
        SWI     XFont_ScanString
        ADD     sp,sp,#20

        MOV     r2,sp
        MOV     r3,#0
        MOV     r6,#bignum
01      CMP     r2,r1
        BHS     %FT03
02      LDRB    r14,[r2]
        TEQ     r14,#26                 ; font change?
        ADDEQ   r2,r2,#2
        BEQ     %BT01                   ; skip it if so
286
      [ UTF8
287
        BL      skipcharR
288 289 290
      |
        ADD     r2,r2,#1
      ]
291 292 293 294 295 296 297 298 299
        CMP     r2,r1
        ADDLS   r3,r3,#1
        BLO     %BT02
03      ; r3 = number of characters to split point
        ADD     sp,sp,r7                ; junk pushed string
        Pull    "r2"                    ; retrieve original r1
        ADD     sp,sp,#8                ; junk original r2,r3
        CMP     r3,#0
        BEQ     %FT12
300 301 302 303 304 305
11
      [ UTF8
        BL      skipcharR
      |
        ADD     r2,r2,#1
      ]
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
        SUBS    r3,r3,#1
        BNE     %BT11
12      MOV     r0,r2
        Pull    "pc"

textop_sysfontsplit
        Pull    "r3"
      ]
        ; Can't cope properly with Unicode system font until appropriate APIs are designed
        MOV     r2,r2,LSR #4            ; r2 = width converted to 8-pixel-wide characters
        MOV     r0,r1                   ; initialise last-seen split character
        CMP     r2,#0
        BEQ     %FT22
        LDRB    r14,[r1],#1
21      CMP     r14,#31                 ; if we've hit the terminator
        SUBLS   r1,r1,#1                ;   then point r1 at the terminator
        BLS     %FT22                   ;   and break from loop
        LDRB    r14,[r1],#1             ; before looping (or not) to next character,
        CMP     r14,#31                 ;   see if it's going to be
        TEQLS   r14,r14                 ;   a terminator
        TEQNE   r14,r3                  ;   or a split character
        SUBEQ   r0,r1,#1                ;   and update last-seen split character if so
        SUBS    r2,r2,#1
        BNE     %BT21
        SUB     r1,r1,#1
22      CMP     r3,#-1                  ; if no split character
        MOVEQ   r0,r1                   ; then just point after last character
        Pull    "pc"


textop_truncate
        ; In:
        ;  r1 -> string
        ;  r2 -> output buffer
        ;  r3 = buffer size
        ;  r4 = max width, OS units
        ; Out:
        ;  r0 = size of buffer needed
        Push    "r1-r4,lr"
        MOV     r2,#0
        BL      textop_gettextwidth
        LDR     r4,[sp,#3*4]
        CMP     r0,r4
        BLS     %FT50

        LDR     r14,ellipsiswidth
        LDR     r1,[sp,#0*4]
        SUB     r2,r4,r14
        MOV     r3,#-1
        BL      textop_getsplitpoint

        Pull    "r1-r3"
        ADD     sp,sp,#4
        SUB     r4,r0,r1                ; r4 = length to copy from original string
        LDRB    r14,ellipsis+1
        TEQ     r14,#0
        MOVEQ   r5,#1                   ; r5 = length of ellipsis
        MOVNE   r5,#3
        ADD     r0,r4,r5
        ADD     r0,r0,#1

        CMP     r3,#0
        Pull    "pc", EQ
11      LDRB    r14,[r1],#1
        STRB    r14,[r2],#1             ; copy bytes from original string while buffer not full
        SUB     r4,r4,#1
        SUBS    r3,r3,#1
        TEQNE   r4,#0
        BNE     %BT11
        CMP     r3,#0
        Pull    "pc", EQ
Ben Avison's avatar
Ben Avison committed
377
        ADRL    r1,ellipsis
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
12      LDRB    r14,[r1],#1
        STRB    r14,[r2],#1
        SUB     r5,r5,#1
        SUBS    r3,r3,#1
        TEQNE   r5,#0
        BNE     %BT12
        CMP     r3,#0
        MOVNE   r14,#0
        STRNEB  r14,[r2]
        Pull    "pc"

50      ; String already fitted in width specified - copy into buffer
        Pull    "r1-r3"
        ADD     sp,sp,#4
        MOV     r4,#0
51      LDRB    r14,[r1,r4]
        ADD     r4,r4,#1                ; count bytes up to and including terminator
        CMP     r14,#' '
        BHS     %BT51
        ; Now r4 = buffer needed
        MOV     r0,r4
        CMP     r3,r4
        MOVHS   r3,r4
        CMP     r3,#0
        Pull    "pc", EQ
52      LDRB    r14,[r1],#1
        STRB    r14,[r2],#1             ; copy bytes including terminator, up to min (buffer size, string length)
        SUBS    r3,r3,#1
        BNE     %BT52
        Pull    "pc"


measure_ellipsis ; called from FindFont, sets things up for textop_truncate
        Entry   "r0-r5"
412
      [ UTF8
413 414 415 416 417
        BL      read_current_alphabet
        LDREQ   r0,=&A680E2             ; lookup not appropriate for UTF-8 - use &E2 &80 &A6
        BEQ     %FT05

        MOV     r1,#Service_International
418
        MOV     r2,#Inter_UCSTable
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
        LDRB    r3,alphabet
        SWI     XOS_ServiceCall
        TEQ     r1,#0                   ; not recognised? (or maybe old International module?)
        LDRNE   r0,=&2E2E2E             ; use "..." if so
        BNE     %FT05

        ADD     r4,r4,#&80*4            ; skip first &80 characters, unlikely to be ellipsis
        MOV     r3,#&80
        LDR     lr,=&2026               ; UCS-4 ellipsis is &2026
01      LDR     r0,[r4],#4
        TEQ     r0,lr
        SUBNES  r3,r3,#1
        BNE     %BT01
        TEQ     r3,#0
        LDREQ   r0,=&2E2E2E             ; use "..." if not in alphabet
        RSBNE   r0,r3,#&100             ; else use appropriate character
435 436 437
      |
        LDR     r0,=&2E2E2E
      ]
438 439 440 441 442 443 444 445 446 447 448 449 450 451
05      STR     r0,ellipsis

      [ outlinefont
        LDR     r0,systemfont
        TEQ     r0,#0
        BEQ     %FT50

10      SUB     sp,sp,#16
        MOV     r1,#0
        MOV     r2,#0
        MOV     r3,#0
        MOV     r4,#0
        MOV     r5,#-1
        Push    "r1-r5"
Ben Avison's avatar
Ben Avison committed
452
        ADRL    r1,ellipsis
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
        LDR     r2,=1:SHL:18 :OR: 1:SHL:8 :OR: 1:SHL:5
        MOV     r3,#bignum/16
        MOV     r4,#bignum/16
        MOV     r5,sp
        SWI     XFont_ScanString
        ADD     sp,sp,#20
        Pull    "r1-r2,r5,r14"          ; get bounding box
        CMP     r5,r1
        CMPLE   r14,r2                  ; if bounding box has zero or negative width and height
        TEQLE   r3,#0
        TEQEQ   r4,#0                   ;   and offsets are both zero
        LDREQ   r0,=&2E2E2E             ;   then consider character to be undefined, so use "..."
        LDR     r14,ellipsis
        MOVNE   r0,r14
        TEQ     r0,r14                  ; if we've just changed to "..." then measure "..." instead
        STRNE   r0,ellipsis
        LDRNE   r0,systemfont
        BNE     %BT10

        LDR     r1,dx
        MOV     r2,#0
        SWI     XFont_Converttopoints
        SUB     r1,r1,#1
        ADD     r3,r3,r1
        BIC     r1,r3,r1                ; round up to next whole number of pixels (cos ConverttoOS will round down)
        SWI     XFont_ConverttoOS

        STR     r1,ellipsiswidth
        EXIT
50
      ]
        LDR     r0,ellipsis
        CMP     r0,#&100
        MOVHS   r0,#48
        MOVLO   r0,#16
        STR     r0,ellipsiswidth
        EXIT


Neil Turton's avatar
Neil Turton committed
492
SWIWimp_ResizeIcon
493 494
        MyEntry "ResizeIcon"

Robert Sprowson's avatar
Robert Sprowson committed
495 496 497
        AcceptLoosePointer_Neg R0,nullptr
        CMP     R0,#nullptr             ; equate to iconbar per PRM
        CMPNE   R0,#nullptr2            ; let through -2 as iconbar, seems natural
Ben Avison's avatar
Ben Avison committed
498 499
        LDREQ   handle,iconbarhandle
        MOVNE   handle,R0
Neil Turton's avatar
Neil Turton committed
500 501 502 503
        BL      checkhandle
        BVS     ExitWimp
        LDR     R0,[handle,#w_nicons]
        CMP     R1,R0
Ben Avison's avatar
Ben Avison committed
504
        BHI     badiconhandle
Neil Turton's avatar
Neil Turton committed
505
        CMP     R1,#0
Ben Avison's avatar
Ben Avison committed
506
        BMI     badiconhandle
Neil Turton's avatar
Neil Turton committed
507 508 509 510 511 512 513 514 515 516 517 518 519 520
        LDR     R0,[handle,#w_icons]
        ADD     R0,R0,R1, LSL #i_shift
        STMIA   R0,{R2-R5}
        B       ExitWimp

        [ UseDynamicArea
wimpspritepoolarea
        DCB     "WSpr"
wimpspritepool
        DCB     "WSP",0
        ALIGN
        ]

allocatespritememory
Kevin Bracey's avatar
Kevin Bracey committed
521
      [ UseDynamicArea
Neil Turton's avatar
Neil Turton committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535
        Push    "R1,R8,LR"

        TEQ     R0,#ModHandReason_Claim
        BNE     %FT10
        ADR     R0,wimpspritepool               ; Look up name for Wimp sprite pool.
        ADR     R2,errorbuffer                  ; Put it in a safe place for now (copied out by OS_DynamicArea).
        MOV     R3,#256
        BL      LookupToken1
        Pull    "R1,R8,PC",VS
        MOV     R8,R2
        MOV     R0,#ModHandReason_Claim         ; Restore corrupted R0.
10
        LDR     R1,wimpspritepoolarea
        BL      Dynamic_Module
Kevin Bracey's avatar
Kevin Bracey committed
536
        Pull    "R1,R8,PC",VC
Neil Turton's avatar
Neil Turton committed
537 538 539

        MyXError WimpNoSprites
        Pull    "R1,R8,PC"
Kevin Bracey's avatar
Kevin Bracey committed
540 541 542 543 544
      |
	Push	"LR"
	SWI	XOS_Module
	Pull	"PC"
      ]
Neil Turton's avatar
Neil Turton committed
545 546 547 548 549 550 551 552

        MakeErrorBlock WimpNoSprites

badiconhandle
        ADRL    R0,ErrorBlock_WimpBadIconHandle
        SETV
        B       ExitWimp

553 554 555
badextend * ExitWimp

SWIWimp_Extend  ROUT
556 557
        MyEntry "Extend"

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        CMP     R0,#WimpExtend_MAX
        ADDLO   PC,PC,R0,LSL #2
        B       extend_more
00
        B       badextend
        B       extend_workspace
        B       extend_jumptable
        B       extend_swicallback
        B       extend_spritenamepointers
        B       extend_tilingcallback
        B       extend_parent
        B       extend_frontchild
        B       extend_backchild
        B       extend_siblingabove
        B       extend_siblingbehind
        B       extend_getborderinfo
        B       extend_ncerrorpointersuspend
        B       extend_spritesuffix
ROOL's avatar
ROOL committed
576
        B       extend_getvalidationstring
577 578 579 580 581 582 583 584 585 586
        ASSERT . - %BT00 = WimpExtend_MAX*4

extend_more
        SUB     R14,R0,#256
        CMP     R14,#WimpExtend_SpriteSuffix_ROL-256
        BEQ     extend_spritesuffix_rol
        B       badextend

extend_workspace
        MOV     R0,R12
Neil Turton's avatar
Neil Turton committed
587 588
        B       ExitWimp

589 590 591 592 593 594 595 596 597 598 599
extend_jumptable
        ADR     R0,extendjumptable
        B       ExitWimp

extend_swicallback
        LDR     R0,wimpswiintercept
        STR     R1,wimpswiintercept
        B       ExitWimp

extend_spritenamepointers
        ADR     R0,spritename
600
        ADRL    R1,list_at
601 602
        STR     R1,[sp]
        B       ExitWimp
Neil Turton's avatar
Neil Turton committed
603

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
extend_tilingcallback
        LDR     R0,plotsprCB
        STR     R1,plotsprCB
        B       ExitWimp

      [ ChildWindows
extend_parent
extend_frontchild
extend_backchild
extend_siblingabove
extend_siblingbehind
        ROUT
        ; In: R0 = 6 => get parent, 7,8 => get top/bottom child, 9,10 => get next/previous sibling
        ;     R1 = window handle, or -1 for top-level
        ; Out: R1 = result handle, or -1 for none
        CMP     R1,#nullptr
Neil Turton's avatar
Neil Turton committed
620 621 622 623 624 625
        BEQ     %FT05

        MOV     handle,R1
        BL      checkhandle_iconbar
        BVS     ExitWimp

626
        CMP     R0,#WimpExtend_FrontChild
Ben Avison's avatar
Ben Avison committed
627 628
        LDRLO   handle,[handle,#w_parent]
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
629 630 631

        LDREQ   handle,[handle,#w_children + lh_forwards]
        BEQ     %FT02
Neil Turton's avatar
Neil Turton committed
632

633
        CMP     R0,#WimpExtend_SiblingAbove
Ben Avison's avatar
Ben Avison committed
634 635
        LDRLO   handle,[handle,#w_children + lh_backwards]
        BLO     %FT02
Neil Turton's avatar
Neil Turton committed
636 637 638 639 640 641

        LDR     R14,[handle,#w_flags]
        TST     R14,#ws_open                    ; sibling pointers are garbage if window is not open
        MOVEQ   handle,#nullptr
        BEQ     %FT04

642
        CMP     R0,#WimpExtend_SiblingAbove
Neil Turton's avatar
Neil Turton committed
643
        LDREQ   handle,[handle,#w_active_link + ll_forwards]
Ben Avison's avatar
Ben Avison committed
644
        LDRHI   handle,[handle,#w_active_link + ll_backwards]
Neil Turton's avatar
Neil Turton committed
645 646 647 648 649 650 651 652 653 654 655 656 657

02      CMP     handle,#nullptr
        LDRNE   R14,[handle,#ll_forwards]       ; if either forward or backward pointer is null, we're at the head entry (not a window)
        CMPNE   R14,#nullptr
        LDRNE   R14,[handle,#ll_backwards]
        CMPNE   R14,#nullptr
        MOVEQ   handle,#nullptr
        SUBNE   handle,handle,#w_active_link

03      CMP     handle,#nullptr
        Rel     handle,handle,NE

04      STR     handle,[sp]
Neil Turton's avatar
Neil Turton committed
658 659
        B       ExitWimp

660
05      CMP     R0,#WimpExtend_FrontChild
Neil Turton's avatar
Neil Turton committed
661 662 663
        LDREQ   handle,activewinds + lh_forwards
        BEQ     %BT02

664
        CMP     R0,#WimpExtend_BackChild
Neil Turton's avatar
Neil Turton committed
665 666 667 668
        LDREQ   handle,activewinds + lh_backwards
        BEQ     %BT02

        B       ExitWimp
669 670 671 672 673 674
      |
extend_parent * badextend
extend_frontchild * badextend
extend_backchild * badextend
extend_siblingabove * badextend
extend_siblingbehind * badextend
Neil Turton's avatar
Neil Turton committed
675
      ]
Neil Turton's avatar
Neil Turton committed
676

677 678
      [ NCErrorBox
        ; Handle hiding of pointer for the duration of keyboard-driving of pointer
679 680
extend_ncerrorpointersuspend
        MOV     R0, #106
681 682 683 684 685 686
        MOV     R1, #0
        SWI     XOS_Byte        ; turn off pointer
        MOV     R0, #1
        ADRL    R14, ptrsuspendflag
        STR     R0, [R14]
        B       ExitWimp
687 688
      |
extend_ncerrorpointersuspend * badextend
689 690
      ]

691 692
extend_spritesuffix ROUT
        ; Work out for the client what resolution suffix to append to a sprites file
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
        ; First available in Wimp 4.85
        ; Older Wimps don't return error, but can be detected because all registers are preserved
        ; On entry:
        ;   r0 = 13 (reason code)
        ;   r1 -> pathname of file without suffix
        ;   r2 -> buffer for result
        ;   r3 = size of buffer (0 to read size required)
        ; On exit:
        ;   r0 corrupted
        ;   r3 = space left in buffer (ie negative of size required if r3=0 on entry)
        ;   other registers preserved
        ;   contents of buffer are only valid if r3>=0
        ;   error "File not found" may be returned
        MOV     R0, R1
loop1   LDRB    LR, [R0], #1
        CMP     LR, #32
        BCS     loop1
        SUB     R0, R0, R1      ; length of original string (incl terminator)
        ADD     R0, R0, #2      ; for the moment, we know the resultant string will be at most 2 bytes longer

        SUBS    R3, R3, R0
        STR     R3, [SP, #2*4]  ; put result in stack frame
        BMI     ExitWimp        ; exit now if buffer not big enough

loop2   LDRB    LR, [R1], #1
        CMP     LR, #32
        STRCSB  LR, [R2], #1    ; copy string into buffer
        BCS     loop2
        MOV     LR, #0
        STRB    LR, [R2, #2]    ; insert terminator after two more characters

        LDRB    R5, romspr_suffix
        LDRB    R6, romspr_suffix+1
        SUB     R5, R5, #'0'
        SUB     R6, R6, #'0'
728 729 730 731 732 733 734 735
loop3
      [ SpritesA
        CMP     R5,R6
        LDREQB  R0,alphaspriteflag
        CMPEQ   R0,#255
        MOVEQ   R5,#'A'-'0'     ; Try alpha before square pixels
      ]
loop4   ADD     LR, R5, #'0'
736 737 738 739 740 741 742 743 744 745 746
        STRB    LR, [R2]
        ADD     LR, R6, #'0'
        STRB    LR, [R2, #1]
        MOV     R0, #&4C        ; try opening a file on File$Path (matches *SLoad etc)
        LDR     R1, [SP, #1*4]  ; retrieve pointer to start of buffer
        SWI     XOS_Find
        MOVVC   R1, R0
        MOVVC   R0, #0
        SWIVC   XOS_Find
        BVC     ExitWimp        ; buffer contains a valid file, so exit

747 748 749 750 751 752
      [ SpritesA
        CMP     R5,#'A'-'0'
        MOVEQ   R5,R6
        BEQ     loop4           ; Try square pixels if alpha failed
      ]

753 754 755 756 757 758 759 760 761
        TEQ     R6, #3
        MOVEQ   R6, #2
        BEQ     loop3           ; after Sprites23, try Sprites22

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

762
      [ Sprites11
763 764 765 766
        TEQ     R5, #1
        MOVEQ   R5, #2
        MOVEQ   R6, #2
        BEQ     loop3           ; after Sprites11, try Sprites22
767
      ]
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786

      [ SpritesA
        LDRB    R0,alphaspriteflag
        CMP     R0,#0
        BEQ     %FT135
        MOV     R14,#'A'
        STRB    R14,[R2]
        MOV     R14,#0
        STRB    R14,[R2,#1]
        MOV     R0, #&4C
        LDR     R1, [SP, #1*4]
        SWI     XOS_Find        ; try just <filename>A before falling back to the original
        MOVVC   R1, R0
        MOVVC   R0, #0
        SWIVC   XOS_Find
        BVC     ExitWimp
135
      ]

787 788 789 790 791 792 793 794 795 796
        MOV     LR, #0
        STRB    LR, [R2]
        MOV     R0, #&4C
        LDR     R1, [SP, #1*4]
        SWI     XOS_Find        ; finally, try with no suffix
        MOVVC   R1, R0
        MOVVC   R0, #0
        SWIVC   XOS_Find
        B       ExitWimp        ; return any error we got from this last one

797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
extend_spritesuffix_rol ROUT
        ; In:   R1 = buffer containing pathname of file with no suffix
        ; Out:  R0 = buffer passed in
        ;       R1 = 0 (to indicate call supported by Wimp version)
        ; This is effectively the same as Wimp_Extend 13, except the name is
        ; updated in-place, and no error is returned if no suitable file is
        ; found.
        ; To keep things simple, we'll just allocate a temporary buffer from the
        ; RMA and call Wimp_Extend 13.
        MOV     R3, #0
        STR     R3, [SP]
10
        LDRB    R0, [R1, R3]
        ADD     R3, R3, #1
        CMP     R0, #32
        BCS     %BT10
        ADD     R3, R3, #2
        MOV     R0, #ModHandReason_Claim
        BL     XROS_Module
        BVS     %FT90           ; Give up if no memory
        MOV     R0, #WimpExtend_SpriteSuffix
        SWI     XWimp_Extend
        BVS     %FT30
        ; Copy result to original buffer
        MOV     R3, #0
20
        LDRB    R0, [R2, R3]
        STRB    R0, [R1, R3]
        CMP     R0, #32
        ADD     R3, R3, #1
        BCS     %BT20
30
        MOV     R0, #ModHandReason_Free
        BL     XROS_Module
90
        MOV     R0, R1
        CLRV
        B       ExitWimp


Neil Turton's avatar
Neil Turton committed
837 838
extendjumptable
        B       getspriteaddr
839 840 841
      [ CnP
        B       extendjumptable_pushfontstring
      |
Neil Turton's avatar
Neil Turton committed
842
        B       pushfontstring
843
      ]
Neil Turton's avatar
Neil Turton committed
844 845 846 847 848 849 850
        B       callaswi
        B       ExitWimp
        B       ExitWimp2
        B       godrawicon
        B       exitcicon
        B       int_setcolour

851 852 853 854 855
      [ CnP
extendjumptable_pushfontstring
        MOV     R7, #nullptr
        B       pushfontstring
      ]
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
                     ^  0, userblk
furnblock_handle     #  4
furnblock_lborder    #  4
furnblock_bborder    #  4
furnblock_rborder    #  4
furnblock_tborder    #  4
furnblock_back       #  4
furnblock_close      #  4
furnblock_titlegap0  #  4
furnblock_title      #  4
furnblock_titlegap1  #  4
furnblock_iconise    #  4
furnblock_togglew    #  4
furnblock_toggleh    #  4
furnblock_vscrgap1   #  4
furnblock_up         #  4
furnblock_vscr       #  4
furnblock_down       #  4
furnblock_vscrgap0   #  4
furnblock_adjusth    #  4
furnblock_adjustw    #  4
furnblock_hscrgap1   #  4
furnblock_right      #  4
furnblock_hscr       #  4
furnblock_left       #  4
furnblock_hscrgap0   #  4

883 884 885
extend_getborderinfo ROUT
        ; In: R1 = pointer to block to fill with furniture dimensions
        ;     [R1,#0] = window handle to use, or 0 for generic values
886
        CMP     userblk, #ApplicationStart
Ben Avison's avatar
Ben Avison committed
887
        MyXError  WimpBadPtrInR1, LO, L
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 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 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 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 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
        BVS     ExitWimp                ; check pointer valid in this case

        LDR     handle, furnblock_handle
        TEQ     handle, #0
        BEQ     %FT01

        BL      checkhandle_iconbar
        BVS     ExitWimp
        ADD     R0, handle, #w_ow0
        LDMIA   R0, {cx0, cy0, cx1, cy1} ; cx0-cy1 = visible area
        LDMIA   R0, {x0, y0, x1, y1}     ; x0-y1 = visible area
        BL      calc_w_x0y0x1y1          ; x0-y1 = window outline
        SUB     R0, cx0, x0
        STR     R0, furnblock_lborder
        SUB     R0, cy0, y0
        STR     R0, furnblock_bborder
        SUB     R0, x1, cx1
        STR     R0, furnblock_rborder
        SUB     R0, y1, cy1
        STR     R0, furnblock_tborder
        SUB     x1, x1, x0               ; calc total lengths of sides - top edge
        SUB     y1, y1, y0               ; - right edge
        MOV     x0, x1                   ; - bottom edge
        LDR     R14, [handle, #w_flags]  ; load flags
        LDR     R1, [handle, #w_parent]  ; get parent
        B       %FT02

01      LDR     R0, dx                   ; assume max border widths
        STR     R0, furnblock_lborder
        LDR     R0, hscroll_height1
        STR     R0, furnblock_bborder
        LDR     R0, vscroll_width1
        STR     R0, furnblock_rborder
        LDR     R0, title_height1
        STR     R0, furnblock_tborder
        MOV     x1, #&200                ; assume reasonably large
        MOV     y1, x1
        MOV     x0, x1
        MOV     R14, #wf_iconbits        ; assume all border flags set
        MOV     R1, #-1                  ; assume a top-level window

02
        TST     R14, #wf_icon1           ; back icon?
        LDRNE   R0, back_width
        MOVEQ   R0, #0
        SUB     x1, x1, R0
        STR     R0, furnblock_back

        TST     R14, #wf_icon2           ; close / iconise icons?
        LDRNE   R0, close_width
        MOVEQ   R0, #0
        SUB     x1, x1, R0
        STR     R0, furnblock_close
      [ IconiseButton
        BEQ     %FT06
        MOV     R0, #0
        CMP     R1, #-1
        BNE     %FT06 ; no iconise button on children
        LDRB    R1, iconisebutton
        TEQ     R1, #0
        BEQ     %FT06
        LDR     R0, iconise_width
06
      |
        MOV     R0, #0
      ]
        SUB     x1, x1, R0
        STR     R0, furnblock_iconise

        TST     R14, #wf_icon4           ; toggle-size icon?
        LDRNE   R0, vscroll_width
        MOVEQ   R0, #0
        SUB     x1, x1, R0
        STR     R0, furnblock_togglew
        LDRNE   R0, title_height
        SUB     y1, y1, R0
        STR     R0, furnblock_toggleh

        TST     R14, #wf_icon3           ; title bar?
        MOVEQ   x1, #0
        STR     x1, furnblock_title

        MOV     R0, #0
        STR     R0, furnblock_titlegap0  ; provided to support future expansion
        STR     R0, furnblock_titlegap1  ; eg extra buttons, or a squashable title bar

        MVN     R0, R14
        TST     R0, #wf_icon5 :OR: wf_icon7
        TSTNE   R0, #wf_icon6            ; adjust-size / blank?
        LDREQ   R0, hscroll_height
        MOVNE   R0, #0
        SUB     y1, y1, R0
        STR     R0, furnblock_adjusth
        LDREQ   R0, vscroll_width
        SUB     x0, x0, R0
        STR     R0, furnblock_adjustw

        TST     R14, #wf_icon5           ; if no vscroll, clear the vscroll words
        MOV     R0, #0
        STREQ   R0, furnblock_vscrgap1
        STREQ   R0, furnblock_up
        STREQ   R0, furnblock_vscr
        STREQ   R0, furnblock_down
        STREQ   R0, furnblock_vscrgap0
        BEQ     %FT04

        Push    "R14"
        TEQ     handle, #0
;       MOVEQ   R0, #0                   ; gap0 = 0
        MOVEQ   R14, #0                  ; gap1 = 0
        BEQ     %FT03
      [ ChildWindows
        Push    "x0,y1"                  ; determine vertical gaps
        MOV     R0, #iconposn_vscroll
        BL      calc_w_iconposn2
        SUB     R0, y0, cy0
        SUB     R14, cy1, y1
        Pull    "x0,y1"
      ]
03      STR     R0, furnblock_vscrgap0
        STR     R14, furnblock_vscrgap1
        SUB     y1, y1, R0
        SUBS    y1, y1, R14

;       CMP     y1, #0                   ; see if vertical arrows are squashed
        MOVLE   cy0, #0                  ; arrows given 0 length if scrollbar has -ve length (it can happen!)
        MOVLE   cy1, #0
        LDRGT   cy0, down_height         ; standard lengths
        LDRGT   cy1, up_height
        ADDGT   R14, cy0, cy1
        RSBGTS  R0, y1, R14
        MOVGT   cy0, y1, LSR#1           ; which may be squashed
        SUBGT   cy1, y1, cy0
        SUB     y1, y1, cy0              ; take arrows from the bar length to give the well length
        SUB     y1, y1, cy1
        STR     cy1, furnblock_up
        STR     y1, furnblock_vscr
        STR     cy0, furnblock_down
        Pull    "R14"

04
        TST     R14, #wf_icon7           ; if no hscroll, clear the hscroll words
        MOV     R0, #0
        STREQ   R0, furnblock_hscrgap1
        STREQ   R0, furnblock_right
        STREQ   R0, furnblock_hscr
        STREQ   R0, furnblock_left
        STREQ   R0, furnblock_hscrgap0
        BEQ     ExitWimp                 ; all done

        TEQ     handle, #0
;       MOVEQ   R0, #0                   ; gap0 = 0
        MOVEQ   R14, #0                  ; gap1 = 0
        BEQ     %FT05
      [ ChildWindows
        Push    "x0"                     ; determine horizontal gaps
        MOV     R0, #iconposn_hscroll
        BL      calc_w_iconposn2
        SUB     R0, x0, cx0
        SUB     R14, cx1, x1
        Pull    "x0"
      ]
05      STR     R0, furnblock_hscrgap0
        STR     R14, furnblock_hscrgap1
        SUB     x0, x0, R0
        SUBS    x0, x0, R14

;       CMP     x0, #0                   ; see if horizontal arrows are squashed
        MOVLE   cx0, #0                  ; arrows given 0 length if scrollbar has -ve length (it can happen!)
        MOVLE   cx1, #0
        LDRGT   cx0, left_width          ; standard lengths
        LDRGT   cx1, right_width
        ADDGT   R14, cx0, cx1
        RSBGTS  R0, x0, R14
        MOVGT   cx0, x0, LSR#1           ; which may be squashed
        SUBGT   cx1, x0, cx0
        SUB     x0, x0, cx0              ; take arrows from the bar length to give the well length
        SUB     x0, x0, cx1
        STR     cx1, furnblock_right
        STR     x0, furnblock_hscr
        STR     cx0, furnblock_left
        B       ExitWimp                 ; all done

ROOL's avatar
ROOL committed
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
        LTORG

extend_getvalidationstring ROUT
        ; Retrieve a validation string for an icon
        ; tricky to do by transferblock as there's no length information easily available
        ; On entry:
        ;   R1 = window handle
        ;   R2 = icon handle
        ;   R3 -> buffer for data (must not be in application space or will get paged out!)
        ;   R4 = buffer size
        ; On exit:
        ;   R0 and V set if error
        ;   R4 = bytes free in buffer
        ;   So to find length of validation string first, call with R4 = 0.
        ;   If returns with R4 = 0 then there's no validation string.
        Push    "R1-R3,R5-R6,handle,R14"
        MOV     handle,R1
        BL      checkhandle
        Pull    "R1-R3,R5-R6,handle,R14",VS
        BVS     ExitWimp

        ; check if icon is valid
        LDR     R6,[handle,#w_nicons]
        CMP     R2,R6
        BHS     %FT99

        LDR     R14,[handle,#w_taskhandle] ; ready for task paging
        LDR     R10,[handle,#w_icons]
        ADD     R10,R10,R2,LSL #i_shift

        ; R10 -> icon data block
        LDR     R5,[R10,#i_flags]
        TST     R5,#if_text
        TSTNE   R5,#if_indirected       ; only IsT have validation
        MOVEQ   R5,#0
        LDRNE   R5,[R10,#i_data+4]      ; pointer to validation string
        AcceptLoosePointer_NegOrZero R5,-1
        CMP     R5,R5,ASR #31
        MOVEQ   R4,#0
        BEQ     %FT30                   ; nothing to do
18
        LDR     R6,taskhandle
        Push    "R6"                    ; current task

        ; page in task
        Task    R14,,"Get validation string"

        ; R5 -> validation string
        ; count length
        MOV     R1,R5
        MOV     R6,#0
19
        LDRB    R0,[R1],#1
        ADD     R6,R6,#1
        CMP     R0,#32
        BGE     %BT19
20
        ; R6 = length inc terminator
        ; copy validation string
        ; enough room?
        SUBS    R4,R4,R6
        BMI     %FT29                   ; no, so return the space needed
21
        LDRB    R0,[R5],#1
        CMP     R0,#32
        MOVLT   R0,#0                   ; force the terminator to be 0
        STRB    R0,[R3],#1
        BGE     %BT21
29
        ; page out if necessary
        Pull    "R14"
        Task    R14,,"Restore after get validation string"
30
        Pull    "R1-R3,R5-R6,handle,R14"
        MOV     R0,#WimpExtend_GetValidationString
        B       ExitWimp2
99
        ; bad icon
        Pull    "R1-R3,R5-R6,handle,R14"
        MyXError WimpBadIconHandle,,L
        B       ExitWimp

Neil Turton's avatar
Neil Turton committed
1153
        END