From 4670b503b18521770c3405fcaf2455808dfbac5a Mon Sep 17 00:00:00 2001
From: AndersonTorres <torres.anderson.85@gmail.com>
Date: Mon, 24 Feb 2014 00:01:43 -0300
Subject: [PATCH 1/2] New package: 8086tiny, a tiny 8086 emulator

---
 .../virtualization/8086tiny/builder.sh        | 45 +++++++++++++++++++
 .../virtualization/8086tiny/default.nix       | 37 +++++++++++++++
 pkgs/top-level/all-packages.nix               |  2 +
 3 files changed, 84 insertions(+)
 create mode 100644 pkgs/applications/virtualization/8086tiny/builder.sh
 create mode 100644 pkgs/applications/virtualization/8086tiny/default.nix

diff --git a/pkgs/applications/virtualization/8086tiny/builder.sh b/pkgs/applications/virtualization/8086tiny/builder.sh
new file mode 100644
index 00000000000..0f321e06754
--- /dev/null
+++ b/pkgs/applications/virtualization/8086tiny/builder.sh
@@ -0,0 +1,45 @@
+
+source $stdenv/setup
+
+mkdir -p ./$name $out/bin $out/share/$name $out/share/doc/$name/images
+
+cd $name
+tar xf $src
+make 8086tiny
+
+install 8086tiny $out/bin
+install bios $out/share/$name/8086tiny-bios
+install fd.img $out/share/$name/8086tiny-floppy.img
+install bios_source/bios.asm  $out/share/$name/8086tiny-bios-src.asmn
+install docs/8086tiny.css  $out/share/doc/$name
+install docs/doc.html  $out/share/doc/$name
+for i in docs/images/*.gif
+do
+    install $i $out/share/doc/$name/images
+done
+
+# Refactoring "runme" script
+
+cat << 'EOF' >> run-8086tiny
+#!/bin/sh
+
+# Setting vars: $1 = bios file, $2 = floppy image, $3= harddisk image
+if [ $# -ne 2 -a $# -ne 3 ]; then
+   echo "Usage: $0 <bios file> <floppy image> [harddisk image]"
+   exit 1
+fi
+
+bios="$1"
+floppy="$2"
+hdimage="$3"
+
+clear
+stty cbreak raw -echo min 0
+8086tiny $bios $floppy $hdimage
+stty cooked echo
+
+EOF
+
+patchShebangs run-8086tiny
+install run-8086tiny $out/bin
+
diff --git a/pkgs/applications/virtualization/8086tiny/default.nix b/pkgs/applications/virtualization/8086tiny/default.nix
new file mode 100644
index 00000000000..0b4ff90e409
--- /dev/null
+++ b/pkgs/applications/virtualization/8086tiny/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl
+, localBios ? false, nasm ? null
+, sdlSupport ? true, SDL ? null
+}:
+
+
+assert sdlSupport -> (SDL != null);
+
+
+stdenv.mkDerivation rec {
+
+  name = "8086tiny-${version}";
+  version = "1.20";
+
+  src = fetchurl {
+    url ="http://www.megalith.co.uk/8086tiny/downloads/8086tiny_120.tar.bz2"; 
+    sha256 = "0yapnr8wvlx7h1q1w98yfy2vsbf0rlp4wd99r3xb0b7l70b36mpw";
+  };
+  
+  buildInputs = with stdenv.lib;
+  optionals localBios [ nasm ] 
+  ++  optionals sdlSupport [ SDL ];
+
+  builder = ./builder.sh;
+
+  meta = {
+    description = "An open-source 8086 emulator";
+    longDescription = ''
+    8086tiny is a tiny, open source (MIT), portable (little-endian hosts) Intel PC emulator, powerful enough to run DOS, Windows 3.0, Excel, MS Flight Simulator, AutoCAD, Lotus 1-2-3, and similar applications. 8086tiny emulates a "late 80's era" PC XT-type machine.
+    
+    8086tiny is based on an IOCCC 2013 winning entry. In fact that is the "unobfuscated" version :)
+    '';
+    homepage = http://www.megalith.co.uk/8086tiny/index.html;
+    license = "MIT";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index c2592799d1b..da606148b34 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1970,6 +1970,8 @@ let
 
   tinc = callPackage ../tools/networking/tinc { };
 
+  tiny8086 = callPackage ../applications/virtualization/8086tiny { };
+
   tmpwatch = callPackage ../tools/misc/tmpwatch  { };
 
   tmux = callPackage ../tools/misc/tmux { };

From ad6bdfaf56b4b6a74850c39adde0e6a7d2a3ad20 Mon Sep 17 00:00:00 2001
From: AndersonTorres <torres.anderson.85@gmail.com>
Date: Mon, 24 Feb 2014 00:12:00 -0300
Subject: [PATCH 2/2] Deleting the "runme" stuff - it is not needed at all, and
 the run method is fully documented

---
 .../virtualization/8086tiny/builder.sh        | 26 -------------------
 1 file changed, 26 deletions(-)

diff --git a/pkgs/applications/virtualization/8086tiny/builder.sh b/pkgs/applications/virtualization/8086tiny/builder.sh
index 0f321e06754..36c381becec 100644
--- a/pkgs/applications/virtualization/8086tiny/builder.sh
+++ b/pkgs/applications/virtualization/8086tiny/builder.sh
@@ -17,29 +17,3 @@ for i in docs/images/*.gif
 do
     install $i $out/share/doc/$name/images
 done
-
-# Refactoring "runme" script
-
-cat << 'EOF' >> run-8086tiny
-#!/bin/sh
-
-# Setting vars: $1 = bios file, $2 = floppy image, $3= harddisk image
-if [ $# -ne 2 -a $# -ne 3 ]; then
-   echo "Usage: $0 <bios file> <floppy image> [harddisk image]"
-   exit 1
-fi
-
-bios="$1"
-floppy="$2"
-hdimage="$3"
-
-clear
-stty cbreak raw -echo min 0
-8086tiny $bios $floppy $hdimage
-stty cooked echo
-
-EOF
-
-patchShebangs run-8086tiny
-install run-8086tiny $out/bin
-