Utility 33.5 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
; 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.
;
        TTL  => Utility

; *****************************************************************************
; Arthur Utility commands

SysModules_Info ROUT     ; start of ROM modules chain
        &       EndOfKernel-SysModules_Info

UtilityMod
        &       StartSuper-UtilityMod
        &       0                               ; no initialisation
        &       Util_Die-UtilityMod
        &       Util_Service-UtilityMod         ; code to register printer buffer with Buffer manager
        &       UtilModTitle-UtilityMod
        &       UtilHelpStr-UtilityMod
        &       UtilHelpTab-UtilityMod
31 32 33
        &       &F00000
        &       Util_SWI-UtilityMod
        &       Util_SWITab-UtilityMod
Neil Turton's avatar
Neil Turton committed
34 35
        &       0
 [ International_Help <> 0
36
        &       MessageFileName-UtilityMod
Neil Turton's avatar
Neil Turton committed
37 38 39
 |
        &       0
 ]
Stewart Brodie's avatar
Stewart Brodie committed
40 41 42
 [ :LNOT: No32bitCode
        &       UtilFlags-UtilityMod
 ]
Neil Turton's avatar
Neil Turton committed
43

44
Util_SWITab
45 46 47
        =       "ARM",0
        =       "IMB",0
        =       "IMBRange",0
48 49 50
        =       0
        ALIGN

Neil Turton's avatar
Neil Turton committed
51 52
Module_BaseAddr SETA UtilityMod

53 54 55
  [ ChocolateService
    ;service table
    ;
Stewart Brodie's avatar
Stewart Brodie committed
56 57 58
        ASSERT Service_MessageFileClosed < Service_BufferStarting
        ASSERT Service_BufferStarting    < Service_TerritoryStarted
        ASSERT Service_TerritoryStarted  < Service_DeviceFSCloseRequest
59
    ;
Stewart Brodie's avatar
Stewart Brodie committed
60

61 62 63
Util_ChocServTab
        DCD    0                            ;flags word
        DCD    Util_ChocService-UtilityMod  ;offset to handler
Stewart Brodie's avatar
Stewart Brodie committed
64 65 66
   [ CacheCommonErrors
        DCD    Service_MessageFileClosed
   ]
67
        DCD    Service_BufferStarting       ;service 1
Stewart Brodie's avatar
Stewart Brodie committed
68 69 70
   [ CacheCommonErrors
        DCD    Service_TerritoryStarted
   ]
71 72 73 74
        DCD    Service_DeviceFSCloseRequest ;service 2
        DCD    0                            ;terminator
        DCD    Util_ChocServTab-UtilityMod  ;table anchor
  ]
Neil Turton's avatar
Neil Turton committed
75
Util_Service ROUT
76 77 78
  [ ChocolateService
        MOV     r0, r0   ;magic instruction for new service table format
  ]
Neil Turton's avatar
Neil Turton committed
79 80
        TEQ     r1, #Service_BufferStarting
        TEQNE   r1, #Service_DeviceFSCloseRequest
Stewart Brodie's avatar
Stewart Brodie committed
81 82 83 84
  [ CacheCommonErrors
        TEQNE   r1, #Service_TerritoryStarted
        TEQNE   r1, #Service_MessageFileClosed
  ]
Kevin Bracey's avatar
Kevin Bracey committed
85
        MOVNE   pc, lr
86 87 88
  [ ChocolateService
    ;entry point excluding pre-rejection code
Util_ChocService
Stewart Brodie's avatar
Stewart Brodie committed
89 90 91 92 93
  ]
  [ CacheCommonErrors
        TEQ     r1, #Service_TerritoryStarted
        TEQNE   r1, #Service_MessageFileClosed
        BEQ     CacheCommonErrorsReinit
94
  ]
Neil Turton's avatar
Neil Turton committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        TEQ     r1, #Service_BufferStarting
        BNE     %FT10
        Push    "r0-r3,lr"

; Register buffers with buffer manager in order of speed - first is fast

 [ MouseBufferManager
        MOV     r0, #BufferFlags_GenerateInputFull
        LDR     r1, =MouseBuff
        LDR     r2, =MouseBuff + MouseBuffSize
        MOV     r3, #Buff_Mouse
        SWI     XBuffer_Register                ; register mouse input buffer
 ]
        MOV     r0, #BufferFlags_GenerateInputFull :OR: BufferFlags_SendThresholdUpCalls
        LDR     r1, =RS423InBuff
        LDR     r2, =RS423InBuff + RS423InBuffSize
        MOV     r3, #Buff_RS423In
        SWI     XBuffer_Register                ; register serial input buffer

        MOV     r0, #BufferFlags_GenerateOutputEmpty
        LDR     r1, =RS423OutBuff
        LDR     r2, =RS423OutBuff + RS423OutBuffSize
        MOV     r3, #Buff_RS423Out
        SWI     XBuffer_Register                ; register serial output buffer

Jeffrey Lee's avatar
Jeffrey Lee committed
120
        LDR     r0, =ZeroPage                   ; used as index to PrinterBufferThing
