Crate lemurs_8080

source ·
Expand description

Intel CPU Emulation

This emulates early Intel 8-bit microprocessors (currently, only the 8080 is supported). It packages a fixed chip core with a “board” that can be user-defined (A very basic board is included and published in the crate, but in most cases, you will want to supply your own, for instance to emulate the non-CPU features of a historical arcade game).

Typically, you will implement the lemurs-8080::Harness trait on a type of your choice and then create a Machine instance that uses a value of that type. You can use any type that dereferences to a mut Harness of some kind, so you can give a machine sole or shared ownership of its Harness or just attach it to a reference.

You can then call the .execute() method on your Machine to execute one instruction or use your Machine as an iterator. By keeping access to the contents of your Harness, you can examine the contents produced by the code and use them with another resource, such as printing text to a console or copying a pixel raster to a window.

By default, the package is built with the "std" feature under the expectation that you will use it in other Rust projects. You can also use this library in C++ projects, by using --no-default-features to deactivate "std", and add the "cpp" (or "_cpp") feature. ("cpp" includes a C++-based global allocator and panic handler from the cruppers crate; "_cpp" just turns on the C++ bridge code and requires you to supply your own memory and panic management.)

The package assumes that you will just use the core opaquely, but the "open" feature exposes several debug features so that you can examine what is happening with the execution directly.

Re-exports

  • pub use crate::chip::opcode::Op::*;
  • pub use crate::chip::opcode::Flag::*;
  • pub use crate::chip::opcode::Test::*;

Modules

Structs

  • This is the main outward-facing type for actually executing instructions. It also accepts interrupt requests, including RST instructions. It can be used as an Iterator to do processing in between operations. It also forwards the contained Harness object out to receive method requests.
  • SimpleBoard is a minimal Harness designed to make it easy to start using the crate; it just stores a full 16k RAM space and byte arrays to store the input and output port values. You can address the RAM space by indexing the SimpleBoard directly.
  • This struct stores the internal registers and flags of the 8080 CPU.

Enums

  • Byte enumerates any one-byte region that can be specified for a read or write:
  • A register pair in the CPU, interpreted as a little-endian 16-bit value, where the B, D or H register contains the more-significant byte and the C, E or L register contains the less-significant byte.
  • Any of the 16-bit registers in the CPU, including the register pairs, but also the program counter and the stack pointer.
  • A single action on the processor. See the 8080 Programmer’s manual for details and operation effects.
  • This enumerates the internal byte registers of the 8080. You can access these by indexing the State struct with them; let val = st[Register::D];

Traits

  • The Harness trait is the core of using this package; the Machine struct will use a type of your choosing that the chip can use to read 8-bit or 16-bit values from 16-bit addresses and write 8-bit or 16-bit values to 16-bit addresses, as well as read and write 8-bit values on 8-bit port numbers.