Emulating the M20 with RetroArch

By Benjamin Eberhardt

This guide highlights the particularities of running the M20 MAME driver on RetroArch with the examples of setting it up on Android and Retropie. For a general overview of running the M20 with MAME itself refer to the M20 emulation with MAME article.

Mauerschießen running on Android RetroArch

Above is the iconic game "Mauerschießen", a pong clone from the German demo floppy running on Android RetroArch, playable entirely by gamepad. The necessary keyboard keys have been mapped to the controller.

Running the M20 on Retroarch can be useful for a number of reasons: Retroach is being built for a vast number of platforms (like Android, the Nintendo Switch, and even Win95) for which there is no pre-compiled Mame option. RetroArch also offers some additional features, like slow down, speed up, and snapshots, effectively introducing a "save game" function. While RetroArch is just the frame, it contains MAME as a "core".

The goal of this article is to get M20 emulation running on RetroArch, and map some keys of simple 1D and 2D games to the RetroArch virtual gamepad "RetroPad", so they can be played without a keyboard. Data provided with this article:

Description File Size CRC
Olivetti M20 - games, thumbnails, MAME hash table m20_games.zip 7182871 c8e858bf
Retropad controller mapping configs m20_retropad_mapping.zip 1089744 fdde389c

Loading floppy images in a non-keyboard environment

On a PC one can call MAME with a number of custom arguments from a console. In RetroArch, we need to supply a single argument to the emulator, in form of a file that the user can tap on. Therefore floppies/ images can be loaded by MAME in two additional ways, that only require a single argument when calling the emulator:

The M20 softlist in MAME

In order to use the softlist loading method, add entries to the hash table/ softlist. When placing the file in the local installation, the listed images can be started directly from the app, without having to create a *.cmd file. A few notes about the xml:

Structure of CMD files

CMD files need to contain at least the following information:

Additional MAME commandline-arguments:

An example could look like this:

mame m20 -speed 1.1 -ctrlrpath /storage/emulated/0/RetroArch/roms/m20/cfg/ -ctrlr othello -rompath /storage/emulated/0/RetroArch/roms/m20 -flop1 /storage/emulated/0/RetroArch/roms/m20/othello.zip

Mapping M20 keys to the RetroPad

Using the retropad (on-screen) gamepad instead of a keyboard (e.g. on a phone) is a bit more difficult, but possible. In order to make this work one needs to map some of retropad buttons to the M20 keyboard. Since every game has different input, we create a dedicated controller config on a per image basis, by adding the -ctrlrpath and -ctrlr arguments to the *.cmd launch file. Custom configs will be placed inside a "cfg" directory with the M20 roms, e.g.:

"-ctrlrpath <RetroArch>/roms/m20/cfg/ -ctrlr <game>"

This will make mame expect a "\.cfg" file inside the given cfg-directory. Let's make a simple mapping for the space key, hereby keeping the keyboard-key intact:

<input>
    <keyboard tag=":kbd:m20" enabled="1" />
    <port tag=":kbd:m20:LINE6" type="KEYBOARD" mask="1" defvalue="0">
    <newseq type="standard">KEYCODE_SPACE OR JOYCODE_1_BUTTON2</newseq></port>
</input>

Similar key mappings can be defined for other keys. Taking e.g. the pong clone "Mauerschießen" as an example, we need the keys "0", "2" (down, up), and "space" (start), and "j" (restart), which is the minimum requirement. For a complete overview of M20 key names in MAME scroll to the bottom of this file.

Examples for some games are provided in m20_retropad_mapping.zip. A python script is provided to create/ change mappings: create_retropad_mapping.py.

When modifying the keys in-game through the MAME menu, the mapping will be saved in a system config file called m20.cfg. If one wants to keep those settings on a per game basis, instead of the ctrlrpath and ctrlr arguments, one can supply the cfg_directory argument, to have the system-config stored in a separate location e.g.:

"-cfg_directory <RetroArch>/roms/m20/cfg/<game>/"

The syntax of the m20.cfg system config file inside this folder is identical to the controller config and can be edited both in-game or with a text editor.

RetroArch on Android

