Shell
How the LainDOS prompt works after boot: built-ins, current directories, AUTOEXEC.BAT, PATH search, environment variables, and the small boundary where it intentionally stops short of COMMAND.COM compatibility.
From boot to A:\>
The shell is just another DOS program, but it is the user-facing control loop for the live image. It receives the initial PSP and environment, runs optional startup commands, then keeps handing child programs to EXEC until EXIT terminates it.
0102030405Startup and dispatch
SHELL.COM owns the prompt loop after boot.The kernel boots SHELL.COM like any other COM program. The shell immediately shrinks its allocation with AH=4Ah, prints LainDOS Shell plus the embedded build id, tries AUTOEXEC.BAT, and then enters the prompt loop.
Every interactive line is read with AH=0Ah, checked for a standalone drive switch, matched case-insensitively against the built-in command table, and finally passed to external command lookup without uppercasing arguments. Tabs count as whitespace everywhere spaces do, so tab-indented batch lines parse normally.
Before dispatch, redir_setup strips a trailing >file or >>file from the line, saves stdout with AH=45h, and force-duplicates the opened target onto handle 1 with AH=46h. All shell output goes through AH=40h writes to handle 1, so built-ins and spawned programs alike inherit the redirection; >NUL discards via the kernel NUL device. redir_restore puts the console back after the command.
Tests that pin this
Built-ins and current directory
Built-ins are small DOS API wrappers.The built-ins intentionally stay narrow. DIR builds a FindFirst/FindNext pattern from the optional operand, formats entries like MS-DOS with fixed 8.3 columns or /W columns, appends human-readable used/free suffixes to the raw-byte summary, and supports /P pagination. CD, MD, RD, and their DOS aliases call the matching directory APIs; RD only removes empty directories, while DELTREE [/Y] path walks a directory tree bottom-up and removes files plus subdirectories, refusing root and current-directory references. COPY copies single files or wildcard patterns (FindFirst/FindNext expansion) with overwrite confirmation, defaulting the destination to the current directory, DEL and ERASE delete files or wildcard patterns with optional /P, REN and RENAME rename one file without moving it, and TYPE opens a file and copies it to handle 1. The large COPY/TYPE buffer is allocated only during those commands so the resident shell leaves more conventional memory for child programs.
Startup-script conveniences are minimal: PAUSE prints Press any key to continue . . . and waits on INT 16h AH=0, BREAK is accepted as a no-op (LainDOS does not implement user-mode Ctrl-Break), MODE CO80 issues INT 10h AH=00h AL=03h, and MORE < file reads the file in transient 4 KiB chunks, prints each line, and waits on the more prompt between screens. PAUSE, MODE, and MORE accept a trailing > nul (with or without space) and suppress the prompt; MORE accepts a leading < file (with space) to redirect input. Batch control includes labels, GOTO, IF [NOT] EXIST path / ERRORLEVEL n / a==b command (ERRORLEVEL compares the stored AH=4Dh exit code; unrecognized forms print Syntax error), and %1-%9/%% parameter expansion for the vendor scripts that need them.
The prompt and drive switches are DOS state, not private shell variables. The prompt asks AH=19h for the current drive and AH=47h for the current directory; C: uses AH=0Eh to select the drive and relies on the kernel to reject missing drives.
External command lookup
COM, EXE, and BAT are tried locally before PATH.If the command has no extension, the shell first tries .COM, then .EXE, then .BAT in the current directory. Only after those fail does it walk PATH for COM, EXE, and BAT candidates. Extension checks are case-insensitive.
Arguments are copied to a PSPPSPThe DOS data block placed before each program, holding terminate vectors, the job file table, command tail, and environment pointer.-compatible command tail without uppercasing. Successful child programs return through AH=4Dh so the shell consumes the exit status and restores DS before printing the next prompt. Batch files stream line-by-line from their handle and save the previous batch handle so a nested BAT can return to its caller.
Tests that pin this
Default environment
COMSPEC, PATH, PROMPT, and BLASTER are kernel-provided.The boot program gets an MCBMCBA 16-byte DOS memory header that describes the allocated or free block immediately after it.-backed environment before it starts. Default variables include COMSPEC=A:SHELL.COM, PATH=A:;A:BIN, PROMPT=$P$G, and the conventional Sound Blaster string used by game setup tools.
When the shell EXECs a child with env segment 0, the loader copies the shell's environment and appends a fresh DOS executable-path tail. The environment tests read PSPPSPThe DOS data block placed before each program, holding terminate vectors, the job file table, command tail, and environment pointer.:2Ch and verify both the variables and the tail visible to child programs.
Tests that pin this
What this is not
LainDOS keeps shell behavior target-driven. The current shell is enough for test images, startup scripts, PATH-based game launchers, and manual emulator use, but it is not a full clone of COMMAND.COM.
Label not found and ends the batch), IF with NOT/EXIST/ERRORLEVEL/== forms, %1-%9 parameters, and nested BAT files are supported, but there is no CALL, FOR, environment-variable expansion, or pipes.