Browse Source

Added commandline options

Right now, it only has options for passing in the ROM to play, but the
framework for adding other flags later is there.
Chris Konstad 4 years ago
parent
commit
68cf1d97cb
4 changed files with 63 additions and 2 deletions
  1. 39 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 1 1
      README.md
  4. 22 1
      src/main.rs

+ 39 - 0
Cargo.lock

@ -2,6 +2,7 @@
2 2
name = "chip8"
3 3
version = "0.1.0"
4 4
dependencies = [
5
 "clap 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
5 6
 "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
6 7
 "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
7 8
 "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
@ -17,11 +18,34 @@ dependencies = [
17 18
]
18 19

													
19 20
[[package]]
21
name = "ansi_term"
22
version = "0.7.2"
23
source = "registry+https://github.com/rust-lang/crates.io-index"
24

													
25
[[package]]
26
name = "bitflags"
27
version = "0.5.0"
28
source = "registry+https://github.com/rust-lang/crates.io-index"
29

													
30
[[package]]
20 31
name = "bitflags"
21 32
version = "0.6.0"
22 33
source = "registry+https://github.com/rust-lang/crates.io-index"
23 34

													
24 35
[[package]]
36
name = "clap"
37
version = "2.4.0"
38
source = "registry+https://github.com/rust-lang/crates.io-index"
39
dependencies = [
40
 "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
41
 "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
42
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
43
 "strsim 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
44
 "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
45
 "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
46
]
47

													
48
[[package]]
25 49
name = "env_logger"
26 50
version = "0.3.3"
27 51
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -180,6 +204,11 @@ dependencies = [
180 204
]
181 205

													
182 206
[[package]]
207
name = "strsim"
208
version = "0.4.1"
209
source = "registry+https://github.com/rust-lang/crates.io-index"
210

													
211
[[package]]
183 212
name = "thread-id"
184 213
version = "2.0.0"
185 214
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -197,11 +226,21 @@ dependencies = [
197 226
]
198 227

													
199 228
[[package]]
229
name = "unicode-width"
230
version = "0.1.3"
231
source = "registry+https://github.com/rust-lang/crates.io-index"
232

													
233
[[package]]
200 234
name = "utf8-ranges"
201 235
version = "0.1.3"
202 236
source = "registry+https://github.com/rust-lang/crates.io-index"
203 237

													
204 238
[[package]]
239
name = "vec_map"
240
version = "0.6.0"
241
source = "registry+https://github.com/rust-lang/crates.io-index"
242

													
243
[[package]]
205 244
name = "winapi"
206 245
version = "0.2.6"
207 246
source = "registry+https://github.com/rust-lang/crates.io-index"

+ 1 - 0
Cargo.toml

@ -12,6 +12,7 @@ name = "chip8"
12 12
path = "src/main.rs"
13 13

													
14 14
[dependencies]
15
clap = "*"
15 16
env_logger = "0.3"
16 17
log = "0.3"
17 18
rand = "0.3"

+ 1 - 1
README.md

@ -2,7 +2,7 @@
2 2
[x] Get keyboard input working
3 3
[x] Get sound working
4 4
[x] Clean up code
5
[ ] Add command line flags for options
5
[x] Add command line flags for options
6 6
[ ] Add documentation
7 7
[ ] Write blog article
8 8
[ ] Move sound to SDL

+ 22 - 1
src/main.rs

@ -1,9 +1,11 @@
1
extern crate clap;
1 2
extern crate libchip8;
2 3
#[macro_use]
3 4
extern crate log;
4 5
extern crate env_logger;
5 6
extern crate sdl2;
6 7

													
8
use clap::{Arg, App};
7 9
use libchip8::Chip8;
8 10
use sdl2::event::Event;
9 11
use sdl2::keyboard::{Keycode, KeyboardState, Scancode};
@ -39,12 +41,31 @@ fn check_keys(chip : &mut Chip8, kb : &KeyboardState) {
39 41
    chip.key[0xF] = kb.is_scancode_pressed(Scancode::F) as u8;
40 42
}
41 43

													
44
fn version() -> &'static str {
45
    concat!(env!("CARGO_PKG_VERSION_MAJOR"),
46
    ".",
47
    env!("CARGO_PKG_VERSION_MINOR"),
48
    ".",
49
    env!("CARGO_PKG_VERSION_PATCH")
50
    )
51
}
52

													
42 53
fn main() {
43 54
    env_logger::init().unwrap();
55

													
56
    let matches = App::new("Chip8 Emulator")
57
        .version(version())
58
        .author("Chris Konstad <chriskon149@gmail.com>")
59
        .about("Runs Chip8 games.")
60
        .arg(Arg::with_name("ROM")
61
             .help("Sets the path to the ROM to play")
62
             .required(true))
63
        .get_matches();
64

													
44 65
    println!("Chip8 emulator starting...");
45 66

													
46 67
    // Initialize the emulator and load the game
47
    let path = Path::new("PONG");
68
    let path = Path::new(matches.value_of("ROM").unwrap());
48 69
    let display = path.display();
49 70

													
50 71
    let mut chip = Chip8::new();