This guide is based on RetroArch Arm64 v1.14. The current version of the "Multi (MESS - Current)" core is based on MAME v0.251 and available from the online core downloader. Note that it is best to install the (linked) buildbot version of the app, since the PlayStore version tends to be out of date (and e.g. not list the MESS core).

The RetroArch directory on the Android device is assumed to be under: "/storage/emulated/0/RetroArch" After setup, the basic structure inside the RetroArch folder should look like this1:

./roms/m20/m20.zip  (bios)
./roms/m20/<game>.zip  (rom)
./roms/m20/cfg/<game>.cfg  (ctrlr-cfg)
./system/mame/hash/m20.xml  (softlist)
./thumbnails/m20/[Named_Boxarts, Named_Snaps, Named_Titles]/<game>.png
./playlists/m20.lpl
./saves/mame/cfg/m20.cfg  (default-sys-cfg)
./logs

Setup

1) Start by installing Retroarch 64 bit for Android. Once downloaded, refresh/ update the "Core Info Files".

2) Download the "Multi (MESS - Current)" via the core downloader either directly or by downloading from buildbot into the RetroArch/download folder.

3) Create a subfolder "roms/m20" and put (zipped) floppy images and M20 bios/ rom inside. Make sure the images have a working/ non-empty track0.

4) Make sure the roms are softlisted in hash/m20.xml or alternatively create a *.cmd launch file pointing at the zip file, and also place into "roms/m20" folder:

   mame m20 -rompath /storage/emulated/0/RetroArch/roms/m20 -flop1 /storage/emulated/0/RetroArch/roms/m20/maus.zip

5) Now it is time to start up the RetroArch app and change a few settings: - Activate file logging into "logs" directory, so that we know why things fail/ crash if they do: Settings -> Logging -> Log to File & Timestamp Log Files

6) Choose input device. There are two options:

7) Launch the emulation by: - Load content -> (select the *.cmd launch file) - When prompted, select "Arcade (MAME - Current)" core

Optional steps

Related work

The M20 keyboard in MAME and RetroArch

Retropad Numbering

Prefix: JOYCODE_1_*
BUTTON1: A      |     RZAXIS_NEG_SWITCH: L2          |    HAT1UP           : UP
BUTTON2: B      |     ZAXIS_NEG_SWITCH : R2          |    HAT1LEFT         : LEFT 
BUTTON3: X      |     SELECT           : Select      |    HAT1RIGHT        : RIGHT 
BUTTON4: Y      |     START            : Start       |    HAT1DOWN         : DOWN
BUTTON5: L1     |     BUTTON9          : L3          |    YAXIS_UP_SWITCH  : Analog UP switch
BUTTON6: R1     |     BUTTON10         : R3          |    XAXIS_LEFT_SWITCH: Analog LEFT switch

Mame M20 key mapping

Issues: KEYCODE_STOP buttons not found/ gets deleted from cfg. Maybe a bug in v0.226 that STOP cannot be used? The period/ stop key also does not work when attaching a physical keyboard.

