You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. extern crate sdl2;
  2. use sdl2::pixels::Color;
  3. use sdl2::render::Canvas;
  4. use clap::{App, Arg};
  5. use chip8::Chip8;
  6. struct SdlEmulator {
  7. w: usize,
  8. h: usize,
  9. zoom: usize,
  10. canvas: Canvas<sdl2::video::Window>,
  11. chip8: Chip8,
  12. }
  13. impl SdlEmulator {
  14. fn new(w: usize, h: usize, zoom: usize) -> SdlEmulator {
  15. let mut c = Chip8::new();
  16. let sdl_context = sdl2::init().unwrap();
  17. let video_subsystem = sdl_context.video().unwrap();
  18. let window = video_subsystem
  19. .window("rust-sdl2 demo", 800, 600)
  20. .position_centered()
  21. .build()
  22. .unwrap();
  23. let mut canvas = window.into_canvas().build().unwrap();
  24. SdlEmulator {
  25. w,
  26. h,
  27. zoom,
  28. canvas,
  29. chip8: c,
  30. }
  31. }
  32. fn draw_graphics(&mut self) {
  33. // TODO
  34. }
  35. fn set_keys(&mut self) {
  36. // TODO
  37. }
  38. }
  39. fn main() {
  40. let matches = App::new("chip8-rs")
  41. .version("0.0.1")
  42. .about("chip8 emulator")
  43. .arg(
  44. Arg::with_name("file")
  45. .short("f")
  46. .long("file")
  47. .takes_value(true)
  48. .help("File path of the rom to load"),
  49. )
  50. .get_matches();
  51. let file = matches.value_of("file");
  52. let file = match file {
  53. Some(file) => file,
  54. _ => panic!("Please specify file path of the rom to load"),
  55. };
  56. println!("{:?}", file);
  57. let mut e = SdlEmulator::new(64, 32, 8);
  58. loop {
  59. e.chip8.emulate_cycle();
  60. if e.chip8.draw_flag {
  61. e.draw_graphics();
  62. }
  63. e.set_keys();
  64. // delay
  65. }
  66. }