Skip to content

Commit c11acc7

Browse files
committed
include roms in binary
1 parent 3085d37 commit c11acc7

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/main.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use std::{
2-
fs::File,
3-
io::{self, Read},
4-
time::Duration,
5-
};
1+
use std::{io, time::Duration};
62

73
use chip8::{Chip8Emulator, SCREEN_WIDTH};
84
use clap::Parser;
@@ -27,7 +23,7 @@ struct Args {
2723
commands: Commands,
2824
}
2925
#[derive(Subcommand, Debug)]
30-
enum Commands {
26+
pub enum Commands {
3127
Pong,
3228
Guess,
3329
Maze,
@@ -41,25 +37,24 @@ pub struct App {
4137
}
4238

4339
fn main() -> io::Result<()> {
44-
let file_name = match Args::parse().commands {
45-
Commands::Pong => "PONG",
46-
Commands::Guess => "GUESS",
47-
Commands::Maze => "MAZE",
48-
};
40+
let command = Args::parse().commands;
4941
let mut terminal = ratatui::init();
50-
let app_result = App::new(file_name).run(&mut terminal);
42+
let app_result = App::new(command).run(&mut terminal);
5143
ratatui::restore();
5244
app_result
5345
}
5446

5547
impl App {
56-
pub fn new(file_name: &str) -> Self {
48+
pub fn new(command: Commands) -> Self {
49+
let pong = include_bytes!("./roms/PONG");
50+
let guess = include_bytes!("./roms/GUESS");
51+
let maze = include_bytes!("./roms/MAZE");
5752
let mut emulator = Chip8Emulator::new();
58-
let mut file = File::open(format!("./src/roms/{file_name}")).expect("Failed to open file");
59-
let mut buffer = Vec::new();
60-
file.read_to_end(&mut buffer)
61-
.expect("Failed to read GUESS file");
62-
emulator.load_data(&buffer);
53+
match command {
54+
Commands::Pong => emulator.load_data(pong),
55+
Commands::Guess => emulator.load_data(guess),
56+
Commands::Maze => emulator.load_data(maze),
57+
}
6358
App {
6459
emulator,
6560
exit: false,

0 commit comments

Comments
 (0)