Chipvuelto8/index.html

103 lines
2.8 KiB
HTML
Raw Permalink Normal View History

2024-09-01 15:52:46 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chip 8 emulator Test</title>
<style>
body {
background-color: #000;
2024-09-02 21:20:00 +01:00
color: #EEE;
}
#emulator-screen{
border: 1px solid pink;
2024-09-01 15:52:46 +01:00
}
</style>
2024-09-02 21:20:00 +01:00
<script src="./dist/revuelto8ts.js"></script>
2024-09-01 15:52:46 +01:00
</head>
<body>
2024-09-02 21:20:00 +01:00
<h1>Chip 8 emulator</h1>
<!-- Original screen is 64x32 -->
2024-09-04 20:38:54 +01:00
<canvas id="emulator-screen" width="512" height="256"></canvas>
2024-09-02 21:20:00 +01:00
<script>
const emulator = new Revuelto8ts.Chip8Emulator();
2024-09-06 11:43:07 +01:00
const emulatorCanvas = document.getElementById('emulator-screen');
2024-09-04 20:38:54 +01:00
let fullDirRoms = [
'./roms/1-chip8-logo.ch8',
'./roms/2-ibm-logo.ch8',
'./roms/3-corax+.ch8',
'./roms/4-flags.ch8',
'./roms/5-quirks.ch8',
'./roms/6-keypad.ch8',
'./roms/7-beep.ch8',
'./roms/8-scrolling.ch8',
'./roms/Maze[David Winter, 199x].ch8',
2024-09-06 11:53:33 +01:00
'./roms/Airplane.ch8',
'./roms/Cave.ch8',
'./roms/Life [GV Samways, 1980].ch8',
'./roms/Pong (1 player).ch8',
'./roms/SQRT Test [Sergey Naydenov, 2010].ch8',
'./roms/Timebomb.ch8',
'./roms/Worm V4 [RB-Revival Studios, 2007].ch8'
2024-09-04 20:38:54 +01:00
];
2024-09-06 11:43:07 +01:00
// Set user keys
emulator.setUserKey('1'.charCodeAt(0), 1); // 1
emulator.setUserKey('2'.charCodeAt(0), 2); // 2
emulator.setUserKey('3'.charCodeAt(0), 3); // 3
emulator.setUserKey('4'.charCodeAt(0), 12); // C
emulator.setUserKey('q'.charCodeAt(0), 4); // 4
emulator.setUserKey('w'.charCodeAt(0), 5); // 5
emulator.setUserKey('e'.charCodeAt(0), 6); // 6
emulator.setUserKey('r'.charCodeAt(0), 13); // D
emulator.setUserKey('a'.charCodeAt(0), 7); // 7
emulator.setUserKey('s'.charCodeAt(0), 8); // 8
emulator.setUserKey('d'.charCodeAt(0), 9); // 9
emulator.setUserKey('f'.charCodeAt(0), 14); // E
emulator.setUserKey('z'.charCodeAt(0), 10); // A
emulator.setUserKey('x'.charCodeAt(0), 0); // 0
emulator.setUserKey('c'.charCodeAt(0), 11); // B
emulator.setUserKey('v'.charCodeAt(0), 15); // F
document.addEventListener("keydown", function(evt) {
emulator.keyDownEvent(evt.key.charCodeAt(0));
});
document.addEventListener("keyup", function(evt) {
emulator.keyUpEvent(evt.key.charCodeAt(0));
});
// Set audio
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
let volume = 0.02; // Volume between [1, 0] // Set it low if you don't want to become deaf
emulator.startAudio(audioContext, volume);
2024-09-04 20:38:54 +01:00
// Load ROM
2024-09-07 00:32:33 +01:00
fetch(fullDirRoms[4])
2024-09-02 21:20:00 +01:00
.then(response => response.arrayBuffer())
2024-09-04 20:38:54 +01:00
.then(arrayBufferRom => {
let romData = new Uint8Array(arrayBufferRom);
emulator.loadRom(romData);
2024-09-01 15:52:46 +01:00
});
2024-09-06 11:43:07 +01:00
2024-09-02 21:20:00 +01:00
2024-09-04 20:38:54 +01:00
setInterval(function() {
if(emulator.isRomLoaded()) {
2024-09-07 00:32:33 +01:00
//console.log(emulator.getCPUStatus());
2024-09-04 20:38:54 +01:00
emulator.emulateCycle();
emulator.drawToCanvas(emulatorCanvas, 8);
}
2024-09-07 00:32:33 +01:00
}, 3);
2024-09-02 21:20:00 +01:00
</script>
2024-09-01 15:52:46 +01:00
</body>
</html>