Skip to content

Instantly share code, notes, and snippets.

@sean3z
Last active December 30, 2022 00:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean3z/f5bdd4446b7baebbf0be90c0b48232dc to your computer and use it in GitHub Desktop.
Save sean3z/f5bdd4446b7baebbf0be90c0b48232dc to your computer and use it in GitHub Desktop.
Example CPU module
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