File size: 5,640 Bytes
89610f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>GBA.js Mobile Fixed</title>
<link rel="stylesheet" href="resources/main.css">
<style>
/* TOUCH CONTROL OVERLAY */
#touch-controls {
display: none; /* Only shows on mobile */
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 280px;
user-select: none;
-webkit-user-select: none;
touch-action: none;
z-index: 2147483647; /* Highest possible z-index */
}
.t-btn {
position: absolute;
background: rgba(255, 255, 255, 0.25);
border: 2px solid rgba(255, 255, 255, 0.4);
border-radius: 50%;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-family: sans-serif;
box-shadow: 0 4px 10px rgba(0,0,0,0.5);
touch-action: none;
}
/* Color change when pressed to confirm it works */
.t-btn:active {
background: rgba(0, 255, 0, 0.5) !important;
transform: scale(0.9);
}
/* D-PAD Positioning */
#t-up { bottom: 180px; left: 75px; width: 65px; height: 65px; }
#t-down { bottom: 50px; left: 75px; width: 65px; height: 65px; }
#t-left { bottom: 115px; left: 10px; width: 65px; height: 65px; }
#t-right { bottom: 115px; left: 140px; width: 65px; height: 65px; }
/* Action Buttons */
#t-a { bottom: 130px; right: 20px; width: 85px; height: 85px; background: rgba(255, 0, 0, 0.4); }
#t-b { bottom: 70px; right: 115px; width: 85px; height: 85px; background: rgba(255, 255, 0, 0.4); }
/* FIXED START/SELECT: Moved up and made larger */
.menu-btn {
width: 90px;
height: 45px;
border-radius: 10px;
font-size: 14px;
bottom: 90px; /* Moved up to avoid iOS home bar */
background: rgba(100, 100, 100, 0.6);
}
#t-select { left: 50%; margin-left: -100px; }
#t-start { left: 50%; margin-left: 10px; }
/* Show on mobile/touch screens */
@media (pointer: coarse) {
#touch-controls { display: block; }
#controls { padding-bottom: 300px; }
#screen { width: 100vw !important; height: auto !important; max-width: 480px; }
}
</style>
<script src="js/util.js"></script>
<script src="js/core.js"></script>
<script src="js/arm.js"></script>
<script src="js/thumb.js"></script>
<script src="js/mmu.js"></script>
<script src="js/io.js"></script>
<script src="js/audio.js"></script>
<script src="js/video.js"></script>
<script src="js/video/proxy.js"></script>
<script src="js/video/software.js"></script>
<script src="js/irq.js"></script>
<script src="js/keypad.js"></script>
<script src="js/sio.js"></script>
<script src="js/savedata.js"></script>
<script src="js/gpio.js"></script>
<script src="js/gba.js"></script>
<script src="resources/xhr.js"></script>
<script>
var gba;
var runCommands = [];
try {
gba = new GameBoyAdvance();
gba.keypad.eatInput = true;
} catch (exception) {
gba = null;
}
window.onload = function() {
if (gba && FileReader) {
var canvas = document.getElementById('screen');
gba.setCanvas(canvas);
loadRom('resources/bios.bin', function(bios) {
gba.setBios(bios);
});
initTouchGamepad();
}
}
function initTouchGamepad() {
// Direct mapping to GBA constants
const map = {
't-a': 0, 't-b': 1, 't-select': 2, 't-start': 3,
't-right': 4, 't-left': 5, 't-up': 6, 't-down': 7
};
Object.keys(map).forEach(id => {
const el = document.getElementById(id);
if (!el) return;
const keyCode = map[id];
const press = (e) => {
e.preventDefault();
// Explicitly resume audio for iOS
if (gba.audio.context && gba.audio.context.state === 'suspended') {
gba.audio.context.resume();
}
gba.keypad.keydown(keyCode);
console.log("Pressed: " + id); // Debugging
};
const release = (e) => {
e.preventDefault();
gba.keypad.keyup(keyCode);
};
// Passive: false is required to override browser scrolling
el.addEventListener('touchstart', press, {passive: false});
el.addEventListener('touchend', release, {passive: false});
el.addEventListener('mousedown', press);
el.addEventListener('mouseup', release);
});
}
function run(file) {
gba.loadRomFromFile(file, function(result) {
if (result) {
document.getElementById('preload').style.display = 'none';
document.getElementById('ingame').classList.remove('hidden');
gba.runStable();
}
});
}
function reset() {
gba.pause();
gba.reset();
gba.runStable();
}
function togglePause() {
var e = document.getElementById('pause');
if (gba.paused) { gba.runStable(); e.textContent = "PAUSE"; }
else { gba.pause(); e.textContent = "UNPAUSE"; }
}
</script>
</head>
<body>
<canvas id="screen" width="480" height="320"></canvas>
<div id="touch-controls">
<div class="t-btn" id="t-up">▲</div>
<div class="t-btn" id="t-down">▼</div>
<div class="t-btn" id="t-left">◀</div>
<div class="t-btn" id="t-right">▶</div>
<div class="t-btn" id="t-a">A</div>
<div class="t-btn" id="t-b">B</div>
<div class="t-btn menu-btn" id="t-select">SELECT</div>
<div class="t-btn menu-btn" id="t-start">START</div>
</div>
<section id="controls">
<div id="preload">
<button class="bigbutton" onclick="document.getElementById('loader').click()">SELECT ROM</button>
<input id="loader" type="file" accept=".gba" onchange="run(this.files[0]);" style="display:none;">
</div>
<div id="ingame" class="hidden">
<button id="pause" class="bigbutton" onclick="togglePause()">PAUSE</button>
<button class="bigbutton" onclick="reset()">RESET</button>
<button onclick="gba.downloadSavedata()">SAVE</button>
</div>
</section>
</body>
</html>
|