From b0886d3f74da10f0edee9058febfed81d3a123a7 Mon Sep 17 00:00:00 2001 From: Isabelle L Date: Sat, 13 Jun 2020 16:12:49 -0500 Subject: [PATCH] memeory stuff and video memory --- Cargo.lock | 164 +++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 4 +- README.md | 5 +- src/lib.rs | 13 +++- src/main.rs | 33 +++++++++- src/memory.rs | 14 ++++ src/registers.rs | 65 ++++++++++++------- src/video.rs | 23 +++++++ 8 files changed, 288 insertions(+), 33 deletions(-) create mode 100644 src/video.rs diff --git a/Cargo.lock b/Cargo.lock index 881207d..5932797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,23 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "autocfg" version = "0.1.7" @@ -33,7 +51,8 @@ name = "ceres" version = "0.1.0" dependencies = [ "logos 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", - "offbrand 0.1.0 (git+https://github.com/izzabelle/offbrand)", + "offbrand 0.1.0", + "structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -41,6 +60,20 @@ name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "clap" +version = "2.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -77,6 +110,22 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hermit-abi" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -191,7 +240,6 @@ dependencies = [ [[package]] name = "offbrand" version = "0.1.0" -source = "git+https://github.com/izzabelle/offbrand#4c63fd4cae6625ba3312b4a88b90a39e4ffa323b" dependencies = [ "minifb 0.16.0 (git+https://github.com/emoon/rust_minifb)", "thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -221,6 +269,30 @@ name = "ppv-lite86" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro-error" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.30" @@ -473,6 +545,33 @@ name = "smallvec" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "structopt" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "structopt-derive" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.15.44" @@ -485,7 +584,7 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -493,6 +592,16 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn-mid" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tempfile" version = "3.1.0" @@ -506,6 +615,14 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thiserror" version = "1.0.19" @@ -521,9 +638,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.1.0" @@ -539,6 +666,16 @@ name = "utf8-ranges" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "void" version = "1.0.2" @@ -668,17 +805,22 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" "checksum cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)" = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum dlib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" "checksum downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +"checksum hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" "checksum libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" @@ -691,11 +833,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" "checksum num-iter 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "dfb0800a0291891dd9f4fe7bd9c19384f98f7fbe0cd0f39a2c6b88b9868bbc00" "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -"checksum offbrand 0.1.0 (git+https://github.com/izzabelle/offbrand)" = "" "checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" "checksum orbclient 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b18f57ab94fbd058e30aa57f712ec423c0bb7403f8493a6c58eef0c36d9402" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" +"checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" +"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" @@ -726,14 +869,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +"checksum structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "863246aaf5ddd0d6928dfeb1a9ca65f505599e4e1b399935ef7e75107516b4ef" +"checksum structopt-derive 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d239ca4b13aee7a2142e6795cbd69e457665ff8037aed33b3effdc430d2f927a" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -"checksum syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2" +"checksum syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6" +"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b13f926965ad00595dd129fa12823b04bbf866e9085ab0a5f2b05b850fbfc344" "checksum thiserror-impl 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "893582086c2f98cde18f906265a65b5030a074b1046c674ae898be6519a7f479" +"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" +"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" "checksum wayland-client 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a42cb608953ec8e132c7f53fde722cca9bfbf8b2071d685dbbb8df2b567fee8b" diff --git a/Cargo.toml b/Cargo.toml index f6b8d20..2fcf5fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,6 @@ edition = "2018" [dependencies] logos = "0.9.7" -offbrand = { git = "https://github.com/izzabelle/offbrand" } \ No newline at end of file +#offbrand = { git = "https://github.com/izzabelle/offbrand" } +offbrand = { path = "../offbrand" } +structopt = "0.3.14" diff --git a/README.md b/README.md index 7d33e6c..ada91ab 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ a shitty fantasy console written in rust using a proprietary MIPS based asm inst ### GRAPHICS -uhhhhh funny 128x72 screen +uhhhhh funny 256x144 screen ### Register layout and info @@ -20,3 +20,6 @@ all registers are unsigned 16 bit | 8 | v1 | return register 2 | | 9-15 | t0-t6 | temporary registers | +### Memory map and info + +god oh fuck what am i even doing \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 555055a..b1a96c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,27 @@ mod memory; mod registers; +mod video; pub use memory::Memory; pub use registers::Registers; +pub use video::VideoMemory; + +pub const SCREEN_WIDTH: usize = 256; +pub const SCREEN_HEIGHT: usize = 144; +pub const VIDEO_MEMORY_LEN: usize = SCREEN_HEIGHT * SCREEN_WIDTH; pub struct System { pub registers: Registers, pub memory: Memory, + pub video_memory: VideoMemory, } impl System { pub fn init() -> System { - System { registers: Registers::init(), memory: Memory::init() } + System { + registers: Registers::init(), + memory: Memory::init(), + video_memory: VideoMemory::init(), + } } } diff --git a/src/main.rs b/src/main.rs index b9096d5..1bee387 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,35 @@ -fn main() { +use offbrand::prelude::*; +use structopt::StructOpt; + +#[derive(StructOpt)] +#[structopt(name = "CERES-16", about = "16bit fantasy console")] +struct Opt { + /// times the screen should be scaled by + #[structopt(short = "s", long = "scale", default_value = "2")] + scale_factor: usize, +} + +fn wrapper() -> Result<()> { + let opt = Opt::from_args(); + let mut ctx = offbrand::Context::new( + ceres::SCREEN_WIDTH * opt.scale_factor, + ceres::SCREEN_HEIGHT * opt.scale_factor, + "CERES-16".to_owned(), + )?; let sys = ceres::System::init(); println!("{}", sys.registers); + + while ctx.is_open() { + ctx.clear(None); + + ctx.present()?; + } + + Ok(()) +} + +fn main() { + if let Err(err) = wrapper() { + eprintln!("error: {:?}", err); + } } diff --git a/src/memory.rs b/src/memory.rs index 34244a0..9fa4422 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -8,3 +8,17 @@ impl Memory { Memory { data: [0x00; std::u16::MAX as usize] } } } + +impl std::ops::Index for Memory { + type Output = u16; + + fn index(&self, index: u16) -> &u16 { + &self.data[index as usize] + } +} + +impl std::ops::IndexMut for Memory { + fn index_mut(&mut self, index: u16) -> &mut u16 { + &mut self.data[index as usize] + } +} diff --git a/src/registers.rs b/src/registers.rs index fe15578..8a32a07 100644 --- a/src/registers.rs +++ b/src/registers.rs @@ -30,25 +30,25 @@ pub struct Registers { } impl Registers { - /// initializes cpu with 0x00 in all registers + /// initializes cpu with 0x0000 in all registers pub fn init() -> Registers { Registers { - z0: 0x00, - gp: 0x00, - sp: 0x00, - ra: 0x00, - a0: 0x00, - a1: 0x00, - a2: 0x00, - v0: 0x00, - v1: 0x00, - t0: 0x00, - t1: 0x00, - t2: 0x00, - t3: 0x00, - t4: 0x00, - t5: 0x00, - t6: 0x00, + z0: 0x0000, + gp: 0x0000, + sp: 0x0000, + ra: 0x0000, + a0: 0x0000, + a1: 0x0000, + a2: 0x0000, + v0: 0x0000, + v1: 0x0000, + t0: 0x0000, + t1: 0x0000, + t2: 0x0000, + t3: 0x0000, + t4: 0x0000, + t5: 0x0000, + t6: 0x0000, } } } @@ -109,11 +109,30 @@ impl std::ops::IndexMut for Registers { impl fmt::Display for Registers { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "-- registers ----------------------------------------------------------------------------\n\ -| z0: 0x{:02X} | gp: 0x{:02X} | sp: 0x{:02X} | ra: 0x{:02X} | a0: 0x{:02X} | a1: 0x{:02X} | a2: 0x{:02X} | v0: 0x{:02X} |\n\ -| v1: 0x{:02X} | t0: 0x{:02X} | t1: 0x{:02X} | t2: 0x{:02X} | t3: 0x{:02X} | t4: 0x{:02X} | t5: 0x{:02X} | t6: 0x{:02X} |\n\ ------------------------------------------------------------------------------------------", - self[0], self[1], self[2], self[3], self[4], self[5], self[6], self[7], - self[8], self[9], self[10], self[11], self[12], self[13], self[14], self[15]) + write!( + f, + "-- registers ----------------------------------------\n\ +| z0: 0x{:04X} | gp: 0x{:04X} | sp: 0x{:04X} | ra: 0x{:04X} |\n\ +| a0: 0x{:04X} | a1: 0x{:04X} | a2: 0x{:04X} | v0: 0x{:04X} |\n\ +| v1: 0x{:04X} | t0: 0x{:04X} | t1: 0x{:04X} | t2: 0x{:04X} |\n\ +| t3: 0x{:04X} | t4: 0x{:04X} | t5: 0x{:04X} | t6: 0x{:04X} |\n\ +-----------------------------------------------------", + self[0], + self[1], + self[2], + self[3], + self[4], + self[5], + self[6], + self[7], + self[8], + self[9], + self[10], + self[11], + self[12], + self[13], + self[14], + self[15] + ) } } diff --git a/src/video.rs b/src/video.rs new file mode 100644 index 0000000..3724dc6 --- /dev/null +++ b/src/video.rs @@ -0,0 +1,23 @@ +pub struct VideoMemory { + data: [u16; crate::VIDEO_MEMORY_LEN], +} + +impl VideoMemory { + pub fn init() -> VideoMemory { + VideoMemory { data: [0x0000; crate::VIDEO_MEMORY_LEN] } + } +} + +impl std::ops::Index for VideoMemory { + type Output = u16; + + fn index(&self, index: u16) -> &u16 { + &self.data[index as usize] + } +} + +impl std::ops::IndexMut for VideoMemory { + fn index_mut(&mut self, index: u16) -> &mut u16 { + &mut self.data[index as usize] + } +}