z80 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new49

Dart implementation of the Zilog Z80 Microprocessor. #

This is an emulator for the Z80 processor, written in Dart. It is developed to serve as a component of an emulator for a larger system which incorporates a Z80 as its CPU.

Ported from: https://github.com/DrGoldfire/Z80.js

Usage #

A simple usage from example/main.dart:

import 'package:z80/z80.dart';

void main() {
  var system = System();
  system.memWrite(0, 1);
  // 0000| $A8 XOR b
  // 0001| $0E LD c, [address]
  // 0002| $07 [address]
  // 0003| $0A LD a, (bc)
  // 0004| $3C inc a
  // 0005| $02 LD (bc), a
  // 0006| $76 HALT
  // 0007| $AA
  system.load(0, [0xA8, 0x0E, 0x07, 0x0A, 0x3C, 0x02, 0x76, 0xAA]);
  print('before ram[7] = ${system.memRead(7).toRadixString(16)}');
  system.run(24);
  print('after  ram[7] = ${system.memRead(7).toRadixString(16)}');
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

This code is copyright Molly Howell, Simon Lightfoot and contributors and is made available under the MIT license. The text of the MIT license can be found in the LICENSE.md file in this repository.

0.1.0 #

  • Initial release

example/main.dart

import 'dart:typed_data';

import 'package:z80/z80.dart';

void main() {
  var system = System();
  system.memWrite(0, 1);
  // 0000| $A8 XOR b
  // 0001| $0E LD c, [address]
  // 0002| $07 [address]
  // 0003| $0A LD a, (bc)
  // 0004| $3C inc a
  // 0005| $02 LD (bc), a
  // 0006| $76 HALT
  // 0007| $AA
  system.load(0, [0xA8, 0x0E, 0x07, 0x0A, 0x3C, 0x02, 0x76, 0xAA]);
  print('before ram[7] = ${system.memRead(7).toRadixString(16)}');
  system.run(24);
  print('after  ram[7] = ${system.memRead(7).toRadixString(16)}');
}

class System implements Z80Core {
  System() {
    _cpu = Z80CPU(this);
    _ram = Uint8ClampedList(32 * 1024); // 32K
  }

  Z80CPU _cpu;
  Uint8ClampedList _ram;

  void load(int address, List<int> data) {
    _ram.setRange(address, address + data.length, data);
  }

  int run(int cycles) {
    while (cycles > 0) {
      cycles -= _cpu.runInstruction();
    }
    return cycles;
  }

  @override
  int memRead(int address) => _ram[address];

  @override
  void memWrite(int address, int value) => _ram[address] = value;

  @override
  int ioRead(int port) => 0;

  @override
  void ioWrite(int port, int value) {}
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  z80: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:z80/z80.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
5
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
83
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Format lib/src/z80_cpu.dart.

Run dartfmt to format lib/src/z80_cpu.dart.

Maintenance suggestions

The package description is too short. (-17 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.0 <3.0.0
Dev dependencies
pedantic ^1.9.0