Skip to content
LGB edited this page Aug 4, 2020 · 5 revisions

XEMU compilation, targets/architectures organization/creation/modification

Foreword

You can try to download binaries here: Download

Targets

Directory targets/ contains various targets, ie. the emulators themselves emulating the desired machines, one machine per target (and per target directory).

Architectures

Do not confuse targets with the architecture: which is simply the OS/hardware the emulator will run on, for example win32 for 32 bit Windows. Architecture dependent Makefile and (always included!) header files are in build/ (Makefile.*, but Makefile.common is the common one, not an architecture specific file) and common/ directories (arch-sys-*.h). Default architecture is the native one which assumes a UNIX-like machine with gcc. Other architectures like win32 are cross compiled ones and also requires to build on UNIX-like machine (just the result will run on Windows).

Windows warning

Please note, that I don't have (really!) Windows at home or at my workplace. So I can only test with wine, not so much serious testing/work behind the Windows architectures, but "it should work" at least. Again: even compiling Windows exe's you must do it on Linux/UNIX like machine, no native Windows compilation is supported (comment: it seems Microsoft released "Linux on Windows" which basically makes possible to run Ubuntu Linux userland on top of Windows 10 kernel ... I can't say too much on this, maybe you can try to compile using that, but don't forget that it uses an older Ubuntu, lacks of SDL 2.0.4 by default - as far as I can say, since I never had Windows, I can't try).

Let's compile for the web?!

The is an experimental architecture in Xemu now named as "html". It uses emscripten compiler to compile into html/javascript, so the result can be used in a web browser. However since it's more than non-trivial currently, I can't give detailed instructions, and needs code edition as well (currently). However this is a quick and dirty demo, how it behaves (note: you need decent browser, with JS/html5 features, IE may not work for example):

http://xemu-dist.lgb.hu/dist/xemu-xc65-sample.html

Compilation

Building a single emulator can be done by changing directory into its target and saying make. In this case, you can even say make run which compiles the target (if needed) and also run it. It's a useful thing during development, since binaries started from default place wouldn't found its ROM etc by default without installation in the emulator on the system.

You can also say make in the top level directory, which will build all of the targets. In this case you can even say make all-arch to build all targets for all architectures.

Notes

  • Result binaries will be built in build/bin/, object files are stored in build/objs (prefixed with architecture and target to avoid name conflict).
  • Command make also accepts the ARCH=... part to compile a given architecture (by default, only ARCH=native is built, unless you did make all-arch from the top level directory), for example: make ARCH=win32 to compile for Windows 32 bit (note, that you need cross compilation tools and SDL2 for that).

Running the emulators

Running the emulators needs the linked libraries of course, in case of Windows, it means the SDL2.dll file usually. Also, you need the ROM images, you can download yourself, or you can say make roms in the top-level directory if you want the system to do it for you.

Note: things like ROM images are searched in various places, including the current directory and rom/ sub-directory of the current directory. It can be a problem if you start the emulator from another place. Xemu tries to look up for files in various directories:

  • current directory
  • rom/ sub-directory of current directory
  • SDL preference directory (SDL related OS-dependent directory)
  • SDL base directory (the same one, where your executable is)
  • On Linux at least: a custom "install" directory set by the Makefile See "Installation" part later about this topic.

Organization of targets, creating a new emulator

Xemu basically consists of "common" sources (in directory /common) shared among all targets. The "target" stuffs are private to the given targets, and are in the corresponding target directory. Even common files are compiled for each targets, as there can be different CFLAGS, whatsoever.

Creating a new emulator is simple enough. Create a new directory here, and copy one Makefile and xemu-target.h of an existing emulator with your customizations then. Basically you need the following lines to change:

Makefile

  • TARGET: name of the target, should be the same as the directory name
  • PRG_TARGET: name of the binary, binaries will be built in the top level directory with extensions added based on the build architecture
  • CFLAGS_TARGET: your custom CFLAGS stuff, may be even empty with only the defaults
  • SRCS_TARGET: source .c files you want to compile from the target directory
  • SRCS_COMMON: source .c files from the common/ directory in the top level, you probably need emutools.c and maybe some emulation related files, for the CPU etc, if you don't want to use your own

xemu-target.h

  • #define TARGET_NAME "xx": should be the same as TARGET in Makefile (thus the directory name as well of the target)
  • #define TARGET_DESC "xxxx": the description of the target, used for ie displaying the window title
  • Other than that, you can write your custom #define statements as well, this header is always included for each C compiler call, even without the source #include'ing it.

For building the project in the top directory, you may need to add your target into the top Makefile too.

Creating a new architecture or modify an existing one

In case of need of a new architecture and/or modification of a current one, you should look for build/Makefile.ARCH and common/arch-sys-ARCH.h where "ARCH" is the name of the architecture. "common" is a reserved name, ie build/Makefile.common is not the architecture, but the common parts of all make mechanisms. File common/arch-sys-ARCH.h is included by default for every C compiler call, without any #include in any sources.

You may need to modify architecture specific settings (ie: compiler, SDL2 stuffs, etc), probably you need to edit the architecture specific Makefile then.

Installation

TODO.