Debug output can be controlled via flags in 8080.c (lines 5-8):
#define DEBUG_CPU 0 // CPU instruction debugging (JNZ, DCR, etc.)
#define DEBUG_DISK_IO 0 // Disk I/O port operations
#define DEBUG_HALT 1 // Show registers when haltingSet to 1 to enable, 0 to disable.
Shows CPU instruction execution details:
[DCR B] 80 → 7F, zero flag=0- Decrement operations[JNZ] PC=0009, target=0007, zero=0, JUMPING to 0007- Jump decisions
Shows all disk I/O operations:
[OUT] Port 0x10: Select disk 0- Port operations[Disk] Write A: T0 S1 ← DMA 0x0200- Disk read/write
Shows register dump when program halts:
========================================
HALT at PC=0x003F
========================================
Registers:
A=FF B=00 C=00 D=00 E=00 H=02 L=00
SP=0000 PC=003F
Flags: AC Z P
========================================
Current Status: The emulator loads code at address 0x0000 regardless of the org directive.
Workaround: Use org 0h in assembly programs for this emulator.
Why: The codeload() function loads hex output sequentially starting at address 0. The assembler's org directive affects address calculations in the assembly, but not where the code is actually loaded.
Example:
org 0h ; Correct for this emulator
; Fill buffer with test pattern
lxi h, 0200h
mvi b, 080h
...Future Fix Options:
- Modify
codeload()to parse and respect org directive - Modify assembler to output position-independent code
- Add loader that reads org from assembly output
For now, always use org 0h for programs in this emulator.
✅ Intel 8080 CPU Emulation
- All instructions implemented
- Flags (Zero, Sign, Parity, Carry, Aux Carry)
- Interrupts (EI/DI, RST)
- DAA (Decimal Adjust Accumulator)
✅ CP/M Console I/O
- BDOS Functions: 1 (input), 2 (output), 9 (print string), 11 (status)
- Port-based I/O: 0x00 (input), 0x01 (output)
- Bidirectional buffering
- Console output mirrored to Xcode debug console
✅ CP/M Disk Emulation
- Two 256KB virtual disks (A: and B:)
- 77 tracks × 26 sectors × 128 bytes per disk
- BDOS Functions: 13 (reset), 14 (select), 25 (get current), 26 (set DMA)
- Port-based I/O: 0x10-0x15
- Read/Write/Home operations
- Verified working with disk test program
✅ iOS Integration
- UIKit-based emulator view with LED displays
- Document browser for saving/loading programs
- Assembler with hex output
- Sample programs (Kill the Bit, Echo Test, Disk Test)
-
Add BDOS file functions:
- Function 15: Open File
- Function 16: Close File
- Function 20: Read Sequential
- Function 21: Write Sequential
- Function 22: Create File
- Function 23: Rename File
- Function 19: Delete File
-
Implement CP/M directory structure:
- Directory entries (32 bytes each)
- File Control Blocks (FCB)
- Allocation vectors
- Directory hash/lookup
-
Add file system operations:
- Format disk with directory
- Create/delete files
- Read/write file data
- Track allocation
-
Load actual CP/M 2.2:
- CCP (Console Command Processor)
- BDOS (already partially implemented)
- BIOS (needs implementation)
-
Run CP/M programs:
- Load .COM files
- Execute ED, PIP, STAT, etc.
- Support CP/M system calls
-
Persistent disk images:
- Save/load disk images to iOS filesystem
- Import/export .DSK files
- Pre-made disk images with software
-
Enhanced UI:
- Terminal view for console I/O
- Disk browser/explorer
- File manager
- Keyboard input support
-
Performance:
- Optimize emulation speed
- Adjustable CPU clock rate
- Fast-forward mode
Disk Test (Success: A=FF)
[Disk] Write A: T0 S1 ← DMA 0x0200
[Disk] Read A: T0 S1 → DMA 0x0200
HALT at PC=0x003F
Registers: A=FF
Program successfully:
- Filled buffer with 0xAA pattern
- Wrote 128 bytes to disk
- Cleared buffer to 0x00
- Read 128 bytes from disk
- Verified data integrity (0xAA matched)
- Halted with success code
8080.c- Added disk emulation, BDOS functions, debug flags8080.h- Fixed CPU bugs, added aux carry, DAA, interruptsEmulatorViewController.swift- Added console output pollingTextDocumentViewController.swift- Added disk test sample programDocument Browser-Bridging-Header.h- Added CP/M function declarations
- Enable DEBUG_CPU to trace instruction execution
- Enable DEBUG_DISK_IO to see all disk operations
- DEBUG_HALT shows final state when program stops
- Watch Xcode console for all debug output
- Use STEP button to single-step through code (with DEBUG_CPU=1)
- ORG must be 0h (code loads at address 0x0000)
- No file system yet (just raw sector I/O)
- Console output only (no keyboard input UI yet)
- STEP button steps by bytes not instructions (display issue)
- Some printf output may not appear during fast execution
Congratulations on getting disk emulation working! 🎉