Skip to main content

Renesas (NEC) 78K0 emulator

Project description

k0emu

Overview

k0emu is an instruction set emulator for running Renesas (NEC) 78K0 binaries. It executes all 78K0 instructions described in the documentation. A companion disassembler, k0dasm, is also available as a separate package.

Originally developed to aid in reverse engineering the Volkswagen Premium 5 car radio made by Delco, k0emu emulates the memory map and some of the built-in peripherals of that radio's microcontroller, the undocumented NEC µPD78F0831Y (which turned out to be a subset of the µPD78F0833Y). However, k0emu has a modular design and can be used as a base to implement emulators for various other 78K0 microcontrollers.

Features

  • Executes all documented 78K0 instructions with cycle counting

  • Bus architecture with memory-mapped peripheral devices

  • All instructions covered by unit tests

  • At least one addressing mode of most operations was tested against hardware

  • Correctly boots and runs a large (60K) real-world firmware without patches

Installation

k0emu is written in Python and requires Python 3.8 or later. Packages are available on the Python Package Index (PyPI). You can download them from there or you can use pip to install k0emu:

$ pip3 install k0emu

On fast hardware, the emulator will run on Python at around 1 MHz. For emulating systems in real time, run k0emu on PyPy instead of Python. On the same hardware, PyPy runs the emulator at 4 MHz easily and as high as 8 MHz.

$ pypy3 -m pip install k0emu

Usage

k0emu is intended to be used by emulator authors as a library. A demo command, k0emu, will run a binary indefinitely in the terminal. The file is assumed to be a ROM image that should be aligned to the bottom of memory. For example, if a 32K file is given, k0emu will assume the image should be located at 0x0000-0x7FFF. After loading the image, the emulator will start executing from the reset vector:

$ k0emu rom.bin

0d88: 7b 1e        di                     AX=0000 BC=0000 DE=0000 HL=0000 SP=0000 [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d8a: 13 42 07     mov 0ff42h,#07h        AX=0000 BC=0000 DE=0000 HL=0000 SP=0000 [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d8d: 13 f9 90     mov 0fff9h,#90h        AX=0000 BC=0000 DE=0000 HL=0000 SP=0000 [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d90: 13 fb 00     mov 0fffbh,#00h        AX=0000 BC=0000 DE=0000 HL=0000 SP=0000 [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d93: ee 1c 1f fe  movw sp,#0fe1fh        AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d97: 4b cd        clr1 0fecdh.4          AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d99: 71 4b 23     clr1 0ff23h.4          AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d9c: f0 cd        mov a,0fecdh           AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0d9e: f2 03        mov 0ff03h,a           AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0da0: 6b ce        clr1 0feceh.6          AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0da2: 71 6b 24     clr1 0ff24h.6          AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0da5: f0 ce        mov a,0feceh           AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
0da7: f2 04        mov 0ff04h,a           AX=0000 BC=0000 DE=0000 HL=0000 SP=FE1F [IE:0 RB:0 ISP:0 Z:0 AC:0 CY:0] ffe4=00000000 ffe5=00000000 ffe6=00000000 ffe7=00000000
...

The k0emu command has no controls; it just executes instructions and displays tracing information. The unit tests can be used as a reference for how to use the emulator's components from your own Python programs. See the premium5 project for an example of a full system emulator based on k0emu.

Author

Mike Naberezny

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

k0emu-2.0.0.tar.gz (102.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k0emu-2.0.0-py3-none-any.whl (106.3 kB view details)

Uploaded Python 3

File details

Details for the file k0emu-2.0.0.tar.gz.

File metadata

  • Download URL: k0emu-2.0.0.tar.gz
  • Upload date:
  • Size: 102.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for k0emu-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f7f7f8de2eaf9f408259dee4576528b39ebee94a83fdba1b756ca9942775a1ed
MD5 8a00a813acb88ede1f8e5f213091b111
BLAKE2b-256 80b2b1fd32626cb47480789917f0d0056a5041c5232a4255834562bec904160b

See more details on using hashes here.

File details

Details for the file k0emu-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: k0emu-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 106.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for k0emu-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10a680ee5ed0f1fcff6a01143f0231fce1dc2d9811105bf9aa2c1d397852464e
MD5 9cfb52aaf276677733a687ea14cf36c7
BLAKE2b-256 47551ead957e2f05a11562cc8953487af75e80dd9c364a420af6c94d5448af4e

See more details on using hashes here.

Supported by

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