GithubHelp home page GithubHelp logo

Comments (1)

has12zen avatar has12zen commented on June 29, 2024
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Debian Emulator</title>
    <script src="./emulator/libv86-debug.js"></script>
</head>
<body>
    <div id="screen_container">
        <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
        <canvas style="display: none"></canvas>
    </div>

    <div>
        <input type="text" id="code_input" placeholder="Type your code here" style="width: 400px;">
        <button id="run_button">Run</button>
    </div>

    <div>
        <pre id="status">Wait for boot...</pre>
        <pre id="output"></pre>
    </div>

    <script>
    "use strict";

    window.onload = function() {
        var emulator = new V86({
            wasm_path: "./emulator/v86-debug.wasm",
            memory_size: 512 * 1024 * 1024,
            vga_memory_size: 8 * 1024 * 1024,
            screen_container: document.getElementById("screen_container"),
            initial_state: { url: "./debina/debian-state-base.bin" },
            filesystem: { baseurl: "./debina/debian-9p-rootfs-flat/" },
            autostart: true,
            disable_keyboard: true,
            disable_mouse: true,
        });

        var data = "";
        var do_output = false;

        emulator.add_listener("serial0-output-byte", function(byte) {
            var char = String.fromCharCode(byte);
            if(char !== "\r") {
                data += char;
            }

            if(do_output) {
                document.getElementById("output").textContent += char;
            }

            if(data.endsWith("~# ")) {
                console.log("Now ready");
                document.getElementById("status").textContent = "Ready.\n";
                document.getElementById("run_button").disabled = false;
                do_output = false;
            }
        });

        document.getElementById("code_input").onkeydown = function(e) {
            if(e.which == 13 && e.ctrlKey) {
                document.getElementById("run_button").onclick();
            }
        };

        document.getElementById("run_button").onclick = function() {
            var code = document.getElementById("code_input").value;
            emulator.serial0_send(bashEscape(code) + "\n");
            document.getElementById("output").textContent = "";
            document.getElementById("status").textContent = "Running ...\n";
            this.disabled = true;
            do_output = true;
        };
    };

    function bashEscape(arg) {
        arg = arg.replace(/\t+/g, "");
        return "'" + arg.replace(/'+/g, function (val) {
            return "'" + val.replace(/'/g, "\\'") + "'";
        }) + "'";
    }
    </script>
</body>
</html>

this worked.

from v86.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.