Wimp03 138 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 322 323 324 325
; 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
;

; attempt to call a pre-poll filter routine, it may modify the flags in R0

        CallFilter prefilter
;
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
      [ 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
341 342 343 344 345 346 347 348 349 350 351
        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
352
; set up R3 -> poll word, with bottom bit set => urgent
Neil Turton's avatar
Neil Turton committed
353 354 355 356
; 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
357 358 359
        MOVLO   R3,#0                   ; R3=0 => no poll word
        BLLO    killfpblock             ; get rid of this!
        BLO     %FT01
Neil Turton's avatar
Neil Turton committed
360 361 362 363 364 365 366 367 368 369

; 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
370
        TST     R3,#3                   ; check that address is word-aligned
Neil Turton's avatar
Neil Turton committed
371
        BNE     err_badR3
Ben Avison's avatar
Ben Avison committed
372
        CMP     R3,#ApplicationStart    ; and not in application space
Neil Turton's avatar
Neil Turton committed
373 374

        [ Medusa
Ben Avison's avatar
Ben Avison committed
375 376
        LDRHS   R14,orig_applicationspacesize
        CMPHS   R14,R3
Neil Turton's avatar
Neil Turton committed
377
        |
Ben Avison's avatar
Ben Avison committed
378
        RSBHSS  R3,R3,#&1000000		; APPSPACE
Neil Turton's avatar
Neil Turton committed
379
        ]
Ben Avison's avatar
Ben Avison committed
380
        BHS     err_badR3
Neil Turton's avatar
Neil Turton committed
381

Ben Avison's avatar
Ben Avison committed
382 383 384
        TST     R0,#flag_pollword
        TSTNE   R0,#flag_pollfast       ; bottom bit set => poll quickly
        ORRNE   R3,R3,#1
Neil Turton's avatar
Neil Turton committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403

        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
404
        TEQNE   R3,#0
Neil Turton's avatar
Neil Turton committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 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 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
        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
;
; 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
480 481
        CMP     R14,#nullptr            ; old Wimp didn't set up escape!
        BNE     %FT02
Neil Turton's avatar
Neil Turton committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
;
        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
506
        Debug   poll2, "repollwimp"
Neil Turton's avatar
Neil Turton committed
507 508 509 510 511 512 513 514 515
        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
 ]
Ben Avison's avatar
Ben Avison committed
516
        MOV     R0,#1
