; A program that says what is on the disk. ; ; Which no program could do until now. Everything the system offered took a name a program ; already knew - read it, save it, rename it, delete it, ask how big it is - and there was no ; way to ask what names there are. dir could list only because it lives in the shell and calls ; the filesystem directly. So a file manager, a backup, and the package manager still to come ; were all unwritable for want of two services. ; ; This is those two, used as simply as they can be: walk, say what each thing is, and ask ; about it. ; ; > Walk ; f Say.sbx 1 ; d Apps 0 ; u halfsaved.txt 3 ; ; ---- And it asks about each one AS IT GOES, which is the point ---- ; ; Where a walk has got to is the system's, and so is where the last file it was asked about ; lives - the same eight bytes of filesystem state. A program that walks a directory and asks ; osFileInfo about each entry is using both at once, which is the obvious thing to write and ; the thing that would quietly go wrong if the two shared a position. ; ; Calling osFileInfo between two steps of the walk is therefore not decoration here. It is the ; check, and a walk that came back wrong afterwards would show up as a short listing or a ; repeated name rather than as an error. #Include services.asm #Program #Base 0x5000 start: SETD.0 Name INIB 0d24 SWI osDirFirst BRI walkCheck walkStep: SETD.0 Name INIB 0d24 SWI osDirNext walkCheck: ; The kind is written down before anything else wants the registers: the comparison below ; is an ALU operation and Q is where its answer goes. MVQA SETD.0 Kind STA.0 INIB 0xFF CCF SUB BRQ walkDone ; f, d or u. A chain rather than a table, because three is not enough to index - and A is ; still the kind, since SUB writes Q and leaves it alone. BRA walkFile INIB 0d1 CCF SUB BRQ walkDirectory SETD.0 Unfinished BRI walkSay walkDirectory: SETD.0 Directory BRI walkSay walkFile: SETD.0 File walkSay: SWI osPrintString SETD.0 Name SWI osPrintString SETD.0 Space SWI osPrintString ; ---- And how big it is, asked BETWEEN two steps of the walk ---- ; ; The name is the only thing the walk hands over, which is what keeps it from being a record ; both sides have to agree the shape of. A program that wants more asks about the name, the ; same way anything else does. ; ; A directory is not asked about. osFileInfo answers for one perfectly well and says nought ; blocks, which is true and reads as a size - and nought is a size a file can genuinely ; have, so the two would be indistinguishable in the listing. SETD.0 Kind LDA.0 INIB 0d1 CCF SUB BRQ walkNoSize SETD.0 Name SWI osFileInfo BNQ walkNoSize PSHD.3 POPB POPA SWI osPrintNumber BRI walkEnded walkNoSize: SETD.0 NoSize SWI osPrintString walkEnded: SETD.0 NewLine SWI osPrintString BRI walkStep walkDone: RSTA SWI osExit #Data #Base 0x3000 File: "f " Directory: "d " Unfinished: "u " Space: " " NoSize: "-" NewLine: 0x0A 0x00 Kind: 0x00 Name: #Reserve 0d24