BASIC-DOS runs on real IBM PCs and compatibles, but most people run it in PCjs, in a browser or with pc.js. This page lists every way that BASIC-DOS (or a program running on it) and PCjs work together beyond emulating the hardware. Every one of them is optional: without PCjs, BASIC-DOS behaves as it does on real hardware.
The PCjs side of each is in the pcjs repository (machines/pcx86/modules/v2 for the emulator, machines/pcx86/modules/v3 for disk images, and tools/pc for pc.js), which BASIC-DOS’s repository mirrors (see Conventions).
| Interface | Direction | BASIC-DOS | PCjs |
|---|---|---|---|
| Date and time | PCjs supplies data at boot | ddclk_init (clkdev.asm), INT_CLKDATA (pcjs.inc) | ChipSet.setBDClock (chipset.js) |
| Disk requests | Program asks PCjs | INT 21h AX = PCJS_REQ or PCJS_REPLY (pcjs.inc): COMMAND’s LOAD drive: (loadDisk, editcmd.asm), a DOS statement (eg, in CDTEST.BAS); call_dos (v86dos.asm) |
FDC.intDOS (fdc.js), HDC.mountNamedDisc (hdc.js), DiskMenu.searchDisks (diskmenu.js) |
| Disk indexes | PCjs searches files on disks | disks/indexes (tools/misc/diskindex.js), DiskMenu.getFiles (diskmenu.js) | |
| Typed input | PCjs watches | DOS_UTL_EDITLN (INT 2Bh AH = 25h) | Keyboardx86.intDOS (keyboard.js) |
| Mouse pointer | PCjs reacts to hardware | MOUSE driver (INT 33h function 1Fh) | Mouse.releaseAll (mouse.js) |
| Memory arena | PCjs Debugger reads memory | CPU_ARENA, DD_LIST (bios.inc) | Debuggerx86.dumpArena (debugger.js) |
| Disk images | PCjs reads and writes disks | boot sector, BPB (disk.inc), MBR (hdddev.asm) | DiskInfo (diskinfo.js), HDC (hdc.js), pcjs.mbr |
| Claude gateway | Program talks to the host over COM2 | CLAUDE.BAS | assets/js/claude-gateway.js, tools/claude/gateway.js |
| pc.js | pc.js builds disks and runs tests | –sys=bd entry (pc.json5) | pc.js |
A PC or PC XT has no real-time clock, so DOS normally asks for the date and time at startup. In PCjs, those machines (models before the 5170) watch for an INT 13h function 02h read into 0:7C00h, and when it returns with carry clear and the sector is a BASIC-DOS boot sector (its system file names, BASDEV COMBASDOS COM, follow the BPB at offset 2Bh), PCjs stores the host’s date and time in vectors 58h-5Bh:
| Address | Contents |
|---|---|
| 0:160h | “PCJS” (PCJS_SIG1 = 4350h, PCJS_SIG2 = 534Ah) |
| 0:164h | Day (1-31) and month (1-12), one byte each |
| 0:166h | Year (word) |
| 0:168h | Ticks since midnight (dword; 1800B0h ticks per day) |
| 0:16Ch | The BIOS tick count when they were saved (dword, from TIMER_LOW and TIMER_HIGH) |
When CLOCK initializes, it adds the ticks since then (the BIOS tick count less the saved one) to the saved time, and uses the result, unless:
- still sets the switch character without discarding them), which is how a user asks to be prompted;Either a real-time clock’s date or PCjs’s makes IOCTL_CLOCK (see CLOCK) and DOS_UTL_GETDATE with AL = 1 (see Utility Functions) return 1, and COMMAND.COM then skips the startup prompts. Nothing else in BASIC-DOS reads these vectors, and they aren’t cleared.
A program can ask PCjs to put a disk in a drive, as if the user had chosen it from the page’s drive list, with an INT 21h function that DOS doesn’t have (its equates are in pcjs.inc):
| Register | Value |
|---|---|
| AX | 7F00h (PCJS_REQ), or 7F01h (PCJS_REPLY) for a reply |
| BX:CX | “PCJS” (BX = PCJS_SIG1 = 4350h, CX = PCJS_SIG2 = 534Ah) |
| DS:DX | the request: a string of up to 255 characters, ending with a null or a CR |
| ES:DI | PCJS_REPLY only: a buffer for the reply |
| SI | PCJS_REPLY only: the buffer’s size |
COMMAND’s LOAD drive: [disk] (see LOAD) makes a PCJS_REPLY request of LOAD and its arguments, displays the reply, and reports any error; it’s loadDisk in editcmd.asm, outside COMMAND’s core, which cmdLoad reaches through genUpper when LOAD’s argument is just a drive. In BASIC, the DOS statement can also make a request (without a reply); eg:
DOS &H7F00, &H4350, &H534A, "LOAD D: PC-SIG Library CD-ROM 8th Edition (April 1990)"
The only request is LOAD drive: [disk]. Drives A: and B: (and any other diskette drives) belong to the FDC component; any other letter is matched against the drives of other controllers (eg, a CD-ROM drive, whose letter is the one after the hard disks; see HDC.getDriveLetter()). The disk is found in the drive’s lists (the drop-down menus’ lists, all of which PCjs fetches if it has to; see DiskMenu.searchDisks()):
None).None removes the disk, and a disk containing / is a path or URL.* or ?), or that looks like an 8.3 file name with a letter (eg, ADVENT.EXE, but not 2.00), is a file word instead: PCjs looks for disks with a matching file in the list’s disk index, and the other words must appear in those disks’ names. If no disk has the file, the file words are treated as ordinary words.PCjs handles the interrupt itself, and DOS never sees it:
Loaded "name" in X: (followed for a file search by the file’s path and date) or Removed the disk in X:.Use "LOAD [drive] [number]" to load one of the numbered disks above), and they become the drive’s list for a later LOAD drive: n.A reply is a null-terminated string of lines, each ending with CR LF, cut to fit the buffer (SI includes the null), with any character above 7Eh replaced by ?. Without PCjs, or for any request that isn’t a LOAD (or that lacks the signature), the INT goes to DOS, which fails function 7Fh with ERR_INVALID (BASIC’s “Illegal function call”; COMMAND’s LOAD reports “Unable to load X”). So a program can’t tell “no PCjs” from “a request this PCjs doesn’t understand”.
PCjs sees the request only when an INT 21h instruction executes, through a CPU notification (CPUx86.addIntNotify), and it reads the string through DS (and writes a reply through ES), so the request works in real mode and from ring 3 in protected mode (DS and ES can be selectors). In a V86 machine, whose IOPL is 0, the program’s INT faults to CPU before PCjs is notified, but V86.COM passes the function on to BASIC-DOS (see call_dos in v86dos.asm) with an INT 21h of its own, with the same registers and a selector for the machine’s DS, and that’s the one PCjs answers (and repeats, while it waits). PCjs never sees an interrupt that’s simulated (eg, PUSHF and a far call), or a V86 machine’s INT that its host doesn’t repeat.
PCjs keeps each pending request by its function and text, so different requests (eg, from two sessions) can be pending at once; a finished request’s result waits for the program to repeat the INT (for up to 10 seconds). Two sessions making the same request at the same time share it.
TESTS\MISC\CDTEST.BAS uses these requests to load a CD-ROM and blank diskettes before it runs every program on the disc (see Testing with CDTEST).
File searches use indexes of the files on every disk in the lists, which tools/misc/diskindex.js builds in disks/indexes, and which each list names with an @files property (eg, diskettes.json’s is /disks/indexes/diskette-files.json; a relative name is relative to the list):
{"disks": [disk paths], "dirs": [directory names], "files": {"NAME.EXT": [disk, dir, date, ...]}}
Each file name maps to triples: the index of a disk in disks, the index of a directory in dirs (eg, GAMES/ADV, without a leading slash; "" is the root), and the file’s date as a number (YYYYMMDD, or 0 if it’s unknown). An index that would be too large to fetch at once is sharded: its files is replaced by "@shards": "folder/", and the folder has a file for each first character (A-Z, 0-9, or _ for any other), with its own dirs and files; a search fetches only the shards that its file words need (so a word that begins with a wildcard can’t search a sharded index).
node tools/misc/diskindex.js diskettes reads every diskette image in the diskette lists (skipping volume labels and directories), and node tools/misc/diskindex.js discs reads the directories of every disc in the CD-ROM list with HTTP Range requests (caching each disc’s directories in tools/pc/disks/tmp-cdindex, so a later run reads only new discs). To keep the CD-ROM index small (about 28Mb, or 7.5Mb compressed, with no shard over 2.7Mb), it has only EXE, COM, BAS, and ZIP files (DISC_EXTS in diskindex.js), and only the discs that have any; the diskette index has every file.
A machine on a page can have an autoType string (eg, DATE\rTIME\rDIR\r on the preview pages), which PCjs types for the user once the machine is ready for input. PCjs learns that from the line-input functions: INT 21h AH = 0Ah (DOS buffered input), and INT 2Bh AH = 25h (DOS_UTL_EDITLN), which COMMAND.COM uses instead. When either executes, the Keyboard component starts typing (or calls a callback that’s waiting for the first prompt). As with disk requests, only an INT instruction that executes is seen.
The MOUSE driver turns a serial mouse’s power off (DTR and RTS off) when no program is using it, and back on with any INT 33h call other than function 1Fh (see MOUSE). PCjs’s serial mouse treats power off as “done”, and releases the browser’s pointer if it locked it; it captures the pointer again only when the mouse is powered on. This is ordinary hardware behavior, so any mouse driver that does the same gets it, but BASIC-DOS is why PCjs has it: without it, the pointer would stay captured after a program that used the mouse ended.
The PCjs Debugger’s d dos command, with no MCB address, lists BASIC-DOS’s memory the way DEBUG.COM’s DM command does (see Physical Memory Arena). It reads these locations, which Debuggerx86.BASICDOS defines, and which must match BASIC-DOS’s:
| Name | Value | BASIC-DOS definition |
|---|---|---|
| DD_LIST | 0:50Ah | bios.inc: the first device driver (to name system blocks by driver) |
| CPU_ARENA | 0:514h | bios.inc: the real-mode address of the arena: an MCB (offset 0) or the 80386 driver’s PMB table (nonzero offset) |
| LIN_BASE | C0000000h | the linear address of physical memory when paging is on |
| PMB_USED | 01h | cpu.inc: PMBTYPE_USED |
| OWNER_SYS | 08h | dosapi.inc: MCBOWNER_SYSTEM |
| TYPES | FREE, CPU, RSVD, SYS, ARR, CODE, ENV, FUNC, STR, TEXT, VAR, DATA | dbgdev.asm: MA_TYPES |
With an MCB segment (d dos seg), it walks an ordinary DOS MCB chain instead.
In protected mode, the Debugger treats an INT 20h as a Windows VxD service call (INT 20h followed by a service ID), and sets a temporary breakpoint there so that it can label the call once Windows patches it. It does so only in 32-bit code, where VxD calls are made, so that it doesn’t confuse the INT 20h that ends a 16-bit BASIC-DOS program in protected mode with one; otherwise, the breakpoint would stop the machine whenever other code later ran at that address.
PCjs builds, reads, and writes disk images (diskinfo.js, used by both the emulator and pc.js), and it knows these BASIC-DOS formats:
PCJS-XT) adopts a disk image’s geometry instead of warning that it doesn’t match the drive type.CLAUDE.BAS (see CLAUDE) sends questions through COM2 (9600 baud, 8 data bits, no parity, 1 stop bit) to a gateway, which asks Claude and returns the answer in chunks. The protocol uses only ASCII control codes that never appear in the text:
| From | Bytes | Meaning |
|---|---|---|
| PC | ENQ | End any answer in progress, and reply with ACK |
| PC | text EOT | A question: a parameter line (the console’s columns, and NEW to start a new conversation), CR, and the question |
| PC | ACK | Send the next chunk |
| Gateway | ACK | The reply to ENQ |
| Gateway | text ETB | A chunk of the answer (at most 100 bytes); wait for ACK |
| Gateway | text EOT | The last chunk |
| Gateway | NAK | (anywhere in a chunk) the rest of the answer is an error message |
Chunks keep the COM driver’s input buffer (128 bytes by default) from overflowing. The gateway converts answers to code page 437 with CR LF line endings, wraps them to the console’s width, and never sends CTRL-C, CTRL-Q, or CTRL-S, which the COM driver handles itself.
The gateway is assets/js/claude-gateway.js. On a demo page that includes it, connectPage() binds it to the machine’s COM2 (the SerialPort component’s exports.bind) and gets an API key from the page’s #claudekey= fragment or a prompt; in Node, tools/claude/gateway.js runs it on stdin and stdout, and pc.js’s --com2="command" connects a command to COM2. Unlike a disk request, this is ordinary serial I/O, so CLAUDE.BAS works the same on a real PC connected to another computer with a null-modem cable.
pc.js runs PCjs machines in Node, and builds their disks. With --sys=bd, the “bd” entry in pc.json5 builds a BASIC-DOS 2.x disk from src: the boot sector (BOOT1.COM), CONFIG.SYS (src/configs/console/serial/fpe’s, which puts the console on COM1), and BASDEV.COM and BASDOS.COM (HIDDEN, SYSTEM, and READONLY) and COMMAND.COM (SYSTEM and READONLY, so DIR still lists it). For BASIC-DOS, pc.js also:
--commands, --test, and the current drive and directory) to the first SHELL line, separated by ` : `, as long as the command tail fits in a PSP (126 characters) and no IF precedes the last command; otherwise it puts them in AUTOEXEC.BAT (starting with @ECHO OFF) and adds that to the SHELL line, since BASIC-DOS doesn’t run AUTOEXEC.BAT itself;/, and with no path for a program in the root;--floppy, removes a PC XT’s hard disk controller, whose empty drive would make the BASIC-DOS boot sector wait for a key;--serial, translates the terminal’s arrow, function, and editing keys to the control characters that BASIC-DOS treats as their aliases (see the scan code table in condev.asm); and--speed), scales file dates that are in the future back into the time since the machine loaded, keeping their order, so MAKE doesn’t rebuild everything.pc.js’s own programs, which it puts on the disks it builds, end with “PCJS” after an INT, which pc.js intercepts:
| Program | Interrupt | Action |
|---|---|---|
| QUIT.COM | INT 19h at offset 102h | Quit pc.js; QUIT /S [drive:] file saves the drive as a disk image first, and QUIT /R reboots |
| LOAD.COM | INT 20h at offset 102h | Run a pc.js load command |
| Helper programs (eg, LS.COM) | INT 20h | Run the host command of the same name in the current drive’s directory (not in a browser) |
These are the conventions that the interfaces above follow, for adding others:
Copyright (c) 2020-2026 Jeff Parsons Released under MIT License