CtrlUtils 40.3 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 37 38 39
; 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.
;
        SUBT    > Sources.CtrlUtils

; FSControl utilities:

; Facilities for constructing full paths
; Facilities for doing catalogues/examines/infos and *accesses
; Facilities for starting up catalogues etc.

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_ConstructFullPathWithoutFSAndSpecial
;
; In    r1 -> tail for directory
;       r2 -> buffer to construct path into
;       r3 = size of buffer
;       r6 = scb^/special field^
;       fscb^
;
; Out
;       r2 advanced to end of string in buffer
;       r3 reduced by length of string inserted, will be sent
;               negative to correct value for full string
;       r4 = special field^ for root fs
;       r5 = root fscb^
;
40
int_ConstructFullPathWithoutFSAndSpecial Entry
Neil Turton's avatar
Neil Turton committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        TEQ     fscb, #Nowt
        BEQ     %FT10
        LDRB    r14, [fscb, #fscb_info]
        TEQ     r14, #0
        BNE     %FT10
        Push    "r1,r6,fscb"
        LDR     fscb, [r6, #:INDEX:scb_fscb]
        LDR     r1, [r6, #:INDEX:scb_path]
        LDR     r6, [r6, #:INDEX:scb_special]
        BL      int_ConstructFullPathWithoutFSAndSpecial
        LDR     r1, [sp]
        LDRB    r1, [r1]
        TEQ     r1, #0
        ADRNE   r1, %FT90                       ; . between path elements, only if next piece of path is non-""
        BLNE    %FT50
        Pull    "r1,r6,fscb"
        BL      %FT50                           ; <path>
        EXIT
10
        ; Got to a real filing system - construct the starting gubbins
        MOV     r4, r6
        MOV     r5, fscb
63 64
        CMP     r1, #0
        BLNE    %FT50                           ; <path>
Neil Turton's avatar
Neil Turton committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        EXIT

50      ; Secure copy a string into the buffer - always accumulate the length, but
        ; not necessarily copy the string
        Push    "lr"
        RSB     r3, r3, #0
        BL      strlen_accumulate
        RSBS    r3, r3, #0
        Swap    r1, r2, GT
        BLGT    strcpy_advance
        Swap    r1, r2, GT
        Pull    "pc"

90
        DCB     ".", 0
        ALIGN
;
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_ConstructPathWithoutFS
;
; In    r1 -> tail for directory
;       r2 -> buffer to construct path into
;       r3 = size of buffer
;       r6 = scb^/special field^
;       fscb^
;
; Out   r2 advanced to end of string in buffer
;       r3 reduced by length of string inserted, will be sent
;               negative to correct value for full string
;       r4 = special field^ for root fs
;       r5 = root fscb^
;
98
int_ConstructPathWithoutFS Entry "r1,r2,r3"
Neil Turton's avatar
Neil Turton committed
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

        ; Get to root FS and special
        MOV     r3, #0
        BL      int_ConstructFullPathWithoutFSAndSpecial

        LDMIB   sp, {r2,r3}

        ; #<special>:
        TEQ     r4, #NULL
        TEQNE   r4, #Nowt
        ADRNE   r1, %FT80
        BLNE    %FT50
        MOVNE   r1, r4
        BLNE    %FT50
        ADRNE   r1, %FT85
        BLNE    %FT50

        ; <rest of path>
        LDR     r1, [sp]
        BL      int_ConstructFullPathWithoutFSAndSpecial

        ; Store the return values
        STMIB   sp, {r2,r3}

        EXIT

50      ; Secure copy a string into the buffer - always accumulate the length, but
        ; not necessarily copy the string
        Push    "lr"
        RSB     r3, r3, #0
        BL      strlen_accumulate
        RSBS    r3, r3, #0
        Swap    r1, r2, GT
        BLGT    strcpy_advance
        Swap    r1, r2, GT
        Pull    "pc"

80
        DCB     "#", 0
85
        DCB     ":", 0
        ALIGN

;
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_ConstructFullPath
;
; In    r1 -> tail for directory
;       r2 -> buffer to construct path into
;       r3 = size of buffer
;       r6 = scb^/special field^
;       fscb^
;
; Out   r2 advanced to end of string in buffer
;       r3 reduced by length of string inserted, will be sent
;               negative to correct value for full string
;
157
int_ConstructFullPath Entry "r1,r2,r3,r4,r5"
Neil Turton's avatar
Neil Turton committed
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219

        ; Get to root FS and special
        MOV     r3, #0
        BL      int_ConstructPathWithoutFS

        LDMIB   sp, {r2,r3}

        TEQ     r5, #Nowt
        BEQ     %FT10

        ; <fs>
        ADD     r1, r5, #fscb_name
        BL      %FT50

10
        ; : (if no special)
        TEQ     r4, #NULL
        TEQNE   r4, #Nowt
        ADREQ   r1, %FT85
        BLEQ    %FT50

        ; <rest of path>
        LDR     r1, [sp]
        BL      int_ConstructPathWithoutFS

        ; Store the return values
        STMIB   sp, {r2,r3}

        EXIT

50      ; Secure copy a string into the buffer - always accumulate the length, but
        ; not necessarily copy the string
        Push    "lr"
        RSB     r3, r3, #0
        BL      strlen_accumulate
        RSBS    r3, r3, #0
        Swap    r1, r2, GT
        BLGT    strcpy_advance
        Swap    r1, r2, GT
        Pull    "pc"

80
        DCB     "#", 0
85
        DCB     ":", 0
        ALIGN

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_ConstructFullPathWithError
;
; In    r1 -> tail for directory
;       r2 -> buffer to construct path into
;       r3 = size of buffer
;       r6 = scb^/special field^
;       fscb^
;
; Out   r2 advanced to end of string in buffer
;       r3 reduced by length of string inserted, will be sent
;               negative to correct value for full string
;       Buffer overflow error generated if r3<0 at the end
;
220
int_ConstructFullPathWithError Entry
Neil Turton's avatar
Neil Turton committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
        BL      int_ConstructFullPath
        CMP     r3, #0
        addr    r0, ErrorBlock_BuffOverflow, LT
        BLLT    CopyError
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_ConstructFullPathOnStack
;
; In    r1 -> tail
;       r6 = scb/special
;       fscb^
;
; Out
;       stack dropped by enough and hole filled in with path
;
238
int_ConstructFullPathOnStack Entry "r2,r3,r7"
Neil Turton's avatar
Neil Turton committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
        MOV     r7, sp
        MOV     r2, #ARM_CC_Mask
        MOV     r3, #0
        BL      int_ConstructFullPath
        RSB     r3, r3, #3+1            ; 3 for round-up, 1 for \0-terminator
        BIC     r3, r3, #3
        SUB     sp, sp, r3
        MOV     r2, sp
        BL      int_ConstructFullPath
        LDMIA   r7, {$Proc_RegList,pc}

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_CatExTitle
;
; In    r1 -> tail for directory
;       r6 = scb^/special field^
;       fscb^ set
;
258
MaxFilenameSpace * StaticName_length
259
int_CatExTitle Entry "r0-r5,fscb"
Neil Turton's avatar
Neil Turton committed
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
 [ debugcontrol
 DSTRING r1, "CatExTitle tail is "
 DREG r6, "scb^/special field^ is "
 DREG fscb, "fscb is "
 ]
        MOV     r5, sp
        BL      int_ConstructFullPathOnStack

        BL      faff_boot_option_startup_given
        BLVC    int_ReadBootOptionGiven
        MOVVS   sp, r5
        BVS     %FT95

        AND     r2, r2, #3
        TEQ     r2, #0
        ADREQ   r0, dirdotspace0
        TEQ     r2, #1
        ADREQ   r0, dirdotspace1
        TEQ     r2, #2
        ADREQ   r0, dirdotspace2
        TEQ     r2, #3
        ADREQ   r0, dirdotspace3

        MOV     r4, sp
        BL      message_write01
        MOV     sp, r5
        BVS     %FT95

        BL      XOS_NewLine_CopyError

        ; Convert to the root non-MultiFS
        BLVC    fscbscbTofscb
        MOVVC   fscb, r2

 [ debugcontrol
 DREG fscb, "Root fscb is "
 ]

        ; Current directory
        ADRVC   r0, csdspace
        ADRVC   r1, csdspaceu
        MOVVC   r2, #Dir_Current
        BLVC    DisplayDirectoryPath
        BLVC    XOS_NewLine_CopyError

        ; Current directory
        ADRVC   r0, libdotspace
        ADRVC   r1, libdotspaceu
        MOVVC   r2, #Dir_Library
        BLVC    DisplayDirectoryPath
        BLVC    XOS_NewLine_CopyError

        ; User root directory
        ADRVC   r0, urdspace
        ADRVC   r1, urdspaceu
        MOVVC   r2, #Dir_UserRoot
        BLVC    DisplayDirectoryPath
        BLVC    XOS_NewLine_CopyError

        EXIT

90
        ; Not enough stack for cat title
        addr    r0, ErrorBlock_NotEnoughStackForFSEntry
        BL      CopyError
        EXIT

95
        BL      CopyErrorExternal
        EXIT


dirdotspace0    DCB     "DDS0", 0
dirdotspace1    DCB     "DDS1", 0
dirdotspace2    DCB     "DDS2", 0
dirdotspace3    DCB     "DDS3", 0
csdspace        DCB     "CSDS", 0
csdspaceu       DCB     "CSDSU", 0
libdotspace     DCB     "LDS", 0
libdotspaceu    DCB     "LDSU", 0
urdspace        DCB     "URDS", 0
urdspaceu       DCB     "URDSU", 0
        ALIGN

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_CatExBody
;
; In    r0 = 0 for Cat, 1 for Ex, 2 for FileInfo
;       r1 -> path tail to supply to fs
;       r2 -> Wildcard to match names to
;       r6 = special field/scb^
;       fscb^
;
; Out   Directory catalogued
Kevin Bracey's avatar
Kevin Bracey committed
355 356 357 358 359 360 361 362 363 364 365 366

 [ CatExLong

; When long file names are in use, we vary the width of columns according to
; the length of the longest filename.  We also adjust the width for the length
; of the file name; we scan the directory twice.  The first time, we simply
; look at the length of the longest name.

CatExMinWidth   *       12              ; minimum amount to allocate for a name (8+'/'+3)

 ]

Neil Turton's avatar
Neil Turton committed
367
CatSpaceAdjustForNFS * -36
Kevin Bracey's avatar
Kevin Bracey committed
368 369 370 371 372
 [ CatExLong
CatSpace * 320
CatStringSpace * 400
 |
CatSpace * 280
Neil Turton's avatar
Neil Turton committed
373
CatStringSpace * 100
Kevin Bracey's avatar
Kevin Bracey committed
374
 ]
Neil Turton's avatar
Neil Turton committed
375 376 377 378 379 380 381 382 383

CatExBodyFrame  RN 9
        ^       0, CatExBodyFrame
CatExBody_EntryCount    # 4
CatExBody_ScreenWidth   # 4
CatExBody_LPos          # 4
CatExBody_PreGap        # 4
CatExBody_ItemsLeft     # 4
CatExBody_EntryRover    # 4
Kevin Bracey's avatar
Kevin Bracey committed
384 385 386
 [ CatExLong
CatExBody_EntryWidth    # 4     ; the width, in characters, of the longest filename to be displayed
 ]
Neil Turton's avatar
Neil Turton committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
CatExBody_FrameSize * :INDEX: @
CatExBody_CatExType     # 4     ; R0In
CatExBody_PathTail      # 4     ; R1In
CatExBody_WildCard      # 4     ; R2In
CatExBody_R3In          # 4
CatExBody_R4In          # 4
CatExBody_R5In          # 4
CatExBody_Special       # 4     ; R6In
CatExBody_R7In          # 4
CatExBody_R8In          # 4
CatExBody_R9In          # 4

CatExBody_WindBlock
        DCD     VduExt_WindowWidth
        DCD     -1

Kevin Bracey's avatar
Kevin Bracey committed
403
 [ CatExLong
Jeffrey Lee's avatar
Jeffrey Lee committed
404
CatExMaxWidthStr        = "FileSwitch$$NameWidth",0
Kevin Bracey's avatar
Kevin Bracey committed
405 406 407 408
        ALIGN
 ]

 [ CatExLong
409
int_CatExBody Entry "r0-r9", CatExBody_FrameSize
Kevin Bracey's avatar
Kevin Bracey committed
410
 |
411
int_CatExBody Entry "r0-r9", CatExBody_FrameSize
Kevin Bracey's avatar
Kevin Bracey committed
412
 ]
Neil Turton's avatar
Neil Turton committed
413 414 415 416 417 418 419 420 421 422 423 424 425
        MOV     CatExBodyFrame, sp
        SUB     sp, sp, #CatSpace + CatStringSpace

 [ debugcontrol
        DREG    r0, "int_CatExBody rc",cc
        DSTRING r1, " on ",cc
        DSTRING r2, " with wildcard "
 ]

        MOV     lr, #0
        STR     lr, CatExBody_EntryCount
        STR     lr, CatExBody_LPos
        STR     lr, CatExBody_PreGap
Kevin Bracey's avatar
Kevin Bracey committed
426 427 428 429

 [ CatExLong
        STR     lr, CatExBody_EntryWidth        ; store the initial maximum width of an entry
 ]
Neil Turton's avatar
Neil Turton committed
430 431 432 433 434
        ADR     r0, CatExBody_WindBlock
        ADR     r1, CatExBody_ScreenWidth
        SWI     XOS_ReadVduVariables
        BVS     %FT80

Kevin Bracey's avatar
Kevin Bracey committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 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 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 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
 [ CatExLong

; *** Here we scan the dir entries, to find the longest name.  Boring, but someone
;     has to do it.

        MOV     r4, #0          ; we don't need to use the stack frame so much here
05
        ; Read another set of directory entries
        MOV     r0, #fsfunc_ReadDirEntriesInfo
        LDR     r1, CatExBody_PathTail
        ADD     r2, sp, #CatStringSpace
        MOV     r3, #CatSpace + CatSpaceAdjustForNFS
        MOV     r5, #CatSpace + CatSpaceAdjustForNFS
        LDR     r6, CatExBody_Special

 [ debugcontrol
 DSTRING r1,"ReadDirEntriesInfo(",cc
 DREG r2,",",cc
 DREG r3,",",cc
 DREG r4,",",cc
 DREG r5,",",cc
 DREG r6,",",cc
 DLINE ")"
 ]
        BL      CallFSFunc_Given
 [ debugcontrol
 DREG r3,"...->(",cc
 DREG r4,",",cc
 DLINE ")"
 ]

        BVS     %FT85

        ; Where no items read?
        TEQ     r3, #0
        BEQ     %FT07

        MOV     r5, r3                          ; r5 used to count down entries in buffer

        ADD     r1, sp, #CatStringSpace         ; point r1 at the buffer

        LDR     r2, CatExBody_EntryWidth        ; width of an entry

        ADD     r1, r1, #&14                    ; point at string
06
        ; deal with another entry

        BL      strlen                          ; (r1->r3) get length of the string

        CMP     r3, r2                          ; is this name longer than the longest?
        MOVHI   r2, r3                          ; if so, then set new longest

        ADD     r1, r1, r3                      ; ptr to next entry
        ADD     r1, r1, #3+1+&14                ; and terminator and round to word, then onto string
        BIC     r1, r1, #3

        SUBS    r5, r5, #1                      ;

        BNE     %BT06                           ; if not then back round loop

        STR     r2, CatExBody_EntryWidth        ; store (maybe updated) width of entry

        CMP     r4, #-1                         ; go to the next stage
        BEQ     %FT08

        B       %BT05                           ; do some more entries

07
        ; No items read

        ; Was it the end?
        CMP     r4, #-1
        BEQ     %FT08                           ; if it was the end, then we can go to the next stage

        ; Wasn't end, so must be buffer overflow
        addr    r0, ErrorBlock_BuffOverflow
        BL      CopyError
        B       %FT85


08
        ; the next stage

        ; find out if there's a system variable with the entry width

        SUB     sp, sp, #16
        MOV     r2, #15
        MOV     r1, sp
        MOV     r3, #0
        MOV     r4, #3                          ; we want to convert it to a string (so that Macros will be sorted)

        ADR     r0, CatExMaxWidthStr            ; variable name

        SWI     XOS_ReadVarVal                  ; get the variable back

 [ debugcontrol
        DREG    r1, "ptr: "
 ]

        MOVVS   r2, #255                        ; maximum limit
        BVS     %FT09                           ; variable not found or too long - ignore it

        CMPS    r4, #1

        LDREQ   r2, [sp]
        BEQ     %FT09


        ; convert its value

        MOV     r0, #0                          ; terminate the string
        STRB    r0, [sp, r2]                    ;

        MOV     r0, #10+(1<<30)                 ; base 10, restrict range 0-255
        MOV     r1, sp

 [ debugcontrol
        DSTRING r1, "string: "
 ]

        SWI     XOS_ReadUnsigned                ; get the value

 [ debugcontrol
        DREG    r2, "converted to: "
 ]

        MOVVS   r2, #255

09      ; here, r2 should contain the max width, or zero
        ADD     sp, sp, #16

        CMPS    r2, #255
        MOVHI   r2, #255

        MOVS    r2, r2
        MOVMI   r2, #12

 [ debugcontrol
        DREG    r2, "init width: "
 ]


        LDR     r3, CatExBody_EntryWidth        ; get the width

        ; now compare screen with and entry width

        LDR     r0, CatExBody_ScreenWidth       ; width of screen

        LDR     r14, CatExBody_CatExType

        TEQ     r14, #0
        SUBEQ   r0, r0, #21-12
        TEQ     r14, #1
        SUBEQ   r0, r0, #63-12
        TEQ     r14, #2
        SUBEQ   r0, r0, #68-12

 [ debugcontrol
        DREG    r0, "width available from screen "

 ]
;       MOV     lr, #&6000
;       STMIA   lr, {r0,r2,r3}

        CMPS    r3, r0
        MOVGT   r3, r0

        CMPS    r3, r2                          ; set the min width
        MOVGT   r3, r2

        CMPS    r3, #CatExMinWidth              ; and if it's <12, make it 12
        MOVLT   r3, #CatExMinWidth

        STR     r3, CatExBody_EntryWidth        ; and now we have a width!

;       STR     r3, [lr, #12]

 [ debugcontrol
 DREG r3, "CatExBody_EntryWidth: "
 ]

        ; now that we've worked out the width, we do the whole thing
        ; again.  we should really optimise for the case where there's
        ; only one batch!

 ]

	MOV	r4, #0
	STR	r4, CatExBody_EntryCount

Neil Turton's avatar
Neil Turton committed
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
10
        ; Read another set of directory entries
        MOV     r0, #fsfunc_ReadDirEntriesInfo
        LDR     r1, CatExBody_PathTail
        ADD     r2, sp, #CatStringSpace
        MOV     r3, #CatSpace + CatSpaceAdjustForNFS
        LDR     r4, CatExBody_EntryCount
        MOV     r5, #CatSpace + CatSpaceAdjustForNFS
        LDR     r6, CatExBody_Special
 [ debugcontrol
 DSTRING r1,"ReadDirEntriesInfo(",cc
 DREG r2,",",cc
 DREG r3,",",cc
 DREG r4,",",cc
 DREG r5,",",cc
 DREG r6,",",cc
 DLINE ")"
 ]
        BL      CallFSFunc_Given
 [ debugcontrol
 DREG r3,"...->(",cc
 DREG r4,",",cc
 DLINE ")"
 ]
        BVS     %FT85

        STR     r4, CatExBody_EntryCount
        STR     r3, CatExBody_ItemsLeft

        ; Where no items read?
        TEQ     r3, #0
        BEQ     %FT75

Kevin Bracey's avatar
Kevin Bracey committed
658

Neil Turton's avatar
Neil Turton committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
        ADD     r1, sp, #CatStringSpace
20
        ; Fill the buffer on the stack

        ; pick out load, execute, length, Attributes, objecttype, advancing r1 to the object name
        LDMIA   r1!, {r2,r3,r4,r5,r6}
        STR     r1, CatExBody_EntryRover

        ; Is it a match?
        MOV     r0, r2
        LDR     r2, CatExBody_WildCard
        BL      WildMatch
        MOV     r2, r0
        BNE     %FT33

        LDR     r8, CatExBody_CatExType         ; r0 as passed in
        TEQ     r8, #2
        BNE     %FT25
        LDR     lr, [fscb, #fscb_info]
        TST     lr, #fsinfo_fileinfo
        BEQ     %FT25

        ; Filing system gets given FileInfo
        MOV     r7, sp
        BL      strlen
        MOV     r0, r1
        LDR     r1, CatExBody_PathTail
        BL      strlen_accumulate
        ADD     r3, r3, #1+1+3
        BIC     r3, r3, #3
        SUB     sp, sp, r3
        MOV     r2, r1
        MOV     r1, sp
        BL      strcpy_advance
        MOV     r2, #"."
        STRB    r2, [r1], #1
        MOV     r2, r0
        BL      strcpy_advance
        MOV     r0, #fsfunc_FileInfo
        MOV     r1, sp
        LDR     r6, CatExBody_Special
 [ debugcontrol
        DREG    r0, "Use filing system:",cc
        DSTRING r1,",",cc
        DSTRING r6,","
 ]
        BL      CallFSFunc_Given
        MOV     sp, r7
        BVS     %FT85
        B       %FT33

25
        MOV     r0, r6                          ; objecttype
        MOV     r6, sp                          ; Buffer start
        ADD     r7, r6, #CatStringSpace         ; Buffer end

        BL      AdjustObjectTypeReMultiFS
Kevin Bracey's avatar
Kevin Bracey committed
716 717 718 719 720 721 722
 [ CatExLong
        Push    "r10"
        LDR     r10, CatExBody_EntryWidth       ; get the width of the entry
  [ debugcontrol
        DREG    r10, "Width being used: "
  ]
 ]
Neil Turton's avatar
Neil Turton committed
723
        BL      int_CatExItem
Kevin Bracey's avatar
Kevin Bracey committed
724 725 726
 [ CatExLong
        Pull    "R10"
 ]
Neil Turton's avatar
Neil Turton committed
727 728 729 730 731 732 733 734
        BVS     %FT80

        ; Get width of string to output
        MOV     r1, sp
        BL      strlen

        ; Column width in r0
        LDR     r14, CatExBody_CatExType
Kevin Bracey's avatar
Kevin Bracey committed
735 736 737 738 739 740 741 742 743 744

 [ CatExLong
        LDR     r0, CatExBody_EntryWidth
        TEQ     r14, #0
        ADDEQ   r0, r0, #21-12
        TEQ     r14, #1
        ADDEQ   r0, r0, #63-12
        TEQ     r14, #2
        ADDEQ   r0, r0, #68-12
 |
Neil Turton's avatar
Neil Turton committed
745 746 747 748 749 750
        TEQ     r14, #0
        MOVEQ   r0, #21                 ; Cat column width
        TEQ     r14, #1
        MOVEQ   r0, #63                 ; Ex column width
        TEQ     r14, #2
        MOVEQ   r0, #68                 ; FileInfo column width
Kevin Bracey's avatar
Kevin Bracey committed
751
 ]
Neil Turton's avatar
Neil Turton committed
752 753 754 755 756 757 758 759

        ; r6{Spacing going to be needed} =
        ;       ((r7{position across line} + r8{at end of entry} + r0{column width} - 1)/r0{column width})*r0{column width} - r7{position across line}
        LDR     r7, CatExBody_LPos
        LDR     r8, CatExBody_PreGap
        ADD     r6, r7, r8
        ADD     r6, r6, r0
        SUB     r6, r6, #1
760
        DivRem  r5, r6, r0, r14, norem
Neil Turton's avatar
Neil Turton committed
761 762 763 764 765 766 767 768 769 770 771 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 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
        MUL     r6, r0, r5
        SUB     r6, r6, r7

        ; r5{new position if printed on this line} = r6{spacing} + r3{width} + r7{current position}
        ADD     r5, r6, r3
        ADD     r5, r5, r7

        ; If following a name and overflow a line, then do a line feed
        TEQ     r8, #0
        LDR     lr, CatExBody_ScreenWidth
        CMPNE   r5, lr
        BLS     %FT30
        SWI     XOS_NewLine
        BVS     %FT80
        MOV     r7, #0  ; position
        MOV     r8, #0  ; after an entry
        MOV     r6, #0  ; spacing

30
        ; position += spacing + width
        ADD     r7, r7, r6
        ADD     r7, r7, r3

        ; Spew out the spacing
        BL      SpewSpaces

        ; Display the item
        MOVVC   r0, sp
        SWIVC   XOS_Write0
        BVS     %FT80

        ; At end of item indicator (is inter-item gap)
        MOV     r8, #1

        STR     r7, CatExBody_LPos
        STR     r8, CatExBody_PreGap

33
        ; Advance to the next item (skip over the name and round up to a word)
        LDR     r1, CatExBody_EntryRover
        ADD     r3, r1, #1 + 3          ; 1 for the nul terminator, 3 for the rounding
        BL      strlen_accumulate
        BIC     r1, r3, #3

        ; Any more items in this batch?
        LDR     r3, CatExBody_ItemsLeft
        SUBS    r3, r3, #1
        STR     r3, CatExBody_ItemsLeft
        BNE     %BT20

        LDR     r4, CatExBody_EntryCount
        CMP     r4, #-1
        BNE     %BT10

50
        ; Successful completion of the body - tidy up the display

        ; If not at start of line, get to the start of line
        LDR     r8, CatExBody_PreGap
        TEQ     r8, #0
        SWINE   XOS_NewLine
        BVS     %FT80

        B       %FT85

75
        ; No items read

        ; Was it the end?
        LDR     r4, CatExBody_EntryCount
        CMP     r4, #-1
        BEQ     %BT50

        ; Wasn't end, so must be buffer overflow
        addr    r0, ErrorBlock_BuffOverflow
        BL      CopyError
        B       %FT85

80
        ; External error - copy it
        BL      CopyErrorExternal

85
        MOV     sp, CatExBodyFrame
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; SpewSpaces
;
; In    r6 = number of spaces to spew
;
; Out   spaces spewed (r0, VS error return mechanism)
;
855
SpewSpaces Entry "r6"
Neil Turton's avatar
Neil Turton committed
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
        B       %FT20
10
        SWI     XOS_WriteI+space
        EXIT    VS
20
        SUBS    r6, r6, #1
        BPL     %BT10
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_CatExItem
;
; In    r0 = object type
;       r1 ->name
;       r2 = load address
;       r3 = execute address
;       r4 = length
;       r5 = attributes
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;       r8 = number of control string:
;               0 - CatFormat
;               1 - ExFormat
;               2 - FileInfoFormat
Kevin Bracey's avatar
Kevin Bracey committed
881 882 883 884

 [ CatExLong
;       r10 = width of a filename field
 ]
Neil Turton's avatar
Neil Turton committed
885 886 887 888 889 890 891 892
;
; Out   r0, VS error return mechanism

CatFormat       DCB "Cat",0
ExFormat        DCB "Ex",0
FileInfoFormat  DCB "FileInfo",0
        ALIGN

Kevin Bracey's avatar
Kevin Bracey committed
893
 [ CatExLong
894
int_CatExItem Entry     "r0-r9"
Kevin Bracey's avatar
Kevin Bracey committed
895
 |
896
int_CatExItem Entry     "r0-r9"
Kevin Bracey's avatar
Kevin Bracey committed
897
 ]
Neil Turton's avatar
Neil Turton committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
        TEQ     r8, #0
        ADREQ   r0, CatFormat
        TEQ     r8, #1
        ADREQ   r0, ExFormat
        TEQ     r8, #2
        ADREQ   r0, FileInfoFormat
        BL      message_lookup
        BVS     %FT40

        MOV     r8, r0
        LDR     r0, [sp, #Proc_LocalStack + 0*4]

        LDRB    r9, [r8], #1
        CMP     r9, #" "
        BHI     %FT20
        B       %FT30

10
        ; Space between items
        MOV     r0, #space
        BL      int_StuffByteIntoBuffer

20
 [ debugcontrol
        DREG    r9, "Stuffing a number "
 ]

        ; Place the text of this item into the buffer
        LDR     r0, [sp, #Proc_LocalStack + 0*4]        ; r0 in
        TEQ     r9, #"0"
        BLEQ    int_StuffFilenameIntoBuffer
        TEQ     r9, #"1"
        BLEQ    int_StuffAttsIntoBuffer
        TEQ     r9, #"2"
        BLEQ    int_StuffLoadExecIntoBuffer
        TEQ     r9, #"3"
        BLEQ    int_StuffFileSizeIntoBuffer
        TEQ     r9, #"4"
        BLEQ    int_StuffExactLoadExecIntoBuffer
        TEQ     r9, #"5"
        BLEQ    int_StuffExactFileSizeIntoBuffer

        BVS     %FT40

        ; Advance to next item
        LDRB    r9, [r8], #1
        CMP     r9, #space
        BHI     %BT10

30
        ; Terminate the buffer
        MOV     r0, #0
        BL      int_StuffByteIntoBuffer

40
        STRVS   r0, [sp]
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffFilenameIntoBuffer
;
; In    r1 ->name
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
Kevin Bracey's avatar
Kevin Bracey committed
963 964 965 966

 [ CatExLong
;       r10 = width of field
 ]
Neil Turton's avatar
Neil Turton committed
967 968 969
;
; Out   r6 advanced or error (r0,VS errors)
;
970
int_StuffFilenameIntoBuffer Entry "r3"
Kevin Bracey's avatar
Kevin Bracey committed
971 972 973 974 975 976 977
 [ CatExLong
  [ debugcontrol
	DREG	r10, "stuffing width: "
  ]
        MOV     r3, r10
        BL      int_StuffRPaddedMaybeTruncatedStringIntoBuffer
 |
Neil Turton's avatar
Neil Turton committed
978 979
        MOV     r3, #12
        BL      int_StuffRPaddedStringIntoBuffer
Kevin Bracey's avatar
Kevin Bracey committed
980
 ]
Neil Turton's avatar
Neil Turton committed
981 982 983 984 985 986 987 988 989 990 991 992 993
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffAttsIntoBuffer
;
; In    r0 = object type
;       r5 = attributes
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
994
int_StuffAttsIntoBuffer Entry "r0,r3", 8
Neil Turton's avatar
Neil Turton committed
995 996 997 998 999 1000 1001 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
        MOV     r3, sp

        ; D
        TST     r0, #object_directory
        MOVNE   r0, #"D"
        STRNEB  r0, [r3], #1

        ; L
        TST     r5, #locked_attribute
        MOVNE   r0, #"L"
        STRNEB  r0, [r3], #1

        ; W
        TST     r5, #write_attribute
        MOVNE   r0, #"W"
        STRNEB  r0, [r3], #1

        ; R/
        TST     r5, #read_attribute
        MOVNE   r0, #"R"
        STRNEB  r0, [r3], #1
        MOV     r0, #"/"
        STRB    r0, [r3], #1

        ; W
        TST     r5, #public_write_attribute
        MOVNE   r0, #"W"
        STRNEB  r0, [r3], #1

        ; R
        TST     r5, #public_read_attribute
        MOVNE   r0, #"R"
        STRNEB  r0, [r3], #1

        MOV     r0, #0
        STRB    r0, [r3], #1

        MOV     r3, #7
        MOV     r1, sp
        BL      int_StuffRPaddedStringIntoBuffer

        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffLoadExecIntoBuffer
;
; In    r0 = object type
;       r2 = load address
;       r3 = execute address
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
ExDateFormat DCB "ExDt",0
ExLoadExecFormat DCB "ExLdEx",0
        ALIGN

1055
int_StuffLoadExecIntoBuffer Entry "r4,r5"
Neil Turton's avatar
Neil Turton committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
        ADR     r4, ExDateFormat
        ADR     r5, ExLoadExecFormat
        BL      int_GenStuffLoadExecIntoBuffer
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffExactLoadExecIntoBuffer
;
; In    r0 = object type
;       r2 = load address
;       r3 = execute address
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
FileInfoDateFormat DCB "FileInDt",0
FileInfoLoadExecFormat DCB "FileInLdEx",0
        ALIGN

1077
int_StuffExactLoadExecIntoBuffer Entry "r4,r5"
Neil Turton's avatar
Neil Turton committed
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
        ADR     r4, FileInfoDateFormat
        ADR     r5, FileInfoLoadExecFormat
        BL      int_GenStuffLoadExecIntoBuffer
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_GenStuffLoadExecIntoBuffer
;
; In    r0 = object type
;       r2 = load address
;       r3 = execute address
;       r4 = tag of date format
;       r5 = tag of load+exec format
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
DirText DCB "Dr",0
        ALIGN

1100
int_GenStuffLoadExecIntoBuffer Entry "r0-r4",24
Neil Turton's avatar
Neil Turton committed
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208

        ; Is it a directory?
        TST     r0, #object_directory
        BEQ     %FT10

        ; It's a directory - output "Directory"
        ADR     r0, DirText
        BL      message_lookup
        MOVVC   r1, r0
        B       %FT20

10
        ; Handling of files
        BL      IsFileTyped
        addr    r1, anull, NE   ; No text in the type field if untyped
        BNE     %FT20

        ; It's typed - display type then date
        BL      ExtractFileType
        BL      DecodeFileType
        BVS     %FT90

        STMVCIA sp, {r2,r3}
        MOVVC   r1, #0
        STRVCB  r1, [sp, #8]
        MOVVC   r1, sp

20
        ; Copy the type to the type field
        MOVVC   r3, #9
        BLVC    int_StuffRPaddedStringIntoBuffer
        MOVVC   r0, #space
        BLVC    int_StuffByteIntoBuffer
        BVS     %FT90

        LDR     r2, [sp, #Proc_LocalStack + 2*4]
        LDR     r3, [sp, #Proc_LocalStack + 3*4]
        BL      IsFileTyped
        BNE     %FT40

        ; Display the date. Reverse order of words to correct byte ordering of date
        STR     r3, [sp, #0*4]
        STR     r2, [sp, #1*4]

        MOV     r0, r4
        BL      message_lookup
        BVS     %FT90

 [ debugcontrol
        DSTRING r0,"Looked up date format OK:"
 ]

        ; faff faff faff: copy the string to be nul-terminated
        MOV     r1, r0
        BL      strlen
        ADD     r4, r3, #1 + 3
        BIC     r4, r4, #3
        SUB     sp, sp, r4
        MOV     r2, r1
        MOV     r1, sp
        BL      strcpy          ; nul terminates

        MOV     r3, r1
        ADD     r0, sp, r4
        MOV     r1, r6
        SUB     r2, r7, r6
        SWI     XOS_ConvertDateAndTime
        ADD     sp, sp, r4
        MOVVC   r6, r1

        B       %FT90

40
        ; It's untyped - display as hex

        ; Convert the hex numbers into text
        MOV     r0, r2
        MOV     r1, sp
        MOV     r2, #12
        SWI     XOS_ConvertHex8
        MOVVC   r0, r3
        ADDVC   r1, sp, #12
        MOVVC   r2, #12
        SWIVC   XOS_ConvertHex8

        ; Now stuff the buffer with the hex numbers
        MOVVC   r0, r5
        MOVVC   r1, r6
        SUBVC   r2, r7, r6
        MOVVC   r4, sp
        ADDVC   r5, sp, #12
        BLVC    message_lookup22_into_buffer
        MOVVC   r6, r1

90
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffFileSizeIntoBuffer
;
; In    r4 = length
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
1209
int_StuffFileSizeIntoBuffer Entry "r0-r2"
Neil Turton's avatar
Neil Turton committed
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
        MOV     r0, r4
        MOV     r1, r6
        SUB     r2, r7, r6
        SWI     XOS_ConvertFixedFileSize
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        MOVVC   r6, r1
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffExactFileSizeIntoBuffer
;
; In    r4 = length
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
1228
int_StuffExactFileSizeIntoBuffer Entry "r0-r2"
Neil Turton's avatar
Neil Turton committed
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
        MOV     r0, r4
        MOV     r1, r6
        SUB     r2, r7, r6
        SWI     XOS_ConvertHex8
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        MOVVC   r6, r1
        EXIT

 [ {FALSE}
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffLPaddedStringIntoBuffer
;
; In    r1 ->name
;       r3 = required width
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
; Stuffs the name into the buffer padded to width
;
1251
int_StuffLPaddedStringIntoBuffer Entry "r3"
Neil Turton's avatar
Neil Turton committed
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
        BL      strlen_accumulate
        RSBS    r3, r3, #0
        MOVLO   r3, #0
        BL      int_StuffSpacesIntoBuffer
        EXIT    VS
        BL      int_StuffStringIntoBuffer
        EXIT
 ]

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffRPaddedStringIntoBuffer
;
; In    r1 ->name
;       r3 = required width
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
; Stuffs the name into the buffer padded to width
;
1274
int_StuffRPaddedStringIntoBuffer Entry "r3"
Neil Turton's avatar
Neil Turton committed
1275 1276 1277 1278 1279 1280 1281 1282 1283
        RSB     r3, r3, #0
        BL      strlen_accumulate
        BL      int_StuffStringIntoBuffer
        EXIT    VS
        RSBS    r3, r3, #0
        MOVHI   r3, #0
        BL      int_StuffSpacesIntoBuffer
        EXIT

Kevin Bracey's avatar
Kevin Bracey committed
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
 [ CatExLong
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffRPaddedMaybeTruncatedStringIntoBuffer
;
; In    r1 ->name
;       r3 = required width
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
; Stuffs the name into the buffer padded to width.  If the string's
; longer than the buffer width, it truncates it.
;
1299
int_StuffRPaddedMaybeTruncatedStringIntoBuffer Entry "r3,r4"
Kevin Bracey's avatar
Kevin Bracey committed
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
        MOV     r4, r3
        BL      strlen                  ; string length in R3
        CMP     r3, r4
        BHI     %FT10
        SUB     r3, r3, r4
        BL      int_StuffStringIntoBuffer
        EXIT    VS
        RSBS    r3, r3, #0
        MOVHI   r3, #0
        BL      int_StuffSpacesIntoBuffer
        EXIT

10
        MOV     r3, r4
        BL      int_StuffRTruncatedStringIntoBuffer
        EXIT
 ]

Neil Turton's avatar
Neil Turton committed
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffSpacesIntoBuffer
;
; In    r1 ->name
;       r3 = required number of spaces
;       r6 = buffer
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced or error (r0,VS errors)
;
; Stuffs the given number of spaces into the buffer
;
1331
int_StuffSpacesIntoBuffer Entry "r0,r3"
Neil Turton's avatar
Neil Turton committed
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
        MOV     r0, #space
        B       %FT20
10
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT    VS
20
        SUBS    r3, r3, #1
        BGE     %BT10           ; Signed
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffStringIntoBuffer
;
; In    r1 = string (ctrl char terminated)
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced by string length, or error (r0,VS)
;       terminator not placed into buffer
;
1354
int_StuffStringIntoBuffer Entry "r0,r1"
Neil Turton's avatar
Neil Turton committed
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
        B       %FT20
10
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT    VS
20
        LDRB    r0, [r1], #1
        CMP     r0, #space-1
        TEQHI   r0, #delete
        BHI     %BT10
        EXIT

Kevin Bracey's avatar
Kevin Bracey committed
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
 [ CatExLong
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffRTruncatedStringIntoBuffer
;
; In    r1 = string (ctrl char terminated)
;       r3 = number of characters to print (including '...')
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced by string length, or error (r0,VS)
;       terminator not placed into buffer
;
1380
int_StuffRTruncatedStringIntoBuffer Entry "r0,r1,r3"
Kevin Bracey's avatar
Kevin Bracey committed
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
        SUB     r3, r3, #3
        B       %FT20
10
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT    VS
20
        SUBS    r3, r3, #1
        BMI     %FT30
        LDRB    r0, [r1], #1
        CMP     r0, #space-1
        TEQHI   r0, #delete
        BHI     %BT10
        EXIT

30 ; just termination to deal with
        MOV     r0, #'.'
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT    VS
        MOV     r0, #'.'
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT    VS
        MOV     r0, #'.'
        BL      int_StuffByteIntoBuffer
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT

 ]
Neil Turton's avatar
Neil Turton committed
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; int_StuffByteIntoBuffer
;
; In    r0 = byte
;       r6 = Buffer start
;       r7 = buffer end (beyond end of usable buffer space)
;
; Out   r6 advanced by 1, or error (r0,VS)
;
1422
int_StuffByteIntoBuffer Entry "r0"
Neil Turton's avatar
Neil Turton committed
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
        CMP     r6, r7
        STRLOB  r0, [r6], #1
        EXIT    LO
        addr    r0, ErrorBlock_BuffOverflow
        BL      copy_error
        STRVS   r0, [sp, #Proc_LocalStack + 0*4]
        EXIT

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; Process_WildPathnameMustExist
;
; In    r1 -> Wildcarded pathname
;
; Out   r0 = object type of 1st of the objects
;       r1 -> Pathtail for object or directory for enumeration as appropriate
;       r2 = load address of the 1st of the objects
;       r3 = execute address of the 1st of the objects
;       r4 = length of the 1st of the objects
;       r5 = attributes of the 1st of the objects
;       r6 = scb^/special field^
;       r7 = NULL or wildcard for enumeration
;       fscb^
;
; PassedFilename, FullFilename and SpecialField are the relevant locations
; for the various parts after processing.
;
; Will generate an error if the object doesn't exist
;
1452
Process_WildPathnameMustExist Entry
Neil Turton's avatar
Neil Turton committed
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 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 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
        BL      Process_WildPathname
        EXIT    VS
        TEQ     r0, #object_nothing
        EXIT    NE
        LDR     r1, PassedFilename
        BL      SetMagicPlainNotFound
        BL      JunkFileStrings
        EXIT


; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
; Process_WildPathname
;
; In    r1 -> Wildcarded pathname
;
; Out   r0 = object type of 1st of the objects
;       r1 -> Pathtail for object or directory for enumeration as appropriate
;       r2 = load address of the 1st of the objects
;       r3 = execute address of the 1st of the objects
;       r4 = length of the 1st of the objects
;       r5 = attributes of the 1st of the objects
;       r6 = scb^/special field^
;       r7 = NULL or wildcard for enumeration
;       fscb^
;
; PassedFilename, FullFilename and SpecialField are the relevant locations
; for the various parts after processing.
;
Process_WildPathname ALTENTRY

        ADR     r0, PassedFilename
        MOV     r2, #NULL
        addr    r3, anull
        ADR     r4, FullFilename
        MOV     r5, #0
        ADR     r6, SpecialField
        BL      TopPath_DoBusinessToPath
        EXIT    VS

        ; Reject case with no filing system
        TEQ     fscb, #Nowt
        LDREQ   r1, PassedFilename
        BLEQ    SetMagicPlainNotFound
        BLVS    JunkFileStrings
        EXIT    VS

        ; Is it an absolute directory?
        Push    "r0,r3"
        BL      strlen
        SUB     r3, r3, #1
        LDRB    r0, [r1, r3]
        BL      IsAbsolute
        Pull    "r0,r3"
        BEQ     %FT70

        ; It's a non-absolute, check the source leaf for wildness

        LDR     r7, PassedFilename
 [ debugutil
        DSTRING r7, "PassedFilename = "
 ]
        Push    "r1,r3"
        MOV     r1, r7
        BL      strlen
        ADD     r8, r7, r3
        Pull    "r1,r3"

10
        LDRB    r14, [r8], #-1
        TEQ     r14, #"*"
        TEQNE   r14, #"#"
        BEQ     %FT30
        TEQ     r14, #"."
        TEQNE   r14, #":"       ; blah:blah or blah::blah, neither of which are wildcards
        BEQ     %FT70
        CMP     r8, r7
        BHS     %BT10
        B       %FT70

20
        ; A wildcard char has been found, continue and see whether it's a leaf name
        ; or just a wierd disc name.
        LDRB    r14, [r8], #-1
        TEQ     r14, #"."
        BEQ     %FT40
        TEQ     r14, #":"
        BNE     %FT30
        CMP     r8, r7
        BLO     %FT70           ; It's just :<wierd disc name>
        LDRB    r14, [r8]
        TEQ     r14, #":"
        BEQ     %FT70           ; It's <thing>::<wierd disc name>
        MOV     r14, #":"
        B       %FT40           ; It's <thing>:<wildcard>
30
        CMP     r8, r7
        BHS     %BT20
40
        ; Confirmed wildleaf found with r8 before string or before preceding . or :
        TEQ     r14, #"."
        TEQNE   r14, #":"
        ADDEQ   r7, r8, #2
        ADDNE   r7, r8, #1

        ; Chop off the leaf from the path tail
        BL      strlen
        ADD     r8, r1, r3
50
        LDRB    r14, [r8, #-1]!
        TEQ     r14, #"."
        MOVEQ   r14, #0
        STREQB  r14, [r8]
        EXIT    EQ
        CMP     r8, r1
        BHI     %BT50

        ; If haven't come to a ., but have come to start of string
        ; then must be tail for MultiFS, so chop it there.
        MOV     r14, #0
        STRB    r14, [r8]
        EXIT

70
        ; It's an absolute or non-wildcard, so
        ; let's do it singularly
        MOV     r7, #NULL
        EXIT

        END