Skip to content

CPU Library

nepx edited this page Apr 8, 2020 · 2 revisions

The CPU emulator was designed to be easily modular-izable. It's relatively easy to separate the CPU into its own separate shared library. Integrating that into your own programs is a different story, though.

I'm writing this page because I'm currently using the CPU library in another project and I'd like to detail the steps that were needed to get it to work.

Compiling

You can easily compile the library by running the following command, which will produce the file libhalfix.so.

node makefile.js libcpu --output libhalfix.so

I assume that you can easily do the same on Windows and convert it into a DLL file, but I haven't tested this.

API

The complete collection of functions that you can use is in include/cpu/libcpu.h. Copy (or symbolically link) the file to wherever it needs to be.

Linking

Add -L. -l:./libhalfix.so to your build fact. The ./libhalfix.so part is critical, or else ld.so can't find the file. This took me too long to find out.

Usage

Call libcpu_init first.

FAQ

Are instrumentation callbacks supported?

If you mean the instrumentation callbacks in src/cpu/instrument.h, no. There is a way to reroute data that would otherwise go to (non-existent) devices to you own callbacks, however.

Clone this wiki locally