index.html
<!DOCTYPE html>
<html>
<head>
    <title>Amstrad Game Selector</title>
    <style>
        /* Reset some basic elements for consistency */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        /* Body Styling */
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            min-height: 100vh;
            padding: 20px;
        }

        /* Container for Input Elements */
        .input-container {
            background-color: #ffffff;
            padding: 30px 40px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 500px;
            width: 100%;
            margin-bottom: 30px;
        }

        /* Heading Styling */
        .input-container h2 {
            margin-bottom: 20px;
            color: #333333;
            font-size: 24px;
        }

        /* Input Field Styling */
        .input-container input[type="text"] {
            width: 100%;
            padding: 12px 20px;
            margin: 10px 0;
            border: 2px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }

        .input-container input[type="text"]:focus {
            border-color: #007bff;
            outline: none;
        }

        /* Button Styling */
        .input-container button {
            padding: 12px 24px;
            margin-top: 10px;
            font-size: 16px;
            color: #ffffff;
            background-color: #007bff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease, transform 0.2s ease;
            width: 100%;
            max-width: 200px;
        }

        .input-container button:hover {
            background-color: #0056b3;
            transform: translateY(-2px);
        }

        .input-container button:active {
            transform: translateY(0);
        }

        /* Emulator iframe Styling */
        iframe#index2Frame {
            width: 100%;
            max-width: 1000px;
            height: 600px;
            border: none;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        /* Responsive Design */
        @media (max-width: 1024px) {
            iframe#index2Frame {
                height: 500px;
            }
        }

        @media (max-width: 768px) {
            .input-container {
                padding: 20px 30px;
            }

            iframe#index2Frame {
                height: 400px;
            }
        }

        @media (max-width: 480px) {
            .input-container {
                padding: 15px 20px;
            }

            .input-container h2 {
                font-size: 20px;
            }

            .input-container input[type="text"],
            .input-container button {
                font-size: 14px;
                padding: 10px 16px;
            }

            iframe#index2Frame {
                height: 300px;
            }
        }
    </style>
</head>
<body>
    <div class="input-container">
        <h2>Enter Amstrad Game Command</h2>
        <input 
            type="text" 
            id="customInput" 
            placeholder='Enter command (e.g., run"yourgame)' 
            onkeypress="handleKeyPress(event)"
        >
        <button onclick="updateIframe()">Start Game</button>
    </div>
    
    <!-- Emulator iframe -->
    <iframe 
        id="index2Frame" 
        src="index2.html?testinput" 
        sandbox="allow-scripts allow-same-origin"
        title="Amstrad Emulator"
    ></iframe>
    
    <script>
        /**
         * Updates the iframe src based on user input for param2.
         * If no input is provided, defaults to 'run"bomber3'.
         * After updating, it emulates a "hello world" keystroke sequence within the iframe.
         */
        function updateIframe() {
            const customInput = document.getElementById('customInput').value.trim();
            const param1 = 'sp2.dsk'; // Fixed disk file parameter
            const param2 = customInput || 'run"bomber3'; // Defaults to 'run"bomber3' if empty

            // Encode parameters to ensure they're URL-safe
            const encodedParam1 = encodeURIComponent(param1);
            const encodedParam2 = encodeURIComponent(param2);

            const iframeSrc = `index2.html?param1=${encodedParam1}&param2=${encodedParam2}`;
            const iframe = document.getElementById('index2Frame');

            // Remove any existing onload handlers to prevent multiple triggers
            iframe.onload = null;

            // Set the onload handler to emulate "hello world" keystrokes after the iframe loads
            iframe.onload = function() {
                try {
                    const iframeWindow = iframe.contentWindow;
                    const iframeDocument = iframe.contentDocument || iframeWindow.document;

                    // Focus the iframe to ensure it can receive messages
                    iframeWindow.focus();

                    // Define the message to send
                    const message = {
                        type: 'typeHelloWorld',
                        payload: 'hello world'
                    };

                    // Send the message to the iframe
                    iframeWindow.postMessage(message, '*'); // Replace '*' with specific origin for better security

                    console.log('"hello world" message sent to the emulator.');
                } catch (error) {
                    console.error('Error sending "hello world" message:', error);
                }
            };

            // Update the iframe src, triggering the onload event
            iframe.src = iframeSrc;
        }

        /**
         * Handles the Enter key press within the input field to trigger iframe update.
         * @param {KeyboardEvent} event 
         */
        function handleKeyPress(event) {
            if (event.key === 'Enter') {
                event.preventDefault(); // Prevent form submission or other default actions
                updateIframe();
            }
        }
    </script>
</body>
</html>