Key IT M20 - KEYCODE_*   - Port           - Mask   - Comment
RESET      - ESC         - :kbd:m20:LINE0 - 1
<  >       - LALT        - :kbd:m20:LINE0 - 2
a  A       - A           - :kbd:m20:LINE0 - 4
b  B       - B           - :kbd:m20:LINE0 - 8
c  C       - C           - :kbd:m20:LINE0 - 16
d  D       - D           - :kbd:m20:LINE0 - 32
e  E       - E           - :kbd:m20:LINE0 - 64
f  F       - F           - :kbd:m20:LINE0 - 128
g  G       - G           - :kbd:m20:LINE1 - 1
h  H       - H           - :kbd:m20:LINE1 - 2
i  I       - I           - :kbd:m20:LINE1 - 4
j  J       - J           - :kbd:m20:LINE1 - 8
k  K       - K           - :kbd:m20:LINE1 - 16
l  L       - L           - :kbd:m20:LINE1 - 32
,  ?       - M           - :kbd:m20:LINE1 - 64
n  N       - N           - :kbd:m20:LINE1 - 128
o  O       - O           - :kbd:m20:LINE2 - 1
p  P       - P           - :kbd:m20:LINE2 - 2
q  Q       - Q           - :kbd:m20:LINE2 - 4
r  R       - R           - :kbd:m20:LINE2 - 8
s  S       - S           - :kbd:m20:LINE2 - 16
t  T       - T           - :kbd:m20:LINE2 - 32
u  U       - U           - :kbd:m20:LINE2 - 64
v  V       - V           - :kbd:m20:LINE2 - 128
z  Z       - W           - :kbd:m20:LINE3 - 1
x  X       - X           - :kbd:m20:LINE3 - 2
y  Y       - Y           - :kbd:m20:LINE3 - 4
w  W       - Z           - :kbd:m20:LINE3 - 8
à 0        - 0           - :kbd:m20:LINE3 - 16
£ 1        - 1           - :kbd:m20:LINE3 - 32
é 2        - 2           - :kbd:m20:LINE3 - 64
"  3       - 3           - :kbd:m20:LINE3 - 128
'  4       - 4           - :kbd:m20:LINE4 - 1
(  5       - 5           - :kbd:m20:LINE4 - 2
_  6       - 6           - :kbd:m20:LINE4 - 4
è 7        - 7           - :kbd:m20:LINE4 - 8
^  8       - 8           - :kbd:m20:LINE4 - 16
ç 9        - 9           - :kbd:m20:LINE4 - 32
)  °       - MINUS       - :kbd:m20:LINE4 - 64
-  +       - EQUALS      - :kbd:m20:LINE4 - 128
ì =        - OPENBRACE   - :kbd:m20:LINE5 - 1
$  &       - CLOSEBRACE  - :kbd:m20:LINE5 - 2
m  M       - COLON       - :kbd:m20:LINE5 - 4
ù %        - QUOTE       - :kbd:m20:LINE5 - 8
*  §       - TILDE       - :kbd:m20:LINE5 - 16
;  .       - COMMA       - :kbd:m20:LINE5 - 32
:  /       - STOP        - :kbd:m20:LINE5 - 64
ò !        - SLASH       - :kbd:m20:LINE5 - 128
Space      - SPACE       - :kbd:m20:LINE6 - 1
Enter      - ENTER       - :kbd:m20:LINE6 - 2
S1         - BACKSLASH   - :kbd:m20:LINE6 - 4
S2         - BACKSPACE   - :kbd:m20:LINE6 - 8
Keypad .   - DEL_PAD     - :kbd:m20:LINE6 - 16
Keypad 0   - 0_PAD       - :kbd:m20:LINE6 - 32 
Keypad 00  - ENTER_PAD   - :kbd:m20:LINE6 - 64
Keypad 1   - 1_PAD       - :kbd:m20:LINE6 - 128
Keypad 2   - 2_PAD       - :kbd:m20:LINE7 - 1      - (DOWN)
Keypad 3   - 3_PAD       - :kbd:m20:LINE7 - 2
Keypad 4   - 4_PAD       - :kbd:m20:LINE7 - 4      - (LEFT)
Keypad 5   - 5_PAD       - :kbd:m20:LINE7 - 8
Keypad 6   - 6_PAD       - :kbd:m20:LINE7 - 16     - (RIGHT)
Keypad 7   - 7_PAD       - :kbd:m20:LINE7 - 32
Keypad 8   - 8_PAD       - :kbd:m20:LINE7 - 64     - (UP)
Keypad 9   - 9_PAD       - :kbd:m20:LINE7 - 128
Keypad +   - PLUS_PAD    - :kbd:m20:LINE8 - 1
Keypad -   - MINUS_PAD   - :kbd:m20:LINE8 - 2
Keypad *   - ASTERISK    - :kbd:m20:LINE8 - 4
Keypad /   - SLASH_PAD   - :kbd:m20:LINE8 - 8
COMMAND    - TAB         - :kbd:m20:MODIFIERS - 1
CTRL       - LCONTROL    - :kbd:m20:MODIFIERS - 2
R SHIFT    - RSHIFT      - :kbd:m20:MODIFIERS - 4
L SHIFT    - LSHIFT      - :kbd:m20:MODIFIERS - 8

  1. https://forums.libretro.com/t/guide-play-non-arcade-systems-with-mame-or-mess/17728 

Page log