From ce1d99dc3715725c3a97d748c729da56123ba1ba Mon Sep 17 00:00:00 2001 From: Izzy Date: Fri, 21 Jun 2019 02:11:35 -0500 Subject: [PATCH] initial commit! --- .gitignore | 2 + Cargo.lock | 95 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 9 +++++ LICENSE | 7 ++++ README.md | 2 + src/cpu.rs | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 7 ++++ src/main.rs | 3 ++ 8 files changed, 231 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/cpu.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7bd1a40 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,95 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "byteorder" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "ceres" +version = "0.1.0" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "logos 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "logos" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "logos-derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "logos-derive" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.15.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum logos 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f494e22d293fa05db60b3fd95fb30e9409feb5672b56ce6f250f99d9fbae6b93" +"checksum logos-derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "13ff1b1068db09ee21d12baf55eccc0900a781a735273e0a606f6f4fbb32a322" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" +"checksum regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d76410686f9e3a17f06128962e0ecc5755870bb890c34820c7af7f1db2e1d48" +"checksum syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)" = "8b4f551a91e2e3848aeef8751d0d4eec9489b6474c720fd4c55958d8d31a430c" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..14e9cc1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ceres" +version = "0.1.0" +authors = ["Izzy "] +edition = "2018" + +[dependencies] +byteorder = "1.3.2" +logos = "0.9.7" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f6b6fb8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2019 ilsko + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdd1355 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Ceres +### a shitty fantasy console written in rust usng a proprietary asm instruction set \ No newline at end of file diff --git a/src/cpu.rs b/src/cpu.rs new file mode 100644 index 0000000..da1a71d --- /dev/null +++ b/src/cpu.rs @@ -0,0 +1,106 @@ +/// 16 register cpu only capable of holding 16 bit unsigned integers +pub struct Cpu { + // zero register + z0: u16, + + // system registers + sp: u16, + ra: u16, + + // argument registers + a0: u16, + a1: u16, + a2: u16, + + // return registers + v0: u16, + v1: u16, + + // temp registers + t0: u16, + t1: u16, + t2: u16, + t3: u16, + t4: u16, + t5: u16, + t6: u16, + t7: u16, +} + +/// initializes cpu with 0x00 in all registers +impl Default for Cpu { + fn default() -> Self { + Cpu { + z0: 0, + sp: 0, + ra: 0, + a0: 0, + a1: 0, + a2: 0, + v0: 0, + v1: 0, + t0: 0, + t1: 0, + t2: 0, + t3: 0, + t4: 0, + t5: 0, + t6: 0, + t7: 0, + } + } +} + +/// indexes registers by register number and returns reference to the registers +/// contents +impl std::ops::Index for Cpu { + type Output = u16; + + fn index(&self, idx: usize) -> &u16 { + match idx { + 0 => &self.z0, + 1 => &self.sp, + 2 => &self.ra, + 3 => &self.a0, + 4 => &self.a1, + 5 => &self.a2, + 6 => &self.v0, + 7 => &self.v1, + 8 => &self.t0, + 9 => &self.t1, + 10 => &self.t2, + 11 => &self.t3, + 12 => &self.t4, + 13 => &self.t5, + 14 => &self.t6, + 15 => &self.t7, + _ => panic!("Invalid register number"), + } + } +} + +/// indexes registers by register number and returns mutable reference to the +/// registers contents +impl std::ops::IndexMut for Cpu { + fn index_mut(&mut self, idx: usize) -> &mut u16 { + match idx { + 0 => &mut self.z0, + 1 => &mut self.sp, + 2 => &mut self.ra, + 3 => &mut self.a0, + 4 => &mut self.a1, + 5 => &mut self.a2, + 6 => &mut self.v0, + 7 => &mut self.v1, + 8 => &mut self.t0, + 9 => &mut self.t1, + 10 => &mut self.t2, + 11 => &mut self.t3, + 12 => &mut self.t4, + 13 => &mut self.t5, + 14 => &mut self.t6, + 15 => &mut self.t7, + _ => panic!("Invalid register number"), + } + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..9428a88 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +pub mod cpu; + +use cpu::Cpu; + +pub struct System { + cpu: Cpu, +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}