{"id":628,"date":"2013-05-22T21:02:22","date_gmt":"2013-05-22T19:02:22","guid":{"rendered":"http:\/\/lallafa.de\/blog\/?p=628"},"modified":"2013-05-22T21:02:22","modified_gmt":"2013-05-22T19:02:22","slug":"emulating-plipbox-with-fs-uae","status":"publish","type":"post","link":"https:\/\/lallafa.de\/blog\/2013\/05\/emulating-plipbox-with-fs-uae\/","title":{"rendered":"Emulating plipbox with FS-UAE"},"content":{"rendered":"<p>Recently, I had some time to spend and wanted to work on the <a title=\"plipbox\" href=\"http:\/\/lallafa.de\/blog\/amiga-projects\/plipbox\/\">plipbox<\/a> project&#8217;s Amiga driver. Unfortunately, I only had my MacBook Pro with me and no\u00c2\u00a0Amiga or plipbox hardware.<\/p>\n<p>What does a SW developer do if the real hardware is not at hand?<\/p>\n<p>Yes, you write an emulator that represents the missing HW in SW on a machine\u00c2\u00a0you have access to&#8230;<\/p>\n<h3><!--more--> Adding a Virtual Parallel Port Protocol in FS-UAE<\/h3>\n<p>That said, I installed all required Amiga SW in a virtual environment in\u00c2\u00a0<a href=\"http:\/\/fs-uae.net\">FS-UAE<\/a> on my Mac and soon I had my <strong>plipbox.device<\/strong> SANA II driver\u00c2\u00a0talking with the virtual parallel port in FS-UAE. What was missing now is a\u00c2\u00a0protocol that communicates the complete I\/O state from FS-UAE to another\u00c2\u00a0process. Then I could write a standalone application that does emulate the\u00c2\u00a0plipbox firmware and plipbox.device in FS-UAE would be operational.<\/p>\n<p>I defined a simple two-byte bi-directional protocol called <strong><a href=\"https:\/\/github.com\/cnvogelg\/fs-uae-gles\/blob\/chris-devel\/vpar.md\">vpar<\/a><\/strong> that\u00c2\u00a0communicates any change in the emulation of FS-UAE&#8217;s Amiga parallel port to an\u00c2\u00a0external process and also receives external changes for input lines from the\u00c2\u00a0process and realizes them in FS-UAE&#8217;s emulated parallel port.<\/p>\n<p>Having a POSIX compatible system with pseudo-terminals (ptys) I devised the\u00c2\u00a0link between both processes as a simple file-open interface in FS-UAE and a pty\u00c2\u00a0in the plipbox emulator (Note: any other interprocess mechanism works here also\u00c2\u00a0but this one was very easy to add in FS-UAE).<\/p>\n<p>The setup looks like this:<\/p>\n<pre>        +----------+                                  +---------+\r\n        | plipbox  |                                  | patched |\r\n        | emulator |--(opens)--&gt; [PTY] &lt;--(file I\/O)--| FS-UAE  |\r\n        +----------+                                  +---------+\r\n                    &lt;--------- vpar protocol --------&gt;<\/pre>\n<p>All required changes to FS-UAE are available in my clone of the FS-UAE\u00c2\u00a0repository on <a href=\"https:\/\/github.com\/cnvogelg\/fs-uae-gles\/tree\/chris-devel\">GitHub<\/a> in the `chris-devel` branch.<\/p>\n<p>For the plipbox emulator application I chose my favorite script language\u00c2\u00a0Python. With it setting up the pty for inter-process communication and\u00c2\u00a0implementing the vpar protocol peer was done in a few hours.<\/p>\n<h3>Setting up the Network<\/h3>\n<p>Ok, the plipbox emulator in Python can now talk PLIP via vpar&#8217;s virtual\u00c2\u00a0parallel port. The next step is to add access to an Ethernet device on the\u00c2\u00a0lowest frame level for our plipbox emulator.<\/p>\n<p>I had a look at the <a href=\"http:\/\/www.tcpdump.org\">pcap<\/a> library that allows injecting packets into\u00c2\u00a0an existing adapter, but the Python bindings often lacked the inject feature\u00c2\u00a0of the library and so I dropped this idea.<\/p>\n<p>Then I found a setup using a <a href=\"http:\/\/en.wikipedia.org\/wiki\/TUN\/TAP\">TAP<\/a> device to easily create and receive\u00c2\u00a0ethernet packets from a user space application. Combine this with a real\u00c2\u00a0ethernet adapter via an interface bridge and you have access to real ethernet\u00c2\u00a0with a simple TAP file I\/O interface (opening \/dev\/tap0) from your\u00c2\u00a0application.<\/p>\n<p>The setup looks like this:<\/p>\n<pre>        +----------+              +---------+                +----------+\r\n        | Real Eth |              | TAP     |                | plipbox  |\r\n        | Adapter  |&lt;-- Bridge --&gt;| Adapter |&lt;-- File I\/O --&gt;| emulator |\r\n        +----------+              +---------+                +----------+\r\n           en1         bridge0       tap0\r\n           +----- OS net interfaces ----+<\/pre>\n<p>For the real ethernet adapter I use a second USB ethernet adapter on my Mac\u00c2\u00a0that is not configured (IP: 0.0.0.0) but active (up) in Mac OS X. This way OS X\u00c2\u00a0does not use it and my emulator can use it exclusively.<\/p>\n<p>Creating the TAP device and building the bridge with the real adapter is done\u00c2\u00a0with some sudo&#8217;ed system command right in the startup of the emulator.<\/p>\n<p>Note: the TAP driver is not shipped with Mac OS X itself, but you can add it by\u00c2\u00a0installing the ones from the <a href=\"http:\/\/tuntaposx.sourceforge.net\">TUN TAP OSX<\/a> project.<\/p>\n<h3>Putting it all together<\/h3>\n<p>On top of the vpar Python module I implemented the magPLIP protocol layer in\u00c2\u00a0an own Python class. Now all pieces to create the plipbox were available.<\/p>\n<p>The plipbox main script sets up the vpar, magplip, and ethernet with TAP and\u00c2\u00a0interface bridge. In the main loop it does I\/O multi-plexing with select() on\u00c2\u00a0the file descriptor for the vpar PTY and for the TAP file.<\/p>\n<p>A packet arriving from TAP is filtered (i.e. multicast and unknown broadcasts\u00c2\u00a0are removed) similar to the real plipbox firmware and then delivered to the\u00c2\u00a0emulated Amiga via the vpar connection.<\/p>\n<p>A packet incoming via PLIP is directly delivered to the local network and thus\u00c2\u00a0written to the TAP file.<\/p>\n<p>That&#8217;s it! A working plipbox running as a Python script on my Mac&#8230;\u00c2\u00a0Similar to the firmware I added some optional debugging output to see the\u00c2\u00a0packet contents and to measure the timing and latency. Now I can develop and test the plipbox.device driver with the emulated environment&#8230;<\/p>\n<h3>Sneak a Peek?<\/h3>\n<p>The plipbox emulator will be shipped with the upcoming version 0.3 of plipbox. If you want to have a look already then head over to my <a href=\"https:\/\/github.com\/cnvogelg\/plipbox\">GitHub<\/a> repository where all development takes place&#8230; Have a look in the <strong>python<\/strong> and <strong>doc<\/strong> dirs \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I had some time to spend and wanted to work on the plipbox project&#8217;s Amiga driver. Unfortunately, I only had my MacBook Pro with me and no\u00c2\u00a0Amiga or plipbox hardware. What does a SW developer do if the real &hellip; <a href=\"https:\/\/lallafa.de\/blog\/2013\/05\/emulating-plipbox-with-fs-uae\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,6,15,9],"tags":[],"class_list":["post-628","post","type-post","status-publish","format-standard","hentry","category-amiga","category-mac-stuff","category-plipbox","category-software"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/piBMF-a8","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/comments?post=628"}],"version-history":[{"count":2,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions\/630"}],"wp:attachment":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}