Wimp03 157 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
; 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.
;
; > Sources.Wimp03

;
; Entry:     [taskhandle] = current task handle
;         [newtaskhandle] = new task handle
; Exit:   R14, [flagword] = R0 on entry to Wimp_Poll (plus version bits)
;                 userblk = R1 on entry to Wimp_Poll
; Errors:  address exception if a dead task is paged IN here
;

pageintask
Kevin Bracey's avatar
Kevin Bracey committed
26 27 28 29 30 31 32 33 34
; Need to preserve flags, and return stuff in R14. Hence EntryS/EXITS are
; no good :(

      [ No32bitCode
        Push    "R0,R14"
      |
        Push    "R0,R1,R14"
        MRS     R1,CPSR
      ]
Neil Turton's avatar
Neil Turton committed
35 36 37 38 39 40 41 42 43
;
        Debuga  sw,"Page in task:",#newtaskhandle
        LDR     R14,newtaskhandle
        CMP     R14,#0                  ; taskhandle = -1 ==> menu owner
      [ debugsw
        BNE     %FT01
        Debug   sw," - system task"
01
      ]
Kevin Bracey's avatar
Kevin Bracey committed
44
        BEQ     pageintaskdone          ; 0 ==> no owner at all (ie. Wimp)
Neil Turton's avatar
Neil Turton committed
45 46 47 48 49 50 51 52 53 54 55 56 57
        LDRLT   R14,menutaskhandle      ; -1 ==> menus
      [ debugsw
        BGE     %FT01
        Debuga  sw," - menu task =",R14
01
      ]
        CMPLT   R14,#0
      [ debugsw
        BGE     %FT01
        Debuga  sw," - deleted!"
01
      ]
        Debug   sw,""
Kevin Bracey's avatar
Kevin Bracey committed
58
        BLT     pageintaskdone          ; if no menu owner, give up
Neil Turton's avatar
Neil Turton committed
59 60 61
        LDR     R0,taskhandle
        TEQ     R0,R14
        LDREQ   R14,flagword
Kevin Bracey's avatar
Kevin Bracey committed
62
        BEQ     pageintaskdone          ; DON'T RELOAD userblk if not nec.!!!
Neil Turton's avatar
Neil Turton committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        Push    "R14"
        LDR     R14,[wsptr,R14]
        TST     R14,#task_unused
        BLEQ    mapslotout              ; map slot out, if still alive
        Pull    "R14"
        STR     R14,taskhandle
        BL      mapslotin
        LDR     R14,taskhandle
        LDR     R14,[wsptr,R14]
        TST     R14,#task_unused        ; tasks are sometimes allowed
      [ debugtask1                      ; to be dead here
        BEQ     %FT01
        Debug   task1,"Dead task paged in:",#taskhandle
01
      ]
        LDREQ   userblk,[R14,#task_registers+4*1]      ; get user R1
        LDREQ   R14,[R14,#task_flagword]
        STREQ   R14,flagword
Kevin Bracey's avatar
Kevin Bracey committed
81 82
pageintaskdone
      [ No32bitCode
Neil Turton's avatar
Neil Turton committed
83
        Pull    "R0,PC",,^                      ; must preserve flags
Kevin Bracey's avatar
Kevin Bracey committed
84 85 86 87
      |
        MSR     CPSR_f,R1
        Pull    "R0,R1,PC"                      ; must preserve flags
      ]
Neil Turton's avatar
Neil Turton committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

lookfornewtask
        Debug   task1,"Task dead on entry to Wimp_Poll"
;
; disconnect the task from any further contact with the Wimp
;
        LDR     R14,ptrtask
        LDR     R5,taskhandle
        TEQ     R5,R14
        MOVEQ   R14,#nullptr            ; avoid ptr_leaving_window!
        STREQ   R14,ptrwindow
;
        MOV     R0,#EscapeHandler       ; the domain is about to die -
        SWI     XOS_ReadDefaultHandler  ; prevent nasty handlers from being
        SWIVC   XOS_ChangeEnvironment   ; called when they shouldn't be!
;
        MOV     R0,#EventHandler
        SWI     XOS_ReadDefaultHandler
        SWIVC   XOS_ChangeEnvironment
Ben Avison's avatar
Ben Avison committed
107 108 109 110
;
        MOV     R0,#UpCallHandler
        SWI     XOS_ReadDefaultHandler
        SWIVC   XOS_ChangeEnvironment
Neil Turton's avatar
Neil Turton committed
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
;
        BL      deallocatependingtask   ; delete task block (gone for good)
                                        ; reclaim memory as well!
;
        Debug   co,"Closing down task: commandflag =",#commandflag
;
        LDR     R7,commandflag          ; R7 used further down!!!
;
        MOV     R0,#0                   ; 'Press SPACE' if anything printed
        BL      int_commandwindow       ; can't call SWI since task is dead!
        CLRV                            ; ignore errors
;
; now look for an alternative task (preserve R7 in this code)
;
        ADRL    R5,taskpointers
        MOV     R6,#maxtasks
01
        LDR     R14,[R5],#4
        TST     R14,#task_unused
        BEQ     %FT02
        SUBS    R6,R6,#1
        BNE     %BT01
;
        Debug   task1,"No tasks left - calling OS_Exit"
        SWI     XOS_Exit
02
        SUB     R5,R5,#4
        SUB     R5,R5,wsptr
        LDR     R6,taskhandle          ; R6 = previous task handle
        STR     R5,taskhandle
        LDR     userblk,[R14,#task_registers+4*1]
        Debug   task1,"Switching to task",R5
;
        BL      mapslotin               ; previous slot is already mapped out
;
; if that was the single task, change mode now!
; the rule is that the screen is reset unless the commandwindow is pending
; (used to be based on singletaskhandle)
;
        LDR     R5,singletaskhandle
        TEQ     R5,R6
        MOVEQ   R14,#nullptr            ; reset singletaskhandle BEFORE resetk
        STREQ   R14,singletaskhandle
        STREQ   R14,backwindow          ; must have been deleted
;
        TEQ     R7,#cf_pending          ; R7 set up further up !!!
        LDRNE   R0,currentmode          ; only change mode if chars printed

        BLNE    int_setmode
Kevin Bracey's avatar
Kevin Bracey committed
160
      [ Medusa
Neil Turton's avatar
Neil Turton committed
161 162 163 164
        ADRL    R14,greys_mode
        LDRB    R14,[R14]
        TEQ     R14,#0
        BLNE    recalc_greys_palette
Kevin Bracey's avatar
Kevin Bracey committed
165
      ]
Neil Turton's avatar
Neil Turton committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

        Debug   task1,"Returned from int_setmode"
;
        ADRL    R3,tempiconblk          ; forget old settings
        BL      resetkeycodes           ; *FX 4,2 etc.
;
        Debug   task1,"Paranoid resetting of state when task exits"
;
        B       taskisused



;;-----------------------------------------------------------------------------
;; Wimp_RegisterFilter - install/deinstall a filter routine
;;
;; in   R0 = filter reason
;;              =0 => pre-poll filter (prior to returning to task)
;;              =1 => post-poll filter (on return back to Wimp)
;;              =2 => block copy filter
;;              =3 => get rectangle filter
;;
;;      R1 -> filter routine / =0 for default
;;      R2 -> workspace for filter
;; out  -
;;-----------------------------------------------------------------------------

        ASSERT  postfilter =prefilter +8
        ASSERT  copyfilter =postfilter +8
        ASSERT  rectanglefilter =copyfilter +8
Kevin Bracey's avatar
Kevin Bracey committed
195 196
	ASSERT	postrectfilter =rectanglefilter +8
	ASSERT	posticonfilter =postrectfilter +8
Neil Turton's avatar
Neil Turton committed
197 198 199 200 201 202 203 204

        ASSERT  prefilterWP =prefilter -4

SWIWimp_RegisterFilter

        MyEntry "RegisterFilter"

        CMP     R0,#WimpFilter_MAX      ; filter number valid?
Ben Avison's avatar
Ben Avison committed
205
        BHS     err_badR0               ; if not then return an error
Neil Turton's avatar
Neil Turton committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

        TEQ     R1,#0                   ; de-register a filter
        ADREQ   R1,filtertable
        LDREQ   R2,[R1,R0,LSL #2]       ; get the default owner
        ADDEQ   R1,R1,R2                ; and resolve to an address, rather than offset

        ADRL    R14,prefilter
        ADD     R14,R14,R0,LSL #3       ; -> vector to store into
        STR     R1,[R14]
        STR     R2,[R14,#-4]            ; setup the handler correctly

        B       ExitWimp

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

; table of default vector owners

filtertable
        & prefilter_default -filtertable
        & postfilter_default -filtertable
        & copyfilter_default -filtertable
        & rectanglefilter_default -filtertable
Kevin Bracey's avatar
Kevin Bracey committed
228 229
        & postrectfilter_default -filtertable
	& posticonfilter_default -filtertable
Neil Turton's avatar
Neil Turton committed
230 231 232 233 234 235
        & -1

prefilter_default
postfilter_default
copyfilter_default
rectanglefilter_default
Kevin Bracey's avatar
Kevin Bracey committed
236 237
postrectfilter_default
posticonfilter_default
Neil Turton's avatar
Neil Turton committed
238

Kevin Bracey's avatar
Kevin Bracey committed
239
        MOV     PC,LR
Neil Turton's avatar
Neil Turton committed
240 241 242 243 244 245

;;-----------------------------------------------------------------------------
;; Reset the filters back to their default state, called on init and svc_reset,
;; once done issue a svc_RegisterFilters.
;;-----------------------------------------------------------------------------

Kevin Bracey's avatar
Kevin Bracey committed
246
defaultfilters EntryS "R0-R2"
Neil Turton's avatar
Neil Turton committed
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

        ADR     R0,filtertable          ; -> list of default owners
        ADRL    R1,prefilter            ; -> list of vectors to install
        MOV     R2,R0

10      LDR     R14,[R0],#4             ; get offset to routine
        CMP     R14,#-1
        ADDNE   R14,R14,R2
        STRNE   R14,[R1],#8             ; if not end of the table then store away
        BNE     %BT10

        ADR     R0,svc_callback
        MOV     R1,WsPtr
        SWI     XOS_AddCallBack         ; add the callback routine

        EXITS

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

; callback routine used to warn the outside world that they should register
; filters with the Window Manager.

svc_callback ROUT

        Push    "R1,LR"
        MOV     R1,#Service_WimpRegisterFilters
        SWI     XOS_ServiceCall
Kevin Bracey's avatar
Kevin Bracey committed
274
        Pull    "R1,PC"                 ; broadcast to the world
Neil Turton's avatar
Neil Turton committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301


;;----------------------------------------------------------------------------
;; Wimp_Poll
;;
;; return codes are prioritised according to number:
;;
;;       1       Redraw_Window_Request
;;       2       Open_Window_Request
;;       3       Close_Window_Request
;;       4       Pointer_Leaving_Window
;;       5       Pointer_Entering_Window
;;       6       Mouse_Click
;;       7       User_Dragbox
;;       8       Key_Pressed
;;       9       Menu_Select
;;      10       Scroll_Request
;;
;; This is also the entry point after deleting a task
;;----------------------------------------------------------------------------

err_badR3
        MyXError  WimpBadR3
        B       ExitWimp
        MakeErrorBlock WimpBadR3

SWIWimp_PollIdle
302
        Debug   poll2, "Wimp_PollIdle entry"
Neil Turton's avatar
Neil Turton committed
303 304 305 306
        ORR     R0,R0,#flag_pollidle    ; time limit is in R2
        B       %FT01

SWIWimp_Poll
307
        Debug   poll2, "Wimp_Poll entry"
Neil Turton's avatar
Neil Turton committed
308 309 310 311
        BIC     R0,R0,#flag_pollidle    ; no time limit supplied

01
        MyEntry "Poll"
312

Neil Turton's avatar
Neil Turton committed
313 314 315 316 317 318 319 320 321
; remember task number, to allow optimisation of return to caller
;
; Entry: R0 = flag word
;        R1 = taskhandle
;        R2 = target time (if R0 & flag_pollidle) - as in ReadMonotonicTime
;        R3 -> poll word  (if R0 & flag_pollword, and Wimp 2.23 known)
;   userblk = original R1 --> poll block
;

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
      [ CnP
; is there a pending Message_DataLoad for the cnp task to handle?
        LDR     R14,clipboard_spritearea_addr
        TEQ     R14,#0
        BEQ     %FT00                   ; definitely not

        ADD     R14,R14,#cnp_message_dataload_park
        LDR     R14,[R14]
        TEQ     R14,#0
        BEQ     %FT00                   ; no message parked at the moment

        ADRL    R14,clipboard_pollword
        LDR     R4,[R14]
        ORR     R4,R4,#clipboard_pw_dataload_flag
        STR     R4,[R14]                ; set the poll word flag so the task can pick up the stored message
00
      ]

Neil Turton's avatar
Neil Turton committed
340 341 342 343
; attempt to call a pre-poll filter routine, it may modify the flags in R0

        CallFilter prefilter
;
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
      [ AutoHourglass                   ; it could still be a while until the next task switch,
        LDR     R1, hourglass_status    ; so ensure the hourglass is off at this point
      [ debugautohg
	Push	"handle"
	LDR	handle, taskhandle
        Debug	autohg, "Hourglass_Off at Wimp_Poll entry: taskhandle, old status =", handle, R1
        Pull	"handle"
      ]
        TEQ     R1, #2                  ; is hourglass still pending or active?
        MOVEQ   R1, #1                  ; yes, so turn off hourglass (but keep on vector for speed reasons)
        STREQ   R1, hourglass_status
        SWIEQ   XHourglass_Off
        CLRV                            ; ignore errors
      ]

Neil Turton's avatar
Neil Turton committed
359 360 361 362 363 364 365 366 367 368 369
        LDR     R1,taskhandle
        LDR     R4,[wsptr,R1]           ; R4 = task data pointer
        TST     R4,#task_unused         ; if task not used, it's been deleted
        BNE     lookfornewtask

        LDR     R5,[R4,#task_flagword]  ; R5 = flag word
        LDR     R14,singletaskhandle
        TEQ     R1,R14                  ; if single-tasking
        LDREQ   R14,=masknewcodes
        ORREQ   R0,R0,R14               ; disallow new reason codes

Ben Avison's avatar
Ben Avison committed
370
; set up R3 -> poll word, with bottom bit set => urgent
Neil Turton's avatar
Neil Turton committed
371 372 373 374
; also validate R0,R3 (but only if task knows about Wimp 2.23)

        LDR     R14,[R4,#task_wimpver]
        CMP     R14,#223
Ben Avison's avatar
Ben Avison committed
375 376 377
        MOVLO   R3,#0                   ; R3=0 => no poll word
        BLLO    killfpblock             ; get rid of this!
        BLO     %FT01
Neil Turton's avatar
Neil Turton committed
378 379 380 381 382 383 384 385 386 387

; this stuff only applies to tasks that know about Wimp 2.23 or later
; bits 22,23 => poll word, bit 24 => save/restore FP registers

        TST     R0,#pollword_bit        ; if this event is disabled,
        BICNE   R0,R0,#flag_pollword    ; then there's no point polling!

        TST     R0,#flag_pollword       ; no poll word if this bit unset
        MOVEQ   R3,#0

Ben Avison's avatar
Ben Avison committed
388
        TST     R3,#3                   ; check that address is word-aligned
Neil Turton's avatar
Neil Turton committed
389
        BNE     err_badR3
Ben Avison's avatar
Ben Avison committed
390
        CMP     R3,#ApplicationStart    ; and not in application space
Neil Turton's avatar
Neil Turton committed
391 392

        [ Medusa
Ben Avison's avatar
Ben Avison committed
393 394
        LDRHS   R14,orig_applicationspacesize
        CMPHS   R14,R3
Neil Turton's avatar
Neil Turton committed
395
        |
396
        RSBHSS  R14,R3,#&1000000        ; APPSPACE
Neil Turton's avatar
Neil Turton committed
397
        ]
Ben Avison's avatar
Ben Avison committed
398
        BHS     err_badR3
Neil Turton's avatar
Neil Turton committed
399

400
	CLRV				; make sure we don't leave V set
Ben Avison's avatar
Ben Avison committed
401 402 403
        TST     R0,#flag_pollword
        TSTNE   R0,#flag_pollfast       ; bottom bit set => poll quickly
        ORRNE   R3,R3,#1
Neil Turton's avatar
Neil Turton committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422

        MOV     R14,R0,LSR #flag_versionbit   ; object if others set
        BICS    R14,R14,#flag_allowed :SHR: flag_versionbit
        BNE     err_badR0                       ; error from Wimp_Poll !!!

; does the task want to save the FP registers?

        TST     R0,#flag_fpsave
        BLEQ    killfpblock                     ; preserves flags
        BLNE    saveFPregs
        BVS     ExitWimp

; save toned-down flag word in task workspace

01
        STR     R3,[R4,#task_pollword]

        LDR     R14,[R4,#task_priority]
        TST     R0,#flag_pollword
Kevin Bracey's avatar
Kevin Bracey committed
423
        TEQNE   R3,#0
Neil Turton's avatar
Neil Turton committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
        ORRNE   R14,R14,#priority_pollword      ; Has a poll word ?
        BICEQ   R14,R14,#priority_pollword

      [ debugpoll
        BEQ     %FT00
        Debug   poll,"New poll task: handle, posn",R1,#PollTaskPtr
00
      ]

        LDRNE   R3,PollTaskPtr
        STRNE   R1,[R3],#4                      ; Add task handle to list of polled tasks
        STRNE   R3,PollTaskPtr

        TST     R0,#flag_pollidle
        ORRNE   R14,R14,#priority_idle          ; Poll_idle ?
        BICNE   R14,R14,#priority_null
        BICEQ   R14,R14,#priority_idle
        BNE     %FT01

        TST     R0,#null_bit
        ORREQ   R14,R14,#priority_null          ; Wants Null events ?
        BICNE   R14,R14,#priority_null
01
        STR     R14,[R4,#task_priority]

        MOV     R0,R0,LSL #32-flag_versionbit   ; clear version bits
        MOV     R0,R0,LSR #32-flag_versionbit
        MOV     R5,R5,LSR #flag_versionbit      ; so we can retain the old ones
        ORR     R0,R0,R5,LSL #flag_versionbit
        STR     R0,[R4,#task_flagword]          ; remember original flags
        STR     R0,flagword
        STR     userblk,[R4,#task_registers+4*1]        ; and user R1
        STR     R2,[R4,#task_registers+4*2]             ; and target time
;
458
; save VFP context, lazily if possible
459 460
;
        MOV     R0,#0
461
        MOV     R1,#VFPSupport_ChangeContext_Lazy+VFPSupport_ChangeContext_AppSpace
462 463
        SWI     XVFPSupport_ChangeContext
        MOVVS   R0,#0 ; Ignore error (probably means VFPSupport isn't loaded)
464
        Debug   fp,"VFP on Wimp_Poll entry",R0
465 466 467
        STR     R0,[R4,#task_vfpcontext]
        CLRV
;
Neil Turton's avatar
Neil Turton committed
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
; check to see if there are any more outstanding parents
;
taskisused
        LDR     R14,taskSP
        ADR     R1,taskstack
        TEQ     R14,R1
        BEQ     %FT01

        LDR     R1,[R14,#-4]!           ; empty ascending stack
        STR     R14,taskSP

        LDR     R0,polltaskhandle       ; R0 = child's task handle
        LDR     R14,[wsptr,R0]          ; R14 = task block pointer
        TST     R14,#task_unused
        MOVNE   R0,#0                   ; R0=0 => child is already dead
        LDREQ   R14,[R14,#task_flagword]
        MOVEQ   R14,R14,LSR #flag_versionbit
        ORREQ   R0,R0,R14,LSL #flag_versionbit

        Task    R1,,"Parent"            ; make sure correct page swaps happen
        LDR     R14,[wsptr,R1]
        TST     R14,#task_unused        ; parent might be dead!
        BNE     lookfornewtask

        B       ExitPoll_toparent       ; exit back to parent task
01

;
; if menus marked for deletion, kill them off!
;
        LDR     R0,menus_temporary      ; -4 ==> kill menus
        TEQ     R0,#0
        STRNE   R0,menutaskhandle       ; NE ==> R0 = -4
        MOVNE   R14,#0
        STRNE   R14,menus_temporary
        BLNE    closemenus
;
; ensure that escape condition generation is disabled on entry
;
      [ debugescape
        LDR     R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
509 510
        CMP     R14,#nullptr            ; old Wimp didn't set up escape!
        BNE     %FT02
Neil Turton's avatar
Neil Turton committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
;
        Push    "R0-R2"

        MOV     R0,#229                 ; *FX 229,1 (escape ==> ascii 27)
        MOV     R1,#1
        MOV     R2,#0
        SWI     XOS_Byte
        TEQ     R1,#0                   ; was escape already disabled?
        TOGPSR  Z_bit, R14              ; NE => escape enabled
        MOVEQ   R0,#126
        SWIEQ   XOS_Byte
        TEQEQ   R1,#0                   ; or was there an escape condition?

        Pull    "R0-R2"
        BEQ     %FT02
        MyXError  WimpBadEscapeState
        B       ExitPoll                ; Wimp reports errors itself
        MakeErrorBlock WimpBadEscapeState
02
      ]
;
; re-entry point from within polling routines
;
repollwimp
535
        Debug   poll2, "repollwimp"
536
        BL      powersave_tick
Neil Turton's avatar
Neil Turton committed
537 538 539 540
        LDR     R14,taskhandle          ; get userblk back (may be corrupted)
        LDR     R14,[wsptr,R14]
        LDR     userblk,[R14,#task_registers+4*1]
;
541 542 543 544
        MOV     R0,#1
        BL      scanpollwords           ; scan high-priority tasks
        BNE     ExitPoll

Neil Turton's avatar
Neil Turton committed
545
        LDR     R2,headpointer          ; are there any outstanding messages?
Ben Avison's avatar
Ben Avison committed
546 547
        CMP     R2,#nullptr
        BNE     returnmessage
548 549 550 551 552 553
;
      [ MultiClose
        LDR     R2, nextwindowtoiconise
        TEQ     R2, #0
        BLNE    iconisenextwindow
        LDR     R2, headpointer         ; are there any outstanding messages now?
Ben Avison's avatar
Ben Avison committed
554 555
        CMP     R2, #nullptr
        BNE     returnmessage
556
      ]
Neil Turton's avatar
Neil Turton committed
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 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
;
        MOV     R14,#0
        STR     R14,sender              ; all Wimp messages from now on
        STR     R14,hotkeyptr           ; reset this if no more messages
;
; check for a recent mode change - if so, deliver Open_Window_Requests
;
        LDRB    R14,modechanged
        TEQ     R14,#0
        BEQ     nomodechange
        MOV     R14,#0
        STRB    R14,modechanged

; copy scrx1,y1 into lastmode_x1,y1 for next time

        LDR     R14,scrx1
        STR     R14,lastmode_x1
        LDR     R14,scry1
        STR     R14,lastmode_y1

; send Message_ModeChange first

        MOV     R14,#ms_data            ; size of block
        STR     R14,[sp,#-ms_data]!
        MOVVC   R0,#User_Message
        MOV     R1,sp
        MOV     R2,#0
        STRVC   R2,[R1,#ms_yourref]
        LDR     R14,=Message_ModeChange
        STRVC   R14,[R1,#ms_action]
        BLVC    int_sendmessage_fromwimp
        ADD     sp,sp,#ms_data          ; correct stack
;
        Debug   task1,"Mode change message sent"

; first make a copy of the window stack, so that changes in the order are OK
; Enumerate the window stack from back to front

        LDR     R5,activewinds+lh_backwards
01
        LDR     R4,[R5,#ll_backwards]
        CMP     R4,#nullptr
        BEQ     repollwimp
        SUB     handle,R5,#w_active_link
        MOV     R5,R4
;
        Debug   ms,"Mode Change: re-opening window handle",R0,handle
;
        LDR     R14,[handle,#w_flags]
        TST     R14,#wf_isapane         ; don't re-open panes
        BNE     %BT01
;
        Push    "R4,R5,userblk"

        LDR     R14,[handle,#w_flags]   ; ensure window is put on-screen

        LDR     R4,forceflags           ; 0 or ws_onscreenonce
        ORR     R14,R14,R4              ; R4 = 0 or ws_onscreenonce
        STR     R14,[handle,#w_flags]

        ADD     R14,handle,#w_wax0
        LDMIA   R14,{cx0,cy0,cx1,cy1,x0,y0}
        Rel     R14,handle              ; bhandle (open at same height)
        MOV     R0,R14

        Push    "R0,cx0,cy0,cx1,cy1,x0,y0,R14"
        MOV     R1,sp

        LDR     R2,[handle,#w_taskhandle]
        CMP     R2,#0                   ; if system window, open automatically
        BGT     %FT11

; Skip backwindow and iconbarwindow

Neil Turton's avatar
Neil Turton committed
631 632 633
      [ true
        B       %FT22
      |
Neil Turton's avatar
Neil Turton committed
634 635 636 637 638
        LDR     R14,backwindowhandle    ; if back window, open at full size
        TEQ     R0,R14
        LDRNE   R14,iconbarhandle
        TEQNE   R0,R14
        BEQ     %FT22                   ; ignore these (already done first)
Neil Turton's avatar
Neil Turton committed
639
      ]
Neil Turton's avatar
Neil Turton committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
11
        Rel     R2,handle               ; must send the handle, so that
        MOV     R0,#Open_Window_Request ; the message is lost if window deleted
        Debug   mode,"Sending open request to",R2
        BL      int_sendmessage_fromwimp
22
        ADD     sp,sp,#u_ow1            ; correct stack (& ignore errors)
        Pull    "R4,R5,userblk"
        B       %BT01

nomodechange
      [ redrawlast
        B       lookatpointer

check_redraw
      ]
Neil Turton's avatar
Neil Turton committed
656 657 658 659 660 661
;
; flush pending opens - make sure this is done BEFORE redraw stuff
;
      [ ChildWindows
        BL      int_flush_opens         ; may cause a braindead panic redraw
      ]
Neil Turton's avatar
Neil Turton committed
662 663 664 665
;
; look at invalid list to see if a redraw is necessary
;
        BL      checkredrawhandle
Neil Turton's avatar
Neil Turton committed
666
      [ :LNOT: ChildWindows             ; this is pointless - can't get an error from checkredrawhandle!
Neil Turton's avatar
Neil Turton committed
667
        BVS     ExitPoll                ; <<<< wot?
Neil Turton's avatar
Neil Turton committed
668
      ]
Neil Turton's avatar
Neil Turton committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
;
; Improved handling of rectangle area full:
; Redraw whole screen intelligently first, then, if that fails, draw
; all the windows from the back to the front (braindead isn't it!)

        LDR     R1,BPR_indication
        TEQ     R1,#BPR_panicnow
        BEQ     start_braindead_panic_redraw
        CMP     R1,#BPR_continuelevel
        BHS     continue_braindead_panic_redraw
        CMP     R1,#BPR_gotfullarea
        BLEQ    BPR_startintelligentredraw
;
        LDR     R1,rlinks+invalidrects
        CMP     R1,#nullptr

; Downgrade to no panic

        MOVEQ   R1,#BPR_notatall
        STREQ   R1,BPR_indication
      [ redrawlast
        BEQ     check_null
      |
        BEQ     lookatpointer           ; screen is all valid!
      ]
;
        LDR     R1,activewinds+lh_forwards
Neil Turton's avatar
Neil Turton committed
696

Neil Turton's avatar
Neil Turton committed
697 698 699 700
pollredrawlp
        LDR     R2,[R1,#ll_forwards]
        CMP     R2,#nullptr
        BEQ     clearrects
Neil Turton's avatar
Neil Turton committed
701

Neil Turton's avatar
Neil Turton committed
702 703
        SUB     handle,R1,#w_active_link

Neil Turton's avatar
Neil Turton committed
704
        Push    "R2"
Neil Turton's avatar
Neil Turton committed
705 706
        BL      invalidouterportion
        Pull    "R1"
Neil Turton's avatar
Neil Turton committed
707

Neil Turton's avatar
Neil Turton committed
708 709 710 711
        LDR     R2,rlinks+windowrects
        CMP     R2,#nullptr
        BEQ     pollredrawlp

Neil Turton's avatar
Neil Turton committed
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
;
; Right - windowrects is the intersection of this window's outer portion with the invalid list
; We need to check whether any of the window's children should be redrawn first
;

process_redrawable_window ROUT

        Debug   child,"process_redrawable_window",handle

      [ ChildWindows
        LDR     R2,[handle,#w_children + lh_forwards]           ; start from the top

01      LDR     R14,[R2,#ll_forwards]
        CMP     R14,#nullptr
        BEQ     %FT04

        Push    "R2"

        LDR     R14,[R2,#w_flags - w_active_link]
        TST     R14,#wf_inborder
        ADDNE   R14,handle,#w_x0                ; clip to outer box if it can go in the border
        ADDEQ   R14,handle,#w_wax0              ; clip to work area otherwise
        LDMIA   R14,{x0,y0,x1,y1}

        ADD     R14,R2,#w_x0 - w_active_link
        LDMIA   R14,{cx0,cy0,cx1,cy1}

        max     cx0,x0                          ; intersect child's outer box with parent's work area or outline
        max     cy0,y0
        min     cx1,x1
        min     cy1,y1

        Debug   child,"process_redrawable: child rectangle",cx0,cy0,cx1,cy1
        MOV     R0,#windowrects
        MOV     R1,#torects
        BL      intrect                         ; see if this intersects with the invalid list

        Pull    "R2"

        LDR     R14,rlinks+torects
        CMP     R14,#nullptr
        BNE     %FT03
Neil Turton's avatar
Neil Turton committed
754

Neil Turton's avatar
Neil Turton committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
02      LDR     R2,[R2,#ll_forwards]
        B       %BT01

; Right - redraw the child first, rather than the parent

03      MOV     R0,#windowrects
        BL      assign_set                      ; calls SetRectPtrs internally
        SUB     handle,R2,#w_active_link
      [ debug
        LDR     R14,rlinks + windowrects
        Debug   child,"Detected redraw for child window,rects",handle,R14
      ]
        B       process_redrawable_window       ; in case of nested child windows
04

process_redrawable_window_actually ROUT

        Debug   child,"Actually redraw window",handle
      ]
Neil Turton's avatar
Neil Turton committed
774 775 776 777
;
; check for auto-redraw bit in window flags
;
        LDR     R14,[handle,#w_flags]
Neil Turton's avatar
Neil Turton committed
778
        Debug   child,"window flags are",R14
Neil Turton's avatar
Neil Turton committed
779 780 781 782 783 784 785
        TST     R14,#wf_autoredraw
        BEQ     tryreturnit
;
        BL      int_redraw_window
redrlp  BVS     ExitPoll                        ; <<<< wot?
        TEQ     R0,#0
        BEQ     repollwimp
Neil Turton's avatar
Neil Turton committed
786 787 788 789 790 791
 [ Twitter
        BL      checktwitter
        LDRNE   r14, getrectflags
        ORRNE   r14, r14, #getrect_twitter
        STRNE   r14, getrectflags
 ]
Neil Turton's avatar
Neil Turton committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
        BL      int_get_rectangle               ; will draw the user icons
        B       redrlp
;
; check that task did not disable Redraw_Window_Request
;
tryreturnit
        LDR     R14,[handle,#w_taskhandle]
        Task    R14,,"RedrawRq"         ; can't be a menu (auto-redraw)
        TST     R14,#redraw_bit
      [ redrawlast
        BNE     check_null
      |
        BNE     lookatpointer           ; CAN'T CARRY ON (doesn't work!)
      ]
;
; return Redraw_Window_Request (and remember the handle we want back!)
;
        Rel     R14,handle
        STR     R14,[userblk]
        STR     R14,redrawhandle
Neil Turton's avatar
Neil Turton committed
812 813 814 815
      [ debug
        LDR     R14,rlinks + windowrects
        Debug   child,"Returning Redraw_Window_Request for window,rects",#redrawhandle,R14
      ]
Neil Turton's avatar
Neil Turton committed
816 817 818
        MOV     R0,#Redraw_Window_Request
        B       ExitPoll

819 820 821 822 823 824 825 826 827 828 829 830 831
powersave_tick
        Entry   "r0"
        LDR     R14,IdlePerSec          ; update the idle information for the portable modules
        ADD     R14,R14,#1
        STR     R14,IdlePerSec
 [ Stork
        LDR     R14, WimpPortableFlags
        TST     R14, #PowerSave                 ; if power saving
        TSTNE   R14, #PortableFeature_Idle      ; and Portable_Idle works
        SWINE   XPortable_Idle                  ; then go dormant until next interrupt or centi-second tick
 ]
        EXIT

Neil Turton's avatar
Neil Turton committed
832 833 834 835 836 837 838 839 840 841 842
        LTORG

;
; clearrects - no more windows left, so clear the rest out
;
clearrects
        BL      defaultwindow
        LDR     R0,scrx0
        LDR     R1,scry1
        SUB     R1,R1,#1                ; default is top-left of screen
        SWI     XOS_SetECFOrigin
Kevin Bracey's avatar
Kevin Bracey committed
843
        MOV     R0,#4
Neil Turton's avatar
Neil Turton committed
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
        BL      background
;
        Push    "userblk"
        SetRectPtrs
;
        MOV     R1,#invalidrects
        B       endclearrects
clearrectslp
        getxy   R1,x,y
        BL      graphicswindow
        [ windowsprite
        Push    "R0"
        LDRB    R0,[handle,#w_wbcol]

        BL      plotspritebackground
        Pull    "R0"
        |
        SWI     XOS_WriteI+16
        ]
863 864 865 866 867 868 869 870
      [ Autoscr
        LDR     R14, dragflags
        TST     R14, #dragf_clip ; clipped dragboxes must only be redrawn within their own window
        LDRNE   R14, draghandle
        Abs     R14, R14, NE
        TEQNE   R14, handle
        BLEQ    forcedrag_on            ; put drag rectangle back if nec.
      |
Neil Turton's avatar
Neil Turton committed
871
        BL      forcedrag_on            ; put drag rectangle back if nec.
872
      ]
Neil Turton's avatar
Neil Turton committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
endclearrects
        LDR     R1,[rectlinks,R1]
        CMP     R1,#nullptr
        BNE     clearrectslp
;
        MOV     R0,#invalidrects
        BL      loserects
        BL      defaultwindow
;
        Pull    "userblk"
        B       repollwimp              ; try again!

start_braindead_panic_redraw
        Debug   bpr,"Starting braindead panic redraw"

; Clear screen to background

        BL      defaultwindow
        LDR     R0,scrx0
        LDR     R1,scry1
        SUB     R1,R1,#1                ; default is top-left of screen
        SWI     XOS_SetECFOrigin
Kevin Bracey's avatar
Kevin Bracey committed
895
        MOV     R0,#4
Neil Turton's avatar
Neil Turton committed
896
        BL      background
897
        SWI     XOS_WriteI+16           ; CLG
Neil Turton's avatar
Neil Turton committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917

; Find the backmost window and store in BPR_indication -
; BPR_notatall is used to indicate no windows

        LDR     R14,activewinds+lh_backwards
        LDR     R0,[R14,#ll_backwards]
        CMP     R0,#nullptr
        MOVEQ   R14,#BPR_notatall
        SUBNE   R14,R14,#w_active_link
        Rel     R14,R14,NE
        STR     R14,BPR_indication

continue_braindead_panic_redraw

; Run out of windows? - done with redrawing

        LDR     handle,BPR_indication
        TEQ     handle,#BPR_notatall
        BEQ     repollwimp

Neil Turton's avatar
Neil Turton committed
918
        Debug   bpr,"Continuing braindead panic redraw on handle",handle
Neil Turton's avatar
Neil Turton committed
919 920 921 922 923 924 925 926 927

; Window gone? - start from the start again

        BL      checkhandle
        BVS     start_braindead_panic_redraw

; Window closed? - start from the start again

        LDR     R14,[handle,#w_flags]
Neil Turton's avatar
Neil Turton committed
928
        Debug   bpr,"handle, flags are",handle,R14
Neil Turton's avatar
Neil Turton committed
929 930 931
        TST     R14,#ws_open
        BEQ     start_braindead_panic_redraw

Neil Turton's avatar
Neil Turton committed
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
; Move BPR_indication to next window in stack (must deal with child window stacks as well)

      [ ChildWindows
        Push    "handle"

        LDR     R0,[handle,#w_children + lh_backwards]          ; go for backmost child window first
        LDR     R14,[R0,#ll_backwards]
        CMP     R14,#nullptr
        BNE     %FT02

01      LDR     R0,[handle,#w_active_link + ll_backwards]       ; then go for next sibling
        Debug   bpr,"Next sibling",handle,R0
        LDR     R14,[R0,#ll_backwards]
        CMP     R14,#nullptr
        BNE     %FT02

        LDR     handle,[handle,#w_parent]                       ; else go for parent's next sibling, etc.
        Debug   bpr,"Move up to parent",handle
        CMP     handle,#nullptr
        BNE     %BT01

02      MOVEQ   R0,#BPR_notatall
        SUBNE   R0,R0,#w_active_link
        Rel     R0,R0,NE
        STR     R0,BPR_indication
Neil Turton's avatar
Neil Turton committed
957

Neil Turton's avatar
Neil Turton committed
958 959 960 961
        Pull    "handle"

        Debug   bpr,"Braindead redraw: this,next",handle,R0
      |
Neil Turton's avatar
Neil Turton committed
962 963 964 965 966 967 968
        LDR     R0,[handle,#w_active_link+ll_backwards]
        LDR     R14,[R0,#ll_backwards]
        CMP     R14,#nullptr
        MOVEQ   R0,#BPR_notatall
        SUBNE   R0,R0,#w_active_link
        Rel     R0,R0,NE
        STR     R0,BPR_indication
Neil Turton's avatar
Neil Turton committed
969
      ]
Neil Turton's avatar
Neil Turton committed
970 971 972 973 974 975

; Process this window (exactly)

        BL      initrectptrs
        ADD     R0,handle,#w_x0
        LDMIA   R0,{cx0,cy0,cx1,cy1}
Neil Turton's avatar
Neil Turton committed
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999

; If this is a child window, clip to parent's work area/outline

      [ ChildWindows
        MOV     R1,handle
        B       %FT12

11      TST     R0,#wf_inborder
        ADDNE   R14,R1,#w_x0            ; clip to outer box if allowed to overlap border
        ADDEQ   R14,R1,#w_wax0          ; clip to parent's work area otherwise
        LDMIA   R14,{x0,y0,x1,y1}
        max     cx0,x0
        max     cy0,y0
        min     cx1,x1
        min     cy1,y1

12      LDR     R0,[R1,#w_flags]
        LDR     R1,[R1,#w_parent]
        CMP     R1,#nullptr
        BNE     %BT11
      ]

; make one-rectangle list of the window's outer box (clipped to its parent's work area)

Neil Turton's avatar
Neil Turton committed
1000 1001 1002 1003 1004 1005
        MOV     R0,#windowrects
        MOV     R1,R0
        BL      addrect
        LDR     R14,rlinks+windowrects
        CMP     R14,#nullptr
        BEQ     continue_braindead_panic_redraw
Neil Turton's avatar
Neil Turton committed
1006 1007 1008
      [ ChildWindows
        B       process_redrawable_window_actually      ; DON'T consider the children this time
      |
Neil Turton's avatar
Neil Turton committed
1009
        B       process_redrawable_window
Neil Turton's avatar
Neil Turton committed
1010
      ]
Neil Turton's avatar
Neil Turton committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024


;;----------------------------------------------------------------------------
;; Just before looking at the mouse, check all poll words
;;----------------------------------------------------------------------------

lookatpointer
        MOV     R0,#-1
        BL      scanpollwords           ; scan all tasks with pollwords
        BNE     ExitPoll
;
; Has the ticker gone off to see if we need to look at the
; mouse co-ordinates, have they changed yet?!
;
Kevin Bracey's avatar
Kevin Bracey committed
1025
      [ mousecache
Neil Turton's avatar
Neil Turton committed
1026 1027 1028 1029 1030 1031 1032
        LDRB    R0,recacheposn
        TEQ     R0,#0                   ; do we recache the information?
        BEQ     trykeys                 ; no, so ignore
      ]
;
; now see what user input has occurred
;
1033
        Debug   poll2, "Processing mouse"
Neil Turton's avatar
Neil Turton committed
1034
        BL      getmouseposn            ; ie. MOUSE R0,R1,R2
Kevin Bracey's avatar
Kevin Bracey committed
1035 1036 1037 1038

      [ PoppingIconBar
	BL	checkiconbarpop
      ]
1039 1040 1041 1042 1043 1044 1045

      [ CnP
        ; autoscroll an icon?
        LDR     R14,cnp_iconautoscr_state
        TST     R14,#cnp_af_enabled
        BLNE    poll_iconautoscroll
      ]
Neil Turton's avatar
Neil Turton committed
1046 1047 1048 1049 1050 1051
;
; are we dragging a box?
;
        LDR     R14,dragtype
        TEQ     R14,#0
        BEQ     notdragging
1052 1053 1054 1055 1056
      [ CnP
        TEQ     R14,#drag_icon_selection
        BEQ     dragging_iconselection
      ]

Neil Turton's avatar
Neil Turton committed
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
;
; update coords (depends on drag type) and do bound checking
;
        Push    "R0-R2"                 ; mouse x,y coords and buttons

        LDR     R14,dragoldx
        STR     R0,dragoldx
        SUB     R0,R0,R14               ; x-offset this time
        LDR     R14,dragoldy
        STR     R1,dragoldy
        SUB     R1,R1,R14

        ADR     R14,dragx0
        LDMIA   R14,{x0,y0,x1,y1}
        LDR     R14,dragtype
        TEQ     R14,#drag_size          ; do we move both coords?
        TEQNE   R14,#drag_user2         ; user rubber-box
        TEQNE   R14,#drag_subr_size     ; user-supplied subroutine, rubber box
        TEQNE   R14,#drag_subr_size2    ; user-supplied subroutine, rubber box
        ADDNE   x0,x0,R0
        ADDNE   y1,y1,R1
        ADD     x1,x1,R0
        ADD     y0,y0,R1
;
; if drag types 10 or 11, or still holding button down, update box and continue
;
        TEQ     R14,#drag_subr_posn2
        TEQNE   R14,#drag_subr_size2
        TOGPSR  Z_bit,R14               ; NE ==> it is one of these
        TSTEQ   R2,#button_left:OR:button_middle:OR:button_right
        BLEQ    nodrag
        BLNE    yesdrag                 ; updates dragx0,y0,x1,y1
        Pull    "R0-R2"
        BEQ     boxdropped
;
; check sysflags to see if continuous dragging occurs
;
        LDR     R14,dragtype
Kevin Bracey's avatar
Kevin Bracey committed
1095
        TEQ     R14,#drag_scrollboth    ; use vscroll bit of sysflags for this
Neil Turton's avatar
Neil Turton committed
1096 1097
        MOVEQ   R14,#drag_vscroll
        CMP     R14,#drag_user
Ben Avison's avatar
Ben Avison committed
1098
        BHS     notdragging             ; only system drags are elegible
Neil Turton's avatar
Neil Turton committed
1099 1100 1101 1102 1103 1104 1105 1106 1107

        Push    "R0"
        LDRB    R0,sysflags             ; drag bits are 0..3
        MOVS    R0,R0,LSR R14
        Pull    "R0"
        BCC     notdragging             ; R0,R1 = mouse coords here

        LDR     R1,dragtype             ; R14 may not = dragtype
        B       returndrag
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 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287

      [ CnP
dragging_iconselection
; continue dragging selection
        TST     R2,#button_left:OR:button_middle:OR:button_right
        BEQ     %FT91                   ; all done, terminate the drag

        ; get current string index from mouse coords
        MOV     R2,R0
        MOV     R3,R1
        LDR     R0,caretdata+caretwindow
        LDR     R1,caretdata+careticon
        Abs     handle,R0

        ; page in task as we need access to the icon data
        LDR     R14,taskhandle
        Push    "R14"
        LDR     R14,[handle,#w_taskhandle]
        Task    R14,,"dragging_iconselection"

        ; adjust coords to be relative
        LDR     R4,[handle,#w_scx]
        ADD     R2,R2,R4
        LDR     R4,[handle,#w_wax0]
        SUB     R2,R2,R4

        LDR     R4,[handle,#w_scy]
        ADD     R3,R3,R4
        LDR     R4,[handle,#w_way1]
        SUB     R3,R3,R4
        BL      findclickindex

        ; what do we need to do?
        LDRB    R14,cnp_pending_dragtype

        CMP     R14,#cnp_drag_limit
        ADDLE   PC,PC,R14,LSL #2
        B       %FT80                   ; invalid type, cancel the drag
        B       %FT80                   ; we shouldn't have a type 0
        B       %FT20                   ; create_charselection
        B       %FT30                   ; create_wordselection
        B       %FT80                   ; drag and drop not done through type 13 dragbox
        B       %FT40                   ; adjust_high
        B       %FT50                   ; adjust_low
20
; doing a character selection
; select between caret and new index (R5)

        LDR     R2,[handle,#w_seldata+wselxoverride]  ; get scroll offset

        ; it was set up when iconautoscroll was started
21
        MOV     R3,#0
        MOV     R4,#crf_selection :OR: crf_nocentre
        LDR     R7,caretdata+caretindex

        ; determine order - ensure we are low to high
        CMP     R5,R7
        MOVLT   R6,R7
        MOVGE   R6,R5
        MOVGE   R5,R7

        BL      int_set_caret_position
        B       %FT90
30
        ; doing a word selection
        ; need to select up (or down) to the caret position
        ; we then extend the selection to the next word boundary in whichever
        ; direction

        LDR     R2,[handle,#w_seldata+wselxoverride]  ; current scroll offset
        MOV     R3,#0
        MOV     R4,#crf_selection :OR: crf_nocentre
        ; R5 is mouse index
        Push    "R0,R2"

        ; get icon data pointer
        LDR     R0,[handle,#w_icons]
        ADD     R0,R0,R1,LSL #i_shift
        LDR     R14,[R0,#i_flags]
        TST     R14,#if_indirected
        ADDEQ   R2,R0,#i_data
        LDRNE   R2,[R0,#i_data]
        LDR     R7,caretdata+caretindex         ; current caret position

        CMP     R5,R7
        BLT     %FT35                   ; select to the left
        BGT     %FT38                   ; select to the right
        ; we're at the caret position
        ; issue a zero-width request for now
        BL      skipwordR
        MOV     R6,R5
        MOV     R5,R7
        BL      skipwordL
        Pull    "R0,R2"
        BL      int_set_caret_position
        B       %FT90
35
        ; select word(s) to the left
        BL      skipwordL
        Push    "R5"
        MOV     R5,R7
        BL      skipwordR
        MOV     R6,R5
        Pull    "R5"
        Pull    "R0,R2"
        BL      int_set_caret_position
        B       %FT90
38
        ; select word(s) to the right
        BL      skipwordR
        MOV     R6,R5
        MOV     R5,R7
        BL      skipwordL
        Pull    "R0,R2"
        BL      int_set_caret_position
        B       %FT90
50
        ; dragging adjust selection for low bound

        ; have we swapped over to the high bound now?
        LDR     R6,[handle,#w_seldata+wselhighindex]
        CMP     R5,R6
        MOVGT   R14,R6
        MOVGT   R6,R5
        MOVGT   R5,R14                  ; swap over indices
        MOVGT   R14,#cnp_drag_adjust_high
        STRGTB  R14,cnp_pending_dragtype ; change the drag type

        LDR     R2,[handle,#w_seldata+wselxoverride]  ; we want to keep the offset unchanged
        MOV     R3,#0
        MOV     R4,#crf_selection :OR: crf_nocentre
        BL      int_set_caret_position
        B       %FT90
40
        ; dragging adjust selection for high bound
        ; have we swapped over to the low bound?
        LDR     R14,[handle,#w_seldata+wsellowindex]
        CMP     R14,R5
        MOVLE   R6,R5
        MOVLE   R5,R14                  ; no, so set up regs for setcaretposition call
        MOVGT   R6,R14                  ; yes, so we need to change the drag type as well
        MOVGT   R14,#cnp_drag_adjust_low
        STRGTB  R14,cnp_pending_dragtype

        LDR     R2,[handle,#w_seldata+wselxoverride]  ; we want to keep the offset unchanged
        MOV     R3,#0
        MOV     R4,#crf_selection :OR: crf_nocentre
        BL      int_set_caret_position
        B       %FT90
80
        ; finished dragging selection
        ; just tidy up, nothing to report to clients
        MOV     R14,#0
        STR     R14,dragtype
        MOV     R14,#bignum
        STR     R14,[handle,#w_seldata+wselxoverride] ; no scroll override now

        BL      clearpointerwindow
        BL      iconautoscroll_stop
90
        Pull    "R14"
        Task    R14,,"dragging_iconselection 90"
        B       repollwimp
91
        ; exit, no task to reset
        LDR     R0,caretdata+caretwindow
        Abs     handle,R0

        MOV     R14,#0
        STR     R14,dragtype
        MOV     R14,#bignum
        STR     R14,[handle,#w_seldata+wselxoverride] ; no scroll override now

        BL      clearpointerwindow
        BL      iconautoscroll_stop

        MOV     R0,#0                   ; null event
        B       ExitPoll
      ]
Neil Turton's avatar
Neil Turton committed
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
;
; box has been dropped
; cancel drag box, then return appropriate reason code
;
boxdropped
        Push    "x0,y0,x1,y1"
        BL      clearpointerwindow      ; corrupts x0,y0,x1,y1
        Pull    "x0,y0,x1,y1"
;
        LDR     R1,dragtype
        TEQ     R1,#drag_scrollboth
        BLEQ    pointeron

        MOV     R0,#0                           ; cancel drag operation
        STR     R0,dragtype                     ; >>> leave [draghandle] alone!
        LDR     R0,mouseflags                   ; (for compatibility)
        BIC     R0,R0,#mf_oldcoords
        STR     R0,mouseflags
;
; come here for continuous dragging as well
; R1 = drag type ([dragtype] may already be 0)
;
returndrag
        ADR     R14,dragoffx0                   ; compute box coords
        LDMIA   R14,{cx0,cy0,cx1,cy1}
        ADD     cx0,x0,cx0
        ADD     cy0,y0,cy0
        ADD     cx1,x1,cx1
        ADD     cy1,y1,cy1
        LDR     R14,dragtask                    ; originator of drag
        TEQ     R14,#0                          ; if menu,
        ADREQL  userblk,tempiconblk             ; set up dummy userblk
        Task    R14,NE,"Drag"                   ; else point to user's block

        CMP     R1,#drag_scrollboth
        CMPNE   R1,#drag_user-1
Ben Avison's avatar
Ben Avison committed
1324 1325 1326
        STMHIIA userblk,{cx0,cy0,cx1,cy1}       ; final box coords
        MOVHI   R0,#User_Dragbox
        BHI     ExitPoll                        ; return User_DragBox
Neil Turton's avatar
Neil Turton committed
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
;
; return Open_Window_Request to the application
; R1 = drag type
; [dragtype] = 0 (drag has terminated) - unless continuous dragging
;
        TEQ     R1,#drag_posn
        TEQNE   R1,#drag_size
        BEQ     gonewposnsize
;
        LDR     handle,draghandle
        STR     handle,[userblk]
        BL      checkhandle                     ; might have been deleted?
        BLVS    nodragging                      ; stop it looping
        BVS     notdragging
;
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{x0,y0,x1,y1}
        ADD     R14,userblk,#4
        STMIA   R14!,{x0,y0,x1,y1}
;
; scroll bar was dragged - now work out new scroll bar positions
;
        TEQ     R1,#drag_hscroll
        TEQNE   R1,#drag_scrollboth
        LDRNE   x0,[handle,#w_scx]
        BLEQ    getnewscx                       ; get x0 from cx0,cx1 etc.
;
        TEQ     R1,#drag_vscroll
        TEQNE   R1,#drag_scrollboth
        LDRNE   y0,[handle,#w_scy]
        BLEQ    getnewscy                       ; get y0 from cy0,cy1 etc.
;
        Push    "x0,y0"
        BL      calc_w_status
        Pull    "x0,y0"
        LDR     x1,[handle,#w_bhandle]          ; open at same place in stack
        ADD     R14,userblk,#u_scx
        STMIA   R14,{x0,y0,x1}
;
        B       Exit_OpenWindow

gonewposnsize
        LDR     handle,draghandle               ; handle of window to open
        STR     handle,[userblk,#u_handle]
        BL      checkhandle                     ; window deleted?
        BLVS    nodragging
        BVS     notdragging     ; CLRV
;
        TEQ     R1,#drag_size                   ; R1 = drag type
        BNE     %FT01
        LDR     R14,[handle,#w_flags]
        ORR     R14,R14,#ws_onscreenonce        ; force window onto screen!
        STR     R14,[handle,#w_flags]           ; (don't touch toggled bit)
01
        ADD     R14,handle,#w_scx
        LDMIA   R14,{x1,y1}
        ADD     R14,userblk,#u_wax0
        STMIA   R14!,{cx0,cy0,cx1,cy1}
        STMIA   R14,{x1,y1}                     ; scroll positions

        BL      calc_w_status           ; ensure bhandle up-to-date

        LDR     R2,oldbuttons
        B       openwindow_checkbuttons

Kevin Bracey's avatar
Kevin Bracey committed
1392 1393 1394 1395 1396 1397
	[ PoppingIconBar
	; Note - need to sort out Service_MouseTrap for all this!
	ROUT
checkiconbarpop
	Push	"R0,LR"
	LDR	R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
1398 1399
	CMP	R14,#nullptr
	Pull	"R0,PC",NE		; old-style tasks don't have an icon bar!
Kevin Bracey's avatar
Kevin Bracey committed
1400 1401 1402 1403 1404 1405
	LDR	R14,iconbar_pop_state
	ADD	PC,PC,R14,LSL #2
	NOP
	B	%F10
	B	%F20
	B	%F30
1406 1407 1408
	[ OldStyleIconBar
; Icon bar is held by menu
	|
1409 1410
	NOP ; drops through
; Icon bar is held by menu, or fronted by keyboard
1411
        ]
Kevin Bracey's avatar
Kevin Bracey committed
1412 1413 1414
	Pull	"R0,PC"

; Icon bar is at back
1415 1416 1417 1418 1419
10      LDRB    R14, popiconbar
        TEQ     R14, #0
        Pull    "R0, PC", EQ    ; don't bring to front if configured off

        TEQ	R1,#0		; are we at the bottom of the screen?
Kevin Bracey's avatar
Kevin Bracey committed
1420 1421
	Pull	"R0,PC",NE

1422 1423 1424 1425 1426 1427
      [ Autoscr
        ; Don't bring to front if autoscrolling
        LDR     R14, autoscr_state
        TST     R14, #af_enable
        Pull    "R0, PC", NE
      ]
Kevin Bracey's avatar
Kevin Bracey committed
1428 1429 1430
	; Don't bring to front if dragging a window
	LDR	R14,dragtype
	CMP	R14,#drag_posn
Ben Avison's avatar
Ben Avison committed
1431
	BLO	%FT11
Kevin Bracey's avatar
Kevin Bracey committed
1432
	CMP	R14,#drag_vscroll
Ben Avison's avatar
Ben Avison committed
1433
	Pull	"R0,PC",LO
Kevin Bracey's avatar
Kevin Bracey committed
1434 1435 1436 1437 1438
	TEQ	R14,#drag_scrollboth
	Pull	"R0,PC",EQ

11	SWI	XOS_ReadMonotonicTime
	Pull	"R0,PC",VS
1439 1440
	[ true
	LDR	R14, popiconbar_pause
Kevin Bracey's avatar
Kevin Bracey committed
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
	ADD	R0,R0,R14
	|
	ADD	R0,R0,#pop_DelayTime
	]
	STR	R0,iconbar_pop_time
	MOV	R0,#pop_Delaying
	STR	R0,iconbar_pop_state
	Pull	"R0,PC"

; Icon bar is delaying
20	TEQ	R1,#0
	MOVNE	R14,#pop_Back
	STRNE	R14,iconbar_pop_state
	Pull	"R0,PC",NE
	SWI	XOS_ReadMonotonicTime
	LDR	R14,iconbar_pop_time
	CMP	R0,R14
	Pull	"R0,PC",LO
	MOV	R14,#pop_Front
	STR	R14,iconbar_pop_state
	MOV	R14,#0
	B	%FT50

; Icon bar is at front
30	LDR	R14,iconbarheight
	CMP	R1,R14
	Pull	"R0,PC",LE
	MOV	R14,#pop_Back
	STR	R14,iconbar_pop_state
	MOV	R14,#1

50
	MOV	R0,R14
	LDR	handle,iconbarhandle
Ben Avison's avatar
Ben Avison committed
1475 1476
	CMP	handle,#nullptr
	Pull	"R0,PC",EQ
Kevin Bracey's avatar
Kevin Bracey committed
1477

1478 1479 1480
;
; As we enter here, R0=0 means pop to front, else go to back (or previous position)
;
Kevin Bracey's avatar
Kevin Bracey committed
1481 1482 1483 1484
	Push	"R1-R11"
	BL	checkhandle             ; handle -> window block
	BLVC	calc_w_status           ; set up flag word
	LDRVC	R14,[handle,#w_flags]
1485
	BVS	%FT70
Kevin Bracey's avatar
Kevin Bracey committed
1486
	TEQ	R0,#0
1487 1488
	BNE	%FT60
	; Going to front. Remember where to go back to.
1489
	[ OldStyleIconBar
1490
	TST	R14,#wf_backwindow
Kevin Bracey's avatar
Kevin Bracey committed
1491
	MOVNE	R6,#-2
1492 1493 1494
	LDREQ	R6,[handle,#w_bhandle]
	ADRL	R0,iconbar_pop_previous
	STR	R6,[R0]
1495
	]
1496 1497 1498 1499 1500 1501
	BIC	R14,R14,#wf_backwindow
	STR	R14,[handle,#w_flags]
	MOV	R6,#-1
	B	%FT65

60	; Going back to previous position.
1502
        [ OldStyleIconBar
1503 1504 1505 1506 1507
	ADRL	R6,iconbar_pop_previous
	LDR	R6,[R6]
	CMP	R6,#-2
	ORREQ	R14,R14,#wf_backwindow
	STREQ	R14,[handle,#w_flags]
1508 1509 1510 1511 1512 1513 1514 1515 1516
	|
	ORR     R14, R14, #wf_backwindow
	STR     R14, [handle, #w_flags]
 [ HideIconBar
	MOV     R6, #-3
 |
	MOV     R6, #-2
 ]
	]
1517 1518 1519
65
	ADD	R14,handle,#w_wax0
	LDMIA	R14,{R0-R3,R4,R5}
Kevin Bracey's avatar
Kevin Bracey committed
1520
	Push	"R0-R6"
1521
	LDR	R14,iconbarhandle
Kevin Bracey's avatar
Kevin Bracey committed
1522
	Push	"R14"
1523 1524
	MOV	userblk,sp
	BL	int_open_window
Kevin Bracey's avatar
Kevin Bracey committed
1525
	ADD	sp,sp,#8*4
1526
70
Kevin Bracey's avatar
Kevin Bracey committed
1527 1528 1529
	Pull	"R1-R11"
	Pull	"R0,PC"
	]
Neil Turton's avatar
Neil Turton committed
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539

;;----------------------------------------------------------------------------
;; Check for pointer changing window
;;----------------------------------------------------------------------------

notdragging

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

      ; CLRV                            ; ignore errors if they reach here
1540
        MOV     R5,#0                   ; don't match shaded icons
Neil Turton's avatar
Neil Turton committed
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
        BL      int_get_pointer_info    ; R3,R4 = window/icon handle

        LDR     R14,dragtype            ; We've just changed icon, do we
        TEQ     R14,#0                  ; to change pointer shape?
        BNE     %FT92
        LDR     R14,mouseflags
        TST     R14,#mf_waitdrag
        BNE     %FT92

        Push    "r0"

        ADRL    r0,old_icon
        LDR     R14,[r0]
        TEQ     R3,R14
        STRNE   R3,[r0]
        ADRL    r0,old_window
        LDREQ   R14,[r0]
        TEQEQ   R4,R14
        STRNE   R4,[r0]

        Pull    "r0"

        BEQ     %FT92

        Push    "R0-R7,handle"

1567 1568 1569
        CMP     R3,#nullptr
        BEQ     %FT90

Neil Turton's avatar
Neil Turton committed
1570 1571 1572 1573 1574 1575 1576 1577 1578
        Abs     R14,R3
        LDR     R14,[R14,#w_taskhandle]
        CMP     R14,#-1                 ; is the task -1, ie. owned by a menu
        BNE     %FT01
;
        SWI     XOS_ReadMonotonicTime
        LDR     R1,automenu_timelimit
        ADD     R1,R1,R0                ; reset the time limit
        STR     R1,automenu_timeouttime
1579 1580 1581 1582
      [ ClickSubmenus
        MOV     R14, #0
        STRB    R14, submenuopenedbyclick
      ]
Neil Turton's avatar
Neil Turton committed
1583
01
Ben Avison's avatar
Ben Avison committed
1584 1585 1586
        CMP     R4,#nullptr
        CMPNE   R4,#nullptr2
        BEQ     %FT90
Neil Turton's avatar
Neil Turton committed
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620

        Debug   bo,"New window,icon",r3,r4

        LDR     r14,iconbarhandle
        CMP     r14,r3
        Debug   bo,"iconbar handle , handle",r14,r3
        TEQ     r14,r3
        BNE     %FT01

        Push    "R1-R4,R7"
        BL      findicon
        LDR     R14,[R2,#icb_taskhandle]
        Task    R14,,"Icon bar pointer shape check"
        Pull    "R1-R4,R7"
        Abs     r14,r3
        B       ptr_iconbar_icon

01
        Abs     R14,r3
        LDR     r3,[r14,#w_taskhandle]
        Push    "R14"
        Task    r3
        Pull    "R14"

ptr_iconbar_icon
        LDR     R14,[R14,#w_icons]
        ADD     R14,R14,R4,ASL #i_shift ; Point at the icon.
        LDR     r3,[r14,#i_flags]
        TST     r3,#if_text
        TSTNE   r3,#if_indirected       ; Is it indirected text ?
        BEQ     %FT90

        MOV     r2,#WimpValidation_Pointer
        LDR     r3,[r14,#i_data+4]      ; Pointer to validation string.
Robert Sprowson's avatar
Robert Sprowson committed
1621
        AcceptLoosePointer_NegOrZero r3,-1
Ben Avison's avatar
Ben Avison committed
1622 1623
        CMP     r3,r3,ASR #31
        BEQ     %FT90
Neil Turton's avatar
Neil Turton committed
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
        DebugS  bo,"Validation string is ",r3
        BL      findcommand
        BNE     %FT90

        ADRL    r2,pointer_sprite
        Debug   bo,"Copy Sprite name"
88
        LDRB    R14,[r3],#1
        CMP     R14,#","
        MOVEQ   R14,#-1
        CMP     R14,#";"
        MOVEQ   R14,#0
        CMP     R14,#" "