Feature/batch support and fixed all MS-DOS 1.x NON-IOCTL console functions and IOCTL console functions bugs#2004
Conversation
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Pull request overview
Adds DOS batch-file (.BAT) execution support by routing program launches through a new in-emulator batch execution engine and extending executable path resolution to follow DOS priority rules.
Changes:
- Added
DosBatchExecutionEngineto interpret a subset of DOS batch syntax (CALL/GOTO/IF/FOR/SHIFT/SET/ECHO) plus redirection and piping. - Extended program/path resolution and loading to treat
.BATas executable and prefer.BATover.COMover.EXEwhen no extension is provided. - Introduced a memory-backed Z: drive concept for bootstrap/AUTOEXEC behavior and added extensive integration tests.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Spice86.Tests/Dos/DriveAbstractionTests.cs | Adds unit-style tests for MemoryDrive, AUTOEXEC generation, and mounting Z: memory drive. |
| tests/Spice86.Tests/Dos/DosPathResolverIntegrationTests.cs | Verifies DOS executable extension priority (BAT → COM → EXE) when resolving TOOL without extension. |
| tests/Spice86.Tests/Dos/DosDriveManagerBootstrapTests.cs | Adds bootstrap-style tests around mounting Z: and injecting AUTOEXEC.BAT content. |
| tests/Spice86.Tests/Dos/DosBatchRoutingIntegrationTests.cs | Large integration suite validating batch routing, internal commands, redirection, piping, env vars, and control flow. |
| tests/Spice86.Tests/Dos/BootstrapAutoexecIntegrationTests.cs | Adds bootstrap/AUTOEXEC “RED tests” scaffolding (some are effectively “GREEN” assertions). |
| src/Spice86.Core/Emulator/ProgramExecutor.cs | Treats .BAT as a DOS program for initial load preparation. |
| src/Spice86.Core/Emulator/OperatingSystem/Structures/MemoryDrive.cs | Introduces an in-memory drive abstraction for Z: content injection (AUTOEXEC, scripts). |
| src/Spice86.Core/Emulator/OperatingSystem/Structures/DosDriveBase.cs | Makes IsReadOnlyMedium init-settable to support memory drive initialization patterns. |
| src/Spice86.Core/Emulator/OperatingSystem/DosProgramLoader.cs | Routes initial host launch through the batch execution pipeline and applies redirection before loading the real program. |
| src/Spice86.Core/Emulator/OperatingSystem/DosProcessManager.cs | Integrates batch engine, adds env var accessors, updates executable host-path resolution, and resumes batch execution on process termination. |
| src/Spice86.Core/Emulator/OperatingSystem/DosPathResolver.cs | Adds executable-specific host path resolution with extension probing in DOS priority order. |
| src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs | Exposes executable-path host resolution via the path resolver. |
| src/Spice86.Core/Emulator/OperatingSystem/DosDriveManager.cs | Adds mounting/retrieval of memory-backed drives (separate map from normal drives). |
| src/Spice86.Core/Emulator/OperatingSystem/DosBatchExecutionEngine.cs | New batch interpreter handling CALL/GOTO/IF/FOR/SHIFT/SET/ECHO, variable expansion, redirection, and piping. |
| src/Spice86.Core/Emulator/OperatingSystem/Dos.cs | Bootstraps a Z: memory drive during DOS initialization. |
| src/Spice86.Core/Emulator/OperatingSystem/AutoexecBatGenerator.cs | Adds generator for AUTOEXEC.BAT content (currently appears separate from runtime engine generation). |
| src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs | Exposes DosFileManager for use by the program loader/batch pipeline. |
| dosbox-staging | Updates submodule commit pointer. |
You can also share your feedback on Copilot code review. Take the survey.
6c1964c to
e837b30
Compare
aa66af1 to
bf312f0
Compare
There was a problem hiding this comment.
Pull request overview
Adds DOS batch (.BAT) execution support by routing host-requested programs through a synthetic Z:\AUTOEXEC.BAT and introducing a batch execution engine with redirection/pipeline support.
Changes:
- Introduces
DosBatchExecutionEngineand integrates it into program loading/execution flow (including I/O redirection and pipelines). - Adds a memory-backed
Z:drive (MemoryDrive) to hostAUTOEXEC.BATand related bootstrap behavior. - Adds extensive DOS batch integration tests (routing, CALL/GOTO/IF/FOR/SHIFT, redirection, pipes, args propagation).
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Spice86.Tests/Spice86Creator.cs | Adds exeArgs pass-through to support host-provided arguments in integration tests. |
| tests/Spice86.Tests/Dos/DriveAbstractionTests.cs | Adds tests for new memory-drive abstraction used for Z: bootstrap. |
| tests/Spice86.Tests/Dos/DosPathResolverIntegrationTests.cs | Validates executable resolution behavior when extension is omitted. |
| tests/Spice86.Tests/Dos/DosBatchRoutingIntegrationTests.cs | Adds end-to-end coverage for batch routing, built-ins, redirection, and pipelines. |
| tests/Spice86.Tests/Dos/BootstrapAutoexecIntegrationTests.cs | Verifies host startup program routing through generated Z:\AUTOEXEC.BAT. |
| tests/Spice86.Tests/Dos/BatchTestHelpers.cs | Shared helpers to build tiny DOS programs and run emulation for integration tests. |
| src/Spice86/Spice86DependencyInjection.cs | Refactors GUI↔renderer wiring and removes VgaCard usage. |
| src/Spice86.Core/Emulator/VM/Machine.cs | Removes VgaCard from the VM aggregator constructor/state. |
| src/Spice86.Core/Emulator/ProgramExecutor.cs | Treats .BAT as a DOS program for initial load preparation. |
| src/Spice86.Core/Emulator/OperatingSystem/Structures/MemoryDrive.cs | Introduces in-memory drive storage for bootstrap files (notably AUTOEXEC.BAT). |
| src/Spice86.Core/Emulator/OperatingSystem/Structures/DosDriveBase.cs | Makes IsReadOnlyMedium init-settable to support memory drive instantiation. |
| src/Spice86.Core/Emulator/OperatingSystem/DosProgramLoader.cs | Routes initial program through the batch engine and applies redirections before launch. |
| src/Spice86.Core/Emulator/OperatingSystem/DosProcessManager.cs | Adds batch-engine lifecycle + resumption after child termination and environment helpers. |
| src/Spice86.Core/Emulator/OperatingSystem/DosPathResolver.cs | Adds executable resolution method with extension probing and updates formatting. |
| src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs | Exposes executable-specific host resolution and provides wildcard matching helper for FOR. |
| src/Spice86.Core/Emulator/OperatingSystem/DosDriveManager.cs | Adds mounting and retrieval for memory-backed drives (e.g., Z:). |
| src/Spice86.Core/Emulator/OperatingSystem/DosBatchExecutionEngine.cs | Implements batch parsing/execution, built-ins, redirection, pipelines, and bootstrap autoexec sync. |
| src/Spice86.Core/Emulator/OperatingSystem/Dos.cs | Mounts Z: memory drive at DOS initialization for bootstrap support. |
| src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs | Exposes DosFileManager for use by DosProgramLoader. |
| src/Spice86.Core/Emulator/Devices/Video/VgaCard.cs | Removes VgaCard wrapper (replaced by subscription logic in DI). |
| dosbox-staging | Adds dosbox-staging as a subproject reference. |
| .github/copilot-instructions.md | Updates contributor guidance for tests and TDD expectations. |
f410bf6 to
ad5b233
Compare
2119b09 to
0aff2c7
Compare
f3878c0 to
8c90910
Compare
|
@copilot apply changes based on the comments in this thread |
Applied all three changes from the review in commit 754e9ee:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
00b1897 to
6419da8
Compare
6419da8 to
d97f9e8
Compare
|
@copilot fix tests only passing on Windows but not mac or linux, see CI runs. There's at least a '/' vs '' problem. |
Fixed again in commit 92c72d3. The branch was rebased after my previous fix, so the three Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
92c72d3 to
96a8092
Compare
3c68164 to
c985a09
Compare
…ArrayBasedIndexable
7091e00 to
30fee84
Compare
Feature/batch support and fixed all MS-DOS 1.x NON-IOCTL console functions and IOCTL console functions bugs
Summary
This PR adds a complete DOS batch file execution engine to Spice86, along with substantial fixes and enhancements to the DOS subsystem (INT 21h, IOCTL, keyboard, file management, path resolution, drive abstraction). The batch engine supports
ECHO,SET,IF,FOR,GOTO,CALL,SHIFT,PAUSE,CHOICE,CTTY, I/O redirection, piping, nestedCALLcontexts,ERRORLEVELpropagation, andAUTOEXEC.BATbootstrapping.Fixes #1222
56 files changed, +10,432 / −343 lines across 13 commits.
Commit-by-commit walkthrough
1.
fix(vga): ignore INT10H 0xFE probe from Tandy/PCjr programs(00a5ad0)Adds a no-op handler for INT 10h AH=0xFE, which some Tandy/PCjr-era programs call to probe video page mapping. Previously this raised an unhandled-function error. Makes 'Three Sisters Story' work.
three_sisters_story.mp4
Its batch file is:
Files:
VgaBios.cs2.
feat: add X86InstructionBuilder and extend MemoryAsmWriter(e9bde50)Extends
MemoryAsmWriterwith a second constructor(IIndexable, SegmentedAddress)that works without aCallbackHandler, plus new instruction helpers (WriteSti,WriteMovAh,WriteMovAx,WriteMovDx,WriteCmpAl,WriteCmpAh,WriteJa,WriteJb,WriteSubAl,WriteMovAxSplit,WriteBytes). These are used by the batch engine to emit in-memory COM stubs at runtime (e.g. PAUSE and CHOICE programs).Files:
MemoryAsmWriter.cs3.
feat: DosPathResolver - executable lookup, new file resolution, 8.3 name fix(fae5c95)Adds
ResolveExecutablePath(searches PATH + PATHEXT-like.COM;.EXE;.BATextensions),ResolveNewFilePath(for file creation), and fixes 8.3 short-name truncation for names with leading dots. Also addsGetDirectoryEntriesfor batchFORandDIRglob support.Files:
DosPathResolver.cs,DosPathResolverTest.cs,DosPathResolverIntegrationTests.cs4.
feat: drive abstraction - memory drives, virtual drive devices(068c279)Introduces
IVirtualDriveDevice,VirtualDriveDeviceBase,VirtualDriveInfo,VirtualDriveMediaType, andMemoryDrive. Memory drives are RAM-backed filesystems used for temporary batch artifacts.DosDriveManagergains IOCTL device-info queries (subfunction 0x0D / category 0x08).Files:
IVirtualDriveDevice.cs,VirtualDriveDeviceBase.cs,VirtualDriveInfo.cs,VirtualDriveMediaType.cs,MemoryDrive.cs,DosDriveManager.cs,DosDriveBase.cs,DriveAbstractionTests.cs5.
feat: DosFileManager - IOCTL fixes, file operations, search improvements(d4bca2b)Fixes IOCTL
GetDeviceInfo(handle validation, device-info word layout), implementsSetDeviceInfo, addsIsInputReady/IsOutputReadyfor character devices, and improvesFindFirst/FindNextto support batch wildcard expansion. File-open now respects creation mode flags properly.Files:
DosFileManager.cs,DosFileManagerTests.cs6.
fix(dos): console device off-by-one in data-available check(e9279d8)Fixes
ConsoleDevice.DataAvailablewhich was returning the wrong count with an off-by-one error, causing IOCTL input-status checks to misbehave.Files:
ConsoleDevice.cs7.
feat(keyboard): enhanced INT16H (AH=10h/11h) + Ctrl-Break enqueue + stale PS/2 fix(f9dd1c2)Implements INT 16h AH=10h (extended keystroke read) and AH=11h (extended keystroke peek), adds Ctrl-Break / Ctrl-C enqueueing into the BIOS keyboard buffer, and fixes a stale PS/2 scancode issue in
BiosKeyboardInt9Handler.Files:
KeyboardInt16Handler.cs,BiosKeyboardInt9Handler.cs,KeyboardInt16EnhancedIntegrationTests.cs8.
feat: batch execution engine + types + DosProcessManager integration + Dos.cs wiring(7074378)The core of the PR — the
DosBatchExecutionEngine(~2,800 lines) plus all batch types (BatchFileContext,BatchCommandHandlers,ParsedCommandLine,ParsedChoiceArguments,CommandRedirection,RedirectionBuilder,LaunchRequesthierarchy, etc.). Integrates withDosProcessManagerforCALL/ nested execution andDos.csfor wiring. IncludesDosBatchProgramLoaderfor.BATdetection andInternalBatchProgramBuilderfor runtime PAUSE/CHOICE COM stub generation.Files:
DosBatchExecutionEngine.cs,BatchCommandHandlers.cs,BatchFileContext.cs,CommandExecutionContext.cs,CommandRedirection.cs,ContinueBatchExecutionLaunchRequest.cs,DosBatchDisplayCommandHandler.cs,IBatchDisplayCommandHandler.cs,IDosBatchExecutionHost.cs,InternalBatchProgramBuilder.cs,InternalProgramLaunchRequest.cs,LaunchRequest.cs,ParsedChoiceArguments.cs,ParsedCommandLine.cs,ProgramLaunchRequest.cs,RedirectionBuilder.cs,DosBatchProgramLoader.cs,Dos.cs,DosProcessManager.cs,DosProgramLoader.cs,ProgramExecutor.cs9.
feat: DosInt21Handler - WriteAssemblyInRam rewrite + new functions(45a9796)Rewrites
WriteAssemblyInRamto useMemoryAsmWriterinstead of raw byte arrays. Implements or fixes numerous INT 21h functions: AH=01h–0Ch console I/O, AH=0Ah buffered input, AH=25h/35h interrupt vector get/set, AH=4400h–4407h IOCTL device subfunctions, AH=48h–4Ah memory allocation, AH=4Bh EXEC with proper PSP setup, AH=4Ch terminate, AH=4Dh get return code.Files:
DosInt21Handler.cs,DosInt21HandlerTests.cs10.
feat: HeadlessGui keyboard simulation + test infrastructure rewrite(6b1c31d)Enhances
HeadlessGuiwithEnqueueScanCodeandEnqueueKeyfor injecting keystrokes in integration tests without a real UI. RewritesDosTestFixtureto exposeHeadlessGuiand simplify keyboard simulation setup. AddsHeadlessGui?property toSpice86DependencyInjectionfor test access.Files:
HeadlessGui.cs,DosTestFixture.cs,Spice86Creator.cs,Spice86DependencyInjection.cs11.
test: comprehensive integration tests for batch, INT 21h, IOCTL, keyboard(eb08fe9)~3,800 lines of integration tests covering: batch routing (ECHO, SET, IF, FOR, GOTO, CALL, SHIFT, PAUSE, CHOICE, piping, redirection, ERRORLEVEL), INT 21h console functions, IOCTL device info, keyboard enhanced functions, and AUTOEXEC.BAT bootstrapping. Also adds
BatchTestHelpersand test resourceTESTFKEY.COM.Files:
BatchTestHelpers.cs,DosBatchRoutingIntegrationTests.cs,DosConsoleIoctlIntegrationTests.cs,DosInt21IntegrationTests.cs,BootstrapAutoexecIntegrationTests.cs,TsrIntegrationTests.cs,DosProcessManagerTests.cs,DosFcbManagerTests.cs,TESTFKEY.COM12.
chore: update copilot instructions(9d050d9)Minor update to
.github/copilot-instructions.md.Files:
copilot-instructions.md13.
refactor: remove X86InstructionBuilder, use MemoryAsmWriter with ByteArrayBasedIndexable(c985a09)Removes the temporary
X86InstructionBuilderclass.InternalBatchProgramBuildernow writes directly into aByteArrayBasedIndexableviaMemoryAsmWriter, eliminating the intermediate builder and aligning all instruction-emission code on the same abstraction.Files:
InternalBatchProgramBuilder.cs,MemoryAsmWriter.csTesting
SingleStepTest)DosBatchRoutingIntegrationTests— batch command routing, control flow, redirection, pipingDosConsoleIoctlIntegrationTests— IOCTL device info and console statusDosInt21IntegrationTests— INT 21h console I/O, buffered input, interrupt vectorsKeyboardInt16EnhancedIntegrationTests— extended keystroke read/peekBootstrapAutoexecIntegrationTests— AUTOEXEC.BAT loading and executionDriveAbstractionTests— memory drives, virtual drive devicesDosPathResolverIntegrationTests— executable lookup with PATH/extensionsHow to review
The commits are ordered bottom-up by dependency:
DosBatchExecutionEngine.csand the batch type files