Skip to main content

CP/M-80 2.2 emulator with API

Project description

cpm80

CP/M-80 2.2 emulator with Python API.

Python Package CI

Based on the fast and flexible z80 emulator.

Installing

$ pip install cpm80

Running and terminating

$ cpm80

>save 1 dump.dat
A>dir
A: DUMP     DAT
A>exit

Enter exit or just hit Ctrl + C three times to quit the emulator.

Running commands automatically

From the command line:

$ cpm80 dir 'save 1 a.dat' dir

Alternatively, we can use the API's StringKeyboard class to feed arbitrary commands to the command processor, CCP, thus replacing KeyboardDevice console readers used by default:

import cpm80

COMMANDS = (
    'dir',
    'save 1 a.dat',
    'dir',
    )

console_reader = cpm80.StringKeyboard(*COMMANDS)
m = cpm80.I8080CPMMachine(console_reader=console_reader)
m.run()

string_keyboard.py

Output:

A>dir
NO FILE
A>save 1 a.dat
A>dir
A: A        DAT
A>

Getting output as a string

Similarly, we can replace DisplayDevice console writers used by default with custom writers to do special work for the emulator's output. For example, one could use a StringDisplay writer to gather the output into a string.

d = cpm80.StringDisplay()

m = cpm80.I8080CPMMachine(
    console_reader=cpm80.StringKeyboard('dir'),
    console_writer=d)

m.run()

print(d.string)

string_display.py

Making BDOS calls

BDOS calls can be performed on the machine object directly or by using convenience wrappers.

m = cpm80.I8080CPMMachine()

STR_ADDR = 0x100
m.set_memory_block(STR_ADDR, b'Hello $')
m.bdos_call(m.C_WRITESTR, de=STR_ADDR)

m.write_str('World!\n')

bdos_call.py

Working with files

Similarly, using BDOS wrappers one can manipulate files on disks.

drive = cpm80.DiskDrive()

m = cpm80.I8080CPMMachine(drive=drive)
m.make_file('file.txt')
m.write_file(f'bin(100) is {bin(100)}\n'.encode())
m.close_file()
del m

# Then read and print the contents of the file using another machine.
m = cpm80.I8080CPMMachine(drive=drive)
m.open_file('file.txt')
print(m.read_file())
m.close_file()

doing_files.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpm80-1.0a7.tar.gz (14.8 kB view details)

Uploaded Source

File details

Details for the file cpm80-1.0a7.tar.gz.

File metadata

  • Download URL: cpm80-1.0a7.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for cpm80-1.0a7.tar.gz
Algorithm Hash digest
SHA256 688cd48c5725aae584537f5370ed91d3cd25274ed074ead1d8c560fe0a7d0b78
MD5 c2883e041398a11475d9519196f3f9c6
BLAKE2b-256 c108e9e19477832a9b73ada85c15112650e7904d4873ad7a3946b5c6606fc6a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page