Neil Turton's avatar
Neil Turton committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        LDR     r1, [r0, #PrinterBufferAddr]    ; r1 -> start of buffer
        LDR     r2, [r0, #PrinterBufferSize]    ; r2 = size
        ADD     r2, r2, r1                      ; r2 -> end+1 of buffer
        MOV     r3, #Buff_Print
        MOV     r0, #BufferFlags_GenerateOutputEmpty
        SWI     XBuffer_Register                ; register the MOS's printer buffer

        Pull    "r0-r3,pc"

; service DeviceFSCloseRequest
; in:   r2 = handle we are requested to close
;       if r2 = PrinterActive (word) or SerialInHandle (byte) or SerialOutHandle (byte)
;       then zero appropriate variable and close file, then claim service
;       NB there is a disadvantage to doing it for SerialInHandle, in that it won't get
;       opened again, but we assume they accidentally left it in an fx2,2 state
;

10
        Push    "r0,r1,lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
140
        LDR     lr, =ZeroPage
Neil Turton's avatar
Neil Turton committed
141
        MOV     r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
142
        LDR     r1, [lr, #OsbyteVars + :INDEX: PrinterActive]
Neil Turton's avatar
Neil Turton committed
143
        TEQ     r1, r2
Jeffrey Lee's avatar
Jeffrey Lee committed
144
        STREQ   r0, [lr, #OsbyteVars + :INDEX: PrinterActive]
Neil Turton's avatar
Neil Turton committed
145
        BEQ     %FT20
Jeffrey Lee's avatar
Jeffrey Lee committed
146
        LDRB    r1, [lr, #OsbyteVars + :INDEX: SerialInHandle]
Neil Turton's avatar
Neil Turton committed
147
        TEQ     r1, r2
Jeffrey Lee's avatar
Jeffrey Lee committed
148
        STREQB  r0, [lr, #OsbyteVars + :INDEX: SerialInHandle]
Neil Turton's avatar
Neil Turton committed
149
        BEQ     %FT20
Jeffrey Lee's avatar
Jeffrey Lee committed
150
        LDRB    r1, [lr, #OsbyteVars + :INDEX: SerialOutHandle]
Neil Turton's avatar
Neil Turton committed
151
        TEQ     r1, r2
Kevin Bracey's avatar
Kevin Bracey committed
152
        Pull    "r0,r1,pc",NE                   ; if not any of these then exit preserving everything
Jeffrey Lee's avatar
Jeffrey Lee committed
153
        STRB    r0, [lr, #OsbyteVars + :INDEX: SerialOutHandle]
Neil Turton's avatar
Neil Turton committed
154 155 156
20
        SWI     XOS_Find                        ; close file, ignore errors (if we get an error it's closed anyway)
        MOV     r1, #Service_Serviced           ; indicate we closed it
Kevin Bracey's avatar
Kevin Bracey committed
157
        Pull    "r0,lr,pc"                      ; restore r0, junk r1, and exit
Neil Turton's avatar
Neil Turton committed
158 159 160 161 162 163 164 165 166 167 168


Util_Die   ROUT
           CMP   R10, #0
           MOVEQ PC, lr      ; non-fatal : can cope
           ADR   R0, %FT01
 [ International
           Push  "lr"
           BL    TranslateError
           Pull  "pc"
 |
Kevin Bracey's avatar
Kevin Bracey committed
169
           RETURNVS
Neil Turton's avatar
Neil Turton committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
 ]

01
           &     ErrorNumber_CantKill
 [ International
           =    "CantKill", 0
 |
           =    "Deleting the utility module is foolish", 0
 ]


UtilModTitle =  "UtilityModule", 0

UtilHelpStr  =  "MOS Utilities", 9, "$VersionNo", 0

185 186 187 188 189
  [ Oscli_HashedCommands
;
;***WARNING*** if commands are added or changed, UtilHashedCmdTab MUST be updated correspondingly
;
  ]
Neil Turton's avatar
Neil Turton committed
190
UtilHelpTab
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
           Command   Break,              0,  0, International_Help   ; just help
           Command   ChangeDynamicArea,255,  0, International_Help
           Command   Configure,        255,  0, Help_Is_Code_Flag :OR: International_Help
           Command   Commands,           0,  0, Help_Is_Code_Flag :OR: International_Help
           Command   Echo,             255,  0, International_Help
           Command   Error,            255,  1, International_Help
           Command   Eval,             255,  1, International_Help
           Command   FileCommands,       0,  0, Help_Is_Code_Flag :OR: International_Help
           Command   GOS,                0,  0, International_Help
           Command   IF,               255,  2, International_Help
           Command   Ignore,             1,  0, International_Help
           Command   Modules,            0,  0, Help_Is_Code_Flag :OR: International_Help
           Command   PowerOn,            0,  0, International_Help   ; just help
           Command   Reset,              0,  0, International_Help   ; just help
           Command   RMClear,            0,  0, International_Help
           Command   RMEnsure,         255,  2, International_Help
           Command   RMFaster,           1,  1, International_Help
           Command   RMInsert,           2,  1, International_Help
           Command   RMKill,             1,  1, International_Help
           Command   RMLoad,           255,  1, International_Help
           Command   RMReInit,         255,  1, International_Help
           Command   RMRun,            255,  1, International_Help
           Command   RMTidy,             0,  0, International_Help
           Command   ROMModules,         0,  0, International_Help
           Command   Set,              255,  2, International_Help
           Command   SetEval,          255,  2, International_Help
           Command   SetMacro,         255,  2, International_Help
           Command   Show,               1,  0, International_Help   ; *show = *show *
           Command   Status,           255,  0, International_Help
           Command   Syntax,             0,  0, International_Help
           Command   Time,               0,  0, International_Help
           Command   Unplug,             2,  0, International_Help
           Command   Unset,              1,  1, International_Help
Neil Turton's avatar
Neil Turton committed
224 225
           =   0

226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
  [ Oscli_HashedCommands
;
; - Hashing table is 32 wide
; - Hashing function is:
;
;      hash = (sum of all chars of command, each upper-cased) & 0x1f
;
; - Order of commands in each hashed list is chosen as 'most common' first

; Table MUST be reorganised if hashing function changed, or command set altered
;
           ALIGN
UtilHashedCmdTab
;
;    ! 0,"UtilHashedCmdTab  at ":CC::STR:(UtilHashedCmdTab)
;
;First, 1 word per table entry, giving offset to hashed list on each hash value
;
           DCD       0                        ;null list on this hash value
           DCD       UHC_hash01 - UtilityMod
           DCD       UHC_hash02 - UtilityMod
           DCD       0
           DCD       UHC_hash04 - UtilityMod
           DCD       0
           DCD       UHC_hash06 - UtilityMod
           DCD       UHC_hash07 - UtilityMod
           DCD       UHC_hash08 - UtilityMod
           DCD       UHC_hash09 - UtilityMod
           DCD       UHC_hash0A - UtilityMod
           DCD       UHC_hash0B - UtilityMod
           DCD       UHC_hash0C - UtilityMod
           DCD       0
           DCD       0
           DCD       UHC_hash0F - UtilityMod
           DCD       0
           DCD       UHC_hash11 - UtilityMod
           DCD       0
           DCD       0
           DCD       UHC_hash14 - UtilityMod
           DCD       0
           DCD       0
           DCD       0
           DCD       0
           DCD       UHC_hash19 - UtilityMod
           DCD       0
           DCD       UHC_hash1B - UtilityMod
           DCD       0
           DCD       0
           DCD       UHC_hash1E - UtilityMod
           DCD       UHC_hash1F - UtilityMod
;
; Now the hashed lists
;
UHC_hash01
           Command   Show,               1,  0, International_Help
           =   0
           ALIGN
UHC_hash02
           Command   Configure,        255,  0, Help_Is_Code_Flag :OR: International_Help
           =   0
           ALIGN
UHC_hash04
           Command   ChangeDynamicArea,255,  0, International_Help
           Command   RMFaster,           1,  1, International_Help
           Command   Status,           255,  0, International_Help
           Command   Ignore,             1,  0, International_Help
           =   0
           ALIGN
UHC_hash06
           Command   RMClear,            0,  0, International_Help
           =   0
           ALIGN
UHC_hash07
           Command   ROMModules,         0,  0, International_Help
           =   0
           ALIGN
UHC_hash08
           Command   Eval,             255,  1, International_Help
           =   0
           ALIGN
UHC_hash09
           Command   GOS,                0,  0, International_Help
           =   0
           ALIGN
UHC_hash0A
           Command   RMReInit,         255,  1, International_Help
           Command   Error,            255,  1, International_Help
           =   0
           ALIGN
UHC_hash0B
           Command   RMKill,             1,  1, International_Help
           =   0
           ALIGN
UHC_hash0C
           Command   Set,              255,  2, International_Help
           =   0
           ALIGN
UHC_hash0F
           Command   IF,               255,  2, International_Help
           Command   Unset,              1,  1, International_Help
           Command   Time,               0,  0, International_Help
           =   0
           ALIGN
UHC_hash11
           Command   RMEnsure,         255,  2, International_Help
           =   0
           ALIGN
UHC_hash14
           Command   SetEval,          255,  2, International_Help
           Command   RMRun,            255,  1, International_Help
           Command   RMInsert,           2,  1, International_Help
           =   0
           ALIGN
UHC_hash19
           Command   Modules,            0,  0, Help_Is_Code_Flag :OR: International_Help
           Command   RMTidy,             0,  0, International_Help
           =   0
           ALIGN
UHC_hash1B
           Command   Unplug,             2,  0, International_Help
           =   0
           ALIGN
UHC_hash1E
           Command   SetMacro,         255,  2, International_Help
           =   0
           ALIGN
UHC_hash1F
           Command   RMLoad,           255,  1, International_Help
           Command   Echo,             255,  0, International_Help
           =   0
           ALIGN

  ] ;Oscli_HashedCommands

Neil Turton's avatar
Neil Turton committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
Configure_Syntax     * Module_BaseAddr
Commands_Code        * Module_BaseAddr
Commands_Syntax      * Module_BaseAddr
Syntax_Code          * Module_BaseAddr
Syntax_Syntax        * Module_BaseAddr
Echo_Syntax          * Module_BaseAddr
Status_Syntax        * Module_BaseAddr
FileCommands_Code    * Module_BaseAddr
FileCommands_Syntax  * Module_BaseAddr
Reset_Code           * Module_BaseAddr
Reset_Syntax         * Module_BaseAddr
Break_Code           * Module_BaseAddr
Break_Syntax         * Module_BaseAddr
PowerOn_Code         * Module_BaseAddr
PowerOn_Syntax       * Module_BaseAddr

RMFaster_Code
           Push "lr"
           MOV R1, R0
           MOV R0, #ModHandReason_LookupName
           SWI XOS_Module
           Pull "PC", VS
382 383 384 385 386 387
           CMP   R3, #ROM                 ; HS if R3 >= ROM
           BLO   RMFast_notinROM
 [ :LNOT:ROMatTop
           CMP   R3, #ROMLimit
           BHS   RMFast_notinROM
 ]
Neil Turton's avatar
Neil Turton committed
388 389 390 391 392 393 394 395 396 397 398 399
           MOV   R1, R3
           LDR   R2, [R1, #-4]
           MOV   R0, #ModHandReason_CopyArea
           SWI   XOS_Module
           Pull  PC

RMFast_notinROM
           ADRL R0, ErrorBlock_RMNotFoundInROM
         [ International
           BL   TranslateError
         ]
           Pull lr
Kevin Bracey's avatar
Kevin Bracey committed
400
           RETURNVS
Neil Turton's avatar
Neil Turton committed
401 402 403 404 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

RMKill_Code
           MOV R6, #ModHandReason_Delete

Rmcommon   Push "lr"
           MOV r1, r0
           MOV r0, r6
           SWI   XOS_Module
           Pull "PC"

RMLoad_Code
           MOV R6, #ModHandReason_Load
           B   Rmcommon

RMRun_Code
           MOV R6, #ModHandReason_Run
           B   Rmcommon

RMTidy_Code
           MOV R6, #ModHandReason_Tidy
           B   Rmcommon

RMClear_Code
           MOV R6, #ModHandReason_Clear
           B   Rmcommon

RMReInit_Code
           MOV R6, #ModHandReason_ReInit
           B   Rmcommon

Modules_Help   ROUT
          Push  "r2, r3, lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
433 434
          LDR   r2, =ZeroPage                      ; Try our own message file before Global.
          LDR   r0, [r2, #KernelMessagesBlock]
Neil Turton's avatar
Neil Turton committed
435
          TEQ   r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
436
          ADDNE r0, r2, #KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
437
          ADRL  r1, modules_help1
Jeffrey Lee's avatar
Jeffrey Lee committed
438
        [ ZeroPage <> 0
Neil Turton's avatar
Neil Turton committed
439
          MOV   r2, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
440
        ]
Neil Turton's avatar
Neil Turton committed
441 442 443 444 445 446
          SWI   XMessageTrans_Lookup
          SWIVC XMessageTrans_Dictionary
          MOVVC r1, r0
          MOVVC r0, r2
          SWIVC XOS_PrettyPrint
          Pull  "r2, r3, PC", VS
Jeffrey Lee's avatar
Jeffrey Lee committed
447
          LDR    R1, =ZeroPage+Module_List
Neil Turton's avatar
Neil Turton committed
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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
03        LDR    R1, [R1]
          CMP    R1, #0
          BEQ    %FT05
          LDR    R0, [R1, #Module_code_pointer]
          BL     PrintTitle
          BVC    %BT03
05        MOVVC  R0, #0
          Pull  "r2, r3, PC"

PrintTitle ; of module at R0 : corrupts R0
        Push  "R1, lr"
        LDR    R1, [R0, #Module_HelpStr]
        CMP    R1, #0
        ADREQ  R0, NoRIT
      [ International
        BLEQ   Write0_Translated
        ADDNE  R0, R1, R0
        SWINE  XOS_PrettyPrint
      |
        ADDNE  R0, R1, R0
        SWI    XOS_PrettyPrint
      ]
        SWIVC  XOS_NewLine
        Pull  "R1, PC"

Modules_Code ROUT
        Push   "R7, lr"

      [ International
        BL     WriteS_Translated
        =      "Modules:No. Position Workspace Name", 10, 13, 0
        ALIGN
      |
        SWI     XOS_WriteS
        =      "No. Position Workspace Name", 10, 13, 0
        ALIGN
      ]
        Pull   "R7, PC", VS

        MOV     R1, #0
        MOV     R2, #0
        MOV     R6, #0
        MOV     R7, #0
06
        SWI     XOS_ReadEscapeState
        Pull    "R7, lr", CS
        BCS     AckEscape
        MOV     R0, #ModHandReason_GetNames
        SWI     XOS_Module
Kevin Bracey's avatar
Kevin Bracey committed
497 498 499
        BVC     %FT07
        CLRV
        Pull   "R7, pc"              ; back, clearing V
Neil Turton's avatar
Neil Turton committed
500

Kevin Bracey's avatar
Kevin Bracey committed
501
07
Neil Turton's avatar
Neil Turton committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 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
        Push   "R1, R2"
        CMP     R6, #0
        MOVNE   R1, #0
        BNE     %FT02
        ADD     R7, R7, #1
        MOV     R0, R7
        LDR     R1, =GeneralMOSBuffer
        MOV     R2, #256
        SWI     XOS_ConvertCardinal2
        SUB     R1, R1, R0          ; characters in buffer
02      CMP     R1, #3
        SWILT   XOS_WriteI+" "
        BVS     %FT03
        ADDLT   R1, R1, #1
        BLT     %BT02
03
        Pull   "R1, R2"
        BVS     %FT04
        CMP     R6, #0
        SWIEQ   XOS_Write0
        SWIVC   XOS_WriteI+" "
        MOV     R0, R3
        BLVC    HexR0LongWord
        SWIVC   XOS_WriteI+" "
        MOV     R0, R4
        BLVC    HexR0LongWord
        SWIVC   XOS_WriteI+" "
        SWIVC   XOS_WriteI+" "
        BLVC    %FT01         ; title out
        SWIVC   XOS_NewLine
        BVC     %BT06
04
        Pull   "R7, PC"
01
        Push   "lr"
        LDR     R0, [R3, #Module_Title]
        CMP     R0, #0
        ADDNE   R0, R3, R0
        ADREQ   R0, NoRIT
      [ International
        BLEQ    Write0_Translated
        SWINE   XOS_Write0
      |
        SWI     XOS_Write0
      ]
        Pull   "PC", VS
        CMP     R6, #0
        CMPEQ   R2, #0
        MOV     R6, R2
        Pull   "PC", EQ       ; only one incarnation
        SWI     XOS_WriteI + Postfix_Separator
        MOV     R0, R5
        SWIVC   XOS_Write0
        Pull   "PC"

      [ International
NoRIT   =   "Untitled:<Untitled>", 0
      |
NoRIT   =   "<Untitled>", 0
      ]
starstr =   "*", 13
        ALIGN



Show_Code
        CMP     r1, #0                  ; *show only?
        ADREQ   r0, starstr
Kevin Bracey's avatar
Kevin Bracey committed
570
        Entry   "r0,r7",8+256
571
        MRS     r7, CPSR
Neil Turton's avatar
Neil Turton committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

        ADD     r6, sp, #8              ; initial buffer for var expansions
        MOV     lr, #256+4
        STR     lr, [sp, #4]            ; fake heap block size
        MOV     lr, #&ffffffff
        STR     lr, [sp, #0]            ; inhibit page mode off on exit

        ; Read current VDU status and save it away
        MOVVC   r0, #117
        SWIVC   XOS_Byte
        STRVC   R1, [sp, #0]
        SWIVC   XOS_WriteI+14           ; paged mode on.
        BVS     ShowBang

        MOV     r3, #0          ; enumeration pointer
01
Kevin Bracey's avatar
Kevin Bracey committed
588
        LDR     r0, [sp, #Proc_RegOffset + 0*4]        ; wildcard
Neil Turton's avatar
Neil Turton committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
10
        MOV     r1, r6          ; 'heap' block
        LDR     r2, [r6, #-4]   ; block size
        SUB     r2, r2, #4
        MOV     r4, #0          ; no expansion
        SWI     XOS_ReadVarVal
        BVS     Show_ErrorReading

        ; Varname
        MOV     r0, r3
        SWI     XOS_Write0
        BVS     ShowBang

        ; (Number) or (Macro) as appropriate
        CMP     R4, #VarType_String
        BEQ     skipvalprt
      [ :LNOT: International
        SWI     XOS_WriteS
        =       " (", 0
        ALIGN
        BVS     ShowBang
      ]
        CMP     R4, #VarType_Number
        MOVEQ   R2, #256
        LDREQ   R0, [R1]
        SWIEQ   XOS_BinaryToDecimal
        ADREQ   R0, %FT02
        ADRHI   R0, %FT03
      [ International
        BLVC    Write0_Translated
      |
        SWIVC   XOS_Write0
        SWIVC   XOS_WriteI+")"
      ]
        BVS     ShowBang
skipvalprt
        ; " : "
        SWI     XOS_WriteS
        =       " : ", 0
        ALIGN
        BVS     ShowBang

        ; Now output the value's value
        MOV     R5, #-1
05      ADD     R5, R5, #1
        CMP     R5, R2
        BEQ     %FT06
        SWI     XOS_ReadEscapeState
        BLCS    AckEscape
        BVS     ShowBang
        LDRB    R0, [R1, R5]
        CMP     R0, #&7F
        MOVEQ   R0, #"?"-"@"
        CMP     R0, #31
        ADDLE   R0, R0, #"@"
        SWILE   XOS_WriteI+"|"
        BVS     ShowBang

        CMP     R0, #"|"
        CMPNE   R0, #""""
        CMPNE   R0, #"<"
        SWINE   XOS_WriteC
        BVS     ShowBang
        BNE     %BT05

        CMP     R4, #VarType_Macro
        SWINE   XOS_WriteI+"|"
        SWIVC   XOS_WriteC
        BVC     %BT05
ShowBang
Kevin Bracey's avatar
Kevin Bracey committed
659 660
        STR     r0, [sp, #Proc_RegOffset + 0*4]
        ORR     r7, r7, #V_bit                          ; CPSR in
Neil Turton's avatar
Neil Turton committed
661 662 663 664 665 666 667 668 669 670 671 672 673 674

Show_Exit
        ; Release buffer if necessary
        ADD     lr, sp, #8              ; stack buffer
        TEQ     r6, lr
        MOVNE   r0, #ModHandReason_Free
        MOVNE   r2, r6
        SWINE   XOS_Module

        ; Switch paged mode off if necessary
        LDR     lr, [sp, #0]
        TST     lr, #5
        SWIEQ   XOS_WriteI+15  ; paged mode off

675
        MSR     CPSR_f, r7
Kevin Bracey's avatar
Kevin Bracey committed
676
        EXIT
Neil Turton's avatar
Neil Turton committed
677 678 679 680 681

06      SWI     XOS_NewLine
        BVS     ShowBang
        B       %BT01

Kevin Bracey's avatar
Kevin Bracey committed
682 683 684 685 686 687 688 689 690 691 692
      [ International
02
        =       "Number:(Number)", 0
03
        =       "Macro:(Macro)", 0
      |
02
        =       "Number", 0
03
        =       "Macro", 0
      ]
693
        ALIGN
Kevin Bracey's avatar
Kevin Bracey committed
694

Neil Turton's avatar
Neil Turton committed
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 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 771 772 773 774 775 776
Show_ErrorReading
        ; Error from OS_ReadVarVal:
        ; VarCantFind - end of *show
        ; BuffOverflow - try and extend buffer
        ; other - return as error
        LDR     r5, [r0]
        LDR     lr, =ErrorNumber_VarCantFind
        TEQ     r5, lr
        BEQ     Show_Exit
        LDR     lr, =ErrorNumber_BuffOverflow
        TEQ     r5, lr
        BNE     ShowBang

        ; try and extend the buffer
        CLRV
        MOV     r1, r3                  ; actual name so retry gets this node exactly
        ADD     lr, sp, #8              ; stack buffer
        TEQ     r6, lr
        MOV     r0, #ModHandReason_Free
        MOV     r2, r6
        MOV     r6, lr                  ; to prevent any attempt at freeing in ShowBang
        SWINE   XOS_Module
        BVS     ShowBang

        MOV     r0, r1
        MOV     r1, #ARM_CC_Mask
        MOV     r2, #-1                 ; To sence size
        MOV     r3, #0                  ; 1st var
        MOV     r4, #0                  ; unexpanded
        SWI     XOS_ReadVarVal
        CLRV                            ; error will be buffer overflow
        MOV     r1, r3                  ; varname again
        MVN     r3, r2
        ADD     r3, r3, #&ff            ; round up to 256 byte boundary
        BIC     r3, r3, #&ff
        MOV     r0, #ModHandReason_Claim
        SWI     XOS_Module
        BVS     ShowBang
        MOV     r6, r2
        MOV     r0, r1
        MOV     r3, #0                  ; restart from that node
        B       %BT10

Set_Code ROUT
        MOV    R4, #VarType_String
01
        Push  "lr"

        ; space terminated name in R0

        ; Skip name in R1
        MOV    R1, R0
02      LDRB   R2, [R1], #1
        CMP    R2, #" "
        BNE    %BT02

        ; Then skip spaces
03      LDRB   R2, [R1], #1
        CMP    R2, #" "
        BEQ    %BT03
        SUB    R1, R1, #1

        ; r2 +ve to set, r3 = 0 for 1st var
        MOV    R2, #1
        MOV    R3, #0
        SWI    XOS_SetVarVal
        Pull  "PC"

        LTORG

SetMacro_Code MOV    R4, #VarType_Macro
        B  %BT01

SetEval_Code MOV    R4, #VarType_Expanded
        B  %BT01

Unset_Code ROUT
        Push  "lr"
        MOV    R2, #-1
        MOV    R3, #0
01      SWI    XOS_SetVarVal
        BVC    %BT01
Kevin Bracey's avatar
Kevin Bracey committed
777 778
        CLRV
        Pull  "pc"
Neil Turton's avatar
Neil Turton committed
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803

Echo_Code ROUT
        Push  "lr"
        MOV    R2, #GS_NoQuoteMess
        SWI    XOS_GSInit
01      SWI    XOS_GSRead
        BVS    %FT02
        MOVCC  R3, R0
        MOVCC  R0, R1
        SWICC  XOS_WriteC
        BVS    %FT02
        MOVCC  R0, R3
        BCC    %BT01
        SWI    XOS_NewLine
02
        Pull  "PC"

Commands_Help  ROUT
        Push  "R0, lr"         ; keep buffer pointer
        ADRL   R0, commands_helpstr
        MOV    R1, #0
KeyHelpCommon                  ; also used by *Configure
        Push   r1
; R2 & R3 can be junked here?
        MOV    r1, r0
Jeffrey Lee's avatar
Jeffrey Lee committed
804 805
        LDR    r2, =ZeroPage   ; Try our own message file before Global.
        LDR    r0, [r2, #KernelMessagesBlock]
Neil Turton's avatar
Neil Turton committed
806
        TEQ    r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
807 808
        ADDNE  r0, r2, #KernelMessagesBlock+4
      [ ZeroPage <> 0
Neil Turton's avatar
Neil Turton committed
809
        MOV    r2, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
810
      ]
Neil Turton's avatar
Neil Turton committed
811 812 813 814 815 816 817 818 819 820 821
        SWI    XMessageTrans_Lookup
        SWIVC  XMessageTrans_Dictionary
        MOVVC  r1, r0
        MOVVC  r0, r2
        SWIVC  XOS_PrettyPrint
        Pull   "r1,lr,PC", VS  ; if error, pull R1, junk stacked R0 and exit
        Pull   "r1,r3"         ; restore r1 and get buffer pointer
        MOV    r0, #0
        ADRL   R2, SysCommsModule
        BL     OneModuleK
        BVS    %FT10
Jeffrey Lee's avatar
Jeffrey Lee committed
822
        LDR    R6, =ZeroPage+Module_List
Neil Turton's avatar
Neil Turton committed
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
12      LDR    R6, [R6]
        CMP    R6, #0
        BEQ    %FT10
        LDR    R2, [R6, #Module_code_pointer]
        BL     OneModuleK
        BVC    %BT12
10      MOVVC  R0, #0
        Pull  "PC"

FileCommands_Help
        Push  "R0, lr"
        ADRL   R0, fscommands_helpstr
        MOV    R1, #FS_Command_Flag
        B      KeyHelpCommon

; take module code pointer in r2
;                    flags in r1
;    HelpBufferSize buffer in r3
;          string to print in r0

OneModuleK     ROUT
844
        Push  "r2-r7, lr"
Neil Turton's avatar
Neil Turton committed
845 846
        LDR    R4, [R2, #Module_HC_Table]
        CMP    R4, #0
847 848
        Pull  "r2-r7, PC", EQ       ; no table
        MOV    R7, #&80000000       ; flag
Neil Turton's avatar
Neil Turton committed
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
        MOV    R5, #0               ; buffer offset

        ADD    R2, R2, R4           ; point at table start.
03      MOV    R6, R2
        LDRB   R4, [R2]
        CMP    R4, #0
        BEQ    %FT06

04      LDRB   R4, [R6], #1
        CMP    R4, #0
        BNE    %BT04
        ADD    lr, R6, #3
        BIC    lr, lr, #3           ; align but leave r6 at end of command for below (05)
        LDR    R4, [lr, #0]         ; code offset
        CMP    r1, #-1              ; fudge?
        BEQ    %FT78
        CMP    R4, #0
        ADDEQ  R2, lr, #16
        BEQ    %BT03
        LDRB   R4, [lr, #7]
        BIC    R4, R4, #(Help_Is_Code_Flag:OR:International_Help) :SHR: 24
        CMP    R4, R1, LSR #24      ; move flags into bottom byte
79      ADDNE  R2, lr, #16
        BNE    %BT03
873
        TST    R7, #&80000000
Neil Turton's avatar
Neil Turton committed
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
        BEQ    %FT05
        SWI    XOS_NewLine
        SWIVC  XOS_NewLine
        BVS    %FT77
        MOV    r4, r0
        CMP    r0, #0
        BEQ    OneModuleK_PrintTitle ; Don't trust MessageTrans to preserve Z
        SWI    XMessageTrans_Dictionary
        STMDB  sp!, {r1}
        MOVVC  r1, r0
        MOVVC  r0, r4
        SWIVC  XOS_PrettyPrint
        LDMIA  sp!, {r1}
        B      %FT77
OneModuleK_PrintTitle
        LDR    r0, [stack]
        BL     PrintTitle
77
        MOVVC  r0, r4
893 894
        Pull  "r2-r7, PC", VS
        BIC    R7, R7, #&80000000
Neil Turton's avatar
Neil Turton committed
895 896 897 898 899 900 901 902 903 904 905 906
05
        SUB    lr, r6, r2
        RSB    r4, r5, #HelpBufferSize
        CMP    r4, lr                   ; have we got enough space for command+tab
        BCS    %FT07
        MOV    r4, #0                   ; no, so 0 terminate what we've got and print it
        SUB    r5, r5, #1               ; write 0 over trailing tab
        STRB   r4, [r3, r5]
        MOV    r4, r0
        MOV    r0, r3
        SWI    XOS_PrettyPrint
        SWIVC  XOS_NewLine
907
        Pull   "r2-r7,pc",VS
Neil Turton's avatar
Neil Turton committed
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
        MOV    r0, r4
        MOV    r5, #0                   ; start again with empty buffer
07
        LDRB   r4, [r2], #1             ; copy command
        CMP    r4, #0
        STRNEB r4, [r3, r5]
        ADDNE  r5, r5, #1
        BNE    %BT07
        MOV    r4, #TAB                 ; add tab
        STRB   r4, [r3, r5]
        ADD    r5, r5, #1
        ADD    r2, r2, #3+16            ; align and move on to next command
        BIC    r2, r2, #3
        B      %BT03

78      CMP    r4, #0
        B      %BT79

926 927
06      TST    R7, #&80000000
        Pull  "r2-r7, PC", NE
Neil Turton's avatar
Neil Turton committed
928 929 930 931 932 933 934
        Push  "R0"
        MOV    R0, #0
        SUB    R5, R5, #1
        STRB   R0, [R5, R3]
        MOV    R0, R3
        SWI    XOS_PrettyPrint
        STRVS  r0, [stack]
935
        Pull  "R0, r2-r7, PC"
Neil Turton's avatar
Neil Turton committed
936 937 938 939 940 941 942 943 944 945 946

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

GOS_Code
        Push    lr
        MOV     r2, r0
        addr    R1, UtilModTitle
        MOV     R0, #ModHandReason_Enter
        SWI     XOS_Module
        Pull    pc

947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

; Deal with UtilityModule SWIs.
;
; The UtilityModule provides "OS-independent" SWIs. At present these are:
;
; SWI &F00000 (ARM_IMB)
; SWI &F00001 (ARM_IMBRange)
;
; as specified by the ARMv5 ARM (section 2.7.4 Prefetching and self-modifying
; code)

Util_SWI
        CMP     r11, #1
        BLO     SyncCodeAreasFull       ; (00) will do tail-call return from SWI
        BHI     Util_SWINotKnown        ; (02..3F)

; Ranged wotsit                           (01)
        Push    "r1,r2,lr"
        SUB     r2, r1, #4              ; convert from exclusive to inclusive
        MOV     r1, r0
        BL      SyncCodeAreasRange
        Pull    "r1,r2,pc"

Util_SWINotKnown
        ADR     r0, ErrorBlock_ModuleBadSWI
      [ International
        addr    r4, UtilModTitle
        B       TranslateError_UseR4
      |
        RETURNVS
      ]

        MakeErrorBlock ModuleBadSWI

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ChangeDynamicArea - moved here from the Task Manager as embedded devices
; tend not to have the Task Manager
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

rmaarea         *       1               ; RMA area
screenarea      *       2               ; screen area
spritearea      *       3               ; sprite area
fontarea        *       4               ; font cache dynamic area number
ramfsarea       *       5               ; RAM disc area

                ^       0
vec_fontsize    #       4               ; fields in output vector
vec_spritesize  #       4
vec_ramfssize   #       4
vec_rmasize	#	4
vec_screensize	#	4
ss_outputvec    *       &100

1001
Keydef  DCB     "FontSize/K,SpriteSize/K,RamFSSize/K,RMASize/K,ScreenSize/K"
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
        DCB     0
        ALIGN

; NB: R12 -> private word (don't use workspace, as it may not be present)

ChangeDynamicArea_Code  ROUT
        Push    "R11,LR"
        MOV     R11,sp                  ; remember stack for later
;
        SUB     sp,sp,#ss_outputvec     ; local workspace
;
; scan the comand line by calling OS_ReadArgs
;
        MOV     R1,R0                   ; R1 = input string
        ADR     R0,Keydef               ; R0 = key defion string
        MOV     R2,sp                   ; R2 = output vector
        MOV     R3,#ss_outputvec        ; R3 = max output vector length
        SWI     XOS_ReadArgs
;
; scan the resulting vector for known fields
;
        MOVVC   R0,#rmaarea
        LDRVC   R1,[sp,#vec_rmasize]
        BLVC    changeR0R1              ; R0 = area number, R1 = size required

        MOVVC   R0,#screenarea
        LDRVC   R1,[sp,#vec_screensize]
        BLVC    changeR0R1              ; R0 = area number, R1 = size required

        MOVVC   R0,#fontarea
        LDRVC   R1,[sp,#vec_fontsize]
        BLVC    changeR0R1              ; R0 = area number, R1 = size required

        MOVVC   R0,#spritearea
        LDRVC   R1,[sp,#vec_spritesize]
        BLVC    changeR0R1              ; R0 = area number, R1 = size required

        MOVVC   R0,#ramfsarea           ; NB: do RAMFS last so others get done if it fails
        LDRVC   R1,[sp,#vec_ramfssize]
        BLVC    changeR0R1              ; R0 = area number, R1 = size required

        MOV     sp,R11                  ; restore stack
        Pull    "R11,PC"

; In    R0 = dynamic area number
;       R1 -> string specifying size required (<=0 => don't bother)
; Out   calls OS_ChangeDynamicArea, which gives Service_MemoryMoved
;       this is intercepted, and sets [memoryupdated]
;       this causes a pollword event:
;           which calls set_memory for all memory slots
;           if the RAM disc slot size changes to/from 0
;               [ramfsflag] is set
;               unless dragging the ram slot bar:
;                   reramfsfiler re-ialises the RAMFSFiler
;                   otherwise it waits till the bar is dropped

changeR0R1      ROUT
        Push    "R0-R3,LR"

        CMP     R1,#0
1062
        Pull    "R0-R3,PC",EQ
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

        SWI     XOS_ReadDynamicArea     ; R1 = current size of area
        MOVVC   R3,R1

        LDRVC   R1,[sp,#1*4]
        BLVC    getK                    ; R1 = new amount required

        LDRVC   R0,[sp,#0*4]
        SUBVC   R1,R1,R3                ; R1 = change required
        SWIVC   XOS_ChangeDynamicArea

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


; In    R1 --> string
; Out   R1 = parameter value (number)
; Errors: "Bad number"
;

getK    ROUT
        Push    "R2-R3,LR"
;
        MOV     R0,#10
        SWI     XOS_ReadUnsigned
        Pull    "R2-R3,PC",VS
;
1090
        LDRB    R3,[R1]
1091
        UpperCase R3, R14
1092
        TEQ     R3,#"K"                 ; if terminator is "K" or "k",
1093 1094
        ADDEQ   R1,R1,#1
        MOVEQ   R2,R2,LSL #10           ; multiply by 1024
1095 1096 1097 1098 1099 1100
        TEQ     R3,#"M"                 ; if terminator is "M" or "m",
        ADDEQ   R1,R1,#1
        MOVEQ   R2,R2,LSL #20           ; multiply by 1048576
        TEQ     R3,#"G"                 ; if terminator is "G" or "g",
        ADDEQ   R1,R1,#1
        MOVEQ   R2,R2,LSL #30           ; multiply by 1073741824
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
;
        LDRB    R14,[R1]                ; check terminator
        RSBS    R14,R14,#" "+1          ; ensure GT set if OK
        ADRLEL  R0,ErrorBlock_BadNumb   ; "Number not recognised"
      [ International
        BLLE    TranslateError
      ]
;
        MOVVC   R1,R2                   ; R1 = answer
        Pull    "R2-R3,PC"

Stewart Brodie's avatar
Stewart Brodie committed
1112 1113 1114 1115 1116

 [ :LNOT: No32bitCode
UtilFlags DCD ModuleFlag_32bit
 ]

Neil Turton's avatar
Neil Turton committed
1117
        END