Skip to content

Instantly share code, notes, and snippets.

@romatthe
Created August 25, 2022 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romatthe/d466f276c77aa57fdcd0b6bfe2811426 to your computer and use it in GitHub Desktop.
Save romatthe/d466f276c77aa57fdcd0b6bfe2811426 to your computer and use it in GitHub Desktop.
NES
diff --git a/Cargo.toml b/Cargo.toml
index a8a17b9..9c8bb9b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,7 @@
[package]
name = "powerglove"
version = "0.1.0"
+authors = ["Robin Mattheussen <me@romatthe.dev>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/bus.rs b/src/bus.rs
new file mode 100644
index 0000000..d32c9fb
--- /dev/null
+++ b/src/bus.rs
@@ -0,0 +1,28 @@
+use crate::cpu::CPU;
+
+const RAM_SIZE: usize = 64 * 1024;
+
+pub struct Bus {
+ pub ram: [u8; RAM_SIZE],
+}
+
+impl Bus {
+ pub fn new() -> Self {
+ Bus {
+ ram: [0x0; RAM_SIZE]
+ }
+ }
+
+ pub fn read(&self, address: u16) -> u8 {
+ match address {
+ (0x0000..=0xFFFF) => self.ram[address as usize],
+ _ => 0x0,
+ }
+ }
+
+ pub fn write(&mut self, address: u16, data: u8) {
+ match address {
+ (0x0000..=0xFFFF) => self.ram[address as usize] = data,
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/cpu.rs b/src/cpu.rs
new file mode 100644
index 0000000..ae4b5c0
--- /dev/null
+++ b/src/cpu.rs
@@ -0,0 +1,19 @@
+use crate::bus::Bus;
+
+pub struct CPU {
+ pub bus: Bus,
+}
+
+impl CPU {
+ pub fn new() -> Self {
+ CPU { bus: Bus::new() }
+ }
+
+ pub fn read(&self, address: u16) -> u8 {
+ self.bus.read(address)
+ }
+
+ pub fn write(&mut self, address: u16, data: u8) {
+ self.bus.write(address, data);
+ }
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..8268a29 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,6 @@
+mod bus;
+mod cpu;
+
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment