Skip to content

Command Reference — modred (CP/M ED minimal Python implementation)

This document summarizes the commands implemented by the modred project (modred.py). The goal is to follow the CP/M ED manual (Chapter 2) behavior as closely as practical for a small Python program.

Each command may accept numeric prefixes, signed prefixes +n/-n, or # meaning 65535.

Summary (core commands)

  • nA — Append next n unprocessed source lines to the memory buffer (use #A to append all). OA appends until buffer at least half full.
  • nW — Write the first n lines of the memory buffer to the temporary file x.$$$. OW writes until buffer is at most half full. #W writes the entire buffer.
  • I / i — Insert mode. Enter lines from the console until Ctrl-Z (ASCII SUB) or a line containing ^Z. I (uppercase) translates inserted text to uppercase; i preserves case.
  • T / nT — Type lines from the buffer (display). With V enabled, T prints absolute line numbers.
  • E — End edit: write remaining buffer and unprocessed source to the temporary file, rename original to .BAK, and rename x.$$$ → original file name.
  • Q — Quit without saving changes.
  • O — Return to original file (remove temporary changes, delete temp file, reset SP).
  • H — Head: perform E (save) and reopen the file for editing (starts a new edit session on the resulting file).
  • D / +-nD — Delete characters; signed form deletes forward or backward.
  • K / +-nK — Kill lines (remove lines) forward/backward relative to current line (preserves text before/after CP as specified by manual).
  • C / +-nC — Move the character pointer by n characters (counts CRLF as two chars between lines).
  • L / +-nL — Move n lines up/down. L0 moves to the beginning of the current line.
  • B / -B — Move to beginning (B) or bottom (-B) of buffer.
  • V, -V, 0V — Turn line numbering on (V) or off (-V); 0V prints free/total buffer bytes.
  • U, -U — Toggle uppercase translation of appended input.

Search & replace

  • nF s — Find the nth occurrence of s starting at the current CP. Strings may include ^L to represent a <CR><LF> pair.
  • nN s — Find with autoscan: if s is not found in the current buffer, the implementation writes the buffer to temp and appends more source (like A/W) until the search succeeds or source exhausted.
  • nS s1^Zs2 — Substitute occurrences of s1 with s2, at most n times (0 means until end). S enforces a 100-character limit on search strings and will print BREAK > AT 0 if exceeded.
  • nJ s1^Zs2^Zs3 — Juxtaposition: find s1, insert s2 right after it, then delete up to (but not including) s3.

Libraries & block move

  • nX — Transfer the next n lines from the buffer (starting at current line) into a temporary transferred library (kept in memory and persisted to an on-disk file base.LIB.XTMP) — does not remove from buffer.
  • 0X — Clear the transferred lines (deletes the temporary lib file if present).
  • R — Read transferred lines from X back into the buffer after the CP.
  • Rname — Read name.LIB from disk and insert it after CP.

Macros

  • nM cs — Execute command string cs n times; if n is 0 or 1, execute until an error condition. Nested M calls are disallowed and will report BREAK ? AT 0.

Error messages

  • BREAK ? AT C — general unrecognized command or macro problem.
  • BREAK > AT 0 — memory/line length exceeded for some operations (search strings too long).
  • BREAK O AT 0 — library open error (cannot open .LIB).
  • BDOS ERR on d: BAD SECTOR — disk write error (simulated during temp-file writes).

Limits & behaviors

  • Line lengths and total buffer sizes are approximate and limited by DEFAULT_BUFFER_CAPACITY (by default ~5000 characters) and manual-enforced safeguards.
  • Strings passed to F, S, N, and J are limited to 100 characters in the current implementation.

Notes & examples

  • When inserting interactively on a TTY, pressing Ctrl-Z (ASCII SUB) will end insert mode without suspending the process.
  • For S commands use ^Z separators when providing both s1 and s2, e.g., SOLD^ZNEW^Z replaces OLD with NEW.

For usage examples, see docs/EXAMPLES.md.