|
| 1 | +use graphics::PPU; |
1 | 2 | use opcodes::emulate_cycle; |
2 | 3 | use processor::CPU; |
3 | 4 | use sfml::{ |
4 | 5 | graphics::{Color, RenderTarget, RenderWindow}, |
5 | 6 | window::{Event, Style}, |
6 | 7 | }; |
| 8 | +use std::io; |
7 | 9 | use std::io::prelude::*; |
| 10 | +use std::process::exit; |
8 | 11 | mod graphics; |
9 | | -mod processor; |
10 | | -use graphics::PPU; |
11 | 12 | mod keypad; |
12 | 13 | mod opcodes; |
13 | | -use std::process::exit; |
14 | | -fn main() { |
15 | | - let mut window = RenderWindow::new((640, 320), "Rusty Chip", Style::CLOSE, &Default::default()); |
| 14 | +mod processor; |
16 | 15 |
|
| 16 | +fn main() { |
17 | 17 | let mut cpu: CPU = CPU::new(); |
18 | 18 | let mut ppu: PPU = PPU::new(); |
19 | 19 | let mut gae: [u8; 4096] = [0; 4096]; |
20 | | - let mut file_in = std::fs::File::open("./roms/delay").unwrap(); |
21 | | - file_in.read(&mut gae).unwrap(); |
| 20 | + |
| 21 | + println!("Selectati ce joc doriti sa jucati din lista de mai jos:"); |
| 22 | + println!("1. Tetris"); |
| 23 | + println!("2. Brix"); |
| 24 | + println!("3. Pong"); |
| 25 | + println!("4. Merlin"); |
| 26 | + println!("5. KaleID"); |
| 27 | + //let mut path = String::new(); |
| 28 | + let mut game = String::new(); |
| 29 | + |
| 30 | + io::stdin() |
| 31 | + .read_line(&mut game) |
| 32 | + .expect("Failed to read line"); |
| 33 | + let game: u32 = game |
| 34 | + .trim() |
| 35 | + .parse() |
| 36 | + .expect("Caracterul introdus nu este valid"); |
| 37 | + |
| 38 | + if game == 1 { |
| 39 | + println!("Doriti instructiuni pentru joc? [D / N]"); |
| 40 | + let mut instructiuni = String::new(); |
| 41 | + io::stdin() |
| 42 | + .read_line(&mut instructiuni) |
| 43 | + .expect("Failed to read line"); |
| 44 | + |
| 45 | + if instructiuni.chars().nth(0).expect("idfk") == 'D' |
| 46 | + || instructiuni.chars().nth(0).expect("idfk") == 'd' |
| 47 | + { |
| 48 | + println!("Q - Roteste Piesa\nW si E - Deplaseaza piesa stanga-dreapta"); |
| 49 | + println!("Apasati Enter pentru a juca"); |
| 50 | + let mut any = String::new(); |
| 51 | + io::stdin() |
| 52 | + .read_line(&mut any) |
| 53 | + .expect("Failed to read line"); |
| 54 | + } |
| 55 | + |
| 56 | + let mut file_in = std::fs::File::open("./roms/tetris").unwrap(); |
| 57 | + file_in.read(&mut gae).unwrap(); |
| 58 | + } else if game == 2 { |
| 59 | + println!("Doriti instructiuni pentru joc? [D / N]"); |
| 60 | + let mut instructiuni = String::new(); |
| 61 | + io::stdin() |
| 62 | + .read_line(&mut instructiuni) |
| 63 | + .expect("Failed to read line"); |
| 64 | + |
| 65 | + if instructiuni.chars().nth(0).expect("idfk") == 'D' |
| 66 | + || instructiuni.chars().nth(0).expect("idfk") == 'd' |
| 67 | + { |
| 68 | + println!("Q si E - Deplaseaza paleta stanga-dreapta"); |
| 69 | + println!("Apasati Enter pentru a juca"); |
| 70 | + let mut any = String::new(); |
| 71 | + io::stdin() |
| 72 | + .read_line(&mut any) |
| 73 | + .expect("Failed to read line"); |
| 74 | + } |
| 75 | + |
| 76 | + let mut file_in = std::fs::File::open("./roms/brix").unwrap(); |
| 77 | + file_in.read(&mut gae).unwrap(); |
| 78 | + } else if game == 3 { |
| 79 | + println!("Doriti instructiuni pentru joc? [D / N]"); |
| 80 | + let mut instructiuni = String::new(); |
| 81 | + io::stdin() |
| 82 | + .read_line(&mut instructiuni) |
| 83 | + .expect("Failed to read line"); |
| 84 | + |
| 85 | + if instructiuni.chars().nth(0).expect("idfk") == 'D' |
| 86 | + || instructiuni.chars().nth(0).expect("idfk") == 'd' |
| 87 | + { |
| 88 | + println!("1 si Q - Deplaseaza paleta din stanga sus-jos"); |
| 89 | + println!("4 si R - Deplaseaza paleta din dreapta sus-jos"); |
| 90 | + println!("Apasati Enter pentru a juca"); |
| 91 | + let mut any = String::new(); |
| 92 | + io::stdin() |
| 93 | + .read_line(&mut any) |
| 94 | + .expect("Failed to read line"); |
| 95 | + } |
| 96 | + |
| 97 | + let mut file_in = std::fs::File::open("./roms/pong").unwrap(); |
| 98 | + file_in.read(&mut gae).unwrap(); |
| 99 | + } else if game == 4 { |
| 100 | + println!("Doriti instructiuni pentru joc? [D / N]"); |
| 101 | + let mut instructiuni = String::new(); |
| 102 | + io::stdin() |
| 103 | + .read_line(&mut instructiuni) |
| 104 | + .expect("Failed to read line"); |
| 105 | + |
| 106 | + if instructiuni.chars().nth(0).expect("idfk") == 'D' |
| 107 | + || instructiuni.chars().nth(0).expect("idfk") == 'd' |
| 108 | + { |
| 109 | + println!("Q - Apasa Butonul din coltul stanga-sus"); |
| 110 | + println!("W - Apasa Butonul din coltul dreapta-sus"); |
| 111 | + println!("A - Apasa Butonul din coltul stanga-jos"); |
| 112 | + println!("S - Apasa Butonul din coltul dreapta-jos"); |
| 113 | + |
| 114 | + println!("Apasati Enter pentru a juca"); |
| 115 | + let mut any = String::new(); |
| 116 | + io::stdin() |
| 117 | + .read_line(&mut any) |
| 118 | + .expect("Failed to read line"); |
| 119 | + } |
| 120 | + let mut file_in = std::fs::File::open("./roms/merlin").unwrap(); |
| 121 | + file_in.read(&mut gae).unwrap(); |
| 122 | + } else if game == 5 { |
| 123 | + println!("Doriti instructiuni pentru joc? [D / N]"); |
| 124 | + let mut instructiuni = String::new(); |
| 125 | + io::stdin() |
| 126 | + .read_line(&mut instructiuni) |
| 127 | + .expect("Failed to read line"); |
| 128 | + |
| 129 | + if instructiuni.chars().nth(0).expect("idfk") == 'D' |
| 130 | + || instructiuni.chars().nth(0).expect("idfk") == 'd' |
| 131 | + { |
| 132 | + println!("Demo de generare a unor pattern-uri simetrice"); |
| 133 | + println!("Q si E - Deplasarea liniei stanga-dreapta"); |
| 134 | + println!("2 si S - Deplasarea liniei sus-jos"); |
| 135 | + println!("Apasati Enter pentru a juca"); |
| 136 | + let mut any = String::new(); |
| 137 | + io::stdin() |
| 138 | + .read_line(&mut any) |
| 139 | + .expect("Failed to read line"); |
| 140 | + } |
| 141 | + let mut file_in = std::fs::File::open("./roms/kaleid").unwrap(); |
| 142 | + file_in.read(&mut gae).unwrap(); |
| 143 | + } else { |
| 144 | + panic!("Numarul introdus nu este valid, introduce-ti un numar de la 1 la 5"); |
| 145 | + //do a repetition |
| 146 | + } |
| 147 | + // for argument in env::args() { |
| 148 | + // println!("{}", argument); |
| 149 | + // //path = argument; |
| 150 | + // } |
| 151 | + |
22 | 152 | // print!("{}", z); |
23 | 153 |
|
24 | 154 | for i in 0..4096 { |
25 | 155 | cpu.ram[0x200 + i] = gae[i]; |
26 | 156 | } |
| 157 | + let mut window = RenderWindow::new((640, 320), "Rusty Chip", Style::CLOSE, &Default::default()); |
27 | 158 |
|
28 | 159 | window.set_framerate_limit(60); |
29 | 160 |
|
|
0 commit comments