Skip to content

Commit 4638069

Browse files
committed
feat: add rom selector dropdown for github pages deployment
1 parent d13c098 commit 4638069

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

css/style.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ input[type="range"] {
9898
margin-left: 10px;
9999
}
100100

101+
select {
102+
padding: 8px 16px;
103+
border: 2px solid #007bff;
104+
border-radius: 5px;
105+
background: white;
106+
color: #333;
107+
font-size: 13px;
108+
font-weight: 600;
109+
cursor: pointer;
110+
transition: all 0.3s;
111+
}
112+
113+
select:hover {
114+
background: #f0f8ff;
115+
transform: translateY(-2px);
116+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
117+
}
118+
119+
select:focus {
120+
outline: none;
121+
border-color: #0056b3;
122+
}
123+
101124
.main-grid {
102125
display: grid;
103126
grid-template-columns: 640px 400px 1fr;

index.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,34 @@ <h1>CHIP-8 Emulator</h1>
2121
<button id="reset-btn" class="btn btn-danger">Reset</button>
2222
</div>
2323
<div class="controls-group">
24+
<select id="rom-select">
25+
<option value="">Select a ROM...</option>
26+
<option value="PONG">Pong</option>
27+
<option value="TETRIS">Tetris</option>
28+
<option value="INVADERS">Space Invaders</option>
29+
<option value="BRIX">Brix</option>
30+
<option value="BLITZ">Blitz</option>
31+
<option value="BLINKY">Blinky</option>
32+
<option value="CONNECT4">Connect 4</option>
33+
<option value="GUESS">Guess</option>
34+
<option value="HIDDEN">Hidden</option>
35+
<option value="KALEID">Kaleidoscope</option>
36+
<option value="MAZE">Maze</option>
37+
<option value="MERLIN">Merlin</option>
38+
<option value="MISSILE">Missile</option>
39+
<option value="PONG2">Pong 2</option>
40+
<option value="PUZZLE">Puzzle</option>
41+
<option value="15PUZZLE">15 Puzzle</option>
42+
<option value="SYZYGY">Syzygy</option>
43+
<option value="TANK">Tank</option>
44+
<option value="TICTAC">Tic Tac Toe</option>
45+
<option value="UFO">UFO</option>
46+
<option value="VBRIX">Vertical Brix</option>
47+
<option value="VERS">Vers</option>
48+
<option value="WIPEOFF">Wipe Off</option>
49+
</select>
2450
<label for="rom-input" class="btn btn-primary">
25-
Load ROM
51+
Load Custom ROM
2652
<input type="file" id="rom-input" style="display: none;">
2753
</label>
2854
</div>

js/emulator.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class Emulator {
2525
document.getElementById('step-btn').addEventListener('click', () => this.step());
2626
document.getElementById('reset-btn').addEventListener('click', () => this.reset());
2727

28-
document.getElementById('rom-input').addEventListener('change', (e) => this.loadROM(e));
28+
document.getElementById('rom-select').addEventListener('change', (e) => this.loadROMFromSelect(e));
29+
document.getElementById('rom-input').addEventListener('change', (e) => this.loadROMFromFile(e));
2930

3031
const speedSlider = document.getElementById('speed-slider');
3132
const speedValue = document.getElementById('speed-value');
@@ -35,7 +36,41 @@ class Emulator {
3536
});
3637
}
3738

38-
loadROM(event) {
39+
async loadROMFromSelect(event) {
40+
const romName = event.target.value;
41+
if (!romName) return;
42+
43+
try {
44+
const response = await fetch(`roms/${romName}`);
45+
if (!response.ok) {
46+
throw new Error(`Failed to load ROM: ${response.statusText}`);
47+
}
48+
49+
const buffer = await response.arrayBuffer();
50+
const program = new Uint8Array(buffer);
51+
52+
if (program.length === 0) {
53+
alert('Error: ROM file is empty');
54+
return;
55+
}
56+
57+
if (program.length > 4096 - 0x200) {
58+
alert(`Error: ROM too large (${program.length} bytes). Maximum is ${4096 - 0x200} bytes.`);
59+
return;
60+
}
61+
62+
this.reset();
63+
this.cpu.loadProgram(program);
64+
this.updateWidgets();
65+
66+
console.log(`ROM loaded successfully: ${romName} (${program.length} bytes)`);
67+
} catch (error) {
68+
alert(`Error loading ROM: ${error.message}`);
69+
console.error('ROM loading error:', error);
70+
}
71+
}
72+
73+
loadROMFromFile(event) {
3974
const file = event.target.files[0];
4075
if (!file) return;
4176

0 commit comments

Comments
 (0)