Certainly! To modify your setup so that only the emulator is displayed, taking up the full screen, you'll need to adjust both index.html and index2.html. Below are the detailed steps and updated code snippets to achieve this.
Overview of Changes
-
Remove Input Elements from index.html:
- Eliminate the input container that includes the text input and the button.
- Adjust the styling to allow the emulator iframe to occupy the entire viewport.
-
Adjust index2.html for Full-Screen Display:
- Remove or hide the emulator input field if it's not essential for emulator functionality.
- Ensure that the emulator scales correctly to fit the full screen.
-
Ensure Proper Communication (If Necessary):
- If your emulator relies on inter-frame communication (e.g., sending commands to the emulator), consider alternative methods such as URL parameters or server-side configurations since the input field will no longer be present.
1. Updated index.html
Changes Made:
- Removed the entire input container (
<div class="input-container">), which included the heading, text input, and button.
- Updated the CSS to make the iframe occupy the full viewport without any margins or padding.
<!DOCTYPE html>
<html>
<head>
<title>Amstrad Emulator</title>
<style>
/* Reset basic elements for consistency */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* Body Styling */
body {
font-family: Arial, sans-serif;
background-color: #000; /* Optional: Set to black for better emulator contrast */
display: flex;
align-items: center;
justify-content: center;
height: 100vh; /* Full viewport height */
width: 100vw; /* Full viewport width */
overflow: hidden; /* Prevent scrollbars */
}
/* Emulator iframe Styling */
iframe#index2Frame {
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<!-- Emulator iframe -->
<iframe
id="index2Frame"
src="index2.html?param1=sp2.dsk¶m2=run%22bomber3"
sandbox="allow-scripts allow-same-origin"
title="Amstrad Emulator"
></iframe>
</body>
</html>
Notes:
- Title Change: Updated the
<title> tag to "Amstrad Emulator" for clarity since the input elements are removed.
- Iframe Source (
src): Modified the src to include encoded URL parameters directly (param1=sp2.dsk¶m2=run"bomber3). Ensure that your index2.html can parse these parameters correctly.
- Removed Scripts: Since the input elements and related scripts are no longer needed, they have been removed to simplify the page.
2. Updated index2.html
Changes Made:
- Removed the emulator input field (
<input type="text" id="emulatorInput" />) to eliminate visible input boxes.
- Adjusted styles to ensure the emulator utilizes the full available space.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Amstrad Emulator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Ensure the emulator takes up the full screen */
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #000; /* Optional: Set to black for better emulator contrast */
}
/* Emulator Container Styling (Assuming Emulator is within a container) */
#emulatorContainer {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
/* If the emulator uses a canvas or other elements, ensure they scale */
canvas, #emulatorElement {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!-- Emulator Container -->
<div id="emulatorContainer">
<!-- Placeholder for Emulator -->
<!-- Replace this with your actual emulator's main element -->
<div id="emulatorElement">
<!-- Emulator content goes here -->
</div>
</div>
<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) {
// Assuming the emulator can receive input via keyboard events or another method
// If the emulator input field is removed, implement an alternative input method here
// Example: Dispatching keyboard events to the emulator element
const emulatorElement = document.getElementById('emulatorElement');
if (!emulatorElement) {
console.error('Emulator element not found!');
return;
}
emulatorElement.focus();
for (let char of text) {
const keyEvent = new KeyboardEvent('keypress', {
key: char,
char: char,
bubbles: true,
cancelable: true
});
emulatorElement.dispatchEvent(keyEvent);
}
console.log(`"${text}" simulated typing completed.`);
}
</script>
</body>
</html>
Key Modifications:
-
Removed Input Field:
- The
<input type="text" id="emulatorInput" autofocus placeholder="Emulator Input"/> has been removed to eliminate visible input boxes.
-
Adjusted Styles:
- Ensured that all elements within
index2.html consume the full viewport by setting width and height to 100%.
- Added a container (
#emulatorContainer) to encapsulate the emulator and make future styling easier.
- Removed or repurposed styles related to the input field.
-
Simulated Typing Mechanism:
- Important: Since the input field is removed, the
simulateTyping function has been updated to dispatch keyboard events directly to the emulator's main element (#emulatorElement). Ensure that your emulator can handle such events. If not, you might need to implement or adjust methods for input handling within the emulator.
-
Emulator Element Placeholder:
- Replaced the input field with a
<div id="emulatorElement"> which should be replaced with your actual emulator's main display element (like a <canvas> or specific emulator container).
Considerations:
-
Emulator Input Handling: Removing the input field means that the emulator should have alternative methods to receive user input. This could be through keyboard events, on-screen controls, or another interface. Ensure your emulator is set up to handle inputs appropriately without the text field.
-
Full-Screen Scaling: Depending on how your emulator scales, you might need to adjust additional styles or emulator settings to ensure it looks good on all screen sizes.
-
Security: If you continue to use postMessage for communication between index.html and index2.html, consider restricting the message target origin instead of using '*' to enhance security.
Final Thoughts
By following the above modifications, your setup will display only the emulator in full-screen mode without any additional input boxes or interfaces. Ensure that your emulator can receive and handle inputs appropriately through alternative methods now that the input fields are removed.
If you encounter any issues related to emulator functionality post these changes, you may need to dive deeper into the emulator's input handling mechanisms or adjust the communication protocols between index.html and index2.html accordingly.
Feel free to reach out if you need further assistance or encounter specific issues during the implementation!