Last active
December 30, 2022 00:36
-
-
Save sean3z/f5bdd4446b7baebbf0be90c0b48232dc to your computer and use it in GitHub Desktop.
Example CPU module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; | |
use std::fs::File; | |
use display::Display; | |
use keypad::Keypad; | |
pub struct Cpu { | |
program: usize, // program counter starts at 512 bytes | |
opcode: u16, // current opcode | |
stack: [u16; 16], // stack storage | |
stack_pointer: usize, // stack pointer | |
v: [u8; 16], // cpu registers (V0 through Ee) | |
i: usize, // index register | |
memory: [u8; 4096], // system memory | |
pub keypad: Keypad, // intercept keyboard calls | |
pub display: Display, // visualize on screen | |
} | |
impl Cpu { | |
pub fn new() -> Cpu { | |
Cpu { | |
program: 0x200, | |
opcode: 0, | |
stack: [0; 16], | |
stack_pointer: 0, | |
v: [0; 16], | |
i: 0x200, | |
memory: [0; 4096], | |
keypad: Keypad::new(), | |
display: Display::new(), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment