Wimp02 322 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
; 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.Wimp02

;;-----------------------------------------------------------------------------
;; Initialise current task - allocate block from RMA if necessary
;; In   R0 = latest Wimp version known to this task (0 => old-style task)
;; For swapping versions:
;;          If R0 > swapping_version:
;;             R3 -> List of message numbers the task understands terminated
;;                   by a zero word (task must always understand message 0 = Quit !)
;;
;;-----------------------------------------------------------------------------

markinitialised
        Push    "R0-R4,LR"
;
        LDR     R4,taskhandle
        LDR     R2,[wsptr,R4]
        TST     R2,#task_unused         ; in practice task cannot be used!
        BEQ     %FT01                   ; (Wimp_Init calls closedown first)
;
        LDR     R2,pendingtask          ; see if we can grab this one!
        CMP     R2,#0
Ben Avison's avatar
Ben Avison committed
37 38 39
        MOVPL   R14,#nullptr
        STRPL   R14,pendingtask
        BPL     %FT02
Neil Turton's avatar
Neil Turton committed
40
;
Ben Avison's avatar
Ben Avison committed
41
        Push    "R3"
Neil Turton's avatar
Neil Turton committed
42 43
        MOV     R3,#task_datasize
        BL      claimblock
Ben Avison's avatar
Ben Avison committed
44
        Pull    "R3"
Neil Turton's avatar
Neil Turton committed
45 46 47 48 49 50 51 52 53
        BVS     %FT99
