December SPECIAL! For a limited time only. Get 20% discount on a LIFETIME PRO account!Want more features on Pastebin? Sign Up, it's FREE!
tweet
Guest

Partial deobfuscation of skullcode layer 1

By: a guest on Nov 13th, 2015  |  syntax: JavaScript  |  size: 51.86 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Handles event dispatching, engine initialization and main loop execution.
  3.  * @global
  4.  */
  5. var System = new function() {
  6.     var that = this;
  7.  
  8.     /**
  9.      * Represents a phase of execution (e.g. init, run...).
  10.      * @constructor
  11.      * @abstract
  12.      *
  13.      * Phase life-cycle is as follows:
  14.      *   begin(oldPhase);
  15.      *    - called after previous phase ends but before this phase is active.
  16.      *   wake();
  17.      *    - called after this phase is activated (i.e. System.oldPhase = this).
  18.      *   while (System.phase == this) {
  19.      *     update(dt);
  20.      *      - called on every main loop iteration, dt = time since last call.
  21.      *   }
  22.      *   end();
  23.      *    - called when phase is ending but before next phase begins.
  24.      */
  25.     function Phase() {
  26.         /**
  27.          * Called when this phase is activating.
  28.          *
  29.          * @param {Phase} oldPhase - The previous phase (null if none).
  30.          */
  31.         this.begin = function(oldPhase) {};
  32.  
  33.         /** Called when this phase is ending, before the next phase activates. */
  34.         this.end = function() {};
  35.  
  36.         /** Called when this phase has activated but before the first update. */
  37.         this.wake = function() {};
  38.  
  39.         /**
  40.          * Default NO-OP global event handler.
  41.          * @callback
  42.          * @param {InputState} s - The updated input state.
  43.          */
  44.         var defaultHandler = function(s) {
  45.             return false;
  46.         };
  47.  
  48.         /** Handle a 'character typed' event. */
  49.         this.charTyped = defaultHandler;
  50.         /** Handle a 'mouse scrolled' event. */
  51.         this.mouseWheel = defaultHandler;
  52.         /** Handle a 'mouse button released' event. */
  53.         this.mouseRelease = defaultHandler;
  54.         /** Handle a 'mouse button pressed' event. */
  55.         this.mousePress = defaultHandler;
  56.         /** Handle a 'mouse moved' event. */
  57.         this.mouseMove = defaultHandler;
  58.         /** Handle a 'key released' event. */
  59.         this.keyRelease = defaultHandler;
  60.         /** Handle a 'key pressed' event. */
  61.         this.keyPress = defaultHandler;
  62.  
  63.         /**
  64.          * Called on every main loop iteration whilst this phase is activated.
  65.          */
  66.         this.update = function(dt) {
  67.             return false;
  68.         };
  69.     }
  70.     this.Phase = Phase;
  71.  
  72.     /**
  73.      * @name Vector2
  74.      * Represents a 2-vector.
  75.      * @constructor
  76.      *
  77.      * Initialized to (0,0).
  78.      */
  79.     /**
  80.      * @name Vector2
  81.      * Copies a 2-vector.
  82.      * @constructor
  83.      *
  84.      * @param {Vector2} x - The vector to copy coordinates from.
  85.      */
  86.     /**
  87.      * Represents a 2-vector.
  88.      *
  89.      * @constructor
  90.      * @param {number} x - The initial x-coordinate of the vector.
  91.      * @param {number} y - The initial y-coordinate of the vector.
  92.      */
  93.     function Vector2(x, y) {
  94.         var that = this;
  95.         if (arguments.length >= 2) {
  96.             this.x = x;
  97.             this.y = y;
  98.         } else if (arguments.length == 1) {
  99.             this.x = x.x;
  100.             this.y = x.y;
  101.         } else {
  102.             this.x = this.y = 0;
  103.         }
  104.         this.toString = function() {
  105.             return "{x:" + that.x + ",y:" + that.y + "}";
  106.         };
  107.     }
  108.     this.Vector2 = Vector2;
  109.  
  110.     /**
  111.      * Represents a sample of input states.
  112.      * @constructor
  113.      *
  114.      * @param {InputState} [obj] - The InputState object to copy, if specified.
  115.      *
  116.      * If no InputState object is given, the state properties are initialized to
  117.      * 0/false.
  118.      *
  119.      * @member {Vector2} pagePos - Position of mouse in page coordinates.
  120.      * @member {Vector2} mousePos - Position of mouse in canvas coordinates.
  121.      * @member {Vector2} mouseMov - Distance moved since list mousemove event.
  122.      * @member {number} mouseWheel - 1 if last scrolled down, -1 if last scrolled up.
  123.      * @member {number} mouseButton - Bit-flags indicating currently pressed mouse buttons.
  124.      * @member {number} keyCode - key-code of last pressed key (see KeyboardEvent.keyCode).
  125.      * @member {number} charCode - char-code of last pressed key (see KeyboardEvent.charCode).
  126.      * @member {boolean} ctrlPressed - Flag indicating whether CTRL is pressed.
  127.      * @member {boolean} altPressed - Flag indicating whether ALT is pressed.
  128.      * @member {boolean} shiftPressed - Flag indicating whether SHIFT is pressed.
  129.      */
  130.     function InputState(obj) {
  131.         if (arguments.length > 0) {
  132.             this.pagePos = new Vector2(obj.pagePos);
  133.             this.mousePos = new Vector2(obj.mousePos);
  134.             this.mouseMov = new Vector2(obj.mouseMov);
  135.             this.mouseWheel = obj.mouseWheel;
  136.             this.mouseButton = obj.mouseButton;
  137.             this.keyCode = obj.keyCode;
  138.             this.charCode = obj.charCode;
  139.             this.ctrlPressed = obj.ctrlPressed;
  140.             this.altPressed = obj.altPressed;
  141.             this.shiftPressed = obj.shiftPressed;
  142.         } else {
  143.             this.pagePos = new Vector2();
  144.             this.mousePos = new Vector2();
  145.             this.mouseMov = new Vector2();
  146.             this.charCode = this.keyCode = this.mouseWheel = this.mouseButton = 0;
  147.             this.shiftPressed = this.altPressed = this.ctrlPressed = false;
  148.         }
  149.     }
  150.     this.InputState = InputState;
  151.  
  152.     /**
  153.      * Update the input state with the current modifier key states.
  154.      *
  155.      * @param {Event} evt - The current DOM event.
  156.      */
  157.     function updateModifiers(evt) {
  158.         inputState.ctrlPressed = evt.ctrlKey;
  159.         inputState.altPressed = evt.altKey;
  160.         inputState.shiftPressed = evt.shiftKey;
  161.     }
  162.  
  163.     /**
  164.      * Initialize input callbacks and start engine.
  165.      */
  166.     function init() {
  167.         if (canvasLoaded) {
  168.             that.phase = new Phase();
  169.             oldPhase = null;
  170.  
  171.             // mousewheel handler
  172.             var mousewheelHandler = function(evt) {
  173.                 try {
  174.                     updateModifiers(evt);
  175.                     // Get direction of scroll (1 = down, -1 = up)
  176.                     inputState.mouseWheel = (0 < (evt.detail ? evt.detail : -evt.wheelDelta) ? 1 : -1);
  177.                     if (that.phase !== null) {
  178.                         that.phase.mouseWheel(inputState);
  179.                     }
  180.                 } catch (err) {}
  181.                 evt.preventDefault();
  182.             };
  183.             document.addEventListener("DOMMouseScroll", mousewheelHandler, false);
  184.             document.addEventListener("mousewheel", mousewheelHandler, false);
  185.  
  186.             // mousemove handler
  187.             window.addEventListener("mousemove", function(evt) {
  188.                 updateModifiers(evt);
  189.                 var canvasRect = canvas.getBoundingClientRect();
  190.                 inputState.mousePos.x = Math.floor((inputState.pagePos.x = evt.pageX) - canvasRect.left);
  191.                 inputState.mousePos.y = Math.floor((inputState.pagePos.y = evt.pageY) - canvasRect.top);
  192.  
  193.                 if (evt.movementX !== 0) {
  194.                     inputState.mouseMov.x = evt.movementX;
  195.                     inputState.mouseMov.y = evt.movementY;
  196.                 } else if (evt.mozMovementX !== 0) {
  197.                     inputState.mouseMov.x = evt.mozMovementX;
  198.                     inputState.mouseMov.y = evt.mozMovementY;
  199.                 } else if (evt.webkitMovementX !== 0) {
  200.                     inputState.mouseMov.x = evt.webkitMovementX;
  201.                     inputState.mouseMov.y = evt.webkitMovementY;
  202.                 }
  203.                 if (that.phase !== null) {
  204.                     that.phase.mouseMove(inputState);
  205.                 }
  206.                 evt.preventDefault();
  207.             }, false);
  208.  
  209.             // mousedown handler
  210.             canvas.addEventListener("mousedown", function(evt) {
  211.                 updateModifiers(evt);
  212.                 evt.preventDefault();
  213.                 document.activeElement.blur();
  214.                 inputState.mouseButton |= 1 << evt.button;
  215.                 if (that.phase !== null) {
  216.                     that.phase.mousePress(inputState);
  217.                 }
  218.             }, false);
  219.  
  220.             // contextmenu handler
  221.             bodyElement.oncontextmenu = function() {
  222.                 return contextMenuAllowed;
  223.             };
  224.  
  225.             // mouseup handler
  226.             window.addEventListener("mouseup", function(evt) {
  227.                 updateModifiers(evt);
  228.                 evt.preventDefault();
  229.                 inputState.mouseButton &= ~(1 << evt.button);
  230.                 if (that.phase !== null) {
  231.                     that.phase.mouseRelease(inputState);
  232.                 }
  233.             }, false);
  234.  
  235.             // keydown handler
  236.             document.addEventListener("keydown", function(evt) {
  237.                 updateModifiers(evt);
  238.                 inputState.keyCode = evt.keyCode;
  239.                 // Prevent tab/backspace from doing their default actions
  240.                 if (evt.keyCode === 8 || evt.keyCode === 9) {
  241.                     evt.preventDefault();
  242.                 }
  243.                 if (that.phase !== null) {
  244.                     that.phase.keyPress(inputState);
  245.                 }
  246.             }, false);
  247.  
  248.             // keypress handler
  249.             document.addEventListener("keypress", function(evt) {
  250.                 updateModifiers(evt);
  251.                 inputState.keyCode = evt.keyCode;
  252.                 inputState.charCode = evt.charCode;
  253.                 if (that.phase !== null) {
  254.                     that.phase.charTyped(inputState);
  255.                 }
  256.                 evt.preventDefault();
  257.             }, false);
  258.  
  259.             // keyup handler
  260.             document.addEventListener("keyup", function(evt) {
  261.                 updateModifiers(evt);
  262.                 inputState.keyCode = evt.keyCode;
  263.                 if (that.phase !== null) {
  264.                     that.phase.keyRelease(inputState);
  265.                 }
  266.                 evt.preventDefault();
  267.             }, false);
  268.             postInit();
  269.             that.update()
  270.         }
  271.     }
  272.  
  273.     /**
  274.      * Call onInit handlers and prevent further attempts to initialize.
  275.      */
  276.     function postInit() {
  277.         for (var i = 0; i < initHandlers.length; i++) {
  278.             try {
  279.                 initHandlers[i](systemConfig);
  280.             } catch (err) {
  281.                 that.err("postInit routine #" + i, err)
  282.             }
  283.         }
  284.         initDone = true;
  285.     }
  286.  
  287.     /**
  288.      * Execute a loop of the engine.
  289.      *
  290.      * @param {DOMHighResTimeStamp} timestamp - The current time.
  291.      * @callback Window.requestAnimationFrame
  292.      */
  293.     function mainLoop(timestamp) {
  294.         if (realtimeEnabled) {
  295.             // Schedule update ASAP
  296.             window.requestAnimationFrame(mainLoop);
  297.         }
  298.         var dt = 0;
  299.         if (prevTimestamp != 0) {
  300.             dt = timestamp - prevTimestamp;
  301.         }
  302.         prevTimestamp = timestamp;
  303.         try {
  304.             if (that.phase !== oldPhase) {
  305.                 if (oldPhase !== null) {
  306.                     oldPhase.end()
  307.                 }
  308.                 if (that.phase != null) {
  309.                     that.phase.begin(oldPhase);
  310.                     oldPhase = that.phase;
  311.                     that.phase.wake();
  312.                 }
  313.             }
  314.             if (that.phase != null) {
  315.                 that.phase.update(dt);
  316.             }
  317.         } catch (err) {
  318.             that.err("mainLoop()", err)
  319.         }
  320.     }
  321.  
  322.     /** Skullcode version? */
  323.     this.version = 1408337099853;
  324.     /** @constant {number} */
  325.     this.TAU = 6.283185307179586;
  326.     /** @constant {number} */
  327.     this.RAD2DEG = 57.2957795131;
  328.     /** @constant {number} */
  329.     this.DEG2RAD = 0.01745329251;
  330.     /** @constant {number} */
  331.     this.VIEW2D = 0;
  332.     /** @constant {number} */
  333.     this.VIEW3D = 1;
  334.     /** @constant {number} */
  335.     this.NEAREST = 0;
  336.     /** @constant {number} */
  337.     this.LINEAR = 1;
  338.     /** @constant {number} */
  339.     this.DRAW = 1;
  340.     /** @constant {number} */
  341.     this.CACHE = 2;
  342.     /** @constant {number} */
  343.     this.DRAW_CACHE = this.DRAW | this.CACHE;
  344.  
  345.     /** Currently active phase. */
  346.     this.phase = null;
  347.  
  348.     var realtimeEnabled = true,
  349.         bodyElement = null,
  350.         oldPhase = null,
  351.         canvas = null,
  352.         initHandlers = [],
  353.         initDone = false,
  354.         canvasLoaded = false,
  355.         systemConfig = null,
  356.         intervalID = null,
  357.         inputState = new InputState(),
  358.         prevTimestamp = 0,
  359.         contextMenuAllowed = false;
  360.  
  361.     /**
  362.      * Set whether the context menu is enabled.
  363.      *
  364.      * @param {boolean} enable - If true, allow the context menu to appear.
  365.      */
  366.     this.allowContextMenu = function(enable) {
  367.         contextMenuAllowed = enable ? true : false;
  368.     };
  369.  
  370.     /**
  371.      * Log a given message (triggers a window.alert()).
  372.      *
  373.      * @param {string} msg - The message to log.
  374.      */
  375.     this.log = function(msg) {
  376.         window.alert(msg);
  377.     };
  378.  
  379.     /**
  380.      * Log a given error.
  381.      *
  382.      * @param {string} msg - A string describing the error.
  383.      * @param {exception} [exc] - An exception associated with the error.
  384.      */
  385.     this.err = function(msg, exc) {
  386.         try {
  387.             if (arguments.length < 2) {
  388.                 this.log("ERROR: " + msg);
  389.             } else {
  390.                 this.log("ERROR: " + msg + " : " + exc.toString() + " : line " +
  391.                     exc.lineNumber + " of file: " + exc.fileName);
  392.             }
  393.         } catch (err) {}
  394.     };
  395.  
  396.     /**
  397.      * Log a given warning.
  398.      *
  399.      * @param {string} msg - A string describing the warning.
  400.      * @param {exception} [exc] - An exception associated with the warning.
  401.      */
  402.     this.warn = function(msg, exc) {
  403.         try {
  404.             if (arguments.length < 2) {
  405.                 this.log("WARNING: " + msg);
  406.             } else {
  407.                 this.log("WARNING: " + msg + " : " + exc.toString() + " : line " +
  408.                     exc.lineNumber + " of file: " + exc.fileName);
  409.             }
  410.         } catch (err) {}
  411.     };
  412.  
  413.     /**
  414.      * Add a callback to the list of onInit handlers.
  415.      *
  416.      * @param {function(systemConfig)} f - The function to call on initialization.
  417.      */
  418.     this.onInit = function(f) {
  419.         if (!initDone) {
  420.             initHandlers.push(f);
  421.         } else {
  422.             this.err("Function not added via onInit(), already initialized");
  423.         }
  424.     };
  425.  
  426.     /**
  427.      * Configure and initialize the engine.
  428.      *
  429.      * @param {dictionary} config - The configuration of the engine.
  430.      *
  431.      * Supported configuration options are:
  432.      *   realtime - ?
  433.      *   canvas - ID/DOM object of canvas to render to.
  434.      */
  435.     this.start = function(config) {
  436.         if (systemConfig != null) {
  437.             this.err("start() called while engine is already running.");
  438.             return false;
  439.         }
  440.         systemConfig = {
  441.             realtime: true,
  442.             canvas: "viewport"
  443.         };
  444.         if (typeof config != "undefined" && config !== null) try {
  445.             systemConfig.realtime = config.realtime ? true : false;
  446.             if (typeof config.canvas != "undefined") {
  447.                 systemConfig.canvas = config.canvas;
  448.             }
  449.         } catch (err) {
  450.             return this.err("setup object invalid ", err), false
  451.         }
  452.         return init();
  453.     };
  454.  
  455.     /**
  456.      * Enable or disable realtime execution.
  457.      *
  458.      * @param {boolean} enable - If true, VM updates will occur as soon as possible.
  459.      */
  460.     this.setRealtime = function(enable) {
  461.         if (enable && realtimeEnabled != enable) {
  462.             window.requestAnimationFrame(mainLoop);
  463.         }
  464.         realtimeEnabled = enable;
  465.     };
  466.  
  467.     /**
  468.      * Enable or disable image smoothing.
  469.      *
  470.      * @param {CanvasRenderingContext2D} context - The context to set image smoothing state on.
  471.      * @param {boolean} enable
  472.      */
  473.     this.scaleSmoothing = function(context, enable) {
  474.         enable = enable ? true : false;
  475.         context.imageSmoothingEnabled = enable;
  476.         context.mozImageSmoothingEnabled = enable;
  477.         context.webkitImageSmoothingEnabled = enable;
  478.     };
  479.  
  480.     /**
  481.      * Enter or leave full-screen mode.
  482.      *
  483.      * @param {boolean} enable
  484.      */
  485.     this.setFullScreen = function(enable) {
  486.         this.log("Setting screen mode: " + enable);
  487.         if (enable) {
  488.             if (canvas.requestFullscreen) {
  489.                 canvas.requestFullscreen();
  490.             } else if (canvas.msRequestFullscreen) {
  491.                 canvas.msRequestFullscreen();
  492.             } else if (canvas.mozRequestFullScreen) {
  493.                 canvas.mozRequestFullScreen();
  494.             } else if (canvas.webkitRequestFullscreen) {
  495.                 canvas.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  496.             } else {
  497.                 this.log("Fullscreen not supported.")
  498.             }
  499.         } else {
  500.             if (document.exitFullscreen) {
  501.                 document.exitFullscreen();
  502.             } else if (document.msExitFullscreen) {
  503.                 document.msExitFullscreen();
  504.             } else if (document.mozCancelFullScreen) {
  505.                 document.mozCancelFullScreen();
  506.             } else if (document.webkitExitFullscreen) {
  507.                 document.webkitExitFullscreen();
  508.             } else {
  509.                 this.log("Fullscreen not supported.");
  510.             }
  511.         }
  512.     };
  513.  
  514.     /**
  515.      * Enable or disable pointer lock.
  516.      *
  517.      * @param {boolean} enable
  518.      */
  519.     this.setPointerLock = function(enable) {
  520.         this.log("Setting pointer lock: " + enable);
  521.         if (enable) {
  522.             if (canvas.requestPointerLock) {
  523.                 canvas.requestPointerLock();
  524.             } else if (canvas.mozRequestPointerLock) {
  525.                 canvas.mozRequestPointerLock();
  526.             } else if (canvas.webkitRequestPointerLock) {
  527.                 canvas.webkitRequestPointerLock();
  528.             } else {
  529.                 this.log("Pointer lock not supported.")
  530.             }
  531.         } else {
  532.             if (canvas.exitPointerLock) {
  533.                 canvas.exitPointerLock();
  534.             } else if (canvas.mozExitPointerLock) {
  535.                 canvas.mozExitPointerLock();
  536.             } else if (canvas.webkitExitPointerLock) {
  537.                 canvas.webkitExitPointerLock();
  538.             } else {
  539.                 this.log("Pointer lock not supported.");
  540.             }
  541.         }
  542.     };
  543.  
  544.     /**
  545.      * Run a single iteration of the main engine loop.
  546.      */
  547.     this.update = function() {
  548.         window.requestAnimationFrame(mainLoop);
  549.     };
  550.  
  551.     // Wait for canvas to load before initializing.
  552.     intervalID = window.setInterval(function preInit() {
  553.         try {
  554.             if (!bodyElement) {
  555.                 bodyElement = document.getElementsByTagName("body")[0];
  556.             }
  557.             if (systemConfig !== null && canvas === null)
  558.                 if ("string" == typeof systemConfig.canvas) {
  559.                     canvas = document.getElementById(systemConfig.canvas);
  560.                     if (canvas) {
  561.                         systemConfig.canvas = canvas;
  562.                     }
  563.                 } else {
  564.                     canvas = systemConfig.canvas;
  565.                 }
  566.             if (bodyElement && canvas) {
  567.                 window.clearInterval(intervalID);
  568.                 intervalID = null;
  569.                 canvasLoaded = true;
  570.                 if (systemConfig != null) {
  571.                     // System is configured, make sure it is initialized.
  572.                     init();
  573.                 }
  574.             }
  575.         } catch (err) {
  576.             that.err("preInit() failed", err);
  577.         }
  578.     }, 250);
  579. };
  580. new function() {
  581.     var sys = System;
  582.  
  583.     function h(f) {
  584.         var a = this,
  585.             e = a.value = 0;
  586.         a.advance = function(c) {
  587.             e += c;
  588.             return 0 >= e ? a.value = e = 0 : e >= f ? (e = f, a.value = 1) : a.value = e / f
  589.         };
  590.         a.reset = function(c) {
  591.             e = a.value = 0;
  592.             0 < arguments.length && (f = c)
  593.         }
  594.     }
  595.     sys.LinearInterp = h;
  596.  
  597.     /**
  598.      * @name Vector3
  599.      * Represents a 3-vector.
  600.      * @constructor
  601.      *
  602.      * Initialized to (0,0,0).
  603.      */
  604.     /**
  605.      * @name Vector3
  606.      * Copies a 3-vector.
  607.      * @constructor
  608.      *
  609.      * @param {Vector3} x - The vector to copy coordinates from.
  610.      */
  611.     /**
  612.      * Represents a 3-vector.
  613.      *
  614.      * @constructor
  615.      * @param {number} x - The initial x-coordinate of the vector.
  616.      * @param {number} y - The initial y-coordinate of the vector.
  617.      * @param {number} z - The initial z-coordinate of the vector.
  618.      */
  619.     function Vector3(x, y, z) {
  620.         var that = this;
  621.         if (arguments.length >= 2) {
  622.             this.x = x;
  623.             this.y = y;
  624.             this.z = z;
  625.         } else if (arguments.length == 1) {
  626.             this.x = x.x;
  627.             this.y = x.y;
  628.             this.z = x.z;
  629.         } else {
  630.             this.x = this.y = this.z = 0;
  631.         }
  632.         this.toString = function() {
  633.             return "{x:" + that.x + ",y:" + that.y + ",z:" + that.z + "}";
  634.         }
  635.     }
  636.     sys.Vector3 = Vector3;
  637.  
  638.     /**
  639.      * Represents a linked list of objects.
  640.      * @constructor
  641.      *
  642.      * Note: 'prior' and 'next' properties are added to objects that are
  643.      * added to this linked list, and can be used to navigate it.
  644.      */
  645.     sys.LinkedList = function() {
  646.         var _first = null,
  647.             _last = null;
  648.  
  649.         /** @returns {object} The first object in the list. */
  650.         this.first = function() {
  651.             return _first;
  652.         };
  653.  
  654.         /** @returns {object} The last object in the list. */
  655.         this.last = function() {
  656.             return _last;
  657.         };
  658.  
  659.         /**
  660.          * Add an object to the end of the list.
  661.          *
  662.          * @param {object} elem - The object to add.
  663.          */
  664.         this.add = function(elem) {
  665.             if (_first == null) {
  666.                 _first = elem;
  667.             } else {
  668.                 _last.next = elem;
  669.             }
  670.             elem.prior = _last;
  671.             _last = elem;
  672.         };
  673.  
  674.         /**
  675.          * Remove an object from the list (next and prior are set to null).
  676.          *
  677.          * @param {object} elem - The object to remove.
  678.          */
  679.         this.unlink = function(elem) {
  680.             if (elem.next == null) {
  681.                 _last = elem.prior;
  682.             } else {
  683.                 elem.next.prior = elem.prior;
  684.             }
  685.             if (elem.prior == null) {
  686.                 _first = elem.next;
  687.             } else {
  688.                 elem.prior.next = elem.next;
  689.             }
  690.             elem.prior = elem.next = null;
  691.         };
  692.  
  693.         /**
  694.          * Insert an object after an element.
  695.          *
  696.          * @param {object} elem - The object to insert.
  697.          * @param {object} [target] - The object to insert before (defaults to this.first)
  698.          */
  699.         this.insert = function(elem, target) {
  700.             if (null == target) {
  701.                 target = _first;
  702.             }
  703.             if (null == target) {
  704.                 _last = _first = elem;
  705.             } else {
  706.                 if (target === _first) {
  707.                     _first = elem;
  708.                 } else {
  709.                     target.prior.next = elem;
  710.                 }
  711.                 elem.prior = target.prior;
  712.                 target.prior = elem;
  713.                 elem.next = target;
  714.             }
  715.         };
  716.         /**
  717.          * Clear the contents of this list (note: does not reset elements).
  718.          */
  719.         this.empty = function() {
  720.             _first = _last = null;
  721.         };
  722.         /**
  723.          * Attach a list to the end of this list.
  724.          *
  725.          * @param {LinkedList} list - The list to attach (will be emptied afterwards).
  726.          */
  727.         this.attach = function(list) {
  728.             if (_first == null) {
  729.                 _first = list.first();
  730.                 _last = list.last();
  731.             } else {
  732.                 _last.next = list.first();
  733.                 if (_last.next != null) {
  734.                     _last.next.prior = _last;
  735.                     _last = list.last();
  736.                 }
  737.             }
  738.             list.empty();
  739.         }
  740.     };
  741.  
  742.     sys.LCPRNG = function(f, a) {
  743.         var e = this,
  744.             c = [],
  745.             b = 0;
  746.         e.seed = function(l) {
  747.             if (0 < arguments.length) {
  748.                 c[0] = f = l | 0;
  749.                 for (var g = a - 1, d = 1; d < g; ++d) c[d] = 16807 * c[d - 1] & 2147483647;
  750.                 c[g] = c[0];
  751.                 c[0] = c[1];
  752.                 c[1] = c[2];
  753.                 b = 2;
  754.                 g = a << 4;
  755.                 for (d = 0; d < g; ++d) e.rand()
  756.             }
  757.             return f
  758.         };
  759.         e.rand = function() {
  760.             var e = b;
  761.             b = (b + 1) % a;
  762.             return c[e] = c[b] + c[(b + 29) % a] >> 0
  763.         };
  764.         e.toString = function() {
  765.             return e.seed()
  766.         };
  767.         1 > arguments.length && (f = 1);
  768.         2 > arguments.length && (a = 32);
  769.         e.seed(f)
  770.     };
  771.     sys.SineInterp = function(f) {
  772.         var a = this;
  773.         a.value = 0;
  774.         var e = new h(f),
  775.             c = Math.PI / 2;
  776.         a.advance = function(b) {
  777.             b = e.advance(b);
  778.             return 1 == b ? a.value = 1 : 0 == b ? a.value = 0 : a.value = Math.sin(b * c)
  779.         };
  780.         a.reset = function(b) {
  781.             a.value = 0;
  782.             0 < arguments.length ? e.reset(b) : e.reset()
  783.         }
  784.     };
  785.     sys.CosineInterp = function(f) {
  786.         var a = this;
  787.         a.value = 0;
  788.         var e = new h(f),
  789.             c = Math.PI;
  790.         a.advance = function(b) {
  791.             b = e.advance(b);
  792.             return 1 == b ? a.value = 1 : 0 == b ? a.value = 0 : a.value = 0.5 * (1 - Math.cos(b * c))
  793.         };
  794.         a.reset = function(b) {
  795.             a.value = 0;
  796.             0 < arguments.length ? e.reset(b) : e.reset()
  797.         }
  798.     };
  799.     sys.Box3 = function(f, a, e, c, b, l) {
  800.         var n = this;
  801.         5 <= arguments.length ? (n.a = new Vector3(f, a, e), n.b = new Vector3(c, b, l)) : 1 < arguments.length ? (n.a = new Vector3(f), n.b = new Vector3(a)) : 1 == arguments.length ? (n.a = new Vector3(f.a), n.b = new Vector3(f.b)) : (n.a = new Vector3, n.b = new Vector3);
  802.         this.toString = function() {
  803.             return "{a:" + n.a + ",b:" + n.b + "}"
  804.         }
  805.     };
  806.  
  807.     /**
  808.      * Calculates the cross product of two Vector3 instances.
  809.      *
  810.      * @param {Vector3} a - The left parameter to the cross product.
  811.      * @param {Vector3} b - The right parameter to the cross product.
  812.      * @param {Vector3} c - The Vector3 to set to the result.
  813.      */
  814.     sys.cross = function(a, b, c) {
  815.         c.x = a.y * b.z - a.z * b.y;
  816.         c.y = a.z * b.x - a.x * b.z;
  817.         c.z = a.x * b.y - a.y * b.x
  818.     }
  819. };
  820. new function() {
  821.     function h(f, a) {
  822.         function e(b) {
  823.             if (!b.isLoaded) {
  824.                 b.isLoaded = true;
  825.                 try {
  826.                     var d = eval(l.responseText);
  827.                     a(d)
  828.                 } catch (c) {
  829.                     a(null)
  830.                 }
  831.             }
  832.         }
  833.         var c = document.getElementsByTagName("body")[0];
  834.         if (!c) return false;
  835.         if (k) {
  836.             _JSE_ = null;
  837.             var b = document.createElement("script");
  838.             b.onload = function() {
  839.                 a(_JSE_);
  840.                 c.removeChild(b)
  841.             };
  842.             b.onerror = function() {
  843.                 g.log("fetchObj() failed to load: " + f);
  844.                 c.removeChild(b);
  845.                 a(null)
  846.             };
  847.             b.src = f;
  848.             c.appendChild(b)
  849.         } else {
  850.             var l = new XMLHttpRequest;
  851.             l.isLoaded = false;
  852.             l.onreadystatechange = function() {
  853.                 4 === l.readyState && e(l)
  854.             };
  855.             l.onload = function() {
  856.                 e(l)
  857.             };
  858.             l.ontimeout = function() {
  859.                 g.log("fetchObj() failed to download: " + f);
  860.                 a(null)
  861.             };
  862.             l.open("GET", f, true);
  863.             l.send(null)
  864.         }
  865.     }
  866.     var g = System,
  867.         k = "file:" == window.location.protocol;
  868.     g.fetchObject = h;
  869.     g.ImageLoader = function(f, a) {
  870.         this.fails = this.loaded = this.count = 0;
  871.         this.queue = function(b, l) {
  872.             var g = new Image;
  873.             b = f + b;
  874.             g.onload = function() {
  875.                 var d = b;
  876.                 try {
  877.                     e.loaded++, a && a(g, true, d, l)
  878.                 } catch (c) {}
  879.             };
  880.             g.onerror = function() {
  881.                 var d = b;
  882.                 try {
  883.                     e.fails++, a && a(g, false, d, l)
  884.                 } catch (c) {}
  885.             };
  886.             g.src = b;
  887.             c[c.length] = g;
  888.             e.count = c.length
  889.         };
  890.         var e = this,
  891.             c = [];
  892.         void 0 == f && (f = "")
  893.     };
  894.     g.Asset = function(f, a, e, c, b, l) {
  895.         function g(a, b) {
  896.             null != a && (d.flag = a ? d.flag | b : d.flag & ~b);
  897.             return 0 < (d.flag & b) ? true : false
  898.         }
  899.         var d = this;
  900.         d.type = f ? f : "unknown";
  901.         d.name = a ? a : "";
  902.         d.path = e ? e : "";
  903.         d.flag = c ? c : 0;
  904.         d.rev = l ? l : 0;
  905.         5 <= arguments.length ? d.id = b : (d.id = assets.length, d.flag |= 6);
  906.         assets[d.id] = d;
  907.         d.loaded = function(a) {
  908.             return g(1 > arguments.length ? null : a, 1)
  909.         };
  910.         d.stow = function(a) {
  911.             return g(1 > arguments.length ? null : a, 2)
  912.         };
  913.         d.updated = function(a) {
  914.             return g(1 > arguments.length ? null : a, 4)
  915.         };
  916.         d.customJSE = function() {
  917.             return null
  918.         };
  919.         d.toString = function() {
  920.             var a = d.customJSE(),
  921.                 b = d.flags;
  922.             d.loaded(false);
  923.             d.updated(false);
  924.             a = "{\tid :\t" + d.id + ",\n\trev :\t" + d.rev + ",\n\tflag :\t" + d.flag + ",\n\ttype :\t" + JSON.stringify(d.type) + ",\n\tname :\t" + JSON.stringify(d.name) + ",\n\tpath :\t" + JSON.stringify(d.path) + (null == a ? "" : ",\n\t" + a) + "\n}";
  925.             d.flags = b;
  926.             return a
  927.         }
  928.     };
  929.     g.AssetManager = function(f) {
  930.         var a = this,
  931.             e = {},
  932.             c = {},
  933.             b = {};
  934.         f = 1 > arguments.length ? "" : f.toString();
  935.         a.register = function(a, c) {
  936.             b[a] = c
  937.         };
  938.         a.storeAll = function(b, c, d) {
  939.             var f = 0,
  940.                 g;
  941.             for (g in e) {
  942.                 var h = e[g];
  943.                 null == h || b && "function" == typeof h.updated && !h.updated() || (++f, a.store(h, c, d))
  944.             }
  945.             return f
  946.         };
  947.         a.store = function(a, b, d) {
  948.             if (d) {
  949.                 g.log("Error: AssetManager.store(): Remote storage unimplemented.", "#911");
  950.                 try {
  951.                     b(a, 0)
  952.                 } catch (c) {
  953.                     g.log("Error: AssetManager.store() callback(data,0): " + c)
  954.                 }
  955.             } else if (localStorage) try {
  956.                 localStorage.setItem(a.path, "_JSE_=" + a.toString());
  957.                 try {
  958.                     b(a, 1)
  959.                 } catch (e) {
  960.                     g.log("Error: AssetManager.store() callback(data,1): " + e)
  961.                 }
  962.             } catch (f) {
  963.                 g.log("Error: AssetManager.store() localStorage.setItem(): " + f);
  964.                 try {
  965.                     b(a, 0)
  966.                 } catch (h) {
  967.                     g.log("Error: AssetManager.store() callback(data,0): " + h)
  968.                 }
  969.             } else {
  970.                 g.log("Error: AssetManager.store(): No localStorage");
  971.                 try {
  972.                     b(a, 0)
  973.                 } catch (k) {
  974.                     g.log("Error: AssetManager.store() callback(data,0): " + k)
  975.                 }
  976.             }
  977.         };
  978.         a.fetch = function(a, k, d) {
  979.             3 > arguments.length && (d = false);
  980.             var p = e[a];
  981.             if (p) {
  982.                 try {
  983.                     g.log("AM: already loaded: " + a), k(p, a)
  984.                 } catch (r) {
  985.                     return g.log("AssetManager callback error '" + f + a + "': " + r, "#911"), -1
  986.                 }
  987.                 return 0
  988.             }
  989.             var u = c[a];
  990.             if (u) return d || u.push(func), 3;
  991.             var u = c[a] = [k],
  992.                 v = function(d) {
  993.                     if (null == d)
  994.                         for (var h in u) try {
  995.                             u[h](null, a)
  996.                         } catch (k) {
  997.                             g.log("AssetManager callback error '" + f + a + "': " + k, "#911")
  998.                         } else {
  999.                             if (d.type) {
  1000.                                 var n = b[d.type];
  1001.                                 if (n) try {
  1002.                                     d = n(d, a)
  1003.                                 } catch (p) {
  1004.                                     g.log("AssetManager creation error '" + f + a + "': " + p, "#911");
  1005.                                     for (h in u) try {
  1006.                                         var r = u[h];
  1007.                                         r && r(null, a)
  1008.                                     } catch (G) {
  1009.                                         g.log("AssetManager callback error '" + f + a + "': " + G, "#911")
  1010.                                     }
  1011.                                     delete c[a];
  1012.                                     return
  1013.                                 }
  1014.                             }
  1015.                             e[a] = d;
  1016.                             for (h in u) try {
  1017.                                 (r = u[h]) && r(d, a)
  1018.                             } catch (T) {
  1019.                                 g.log("AssetManager callback error '" + f + a + "': " + T, "#911")
  1020.                             }
  1021.                         }
  1022.                     delete c[a]
  1023.                 };
  1024.             if (localStorage && (p = localStorage.getItem(a), null != p)) try {
  1025.                 return v(eval(p)), 1
  1026.             } catch (A) {
  1027.                 g.log("AssetManager localStorage eval() error '" + a + "': " + A + "\n" + p.toString(), "#911")
  1028.             }
  1029.             h(f + a, v);
  1030.             return 2
  1031.         };
  1032.         a.getAsset = function(a) {
  1033.             a = e[a];
  1034.             return void 0 != typeof a ? a : null
  1035.         };
  1036.         a.setAsset = function(a, b) {
  1037.             null === b ? delete e[a] : e[a] = b
  1038.         }
  1039.     };
  1040.     g.getAsset = function(f) {
  1041.         f = assets[f];
  1042.         return void 0 == typeof f ? null : f
  1043.     }
  1044. };
  1045. var M = "<snip - see vm.js>";
  1046. new function() {
  1047.     function h(a) {
  1048.         this.data = null;
  1049.         this.direct = false;
  1050.         this.size = this.pos = this.id = this.host = null;
  1051.         0 < arguments.length && (this.data = a.data, this.direct = a.direct, this.host = a.host, this.id = a.id, this.pos = a.pos, this.size = a.size)
  1052.     }
  1053.  
  1054.     function g() {
  1055.         this.skull = this.id = null;
  1056.         this.bind = function(a, e) {
  1057.             return null
  1058.         };
  1059.         this.connect = function(a, e, c) {
  1060.             k.log("sc.connect( " + a + ", " + e + ", " + c + " )");
  1061.             return true
  1062.         }
  1063.     }
  1064.     var k = System,
  1065.         f = M;
  1066.     M = "";
  1067.     k.Protocol = h;
  1068.     k.Machine = g;
  1069.     Math.imul || (Math.imul = function(a, e) {
  1070.         var c = a & 65535,
  1071.             b = e & 65535;
  1072.         return c * b + ((a >>> 16 & 65535) * b + c * (e >>> 16 & 65535) << 16 >>> 0) | 0
  1073.     });
  1074.     Math.fround || (Math.fround = function() {
  1075.         var a = new Float32Array(1);
  1076.         return function(e) {
  1077.             a[0] = +e;
  1078.             return a[0]
  1079.         }
  1080.     }());
  1081.     k.Environment = function() {
  1082.         function a(a) {
  1083.             if ("number" != typeof a) try {
  1084.                 return a.toString()
  1085.             } catch (b) {
  1086.                 a = v
  1087.             }
  1088.             a |= 0;
  1089.             return 0 > a || a >= m.length ? "Unknown Error." : m[a]
  1090.         }
  1091.  
  1092.         function e(a) {
  1093.             throw a >>> 0;
  1094.         }
  1095.  
  1096.         function c() {
  1097.             var a;
  1098.             do a = (+new Date ^ 65536 * Math.random() ^ 65536 * Math.random() << 16) >>> 0 | 0; while (void 0 !== w[a]);
  1099.             return a
  1100.         }
  1101.  
  1102.         function b() {
  1103.             var a;
  1104.             do a = (+new Date ^ 65536 * Math.random() ^ 65536 * Math.random() << 16) >>> 0 | 0; while (void 0 !== C[a]);
  1105.             return a
  1106.         }
  1107.  
  1108.         function l(b) {
  1109.             if ("number" == typeof b) return 0 < b ? (k.log("sc error " + b + ", 0x" + b.toString(16) + ": " + a(b)), b) : b - 1;
  1110.             k.log("sc error ?: " + a(b));
  1111.             k.log(b);
  1112.             return A
  1113.         }
  1114.  
  1115.         function n(a) {
  1116.             k.log("sc.logs: " + a)
  1117.         }
  1118.  
  1119.         function d(a) {
  1120.             k.log("sc.logv: " + (a >>> 0).toString(16) + " : " + a)
  1121.         }
  1122.  
  1123.         function p(a) {
  1124.             a |= 0;
  1125.             0 > a && (a = 0);
  1126.             throw -a;
  1127.         }
  1128.  
  1129.         function r() {
  1130.             return Date.now()
  1131.         }
  1132.  
  1133.         function u(a) {
  1134.             this.inherit = g;
  1135.             this.inherit();
  1136.             a = (a | 0) >>> 13;
  1137.             ++D;
  1138.             this.id = c();
  1139.             a <<= 13;
  1140.             var b = new ArrayBuffer(a);
  1141.             new Uint8Array(b);
  1142.             var l = new Uint32Array(b);
  1143.             this.connect = function(a, b, d) {
  1144.                 return false
  1145.             };
  1146.             this.bind = function(a, b) {
  1147.                 return l.subarray(a >> 2, (a >> 2) + (b >> 2))
  1148.             };
  1149.             this.brain = (new Function("std", "foriegn", "heap", f))(window, {
  1150.                 error: e,
  1151.                 imul: Math.imul,
  1152.                 logs: n,
  1153.                 logv: d,
  1154.                 wait: p,
  1155.                 time: r
  1156.             }, b);
  1157.             this.size = a;
  1158.             this.heap = b
  1159.         }
  1160.         var v = 6,
  1161.             A = 7,
  1162.             m = "OK.;Permission Required.;Out of memory.;Invalid operation.;Invalid memory access.;Invalid access alignment.;Unknown error.;Host environment exception.;Halted.;Operation not supported.".split(";"),
  1163.             s = void 0;
  1164.         this.LSB = s;
  1165.         var D = 0,
  1166.             w = [],
  1167.             C = [];
  1168.         this.explain = a;
  1169.         this.cycle = function(a, b) {
  1170.             try {
  1171.                 return w[a].brain.cycle(b | 0)
  1172.             } catch (d) {
  1173.                 return l(d)
  1174.             }
  1175.         };
  1176.         this.init = function(a, b, d, c, e, f, g) {
  1177.             try {
  1178.                 w[a].brain.init(w[a].size - 1, b, d, c, e, f, g)
  1179.             } catch (h) {
  1180.                 return l(h)
  1181.             }
  1182.         };
  1183.         this.load = function(b, d, c) {
  1184.             try {
  1185.                 if ("string" == typeof d) throw a(9);
  1186.                 var e = w[b].bind(c, d.length << 2);
  1187.                 for (b = 0; b < d.length && b < e.length; ++b) e[b] = d[b];
  1188.                 k.log("Loaded " + b + " words.")
  1189.             } catch (f) {
  1190.                 return l(f)
  1191.             }
  1192.         };
  1193.         Date.now || (Date.now = function() {
  1194.             return (new Date).getTime()
  1195.         });
  1196.         try {
  1197.             s = function() {
  1198.                 var a = new ArrayBuffer(4);
  1199.                 (new DataView(a)).setUint32(0, 1718303319, true);
  1200.                 switch ((new Int32Array(a))[0]) {
  1201.                     case 1463446374:
  1202.                         return false;
  1203.                     case 1718303319:
  1204.                         return true;
  1205.                     default:
  1206.                         return null
  1207.                 }
  1208.             }()
  1209.         } catch (y) {
  1210.             k.log("sc: can't test LSB: " + y)
  1211.         }
  1212.         this.LSB = s;
  1213.         this.build = function(a) {
  1214.             a = new u(a);
  1215.             if (!a) throw 3;
  1216.             w[a.id] = a;
  1217.             return a.id
  1218.         };
  1219.         this.dump = function(a) {
  1220.             return w[a].heap
  1221.         };
  1222.         this.support = function(a) {
  1223.             var d = new h(a);
  1224.             d.id = b();
  1225.             C[d.id] = d;
  1226.             return a.id = d.id
  1227.         };
  1228.         this.register = function(a) {
  1229.             var b = c();
  1230.             w[b] = a;
  1231.             return b
  1232.         };
  1233.         this.connect = function(a, d, c) {
  1234.             var e = w[a];
  1235.             c = w[c];
  1236.             var f = C[d];
  1237.             if (!e || !c || !f) throw 3;
  1238.             try {
  1239.                 if (f = new h(f), f.host = e, f.client = c, f.data = e.bind(f.pos, f.size), f.id = b(), f.direct) try {
  1240.                     C[f.id] = f, c.connect(a, d, f.data)
  1241.                 } catch (g) {
  1242.                     throw delete C[f.id], A;
  1243.                 } else C[f.id] = f
  1244.             } catch (l) {
  1245.                 throw A;
  1246.             }
  1247.             return f.id
  1248.         }
  1249.     }
  1250. };
  1251. new function() {
  1252.     var h = System,
  1253.         g = "#000 #00a #0a0 #0aa #a00 #a0a #a50 #aaa #555 #55f #5f5 #5ff #f55 #f5f #ff5 #fff".split(" "),
  1254.         k = "#000000 #000084 #008400 #008080 #840000 #800080 #804000 #808080 #404040 #4040ff #38ff38 #40ffff #ff4040 #ff40ff #ffff40 #ffffff".split(" "),
  1255.         f = "#000000 #000099 #009900 #009292 #9b0000 #940094 #964b00 #939393 #4b4b4b #4c4ce0 #39e339 #40e2df #e34b4b #e34ae3 #e0e048 #e2e2e2".split(" ");
  1256.     h.InputDevice = function(a) {
  1257.         function e(b) {
  1258.             c[g] = (b.shiftPressed ? 1 : 0) | (b.ctrlPressed ? 2 : 0) | (b.altPressed ? 4 : 0);
  1259.             a(-1)
  1260.         }
  1261.         this.inherit = h.Phase;
  1262.         this.inherit();
  1263.         this.inherit = h.Machine;
  1264.         this.inherit();
  1265.         var c = null,
  1266.             b = false,
  1267.             f = 1,
  1268.             g = 2;
  1269.         this.setScale = function(a) {
  1270.             f = 0 + a
  1271.         };
  1272.         this.mouseMove = function(a) {
  1273.             c[5] = a.mousePos.x * f;
  1274.             c[6] = a.mousePos.y * f;
  1275.             c[9] += a.mouseMov.x * f;
  1276.             c[10] += a.mouseMov.y * f;
  1277.             c[0] |= 1;
  1278.             e(a)
  1279.         };
  1280.         this.mousePress = function(a) {
  1281.             c[7] = a.mouseButton;
  1282.             c[0] |= 2;
  1283.             e(a)
  1284.         };
  1285.         this.mouseRelease = function(a) {
  1286.             c[7] = a.mouseButton;
  1287.             c[0] |= 4;
  1288.             e(a)
  1289.         };
  1290.         this.mouseWheel = function(a) {
  1291.             c[8] = a.mouseWheel | 0;
  1292.             c[0] |= 8;
  1293.             e(a)
  1294.         };
  1295.         this.keyPress = function(a) {
  1296.             c[0] |= 16;
  1297.             c[3] = a.keyCode;
  1298.             e(a)
  1299.         };
  1300.         this.keyRelease = function(a) {
  1301.             c[3] = a.keyCode;
  1302.             c[0] |= 32;
  1303.             e(a)
  1304.         };
  1305.         this.charTyped = function(a) {
  1306.             c[0] |= 64;
  1307.             c[4] = a.charCode;
  1308.             e(a)
  1309.         };
  1310.         this.begin = function() {};
  1311.         this.end = function() {};
  1312.         this.update = function(b) {
  1313.             a(b);
  1314.             return true
  1315.         };
  1316.         this.connect = function(a, e, f) {
  1317.             if (b) return false;
  1318.             c = f;
  1319.             return b = true
  1320.         }
  1321.     };
  1322.     h.TextDisplay = function(a, e, c, b, l) {
  1323.         function n(a, b) {
  1324.             var c = b.length;
  1325.             if (null == N) {
  1326.                 N = Array(c);
  1327.                 for (var d = c; 0 <= --d;) N[d] = document.createElement("canvas")
  1328.             }
  1329.             for (d = c; 0 <= --d;) canvas = N[d], canvas.width = a.width, canvas.height = a.height, c = canvas.getContext("2d"), c.globalAlpha = 1, c.globalCompositeOperation = "source-over", c.drawImage(a, 0, 0), c.globalCompositeOperation = "source-atop", c.fillStyle = b[d], c.fillRect(0, 0, canvas.width, canvas.height)
  1330.         }
  1331.         var d = this;
  1332.         d.inherit = h.Machine;
  1333.         d.inherit();
  1334.         l = l ? true : false;
  1335.         b |= 0;
  1336.         e |= 0;
  1337.         c |= 0;
  1338.         var p = e * b,
  1339.             r = c * b;
  1340.         a.width = p;
  1341.         a.height = r;
  1342.         var u = null,
  1343.             v = 0,
  1344.             A = 0,
  1345.             m = a.getContext("2d"),
  1346.             s = m,
  1347.             D = 1 < b && l ? k : g;
  1348.         1 < b && (u = document.createElement("canvas"), u.width = e, u.height = c, s = u.getContext("2d"), u.ctx = s);
  1349.         s.fillStyle = D[0];
  1350.         s.fillRect(0, 0, e, c);
  1351.         var w = Math.floor(e / 9),
  1352.             C = c >>> 4,
  1353.             y = C * w,
  1354.             G = 4,
  1355.             T = G + (y >> 1) - 1,
  1356.             y = new ArrayBuffer(y << 2),
  1357.             R = new Uint32Array(y),
  1358.             U = false,
  1359.             q = 0,
  1360.             H, L, I, J, U = false,
  1361.             E = 0,
  1362.             B = null,
  1363.             Z = false,
  1364.             F, V, W, Q;
  1365.         d.connect = function(a, b, c) {
  1366.             if (Z) return false;
  1367.             B = c;
  1368.             V = +new Date;
  1369.             W = 666;
  1370.             Q = 0;
  1371.             F = false;
  1372.             G = 4;
  1373.             L = 13;
  1374.             H = 1;
  1375.             I = 7;
  1376.             J = 2;
  1377.             E = 0;
  1378.             q = E << 16 | H << 12 | L << 8 | I << 4 | J | 134217728;
  1379.             l && (q |= 268435456);
  1380.             B[0] = q;
  1381.             B[2] = C << 16 | w;
  1382.             B[1] = 0;
  1383.             B[3] = G;
  1384.             return Z = true
  1385.         };
  1386.         d.setScanLines = function(a) {
  1387.             l = a ? true : false;
  1388.             n(K[1], l ? k : g);
  1389.             l && 1 < b ? (viewport.parentElement.style.backgroundColor = f[E], D = k) : (viewport.parentElement.style.backgroundColor = g[E], D = g);
  1390.             s = 1 < b ? u.ctx : m;
  1391.             for (a = 0; a < R.length; ++a) R[a] = 0
  1392.         };
  1393.         d.render = function() {
  1394.             if (U) {
  1395.                 h.scaleSmoothing(s, false);
  1396.                 q = B[0];
  1397.                 0 == (q & 2147483648) && (B[0] = q |= 2147483648, B[2] = C << 16 | w);
  1398.                 var k = B[1],
  1399.                     n = k >>> 16 & 65535,
  1400.                     k = k & 65535;
  1401.                 if (0 == (q & 134217728)) F && (q |= 536870912), F = false;
  1402.                 else if (W) {
  1403.                     var t = +new Date;
  1404.                     Q += t - V;
  1405.                     Q >= W && (Q = 0, F = !F, q |= 536870912);
  1406.                     V = t
  1407.                 } else F || (q |= 536870912), F = true;
  1408.                 if (0 != (q & 1610612736)) {
  1409.                     q &= -536870913;
  1410.                     t = q >>> 16 & 15;
  1411.                     H = q >>> 12 & 15;
  1412.                     L = q >>> 8 & 15;
  1413.                     I = q >>> 4 & 15;
  1414.                     J = q & 15;
  1415.                     v = (k + n * w >> 1) + G;
  1416.                     0 != (q & 268435456) != l ? (E = t, d.setScanLines(q & 268435456)) : t != E && (E = t, viewport.parentElement.style.backgroundColor = l ? f[E] : g[E]);
  1417.                     s.globalCompositeOperation = "source-over";
  1418.                     s.globalAlpha = 1;
  1419.                     for (var z = t = 0, y = 0, x = 0, S = 0, O = 0, P = 0, K = 0, y = G; y <= T; ++y) {
  1420.                         x = B[y];
  1421.                         if (x == R[K] && y != v && y != A) {
  1422.                             if (++K, t += 9, t >= e && (z += 16, t = 0, z >= c)) break
  1423.                         } else {
  1424.                             R[K++] = x;
  1425.                             O = x >> 8 & 15;
  1426.                             S = x >> 12 & 15;
  1427.                             P = x & 255;
  1428.                             chx = P & 31;
  1429.                             chy = P >> 5 & 7;
  1430.                             s.fillStyle = D[S];
  1431.                             s.fillRect(t, z, 9, 16);
  1432.                             s.drawImage(N[O], 2 + 12 * chx, 2 + 19 * chy, 9, 16, t, z, 9, 16);
  1433.                             t += 9;
  1434.                             if (t >= e && (z += 16, t = 0, z >= c)) break;
  1435.                             x >>>= 16;
  1436.                             O = x >> 8 & 15;
  1437.                             S = x >> 12 & 15;
  1438.                             P = x & 255;
  1439.                             chx = P & 31;
  1440.                             chy = P >> 5 & 7;
  1441.                             s.fillStyle = D[S];
  1442.                             s.fillRect(t, z, 9, 16);
  1443.                             s.drawImage(N[O], 2 + 12 * chx, 2 + 19 * chy, 9, 16, t, z, 9, 16)
  1444.                         }
  1445.                         t += 9;
  1446.                         if (t >= e && (z += 16, t = 0, z >= c)) break
  1447.                     }
  1448.                     A = v;
  1449.                     F && (k < w && n < C) && (x = B[v], k & 1 && (x >>>= 16), O = x >> 8 & 15, 9 > H && (0 < J && 0 < I) && (9 < H + I && (I = 9 - H), 16 < L + J && (J = 16 - L), s.fillStyle = D[O], s.fillRect(9 * k + H, (n << 4) + L, I, J)));
  1450.                     1 < b && (h.scaleSmoothing(m, false), m.globalAlpha = 1, m.globalCompositeOperation = "source-over", m.drawImage(u, 0, 0, e, c, 0, 0, p, r), l && null != X && (m.fillStyle = X, m.fillRect(0, 0, p, r), m.globalCompositeOperation = "lighter", h.scaleSmoothing(m, true), m.globalAlpha = 0.5, m.drawImage(a, 0, 0, p, r, 1.5, 0, p, r), m.drawImage(a, 0, 0, p, r, -0.25, 1, p, r)));
  1451.                     B[0] = q
  1452.                 }
  1453.             }
  1454.         };
  1455.         var K = [],
  1456.             N = null,
  1457.             X = null,
  1458.             Y = new h.ImageLoader("img/", function(a, b, c, d) {
  1459.                 if (b) {
  1460.                     if (h.log("Loaded texture #" + d + " from: " + c), K[d] = a, Y.count == Y.loaded) {
  1461.                         b = document.createElement("canvas");
  1462.                         K[0] = b;
  1463.                         b.width = 64;
  1464.                         b.height = 64;
  1465.                         c = b.getContext("2d");
  1466.                         c.fillStyle = "#000";
  1467.                         c.globalAlpha = 1;
  1468.                         h.scaleSmoothing(c, false);
  1469.                         for (d = 1; 64 > d; d += 2) c.fillRect(0, d, 64, 1);
  1470.                         X = c.createPattern(b, "repeat");
  1471.                         n(a, l ? k : g);
  1472.                         h.log("Display ready.");
  1473.                         U = true
  1474.                     }
  1475.                 } else h.log("Could not load texture #" + d + " from: " + c)
  1476.             });
  1477.         Y.queue("sc-font-9x16.png", 1);
  1478.         viewport.parentElement.style.backgroundColor = l && 1 < b ? f[E] : g[E];
  1479.         d.toString = function() {
  1480.             return "TextDisplay"
  1481.         }
  1482.     }
  1483. };
  1484. new function() {
  1485.     var h = System;
  1486.     h.onInit(function() {
  1487.         try {
  1488.             h.log = function(a) {
  1489.                 console.log(a)
  1490.             };
  1491.             var g = new h.Environment,
  1492.                 k = g.build(2097152),
  1493.                 f = new h.Protocol;
  1494.             f.pos = 0;
  1495.             f.size = 64;
  1496.             f.direct = true;
  1497.             g.support(f);
  1498.             var a = new h.Protocol;
  1499.             a.pos = f.size;
  1500.             a.size = 16384;
  1501.             a.direct = true;
  1502.             g.support(a);
  1503.             var e = document.getElementById("viewport"),
  1504.                 c = true,
  1505.                 b = new h.InputDevice(function(a) {
  1506.                     c || (0 <= a && (cycleDelay = -g.cycle(k, 32768), l.render()), 0 > cycleDelay && (c = true))
  1507.                 }),
  1508.                 l;
  1509.             1440 <= e.offsetParent.offsetWidth + 4 && 800 <= e.offsetParent.offsetHeight + 4 ? (l = new h.TextDisplay(e, 720, 400, 2, false), b.setScale(1)) : (l = new h.TextDisplay(e, 720, 400, 1, false), b.setScale(2));
  1510.             window.setScanLines = l.setScanLines;
  1511.             var n = g.register(l);
  1512.             g.connect(k, a.id, n);
  1513.             var d = g.register(b);
  1514.             g.connect(k, f.id, d);
  1515.             var p = a.pos + a.size + 1023 & 268434432,
  1516.                 f = [<snip - bootloader?>];
  1517.             g.load(k, f, p);
  1518.             g.init(k, p, p + (f.length << 2), 0, 0, 0, 0);
  1519.             c = false
  1520.         } catch (r) {
  1521.             if ("number" == typeof r) throw g.explain(r);
  1522.             throw "boot: " + r.toString() + ": line " + r.lineNumber + ": " + r.fileName;
  1523.         }
  1524.         h.phase = b
  1525.     });
  1526.     h.start({
  1527.         canvas: "viewport",
  1528.         realtime: true
  1529.     })
  1530. };
clone this paste RAW Paste Data
Top