Basic hello world, running the CPU
This commit is contained in:
+22
-14
@@ -16,7 +16,7 @@ use crate::cpu::CPU;
|
||||
use crate::memory::{Memory, PeekPoke};
|
||||
use crate::word::Word;
|
||||
use pixels::{Pixels, SurfaceTexture};
|
||||
use std::time::Instant;
|
||||
use std::time::{Instant, Duration};
|
||||
use winit::window::Window;
|
||||
|
||||
fn main() {
|
||||
@@ -42,12 +42,14 @@ fn main() {
|
||||
let memory = Memory::from(rng);
|
||||
let mut cpu = CPU::new(memory);
|
||||
display::reset(&mut cpu);
|
||||
for n in 0..128 {
|
||||
cpu.poke(Word::from(0x10000 + 128 * n), 0b11100000);
|
||||
cpu.poke(Word::from(0x10000 + n), 0xff);
|
||||
cpu.poke(Word::from(0x10000 + 128 * n + 127), 0b00000011);
|
||||
cpu.poke(Word::from(0x10000 + 128 * 127 + n), 0b00011100);
|
||||
}
|
||||
// for n in 0..128 {
|
||||
// cpu.poke(Word::from(0x10000 + 128 * n), 0b11100000);
|
||||
// cpu.poke(Word::from(0x10000 + n), 0xff);
|
||||
// cpu.poke(Word::from(0x10000 + 128 * n + 127), 0b00000011);
|
||||
// cpu.poke(Word::from(0x10000 + 128 * 127 + n), 0b00011100);
|
||||
// }
|
||||
cpu.poke_slice(Word::from(0x400), include_bytes!("gfx_test.rom"));
|
||||
cpu.start();
|
||||
window_loop(event_loop, window, pixels, cpu)
|
||||
}
|
||||
|
||||
@@ -60,17 +62,23 @@ fn window_loop(event_loop: EventLoop<()>, window: Window, mut pixels: Pixels, mu
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
||||
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::Resized(newSize),
|
||||
window_id
|
||||
} if window_id == window.id() => {
|
||||
pixels.resize_surface(newSize.width, newSize.height);
|
||||
}
|
||||
|
||||
Event::MainEventsCleared => {
|
||||
let start = Instant::now();
|
||||
draw(pixels.get_frame(), &mut cpu);
|
||||
let draw_time = Instant::now() - start;
|
||||
pixels.render().expect("Problem displaying framebuffer");
|
||||
let total_time = Instant::now() - start;
|
||||
println!(
|
||||
"Tick took {} total, {} to draw",
|
||||
total_time.as_micros(),
|
||||
draw_time.as_micros()
|
||||
);
|
||||
while Instant::now() < start + Duration::from_millis(25) {
|
||||
for _ in 1..1000 {
|
||||
cpu.tick()
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user