;
        MOV     R14,#nullptr            ; null slot if new task
        STR     R14,[R2,#task_slotptr]

        MOV     R14,#0                  ; no fp registers saved
        STR     R14,[R2,#task_fpblock]
        STR     R14,[R2,#task_windows]
        STR     R14,[R2,#task_messagessize]
54
        STR     R14,[R2,#task_vfpcontext]
Neil Turton's avatar
Neil Turton committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

        MOV     R14,#-1
        STR     R14,[R2,#task_messages] ; flag as accepting all messages
02
        Debug   task1,"Task block allocated:",R4,R2,wsptr
        STR     R2,[wsptr,R4]

        LDR     R14,taskcount           ; if task wasn't already initialised
        ADD     R14,R14,#1              ; increment task count
        STR     R14,taskcount

        Debug   task1,"tastcount",#taskcount
01
        Debug   task1,"task pointer, handle =",R2,R4

        LDR     R0,[sp]                 ; latest known Wimp version
        STR     R0,[R2,#task_wimpver]   ; separate copy for each task

; The following things are held for each task ready for swapping to be enabled.

        Debug   task1,"task count =",#taskcount
        Debug   task1,"about to add messages to list"

        LDR     R14,=284                ; R4 = task handle from above.
        CMP     R0,R14
Ben Avison's avatar
Ben Avison committed
80 81
        MOVHS   R14,#0
        MOVLO   R14,#priority_old       ; if old style task then flag as old priorty
Neil Turton's avatar
Neil Turton committed
82 83
        STR     R14,[R2,#task_priority]
        Debug   task1,"task_priority =",R14
Ben Avison's avatar
Ben Avison committed
84
        BLO     %FT01                   ; ignore the messages if not a valid task
Neil Turton's avatar
Neil Turton committed
85

86
        CMP     R3,R3,ASR #31           ; is the handle valid? (-1 pointer still means all messages, for compatibility)
Ben Avison's avatar
Ben Avison committed
87 88 89 90 91 92 93 94 95
        MOVEQ   R14,R3                  ; set all or no messages
        MOVNE   R14,#0                  ; set no messages prior to calling addmessages
        STR     R14,[R2,#task_messages]
        BEQ     %FT01
        BL      addmessages             ; add messages as required
        LDR     R14,[R2,#task_messages]
        TEQ     R14,#0                  ; if still no messages
        MOVEQ   R14,#-1
        STREQ   R14,[R2,#task_messages] ; then they actually wanted all of them
Neil Turton's avatar
Neil Turton committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 195 196 197
01
      [ Swapping                        ; Things to be done only if swapping is enabled.
        ADRL    R1,swapping
        LDR     R3,[R1]
        CMP     R3,#0
        MOVEQ   R14,R3
        BEQ     %FT02                   ; No swap$dir

        ADRL    R0,swap_filename
        LDR     R14,[R0]
        Push    "R14"
        BL      increment_swap_filename
        Pull    "R14"

02      MOV     R0,#0
        STR     R14,[R2,#task_filename]      ; Store name even if error.
        STR     R0,[R2,#task_file]           ; 0 if error.
      ]

        LDR     R14,tasknumber          ; global counter
        ADD     R14,R14,#flag_version   ; increment version number (always)
        BICS    R14,R14,#task_unused    ; ensure top bit unset
        ADDEQ   R14,R14,#flag_version   ; avoid 0!
        STR     R14,tasknumber
        STR     R14,[R2,#task_flagword]

        Debug   task1,"tasknumber =",R14
99
        Debug   task1,"back from markinitialised"

        STRVS   R0,[sp]
        Pull    "R0-R4,PC"


;
; Entry:  if R1 = "TASK", then
;            R0 = latest known Wimp version number * 100
;   (If known version >= 284)    R3 -> List of messages the task wants to receive.
; Exit:   R0 = actual Wimp version number * 100
;         if R1 = "TASK" on entry, then
;            R1 = task handle on exit
;
; In future Wimps, the value of R0 on entry to Wimp_Initialise will be used
;                  to get round any compatibility issues
;

wn_command      DCB     "command",0
                ALIGN
wn_error        DCB     "error",0       ; must be word-aligned
                ALIGN
wn_backwindow   DCB     "backwindow",0
                ALIGN
             [  Swapping
swap_var_name   DCB     "Swap$Dir",0
                ALIGN
swap_limit_name DCB     "Swap$Limit",0
                ALIGN
             ]

svc_closedown   *       0
svc_initialise  *       1

SWIWimp_Initialise
        MyEntry "Initialise"

        Debuga  xx,"Wimp_Initialise: R0 =",R0
        Debug   xx,", taskcount =",#taskcount

        Push    "R0-R3"
        LDR     R14,commandflag         ; watch out for errors later!
        ORR     R14,R14,#cf_suspended   ; NB this stops closedown from
        STR     R14,commandflag         ; setting the command window pending
        MOV     R1,#0                   ; ensure R1 <> "TASK"
        MOV     R2,#svc_initialise
        BL      closedown               ; close down previous task in domain
        STRVS   R0,[sp]
        Pull    "R0-R3"                 ; error can be returned from this!
        BVS     exitinit                ; un-suspends command window
;
        Debug   xx,"taskcount =",#taskcount
;
        LDR     R14,taskcount           ; if more tasks running, ensure that
        TEQ     R14,#0                  ; quit handler has not been set up
        BEQ     initfirsttask
;
        Debug   xx,"taskcount (after) =",#taskcount

    ;   LDR     R14,parentquithandler   ; check for nasty tasks like Twin
    ;   ADRL    R3,Do_ExitHandler
    ;   TEQ     R14,R3                  ; can't allow them to set exit handlers
    ;   XError  WimpCantKill,NE         ; no => "Wimp is currently active"
;
        Debug   xx,"Version requested =",R0
;
        BLVC    checkversion            ; refuse to start up if bad version
        BLVC    markinitialised         ; increase 'task version number'

        ADRVCL  R3,tempiconblk          ; set up key codes
        BLVC    resetkeycodes           ; (but don't remember old settings)
        Debug   task1,"New task:",#taskhandle
;
        B       rationalisememory
198 199 200 201

      [ true ; debug
taskidentifier2 DCB "TASK"
      ]
Neil Turton's avatar
Neil Turton committed
202 203 204 205 206 207
;
; if error window doesn't exist, read it in (before error handler set!)
;
initfirsttask

        Push    "R0-R3"
208 209 210 211
      [ AutoHourglass
        MOV     R0, #0
        STR     R0, hourglass_status   ; note that autohourglass is initially switched off
      ]
212 213 214 215 216 217
;
      [ SwitchingToSprite
        MOV     R0, #0
        STR     R0, switchtospr_current ; initialise both of these as though output is directed to screen
        STR     R0, switchtospr_correctfor
      ]
Neil Turton's avatar
Neil Turton committed
218 219
;
        LDR     R0,currentmode
Ben Avison's avatar
Ben Avison committed
220
        CMP     R0,#-1
ROOL's avatar
ROOL committed
221
        BLEQ    read_current_configd_mode
Neil Turton's avatar
Neil Turton committed
222 223 224 225 226
05
        BL      recalcmodevars          ; before any SWIs are called!
        BL      getromsprites
;
        LDR     R0,tool_area            ; have any tools be pre-loaded?
Kevin Bracey's avatar
Kevin Bracey committed
227
        TEQ     R0,#0
Neil Turton's avatar
Neil Turton committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
        BLEQ    int_toolsprites         ; none already installed so load some new ones
        CLRV                            ; ignore errors - falls back as required
;
      [ :LNOT: Swapping
        Pull    "R0-R3"
      ]
;
      [ Swapping
        ADR     R0,swap_var_name
        ADRL    R1,swap_path
        MOV     R2,#-1
        MOV     R3,#0
        MOV     R4,#3
        SWI     XOS_ReadVarVal

Kevin Bracey's avatar
Kevin Bracey committed
243
        TEQ     R2,#0
Neil Turton's avatar
Neil Turton committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        ADREQL  R0,swapping
        STREQ   R2,[R0]
        BEQ     %FT02              ; No swap directory.

        ADR     R0,swap_var_name
        ADRL    R1,swap_path
        MOV     R2,#256
        MOV     R3,#0
        MOV     R4,#3
        SWI     XOS_ReadVarVal
        BVS     exitinit

        MOV     R0,#"."            ; Add a "." to the string.
        STRB    R0,[R1,R2]
        ADD     R2,R2,#1
        ADRL    R0,swapping
        STR     R2,[R0]

        ADRL    R0,swap_filename
        LDR     R1,=&00414141
        STR     R1,[R0]

        ADR     R0,swap_limit_name ; Get limit of swap space.
        ADRL    R1,errorbuffer
        MOV     R2,#-1
        MOV     R3,#0
        MOV     R4,#3
        SWI     XOS_ReadVarVal

Kevin Bracey's avatar
Kevin Bracey committed
273
        TEQ     R2,#0
Neil Turton's avatar
Neil Turton committed
274 275 276 277 278 279 280 281 282 283 284
        BEQ     %FT02              ; No limit.

        ADR     R0,swap_limit_name ; Get limit of swap space.
        ADRL    R1,errorbuffer
        MOV     R2,#256
        MOV     R3,#0
        MOV     R4,#3
        SWI     XOS_ReadVarVal
        BVS     exitinit

        MOV     R0,#10             ; Read number in base 10.
285
        SWI     XOS_ReadUnsigned
Neil Turton's avatar
Neil Turton committed
286 287 288
        BVS     exitinit

        LDRB    R0,[R1]            ; Get terminator.
Kevin Bracey's avatar
Kevin Bracey committed
289 290
        ORR     R0,R0,#32          ; Make Lowercase
        TEQ     R0,#"m"
Neil Turton's avatar
Neil Turton committed
291
        MOVEQ   R2,R2,ASL #20      ; Convert to bytes.
Kevin Bracey's avatar
Kevin Bracey committed
292
        TEQ     R0,#"k"
Neil Turton's avatar
Neil Turton committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
        MOVEQ   R2,R2,ASL #10      ; Convert to bytes.

02
        ADRL    R0,swapsize
        STR     R2,[R0]
        Debug   swp,"Swap size is ",R2
        MOV     R0,#0
        ADRL    R2,swapused
        STR     R0,[R2]

        Pull    "R0-R3"
      ]

        MOV     R14,#bignum
        STR     R14,lastmode_x1         ; force onto screen first time
        STR     R14,lastmode_y1

        BL      checkversion            ; refuse to start up if bad version
        BLVC    markinitialised         ; increase 'task version number'
        BVS     exitinit
        Debug   task1,"First task:",#taskhandle
;
        MOV     R0,#-1
        SWI     XTerritory_WriteDirection
317 318
        MOVVS   R0,#WriteDirection_LeftToRight
        TST     R0,#WriteDirection_RightToLeft
Neil Turton's avatar
Neil Turton committed
319 320 321 322 323 324 325 326 327 328 329 330
        MOVNE   R0,#-1
        MOVEQ   R0,#0
        STR     R0,writeabledir
        MOVNE   R0,#0
        STR     R0,reversedmenu
        STR     R0,externalcreate
;
        STR     R0,old_icon
        STR     R0,old_window
        STR     R0,special_pointer
;
        STR     R0,IdlePerSec
331 332
        STR     R0,MaxSlowIdleEvents    ; setup ready for speed monitoring
        STR     R0,MaxFastIdleEvents
Neil Turton's avatar
Neil Turton committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
;
        Push    "R0-R2"
 [ Stork
        SWI     XPortable_ReadFeatures
        BVC     %FT01
;
        MOV     R0, #0
        MOV     R1, #0
        SWI     XPortable_Speed         ; attempt to make the portable go fast!
        MOVVC   R1, #PortableFeature_Speed
        MOVVS   R1, #0
01
        AND     R1, R1, #(PortableFeature_Speed :OR: PortableFeature_Idle :OR: PortableFeature_Stop)
        TST     R1, #(PortableFeature_Speed :OR: PortableFeature_Idle)
        STR     R1, WimpPortableFlags
        BEQ     %FT01                   ; don't attach call back routine if no portable
 |
        MOV     R0,#0
        MOV     R1,#0
        SWI     XPortable_Speed         ; attempt to make the portable go fast!
        MOVVC   R0,#-1
        MOVVS   R0,# 0                  ; flag to indicate presence of portable module
        STR     R0,WimpPortableFlag
        BVS     %FT01                   ; don't attach call back routine if no portable
 ]
;
        MOV     R0,#99                  ; call every second (99 due to bug in CallEvery)
        ADRL    R1,CallEveryHandler
        MOV     R2,WsPtr
        SWI     XOS_CallEvery           ; install handler
01
        [ mousecache
        MOV     R0,#TickerV
        ADRL    R1,MouseCallEveryHandler
        BL      claim
;
        MOV     R0,#-1                  ; recache when required
        STRB    R0,recacheposn
        ]

      [ NewErrorSystem
        [ WatchdogTimer
        MOV     R0,#9                   ; ten times a second
        ADRL    R1,BreakWatchdogHandler
        STR     R1,watchdogarea
        MOV     R2,WsPtr
        SWI     XOS_CallEvery
        |
        MOV     R0,#EventV
        ADRL    R1,BreakWatchdogHandler
        MOV     R2,WsPtr
        SWI     XOS_Claim
        MOV     R0,#14
        MOV     R1,#Event_Keyboard
        SWI     XOS_Byte
        ]
      ]
;
      [ outlinefont
        BL      FindFont                ; recache the system font (if possible!)
      ]
;
        CLRV
        Pull    "R0-R2"
;
        LDR     R0,backwindowhandle
Ben Avison's avatar
Ben Avison committed
399 400
        CMP     R0,#nullptr
        BNE     %FT01
Neil Turton's avatar
Neil Turton committed
401 402 403 404 405 406 407 408 409 410
        ADR     R0,wn_backwindow
        MOV     R2,#0
        MOV     R3,#0
        BL      createsystemp
        STRVC   R0,backwindowhandle
        MOVVC   R1,#nullptr2            ; open at back
        BLVC    openfullsize            ; open at full size of screen
        BVS     exitinit
;
        LDR     R0,errorhandle
Ben Avison's avatar
Ben Avison committed
411 412
        CMP     R0,#nullptr
        BNE     %FT01
Neil Turton's avatar
Neil Turton committed
413
        ADR     R0,wn_error
414
        ADRL    R2,errortitle           ; indirected icons go in [errortitle]
Neil Turton's avatar
Neil Turton committed
415 416 417 418 419
        ADRL    R3,errortitend          ; (assume title is first icon)
        BL      createsystemp
        STRVC   R0,errorhandle
        BVS     exitinit
;
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
 [ NewErrorSystem
        LDR     R14, [handle, #w_icons]         ; read important values from the template before they get corrupted

        ADD     R3, R14, #i_size * 1            ; use Continue button as template for default (aka "highligted") buttons
        LDR     R2, [R3, #i_bby0]
        STR     R2, errbut_y0_def
        LDR     R2, [R3, #i_bby1]
        STR     R2, errbut_y1_def
        LDR     R2, [R3, #i_flags]
        BIC     R2, R2, #is_inverted :OR: is_deleted
        STR     R2, errbut_fl_def
        LDR     R2, [R3, #i_data + 4]
        STR     R2, errbut_va_def
        LDR     R2, [R3, #i_bbx0]
        LDR     R3, [R3, #i_bbx1]
        SUB     R2, R3, R2
        STR     R2, errbut_w_def

        ADD     R3, R14, #i_size * 4            ; use Cancel button as template for other buttons
        LDR     R2, [R3, #i_bby0]
        STR     R2, errbut_y0
        LDR     R2, [R3, #i_bby1]
        STR     R2, errbut_y1
        LDR     R2, [R3, #i_flags]
        BIC     R2, R2, #is_inverted :OR: is_deleted
        STR     R2, errbut_fl
        LDR     R2, [R3, #i_data + 4]
        STR     R2, errbut_va
        LDR     R2, [R3, #i_bbx0]
        LDR     R3, [R3, #i_bbx1]
        SUB     R2, R3, R2
        STR     R2, errbut_w

        LDR     R2, [R14, #i_size * 2 + i_bbx0] ; remember distance app sprite is in from the side
        STR     R2, errapp_x0

        LDR     R2, [R14, #i_size * 3 + i_bbx0] ; remember distance error type sprite is in from the side
        STR     R2, errtype_x0

        LDR     R2, [R14, #i_size * 0 + i_bbx0] ; remember distance error message is in from the side
        STR     R2, errmess_x0
 |
Neil Turton's avatar
Neil Turton committed
462 463 464 465 466 467 468 469
        LDR     R14,[handle,#w_icons]
        LDR     R14,[R14,#1*i_size+i_flags]            ; OK box
        AND     R14,R14,#if_fcol:OR:if_bcol
        STR     R14,highlighted_colour
        LDR     R14,[handle,#w_icons]
        LDR     R14, [R14, #4*i_size+i_flags]           ; Cancel box
        AND     R14,R14,#if_fcol:OR:if_bcol
        STR     R14,unhighlighted_colour
470
 ]
Neil Turton's avatar
Neil Turton committed
471 472
01
        LDR     R0,commandhandle
Ben Avison's avatar
Ben Avison committed
473 474
        CMP     R0,#nullptr
        BNE     %FT01
Neil Turton's avatar
Neil Turton committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
;
        ADRL    R0,wn_command           ; for *Copy etc.
        MOV     R2,#0
        MOV     R3,#0
        BL      createsystemp
        STRVC   R0,commandhandle
        BVS     exitinit                ; can't cope without this!
01
;
; if first task, replace its quit handler with mine, and remember old one!
;
        Debug   task1,"Setting up handlers for first task"
;
        MOV     R0,#ExitHandler
        ADRL    R1,Do_ExitHandler
        MOV     R2,wsptr
        ADRL    R3,registerbuffer
        SWI     XOS_ChangeEnvironment
        BVS     exitinit
;
        ADRL    R14,Do_ExitHandler
        TEQ     R1,R14                  ; Is this my own quit handler???
        BEQ     skipupcall              ; if same, we've done this already!
;
        ADR     R14,wimpquithandler
        STMIA   R14,{R1-R3}
;
        MOV     R0,#UpCallV             ; claim upcall at same time
        ADRL    R1,UpCallCode
        BL      claim
;
        SWI     XOS_ReadMonotonicTime   ; reset the counter
        STR     R0,rotatecounter

skipupcall
        BL      setdefaulthandlers      ; looks at [handlerword]
        BL      findpages               ; initialise free pool, if possible

        BVS     exitinit                ; DO THIS FIRST - MEMORY MAY MOVE!!!
;
        ADR     R3,oldfxstatus          ; remember old codes
        BL      resetkeycodes           ; *FX 4,2 etc.
;
518 519 520
      [ true ; debug
        LDR     R5,taskidentifier2       ; if R1="TASK" on entry ...
      |
Neil Turton's avatar
Neil Turton committed
521
        LDR     R5,taskidentifier       ; if R1="TASK" on entry ...
522
      ]
Neil Turton's avatar
Neil Turton committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
        TEQ     userblk,R5
        BEQ     %FT02
;
        BL      int_allbutmode          ; don't set mode/palette if old type
        ADRL    R1,paltable
        MOV     R2,#15
01
        STRB    R2,[R1,R2,LSL #2]       ; set up 1:1 mapping
        SUBS    R2,R2,#1
        BPL     %BT01
02

; deallocate application memory if it isn't being used

rationalisememory
        Debug   task1,"into rationalisememory"

Kevin Bracey's avatar
Kevin Bracey committed
540
      [ :LNOT:Medusa
Neil Turton's avatar
Neil Turton committed
541 542 543
        LDR     R14,freepool            ;; Wimp 1.89o onwards
        CMP     R14,#nullptr            ;; don't bother if no free pool
        BEQ     %FT01                   ;; (keep all the memory)
Kevin Bracey's avatar
Kevin Bracey committed
544
      ]
Neil Turton's avatar
Neil Turton committed
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
        BLVC    testapplication         ; unless application space is in use,
        BCC     %FT01

        Debug   task1,"Application space being used"

      [ Swapping                       ; No need for swap file if no
        Push   "R0"                     ; application memory.
        LDR    R14,taskhandle
        LDR    R14,[wsptr,R14]
        MOV    R0,#0
        STR    R0,[R14,#task_filename]
        Pull    "R0"
      ]
        BLVC    deallocateslot          ; reclaim the memory
        MOVVC   R1,#ApplicationStart
        BLVC    setmemsize              ; rewrite memory limit as well!
01
        DebugE  task1,"exitinit with "
        BVS     exitinit
;

        MOV     R14,#nullptr            ; can't call this while redrawing!
        STR     R14,redrawhandle
        STR     R14,backwindow          ; assume none yet
;
        Debug   task1,"singletaskhandle",#singletaskhandle
;
        LDR     R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
573 574
        CMP     R14,#nullptr
        BEQ     returntaskhandle
Neil Turton's avatar
Neil Turton committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
;
; if old-style Wimp_Init, cover any pre-existing windows
;
        Debug   task1,"Single-tasking"
;
        ADR     userblk,backdef-(w_flags-w_cw0)
        BL      int_create_window
        STRVC   R0,backwindow           ; R0 = relative handle (remember)
        MOVVC   R1,#nullptr             ; R1 = bhandle (open at front)
        BLVC    openfullsize
;
        B       exitinit

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

; Ticker routine called every second if its a portable, install a callback
; handler and then exit.

Kevin Bracey's avatar
Kevin Bracey committed
593
CallEveryHandler Entry "R0-R1"
Neil Turton's avatar
Neil Turton committed
594

Kevin Bracey's avatar
Kevin Bracey committed
595
        [ No32bitCode
Neil Turton's avatar
Neil Turton committed
596 597 598
        MOV     R0,PC
        TEQP    PC,#SVC_mode            ; back to SVC mode IRQs on
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
599 600 601 602 603 604 605
        |
        MRS     R0,CPSR
        BIC     R1,R0,#I32_bit+F32_bit
        ORR     R1,R1,#SVC_mode
        MSR     CPSR_c,R1
        ]
        Push    "R0,LR"                 ; preserve SVC_R0 and SVC_R14
Neil Turton's avatar
Neil Turton committed
606 607 608 609 610

        ADR     R0,callback
        MOV     R1,WsPtr                ; -> callback routine
        SWI     XOS_AddCallBack

Kevin Bracey's avatar
Kevin Bracey committed
611 612
        Pull    "R0,LR"
        [ No32bitCode
Neil Turton's avatar
Neil Turton committed
613 614
        TEQP    PC,R0                   ; back to original mode
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
615 616 617 618
        |
        MSR     CPSR_c,R0
        ]
        Pull    "R0-R1,PC"              ; and then back to original handler
Neil Turton's avatar
Neil Turton committed
619 620 621 622 623 624 625

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

; This ticker gets called every 50hz, it is called to allow the mouse
; co-ordinates to be re-read at a suitable point so that we do not
; continually poll the Window Manager.

Kevin Bracey's avatar
Kevin Bracey committed
626
      [ mousecache
Neil Turton's avatar
Neil Turton committed
627

Kevin Bracey's avatar
Kevin Bracey committed
628
MouseCallEveryHandler
Neil Turton's avatar
Neil Turton committed
629 630 631

        MOV     R0,#-1                  ; flag as needing to re-read mouse posn
        STRB    R0,recacheposn
Kevin Bracey's avatar
Kevin Bracey committed
632
        MOV     PC,LR
Neil Turton's avatar
Neil Turton committed
633 634 635 636 637 638 639 640

      ]

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

; CallBack routine used to update the idle speeds ready for speed control.
; 321nk updated to use PowerUtils 'more inteligent' algorithms.

641
callback Entry "R0-R3"
Neil Turton's avatar
Neil Turton committed
642 643 644 645 646 647

        LDR     r3, IdlePerSec
        MOV     r1, #0                  ; read and then reset, even if not active
        STR     r1, IdlePerSec

        LDR     r0, taskcount
Kevin Bracey's avatar
Kevin Bracey committed
648
        TEQ     r0, #0                  ; r0=0 => Wimp inactive
Neil Turton's avatar
Neil Turton committed
649 650
        LDRNE   r0, commandflag
        EORNES  r0, r0, #cf_active      ; r0=0 => command window active
Kevin Bracey's avatar
Kevin Bracey committed
651
        EXIT    EQ                      ; not active, so don't mess around with speed
Neil Turton's avatar
Neil Turton committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667

 [ Stork
       ;DREG    r3, "Idle count: ",cc,Integer

        LDR     r0, MaxSlowIdleEvents
       ;DREG    r0, "  Slow count: ",cc,Integer
        LDR     r0, MaxFastIdleEvents
       ;DREG    r0, "  Fast count: ",,Integer

        LDR     r2, WimpPortableFlags
        TST     r2, #PowerSave          ; are we in power save mode
        BNE     %FT10
 |
        MOV     r0, #0                  ; read old state
        MOV     r1, #-1
        SWI     XPortable_Speed         ; r0 = old state
Kevin Bracey's avatar
Kevin Bracey committed
668
        EXIT    VS                      ; if an error, don't do anything stupid
Neil Turton's avatar
Neil Turton committed
669 670 671 672 673 674 675 676 677 678

        TEQ     r0, #0
        BNE     %FT10
 ]
; was going fast

        LDR     r0, MaxFastIdleEvents
        Debug   xx,"r3 = ",r3
        SUBS    r0, r0, r0, LSR #5      ; multiply by 31/32 to do decay
        STREQ   r3, MaxFastIdleEvents   ; if we haven't had any yet, then store new max
Kevin Bracey's avatar
Kevin Bracey committed
679
        EXIT    EQ                      ; and exit
Neil Turton's avatar
Neil Turton committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699

        CMP     r3, r0
        MOVGT   r0, r3
        STR     r0, MaxFastIdleEvents

        MOV     r1, r0, LSR #3
        ADD     r1, r1, r1, LSR #1
        SUB     r0, r0, r1              ; r0 = 13/16 of maximum

        CMP     r3, r0
        CMPGT   r3, #Threshold          ; If below threshold, never go slow.
 [ Stork
  [ PokeBorder
VIDC            EQU     &03500000
        LDRGT   r2, =&40FF00FF          ; magenta = slow
        LDRLE   r2, =&40FFFF00          ; cyan = fast
        MOV     r0, #VIDC
        STR     r2, [r0]
        LDR     r2, WimpPortableFlags   ; restore corrupted r2
  ]
Kevin Bracey's avatar
Kevin Bracey committed
700
        EXIT    LE                      ; exit if we want to go fast cos we're already doing so
Neil Turton's avatar
Neil Turton committed
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719

        ORR     r2, r2, #PowerSave      ; indicate power save mode
        STR     r2, WimpPortableFlags
        TST     r2, #PortableFeature_Speed      ; if speed change works
        MOVNE   r0, #1
        MOVNE   r1, #0
        SWINE   XPortable_Speed         ; then issue SWI 'go slow'
                                        ; else we call Portable_Idle elsewhere
 |
  [ PokeBorder
        LDRGT   r2, =&4000080F          ; magenta = slow
        LDRLE   r2, =&400008F0          ; cyan = fast
  ]

        MOVGT   r0, #1                  ; if we want to go slow, then issue SWI
        MOVGT   r1, #0
        SWIGT   XPortable_Speed

  [ PokeBorder
Kevin Bracey's avatar
Kevin Bracey committed
720
VIDC	*	&03400000
Neil Turton's avatar
Neil Turton committed
721 722 723 724
        MOV     r0, #VIDC
        STR     r2, [r0]
  ]
 ]
Kevin Bracey's avatar
Kevin Bracey committed
725
        EXIT
Neil Turton's avatar
Neil Turton committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770

; was going slow

10
        LDR     r0, MaxSlowIdleEvents
        SUB     r0, r0, r0, LSR #5      ; multiply by 31/32 to do decay
        CMP     r3, r0
        MOVGT   r0, r3
        STR     r0, MaxSlowIdleEvents

        MOV     r0, r0, LSR #1          ; r0 = 1/2 of maximum

        CMP     r3, r0
 [ Stork
  [ PokeBorder
        LDRGT   r2, =&40FF00FF          ; magenta = slow
        LDRLE   r2, =&40FFFF00          ; cyan = fast
        MOV     r0, #VIDC
        STR     r2, [r0]
        LDR     r2, WimpPortableFlags   ; restore corrupted r2
  ]
        EXIT    GT                      ; exit if we want to go slow cos we're already doing so

        BIC     r2, r2, #PowerSave      ; full steam ahead
        STR     r2, WimpPortableFlags
        TST     r2, #PortableFeature_Speed      ; if speed change works
        MOVNE   r0, #0
        MOVNE   r1, #0
        SWINE   XPortable_Speed         ; then issue SWI 'go fast'

 |
  [ PokeBorder
        LDRGT   r2, =&4000080F          ; magenta = slow
        LDRLE   r2, =&400008F0          ; cyan = fast
  ]

        MOVLE   r0, #0                  ; if we want to go fast, then issue SWI
        MOVLE   r1, #0
        SWILE   XPortable_Speed

  [ PokeBorder
        MOV     r0, #VIDC
        STR     r2, [r0]
  ]
 ]
Kevin Bracey's avatar
Kevin Bracey committed
771
        EXIT
Neil Turton's avatar
Neil Turton committed
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798

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

; In    R0 = window handle
;       R1 = bhandle (-1 for front, -2 for back)
; Out   window opened at full size of screen

openfullsize
        Push    "cx0-y1,userblk,LR"
;
        ADRVC   R14,scrx0
        LDMVCIA R14,{cx0,cy0,cx1,cy1}   ; dimensions of screen
        MOVVC   x0,#0                   ; scroll x,y
        MOVVC   y0,#0
;
        Push    "R1"                           ; bhandle
        Push    "R0,cx0,cy0,cx1,cy1,x0,y0"     ; handle,x0,y0,x1,y1,scx,scy
        MOVVC   userblk,sp
        BLVC    int_open_window
        ADD     sp,sp,#u_ow1
;
        Pull    "cx0-y1,userblk,PC"

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

; In    R3 -> save area for old key settings
; Out   *fx 4,2 : *fx 219,&8A : *fx 221,2 .. 228,2 : *fx 229,1 : *fx 124
Kevin Bracey's avatar
Kevin Bracey committed
799
;       *fx 9,0 : *fx 10,0
Neil Turton's avatar
Neil Turton committed
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826

resetkeycodes
        Push    "LR"
;
        Debug   task1,"setting up key codes: R12,R13,R3 =",R12,R13,R3
;
        MOV     R0,#4
        MOV     R1,#2
        SWI     XOS_Byte                ; *FX 4,2
        STRB    R1,[R3],#1
;
        MOV     R0,#219
        MOV     R1,#&8A                 ; *FX 219,&8A (TAB key)
        MOV     R2,#0
        SWI     XOS_Byte
        STRB    R1,[R3],#1
;
        MOV     R0,#221
01
        Push    "R0"
        MOV     R1,#2
        MOV     R2,#0
        SWI     XOS_Byte                ; *FX 221,2 to *FX 228,2
        Pull    "R0"
        STRB    R1,[R3],#1
        ADD     R0,R0,#1
        CMP     R0,#228
Ben Avison's avatar
Ben Avison committed
827
        BLS     %BT01
Kevin Bracey's avatar
Kevin Bracey committed
828 829 830 831 832 833 834 835 836 837
;
        MOV     R0,#9
        MOV     R1,#0
        SWI     XOS_Byte
        STRB    R1,[R3],#1

        MOV     R0,#10
        MOV     R1,#0
        SWI     XOS_Byte
        STRB    R1,[R3],#1
Neil Turton's avatar
Neil Turton committed
838 839
;
        LDR     R14,singletaskhandle
Ben Avison's avatar
Ben Avison committed
840 841
        CMP     R14,#nullptr            ; old Wimp didn't set up escape!
        BNE     noescape                ; NB old tasks can't start others!
Neil Turton's avatar
Neil Turton committed
842 843 844 845 846 847 848 849 850 851 852 853
;
        MOV     R0,#229                 ; *FX 229,1 (escape ==> ascii 27)
        MOV     R1,#1
        MOV     R2,#0
        SWI     XOS_Byte
        STRB    R1,[R3],#1
;
        MOV     R0,#124                 ; clear escape condition (if any)
        SWI     XOS_Byte

noescape
        Debug   task1,"key codes reset"
Kevin Bracey's avatar
Kevin Bracey committed
854 855
        CLRV
        Pull    "PC"                    ; ignore errors
Neil Turton's avatar
Neil Turton committed
856 857 858

backdef
        DCD     wf_autoredraw:OR:wf_nochecks:OR:wf_backwindow
Kevin Bracey's avatar
Kevin Bracey committed
859
        DCB     0,0,0,4, 0,0,0,0
Neil Turton's avatar
Neil Turton committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
        DCD     0,-bignum,bignum,0
        DCD     0                               ; title flags
        DCD     ibt_never:SHL:ib_buttontype     ; work area flags
        DCD     0                               ; areaCBptr
        DCD     0                               ; reserved
        DCD     0,0,0                           ; title
        DCD     0                               ; no of icons
endbackdef
        ASSERT  (endbackdef-backdef) = (w_cw1-w_flags)

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

; if R1 = "TASK" on entry, return R1 = task handle on exit
;                          send TaskInitialise broadcast as well

returntaskhandle
        BL      fulltaskhandle          ; R14 = handle including version bits
        STR     R14,[sp,#0*4]           ; overwrite value of R1 on stack
;
879
        MOV     R0,#ApplicationSpaceSize; do this now cos R0 needed
Neil Turton's avatar
Neil Turton committed
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
        MOV     R1,#0
        SWI     XOS_ChangeEnvironment
        SUB     R5,R1,#ApplicationStart ; data + 4
;
        LDR     R0,[sp,#1*4]            ; send message including name
        BL      count0                  ; R1 = length of string (inc. 0)
        ADD     R1,R1,#3
        BIC     R1,R1,#3                ; align to word boundary
        ADD     R1,R1,#ms_data+8
        STR     R1,[sp,-R1]!            ; set up message block on stack
;
      [ debugxx
        ADD     R1,sp,R1
        LDMIA   R1,{R1,R2}
        Debuga  xx,", handle =",R1
        DebugS  xx,", name =",R2
      ]
;
        BL      readCAOpointer                  ; R2 = CAO pointer
        MOV     R4,R2
        MOV     R2,#0                           ; your ref
        LDR     R3,=Message_TaskInitialise      ; action
;
        ADD     R1,sp,#ms_yourref               ; R5 set up earlier!
        STMIA   R1!,{R2-R5}
        LDRB    R14,[R0]
906
        TEQ     R14,#"\\"
Neil Turton's avatar
Neil Turton committed
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
        ADDEQ   R0,R0,#1
        BL      copy0                   ; copy from [R0] to [R1]
;
        MOV     R0,#User_Message
        MOV     R1,sp
        MOV     R2,#0                   ; broadcast
        BL      int_sendmessage         ; send from this task
        LDR     R14,[sp]
        ADD     sp,sp,R14               ; correct stack
        BVS     exitinit
;
        LDR     R14,commandflag
        TEQ     R14,#cf_pending:OR:cf_suspended
        LDRNE   R0,currentmode          ; reset mode if nasties have occurred
;        ADRNEL  R14,wimpmodebefore
;        LDRNEB  R14,[R14]
;        TEQNE   R14,#1                  ; mode already changed
        BLNE    int_setmode             ; command window suspended, so it's OK

exitinit
        Debug   task1,"exitinit; command flag =",#commandflag

        LDR     R14,commandflag         ; un-suspend window,
        BIC     R14,R14,#cf_suspended
        STR     R14,commandflag
        MOVVC   R0,#-1                  ; then get rid of it if no errors!
        SWIVC   XWimp_CommandWindow
;
Kevin Bracey's avatar
Kevin Bracey committed
935
        LDRVC   R0,=Module_Version      ; R0 = Wimp version number
Neil Turton's avatar
Neil Turton committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
        B       ExitWimp
        LTORG

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

; In    R1 = "TASK" => R0 = latest known Wimp version
;       otherwise this is an old-style task
; Out   R0 = latest known Wimp version (0 if old-style task)
;       [singletaskhandle] = [taskhandle] if old-style task
;       [singletaskhandle] = -1 if new-style task
;       Error if R1 = "TASK" but R0 looks invalid

checkversion
        Push    "LR"

951
        LDR     R14,taskidentifier2
Neil Turton's avatar
Neil Turton committed
952 953 954 955 956 957 958 959 960 961
        TEQ     R1,R14
        MOVEQ   R14,#nullptr           ; new-style tasks are not single-tasking
        LDRNE   R14,taskhandle
        STR     R14,singletaskhandle
        MOVNE   R0,#0
        STRNEB  R0,modechanged          ; don't deliver if old-style task
        Pull    "PC",NE                 ; a mode change will occur on exit

     [ true
        CMP     R0,#200                 ; must be AT LEAST version 2.00
Ben Avison's avatar
Ben Avison committed
962
        BLO     %FT01
Neil Turton's avatar
Neil Turton committed
963
        CMP     R0,#300
Ben Avison's avatar
Ben Avison committed
964 965
        MOVLO   R0,#200
        TEQLO   R0,R0                   ; If 200 <= v < 300 Then v=200 !
Neil Turton's avatar
Neil Turton committed
966 967
        BEQ     %FT01
       [ true
Neil Turton's avatar
Neil Turton committed
968 969 970 971
       [ ChildWindows
        TEQ     R0,#380
        LDRNE   R0,=310                 ; unless v=380, set v=310
       |
Neil Turton's avatar
Neil Turton committed
972
        LDR     R0,=310                 ; IF v>300 Then v=310
Neil Turton's avatar
Neil Turton committed
973
       ]
Neil Turton's avatar
Neil Turton committed
974 975 976 977
        TEQ     R0,R0
        |
        LDR     R14,=310
        CMP     R0,R14
Ben Avison's avatar
Ben Avison committed
978 979
        MOVLO   R0,R14                 ; If 300 < v < 310 Then v=310
        TEQLO   R0,R0                   ; If 200 <= v < 300 Then v=200 !
Neil Turton's avatar
Neil Turton committed
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
       ]
01
      [ true
        MyXError  WimpBadVersion,NE
        |
        Push    "R0-R3"
        MyXError  WimpBadVersion,NE
        MOVNE   R1,#0
        SWINE   XWimp_ReportError       ; Report the error, but don't return it !
        Pull    "R0-R3"
      ]
     |
        RSBCSS  R14,R0,#10240           ; assume version 102.40 is latest!
        MyXError  WimpBadVersion,CC
     ]

        Pull    "PC"
        MakeErrorBlock WimpBadVersion

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

; Entry:  [taskhandle] = task index
; Exit:   R14 = full task handle (including version number)

fulltaskhandle
        Push    "R1,LR"
        LDR     R1,taskhandle
        LDR     R14,[wsptr,R1]
        LDR     R14,[R14,#task_flagword]
        MOV     R14,R14,LSR #flag_versionbit
        ORR     R14,R1,R14,LSL #flag_versionbit
        Pull    "R1,PC"

1013 1014
        LTORG

Neil Turton's avatar
Neil Turton committed
1015 1016 1017 1018 1019 1020 1021 1022
;;------------------------------------------------------------------------------
;; in   R0=0 => print syntax message only
;;      R0=1 => *Status WimpMode was typed - print out value
;;      R0-> command tail => *Configure WimpMode <mode>
;; out  if *configure, CMOS RAM configured
;;                     [currentmode] or [sysflags] reset
;;-----------------------------------------------------------------------------

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
    [ true
; New configuration code that isn't as closely tied to the CMOS byte involved
; (most bytes are now shared by multiple options)

        MACRO
$lab    ConfigOption $string, $unit, $cmosbyte, $cmosbit, $cmossize, $shift, $eor, $expbyte, $expbit, $intvar, $intmul, $intbyte, $lut, $num
        ; $string:   tail of label for status string
        ; $unit:     (optional) tail of label for unit token string
        ; $cmosbyte: byte to read for mantissa
        ; $cmosbit:  (default 0) minimum significant bit
        ; $cmossize: (default 8) number of significant bits
        ; $shift:    non-null means don't shift mantissa bitfield down when reading (to make lsb=0)
        ; $eor:      (optional) value to EOR with mantissa read from CMOS
        ; $expbyte:  (optional) byte holding 1-bit exponent
        ; $expbit:   (optional) bit holding 1-bit exponent
1038
        ; $intvar:   (optional) internal variable to set to value
1039 1040 1041 1042
        ; $intmul:   non-null means store value * 10 in internal variable
        ; $intbyte:  B => store as byte value
        ; $lut:      (optional) label for table of <8 char strings to use for each value
        ; $num:      non-null means table contains 32-bit words instead
1043
        Entry   "R7-R11"
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
        LDR     wsptr, [R12]
        CMP     R0, #1
        BHI     %FT02
        BEQ     %FT01

        ; Print syntax string
        ADRL    R0, configmess_$string
        SWI     XOS_Write0
        EXIT

        ; Print status string
01      ADR     R0, statusmess_$string
        SWI     XOS_Write0
        MOVVC   R0, #ReadCMOS
        MOVVC   R1, #$cmosbyte
        SWIVC   XOS_Byte
        [ "$expbyte" <> "" :LAND: "$expbit" <> ""
        [ $expbyte = $cmosbyte
        MOVVC   R4, R2                  ; remember, to save another CMOS read later
        ]
        ]
        [ "$cmosbit" <> "" :LAND: "$cmossize" <> ""
        ANDVC   R2, R2, #((1 :SHL: $cmossize) - 1) :SHL: $cmosbit
        [ "$shift" = "" :LAND: $cmosbit <> 0
        MOVVC   R2, R2, LSR#$cmosbit
        ]
        ]
        [ "$eor" <> ""
        [ $eor <> 0
        EORVC   R2, R2, #$eor
        ]
        ]
        [ "$expbyte" <> "" :LAND: "$expbit" <> ""
        MOVVC   R3, R2
        [ $expbyte = $cmosbyte
        MOVVC   R2, R4                  ; get value read earlier
        |
        MOVVC   R0, #ReadCMOS
        MOVVC   R1, #$expbyte
        SWIVC   XOS_Byte
        ]
        TSTVC   R2, #1 :SHL: $expbit    ; preserves V
        ADDNE   R3, R3, R3, LSL#2
        MOVNE   R2, R3, LSL#1           ; multiply by 10
        MOVEQ   R2, R3
        ]
        [ "$lut" = ""
        SUB     sp, sp, #4              ; buffer space
        MOVVC   R0, R2
        MOVVC   R1, sp
        MOVVC   R2, #4
        SWIVC   XOS_ConvertCardinal1
        SWIVC   XOS_Write0
        ADD     sp, sp, #4
        |
        ADRVCL  R0, $lut
        [ "$num" = ""
        ADDVC   R0, R0, R2, LSL#3       ; strings are at 8-byte intervals
        SWIVC   XOS_Write0
        |
        ADDVC   R0, R0, R2, LSL#2       ; ints are at 4-byte intervals
        SUB     sp, sp, #12             ; buffer space
        LDRVC   R0, [R0]
        MOVVC   R1, sp
        MOVVC   R2, #12
        SWIVC   XOS_ConvertCardinal4
        SWIVC   XOS_Write0
        ADD     sp, sp, #12
        ]
        ]
        [ "$unit" <> ""
        ADRVCL  R0, statusmess_$unit
        BLVC    QuickLookup
        SWIVC   XOS_WriteN
        ]
        SWIVC   XOS_NewLine

        TEQ     PC, #0                  ; get around kernel bug: Z must be clear on exit
        EXIT

02      ; Set configuration - uses another macro due to assembler's limit on macro size
        SetConfig $string, $unit, $cmosbyte, $cmosbit, $cmossize, $shift, $eor, $expbyte, $expbit, $intvar, $intmul, $intbyte, $lut, $num
        MEND

        MACRO
$lab    SetConfig $string, $unit, $cmosbyte, $cmosbit, $cmossize, $shift, $eor, $expbyte, $expbit, $intvar, $intmul, $intbyte, $lut, $num
        [ "$lut" = "" :LOR: ("$lut" <> "" :LAND: "$num" <> "")
        MOV     R1, R0
        MOV     R0, #10 :OR: 1:SHL:31   ; base 10, terminate at control char or space
        SWI     XOS_ReadUnsigned
        EXIT    VS
        [ "$lut" <> "" :LAND: "$num" <> ""
        ADRL    R0, $lut
        BL      status_scaninttable
        ]
        |
        ADRL    R4, $lut
        BL      status_scanstringtable
        EXIT    VS
        ]

        ; Restrict R2 to a valid value, calculate mantissa (R3) and exponent (R4) if applicable
        [ "$shift" <> ""
        MOV     R2, R2, LSR #$cmosbit
        ]
          [ "$cmossize" <> ""
        CMP     R2, #(1 :SHL: $cmossize) - 1
          |
        CMP     R2, #&FF
          ]
        [ "$expbyte" = ""
          [ "$cmossize" <> ""
        MOVHI   R2, #(1 :SHL: $cmossize) - 1
          |
        MOVHI   R2, #&FF
          ]
        |
Ben Avison's avatar
Ben Avison committed
1161 1162 1163
        MOVLS   R3, R2
        MOVLS   R4, #0
        BLS     %FT07
1164
        DivRem  R3, R2, #10, R0, norem   ; R3 = R2 DIV 10
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
        CMP     R3, #((1 :SHL: $cmossize) - 1) / 10 ; do we need to round down to 15?
        MOVEQ   R3, #(1 :SHL: $cmossize) - 1
        MOVEQ   R4, #0
        MOVHI   R4, #1
        CMP     R3, #(1 :SHL: $cmossize) - 1
        MOVHI   R3, #(1 :SHL: $cmossize) - 1
07      MOV     R2, R3, LSL R4
        TEQ     R4, #0
        ADDNE   R2, R2, R2, LSL #2
        ]

        [ "$intvar" <> ""
        [ "$shift" <> ""
        MOV     R1, R2, LSL #$cmosbit
        |
        MOV     R1, R2
        ]
        [ "$intmul" <> ""
        MOV     R1, R1, LSL#1
        ADD     R1, R1, R1, LSL#2
        ]
        [ "$lut" <> "" :LAND: "$num" <> ""
        ADRL    R0, $lut
        LDR     R1, [R0, R1, LSL#2]
        ]
        STR$intbyte R1, $intvar
        ]
        [ "$intvar" = "preferredpool" ; special case
        TEQ     R1, #0
        LDR     R0, baseofsprites
        STREQ   R0, baseofhisprites
        STRNE   R0, baseoflosprites
        LDR     R0, baseofromsprites
        STREQ   R0, baseoflosprites
        STRNE   R0, baseofhisprites
        [ windowsprite
1201 1202 1203 1204
	 [ ThreeDPatch
        MOV     R0, #0
	BL	reset_all_tiling_sprites
	 |
1205 1206
        MOV     R0, #-1
        STR     R0, tiling_sprite
1207
         ]
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
        ]
        BL      freelist ; mark cached sprite list invalid
        ]

        [ "$expbyte" = ""
          [ "$eor" <> ""
          [ $eor <> 0
          [ "$shift" <> ""
        EOR     R2, R2, #$eor :SHR: $cmosbit
          |
        EOR     R2, R2, #$eor
          ]
          ]
          ]
          [ "$cmosbit" <> "" :LAND: "$cmossize" <> ""
        MOV     R3, R2
        MOV     R0, #ReadCMOS
        MOV     R1, #$cmosbyte
        SWI     XOS_Byte
        EXIT    VS
        BIC     R2, R2, #((1 :SHL: $cmossize) - 1) :SHL: $cmosbit
        ORR     R2, R2, R3, LSL #$cmosbit
          |
        MOV     R1, #$cmosbyte
          ]
        MOV     R0, #WriteCMOS
        SWI     XOS_Byte
        |

          [ "$eor" <> ""
          [ $eor <> 0
        EOR     R3, R3, #$eor
          ]
          ]
        [ "$cmosbyte" = "$expbyte"
        MOV     R0, #ReadCMOS
        MOV     R1, #$cmosbyte
        SWI     XOS_Byte
        EXIT    VS
        BIC     R2, R2, #(((1 :SHL: $cmossize) - 1) :SHL: $cmosbit) + (1 :SHL: $expbit)
        ORR     R2, R2, R3, LSL #$cmosbit
        ORR     R2, R2, R4, LSL #$expbit
        MOV     R0, #WriteCMOS
        SWI     XOS_Byte
        |

        MOV     R0, #ReadCMOS
        MOV     R1, #$cmosbyte
        SWI     XOS_Byte
        EXIT    VS
        BIC     R2, R2, #((1 :SHL: $cmossize) - 1) :SHL: $cmosbit
        ORR     R2, R2, R3, LSL #$cmosbit
        MOV     R0, #WriteCMOS
        SWI     XOS_Byte
        EXIT    VS
        MOV     R0, #ReadCMOS
        MOV     R1, #$expbyte
        SWI     XOS_Byte
        EXIT    VS
        BIC     R2, R2, #1 :SHL: $expbit
        ORR     R2, R2, R4, LSL #$expbit
        MOV     R0, #WriteCMOS
        SWI     XOS_Byte
        ]
        ]

        EXIT
        MEND

status_scaninttable
; In:  R0 -> increasing integer table (terminated by -1)
;      R2 = number to match
; Out: R2 = index into table of best match
1281
        Entry
1282 1283 1284 1285 1286 1287
        MOV     R4, R2
        MOV     R1, #0
01      LDR     R3, [R0, R1, LSL #2]
        CMP     R4, R3
        MOVHS   R2, R1
        ADD     R1, R1, #1
Ben Avison's avatar
Ben Avison committed
1288 1289
        CMP     R3, #-1
        BNE     %BT01
1290 1291 1292 1293 1294 1295
        EXIT

status_scanstringtable
; In:  R0 -> string to match case-insensitively (not null terminated)
;      R4 -> array of null-terminated strings, starting at 2-word boundaries (terminates with a null string)
; Out: R2 = index into array of match, or V set if no match
1296
        Entry
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
        MOV     R3, sp
        SUB     sp, sp, #12 ; must be at least 2 longer than longest string
        MOV     R2, sp
03      LDRB    R1, [R0], #1
        CMP     R1, #' '
        MOVLS   R1, #0 ; also terminate at spaces
        STRB    R1, [R2], #1
        TEQ     R2, R3
        BNE     %BT03
        MOV     R0, #0
        STRB    R0, [R2, #-1] ; just in case
        MOV     R5, #0
        MOV     R6, #-1
        MOV     R1, sp
        MOV     R3, #Collate_IgnoreCase
04      ADD     R2, R4, R5, LSL #3
        LDRB    R14, [R2]
        TEQ     R14, #0
        BEQ     %FT05 ; this signifies the end of the table
        MOV     R0, #1 ; * commands are all in English
        SWI     XTerritory_Collate
        EXIT    VS
        MOVEQ   R6, R5
        ADD     R5, R5, #1
        B       %BT04
05      ADD     sp, sp, #12 ; matches with above
Ben Avison's avatar
Ben Avison committed
1323 1324 1325
        CMP     R6, #-1
        MOVNE   R2, R6
        EXIT    NE
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
        MOV     R0, #0 ; "Bad configure option"
        SETV
        EXIT

; Units tokens for *Status
statusmess_osunits              DCB     "OSUnits",0
statusmess_ds                   DCB     "DeciSec",0
statusmess_osupersec            DCB     "OSUperSec",0
statusmess_osupersec2           DCB     "OSUperSec2",0
        ALIGN
status_offon                    DCB     "Off",0,0,0,0,0,"On",0,0,0,0,0,0,0,0,0,0
status_ramrom                   DCB     "RAM",0,0,0,0,0,"ROM",0,0,0,0,0,0,0,0,0
status_clickrelease             DCB     "Click",0,0,0,  "Release",0,0,0,0,0
1339
        ALIGN
1340 1341 1342 1343 1344

; Code for handling *Configure/*Status
WimpFlagsC_Code
    ConfigOption flags,,WimpFlagsCMOS,,,,,,,sysflags,,B
statusmess_flags                DCB     "WimpFlags  ",0
Ben Avison's avatar
Ben Avison committed
1345
configmess_flags                DCB     "WimpFlags  <D>",lf,cr,0
1346
        ALIGN
1347 1348 1349 1350

WimpFontC_Code
    ConfigOption wimpfont,,DesktopFeaturesCMOS,1,4
statusmess_wimpfont             DCB     "WimpFont   ",0
Ben Avison's avatar
Ben Avison committed
1351
configmess_wimpfont             DCB     "WimpFont   <D>",lf,cr,0
1352
        ALIGN
1353 1354 1355 1356

WimpDragDelayC_Code
    ConfigOption dragdelay,ds,WimpDragTimeCMOS,0,4,,default_drag_timelimit,WimpDragMoveLimitCMOS,0,drag_timelimit,x10
statusmess_dragdelay            DCB     "WimpDragDelay  ",0
Ben Avison's avatar
Ben Avison committed
1357
configmess_dragdelay            DCB     "WimpDragDelay  <D>",lf,cr,0
1358
        ALIGN
1359 1360 1361 1362

WimpDragMoveC_Code
    ConfigOption dragmove,osunits,WimpDragMoveLimitCMOS,2,5,noshift,default_drag_movelimit,,,drag_movelimit,,B
statusmess_dragmove             DCB     "WimpDragMove  ",0
Ben Avison's avatar
Ben Avison committed
1363
configmess_dragmove             DCB     "WimpDragMove  <D>",lf,cr,0
1364
        ALIGN
1365 1366 1367 1368

WimpDoubleClickDelayC_Code
    ConfigOption doubleclickdelay,ds,WimpDoubleClickTimeCMOS,0,4,,default_doubleclick_timelimit,WimpDoubleClickMoveLimitCMOS,0,doubleclick_timelimit,x10
statusmess_doubleclickdelay     DCB     "WimpDoubleClickDelay  ",0
Ben Avison's avatar
Ben Avison committed
1369
configmess_doubleclickdelay     DCB     "WimpDoubleClickDelay  <D>",lf,cr,0
1370
        ALIGN
1371 1372 1373 1374

WimpDoubleClickMoveC_Code
    ConfigOption doubleclickmove,osunits,WimpDoubleClickMoveLimitCMOS,2,5,noshift,default_doubleclick_movelimit,,,doubleclick_movelimit,,B
statusmess_doubleclickmove      DCB     "WimpDoubleClickMove  ",0
Ben Avison's avatar
Ben Avison committed
1375
configmess_doubleclickmove      DCB     "WimpDoubleClickMove  <D>",lf,cr,0
1376
        ALIGN
1377 1378 1379 1380

WimpAutoMenuDelayC_Code
    ConfigOption automenudelay,ds,WimpAutoSubMenuTimeCMOS,0,4,,default_automenudelay,WimpAutoSubMenuTimeCMOS,4,automenu_timelimit,x10
statusmess_automenudelay        DCB     "WimpAutoMenuDelay  ",0
Ben Avison's avatar
Ben Avison committed
1381
configmess_automenudelay        DCB     "WimpAutoMenuDelay  <D>",lf,cr,0
1382
        ALIGN
1383 1384 1385 1386

WimpMenuDragDelayC_Code
    ConfigOption menudragdelay,ds,WimpMenuDragDelayCMOS,0,4,,default_menudragdelay,WimpMenuDragDelayCMOS,4,menudragdelay,x10
statusmess_menudragdelay        DCB     "WimpMenuDragDelay  ",0
Ben Avison's avatar
Ben Avison committed
1387
configmess_menudragdelay        DCB     "WimpMenuDragDelay  <D>",lf,cr,0
1388
        ALIGN
1389 1390 1391 1392

WimpIconBarSpeedC_Code
    ConfigOption iconbarspeed,osupersec,WimpAutoSubMenuTimeCMOS,5,3,,default_iconbarspeed,,,iconbar_scroll_speed,,,iconbarlogtable,numeric
statusmess_iconbarspeed         DCB     "WimpIconBarSpeed  ",0
Ben Avison's avatar
Ben Avison committed
1393
configmess_iconbarspeed         DCB     "WimpIconBarSpeed  <D>",lf,cr,0
1394
        ALIGN
1395 1396 1397 1398

WimpIconBarAccelerationC_Code
    ConfigOption iconbaraccel,osupersec2,WimpMenuDragDelayCMOS,5,3,,default_iconbaraccel,,,iconbar_scroll_accel,,,iconbarlogtable,numeric
statusmess_iconbaraccel         DCB     "WimpIconBarAcceleration  ",0
Ben Avison's avatar
Ben Avison committed
1399
configmess_iconbaraccel         DCB     "WimpIconBarAcceleration  <D>",lf,cr,0
1400
        ALIGN
1401 1402 1403 1404 1405

        [ SpritePriority
WimpSpritePrecedenceC_Code
    ConfigOption sprite,,DesktopFeaturesCMOS,5,1,,0,,,preferredpool,,,status_ramrom
statusmess_sprite               DCB     "WimpSpritePrecedence  ",0
Ben Avison's avatar
Ben Avison committed
1406
configmess_sprite               DCB     "WimpSpritePrecedence  RAM|ROM",lf,cr,0
1407
        ALIGN
1408 1409 1410 1411 1412 1413
        ]

        [ BounceClose
WimpButtonTypeC_Code
    ConfigOption button,,DesktopFeaturesCMOS,6,1,,0,,,buttontype,,B,status_clickrelease
statusmess_button               DCB     "WimpButtonType  ",0
Ben Avison's avatar
Ben Avison committed
1414
configmess_button               DCB     "WimpButtonType  Click|Release",lf,cr,0
1415
        ALIGN
1416 1417 1418 1419 1420 1421
        ]

        [ IconiseButton
WimpIconiseButtonC_Code
    ConfigOption iconisebut,,WimpDragMoveLimitCMOS,7,1,,0,,,iconisebutton,,B,status_offon
statusmess_iconisebut           DCB     "WimpIconiseButton  ",0
Ben Avison's avatar
Ben Avison committed
1422
configmess_iconisebut           DCB     "WimpIconiseButton  On|Off",lf,cr,0
1423
        ALIGN
1424 1425 1426 1427 1428 1429
        ]

        [ StickyEdges
WimpStickyEdgesC_Code
    ConfigOption sticky,,DesktopFeaturesCMOS,6,1,,0,,,stickyedges,,B,status_offon
statusmess_sticky               DCB     "WimpStickyEdges  ",0
Ben Avison's avatar
Ben Avison committed
1430
configmess_sticky               DCB     "WimpStickyEdges  On|Off",lf,cr,0
1431
        ALIGN
1432 1433 1434 1435 1436 1437
        ]

        [ PoppingIconBar
WimpAutoFrontIconBarC_Code
    ConfigOption autofront,,WimpDoubleClickMoveLimitCMOS,7,1,,1,,,popiconbar,,B,status_offon
statusmess_autofront            DCB     "WimpAutoFrontIconBar  ",0
Ben Avison's avatar
Ben Avison committed
1438
configmess_autofront            DCB     "WimpAutoFrontIconBar  On|Off",lf,cr,0
1439
        ALIGN
1440 1441 1442 1443

WimpAutoFrontDelayC_Code
    ConfigOption autofrontdelay,ds,WimpDoubleClickTimeCMOS,4,4,,default_autofrontdelay,WimpDoubleClickMoveLimitCMOS,1,popiconbar_pause,x10
statusmess_autofrontdelay       DCB     "WimpAutoFrontDelay  ",0
Ben Avison's avatar
Ben Avison committed
1444
configmess_autofrontdelay       DCB     "WimpAutoFrontDelay  <D>",lf,cr,0
1445
        ALIGN
1446 1447 1448 1449 1450 1451
        ]

        [ Autoscr
WimpAutoScrollDelayC_Code
    ConfigOption scrolldelay,ds,WimpDragTimeCMOS,4,4,,default_autoscrolldelay,WimpDragMoveLimitCMOS,1,autoscr_default_pause,,B
statusmess_scrolldelay          DCB     "WimpAutoScrollDelay  ",0
Ben Avison's avatar
Ben Avison committed
1452
configmess_scrolldelay          DCB     "WimpAutoScrollDelay  <D>",lf,cr,0
1453
        ALIGN
1454 1455
        ]

1456 1457 1458 1459
        [ ClickSubmenus
WimpClickSubmenuC_Code
    ConfigOption clicksubmenu,,Misc1CMOS,0,1,,0,,,clicksubmenuenable,,B,status_offon
statusmess_clicksubmenu         DCB     "WimpClickSubmenu  ",0
1460
configmess_clicksubmenu         DCB     "WimpClickSubmenu  On|Off",lf,cr,0
1461
        ALIGN
1462
        ]
1463

1464 1465
    |

Neil Turton's avatar
Neil Turton committed
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
WimpDragDelayC_Code
        MOV     R1,#WimpDragTimeCMOS
        B       %FT01

WimpDragMoveC_Code
        MOV     R1,#WimpDragMoveLimitCMOS
        B       %FT01

WimpDoubleClickDelayC_Code
        MOV     R1,#WimpDoubleClickTimeCMOS
        B       %FT01

WimpDoubleClickMoveC_Code
        MOV     R1,#WimpDoubleClickMoveLimitCMOS
        B       %FT01

WimpAutoMenuDelayC_Code
        MOV     R1,#WimpAutoSubMenuTimeCMOS
        B       %FT01

WimpMenuDragDelayC_Code
        MOV     R1,#WimpMenuDragDelayCMOS
        B       %FT01

WimpFontC_Code
        MOV     R1,#DesktopFeaturesCMOS
        B       %FT01

WimpFlagsC_Code
        MOV     R1,#WimpFlagsCMOS
01
        Push    "R1,R12,LR"
        LDR     wsptr,[R12]             ; R12 --> workspace
;
        CMP     R0,#1
        BEQ     printstatus
Ben Avison's avatar
Ben Avison committed
1502
        BLO     printsyntax
Neil Turton's avatar
Neil Turton committed
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
;
        MOV     R1,R0                   ; R1 --> string
        MOV     R0,#&C000000A           ; base 10, check terminator, <= 255
        SWI     XOS_ReadUnsigned
        Pull    "R1,R12,PC",VS
01
        LDRB    R14,[R1],#