Neil Turton's avatar
Neil Turton committed
517 518 519 520 521 522 523 524
        BL      scanpollwords           ; scan high-priority tasks
        BNE     ExitPoll

        LDR     R14,taskhandle          ; get userblk back (may be corrupted)
        LDR     R14,[wsptr,R14]
        LDR     userblk,[R14,#task_registers+4*1]
;
        LDR     R2,headpointer          ; are there any outstanding messages?
Ben Avison's avatar
Ben Avison committed
525 526
        CMP     R2,#nullptr
        BNE     returnmessage
527 528 529 530 531 532
;
      [ 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
533 534
        CMP     R2, #nullptr
        BNE     returnmessage
535
      ]
Neil Turton's avatar
Neil Turton committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 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
;
        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
610 611 612
      [ true
        B       %FT22
      |
Neil Turton's avatar
Neil Turton committed
613 614 615 616 617
        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
618
      ]
Neil Turton's avatar
Neil Turton committed
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
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
635 636 637 638 639 640
;
; 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
641 642 643 644
;
; look at invalid list to see if a redraw is necessary
;
        BL      checkredrawhandle
Neil Turton's avatar
Neil Turton committed
645
      [ :LNOT: ChildWindows             ; this is pointless - can't get an error from checkredrawhandle!
Neil Turton's avatar
Neil Turton committed
646
        BVS     ExitPoll                ; <<<< wot?
Neil Turton's avatar
Neil Turton committed
647
      ]
Neil Turton's avatar
Neil Turton committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
;
; 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
675

Neil Turton's avatar
Neil Turton committed
676 677 678 679
pollredrawlp
        LDR     R2,[R1,#ll_forwards]
        CMP     R2,#nullptr
        BEQ     clearrects
Neil Turton's avatar
Neil Turton committed
680

Neil Turton's avatar
Neil Turton committed
681 682
        SUB     handle,R1,#w_active_link

Neil Turton's avatar
Neil Turton committed
683
        Push    "R2"
Neil Turton's avatar
Neil Turton committed
684 685
        BL      invalidouterportion
        Pull    "R1"
Neil Turton's avatar
Neil Turton committed
686

Neil Turton's avatar
Neil Turton committed
687 688 689 690
        LDR     R2,rlinks+windowrects
        CMP     R2,#nullptr
        BEQ     pollredrawlp

Neil Turton's avatar
Neil Turton committed
691 692 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 728 729 730 731 732
;
; 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
733

Neil Turton's avatar
Neil Turton committed
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
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
753 754 755 756
;
; check for auto-redraw bit in window flags
;
        LDR     R14,[handle,#w_flags]
Neil Turton's avatar
Neil Turton committed
757
        Debug   child,"window flags are",R14
Neil Turton's avatar
Neil Turton committed
758 759 760 761 762 763 764
        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
765 766 767 768 769 770
 [ Twitter
        BL      checktwitter
        LDRNE   r14, getrectflags
        ORRNE   r14, r14, #getrect_twitter
        STRNE   r14, getrectflags
 ]
Neil Turton's avatar
Neil Turton committed
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
        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
791 792 793 794
      [ debug
        LDR     R14,rlinks + windowrects
        Debug   child,"Returning Redraw_Window_Request for window,rects",#redrawhandle,R14
      ]
Neil Turton's avatar
Neil Turton committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808
        MOV     R0,#Redraw_Window_Request
        B       ExitPoll

        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
809
        MOV     R0,#4
Neil Turton's avatar
Neil Turton committed
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
        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
        ]
829 830 831 832 833 834 835 836
      [ 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
837
        BL      forcedrag_on            ; put drag rectangle back if nec.
838
      ]
Neil Turton's avatar
Neil Turton committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
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
861
        MOV     R0,#4
Neil Turton's avatar
Neil Turton committed
862
        BL      background
863
        SWI     XOS_WriteI+16           ; CLG
Neil Turton's avatar
Neil Turton committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883

; 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
884
        Debug   bpr,"Continuing braindead panic redraw on handle",handle
Neil Turton's avatar
Neil Turton committed
885 886 887 888 889 890 891 892 893

; 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
894
        Debug   bpr,"handle, flags are",handle,R14
Neil Turton's avatar
Neil Turton committed
895 896 897
        TST     R14,#ws_open
        BEQ     start_braindead_panic_redraw

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 918 919 920 921 922
; 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
923

Neil Turton's avatar
Neil Turton committed
924 925 926 927
        Pull    "handle"

        Debug   bpr,"Braindead redraw: this,next",handle,R0
      |
Neil Turton's avatar
Neil Turton committed
928 929 930 931 932 933 934
        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
935
      ]
Neil Turton's avatar
Neil Turton committed
936 937 938 939 940 941

; Process this window (exactly)

        BL      initrectptrs
        ADD     R0,handle,#w_x0
        LDMIA   R0,{cx0,cy0,cx1,cy1}
Neil Turton's avatar
Neil Turton committed
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965

; 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
966 967 968 969 970 971
        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
972 973 974
      [ ChildWindows
        B       process_redrawable_window_actually      ; DON'T consider the children this time
      |
Neil Turton's avatar
Neil Turton committed
975
        B       process_redrawable_window
Neil Turton's avatar
Neil Turton committed
976
      ]
Neil Turton's avatar
Neil Turton committed
977 978 979 980 981 982 983 984 985 986 987 988 989 990


;;----------------------------------------------------------------------------
;; 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
991
      [ mousecache
Neil Turton's avatar
Neil Turton committed
992 993 994 995 996 997 998
        LDRB    R0,recacheposn
        TEQ     R0,#0                   ; do we recache the information?
        BEQ     trykeys                 ; no, so ignore
      ]
;
; now see what user input has occurred
;
999
        Debug   poll2, "Processing mouse"
Neil Turton's avatar
Neil Turton committed
1000
        BL      getmouseposn            ; ie. MOUSE R0,R1,R2
Kevin Bracey's avatar
Kevin Bracey committed
1001 1002 1003 1004

      [ PoppingIconBar
	BL	checkiconbarpop
      ]
Neil Turton's avatar
Neil Turton committed
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
;
; are we dragging a box?
;
        LDR     R14,dragtype
        TEQ     R14,#0
        BEQ     notdragging
;
; 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
1049
        TEQ     R14,#drag_scrollboth    ; use vscroll bit of sysflags for this
Neil Turton's avatar
Neil Turton committed
1050 1051
        MOVEQ   R14,#drag_vscroll
        CMP     R14,#drag_user
Ben Avison's avatar
Ben Avison committed
1052
        BHS     notdragging             ; only system drags are elegible
Neil Turton's avatar
Neil Turton committed
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097

        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
;
; 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
1098 1099 1100
        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
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
;
; 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
1166 1167 1168 1169 1170 1171
	[ 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
1172 1173
	CMP	R14,#nullptr
	Pull	"R0,PC",NE		; old-style tasks don't have an icon bar!
Kevin Bracey's avatar
Kevin Bracey committed
1174 1175 1176 1177 1178 1179
	LDR	R14,iconbar_pop_state
	ADD	PC,PC,R14,LSL #2
	NOP
	B	%F10
	B	%F20
	B	%F30
1180 1181 1182
	[ OldStyleIconBar
; Icon bar is held by menu
	|
1183 1184
	NOP ; drops through
; Icon bar is held by menu, or fronted by keyboard
1185
        ]
Kevin Bracey's avatar
Kevin Bracey committed
1186 1187 1188
	Pull	"R0,PC"

; Icon bar is at back
1189 1190 1191 1192 1193
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
1194 1195
	Pull	"R0,PC",NE

1196 1197 1198 1199 1200 1201
      [ 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
1202 1203 1204
	; Don't bring to front if dragging a window
	LDR	R14,dragtype
	CMP	R14,#drag_posn
Ben Avison's avatar
Ben Avison committed
1205
	BLO	%FT11
Kevin Bracey's avatar
Kevin Bracey committed
1206
	CMP	R14,#drag_vscroll
Ben Avison's avatar
Ben Avison committed
1207
	Pull	"R0,PC",LO
Kevin Bracey's avatar
Kevin Bracey committed
1208 1209 1210 1211 1212
	TEQ	R14,#drag_scrollboth
	Pull	"R0,PC",EQ

11	SWI	XOS_ReadMonotonicTime
	Pull	"R0,PC",VS
1213 1214
	[ true
	LDR	R14, popiconbar_pause
Kevin Bracey's avatar
Kevin Bracey committed
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
	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
1249 1250
	CMP	handle,#nullptr
	Pull	"R0,PC",EQ
Kevin Bracey's avatar
Kevin Bracey committed
1251

1252 1253 1254
;
; As we enter here, R0=0 means pop to front, else go to back (or previous position)
;
Kevin Bracey's avatar
Kevin Bracey committed
1255 1256 1257 1258
	Push	"R1-R11"
	BL	checkhandle             ; handle -> window block
	BLVC	calc_w_status           ; set up flag word
	LDRVC	R14,[handle,#w_flags]
1259
	BVS	%FT70
Kevin Bracey's avatar
Kevin Bracey committed
1260
	TEQ	R0,#0
1261 1262
	BNE	%FT60
	; Going to front. Remember where to go back to.
1263
	[ OldStyleIconBar
1264
	TST	R14,#wf_backwindow
Kevin Bracey's avatar
Kevin Bracey committed
1265
	MOVNE	R6,#-2
1266 1267 1268
	LDREQ	R6,[handle,#w_bhandle]
	ADRL	R0,iconbar_pop_previous
	STR	R6,[R0]
1269
	]
1270 1271 1272 1273 1274 1275
	BIC	R14,R14,#wf_backwindow
	STR	R14,[handle,#w_flags]
	MOV	R6,#-1
	B	%FT65

60	; Going back to previous position.
1276
        [ OldStyleIconBar
1277 1278 1279 1280 1281
	ADRL	R6,iconbar_pop_previous
	LDR	R6,[R6]
	CMP	R6,#-2
	ORREQ	R14,R14,#wf_backwindow
	STREQ	R14,[handle,#w_flags]
1282 1283 1284 1285 1286 1287 1288 1289 1290
	|
	ORR     R14, R14, #wf_backwindow
	STR     R14, [handle, #w_flags]
 [ HideIconBar
	MOV     R6, #-3
 |
	MOV     R6, #-2
 ]
	]
1291 1292 1293
65
	ADD	R14,handle,#w_wax0
	LDMIA	R14,{R0-R3,R4,R5}
Kevin Bracey's avatar
Kevin Bracey committed
1294
	Push	"R0-R6"
1295
	LDR	R14,iconbarhandle
Kevin Bracey's avatar
Kevin Bracey committed
1296
	Push	"R14"
1297 1298
	MOV	userblk,sp
	BL	int_open_window
Kevin Bracey's avatar
Kevin Bracey committed
1299
	ADD	sp,sp,#8*4
1300
70
Kevin Bracey's avatar
Kevin Bracey committed
1301 1302 1303
	Pull	"R1-R11"
	Pull	"R0,PC"
	]
Neil Turton's avatar
Neil Turton committed
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348

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

notdragging

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

      ; CLRV                            ; ignore errors if they reach here
        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"

        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
1349 1350 1351 1352
      [ ClickSubmenus
        MOV     R14, #0
        STRB    R14, submenuopenedbyclick
      ]
Neil Turton's avatar
Neil Turton committed
1353
01
Ben Avison's avatar
Ben Avison committed
1354
        CMP     R3,#nullptr
Neil Turton's avatar
Neil Turton committed
1355
        BEQ     %FT90
Ben Avison's avatar
Ben Avison committed
1356 1357 1358 1359 1360
        CMP     R4,#nullptr
        CMPNE   R4,#nullptr2
        BEQ     %FT90
;        TST     R3,#1
;        BEQ     %FT90
Neil Turton's avatar
Neil Turton committed
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 1392 1393 1394

        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.
Ben Avison's avatar
Ben Avison committed
1395 1396
        CMP     r3,r3,ASR #31
        BEQ     %FT90
Neil Turton's avatar
Neil Turton committed
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
        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,#" "
Ben Avison's avatar
Ben Avison committed
1410 1411
        STRGTB  r14,[r2],#1
        BGT     %BT88
Neil Turton's avatar
Neil Turton committed
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438

        MOV     R4,#0                   ; Default active point is 0,0
        MOV     R5,#0
        STRB    R4,[r2]                 ; Terminate the sprite name.

        CMP     R14,#-1
        BNE     %FT02

        Debug   bo,"Sprite name copied"

        BL      getnumber
        MOV     R4,R0                   ; Returns 0 if not found.

        LDRB    R14,[R3],#1
        CMP     R14,#","
        BNE     %FT02
        BL      getnumber
        MOV     R5,R0                   ; Returns 0 if not found.

        [ debugbo
         ADRL    r2,pointer_sprite
         DebugS  bo,"Sprite name is :",r2
        ]
02
        MOV     R0,#SpriteReason_SetPointerShape
        ADRL    R2,pointer_sprite
        MOV     R3,#1
1439 1440 1441 1442 1443
      [ Autoscr
        LDR     R14, autoscr_state      ; don't reprogram pointer if autoscrolling is enabled
        TST     R14, #af_enable
        ORRNE   R3, R3, #&10
      ]
Neil Turton's avatar
Neil Turton committed
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 1475 1476 1477
        MOV     R6,#0
        MOV     R7,#0
        SWI     XWimp_SpriteOp          ; take from Wimp's sprite area(s)
        MOV     R14,#-1
        ADRL    R1,special_pointer
        STR     R14,[r1]
        B       %FT91
90
        ADRL    R1,special_pointer
        LDR     R14,[R1]
        CMP     R14,#0
        MOVNE   R14,#0
;        ADRNEL  R1,special_pointer
        STRNE   R14,[r1]
        MOVNE   R3,#1
        BLNE    doubleptr_off
91
        Pull    "r0-r7,handle"
92

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

; if icon changes while drag pending, return code now!

        LDR     R14,pending_window      ; if icon changes while drag pending
        TEQ     R3,R14                  ; do it now!
        LDREQ   R14,pending_icon
        TEQEQ   R4,R14
        LDRNE   R7,mouseflags
        TSTNE   R7,#mf_waitdrag
        ORRNE   R7,R7,#mf_oldcoords     ; avoid missing clicks

        BNE     waitdrag_action         ; pre-emptive strike!

1478 1479 1480 1481 1482 1483 1484 1485
      [ Autoscr
; do we need to do something about autoscrolling?
        LDR     R14, autoscr_state
        TST     R14, #af_enable
        BLNE    poll_autoscroll         ; may or may not return, preserves flags if it does
        BNE     %FT01                   ; don't scroll icon bar if scrolling something else!
      ]

Neil Turton's avatar
Neil Turton committed
1486 1487
; if in iconbar, check whether we should scroll automatically

Kevin Bracey's avatar
Kevin Bracey committed
1488
 [ false
Neil Turton's avatar
Neil Turton committed
1489
        LDR     R14,iconbarhandle
Ben Avison's avatar
Ben Avison committed
1490 1491
        CMP     R14,#nullptr
        BEQ     %FT01                   ; no iconbar
Neil Turton's avatar
Neil Turton committed
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
        TEQ     R3,R14
        BNE     %FT01                   ; this isn't it!
;
        LDR     R14,scrx0
        ADD     R14,R14,#iconbarsepgap
        CMP     R0,R14
        MOVLT   R8,#-16                 ; scroll left
        BLT     %FT02
        LDR     R14,scrx1
        SUB     R14,R14,#iconbarsepgap
        CMP     R0,R14
        MOVGT   R8,#16                  ; scroll right
        BLE     %FT01
02
        Push    "R0-R8,handle,userblk"
        Abs     handle,R3
        BL      calc_w_status           ; ensure bhandle is correct
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{R1-R7}             ; x0,y0,x1,y1,scx,scy,bhandle
        LDR     R8,[sp,#8*4]
        ADD     R5,R5,R8                ; add in appropriate offset
        LDR     R0,iconbarhandle
        Push    "R0,R1-R7"              ; first word is window handle
        MOV     userblk,sp
        BL      int_open_window
        ADD     sp,sp,#4*8              ; handle,x0,y0,x1,y1,scx,scy,bhandle
        Pull    "R0-R8,handle,userblk"
Kevin Bracey's avatar
Kevin Bracey committed
1519 1520
  |
        LDR     R14,iconbarhandle
Ben Avison's avatar
Ben Avison committed
1521 1522
        CMP     R14,#nullptr
        BEQ     %FT01                   ; no iconbar
Kevin Bracey's avatar
Kevin Bracey committed
1523 1524 1525 1526 1527 1528 1529 1530
        TEQ     R3,R14
	MOVNE	R14,#0
	STRNE	R14,iconbar_scroll_start_time
        BNE     %FT01                   ; this isn't it!
;
        LDR     R14,scrx0
        ADD     R14,R14,#iconbarsepgap
        CMP     R0,R14
1531 1532
        LDRLT   R8, iconbar_scroll_speed
        MVNLT   R8, R8 ; ensure msb set                        ; scroll left
Kevin Bracey's avatar
Kevin Bracey committed
1533
        BLT     %FT02
1534
;
Kevin Bracey's avatar
Kevin Bracey committed
1535 1536 1537 1538 1539 1540
        LDR     R14,scrx1
        SUB     R14,R14,#iconbarsepgap
        CMP     R0,R14
	MOVLE	R14,#0
	STRLE	R14,iconbar_scroll_start_time
        BLE     %FT01
1541
        LDRGT   R8, iconbar_scroll_speed                       ; scroll right
Kevin Bracey's avatar
Kevin Bracey committed
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
02
        Push    "R0-R8,handle,userblk"
        Abs     handle,R3
        BL      calc_w_status           ; ensure bhandle is correct
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{R1-R7}             ; x0,y0,x1,y1,scx,scy,bhandle
        LDR     R8,[sp,#8*4]

	SWI	XOS_ReadMonotonicTime
	LDR	R14,iconbar_scroll_start_time
	TEQ	R14,#0
	STREQ	R0,iconbar_scroll_start_time
	STREQ	R5,iconbar_scroll_start_scx
	BEQ	%FT04
	; The following formula gives speed = iconbar_scroll_speed+iconbar_scroll_accel * time
	Push	"R2"
	LDR	R5,iconbar_scroll_start_scx
	LDR	R2,iconbar_scroll_start_time
	SUB	R2,R0,R2		; R2=time since scroll start (in centi-seconds)
1561 1562 1563 1564 1565 1566
	CMP     R2, #&3800              ;; much more than this, and accel*time^2 will overflow
	MOVHI   R2, #&3800              ;; when maximum acceleration is configured
	LDR	LR, iconbar_scroll_accel
	MUL	LR,R2,LR		; LR=accel * time (cs)
	MOV     LR, LR, ASR#6
	ADD     LR, LR, LR, ASR#2       ; LR=accel * time (s) (within 3%)
Kevin Bracey's avatar
Kevin Bracey committed
1567
	CMP	R8,#0
1568
	ADDGE	R8,R8,LR
Kevin Bracey's avatar
Kevin Bracey committed
1569
	SUBLT	R8,R8,LR		; R8=(+/-)(speed + accel*time)
1570 1571 1572 1573
	ADDLT   R8, R8, #1              ; adjust because we used NOT(speed) rather than -(speed) for velocity
	MUL	R8,R2,R8		; R8=(+/-)(speed + accel*time) * time (cs)
	ADD     R8, R8, R8, ASR#2
	ADD	R5,R5,R8,ASR #6		; R5+=(+/-)(speed + accel*time) * time (s)
Kevin Bracey's avatar
Kevin Bracey committed
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
	Pull	"R2"

        LDR     R0,iconbarhandle
        Push    "R0,R1-R7"              ; first word is window handle
        MOV     userblk,sp
        BL      int_open_window
        ADD     sp,sp,#4*8              ; handle,x0,y0,x1,y1,scx,scy,bhandle
04
        Pull    "R0-R8,handle,userblk"
  ]
Neil Turton's avatar
Neil Turton committed
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
01

; if dragging, treat as window -1 (do this after iconbar scrolling)

        LDR     R14,dragtype            ; avoid ptr_changing events
        TEQ     R14,#0
        TEQNE   R14,#drag_subr_posn2
        TEQNE   R14,#drag_subr_size2
        MOVNE   R3,#nullptr

; Ptr_Entering/Leaving_Window treats system area as window -1

        Push    "R3"                    ; actual window handle
1597 1598 1599 1600 1601 1602 1603
      [ Autoscr
; also treat as window -1 (but just for the purposes of Pointer Leaving/Entering Window events) if
; we're autoscrolling (which is not necessarily a subset of if dragging)
        LDR     R14, autoscr_state
        TST     R14, #af_enable
        MOVNE   R3, #nullptr
      ]
Neil Turton's avatar
Neil Turton committed
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
        LDR     R14,iconbarhandle
        TEQ     R3,R14                  ; treat as window handle -1:
        LDRNE   R14,backwindow          ; (a) if in back window
        TEQNE   R3,R14
        LDRNE   R14,backwindowhandle    ;     (either of them)
        TEQNE   R3,R14
        CMPNE   R4,#nullptr2            ; (b) if in iconbar window
        MOVEQ   R3,#nullptr             ; (c) if in system area
        LDR     R14,ptrwindow
        CMP     R3,R14                  ; same window?
        Pull    "R3",EQ                 ; actual window handle
        BEQ     cantchange
        Debug   ptr,"pointer new,old",R3,r14


;
; if old window not null, return 'leaving window', and set ptrwindow to null
; otherwise set ptrwindow to new window, and return 'entering window'
; in both cases set mf_oldcoords bit.
;
        Push    "R0"                    ; now R0,R3 on stack
        CMP     R14,#nullptr
        BEQ     entering
leaving
        MOV     R8,R14                  ; old handle
        LDR     R9,ptrtask              ; old task

        LDR     R14,[wsptr,R9]          ; Check if old task is dead
        TST     R14,#task_unused        ; If so, just return 'entering window'
        BEQ     %FT01
        CMP     R3,#nullptr             ; Unless new window is null !!
        BNE     entering                ;
        STR     R3,ptrwindow
        Pull    "r0,r3"
        B       cantchange
01
        MOV     R3,#nullptr             ; set ptrwindow to null
        MOV     R0,#Pointer_Leaving_Window
        MOV     R14,#ptrleaving_bit
        B       ptrboth

entering
        Abs     handle,R3
        LDR     R9,[handle,#w_taskhandle]

        MOV     R8,R3                   ; new handle
        MOV     R0,#Pointer_Entering_Window
        MOV     R14,#ptrentering_bit

ptrboth
        STR     R3,ptrwindow
;
        Push    "R14"
        CMP     R3,#nullptr          ; if ptrwindow not null, task is relevant
        Abs     handle,R3,NE
        LDRNE   R14,[handle,#w_taskhandle]
        STRNE   R14,ptrtask             ; not nec. same as taskhandle
        Pull    "R14"
;
        CMP     R9,#0                   ; if this is a menu or a system window
        Pull    "R0,R3",LE
        BLE     cantchange              ; ignore it!
;
        Push    "R14"
        Task    R9,,"PtrWindow"
        MOV     R9,R14                  ; get flag word
        Pull    "R14"

        TST     R9,R14                  ; see if relevant bit is set
        STREQ   R0,[sp]                 ; keep 'action' flag
        Pull    "R0,R3"
        BNE     cantchange              ; user isn't interested!
;
        LDR     R14,mouseflags
        ORR     R14,R14,#mf_oldcoords
        STR     R14,mouseflags           ; use same values again!
;
        STR     R8,[userblk]            ; R0 = reason code already
        B       ExitPoll


;;----------------------------------------------------------------------------
;; Check for interesting mouse clicks
;;   -  depends on 'button type' of relevant icon
;;----------------------------------------------------------------------------

;
; button attributes
;

ibb_notpressed  *       2_000000000001
ibb_select      *       2_000000000010
ibb_writeable   *       2_000000000100      ; for writeable icons
ibb_canreport   *       2_100000000000

ibb_waitrepeat  *       2_000000001000
ibb_waitclick   *       2_000000010000
ibb_waitdrag    *       2_000000100000
ibb_waitrelease *       2_000001000000
ibb_wait2clicks *       2_000010000000
ibb_waitremove  *       2_000100000000
ibb_pending     *       2_000111111000
ibb_report5     *       2_001000000000
ibb_report6     *       2_010000000000

ibb_justselect  *       ibb_pending :AND: (:NOT:ibb_waitdrag)

bb_setflags     *       3               ; bit number of pending flags


buttonattributes
        DCD     2_000000000000  ; 0 never report
        DCD     2_100000000001  ; 1 always report
        DCD     2_100000001000  ; 2 report if button clicked (auto-repeat)
        DCD     2_100000000000  ; 3 report if button clicked
        DCD     2_100101000010  ; 4 select if clicked, report if released
        DCD     2_100010000010  ; 5 select if clicked, report if 2 clicks
        DCD     2_100000100000  ; 6 as for (3), but can also drag
        DCD     2_100001100010  ; 7 as for (4), but can also drag
        DCD     2_100010100010  ; 8 as for (5), but can also drag
        DCD     2_100100010011  ; 9 select always, report if clicked
        DCD     2_101010100010  ;10 report 1 or 2 clicks (:SHL:8 if 1 click)
        DCD     2_100000100010  ;11 as (8), but select+notify on single click
        DCD     2_110010100010  ;12
        DCD     2_100010000000  ;13
        DCD     2_100000100100  ;14 writeable, but also report as for (6)
        DCD     2_000000000100  ;15 writeable icon (don't report)

        ALIGN

; R0,R1 = mouse coords (absolute)
;    R2 = mouse button state
; R3,R4 = actual window/icon handles (R3 not forced to -1 for background)

cantchange
        LDR     R14,dragtype
        TEQ     R14,#0
        TEQNE   R14,#drag_subr_posn2
        TEQNE   R14,#drag_subr_size2
        BNE     trykeys                 ; don't recognise any other buttons
;
        BL      scanmenus               ; preserves task if it returns here
        BVS     ExitPoll
;
; window handle can come back -1 if we clicked on a greyed-out menu item
;
        CMP     R3,#nullptr             ; should only happen for grey menu items
        BEQ     trykeys
;
; translate icon -2 to appropriate system icon handle
;
        CMP     R4,#nullptr2            ; in system area?
Kevin Bracey's avatar
Kevin Bracey committed
1756 1757 1758 1759
        BNE     %FT01

        BL      setwimpicon             ; set up R4 and R5
        B       gotbttype
Neil Turton's avatar
Neil Turton committed
1760 1761 1762
;
; obtain 'button type' of user icon
;
Kevin Bracey's avatar
Kevin Bracey committed
1763
01      CMP     R4,#nullptr
Neil Turton's avatar
Neil Turton committed
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811
        LDREQ   R5,[handle,#w_workflags]; look up work area button type
        LDRNE   R5,[handle,#w_icons]
        ADDNE   R5,R5,#i_flags
        LDRNE   R5,[R5,R4,ASL #i_shift] ; R5 = flag word
;
; always report the menu button unless in border region
;

gotbttype
        CMP     R4,#nullptr2
        BLE     issystemarea
        LDR     R14,oldbuttons
        BIC     R14,R2,R14
        TST     R14,#button_middle      ; look for +ve edge of MENU button
        BNE     justtellhim
        BIC     R2,R2,#button_middle    ; pretend it's off!

issystemarea

;
; for select and adjust, check the button type
;
        AND     R14,R5,#if_buttontype           ; use field as index offset
        MOVS    R14,R14,LSR #ib_buttontype
        ADR     R6,buttonattributes
        LDR     R6,[R6,R14,ASL #2]              ; R6 = internal flag word
        LDR     R7,mouseflags                   ; R7 = mouse flags
        LDR     R8,oldbuttons                   ; R8 = old button state

; R0,R1 => x,y mouse co-ordinates
; R2 => button state
; R4 => icon handle
; R6 => button attributes
; R7 => mouse flag
; R8 => old button state
; handle => internal window handle

        Push    "R0-R2,handle"
;
        BL      modifytool                      ; attempt to handle window tools changing (when possible)
;
        TST     R2,#button_left+button_right
        BNE     %FT01                           ; if not released then ignore
;
        ASSERT  nullptr = windowicon_workarea
;
        LDR     R0,border_iconselected          ; may have changed!
        CMP     R0,#windowicon_workarea
Kevin Bracey's avatar
Kevin Bracey committed
1812
        BLE     %FT01                           ; if -VE then ignore its not worth the hassle
Neil Turton's avatar
Neil Turton committed
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
;
        MOV     R1,#0
        MOV     R2,#is_inverted
        LDR     handle,border_windowselected
        BL      int_set_icon_state              ; modify the tool icon
;
        MOV     R0,#nullptr
        STR     R0,border_iconselected
        STR     R0,border_windowselected        ; flag as no icon / window selected
01
        Pull    "R0-R2,handle"
;
; cancel certain pending actions if icon has changed
;
        LDR     R14,pending_window
        TEQ     R3,R14
        LDREQ   R14,pending_icon
        TEQEQ   R4,R14
        BEQ     sameicon
;
        TST     R7,#mf_waitremove               ; cancel previous icon
        BEQ     dontpratabout
        Push    "R0,R4,handle"
        LDR     handle,pending_window
        BL      checkhandle                     ; IGNORE errors!
        LDRVC   R4,pending_icon
        BLVC    deselecticon
        Pull    "R0,R4,handle"                  ; V cleared lower down

dontpratabout
        TST     R7,#mf_wait2clicks              ; reset pointer shape if nec.
        BLNE    doubleptr_off
        BIC     R7,R7,#mf_pendingexceptdrag     ; cancel pending (except drag)
        STR     R7,mouseflags
;
sameicon
        TST     R7,#mf_waitdrag
        BLNE    waitdrag                        ; may or may not return here
        TST     R7,#mf_waitrelease
        BNE     waitrelease
        TST     R7,#mf_wait2clicks
        BNE     wait2clicks
        TST     R7,#mf_waitclick
        BNE     waitclick
        TST     R7,#mf_waitrepeat
        BNE     waitrepeat
;
testbutton
        CMP     R3,#nullptr             ; can't have select or adjust here!
        BEQ     trykeys
;
        BIC     R2,R2,R8                ; look for +ve edges
;
        TST     R6,#ibb_notpressed      ; unless notpressed, check key is down
        TSTEQ   R2,#button_left:OR:button_middle:OR:button_right
        BEQ     trykeys
;
; icon responds - set up appropriate pending flags
;
        AND     R14,R6,#ibb_pending
        BIC     R7,R7,#mf_pending
        ORR     R7,R7,R14,LSL #mfb_setflags-bb_setflags  ; set up mouseflags
        STR     R7,mouseflags

        TST     R14,#ibb_waitrepeat
        BLNE    getfx12                 ; get auto-repeat settings
        LDRNEB  R14,repeatdelay
        STRNEB  R14,repeatlimit
;
        LDR     R14,timeblk             ; go!
        STR     R14,pending_time
;
        ADR     R14,pending_x
        STMIA   R14,{R0-R4}             ; saves x,y,buttons,window,icon

; change pointer shape for double-clicks to help wally users

        TST     R7,#mf_wait2clicks
        BLNE    doubleptr_on            ; if current shape = 1, set double ptr

; see if the icon reports back, or is just selected

        TST     R6,#ibb_writeable       ; special code for writeable icons
        BLNE    clickonwriteable        ; will return here
        TST     R6,#ibb_canreport
        BEQ     trykeys                 ; type 15 is writeable but can't report
        TST     R6,#ibb_select
        BEQ     justtellhim             ; report direct to the user!
        TST     R6,#ibb_report5         ; report 1 click as well
        MOVNE   R2,R2,LSL #8            ; shift up by 8 bits
        BNE     justtellhim
        TST     R6,#ibb_report6
        BNE     trykeys                 ; don't tell him!
;
; implicit selection takes place (don't tell the user!)
;
        CMP     R4,#nullptr             ; don't select work or system area
        BLGT    selecticon              ; take note of ESG's etc.
;
        TST     R6,#ibb_justselect      ; if no pending actions,
        BEQ     justtellhim             ; notify the user AS WELL as selecting
;
        TST     R6,#ibb_waitclick       ; button could go down AT THE SAME TIME
        BICNES  R14,R2,R8               ; as the pointer enters the icon!
        BNE     justtellhim
;
        B       trykeys

;
; check for pending icon
;

waitrelease
        TST     R2,#button_left:OR:button_middle:OR:button_right
        BICEQ   R7,R7,#mf_waitrelease
        STREQ   R7,mouseflags
        LDREQ   R2,pending_buttons      ; remember original button press
        BEQ     justtellhim
        B       trykeys                 ; keep waiting!

wait2clicks

; new version changes the pointer shape during the double-click period

        LDRB    R5,doubleclick_movelimit
        BL      checkpointermoved       ; sets C if pointer moved too far

        LDR     R5,doubleclick_timelimit
        BLCC    pendingtime             ; preserves flags
        CMPCC   R14,R5
        BCS     %FT01                   ; too late!

        BICS    R2,R2,R8                ; doesn't affect C flag
        BEQ     testbutton

        LDR     R14,pending_buttons     ; can't double-click with different buttons
        TST     R2,R14
        CMPEQ   R2,R2                   ; set C => don't do the double-click
01
        BIC     R7,R7,#mf_wait2clicks
        STR     R7,mouseflags

        BL      doubleptr_off           ; preserves flags
        BCS     testbutton              ; CS: don't do the double-click
        B       justtellhim             ; CC: do the double-click

; In    R0,R1 = current mouse position
;       R5 = movement limit (OS units)
;       [pending_x/y] = mouse position when initial click occurred
; Out   CS => mouse has moved away from that position

checkpointermoved

        Push    "R6,LR"
        LDR     R14,pending_x           ; get chicago dist. from orig. point
        SUBS    R14,R14,R0
        RSBMI   R14,R14,#0
        LDR     R6,pending_y            ; R5 not used any more
        SUBS    R6,R6,R1
        RSBMI   R6,R6,#0
        ADD     R6,R6,R14
        CMP     R6,R5
        Pull    "R6,PC"                 ; CS => pointer has moved away

waitclick
        BICS    R14,R2,R8
        BEQ     testbutton              ; not interested
        B       justtellhim

waitrepeat
        LDR     R14,pending_buttons
        TST     R2,R14                  ; still held down?
        BICEQ   R7,R7,#mf_waitrepeat
        STREQ   R7,mouseflags
        BEQ     testbutton
;
        BL      pendingtime
        Push    "R2"
        LDRB    R2,repeatlimit
        CMP     R14,R2
        Pull    "R2"
        BCC     trykeys                 ; still waiting
;
        LDR     R14,timeblk             ; reset timer
        STR     R14,pending_time
        BL      getfx12
        LDRB    R14,repeatrate          ; different delay this time!
        STRB    R14,repeatlimit
        MOV     R14,#1
        STRB    R14,autorepeating
        B       justtellhim             ; return button press

getfx12
        Push    "R0-R2,LR"
        MOVNE   R0,#&C4
        MOVNE   R1,#0
        MOVNE   R2,#&FF
        SWINE   XOS_Byte
        STRNEB  R1,repeatdelay
        STRNEB  R2,repeatrate
        Pull    "R0-R2,PC"

waitdrag
        Push    "LR"
;
        TST     R2,#button_left:OR:button_middle:OR:button_right
        BICEQ   R7,R7,#mf_waitdrag      ; button released!
        STREQ   R7,mouseflags
        Pull    "PC",EQ
;
        LDRB    R5,drag_movelimit
        BL      checkpointermoved       ; CS => pointer has moved
        BLCC    pendingtime             ; can't return an error
        LDRCC   R5,drag_timelimit
        CMPCC   R14,R5
        Pull    "PC",CC                 ; still waiting
        Pull    "LR"                    ; drop through
;
; This code is also called from higher up, if the window/icon have changed
; Entry:  R7 = current mouseflags
; Exit:   drag buttons reported to the application
;
waitdrag_action
        BL      mousetrap               ; buttons haven't changed
;
        BIC     R7,R7,#mf_waitdrag      ; don't cancel others!
        STR     R7,mouseflags
        ADR     R14,pending_x
        LDMIA   R14,{R0-R4}
        STR     R0,mousexpos            ; to fool Drag_Box if called
        STR     R1,mouseypos
        MOV     R2,R2,ASL #4            ; 'alias' to different buttons
                                        ; drop through

;-----------------------------------------------------------------------------
; Return mouse buttons to the user
; Entry:  R0,R1 = mouse x,y coords
;         R2 = mouse buttons:
Kevin Bracey's avatar
Kevin Bracey committed
2051

Neil Turton's avatar
Neil Turton committed
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073
;              bits 0-3  = normal response    (depends on button type)
;              bits 4-7  = 'drag' operation   (button held down)
;              bits 8-11 = 'select' operation (ie. 1 click if it's that type)
;         R3,R4 = window/icon handles (-1 if none)
; Exit:   data put into [userblk], and Mouse_Click returned
;-----------------------------------------------------------------------------

justtellhim
        CMP     R4,#nullptr2
        BLE     wimpaction              ; click in system area
;
; if R3 is really -1, then we shouldn't return it to anyone
; (menu clicks on background only work in single-tasking mode)
;
        LDR     R14,backwindowhandle    ; this counts as the background too!
        CMP     R3,R14
        CMPNE   R3,#nullptr
        BEQ     repollwimp
;
; page in correct task (again) - R3 may be changed by waitdrag
;
        LDR     R14,iconbarhandle
Ben Avison's avatar
Ben Avison committed
2074 2075
        CMP     R14,#nullptr            ; don't do this if no iconbar!
        BEQ     notiniconbar
Neil Turton's avatar
Neil Turton committed
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091
        TEQ     R3,R14
        BNE     notiniconbar
;
        Push    "R0-R4"                 ; save mouse data!
        BL      findicon                ; finds icon R4 in iconbar
        LDREQ   R14,[R2,#icb_taskhandle]
        Task    R14,EQ,"IconBar"
        Pull    "R0-R4"
        BNE     repollwimp              ; unrecognised!
        MOV     R3,#nullptr2            ; return window handle -2 for iconbar
        B       returnclick
;
; ensure that correct task is paged in
; NB ptrwindow may not be the same as R3 (eg. drag button activates later)
;
notiniconbar
Ben Avison's avatar
Ben Avison committed
2092 2093
        CMP     R3,#nullptr
        BEQ     repollwimp              ; window has been deleted!!!
Neil Turton's avatar
Neil Turton committed
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
        Abs     handle,R3
        LDR     R14,[handle,#w_taskhandle]
        Task    R14,,"ReturnClick"
;
        LDR     R14,flagword
        TST     R14,#buttonchange_bit
        BNE     trykeys
;
; if backwindow, pretend it's really window -1
;
        LDR     R14,backwindow
        TEQ     R3,R14
        MOVEQ   R3,#nullptr             ; (for menu clicks in singletask mode)
;
Ben Avison's avatar
Ben Avison committed
2108 2109
        CMP     R3,#nullptr             ; is it a real window?
        BEQ     %FT10                   ; if not then icon
Neil Turton's avatar
Neil Turton committed
2110 2111
;
        CMP     R4,#0
Ben Avison's avatar
Ben Avison committed
2112
        BMI     %FT10                   ; if its the background then ignore it
Neil Turton's avatar
Neil Turton committed
2113
;
Kevin Bracey's avatar
Kevin Bracey committed
2114 2115 2116
	TST	R2,#button_middle	; ignore menu clicks for slabbing
	BNE	%FT10

Neil Turton's avatar
Neil Turton committed
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
        Push    "R0-R3"

; R3 = window handle / handle => window defn ( <= 0 if none )
; R4 = icon handle

        LDR     R14,[handle,#w_icons]
        ADD     R14,R14,R4,LSL #i_shift ; R14 -> icon defn
;
        LDR     R1,[R14,#i_flags]
        LDR     R3,[R14,#i_data+4]      ; get flags, -> validation string
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138
      [ true
        AND     R14, R1, #if_buttontype ; border_icon/windowselected behaviour is only suitable for a few button types
        MOV     R14, R14, LSR #ib_buttontype
        TEQ     R14, #ibt_autorepeat
        TEQNE   R14, #ibt_click
        TEQNE   R14, #ibt_clickrelease
        TEQNE   R14, #ibt_click2
        TEQNE   R14, #ibt_dclick
        TEQNE   R14, #ibt_dclickrelease
        TEQNE   R14, #ibt_dclick2
        BNE     %FT03
      ]
Neil Turton's avatar
Neil Turton committed
2139 2140 2141 2142
        BL      getborder               ; decode to setup the border information
;
        TEQ     R0,#border_action
        TEQNE   R0,#border_defaultaction
Kevin Bracey's avatar
Kevin Bracey committed
2143 2144 2145 2146
	BNE	%FT03
;
	LDR	R14,border_windowselected    ; Make sure previous selected icon
	CMP	R14,#nullptr                 ; is unslabbed
Ben Avison's avatar
Ben Avison committed
2147
	BEQ	%F1
Kevin Bracey's avatar
Kevin Bracey committed
2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
	TEQ	R14,handle
	LDR	R0,border_iconselected
	CMP	R0,#nullptr
	BLE	%F1
	TEQ	R0,R4
	TEQEQ	R14,handle
	BEQ	%F2
	Push	"handle"
	MOV	handle,R14
	MOV	R1,#0
	MOV	R2,#is_inverted
	BL	int_set_icon_state
	Pull	"handle"

1       STR     handle,border_windowselected
        STR     R4,border_iconselected
;
2       LDRB    R0,autorepeating
        CMP     R0,#0
3       MOVNE   R0,#0
Neil Turton's avatar
Neil Turton committed
2168
        STRNEB  R0,autorepeating
Kevin Bracey's avatar
Kevin Bracey committed
2169
	BNE	%F5
Neil Turton's avatar
Neil Turton committed
2170

Kevin Bracey's avatar
Kevin Bracey committed
2171 2172 2173 2174
        MOV     R0,R4                   ; R1 => icon handle
        MOV     R1,#is_inverted
        MOV     R2,#0
        BL      int_set_icon_state      ; and then select the icon
Neil Turton's avatar
Neil Turton committed
2175
;
Kevin Bracey's avatar
Kevin Bracey committed
2176
5
Neil Turton's avatar
Neil Turton committed
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189
        Pull    "R0-R3"
10
;
; to ensure that Message_MenusDeleted arrives before the next click,
; send mouse clicks as messages if the message queue is not empty
;

returnclick
        LDR     R14,oldbuttons
        STMIA   userblk,{R0,R1,R2,R3,R4,R14}
        MOV     R0,#Mouse_Click

        LDR     R14,headpointer
Ben Avison's avatar
Ben Avison committed
2190 2191
        CMP     R14,#nullptr
        BEQ     ExitPoll                ; return directly for efficiency
Neil Turton's avatar
Neil Turton committed
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203

        MOV     R1,userblk
        LDR     R2,taskhandle
        BL      int_sendmessage_fromwimp
        B       repollwimp              ; deliver outstanding messages


;----------------------------------------------------------------------------
; Check for a key press
;----------------------------------------------------------------------------

trykeys
2204
        Debug   poll2, "Processing keys"
2205 2206 2207
 [ UTF8
        ; First, check if caret task is queueing keypresses for later handling
        LDR     handle, caretdata + 0
Ben Avison's avatar
Ben Avison committed
2208 2209
        CMP     handle, #nullptr
        BEQ     %FT11                   ; still read character (may be hot!)
2210 2211 2212 2213 2214 2215 2216
        BL      checkhandle             ; check it hasn't been deleted!
        MOVVS   handle, #nullptr
        STRVS   handle, caretdata + 0   ; if deleted, turn it off
        BVS     %FT11

        LDR     R14, [handle, #w_taskhandle]
        CMP     R14, #0
Ben Avison's avatar
Ben Avison committed
2217
        LDRMI   R14, menutaskhandle
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233
        LDR     R14, [wsptr, R14]
        LDR     R14, [R14, #task_flagword]
        TST     R14, #keypress_bit
        BNE     nothing                 ; queue for later handling
11

        ; See if we're in the middle of a multi-byte external key event
        LDRB    R14, keyout_buflen
        TEQ     R14, #0
        BEQ     trykeys_getinternalkeycode
        ADRL    R1, keyout_buffer
        LDRB    R6, [R1]                ; next byte to process
        ADD     R2, R1, R14
01      LDRB    R0, [R1, #1]            ; copy the other bytes down
        STRB    R0, [R1], #1
        CMP     R1, R2
Ben Avison's avatar
Ben Avison committed
2234
        BLO     %BT01
2235 2236 2237 2238
        SUB     R14, R14, #1            ; decrement byte count
        STRB    R14, keyout_buflen

        LDR     R14, singletaskhandle
Ben Avison's avatar
Ben Avison committed
2239 2240 2241
        CMP     R14, #nullptr
        BLEQ    topmost_window
        STREQ   R0, hotkeyptr           ; initialise hotkey system, unless we're single-tasking
2242 2243
        ADRL    R14, savedcaretdata     ; get caret data
        LDMIA   R14, {R0-R5}
Ben Avison's avatar
Ben Avison committed
2244 2245
        CMP     R0, #nullptr            ; is there a caret?
        BNE     %FT02
2246 2247 2248 2249 2250 2251 2252 2253 2254
        BL      int_processkey          ; if not, send hotkey
        B       repollwimp              ; (no need to check if single-tasking, as we won't get here otherwise)
02      MOV     handle, R0
        BL      checkhandle             ; check savedcaret window hasn't been deleted
        MOVVS   R0, #0
        STRVSB  R0, keyout_buflen       ; if it has (!) then delete continuation byte queue
        BVS     trykeys                 ; and restart key processing
        LDR     R14, [handle, #w_taskhandle]
        CMP     R14, #0
Ben Avison's avatar
Ben Avison committed
2255
        LDRMI   R14, menutaskhandle
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
        Task    R14,, "KeyPressed continuation"
        STMIA   userblk, {R0-R6}
        MOV     R0, #Key_Pressed
        B       ExitPoll                ; return Key_Pressed event

trykeys_getinternalkeycode
        ; Get the next "key" from the expanded function key (if applicable)
        ADR     R5, keystring_buffer
        ADRL    R7, keystring_buflen
        BL      get_internal_keycode_from_buffer
        CMP     R6, #-1                 ; was there one?
        BNE     trykeys_gotinternalkeycode

        ; Get the next task-generated key
        ADR     R5, keyprocess_buffer
        ADRL    R7, keyprocess_buflen
        BL      get_internal_keycode_from_buffer
        CMP     R6, #-1                 ; was there one?
        BNE     trykeys_gotinternalkeycode

        ; Fill our keyboard input buffer from kernel keyboard buffer (needed so we can look ahead)
        LDRB    R3, keyin_buflen
        ADRL    R5, keyin_buffer
2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
      [ true
        MOV     R0, #&81                ; OS_Byte 129 (INKEY)
        MOV     R1, #0
        MOV     R2, #0                  ; time limit 0
        SWI     XOS_Byte
        TEQ     R2, #&FF
        BEQ     %FT02                   ; break if no byte available
        STRB    R1, [R5, R3]            ; stick byte in my buffer
        ADD     R3, R3, #1
        TEQ     R1, #0                  ; null byte (=> either a null or a function key) ?
        MOVEQ   R7, #2
        BEQ     %FT01
        BL      read_current_alphabet
        BNE     %FT02                   ; except in UTF-8, all chars are one byte
        MOV     R0, R1
        BL      estimate_UTF8_char_len  ; may return length 0, but that's okay because we've already read one byte
        MOV     R7, R1
01      CMP     R3, R7
      |
2298
01      CMP     R3, #6
2299
      ]
Ben Avison's avatar
Ben Avison committed
2300
        BHS     %FT02                   ; break from loop if full
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312
        MOV     R0, #&81                ; OS_Byte 129 (INKEY)
        MOV     R1, #0
        MOV     R2, #0                  ; time limit 0
        SWI     XOS_Byte
        TEQ     R2, #&FF
        BEQ     %FT02                   ; break if no byte available
        STRB    R1, [R5, R3]            ; stick byte in my buffer
        ADD     R3, R3, #1
        B       %BT01
02      STRB    R3, keyin_buflen

        ; Get a key from our input buffer
2313
        ADRL    R7, keyin_buflen        ; R5 already set up
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330
        BL      get_internal_keycode_from_buffer
        CMP     R6, #-1                 ; was there one?
        BEQ     nothing                 ; no keys to handle

trykeys_gotinternalkeycode
        ; *All* Key_Pressed events now return caretdata as it is at this time
        ; - ie. before the writable icon handling messes around with it.
        ; This saves on the horrible kludge of storing the Key_PressedOldData
        ; event number in order to specify where to get the caret data from.
        Push    "R0-R5"
        ADR     R14, caretdata
        LDMIA   R14, {R0-R5}
        ADRL    R14, savedcaretdata
        STMIA   R14, {R0-R5}
        Pull    "R0-R5"

        ; Page in correct task
Ben Avison's avatar
Ben Avison committed
2331 2332
        CMP     handle, #nullptr
        BEQ     %FT01
2333 2334
        LDR     R14, [handle, #w_taskhandle]
        CMP     R14, #0
Ben Avison's avatar
Ben Avison committed
2335
        LDRMI   R14, menutaskhandle
2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
        Task    R14,, "KeyPressed"
01

        ; KeyboardMenus gets a look in first
      [ KeyboardMenus
        LDR     R4, menuSP
        CMP     R4, #0
        BLT     %FT00                   ; no menu open so don't grab special keys

        ADR     R5, menudata            ; if it's a dbox then don't grab keys
        LDR     R5, [R5, R4]
        TST     R5, #3
        BNE     %FT00

        ADR     R14, menuhandles        ; if menu has caret then don't grab keys
        LDR     R14, [R14, R4]
        LDR     R0, menucaretwindow
        TEQ     R0, R14
        BEQ     %FT00

        TEQ     R6, #13                 ; check for return and cursor keys
        BEQ     handlemenukey
        TST     R6, #1:SHL:31
        BEQ     %FT00
        BIC     R14, R6, #1:SHL:31
        TEQ     R14, #&8C
        TEQNE   R14, #&8D
        TEQNE   R14, #&8E
        TEQNE   R14, #&8F
        SUBEQ   R6, R14, #(&8C-136)     ; map onto range 136-139
        BEQ     handlemenukey
00
      ]

        ; Handle escape keypresses
        TEQ     R6,#&1B                 ; escape?
        BNE     %FT02
      [ KeyboardMenus
        CMP     r4, #0                  ; if no menu open then skip
        BLT     %FT02
        TST     r5, #3                  ; check for dialogue
        SUBNE   r0, r4, #4              ; if dialogue open then just remove it
        MOVEQ   r0, #-4                 ; otherwise remove whole menu tree
        CMP     r0, #0
        BLLT    menusdeleted            ; send Message_MenusDeleted if whole menu going (preserves r0)
        BL      closemenus
      |
        LDR     R0,menuSP
        CMP     R0,#0
        BLT     %FT02

        BL      menusdeleted            ; send Message_MenusDeleted
        MOVVC   R0,#-4
        BLVC    closemenus
      ]
        BVC     nothing                 ; absorb escape if used to close menus
        B       ExitPoll                ; report error if any

02      ; Examine caret state to determine what to do with keypress
        ADRL    R14, savedcaretdata
        LDMIA   R14, {R0-R5}
Ben Avison's avatar
Ben Avison committed
2397 2398
        CMP     R0, #nullptr
        BEQ     tryhotkeys              ; no input focus
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
        CMP     R1, #nullptr
        BNE     processkey              ; wimp gets first bash at this one!

keypressed
; Return a Key_Pressed event to the caret-owning task
        BL      prepare_external_key_event
        STMIA   userblk, {R0-R6}
        MOV     R0,#Key_Pressed         ; task handle already set up
        B       ExitPoll

tryhotkeys
; Initiate hotkey chain of events
        BL      prepare_external_key_event
        MOVGT   R0, #0
        STRGTB  R0, keyout_buflen       ; don't cache the other bytes if we're single-tasking!
        BLLE    int_processkey
        B       repollwimp


; Support routines for the above

prepare_external_key_event
; Munges internal keycode back into UTF-8 / external keycode format, and initialises hotkey system
; Entry: R6 = internal key code
; Exit:  R6 = first external key code
;        keyout_buffer filled with any remaining external keycodes
;        hotkeyptr set up (unless we're not multitasking)
;        LE => we are multitasking
2427
        Entry   "R0,R4,R5"
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447
        TST     R6, #1:SHL:31           ; was it a function key?
        ANDNE   R6, R6, #&FF
        ORRNE   R6, R6, #&100           ; convert into external form if so
        BNE     %FT01

        BL      read_current_alphabet   ; are we in UTF-8 alphabet?
        ANDNE   R6, R6, #&FF
        BNE     %FT01                   ; return bottom byte if not

        SUB     sp, sp, #8
        MOV     R5, sp
        BL      convert_UCS4_to_UTF8
        LDRB    R6, [sp]                ; first byte
        SUB     R4, R4, #1
        STRB    R4, keyout_buflen       ; held-over byte count
        ADD     R14, R5, R4             ; -> last byte in sequence
        ADRL    R4, keyout_buffer
02      LDRB    R0, [R5, #1]!
        STRB    R0, [R4], #1
        CMP     R5, R14
Ben Avison's avatar
Ben Avison committed
2448
        BLO     %BT02
2449 2450 2451
        ADD     sp, sp, #8

01      LDR     R14, singletaskhandle
Ben Avison's avatar
Ben Avison committed
2452 2453 2454
        CMP     R14, #nullptr
        BLEQ    topmost_window          ; if we're multitasking, get top window handle
        STREQ   R0, hotkeyptr           ; and store it as the first hotkey window
2455 2456 2457
        EXIT                            ; leave flags as they are

get_internal_keycode_from_buffer
2458 2459
; Reads a key from one of keyin_buffer, keyprocess_buffer or keystring_buffer,
; from a range appropriate to the current alphabet
2460 2461 2462 2463 2464 2465
; Skips any malformed characters
; Entry: R5 -> buffer
;        R7 -> buffer length byte
; Exit:  R6 = internal keycode : -1 means no character
;                                &800000xx represents a function key
;                                else character code ( <= &7FFFFFFF if UTF-8 alphabet, <= &FF otherwise )
2466
        Entry   "R0-R4"
2467 2468 2469 2470
        LDRB    R3, [R7]                ; get buffer length
get_internal_keycode_restartpoint
        CMP     R3, #0                  ; nothing in my buffer?
        MOVLE   R6, #-1
Kevin Bracey's avatar
Kevin Bracey committed
2471
        EXIT    LE
2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507

        LDRB    R6, [R5]
        TEQ     R6, #0                  ; first byte null => either a null or a function key
        BNE     get_internal_keycode_isntafunctionkey

get_internal_keycode_isafunctionkey
        TEQ     R3, #1                  ; if it's just one null byte, it's a malformed character
        MOVEQ   R4, #1
        MOVEQ   R6, #-1
        BEQ     get_internal_keycode_removefrombuffer

        LDRB    R6, [R5, #1]
        TEQ     R6, #0
        ORRNE   R6, R6, #1:SHL:31       ; unless a null, set top bit to indicate function key status
        MOV     R4, #2                  ; either way, it's a 2-byte character
        B       get_internal_keycode_removefrombuffer

get_internal_keycode_isntafunctionkey
        BL      read_current_alphabet
        MOVNE   R4, #1                  ; if not UTF-8, then it's got to be a valid 1-byte character
        BNE     get_internal_keycode_removefrombuffer

        MOV     R6, R5
        MOV     R4, R3
        BL      convert_UTF8_to_UCS4    ; sets up R4 and R6

get_internal_keycode_removefrombuffer
        ; R6 = internal Wimp key number, or -1 if malformed
        ; R4 = number of bytes of keyboard buffer it used
        SUB     R3, R3, R4              ; number of bytes that will still be in buffer after removal
        STRB    R3, [R7]
        ADD     R1, R5, R3              ; -> byte after final byte in buffer (after copying down)
        MOV     R2, R5                  ; rover
01      LDRB    R0, [R2, R4]
        STRB    R0, [R2], #1            ; copy down
        CMP     R2, R1
Ben Avison's avatar
Ben Avison committed
2508
        BLO     %BT01
2509 2510 2511 2512

        CMP     R6, #-1                 ; was it a malformed character?
        BEQ     get_internal_keycode_restartpoint  ; swallow it if so!

Kevin Bracey's avatar
Kevin Bracey committed
2513
        EXIT
2514 2515 2516

 | ; else not UTF8...

Neil Turton's avatar
Neil Turton committed
2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
 [ KeyboardMenus
        MOV     r6, #-1                 ; so we can tell later on if we read a key
        LDR     r4, menuSP
        CMP     r4, #0
        BLT     %FT00                   ; no menu open so don't grab special keys

        ADR     r5, menudata            ; if it's a dbox then don't grab keys
        LDR     r5, [r5, r4]
        TST     r5, #3
        BNE     %FT00

        ADR     r14, menuhandles        ; if menu has caret then don't grab keys
        LDR     r14, [r14, r4]
        LDR     r0, menucaretwindow
        TEQ     r0, r14
        BEQ     %FT00

        MOV     r0, #4                  ; allow us to read cursor keys
        MOV     r1, #1
        SWI     XOS_Byte
        MOV     r3, r1
        MOV     r0, #&81                ; INKEY(0)
        MOV     r1, #0
        MOV     r2, #0
        SWI     XOS_Byte
        MOV     r6, r1
        MOV     r7, r2
        MOV     r0, #4                  ; restore cursor key state
        MOV     r1, r3
        SWI     XOS_Byte
        CMP     r7, #&FF                ; was there a key?
        BEQ     nothing

        TEQ     r6, #13                 ; check for return and cursor keys
        TEQNE   r6, #136
        TEQNE   r6, #137
        TEQNE   r6, #138
        TEQNE   r6, #139
        BEQ     handlemenukey
 ]
00
Neil Turton's avatar
Neil Turton committed
2558
        LDR     handle,caretdata+0
Ben Avison's avatar
Ben Avison committed
2559 2560
        CMP     handle,#nullptr
        BEQ     %FT01                   ; still read character (may be hot!)
Neil Turton's avatar
Neil Turton committed
2561 2562 2563 2564
;
        BL      checkhandle             ; check it hasn't been deleted!
        MOVVS   handle,#nullptr
        STRVS   handle,caretdata+0      ; if deleted, turn it off
Neil Turton's avatar
Neil Turton committed
2565
        BVS     %BT00
Neil Turton's avatar
Neil Turton committed
2566 2567
;
        LDR     R14,[handle,#w_taskhandle]
Neil Turton's avatar
Neil Turton committed
2568
        CMP     R14,#0
Ben Avison's avatar
Ben Avison committed
2569
        LDRMI   R14,menutaskhandle
Neil Turton's avatar
Neil Turton committed
2570 2571 2572

        LDR     R14,[wsptr,R14]
        LDR     R14,[R14,#task_flagword]
Neil Turton's avatar
Neil Turton committed
2573 2574 2575 2576
        TST     R14,#keypress_bit
        BNE     nothing                 ; temporarily disabled

01
Neil Turton's avatar
Neil Turton committed
2577 2578
 [ KeyboardMenus
        CMP     r6, #0
Kevin Bracey's avatar
Kevin Bracey committed
2579 2580 2581 2582
        BGE     %FT22
        BL      inkey0                  ; if we don't have a key yet then get one
        MOVS    r6, r1
22
Neil Turton's avatar
Neil Turton committed
2583
 |
Neil Turton's avatar
Neil Turton committed
2584 2585
        BL      inkey0                  ; may branch elsewhere
        MOVS    R6,R1                   ; actual key value
Neil Turton's avatar
Neil Turton committed
2586
 ]
Neil Turton's avatar
Neil Turton committed
2587 2588 2589 2590 2591 2592
        BNE     %FT01
        BL      inkey0                  ; may branch elsewhere!
        MOVS    R6,R1
        ADDNE   R6,R6,#&100             ; add &100 to the value (unless 0)
01
        LDR     R14,caretdata+0
Ben Avison's avatar
Ben Avison committed
2593 2594 2595
        CMP     R14,#nullptr
        LDRNE   R14,[handle,#w_taskhandle]
        LDREQ   R14,menutaskhandle
Neil Turton's avatar
Neil Turton committed
2596 2597 2598 2599
        Task    R14,,"KeyPressed"       ; page in correct task

        TEQ     R6,#&1B                 ; escape?
        BNE     %FT02
Neil Turton's avatar
Neil Turton committed
2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610

 [ KeyboardMenus
        CMP     r4, #0                  ; if no menu open then skip
        BLT     %FT02
        TST     r5, #3                  ; check for dialogue
        SUBNE   r0, r4, #4              ; if dialogue open then just remove it
        MOVEQ   r0, #-4                 ; otherwise remove whole menu tree
        CMP     r0, #0
        BLLT    menusdeleted            ; send Message_MenusDeleted if whole menu going (preserves r0)
        BL      closemenus
 |
Neil Turton's avatar
Neil Turton committed
2611 2612 2613 2614 2615 2616 2617
        LDR     R0,menuSP
        CMP     R0,#0
        BLT     %FT02

        BL      menusdeleted            ; send Message_MenusDeleted
        MOVVC   R0,#-4
        BLVC    closemenus
Neil Turton's avatar
Neil Turton committed
2618
 ]
Neil Turton's avatar
Neil Turton committed
2619 2620 2621 2622 2623
        BVC     nothing                 ; absorb escape if used to close menus
        B       ExitPoll                ; report error if any

02      ADR     R14,caretdata
        LDMIA   R14,{R0-R5}
Ben Avison's avatar
Ben Avison committed
2624 2625
        CMP     R0,#nullptr
        BEQ     tryhotkeys              ; no input focus
Neil Turton's avatar
Neil Turton committed
2626 2627 2628 2629 2630 2631
        CMP     R1,#nullptr
        BNE     processkey              ; wimp gets first bash at this one!

keypressed
        STMIA   userblk,{R0-R6}         ; including the key value
        LDR     R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
2632 2633 2634
        CMP     R14,#nullptr
        BLEQ    topmost_window
        STREQ   R0,hotkeyptr
Neil Turton's avatar
Neil Turton committed
2635 2636 2637 2638 2639 2640 2641
;

        MOV     R0,#Key_Pressed         ; task handle already set up
        B       ExitPoll

tryhotkeys
        LDR     R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
2642
        CMP     R14,#nullptr
Neil Turton's avatar
Neil Turton committed
2643 2644 2645

; Set hotkeyptr to topmost window

Ben Avison's avatar
Ben Avison committed
2646 2647 2648
        BLEQ    topmost_window
        STREQ   R0,hotkeyptr
        BLEQ    int_processkey          ; R6 = key code
Neil Turton's avatar
Neil Turton committed
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
        B       repollwimp

inkey0
        Push    "LR"
        MOV     R0,#&81                 ; INKEY(0)
        MOV     R1,#0
        MOV     R2,#0
        SWI     XOS_Byte
        Pull    "LR"
        BVS     ExitPoll                ; wot?
;
        CMP     R2,#&FF                 ; was there a key?
        BEQ     nothing
Kevin Bracey's avatar
Kevin Bracey committed
2662
        MOV     PC,LR
Neil Turton's avatar
Neil Turton committed
2663

2664 2665 2666
 ] ; end UTF8 conditional


Neil Turton's avatar
Neil Turton committed
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699
 [ KeyboardMenus
; In:   r4 = menuSP
;       r5 -> menu data
;       r6 = key pressed
;
handlemenukey
        LDR     R14, menutaskhandle
        Task    R14,,"KeyPressed"       ; page in correct task

        LDR     r14, mousexpos
        STR     r14, lastxpos
        LDR     r14, mouseypos
        STR     r14, lastypos

        ADR     r14, menuselections
        LDR     r1, [r14, r4]           ; r1 = previous selection index

        TEQ     r6, #13
        BNE     trymenucursorkeys
        CMP     r1, #0                  ; handle return
        BLT     nothing                 ; do nothing if no selection
        STR     r4, whichmenu
        MOV     r2, #4                  ; fake SELECT mouse button
        B       gomenuselect

trymenucursorkeys
        TEQ     r6, #137                ; check for right (sub-menu)
        BNE     trymenuleft
        CMP     r1, #0                  ; handle right
        BLT     nothing
        ADD     r7, r1, r1, LSL #1      ; r7 = selected item * 3 (also used later)
        ADD     r6, r5, r7, LSL #3      ; r6 -> selected menu item
        LDR     r1, [r6, #mi_submenu]   ; r1 -> sub-menu data block
Ben Avison's avatar
Ben Avison committed
2700 2701
        CMP     r1, r1, ASR #31         ; check for sub-menu/dbox
        BEQ     nothing
Neil Turton's avatar
Neil Turton committed
2702 2703 2704 2705 2706
        ADR     r14, menuhandles        ; get menu window handle
        LDR     handle, [r14, r4]
        BL      checkhandle
        BVS     nothing
        LDR     r2, reversedmenu
2707
        CMP     r2, #"\\"
Neil Turton's avatar
Neil Turton committed
2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742
        LDREQ   r2, [handle, #w_wax0]   ; get menu x
        LDRNE   r2, [handle, #w_wax1]
        LDR     r14, [handle, #w_icons]
        ADD     r14, r14, #i_bby1
        ADD     r7, r7, #1              ; r7 = middle icon
        LDR     r3, [r14, r7, ASL #i_shift]
        LDR     r14, [handle, #w_way1]
        ADD     r3, r3, r14             ; get menu y
        LDR     r14, [handle, #w_scy]
        SUB     r3, r3, r14             ; adjust for scrolling
 [ NCMenus
        ADD     r3, r3, #24             ; adjust for NCMenus border
 ]
        LDR     r14, [r6, #mi_mflags]
        TST     r14, #mif_warning
        BLNE    sendmenuwarning         ; preserves flags
        BLEQ    int_create_menu
        B       nothing

trymenuleft
        TEQ     r6, #136
        BLNE    trymenuupdown           ; preserves flags
        BNE     nothing
        SUBS    r0, r4, #4              ; handle left
        BLGE    closemenus
        B       nothing

trymenuupdown
; In:   r1 = current selected menu item
;       r4 = menuSP
;       r5 -> menu data
;       r6 = key pressed
; Out:  Could corrupt almost anything
;       Flags preserved
;
Kevin Bracey's avatar
Kevin Bracey committed
2743
        EntryS
Neil Turton's avatar
Neil Turton committed
2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781
        MOV     r7, #0                  ; determine how many items in menu
00
        ADD     r7, r7, #1
        LDR     r0, [r5], #mi_size
        TST     r0, #mif_lastone
        BEQ     %BT00

        CMP     r1, #-1
        SUBEQ   r1, r7, #1
        MOV     r0, r1                  ; start with current menu item
trynextupdown
        TEQ     r6, #138                ; check for down
        BNE     trymenuupkey
        ADD     r0, r0, #1              ; handle down key
        CMP     r0, r7
        MOVGE   r0, #0                  ; wrap if necessary
        B       %FT10

trymenuupkey
        TEQ     r6, #139                ; check for up
        BNE     %FT20
        SUBS    r0, r0, #1              ; handle up key
        SUBLT   r0, r7, #1              ; wrap if necessary
10
        TEQ     r0, r1                  ; if all menu items grey then don't loop forever
        BEQ     %FT20

        ADR     r14, menuhandles
        LDR     handle, [r14, r4]       ; get menu window handle
        BL      checkhandle
        BVS     %FT20
        Push    "r6,r7"
        BL      menuhighlight
        Pull    "r6,r7"
        BVS     %FT20
        TEQ     r14, #0
        BEQ     trynextupdown           ; if item greyed out then try next
20
Kevin Bracey's avatar
Kevin Bracey committed
2782
        EXITS
Neil Turton's avatar
Neil Turton committed
2783
 ]
Neil Turton's avatar
Neil Turton committed
2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831

;----------------------------------------------------------------------------
; Return to next task with null event
; The 'PollIdle' class of tasks is considered first,
; followed by the 'Poll' tasks (if none of the others have timed-out)
; The current task is taken as the starting point.
;----------------------------------------------------------------------------

nothing
      [ redrawlast
        B       check_redraw

check_null
      ]

        SWI     XOS_ReadMonotonicTime
        BVS     ExitPoll                ; wot?
;
; if an old-style program is running, the other clients are ignored
;
        LDR     R14,polltaskhandle
        LDR     R5,singletaskhandle
        TEQ     R14,R5
        BEQ     nullexit
;
; Wimp_Poll treated as Wimp_PollIdle but with immediate timeout
;
        LDR     R5,nulltaskhandle
        ADD     R5,wsptr,R5             ; R5 --> current task data
        ADD     R5,R5,#4                ; start at next one along
        ADRL    R7,taskpointers+maxtasks*4 ; R7 = wrap address
        MOV     R6,#maxtasks            ; R6 = number to try
01
        CMP     R5,R7
        ADRCSL  R5,taskpointers
        LDR     R4,[R5],#4
        TST     R4,#task_unused
        LDREQ   R14,[R4,#task_flagword]
        TSTEQ   R14,#null_bit
        BNE     %FT02
        TST     R14,#flag_pollidle
        BEQ     returnnull
        LDR     R2,[R4,#task_registers+2*4]
        CMP     R0,R2
        BPL     returnnull              ; time's up! (use PL not CS)
02
        SUBS    R6,R6,#1
        BNE     %BT01
2832
        B       triggercallbacks        ; no 'null return' tasks
Neil Turton's avatar
Neil Turton committed
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846

returnnull

        SUB     R14,R5,#4
        SUB     R14,R14,wsptr           ; R14 = task handle
        STR     R14,nulltaskhandle
        Task    R14,,"Null"

        MOV     R0,#No_Reason           ; null reason code
        B       ExitPoll

nullexit
        LDR     R14,flagword            ; single-tasking exit
        TST     R14,#null_bit
2847
        BNE     triggercallbacks
Neil Turton's avatar
Neil Turton committed
2848 2849 2850
        MOV     R0,#No_Reason           ; null reason code
        B       ExitPoll

2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
triggercallbacks
        ; No null events to deliver, so try triggering callbacks
      [ UseLeaveOS
        SWI     XOS_LeaveOS
      |
      [ Medusa
        MRS     r0, CPSR
        BIC     r0, r0, #&F             ; drop to same 32-bitness of USR mode
        MSR     CPSR_c, r0
      |
        TEQP    pc, #0
        NOP
      ]
        SWI     XOS_IntOn               ; callbacks will be triggered on exit
      ]
        SWI     XOS_EnterOS
        B       repollwimp
Neil Turton's avatar
Neil Turton committed
2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880

;-----------------------------------------------------------
; Remove task from list of tasks with pollwords
;
; In:
;   handle = task to remove (if found)
;
; Out:
;   None, preserves flags
;
;-----------------------------------------------------------


Kevin Bracey's avatar
Kevin Bracey committed
2881
DeletePollTask  EntryS "R0,R1"
Neil Turton's avatar
Neil Turton committed
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
        ADR     R0,PollTasks            ; Get -> start of polltask list
        LDR     R1,PollTaskPtr          ; Get -> first free slot
01
        CMP     R0,R1                   ; End of list?
        EXITS   HS                      ; Yes then exit, not found

        LDR     LR,[R0],#4              ; Get polled task handle
        TEQ     LR,handle               ; Match?
        BNE     %BT01                   ; No then try next polled task

        LDR     LR,[R1,#-4]!            ; Get last entry
        STR     LR,[R0,#-4]!            ; Overwrite current entry
        STR     R1,PollTaskPtr          ; New end of list

        Debug   poll,"Delete poll: handle, posn, new, end",handle,R0,LR,R1

        EXITS



;;----------------------------------------------------------------------------
;; Check tasks' poll words to see if they are non-zero
;;----------------------------------------------------------------------------

; In    R0 = mask word to apply to poll words (only consider if word & R0 set)
; Out   NE => R0=reason code, correct task paged in
;       [userblk,#0] = poll word address
;       [userblk,#4] = poll word contents, as read (once) by Wimp


2912
scanpollwords   Entry "R1-R4"
Neil Turton's avatar
Neil Turton committed
2913 2914 2915 2916 2917 2918 2919 2920 2921 2922
        ADR     R1,PollTasks            ; Get -> start of polltask list
        LDR     R2,PollTaskPtr          ; Get -> first free slot
01
        TEQ     R1,R2                   ; End of list?
        EXIT    EQ                      ; Yes then exit, not found

        LDR     LR,[R1],#4              ; Read polled task handle
        LDR     R3,[LR,wsptr]           ; Read address of task data
        LDR     R3,[R3,#task_pollword]  ; Task pollword
        TST     R3,R0                   ; NE => consider this
Ben Avison's avatar
Ben Avison committed
2923
        LDRNE   R4,[R3]                 ; Read pollword (bottom bit is irrelevant to zero-ness!)
Neil Turton's avatar
Neil Turton committed
2924 2925 2926 2927 2928 2929 2930
        TEQNE   R4,#0                   ; NE => word non-zero!
        BEQ     %BT01                   ; Jump if not found

        Debug   poll,"Pollword non-zero: task,list,address",LR,R1,R3

        Task    LR,,"Poll word"         ; preserves flags
        MOV     R0,#PollWord_NonZero    ; R0 = reason code
Ben Avison's avatar
Ben Avison committed
2931
        BIC     R3,R3,#1
Neil Turton's avatar
Neil Turton committed
2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958
        STMIA   userblk,{R3,R4}

        EXIT                            ; Returns NE




;-----------------------------------------------------------------------------

pendingtime
        Push    "R2,LR"
;
        LDR     R14,timeblk
        LDR     R2,pending_time
        SUB     R14,R14,R2              ; R14 = elapsed time since 1st press
;
        Pull    "R2,PC"                 ; preserves flags


;----------------------------------------------------------------------------
; Routine to select an icon
; Also deselects any other icons in the same ESG
; Entry:  handle,R4 = window/icon to select
;         R2 = button state causing selection
;----------------------------------------------------------------------------

selecticon
Kevin Bracey's avatar
Kevin Bracey committed
2959
        EntryS  "R0-R8"
Neil Turton's avatar
Neil Turton committed
2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010
;
        LDR     R5,[handle,#w_icons]
        ADD     R5,R5,#i_flags

        LDR     R6,[R5,R4,ASL #i_shift]         ; get flags
        ANDS    R14,R6,#if_esg2                 ; get ESG field
        MOVEQ   R2,#0                           ; invert state if on it's own
        BEQ     goselect
;
        TST     R6,#if_canadjust                ; can we select multiply?
        TSTNE   R2,#button_right
        BNE     dontcancel                      ; allow 'adjust' to work
        MOV     R6,R14                          ; get ESG
;
        LDR     R8,[handle,#w_nicons]
sellp
        SUBS    R8,R8,#1
        BMI     dontcancel                      ; finished
        CMP     R8,R4
        BEQ     sellp                           ; ignore this one
;
        LDR     R7,[R5,R8,ASL #i_shift]
        AND     R14,R7,#if_esg2                 ; see if same ESG
        TEQ     R14,R6
        BNE     sellp
;
        TST     R7,#is_inverted
        MOVNE   R0,R8
        MOVNE   R1,#0                   ; EOR value
        MOVNE   R2,#is_inverted         ; BIC value
        BLNE    int_set_icon_state
        B       sellp

dontcancel
        LDR     R2,[R13,#8]             ; get button state again!
        TST     R2,#button_right
        MOVNE   R2,#0
        BNE     goselect                ; invert state if using ADJUST
;
        LDR     R14,[R5,R4,ASL #i_shift]        ; don't bother if already done
        TST     R14,#is_inverted
        BNE     exitselect
;
        MOV     R2,#is_inverted         ; BIC value (ie. set this state)
goselect
        MOV     R0,R4                   ; icon handle
        MOV     R1,#is_inverted         ; EOR value
        BL      int_set_icon_state
;
exitselect
        STRVS   R0,[R13]
Kevin Bracey's avatar
Kevin Bracey committed
3011
        EXITV                           ; preserve V
Neil Turton's avatar
Neil Turton committed
3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025


;;----------------------------------------------------------------------------
;; Wimp system icon detection
;; Entry:  R0,R1 = coords of mouse pointer
;;         R4 = -2 (in system area)
;;         handle -> window definition
;; Exit :  R4 = -2 to -n (corresponding to which icon the pointer is over)
;;         R5 = appropriate flag word
;;         other registers preserved (inc. flags)
;;----------------------------------------------------------------------------

setwimpicon
        CMP     R3,#nullptr
Kevin Bracey's avatar
Kevin Bracey committed
3026
        MOVEQ   PC,LR                           ; forget it!
Neil Turton's avatar
Neil Turton committed
3027 3028 3029 3030 3031 3032 3033 3034 3035
;
        Push    "R2,R3,x0,y0,x1,y1,LR"
;
        MOV     R3,#wf_icon1
        MOV     R4,#1
        LDR     R2,[handle,#w_flags]
01
        TST     R2,R3
        BEQ     %FT02
Kevin Bracey's avatar
Kevin Bracey committed
3036
05
Neil Turton's avatar
Neil Turton committed
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049
        Push    "R0,R1"
        MOV     R0,R4
        BL      calc_w_iconposn
        Pull    "R0,R1"
        CMP     R0,x0
        CMPGT   R1,y0
        CMPGT   x1,R0
        CMPGT   y1,R1
        BLE     %FT02
;        Debug   ub,"on an icon !"
;
        CMP     R4,#5                   ; icon 5 is really 3 icons
        BEQ     check_v_arrows
Ben Avison's avatar
Ben Avison committed
3050
        ADDHI   R4,R4,#2
Neil Turton's avatar
Neil Turton committed
3051 3052
        CMP     R4,#7+2                 ; fudge!
        BEQ     check_h_arrows          ; icon 7 is also really 3 icons
Kevin Bracey's avatar
Kevin Bracey committed
3053
      [ IconiseButton
Ben Avison's avatar
Ben Avison committed
3054
        ADDHI	R4,R4,#3		; and skip -13 (which is the border)
Kevin Bracey's avatar
Kevin Bracey committed
3055
      ]
Neil Turton's avatar
Neil Turton committed
3056
03
3057 3058 3059 3060 3061 3062
      [ BounceClose
        LDRB    R14, buttontype
        TEQ     R14, #0
        ADREQ   R14, wiconflags - 4
        ADRNE   R14, wiconflags_release - 4
      |
Neil Turton's avatar
Neil Turton committed
3063
        ADR     R14,wiconflags-4
3064
      ]
Neil Turton's avatar
Neil Turton committed
3065 3066 3067 3068 3069 3070 3071
        LDR     R5,[R14,R4,ASL #2]
        CMP     R5,#-1
        MOVEQ   R5,#ibt_click:SHL:ib_buttontype
        TSTEQ   R2,#wf_userscroll2      ; debounced form of userscroll
        MOVEQ   R5,#ibt_autorepeat:SHL:ib_buttontype
        MOV     R14,#-1
        SUB     R4,R14,R4               ; R4 in range -2 to -n
Kevin Bracey's avatar
Kevin Bracey committed
3072
        Pull    "R2,R3,x0,y0,x1,y1,PC"
Neil Turton's avatar
Neil Turton committed
3073 3074

check_v_arrows
Neil Turton's avatar
Neil Turton committed
3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088
      [ ChildWindows
        LDR     R14,up_height           ; if scrollbar is small, only the arrows are shown (scaled down)
        LDR     R5,down_height
        ADD     R5,R14,R5
        SUB     R14,y1,y0
        CMP     R5,R14
        BLE     %FT10

        ADD     R14,y0,R14,LSR #1
        CMP     R1,R14
        ADDLT   R4,R4,#2                ; down arrow
        B       %BT03
10
      ]
Neil Turton's avatar
Neil Turton committed
3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099
        LDR     R14,up_height
        SUB     R14,y1,R14
        CMP     R1,R14
        ADDLT   R4,R4,#1                ; not up-arrow
        LDR     R14,down_height
        ADD     R14,y0,R14
        CMP     R1,R14
        ADDLT   R4,R4,#1                ; not middle bit
        B       %BT03

check_h_arrows
Neil Turton's avatar
Neil Turton committed
3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113
      [ ChildWindows
        LDR     R14,left_width          ; if scrollbar is small, only the arrows are shown (scaled down)
        LDR     R5,right_width
        ADD     R5,R14,R5
        SUB     R14,x1,x0
        CMP     R5,R14
        BLE     %FT11

        ADD     R14,x0,R14,LSR #1
        CMP     R0,R14
        ADDGT   R4,R4,#2                ; right arrow
        B       %BT03
11
      ]
Neil Turton's avatar
Neil Turton committed
3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127
        LDR     R14,left_width
        ADD     R14,x0,R14
        CMP     R0,R14
        ADDGT   R4,R4,#1                ; not left-arrow
        LDR     R14,right_width
        SUB     R14,x1,R14
        CMP     R0,R14
        ADDGT   R4,R4,#1                ; not middle bit
        B       %BT03

02
        MOVS    R3,R3,ASL #1
        ADD     R4,R4,#1
        CMP     R4,#8
Kevin Bracey's avatar
Kevin Bracey committed
3128 3129 3130 3131 3132
        BLO     %BT01
      [ IconiseButton
	BHI	%FT04
	LDR	R2,[handle,#w_flags]
	TST	R2,#wf_icon2
3133 3134 3135 3136 3137 3138 3139
	BEQ     %FT04
	LDR     R2, [handle, #w_parent]
	CMP     R2, #-1
	BNE     %FT04
	LDRB    R2, iconisebutton
	TEQ     R2, #0
	BNE     %BT05
Kevin Bracey's avatar
Kevin Bracey committed
3140 3141
04
      ]
Neil Turton's avatar
Neil Turton committed
3142 3143 3144
;
        MOV     R4,#bordericon                          ; in the border
        MOV     R5,#ibt_never :SHL: ib_buttontype       ; has no effect
Kevin Bracey's avatar
Kevin Bracey committed
3145
        Pull    "R2,R3,x0,y0,x1,y1,PC"
Neil Turton's avatar
Neil Turton committed
3146 3147 3148


wiconflags
Kevin Bracey's avatar
Kevin Bracey committed
3149
        DCD     ibt_click        :SHL: ib_buttontype        ; back
3150
        DCD     ibt_click        :SHL: ib_buttontype        ; quit
Neil Turton's avatar
Neil Turton committed
3151 3152 3153 3154 3155 3156 3157 3158 3159 3160
        DCD     ibt_click        :SHL: ib_buttontype        ; move BLOBBY
        DCD     ibt_click        :SHL: ib_buttontype        ; toggle
        DCD     -1                                          ; scup
        DCD     ibt_click        :SHL: ib_buttontype        ; scvert
        DCD     -1                                          ; scdown
        DCD     ibt_click        :SHL: ib_buttontype        ; size
        DCD     -1                                          ; scleft
        DCD     ibt_click        :SHL: ib_buttontype        ; schoriz
        DCD     -1                                          ; scright
bordericon      *       -2 - (.-wiconflags)/4
Kevin Bracey's avatar
Kevin Bracey committed
3161 3162 3163 3164
	[ IconiseButton
	DCD	-1
	DCD	ibt_click        :SHL: ib_buttontype	    ; iconise
	]
3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181

    [ BounceClose
wiconflags_release
        DCD     ibt_clickrelease :SHL: ib_buttontype        ; back
        DCD     ibt_clickrelease :SHL: ib_buttontype        ; quit
        DCD     ibt_click        :SHL: ib_buttontype        ; move BLOBBY
        DCD     ibt_clickrelease :SHL: ib_buttontype        ; toggle
        DCD     -1                                          ; scup
        DCD     ibt_click        :SHL: ib_buttontype        ; scvert
        DCD     -1                                          ; scdown
        DCD     ibt_click        :SHL: ib_buttontype        ; size
        DCD     -1                                          ; scleft
        DCD     ibt_click        :SHL: ib_buttontype        ; schoriz
        DCD     -1                                          ; scright
	[ IconiseButton
	DCD	-1
	DCD	ibt_clickrelease :SHL: ib_buttontype	    ; iconise
Kevin Bracey's avatar
Kevin Bracey committed
3182
	]
3183 3184
    ]

Neil Turton's avatar
Neil Turton committed
3185
wimpaction
Ben Avison's avatar
Ben Avison committed
3186 3187
        CMP     R3,#nullptr             ; is this a real window?
        BLNE    pageinicontask_R3R4     ; takes note of iconbar
Neil Turton's avatar
Neil Turton committed
3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205

        TST     R2,#button_left:OR:button_right
        BEQ     trykeys                         ; menu not allowed here!
        ADR     R14,wiconjump-8
        SUB     PC,R14,R4,ASL #2                ; wow!

wiconjump
        B       wicon_back
        B       wicon_quit
        B       wicon_move
        B       wicon_toggle
        B       wicon_scup
        B       wicon_scvert
        B       wicon_scdown
        B       wicon_size
        B       wicon_scleft
        B       wicon_schoriz
        B       wicon_scright
Kevin Bracey's avatar
Kevin Bracey committed
3206 3207 3208 3209
	[ IconiseButton
	MOV	PC,#0
	B	wicon_iconise
	]
Neil Turton's avatar
Neil Turton committed
3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229


;;----------------------------------------------------------------------------
;; jump destinations for possible wimp icons
;;----------------------------------------------------------------------------

wicon_size
        MOV     R0,#drag_size
        BL      int_drag_box            ; handle,R0 are params
        B       trykeys

wicon_move
        MOV     R0,#drag_posn
        BL      int_drag_box            ; handle,R0 are params
        B       trykeys

wicon_toggle
        MOV     R1,#wf_isapane          ; we want to ignore panes
        BL      go_get_window_state     ; 2nd entry point - uses R1
        LDR     R14,[handle,#w_flags]
Kevin Bracey's avatar
Kevin Bracey committed
3230
      [ togglebits
Neil Turton's avatar
Neil Turton committed
3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261
        TST     R14,#ws_toggled :OR: ws_toggled2
        BIC     R14,R14,#ws_toggled2
      |
        TST     R14,#ws_toggled
      ]
        ORR     R14,R14,#ws_toggling     ; set up to toggle when opened
        ORREQ   R14,R14,#ws_onscreenonce ; keep on-screen this time
        STR     R14,[handle,#w_flags]
        BNE     makesmall
;
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{cx0,cy0,cx1,cy1}
        ADD     R14,handle,#w_bwax0     ; remember old position
        STMIA   R14!,{cx0,cy0,cx1,cy1}
        LDR     x0,[handle,#w_scx]
        LDR     y0,[handle,#w_scy]
        LDR     x1,[handle,#w_bhandle]

        STMIA   R14,{x0,y0,x1}
;
        ADD     R14,handle,#w_wex0      ; add max size to get other coords
        LDMIA   R14,{x0,y0,x1,y1}
        SUB     x1,x1,x0
        SUB     y1,y1,y0
        ADD     cx1,cx0,x1
        SUB     cy0,cy1,y1

; Now check to see if <shift> is depressed, either will do.  If it
; is then attempt to toggle the window to a sensible size, not obscuring
; the icon bar.

Kevin Bracey's avatar
Kevin Bracey committed
3262
        Push    "R0-R2,R4,R6"
Neil Turton's avatar
Neil Turton committed
3263

Neil Turton's avatar
Neil Turton committed
3264 3265 3266 3267 3268 3269
      [ ChildWindows
        LDR     R14,[handle,#w_parent]
        CMP     R14,#nullptr
        BNE     %FT01                   ; this stuff only applies to top-level windows
      ]

Kevin Bracey's avatar
Kevin Bracey committed
3270 3271 3272 3273 3274 3275
	LDR	R4,iconbarheight
	SUB	R4,R4,#8;-40
	LDR	R14,[handle,#w_flags]
	TSTS	R14,#wf_icon7
        LDRNE   R14,hscroll_height
        ADDNE   R4,R4,R14               ; area not to be obscured
Neil Turton's avatar
Neil Turton committed
3276

Kevin Bracey's avatar
Kevin Bracey committed
3277
        SUBS    R6,cy0,R4               ; does the bottom of the window obscure the icon bar?
Neil Turton's avatar
Neil Turton committed
3278 3279 3280 3281 3282 3283
        BGE     %FT01                   ; if not then don't bother faffing around

        MOV     R0,#121
        MOV     R1,#&80
        SWI     XOS_Byte                ; scan for shift being depressed

Kevin Bracey's avatar
Kevin Bracey committed
3284
      [ togglebits
Neil Turton's avatar
Neil Turton committed
3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297
        Push    "R1"
        MOV     R0,#ReadCMOS
        MOV     R1,#FileSwitchCMOS
        SWI     XOS_Byte                ; check for special <shift> toggle action
        TST     R2,#WimpShiftToggleCMOSBit
        Pull    "R1"
        EORNE   R1,R1,#255              ; if active then invert the action
      ]

        TEQ     R1,#&FF
        BNE     %FT01                   ; if it isn't then ignore the munging of the bits

        MOV     cy0,R4
Kevin Bracey's avatar
Kevin Bracey committed
3298 3299 3300
        SUB     cy1,cy1,R6              ; setup the new co-ordinates for bottom & top Y's

	LDR	R6,scry1
3301 3302 3303 3304 3305 3306
      [ togglebits
        LDR     R14, [handle, #w_flags]
        TST     R14, #wf_icon3          ; we can still have a toggle-size button without a title bar!
        LDRNE   R14, title_height
        SUBNE   R6, R6, R14
      |
Kevin Bracey's avatar
Kevin Bracey committed
3307 3308
	LDR	R14,title_height
	SUB	R6,R6,R14
3309
      ]
Kevin Bracey's avatar
Kevin Bracey committed
3310 3311 3312 3313 3314 3315 3316 3317 3318 3319
	LDR	R14,iconbarheight
	SUB	R14,R14,#8
	SUB	R0,R6,R14
	LDR	R14,[handle,#w_flags]
	TSTS	R14,#wf_icon7
	LDRNE	R14,hscroll_height
	SUBNE	R0,R0,R14		; R0 = max window height that can fit on screen
	CMPS	y1,R0
	MOVGT	cy1,R6		        ; window won't fit at maximum extent, so carefully trim
	SUBGT	y1,cy1,cy0
Neil Turton's avatar
Neil Turton committed
3320

Kevin Bracey's avatar
Kevin Bracey committed
3321
      [ togglebits
Neil Turton's avatar
Neil Turton committed
3322 3323 3324 3325 3326
        LDR     R14,[handle,#w_flags]   ; set toggled in silly way bit
        ORR     R14,R14,#ws_toggled2
        STR     R14,[handle,#w_flags]
      ]
01
Kevin Bracey's avatar
Kevin Bracey committed
3327
        Pull    "R0-R2,R4,R6"
Neil Turton's avatar
Neil Turton committed
3328 3329 3330 3331

        ADD     R14,userblk,#u_wax0
        STMIA   R14,{cx0,cy0,cx1,cy1}
;
Kevin Bracey's avatar
Kevin Bracey committed
3332
      [ togglebits
Neil Turton's avatar
Neil Turton committed
3333 3334 3335 3336 3337 3338 3339 3340 3341 3342
        SUB     cx0,cx1,cx0
        SUB     cy0,cy1,cy0             ; work out the area really shown
;
        ASSERT  w_toggleheight = w_togglewidth +4
        ADD     R14,handle,#w_togglewidth
        STMIA   R14,{cx0,cy0}           ; push the co-ordinates away
      ]
;
        BL      calc_w_status           ; ensure bhandle up-to-date

3343 3344 3345
      [ BounceClose
        LDR     R2,pending_buttons      ; Horrible hack so adjust works even with release buttons
      |
Neil Turton's avatar
Neil Turton committed
3346
        LDR     R2,mousebuttons         ; bhandle depends on adjust button
3347
      ]
Neil Turton's avatar
Neil Turton committed
3348 3349 3350

openwindow_checkbuttons
        TST     R2,#button_right        ; if adjust used, open at same level,
3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374
      [ true
        LDR     R14,[handle,#w_bhandle]
        BNE     %FT02
        ; first the special cases: if *this* window is a pane or a foreground window, use a bhandle of -1
        MOV     R4,#wf_isapane
        ORR     R4,R4,#wf_inborder      ; wf_isapane:OR:wf_inborder isn't a valid immediate constant
        LDR     R3,[handle,#w_flags]
        TST     R3,R4
        MOVNE   R14,#nullptr
        BNE     %FT02
        ; now check the windows above us in our window stack: if they're all either panes or foreground
        ; windows, then don't attempt any reordering, otherwise we end up in an endless loop opening
        ; panes in front of their main windows and vice versa, and nobody else gets any processor time
        LDR     R1,[handle,#w_active_link+ll_backwards]
01      LDR     R2,[R1,#ll_backwards]
        CMP     R2,#nullptr             ; if we've reached the front of the window stack
        BEQ     %FT02                   ; then break leaving R14 = current bhandle
        LDR     R3,[R1,#w_flags-w_active_link]
        TST     R3,R4
        MOVNE   R1,R2
        BNE     %BT01
        MOV     R14,#nullptr            ; found a non-pane non-foreground window: move drag window to top of stack
02
      |
Neil Turton's avatar
Neil Turton committed
3375 3376
        MOVEQ   R14,#nullptr            ; otherwise open window at front
        LDRNE   R14,[handle,#w_bhandle]
3377
      ]
Neil Turton's avatar
Neil Turton committed
3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394
        STR     R14,[userblk,#u_bhandle]
;
        B       Exit_OpenWindow


makesmall
        ADD     R14,handle,#w_bwax0
        LDMIA   R14,{cx0,cy0,cx1,cy1,x0,y0,x1}  ; Load previous x0,y0,x1,y1,scx,scy,bhandle

        ; SMC: 18th January 1995
        ; Correct fix for MED-03674, original fix (amg: 28th September 1994) was too simple
        ; and caused MED-04376 which the following also fixes.

        CMP     x1, #nullptr                    ; If this window was at the top
        BEQ     %FT20                           ; then open it there.

        Push    "r2,r3"
Neil Turton's avatar
Neil Turton committed
3395 3396 3397 3398 3399 3400
      [ ChildWindows
        LDR     r14, [handle, #w_parent]            ; depending on whether this window is at the top-level,
        CMP     r14, #nullptr
        LDREQ   r2, activewinds+lh_forwards         ; scan the list of topmost windows
        LDRNE   r2, [r14, #w_children+lh_forwards]  ; or the list of siblings
      |
Neil Turton's avatar
Neil Turton committed
3401
        LDR     r2, activewinds+lh_forwards     ; Otherwise, scan down the list of windows.
Neil Turton's avatar
Neil Turton committed
3402 3403
      ]
        BIC     r3, x1, #3                      ; Align bhandle for comparisons (should really use the Abs macro)
Neil Turton's avatar
Neil Turton committed
3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419
10
        LDR     r2, [r2, #ll_forwards]
        CMP     r2, #nullptr                    ; If we hit the end,
        LDRNE   r14, [r2, #w_flags-w_active_link]
        ANDNE   r14, r14, #wf_backwindow
        TEQNE   r14, #wf_backwindow             ; or if we hit a backwindow
        MOVEQ   x1, #-2                         ; then open our window at the bottom.
        SUBNE   r14, r2, #w_active_link
        TEQNE   r14, handle                     ; If we hit this window???
        TEQNE   r14, r3                         ; or the one to open behind then drop out and open behind stored window
        BNE     %BT10                           ; else go round loop again.
        Pull    "r2,r3"
20

        ADD     R14,userblk,#u_wax0
        STMIA   R14,{cx0,cy0,cx1,cy1,x0,y0,x1}
3420
        B       Exit_OpenWindow
Neil Turton's avatar
Neil Turton committed
3421 3422 3423

wicon_back
        BL      int_get_window_state
Ben Avison's avatar
Ben Avison committed
3424 3425 3426 3427 3428 3429 3430
      [ true
        MOV     R0, #121
        MOV     R1, #&80
        SWI     XOS_Byte                ; Scan keyboard for Shift key
        TEQ     R1, #&FF
      ]
      [ true :LOR: RO4
3431 3432
        LDR     R14,pending_buttons
        AND     R14,R14,#button_right
Ben Avison's avatar
Ben Avison committed
3433
        BEQ     %FT12                   ; Branch if so
3434
        ASSERT  button_right = (nullptr - nullptr2)
Ben Avison's avatar
Ben Avison committed
3435
11      ADD     R14,R14,#nullptr2
3436
      |
Neil Turton's avatar
Neil Turton committed
3437
        MOV     R14,#nullptr2                   ; will not match
3438
      ]
Neil Turton's avatar
Neil Turton committed
3439 3440 3441
        STR     R14,[userblk,#u_bhandle]        ; so will go to bottom
        B       Exit_OpenWindow

Ben Avison's avatar
Ben Avison committed
3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473
      [ true
12      LDR     R0,[userblk,#u_handle]
        Abs     R0,R0
        ADD     R0,R0,#w_active_link
        MOV     R2,#wf_isapane
        ORR     R2,R2,#wf_grabkeys
        TEQ     R14,#button_right
        MOVEQ   R3,#ll_backwards
        MOVNE   R3,#ll_forwards
        BNE     %FT14                   ; need to search 1 window down, or 2 windows up
13      LDR     R0,[R0,R3]
        LDR     R1,[R0,R3]
        CMP     R1,#nullptr             ; hit the stops?
        BEQ     %BT11                   ; yes, so behave as though shift wasn't pressed
        LDR     R1,[R0,#w_flags - w_active_link]
        TST     R1,R2
        BNE     %BT13                   ; skip over any panes or hotkey windows
14      LDR     R0,[R0,R3]
        LDR     R1,[R0,R3]
        CMP     R1,#nullptr             ; hit the stops?
        BEQ     %BT11                   ; yes, so behave as though shift wasn't pressed
        LDR     R1,[R0,#w_flags - w_active_link]
        TST     R1,#wf_backwindow       ; hit a backwindow (presumably going down)?
        BNE     %BT11                   ; don't open behind it!
        TST     R1,R2
        BNE     %BT14                   ; skip over any panes or hotkey windows
        SUB     R0,R0,#w_active_link
        Rel     R0,R0
        STR     R0,[userblk,#u_bhandle]
        B       Exit_OpenWindow
      ]

Kevin Bracey's avatar
Kevin Bracey committed
3474 3475
      [ IconiseButton
wicon_iconise
3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505
        Push	"r0-r4"
      [ MultiClose
        TST     R2, #button_right       ; Ctrl-Alt-*Adjust* isn't special
        MOVNE   R1, #0                  ; flag as due to iconise button
        BNE     %FT20

        MOV     R0, #121
        MOV     R1, #&81                ; Scan keyboard for Ctrl key
        SWI     XOS_Byte
        MOV     R4, R1
        MOV     R1, #&82                ; Scan keyboard for Alt key
        SWI     XOS_Byte
        TEQ     R4, #&FF
        TEQEQ   R1, #&FF
        MOVNE   R1, #0                  ; flag as due to iconise button
        BNE     %FT20

        ; Iconise all top-level windows that have close buttons (except hotkey windows)
        LDR     handle, activewinds + lh_forwards
        SUB     R0, handle, #w_active_link
        Rel     R0, R0
        STR     R0, nextwindowtoiconise
        BL      iconisenextwindow
        Pull    "R0-R4"
        B       trykeys

      |
        MOV     R1, #0                  ; NOT a shift+click on close icon
        B	%FT20
      ]
Kevin Bracey's avatar
Kevin Bracey committed
3506 3507
      ]

Neil Turton's avatar
Neil Turton committed
3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521
wicon_quit
        Push    "r0-r4"

        [ StickyMenus
        LDR     R0,[handle,#w_taskhandle]
        CMP     R0,#-1
        Pull    "r0-r4",EQ
        BEQ     not_alt                 ; can't iconise menu
        ]

        TST     R2,#button_right        ; If adjust, ignore it.
        Pull    "r0-r4",NE
        BNE     not_alt

3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568
      [ MultiClose
        MOV     R0, #121
        MOV     R1, #&81                ; Scan keyboard for Ctrl key
        SWI     XOS_Byte
        MOV     R4, R1
        MOV     R1, #&82                ; Scan keyboard for Alt key
        SWI     XOS_Byte
        TEQ     R4, #&FF
        TEQEQ   R1, #&FF
        BNE     %FT66

      [ BounceClose
        LDR     R2, pending_buttons
        STR     R2, mousebuttons        ; The usual Horrible Hack
      ]
        ; Close all windows at this level that have close buttons (except hotkey windows)
        LDR     handle, [handle, #w_parent]
        CMP     handle, #nullptr
        LDREQ   handle, activewinds + lh_backwards
        LDRNE   handle, [handle, #w_children + lh_backwards]
01      LDR     R0, [handle, #ll_backwards]
        CMP     R0, #nullptr
        BEQ     %FT02
        LDR     R14, [handle, #w_flags - w_active_link]
        TST     R14, #wf_icon2
        ANDNE   R14, R14, #wf_grabkeys
        TEQNE   R14, #wf_grabkeys
        MOVEQ   handle, R0
        BEQ     %BT01
        ; Found such a window; send close request message
        Push    "R0"
        SUB     handle, handle, #w_active_link
        SUB     sp, sp, #4
        Rel     R2, handle
        STR     R2, [sp]
        MOV     R0, #Close_Window_Request
        MOV     R1, sp
        BL      int_sendmessage_fromwimp
        ADD     sp, sp, #4
        Pull    "handle"
        B       %BT01
02
        Pull    "R0-R4"
        B       trykeys
66
      ]

Kevin Bracey's avatar
Kevin Bracey committed
3569
        MOV     R0,#121                 ; Scan keyboard for shift key
Neil Turton's avatar
Neil Turton committed
3570
        MOV     R1,#&80
3571
        SWI     XOS_Byte
Neil Turton's avatar
Neil Turton committed
3572 3573 3574 3575 3576 3577

        CMP     R1,#&FF

        Pull    "r0-r4",NE
        BNE     not_alt

3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637
        [ ChildWindows
        LDR     R0, [handle, #w_parent] ; don't do anything if Shift-close on child windows
        CMP     R0, #-1
        Pull    "r0-r4",NE
        BNE     trykeys
        ]
20
      [ MultiClose
        LDR     r2, mousexpos
        LDR     r4, mouseypos
      ]
        BL      sendiconisemessages
        Pull    "r0-r4"
        B       trykeys

not_alt
        [ StickyMenus
;        LDR     R0,[handle,#w_taskhandle]
;        CMP     R0,#-1
;        BNE     %FT05
        LDR     R14,menuSP
        CMP     R14,#-4
        BEQ     %FT05                           ; no menu open

        LDR     R14,menuhandles
        Abs     R14,R14
        TEQ     handle,R14

        BNE     %FT02
        BL      menusdeleted
        MOVVC   R0,#-4
        BLVC    closemenus
        B       nothing                         ; swallow it.
02
        LDR     R14,menuSP
        ADD     R14,R14,#4
        ADR     R0,menuhandles
03
        LDR     R1,[R0,R14]
        Abs     R1,R1
        TEQ     R1,handle
        BEQ     %FT04
        SUBS    R14,R14,#4
        BGE     %BT03
        B       %FT05
04
        SUB     R0,R14,#4
        BL      closemenus              ; close down to one above
        B       nothing
05
        ]
	[ BounceClose
	STR	R2,mousebuttons		; Horrible hack so apps can tell that adjust was pressed
	]
        STR     R3,[userblk]
        MOV     R0,#Close_Window_Request
        B       ExitPoll

      [ MultiClose
iconisenextwindow
3638
        Entry   "R0-R4,handle"
3639 3640
        LDR     handle, nextwindowtoiconise
        BL      checkhandle             ; make sure it's still valid
Ben Avison's avatar
Ben Avison committed
3641 3642
        TEQVS   PC, #0                  ; \ set Z = not (V)
        TEQVC   R0, R0                  ; /
3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692
        LDREQ   R14, [handle, #w_flags]
        ANDEQ   R0, R14, #ws_open
        CMPEQ   R0, #ws_open            ; and open
        ADDEQ   handle, handle, #w_active_link
        LDRNE   handle, activewinds + lh_forwards ; if not, restart from top
01
        LDR     R0, [handle, #ll_forwards]
        CMP     R0, #nullptr             ; have we reached the header?
        MOVEQ   R0, #0
        STREQ   R0, nextwindowtoiconise
        EXIT    EQ                       ; stop if we have
        LDR     R14, [handle, #w_flags - w_active_link]
        TST     R14, #wf_backwindow
        MOVNE   R0, #0
        STRNE   R0, nextwindowtoiconise
        EXIT    NE                       ; don't re-iconise already-iconised windows!
        TST     R14, #wf_icon2
        ANDNE   R14, R14, #wf_grabkeys
        TEQNE   R14, #wf_grabkeys
        MOVEQ   handle, R0
        BEQ     %BT01
        ; Found a suitable window; work out suitable entry conditions for sendiconisemessages
        Push    "R0"
        SUB     handle, handle, #w_active_link
        MOV     R0, #iconposn_iconise
        BL      calc_w_iconposn          ; x0-y1 = button bbox
        ADD     R2, x0, x1
        ADD     R4, y0, y1
        MOV     R2, R2, LSR#1
        MOV     R4, R4, LSR#1
        MOV     R1, #0
        Rel     R3, handle
        BL      sendiconisemessages
        ; Now store the next window to process (if any)
        Pull    "handle"
        LDR     R0, [handle, #ll_forwards]
        CMP     R0, #nullptr
        MOVEQ   R0, #0
        SUBNE   R0, handle, #w_active_link
        Rel     R0, R0, NE
        STR     R0, nextwindowtoiconise
        EXIT
      ]

sendiconisemessages
; Entry: R1 = &FF => caused by click on close icon; R1 = 0 => caused by click on iconise icon
;        R3 = relative window handle to send
; and if MultiClose enabled,
;        R2 = mouse x
;        R4 = mouse y
3693
        Entry
3694

Kevin Bracey's avatar
Kevin Bracey committed
3695
        [ IconiseButton
3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746
        ; Send a Message_IconizeAt (RML)
        Push    "r3"
        SUB     sp, sp, #48

        CMP     r1, #&FF                 ; If a Shift+Click on close
        MOVEQ   r0, #1                   ; then bit 0 of flags is set
        MOVNE   r0, #0
        STR     r0, [sp, #ms_data+16]

        MOV     r1, sp
      [ MultiClose
        STR     r2, [r1, #ms_data+8]
        SUB     r4, r4, #32+17
        STR     r4, [r1, #ms_data+12]
      |
        LDR     r0, mousexpos
        STR     r0, [r1,#ms_data+8]
        LDR     r0, mouseypos
        SUB     r0, r0, #(32+17)
        STR     r0, [r1,#ms_data+12]
      ]
        MOV     r0, #40
        STR     r0, [r1,#ms_size]        ; size
        MOV     r0, #0
        STR     r0, [r1, #ms_yourref]    ; your ref
        LDR     r0, =Message_IconizeAt   ; (Message number 22)
        STR     r0, [r1, #ms_action]     ; message action
        STR     r3, [r1, #ms_data+0]     ; window handle

        ; Work out task handle
      [ MultiClose
        LDR     R2, [handle, #w_taskhandle]
      |
        LDR     r2, taskhandle
      ]
        LDR     r4, [wsptr, r2]          ; add in version bits (if alive)
        TST     r4, #task_unused
        LDREQ   r4, [r4, #task_flagword]
        MOVEQ   r4, r4, LSR #flag_versionbit
        ORREQ   r2, r2, r4, LSL #flag_versionbit
        STR     r2, [r1, #ms_data+4]

        MOV     r0, #User_Message
        MOV     r2, #0
        BL      int_sendmessage_fromwimp

        ADD     sp, sp, #48
        Pull    "r3"
        ]
                                                ; Shift-quit, send Message_Iconize.
        MOV     R14,#ms_data+8+20       ; size of block (Window,Task,20 byte from title ).
Neil Turton's avatar
Neil Turton committed
3747 3748 3749 3750 3751
        STR     R14,[sp,#-(ms_data+8+20)]!
        MOV     R0,#User_Message
        MOV     R1,sp
        STR     R3,[R1,#ms_data]

3752 3753 3754 3755 3756 3757
      [ MultiClose
        LDR     R2, [handle, #w_taskhandle]
        LDR     R14, [handle, #w_titleflags]
        TST     R14, #if_indirected
        Task    "R2", NE, "Iconise: reading indirected title string"
      |
Neil Turton's avatar
Neil Turton committed
3758
        LDR     R2,taskhandle
3759
      ]
Neil Turton's avatar
Neil Turton committed
3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771
        LDR     R14,[wsptr,R2]          ; add in version bits (if alive)
        TST     R14,#task_unused
        LDREQ   R14,[R14,#task_flagword]
        MOVEQ   R14,R14,LSR #flag_versionbit
        ORREQ   R2,R2,R14,LSL #flag_versionbit
        STR     R2,[R1,#ms_data+4]

        ADD     R2,handle,#w_title
        LDR     R14,[handle,#w_titleflags]
        TST     R14,#if_indirected
        LDRNE   R2,[R2]                     ; If indirected get real address

3772 3773 3774 3775 3776 3777
      [ true
00      LDRB    R3, [R2]  ; always skip leading spaces
        TEQ     R3, #&20
        ADDEQ   R2, R2, #1
        BEQ     %BT00
      ]
Neil Turton's avatar
Neil Turton committed
3778 3779 3780
        MOV     R14,R2                      ; Find first space.
01      LDRB    R3,[R14],#1
        CMP     R3,#&20
Ben Avison's avatar
Ben Avison committed
3781
        BHI     %BT01
Neil Turton's avatar
Neil Turton committed
3782 3783 3784 3785 3786 3787 3788 3789 3790

02      LDRB    R3,[R14]                    ; Go back to last '.'
        CMP     R14,R2
        CMPNE   R3,#"."
        SUBNE   R14,R14,#1
        BNE     %BT02

        CMP     R3,#"."                     ; Skip '.'
        ADDEQ   R14,R14,#1
3791 3792 3793
      [ true
        LDRB    R3, [R14]
        CMP     R3, #&20
Ben Avison's avatar
Ben Avison committed
3794
        MOVLS   R14, R2   ; if we'd get a null string, then jump back to start
3795
      ]
Neil Turton's avatar
Neil Turton committed
3796 3797 3798 3799

        MOV     R4,#ms_data+8
03      LDRB    R3,[R14],#1
        CMP     R3,#&20
Ben Avison's avatar
Ben Avison committed
3800
        BLS     %FT04
Neil Turton's avatar
Neil Turton committed
3801 3802 3803
        STRB    R3,[R1,R4]
        ADD     R4,R4,#1
        CMP     R4,#27+ms_data
Ben Avison's avatar
Ben Avison committed
3804
        BLO     %BT03
Neil Turton's avatar
Neil Turton committed
3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815

04      MOV     R3,#0                      ; Store zero terminator.
        STRB    R3,[R1,R4]

        MOV     R2,#0
        STR     R2,[R1,#ms_yourref]
        LDR     R14,=Message_Iconize
        STR     R14,[R1,#ms_action]
        BL      int_sendmessage_fromwimp
        ADD     sp,sp,#(ms_data+8+20)     ; correct stack

3816
        EXIT
Neil Turton's avatar
Neil Turton committed
3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944

wicon_scup
        TST     R2,#button_right
        BNE     wicon_scdown2
wicon_scup2
        MOV     R14,#32
        LDR     R1,[handle,#w_wey1]             ; can't scroll up past top
        B       scrolly

wicon_scdown
        TST     R2,#button_right
        BNE     wicon_scup2
wicon_scdown2
        MOV     R14,#-32
        LDR     R1,[handle,#w_way0]
        LDR     R2,[handle,#w_way1]
        SUB     R1,R2,R1                        ; height of window
        LDR     R2,[handle,#w_wey0]
        ADD     R1,R2,R1                        ; min y-scroll coord (-ve)

scrolly
        LDR     R0,[handle,#w_flags]
        TST     R0,#wf_userscroll
        MOVNE   R1,#0                           ; x-scroll
        MOVNE   R2,R14,ASR #5                   ; scale down to +-1
        BNE     userscroll
;
        LDR     R0,[handle,#w_scy]
        TEQ     R0,R1
        BEQ     trykeys
;
        Push    R14
        BL      int_get_window_state
        LDR     R14,[handle,#w_bhandle]         ; open at same posn in stack
        STR     R14,[userblk,#u_bhandle]
        LDR     R0,[userblk,#u_scy]
        Pull    R14
        ADD     R0,R0,R14
        STR     R0,[userblk,#u_scy]
;
        B       Exit_OpenWindow

wicon_scleft
        TST     R2,#button_right
        BNE     wicon_scright2
wicon_scleft2
        MOV     R14,#-32
        LDR     R1,[handle,#w_wex0]             ; can't scroll left past wex0
        B       scrollx

wicon_scright
        TST     R2,#button_right
        BNE     wicon_scleft2
wicon_scright2
        MOV     R14,#32
        LDR     R1,[handle,#w_wax0]
        LDR     R2,[handle,#w_wax1]
        SUB     R1,R2,R1                        ; width of window
        LDR     R2,[handle,#w_wex1]
        SUB     R1,R2,R1                        ; max x-scroll coord

scrollx
        LDR     R0,[handle,#w_flags]
        TST     R0,#wf_userscroll
        MOVNE   R1,R14,ASR #5                   ; scale down to +-1
        MOVNE   R2,#0                           ; y-scroll
        BNE     userscroll
;
        LDR     R0,[handle,#w_scx]
        TEQ     R0,R1
        BEQ     trykeys
;
        Push    R14
        BL      int_get_window_state
        LDR     R14,[handle,#w_bhandle]         ; open at same posn in stack
        STR     R14,[userblk,#u_bhandle]
        LDR     R0,[userblk,#u_scx]
        Pull    R14
        ADD     R0,R0,R14
        STR     R0,[userblk,#u_scx]

;
; Get window opened
; Entry:  handle --> window definition
;         userblk --> data (handle,x0,y0,x1,y1,scx,scy,bhandle)
;

Exit_OpenWindow
        BL      calc_w_status                   ; ensure bhandle is correct
        ADD     R14,handle,#w_wax0
        LDMIA   R14!,{cx0,cy0,cx1,cy1}
        LDMIA   userblk,{R0,x0,y0,x1,y1}

        Push    R14
        LDR     R14,dx_1
        BIC     cx0,cx0,R14
        BIC     cx1,cx1,R14
        BIC     x0,x0,R14
        BIC     x1,x1,R14

        LDR     R14,dy_1
        BIC     cy1,cy1,R14
        BIC     cy0,cy0,R14
        BIC     y0,y0,R14
        BIC     y1,y1,R14
        Pull    R14

        TEQ     cx0,x0
        TEQEQ   cy0,y0
        TEQEQ   cx1,x1
        TEQEQ   cy1,y1
        LDMEQIA R14,{cx0,cy0,cx1}               ; scx,scy,bhandle
        ADDEQ   R14,userblk,#5*4                ; skip handle,x0,y0,x1,y1
        LDMEQIA R14,{x0,y0,x1}

        Push R14
        LDR     R14,dx_1
        BIC     cx0,cx0,R14
        BIC     x0,x0,R14

        LDR     R14,dy_1
        BIC     cy0,cy0,R14
        BIC     y0,y0,R14
        Pull    R14

        TEQEQ   cx0,x0
        TEQEQ   cy0,y0
        TEQEQ   cx1,x1
3945 3946 3947 3948
      [ togglebits
        LDR     R14, [handle, #w_flags]         ; don't mask out requests during a toggle operation!
        TSTEQ   R14, #ws_toggling
      ]
Neil Turton's avatar
Neil Turton committed
3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069
        BEQ     trykeys                         ; go to next bit of polling
;
        LDR     R14,[handle,#w_taskhandle]
        CMP     R14,#0                          ; <= 0 ==> system window
   ;    Task    R14,GT,"OpenWindow"     ; force errors into the open!
        MOVGT   R0,#Open_Window_Request
        BGT     ExitPoll
;
        BL      int_open_window         ; menus are opened automatically
        B       repollwimp

userscrollpage
        MOV     R2,R0                   ; R2 = cx0, so it's in R0 instead

userscroll
        Push    "R1,R2"
        BL      int_get_window_state
        LDR     R14,[userblk,#u_handle]         ; open at same posn in stack
        STR     R14,[userblk,#u_bhandle]
        Pull    "R1,R2"
        ADD     R14,userblk,#u_scroll
        STMIA   R14,{R1,R2}
;
        LDR     R14,[handle,#w_taskhandle]
        Task    R14,,"ScrollRequest"
        MOV     R0,#Scroll_Request
        B       ExitPoll

        LTORG


wicon_scvert
        BL      getvscrollcoords
        MOV     R1,#0                   ; x-scroll = 0
        LDR     R14,mouseypos
        CMP     R14,cy0
        MOVLT   R0,#-2                  ; R2 = cx0, so use R0 instead
        BLT     pagevert
        CMP     R14,cy1
        MOVGT   R0,#2
        BGT     pagevert
;
        LDR     R14,[handle,#w_flags]
        TST     R14,#wf_icon7           ; if there is a horizontal scroll bar,
        LDRNE   R14,mousebuttons        ; and the right-hand button is used
        TSTNE   R14,#button_right       ; allow 2-way scrolling
        MOVEQ   R0,#drag_vscroll
        MOVNE   R0,#drag_scrollboth
        BL      int_drag_box
        B       trykeys

wicon_schoriz
        BL      gethscrollcoords
        MOV     R0,#0                   ; y-scroll = 0
        LDR     R14,mousexpos           ; R2 = cx0, so use R0 instead
        CMP     R14,cx0
        MOVLT   R1,#-2
        BLT     pagehoriz
        CMP     R14,cx1
        MOVGT   R1,#2
        BGT     pagehoriz
;
        LDR     R14,[handle,#w_flags]
        TST     R14,#wf_icon5           ; if there is a vertical scroll bar,
        LDRNE   R14,mousebuttons        ; and the right-hand button is used
        TSTNE   R14,#button_right       ; allow 2-way scrolling
        MOVEQ   R0,#drag_hscroll
        MOVNE   R0,#drag_scrollboth
        BL      int_drag_box
        B       trykeys

pagevert
        LDR     R14,mousebuttons        ; reverse direction if r-button used
        TST     R14,#button_right
        RSBNE   R0,R0,#0
;
        LDR     R14,[handle,#w_flags]
        TST     R14,#wf_userscroll
        BNE     userscrollpage
;
        Rel     R1,handle
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{cx0,cy0,cx1,cy1,x0,y0,x1}
        SUB     R14,cy1,cy0
        TEQ     R0,#0                   ; y scroll direction
        ADDPL   y0,y0,R14
        SUBMI   y0,y0,R14
        ASSERT  (u_handle=0)
        STMIA   userblk,{R1,cx0,cy0,cx1,cy1,x0,y0,x1}
        STR     R1,[userblk,#u_bhandle]         ; same posn in stack
;
        B       Exit_OpenWindow

pagehoriz
        LDR     R14,mousebuttons        ; reverse direction if r-button used
        TST     R14,#button_right
        RSBNE   R1,R1,#0
;
        LDR     R14,[handle,#w_flags]
        TST     R14,#wf_userscroll
        BNE     userscrollpage
;
        Rel     R0,handle
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{cx0,cy0,cx1,cy1,x0,y0,x1}
        SUB     R14,cx1,cx0
        TEQ     R1,#0                   ; x scroll direction
        ADDPL   x0,x0,R14
        SUBMI   x0,x0,R14
        ASSERT  (u_handle=0)
        STMIA   userblk,{R0,cx0,cy0,cx1,cy1,x0,y0,x1}
        STR     R0,[userblk,#u_bhandle]         ; same posn in stack
;
        B       Exit_OpenWindow


;;----------------------------------------------------------------------------
;; Get_Pointer_Info - find out where the mouse pointer is
;;----------------------------------------------------------------------------

SWIWimp_GetPointerInfo
4070
        MyEntry "GetPointerInfo"
Neil Turton's avatar
Neil Turton committed
4071 4072 4073 4074 4075
;
        LDR     R0,mousexpos                    ; just read old values
        LDR     R1,mouseypos
        LDR     R2,mousebuttons
        BL      int_get_pointer_info
Kevin Bracey's avatar
Kevin Bracey committed
4076

Ben Avison's avatar
Ben Avison committed
4077 4078
        CMP     R4, #nullptr2
        BNE     %FT01
Kevin Bracey's avatar
Kevin Bracey committed
4079
	LDR     R14,singletaskhandle            ; if single-tasking,
Ben Avison's avatar
Ben Avison committed
4080 4081 4082 4083
	CMP     R14,#nullptr
	MOVNE   R4,#nullptr                     ; don't confuse punter!
        BLEQ    setwimpicon                     ; if new task, work out which icon it is
01
Neil Turton's avatar
Neil Turton committed
4084 4085 4086 4087 4088 4089 4090
        LDR     R14,backwindowhandle
        TEQ     R3,R14
        LDRNE   R14,backwindow                  ; window -1 for either of these
        TEQNE   R3,R14
        MOVEQ   R3,#nullptr
;
        LDR     R14,iconbarhandle
Ben Avison's avatar
Ben Avison committed
4091 4092
        CMP     R14,#nullptr
        BEQ     %FT01
Neil Turton's avatar
Neil Turton committed
4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126
        TEQ     R3,R14
        MOVEQ   R3,#nullptr2                    ; return -2 for iconbar
01
   ;    LDR     R14,oldbuttons                  ; WAS last parameter
        STMIA   userblk,{R0,R1,R2,R3,R4}
        B       ExitWimp


;-----------------------------------------------------------------------------
; getmouseposn - takes note of mouseflags
;-----------------------------------------------------------------------------

getmouseposn
        Push    "LR"
;
        LDR     R14,mouseflags
        TST     R14,#mf_oldcoords
        BIC     R14,R14,#mf_oldcoords   ; test and reset bit
        STR     R14,mouseflags
        BEQ     newmouseposn
;
        LDR     R0,mousexpos
        LDR     R1,mouseypos
        LDR     R2,mousebuttons
        Pull    "PC"
;
newmouseposn
        LDR     R14,mousebuttons
        STR     R14,oldbuttons          ; copy only if want new buttons

        Push    "R3"

        MOV     R3,#0                   ; see if R3 is set up!

Kevin Bracey's avatar
Kevin Bracey committed
4127
      [ mousecache
Neil Turton's avatar
Neil Turton committed
4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151

; if recacheposn is zero then no need to read the mouse values as they
; will not have been updated, instead read from our workspace and
; wait for the value to go non-zero.

        ASSERT  mouseypos = mousexpos +4
        ASSERT  mousebuttons = mouseypos +4
        ASSERT  mousetime = mousebuttons +4

        LDRB    R0,recacheposn
        TEQ     R0,#0                   ; do we have a cached posn for the mouse?
        ADREQ   R0,mousexpos            ; if they are then pick them up from our workspace
        LDMEQIA R0,{R0,R1,R2,R3}
        BEQ     %FT10

        STRB    R3,recacheposn
      ]

        SWI     XOS_Mouse
        LDR     R14,dx_1                ; R14 <- dx-1
        BIC     R0,R0,R14
        LDR     R14,dy_1                ; R14 <- dy-1
        BIC     R1,R1,R14

Kevin Bracey's avatar
Kevin Bracey committed
4152
      [ mousecache
Neil Turton's avatar
Neil Turton committed
4153 4154 4155 4156 4157 4158 4159
        ADR     R14,mousexpos
        STMIA   R14,{R0,R1,R2,R3}
      |
        STR     R0,mousexpos
        STR     R1,mouseypos
        STR     R2,mousebuttons
      ]
4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173
      [ NCErrorBox
        Push    "R0-R6"
        ASSERT  ptrsuspendflag = ptrsuspenddata + 12
        ADRL    R14, ptrsuspenddata
        LDMIA   R14, {R3-R6}

        TEQ     R6, #1                  ; waiting for keyboard-generated move?
        MOVEQ   R3, #2
        STMEQIA R14, {R0-R3}            ; store mouse state and new flag value

        TEQ     R6, #2                  ; waiting for mouse-generated move?
        BNE     %FT06
        TEQ     R0, R3
        TEQEQ   R1, R4
4174
;        TEQEQ   R2, R5
4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187
        BEQ     %FT06                   ; no change

        ADRL    R14, ptrsuspendflag
        MOV     R0, #0
        STR     R0, [R14]               ; store new flag value
        MOV     R0, #106
        MOV     R1, #1
        SWI     XOS_Byte                ; turn on pointer
        TEQ     R1, #0
        SWINE   XOS_Byte                ; just in case it's been turned on by someone else already!
06
        Pull    "R0-R6"
      ]
Neil Turton's avatar
Neil Turton committed
4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208
10
        TEQ     R3,#0                   ; was it set up?
        BEQ     bodgetime
        STR     R3,timeblk
        Pull    "R3,PC"

bodgetime
        Push    "R0-R2"
        MOV     R0,#1
        ADR     R1,timeblk
        SWI     XOS_Word                ; make a note of the time
        Pull    "R0-R3,PC"


;-----------------------------------------------------------------------------
; int_get_pointer_info - called by Poll_Wimp
; look for a match with a window / user icon
; Entry :  R0,R1 = coords of mouse pointer
; Exit :   R3 = window handle (relative)
;          R4 = button index (or -1 if none)
;          handle --> window definition (if any)
Neil Turton's avatar
Neil Turton committed
4209
;          If clicked in work area, [mousexyrel] = relative coordinates
Neil Turton's avatar
Neil Turton committed
4210 4211 4212
;-----------------------------------------------------------------------------

int_get_pointer_info
Neil Turton's avatar
Neil Turton committed
4213

Neil Turton's avatar
Neil Turton committed
4214
        ADRL    R4,activewinds+lh_forwards-ll_forwards
Neil Turton's avatar
Neil Turton committed
4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232
      [ ChildWindows
        MOV     R3,#0                   ; ignore wf_inborder bit for top-level windows
      ]

; In:   R4 -> list head ( activewinds or [handle,#w_children] )
;       R3 = wf_inborder if we're to search only windows which have this bit
;       R3 = 0 if we're to search all windows in the list

int_get_pointer_info_R4                 ; for ChildWindows

      [ ChildWindows
        Push    "userblk,LR"

        MOV     userblk,R3              ; userblk = wf_inborder or 0
      |
        Push    "LR"
      ]

Neil Turton's avatar
Neil Turton committed
4233 4234 4235 4236 4237 4238
findwlp
        LDR     R4,[R4,#ll_forwards]
        LDR     R14,[R4,#ll_forwards]
        CMP     R14,#nullptr
        MOVEQ   R3,#nullptr
        MOVEQ   R4,#nullptr
Neil Turton's avatar
Neil Turton committed
4239 4240 4241
      [ ChildWindows
        Pull    "userblk,PC",EQ
      |
Neil Turton's avatar
Neil Turton committed
4242
        Pull    "PC",EQ
Neil Turton's avatar
Neil Turton committed
4243
      ]
Neil Turton's avatar
Neil Turton committed
4244 4245
        SUB     handle,R4,#w_active_link
        Rel     R3,handle
Neil Turton's avatar
Neil Turton committed
4246 4247 4248 4249 4250 4251 4252 4253

      [ ChildWindows
        LDR     R14,[handle,#w_flags]
        AND     R14,R14,userblk
        TEQ     R14,userblk                     ; ignore window if userblk = wf_inborder and bit not
        BNE     findwlp
      ]

Neil Turton's avatar
Neil Turton committed
4254 4255
        ADD     R14,handle,#w_x0
        LDMIA   R14,{x0,y0,x1,y1}
Neil Turton's avatar
Neil Turton committed
4256

Neil Turton's avatar
Neil Turton committed
4257 4258 4259 4260 4261 4262
        CMP     R0,x0
        CMPGE   R1,y0
        BLT     findwlp
        CMP     x1,R0
        CMPGT   y1,R1
        BLE     findwlp
Neil Turton's avatar
Neil Turton committed
4263

4264
;        Debug   child,"Click within outer box of",handle
Neil Turton's avatar
Neil Turton committed
4265 4266 4267

; decide whether the click is inside or outside the work area

Neil Turton's avatar
Neil Turton committed
4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281
        Push    "R0-R3,R5-R9"
        ADD     R14,handle,#w_wax0
        LDMIA   R14,{cx0,cy0,cx1,cy1,x0,y0}
;
        Push    "cx0,cy0,cx1,cy1"
        LDR     R14,dx
        SUB     cx0,cx0,R14                     ; include border!
        LDR     R14,dy
        SUB     cy0,cy0,R14
        CMP     R0,cx0                          ; check inside work area
        CMPGE   R1,cy0
        CMPGE   cx1,R0
        CMPGE   cy1,R1
        Pull    "cx0,cy0,cx1,cy1"
Neil Turton's avatar
Neil Turton committed
4282
      [ :LNOT: ChildWindows
Neil Turton's avatar
Neil Turton committed
4283
        BLT     noficon2
Neil Turton's avatar
Neil Turton committed
4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305
      ]

; right - a click inside the work area
; first check to see if it's inside any of the window's children

      [ ChildWindows
        Push    "cx0,cy0,cx1,cy1,x0,y0,x1,y1,handle,userblk"
        MOVLT   R3,#wf_inborder                 ; click was in border area (so only scan children that overlap the border)
        MOVGE   R3,#0                           ; click was in work area (scan all children)
        MOV     userblk,R3
        ADD     R4,handle,#w_children + lh_forwards - ll_forwards
        BL      int_get_pointer_info_R4         ; scan child window stack for a hit
        CMP     R3,#nullptr
        ADDNE   SP,SP,#10*4
        STRNE   R3,[SP,#3*4]
        BNE     exitp4                          ; click found in one of the children
        TEQ     userblk,#0
        Pull    "cx0,cy0,cx1,cy1,x0,y0,x1,y1,handle,userblk"
        BNE     noficon2                        ; click was in border area
      ]
;
; now scan the icon list for a hit (starting at the frontmost, ie. the highest-numbered)
Neil Turton's avatar
Neil Turton committed
4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316
;
        SUB     x1,cx0,x0                       ; coords of top-left
        SUB     y1,cy1,y0
        SUB     R0,R0,x1                        ; make mouse coords relative
        SUB     R1,R1,y1
;
        LDR     R4,[handle,#w_nicons]           ; R4 = no of icons
        LDR     R2,[handle,#w_icons]            ; R2 --> start of icons
        ADD     R2,R2,R4,ASL #i_shift           ; R3 --> end of list
ficlp
        SUBS    R4,R4,#1
Ben Avison's avatar
Ben Avison committed
4317
        BMI     noficon                         ; no more left
Neil Turton's avatar
Neil Turton committed
4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347
        SUB     R2,R2,#i_size                   ; point to current icon
;
        LDR     R14,[R2,#i_flags]
        TST     R14,#is_deleted                 ; always ignore deleted icons
        BNE     ficlp
        TST     R14,#is_shaded                  ; only ignore shaded icons
        LDRNE   R14,[handle,#w_taskhandle]      ; if they're not in a menu
        CMPNE   R14,#nullptr                    ; -1 => menu
        BNE     ficlp
;
        ASSERT  (i_bbx0=0)                      ; check LDMIA is OK
        Push    "R2,R3,R4"
        LDMIA   R2,{cx1,cy1,x0,y0}
        CMP     R0,cx1                          ; see if pointer is inside
        CMPGE   R1,cy1
        Pull    "R2,R3,R4"              ; strategic move!
        BLT     ficlp
        CMP     R0,x0
        CMPLT   R1,y0
        BLT     endficon                ; got it!!!
        B       ficlp
;
noficon2
        MOV     R4,#nullptr2            ; if in border, set icon = -2
        B       endficon
noficon
        MOV     R4,#nullptr
endficon
        STR     R0,mousexrel            ; may be needed later
        STR     R1,mouseyrel
Neil Turton's avatar
Neil Turton committed
4348 4349 4350 4351
exitp4                                  ; for ChildWindows
      [ ChildWindows
        Pull    "R0-R3,R5-R9,userblk,PC" ; restore mouse coords etc.
      |
Neil Turton's avatar
Neil Turton committed
4352
        Pull    "R0-R3,R5-R9,PC"        ; restore mouse coords etc.
Neil Turton's avatar
Neil Turton committed
4353
      ]
Neil Turton's avatar
Neil Turton committed
4354 4355

        END