Utility 38.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
; 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
Jeffrey Lee's avatar
Jeffrey Lee committed
21
        &       (EndOfKernelRW-RWBase)+EndOfKernelRO-SysModules_Info
Neil Turton's avatar
Neil Turton committed
22 23

UtilityMod
24
Module_BaseAddr
Neil Turton's avatar
Neil Turton committed
25 26 27 28 29 30 31
        &       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
32 33 34
        &       &F00000
        &       Util_SWI-UtilityMod
        &       Util_SWITab-UtilityMod
Neil Turton's avatar
Neil Turton committed
35 36
        &       0
 [ International_Help <> 0
37
        &       MessageFileName-UtilityMod
Neil Turton's avatar
Neil Turton committed
38 39 40
 |
        &       0
 ]
Stewart Brodie's avatar
Stewart Brodie committed
41
        &       UtilFlags-UtilityMod
Neil Turton's avatar
Neil Turton committed
42

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

50 51 52
  [ ChocolateService
    ;service table
    ;
53 54
        ASSERT Service_ModeExtension < Service_ModeTranslation
        ASSERT Service_ModeTranslation < Service_MessageFileClosed
Stewart Brodie's avatar
Stewart Brodie committed
55 56 57
        ASSERT Service_MessageFileClosed < Service_BufferStarting
        ASSERT Service_BufferStarting    < Service_TerritoryStarted
        ASSERT Service_TerritoryStarted  < Service_DeviceFSCloseRequest
58 59
        ASSERT Service_DeviceFSCloseRequest < Service_EnumerateScreenModes
        ASSERT Service_EnumerateScreenModes < Service_DisplayStatus
60
    ;
Stewart Brodie's avatar
Stewart Brodie committed
61

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

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

        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
136
        LDR     r0, =ZeroPage                   ; used as index to PrinterBufferThing
Neil Turton's avatar
Neil Turton committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        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
156
        LDR     lr, =ZeroPage
Neil Turton's avatar
Neil Turton committed
157
        MOV     r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
158
        LDR     r1, [lr, #OsbyteVars + :INDEX: PrinterActive]
Neil Turton's avatar
Neil Turton committed
159
        TEQ     r1, r2
Jeffrey Lee's avatar
Jeffrey Lee committed
160
        STREQ   r0, [lr, #OsbyteVars + :INDEX: PrinterActive]
Neil Turton's avatar
Neil Turton committed
161
        BEQ     %FT20
Jeffrey Lee's avatar
Jeffrey Lee committed
162
        LDRB    r1, [lr, #OsbyteVars + :INDEX: SerialInHandle]
Neil Turton's avatar
Neil Turton committed
163
        TEQ     r1, r2
Jeffrey Lee's avatar
Jeffrey Lee committed
164
        STREQB  r0, [lr, #OsbyteVars + :INDEX: SerialInHandle]
Neil Turton's avatar
Neil Turton committed
165
        BEQ     %FT20
Jeffrey Lee's avatar
Jeffrey Lee committed
166
        LDRB    r1, [lr, #OsbyteVars + :INDEX: SerialOutHandle]
Neil Turton's avatar
Neil Turton committed
167
        TEQ     r1, r2
Kevin Bracey's avatar
Kevin Bracey committed
168
        Pull    "r0,r1,pc",NE                   ; if not any of these then exit preserving everything
Jeffrey Lee's avatar
Jeffrey Lee committed
169
        STRB    r0, [lr, #OsbyteVars + :INDEX: SerialOutHandle]
Neil Turton's avatar
Neil Turton committed
170 171
20
        SWI     XOS_Find                        ; close file, ignore errors (if we get an error it's closed anyway)
Jeffrey Lee's avatar
Jeffrey Lee committed
172
        LDR     r0, [sp], #8                    ; restore r0, junk r1
Neil Turton's avatar
Neil Turton committed
173
        MOV     r1, #Service_Serviced           ; indicate we closed it
Jeffrey Lee's avatar
Jeffrey Lee committed
174
        LDR     pc, [sp], #4                    ; exit
Neil Turton's avatar
Neil Turton committed
175 176 177 178 179 180 181 182 183 184 185


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
186
           RETURNVS
Neil Turton's avatar
Neil Turton committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
 ]

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


UtilModTitle =  "UtilityModule", 0

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

202 203 204 205 206
  [ Oscli_HashedCommands
;
;***WARNING*** if commands are added or changed, UtilHashedCmdTab MUST be updated correspondingly
;
  ]
Neil Turton's avatar
Neil Turton committed
207
UtilHelpTab
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
           Command   Append,             1,  1, International_Help
           Command   Build,              1,  1, International_Help
           Command   Close,              0,  0, International_Help
           Command   Create,             4,  1, International_Help
           Command   Delete,             1,  1, International_Help
           Command   Dump,               3,  1, International_Help
           Command   Exec,               1,  0, International_Help
           Command   FX,                 5,  1, International_Help    ; 1-3 parms, but up to 2 commas may be there
           Command   GO,               255,  0, International_Help
HelpText
           Command   Help,             255,  0, International_Help
           Command   Key,              255,  1, International_Help
           Command   Load,               2,  1, International_Help ; Fudge order for compatibility (*L.)
           Command   List,               3,  1, International_Help
           Command   Opt,                2,  0, International_Help
           Command   Print,              1,  1, International_Help
           Command   Quit,               0,  0, International_Help
           Command   Remove,             1,  1, International_Help
           Command   Save,               6,  2, International_Help ; *SAVE Fn St + Le Ex Lo (compatibility)
           Command   Shadow,             1,  0, International_Help
           Command   Spool,              1,  0, International_Help
           Command   SpoolOn,            1,  0, International_Help
           Command   TV,                 3,  0, International_Help
           Command   Type,               3,  1, International_Help ; -file fred -tabexpand

233
           Command   Break,              0,  0, International_Help   ; just help
234
           Command   Cache,              1,  0, International_Help
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
           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
267 268
           =   0

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
  [ 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
;
287
           DCD       UHC_hash00 - UtilityMod
288 289
           DCD       UHC_hash01 - UtilityMod
           DCD       UHC_hash02 - UtilityMod
290
           DCD       UHC_hash03 - UtilityMod
291
           DCD       UHC_hash04 - UtilityMod
292
           DCD       UHC_hash05 - UtilityMod
293 294 295 296 297 298 299
           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
300 301
           DCD       UHC_hash0D - UtilityMod
           DCD       UHC_hash0E - UtilityMod
302
           DCD       UHC_hash0F - UtilityMod
303
           DCD       UHC_hash10 - UtilityMod
304 305
           DCD       UHC_hash11 - UtilityMod
           DCD       0
306
           DCD       UHC_hash13 - UtilityMod
307 308
           DCD       UHC_hash14 - UtilityMod
           DCD       0
309
           DCD       UHC_hash16 - UtilityMod
310
           DCD       0
311
           DCD       UHC_hash18 - UtilityMod
312 313 314
           DCD       UHC_hash19 - UtilityMod
           DCD       0
           DCD       UHC_hash1B - UtilityMod
315
           DCD       UHC_hash1C - UtilityMod
316 317 318 319 320 321
           DCD       0
           DCD       UHC_hash1E - UtilityMod
           DCD       UHC_hash1F - UtilityMod
;
; Now the hashed lists
;
322 323 324 325
UHC_hash00
           Command   Load,               2,  1, International_Help ; Fudge order for compatibility (*L.)
           =   0
           ALIGN
326 327 328 329 330
UHC_hash01
           Command   Show,               1,  0, International_Help
           =   0
           ALIGN
UHC_hash02
331
           Command   Type,               3,  1, International_Help ; -file fred -tabexpand
332 333 334
           Command   Configure,        255,  0, Help_Is_Code_Flag :OR: International_Help
           =   0
           ALIGN
335 336 337 338
UHC_hash03
           Command   Quit,               0,  0, International_Help
           =   0
           ALIGN
339 340 341 342 343 344 345
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
346 347 348 349
UHC_hash05
           Command   Exec,               1,  0, International_Help
           =   0
           ALIGN
350
UHC_hash06
351
           Command   Shadow,             1,  0, International_Help
352 353 354 355 356 357 358 359 360 361 362 363
           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
364 365
           Command   Help,             255,  0, International_Help
           Command   Key,              255,  1, International_Help
366 367 368 369
           Command   GOS,                0,  0, International_Help
           =   0
           ALIGN
UHC_hash0A
370 371
           Command   SpoolOn,            1,  0, International_Help
           Command   TV,                 3,  0, International_Help
372 373 374 375 376 377 378 379 380 381 382 383
           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
384 385 386 387 388 389 390 391 392
UHC_hash0D
           Command   Print,              1,  1, International_Help
           Command   Spool,              1,  0, International_Help
           =   0
           ALIGN
UHC_hash0E
           Command   Remove,             1,  1, International_Help
           =   0
           ALIGN
393
UHC_hash0F
394
           Command   Save,               6,  2, International_Help ; *SAVE Fn St + Le Ex Lo (compatibility)
395 396 397 398 399
           Command   IF,               255,  2, International_Help
           Command   Unset,              1,  1, International_Help
           Command   Time,               0,  0, International_Help
           =   0
           ALIGN
400 401 402 403
UHC_hash10
           Command   Build,              1,  1, International_Help
           =   0
           ALIGN
404 405 406 407
UHC_hash11
           Command   RMEnsure,         255,  2, International_Help
           =   0
           ALIGN
408 409 410 411 412
UHC_hash13
           Command   Delete,             1,  1, International_Help
           Command   Opt,                2,  0, International_Help
           =   0
           ALIGN
413
UHC_hash14
414
           Command   Create,             4,  1, International_Help
415 416 417
           Command   SetEval,          255,  2, International_Help
           Command   RMRun,            255,  1, International_Help
           Command   RMInsert,           2,  1, International_Help
418
           Command   Cache,              1,  0, International_Help
419 420
           =   0
           ALIGN
421 422 423 424 425 426 427 428 429 430
UHC_hash16
           Command   Close,              0,  0, International_Help
           Command   Dump,               3,  1, International_Help
           Command   GO,               255,  0, International_Help
           =   0
           ALIGN
UHC_hash18
           Command   Append,             1,  1, International_Help
           =   0
           ALIGN
431 432 433 434 435 436 437 438 439
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
440 441 442 443
UHC_hash1C
           Command   List,               3,  1, International_Help
           =   0
           ALIGN
444
UHC_hash1E
445
           Command   FX,                 5,  1, International_Help    ; 1-3 parms, but up to 2 commas may be there
446 447 448 449 450 451 452 453 454 455 456
           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
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
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

473 474
        LTORG

Neil Turton's avatar
Neil Turton committed
475 476 477 478 479 480
RMFaster_Code
           Push "lr"
           MOV R1, R0
           MOV R0, #ModHandReason_LookupName
           SWI XOS_Module
           Pull "PC", VS
481 482 483 484 485 486
           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
487 488 489 490 491 492 493 494 495 496 497 498
           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
499
           RETURNVS
Neil Turton's avatar
Neil Turton committed
500 501 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

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
532 533
          LDR   r2, =ZeroPage                      ; Try our own message file before Global.
          LDR   r0, [r2, #KernelMessagesBlock]
Neil Turton's avatar
Neil Turton committed
534
          TEQ   r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
535
          ADDNE r0, r2, #KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
536
          ADRL  r1, modules_help1
Jeffrey Lee's avatar
Jeffrey Lee committed
537
        [ ZeroPage <> 0
Neil Turton's avatar
Neil Turton committed
538
          MOV   r2, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
539
        ]
Neil Turton's avatar
Neil Turton committed
540 541 542 543 544 545
          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
546
          LDR    R1, =ZeroPage+Module_List
Neil Turton's avatar
Neil Turton committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
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
596 597 598
        BVC     %FT07
        CLRV
        Pull   "R7, pc"              ; back, clearing V
Neil Turton's avatar
Neil Turton committed
599

Kevin Bracey's avatar
Kevin Bracey committed
600
07
Neil Turton's avatar
Neil Turton committed
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
        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"
Robert Sprowson's avatar
Robert Sprowson committed
636
        LDR     R0, [R3, #Module_TitleStr]
Neil Turton's avatar
Neil Turton committed
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
        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
669
        Entry   "r0,r7",8+256
670
        MRS     r7, CPSR
Neil Turton's avatar
Neil Turton committed
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686

        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
687
        LDR     r0, [sp, #Proc_RegOffset + 0*4]        ; wildcard
Neil Turton's avatar
Neil Turton committed
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 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
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
758 759
        STR     r0, [sp, #Proc_RegOffset + 0*4]
        ORR     r7, r7, #V_bit                          ; CPSR in
Neil Turton's avatar
Neil Turton committed
760 761 762 763 764 765 766 767 768 769 770 771 772 773

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

774
        MSR     CPSR_f, r7
Kevin Bracey's avatar
Kevin Bracey committed
775
        EXIT
Neil Turton's avatar
Neil Turton committed
776 777 778 779 780

06      SWI     XOS_NewLine
        BVS     ShowBang
        B       %BT01

Kevin Bracey's avatar
Kevin Bracey committed
781 782 783 784 785 786 787 788 789 790 791
      [ International
02
        =       "Number:(Number)", 0
03
        =       "Macro:(Macro)", 0
      |
02
        =       "Number", 0
03
        =       "Macro", 0
      ]
792
        ALIGN
Kevin Bracey's avatar
Kevin Bracey committed
793

Neil Turton's avatar
Neil Turton committed
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
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
876 877
        CLRV
        Pull  "pc"
Neil Turton's avatar
Neil Turton committed
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902

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
903 904
        LDR    r2, =ZeroPage   ; Try our own message file before Global.
        LDR    r0, [r2, #KernelMessagesBlock]
Neil Turton's avatar
Neil Turton committed
905
        TEQ    r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
906 907
        ADDNE  r0, r2, #KernelMessagesBlock+4
      [ ZeroPage <> 0
Neil Turton's avatar
Neil Turton committed
908
        MOV    r2, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
909
      ]
Neil Turton's avatar
Neil Turton committed
910 911 912 913 914 915
        SWI    XMessageTrans_Lookup
        SWIVC  XMessageTrans_Dictionary
        MOVVC  r1, r0
        MOVVC  r0, r2
        SWIVC  XOS_PrettyPrint
        Pull   "r1,r3"         ; restore r1 and get buffer pointer
Jeffrey Lee's avatar
Jeffrey Lee committed
916
        Pull   "pc", VS        ; if error, exit
Neil Turton's avatar
Neil Turton committed
917
        MOV    r0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
918
        LDR    R6, =ZeroPage+Module_List
Neil Turton's avatar
Neil Turton committed
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
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
940
        Push  "r2-r7, lr"
Neil Turton's avatar
Neil Turton committed
941 942
        LDR    R4, [R2, #Module_HC_Table]
        CMP    R4, #0
943 944
        Pull  "r2-r7, PC", EQ       ; no table
        MOV    R7, #&80000000       ; flag
Neil Turton's avatar
Neil Turton committed
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
        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
969
        TST    R7, #&80000000
Neil Turton's avatar
Neil Turton committed
970 971 972 973 974 975 976 977
        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
Jeffrey Lee's avatar
Jeffrey Lee committed
978
        Push   "r1"
Neil Turton's avatar
Neil Turton committed
979 980 981
        MOVVC  r1, r0
        MOVVC  r0, r4
        SWIVC  XOS_PrettyPrint
Jeffrey Lee's avatar
Jeffrey Lee committed
982
        Pull   "r1"
Neil Turton's avatar
Neil Turton committed
983 984 985 986 987 988
        B      %FT77
OneModuleK_PrintTitle
        LDR    r0, [stack]
        BL     PrintTitle
77
        MOVVC  r0, r4
989 990
        Pull  "r2-r7, PC", VS
        BIC    R7, R7, #&80000000
Neil Turton's avatar
Neil Turton committed
991 992 993 994 995 996 997 998 999 1000 1001 1002
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
1003
        Pull   "r2-r7,pc",VS
Neil Turton's avatar
Neil Turton committed
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
        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

1022 1023
06      TST    R7, #&80000000
        Pull  "r2-r7, PC", NE
Neil Turton's avatar
Neil Turton committed
1024 1025 1026 1027 1028 1029 1030
        Push  "R0"
        MOV    R0, #0
        SUB    R5, R5, #1
        STRB   R0, [R5, R3]
        MOV    R0, R3
        SWI    XOS_PrettyPrint
        STRVS  r0, [stack]
1031
        Pull  "R0, r2-r7, PC"
Neil Turton's avatar
Neil Turton committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042

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

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

1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

; 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

1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
Robert Sprowson's avatar
Robert Sprowson committed
1093 1094
vec_rmasize     #       4
vec_screensize  #       4
1095 1096
ss_outputvec    *       &100

1097
Keydef  DCB     "FontSize/K,SpriteSize/K,RamFSSize/K,RMASize/K,ScreenSize/K"
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
        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
1158
        Pull    "R0-R3,PC",EQ
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

        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
;
1186
        LDRB    R3,[R1]
1187
        UpperCase R3, R14
1188
        TEQ     R3,#"K"                 ; if terminator is "K" or "k",
1189 1190
        ADDEQ   R1,R1,#1
        MOVEQ   R2,R2,LSL #10           ; multiply by 1024
1191 1192 1193 1194 1195 1196
        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
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
;
        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
1208 1209 1210

UtilFlags DCD ModuleFlag_32bit

Neil Turton's avatar
Neil Turton committed
1211
        END