index2.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Striker In The Crypt Of Trojan</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
        /* Basic styling for the emulator input */
        #emulatorInput {
            width: 80%;
            padding: 10px;
            font-size: 16px;
            margin-top: 20px;
            border: 2px solid #ccc;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <!-- Emulator Input Field -->
    <input type="text" id="emulatorInput" autofocus placeholder="Emulator Input"/>

    <script type="text/javascript">
        // Existing Emulator Code
        let ie = 0;
        let pb = [];
        let param2 = pbf = pbt = frc = game = t = u = 0;

        function cb(b, c) {
            if (c === 1)
                emul = b;
            else
                game = b;
            if (c === 3)
                document.write(game);
            else if (!t--)
                this.eval(emul.substr(311365));
            else if (c === 2) {
                let k = b.indexOf('\0');
                let ci = b.length;
                frc = bp = k + 1;
                while (bp < ci)
                    pbf += (ap = b.charCodeAt(--ci)), ap !== 255 && bp++;
                while (ci < b.length)
                    ap = b.charCodeAt(ci++), pb[pbt++] = ap === 255 ? ap : ap | b.charCodeAt(frc++) << 8;
                frc = pb[0] & 255;
                let param = b.substr(0, k);
                let paramParts = param.split('/');
                let param1 = paramParts[0];
                param2 = paramParts[1] ? decodeURIComponent(paramParts[1]) : ''; // Decoding param2
                ajax(
                    (param1.slice(-1) === 'a' ? 'snaps/' : 'games/') + param1, 
                    0
                );
            }
        }

        function ajax(f, g, h) {
            let xhr = new XMLHttpRequest();
            if (g < 0) {
                xhr.onreadystatechange = function() {
                    if (xhr && xhr.readyState === 4)
                        rt(ie ? bin2arr(xhr.responseBody) : bin2str(xhr.responseText));
                };
            } else {
                xhr.onreadystatechange = function() {
                    if (xhr && xhr.readyState === 4)
                        cb(ie ? bin2arr(xhr.responseBody) : bin2str(xhr.responseText), h);
                };
            }
            xhr.open(g ? 'POST' : 'GET', f, true);
            if (!ie)
                xhr.overrideMimeType('text/plain;charset=x-user-defined');
            xhr.send(g);
        }

        function bin2str(a) {
            return a.replace(/[\s\S]/g, function(t) {
                return String.fromCharCode(t.charCodeAt(0) & 255);
            });
        }

        function bin2arr(a) {
            return arr(a).replace(/[\s\S]/g, function(t) {
                let v = t.charCodeAt(0);
                return String.fromCharCode(v & 0xff, v >> 8);
            }) + arrl(a);
        }

        let k = location.href.indexOf('?') + 1;
        let ifra = location.href.slice(-1) === '#';

        let param1 = 'sp2.dsk';
        let fullUrl = window.location.href;
        let lastEqualIndex = fullUrl.lastIndexOf('=');
        param2 = lastEqualIndex !== -1 ? decodeURIComponent(fullUrl.slice(lastEqualIndex + 1)) : ''; // Decoding param2 from URL
        t++;
        ajax('' + param1, 0);

        ajax('_6128s.rom', 0, 1);

        // Existing Emulator Code Continued...
        // [Omitted for brevity. Ensure all existing emulator functions and variables remain intact.]

        // -----------------------------------------------------------------
        // Below are the additions to handle simulated keystrokes
        // -----------------------------------------------------------------

        /**
         * Handles incoming messages from the parent iframe (index.html)
         */
        window.addEventListener('message', function(event) {
            // Optional: Verify the origin of the message for security
            // if (event.origin !== "http://yourdomain.com") return;

            const { type, payload } = event.data;

            // Check if the message type is 'typeHelloWorld'
            if (type === 'typeHelloWorld') {
                const text = payload;
                simulateTyping(text);
            }

            // You can handle more message types here if needed
        }, false);

        /**
         * Simulates typing of the provided text by inserting it into the emulator input field
         * @param {string} text - The text to simulate typing
         */
        function simulateTyping(text) {
            const input = document.getElementById('emulatorInput');
            if (!input) {
                console.error('Emulator input field not found!');
                return;
            }

            // Clear any existing text if needed
            input.value = '';

            // Append each character with a slight delay to mimic natural typing
            let index = 0;
            const typingDelay = 100; // milliseconds

            function typeCharacter() {
                if (index < text.length) {
                    const char = text[index];
                    input.value += char;
                    index++;
                    setTimeout(typeCharacter, typingDelay);
                } else {
                    console.log('"hello world" simulated typing completed.');
                }
            }

            typeCharacter();
        }
    </script>
</body>
</html>

remove input boxes so that only emulator is displayed taking up full screen