|
Emulating the M20 with MAMEBy Benjamin EberhardtSince a while, the Multiple Arcade Machine Emulator MAME has a driver for the Olivetti L1 M20, enabling MAME to run M20 floppy images, boot PCOS and execute programs, almost like on the original machine 1. This article is based on MAME v0.252 on Linux Mint 21 (Feb 2023).
Data provided with this article:
Running M20 floppy imagesAfter installing MAME, one needs to separately download the M20's ROM contents, e.g. m20.zip. For legal reasons, most ROMs are not included in MAME. Secondly, one needs a floppy to boot from. Floppy disk images of different types can be loaded. Those can be: dd/ sdd/ rdm20 .img (M20 floppy-sector-dumps), Teledisk .td0, or ImageDisk *.imd files, as found in the disk images section. Single images will only work if they have bootable content (e.g. Olivetti's M20 operating system PCOS). A good entry point is pcos102.img. Images can also be loaded in zipped format. Multiple images belonging to a package can be in one zip file an are specified by number, e.g. "pascal.zip:1". To get started right away, download ROM data and floppy images into a local directory and from within, run:
This puts the floppy image into the virtual M20s right floppy drive (drive 0). Non-PCOS images can additionally be added to the left floppy drive (drive 1) via the "-flop2" argument. Depending on the ROM file, the following M20 bios versions are supported:
* 1.0 ( Note that some images might need more RAM to work and thus need the additional Not all images are running with MAME right away. Some are missing another kind of boot information, which was stored in track0 of the original floppy, but was lost during the imaging process. This is actually the case with most rdm20/ *.img disk images in the disc images section. Unless fixed, these floppies will usually not boot (or boot only partially in MAME), nor work in the second drive. The floppy track0 problemTo find out if an image is affected, use e.g. hexdump to see if track0 has been skipped during imaging. Skipping has usually been done on the reading and writing side, so the first bytes of the file would have been filled with zeros. A working image would display bytes different from zero:
When only dealing with image files in MAME, there is an easy solution. The missing part of track0 does not seem to contain any user data, but information which is written only once while formatting the floppy. It is possible to transfer this track/ information from one image to another. This makes the affected image directly usable with MAME. The file pcos102.img for example has track0 data which can be used. Transferring it to another image using dd:
We have successfully fixed spiele+uhr.img, which will now boot into PCOS and launch a menu of 19 games and demos! Make floppy images writableMAME supports reading multiple floppy image formats: mfi (MAME floppy image), img (M20 floppy sector dumps, we will also call this format "M20"), imd (Image Disk), td0 (Teledisk). Only some of these images are writable:
MAME supplies a tool for converting between these different formats, with the same limitations for write support. The following will convert an ImageDisk floppy image into a writable M20 sector image:
Alternatively, for a bit of PCOS practice, load the image to be converted and an existing image in the target format into the emulator. The method is limited to that the image to be converted needs to be a bootable PCOS image containing the vformat and vcopy tools (see M20 PCOS and BASIC command reference2). This method will also take care of fixing a missing track0 in the target image. Boot PCOS format, and copy the source image over to the target image: On linux:
On PCOS, format flop2 (1:) and copy flop1 (0:) over flop2:
Instead of loading an existing image into flop2, it is also possible to create a completely new image from the MAME in-game menu. However at the time of this writing, it seems to only still be possible to create new *.mfi images. Reading and writing BASIC files from imagesFiles contained in a regular M20-img file can be accessed with m20floppy. Note that BASIC files are usually saved in a compressed/ tokenized binary format. An interesting project to learn about the M20-Basic and convert the tokenized version to ASCII is the M20 Basic Detokenizer3. Alternatively, one can save files as ASCII via MAME under PCOS BASIC with the "A" option, then extract with m20floppy:
When writing BASIC code in ASCII back to the img, one has to make sure, that the newline delimiter is a single "CR". Linux' "LF" and Windows' "CRLF" would need to be replaced with e.g. sed or tr. The anatomy of M20 floppies and MAME imagesThe original M20 stored data on the physical floppy in two different encodings. Part of the first track has data encoded in FM, while the rest of the floppy was encoded in MFM. PC floppy controllers usually do not understand the FM encoding, so reading of this section was often skipped during imaging. Even if the whole floppy track can be read, one has to deal with an additional difficulty: FM tracks are 16 sectors * 128 Bytes (= 2048 Bytes) in size, while MFM encoded track size is 16 sectors * 256 Bytes (= 4096 Bytes). To simplify handling of the image file, MAME on the other hand assumes all sectors to be of equal 256 Byte size. When reading the original floppy in MFM mode and skipping the first track, this automatically results in the correct 4 KiB offset in the image file. When imaging a real floppy including the FM track, however, one has to pad every single FM sector with another 128 Bytes. Table adapted from4:
Instead of extracting from floppy, another option to create a new first track, with PCOS on MAME itself. Booting with a PCOS image in drive0, then create and format a new floppy in drive1:
The resulting image in this example was produced using pcos41a and the first bytes differ slightly from the ones previously obtained from the pcos102 image:
Track0 does not contain any user data (see Page 10.2 of the Italian PCOS 1.0 manual) but its content seems to depend on the PCOS version it was created with. For the purpose of using images in MAME, the track does however seem to be completely interchangeable between images. Digging further into the created image, one can notice:
Two examples showing different padding types, broken down into 16 pairs of 128 bytes, representing the 4 kiB track0 in a MAME compatible sector image:
Bios 1 seems to be more forgiving concerning booting different FM tracks than Bios versions 2. When writing the images back to floppy to be used in a real machine with fixed Bios, one has to be more careful. Ideally the original FM track should be used, if it is not available one should try to use one from a matching PCOS version. (E.g. the german games/ demo disk does not boot on the original machine with the restored FM track from pcos102, but it does so with an FM track from another pcos20h from e.g. one of the oliword images). Compiling MAME from source and running older versionsThe latest version of MAME is the github master branch. On Linux just type "make" in the checked out tree. To compile floptool etc. as well, add the "tools" argument. Compiling only the M20 driver is significantly faster and can be done by adding the "subtarget" and "sources" arguments:
In order to compile a specific MAME (e.g. v0.212) version we might need to use a different python/ compiler version, e.g.:
Some versions < .220 might need this bug fixed. More compile options can be found here. In case it all does not work, another method to run previous MAME versions is to use pre-built binaries. They only exist for Windows, but they do run well with Run MSDOS and CP/M on the M20On a real M20, with the 8086 addon board, you can boot an Olivetti-MS-Dos 2.0. This also works with MAME, by selecting bios >=1 and the msdos.img floppy image from the disk images section.
When asked if you want to boot the alternative CPU (8086), press "y" ("z") to boot into Dos. The keyboard layout can then be changed with the setlang command, e.g.:
In order to boot CP/M on the M20, I had to adjust the ramsize, otherwise CP/M boots into a black screen:
Connecting to the M20 serial interfaceRun mame with the follwing extra arguments:
In PCOS (also see FAQ, forum):
Then connect to the socket with e.g. telnet
We can now type into PCOS from telnet, but PCOS output is not shown in the telnet terminal. I am not sure why. Keyboard and layouts in PCOS and MAMEThe keyboard layout depends on the language of the loaded PCOS. The language on PCOS >= 2.0 can be changed with the sl-command (see FAQ). I could not figure out how to change the language under PCOS1. M20 special keys are usually:
Re-defining input keys can be done through the MAME in game menu. The menu can be accessed by first enabling hotkeys, by pressing the "ui_toggle" key and then "tab" to open the menu. The "ui_toggle" is usually set to "ScrollLock" or to "ForwardDelete" on keyboards which lack the former. If you cannot figure out how to toggle hotkeys, you can launch MAME with "-ui_active" and re-define the key: [tab] -> Configure Options -> General Inputs -> User Interface -> UI Toggle. It might makes sense to specify a consistent config directory to save the key mappings, as MAME seems to otherwise use the local working directory:
While you are in the in-game menu, look into other useful options, like recording screenshots (F12) and recording video (LSHIFT + F12). This little BASIC program can be used to compare different key combinations with the key code tables in the command reference manual:
MAME offers an additionally feature to automatically type specified text into the emulated machine with a specified delay after boot. This is useful to e.g. automatically execute programs after start. One has to keep in mind, that autoboot always uses the original "natural" keyboard that the M20 MAME driver was built on, which is the Italian layout. So one has to use an italian pcos (e.g. pcos102.img) or change a pcos >=2.0 to Italian with slang (> sl 0) and save the change to the floppy with psave (> ps). Then the autoboot string will be interpreted correctly. The following will boot pcos, switch to BASIC mode and draw a circle:
To work with any given system language one would need access to the emulated keyboard. This is not currently possible via autoboot and seems to be a current limitation of MAME. Notes, known issues, open questions, TODOs
Page log
Olivetti is a registered trademark of Telecom Italia. This site is not related to Olivetti nor to Telecom Italia. The material presented is meant for personal use only and is shared in a "fair use" spirit. If you own the copyright of some of the stuff presented here and you think it should be removed, please contact the webmaster. |
Updates
|
|||||||||||||||||||||||||||||||||||