diff --git a/Cargo.lock b/Cargo.lock index 39c169b..97b89ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,25 +1,28 @@ -[root] +[[package]] name = "alvin" version = "0.1.0" dependencies = [ - "clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ansi_term" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "atty" -version = "0.2.2" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -29,203 +32,216 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "0.9.1" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clap" -version = "2.26.2" +version = "2.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "conv" +name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "custom_derive" -version = "0.1.7" +name = "fuchsia-zircon-sys" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lazy_static" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.30" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "magenta" -version = "0.1.1" +name = "num" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "magenta-sys" -version = "0.1.1" +name = "num-integer" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "num" -version = "0.1.40" +name = "num-iter" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "num-integer" -version = "0.1.35" +name = "num-traits" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "num-iter" -version = "0.1.34" +name = "rand" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "num-traits" +name = "redox_syscall" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "rand" -version = "0.3.16" +name = "redox_termios" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sdl2" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "sdl2-sys 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sdl2-sys" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "strsim" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "term_size" -version = "0.3.0" +name = "termion" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "textwrap" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-width" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "vec_map" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.2.8" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] -name = "winapi-build" -version = "0.1.1" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" -"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2" -"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" -"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" -"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" -"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" -"checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525" -"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" -"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" -"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0" -"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" -"checksum sdl2 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63066036ad426250ac56d23e38fd05063b38b661556acd596f4046cc92d98415" -"checksum sdl2-sys 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b48638b7882759f3421038fcd38ad5f1ea19b119d80c99f1601933004629e34d" -"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" -"checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" -"checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" -"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" -"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" +"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" +"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" +"checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe" +"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" +"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a74c2a98a354b20713b90cce70aef9e927e46110d1bc4ef728fd74e0d53eba60" +"checksum sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c543ce8a6e33a30cb909612eeeb22e693848211a84558d5a00bb11e791b7ab7" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" +"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 170d854..4642300 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ categories = ["emulators", "games"] [dependencies] rand = "^0.3" clap = "^2.26.1" -sdl2 = "0.30.0" \ No newline at end of file +sdl2 = "0.31.0" \ No newline at end of file diff --git a/src/disassembler.rs b/src/disassembler.rs index 5009a55..ba0f5e3 100644 --- a/src/disassembler.rs +++ b/src/disassembler.rs @@ -14,4 +14,4 @@ pub fn disassemble(buffer: &[u8]) { println!(); } -} \ No newline at end of file +} diff --git a/src/display.rs b/src/display.rs index 10422ea..e576c48 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,23 +1,36 @@ use sdl2; -use sdl2::rect::Point; use sdl2::pixels::Color; -use sdl2::video::Window; +use sdl2::rect::Point; use sdl2::render::Canvas; +use sdl2::video::Window; -const BG_COLOR: Color = Color { r: 53, g: 59, b: 115, a: 0xFF }; -const FG_COLOR: Color = Color { r: 255, g: 255, b: 41, a: 0xFF }; +const BG_COLOR: Color = Color { + r: 53, + g: 59, + b: 115, + a: 0xFF, +}; +const FG_COLOR: Color = Color { + r: 255, + g: 255, + b: 41, + a: 0xFF, +}; pub struct Display { working_screen: [[bool; 32]; 64], - canvas: Canvas + canvas: Canvas, } impl Display { pub fn new(sdl_context: &sdl2::Sdl) -> Display { let video_subsystem = sdl_context.video().unwrap(); - let window = video_subsystem.window("Alvin", 640, 320) - .position_centered().build().unwrap(); + let window = video_subsystem + .window("Alvin", 640, 320) + .position_centered() + .build() + .unwrap(); let mut canvas = window.into_canvas().accelerated().build().unwrap(); canvas.set_scale(10.0, 10.0); @@ -26,7 +39,7 @@ impl Display { Display { working_screen: [[false; 32]; 64], - canvas + canvas, } } @@ -81,4 +94,4 @@ impl Display { self.canvas.present(); } -} \ No newline at end of file +} diff --git a/src/emulator.rs b/src/emulator.rs index a05105d..912bbaa 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -3,15 +3,15 @@ use sdl2; use rand::distributions::{IndependentSample, Range}; +use std::collections::VecDeque; use std::thread; use std::time::Instant; -use std::collections::VecDeque; -use sound::Sound; -use opcode::Opcode; use display::Display; use input::{Input, InputAction}; use memory::{load_fonts, load_program}; +use opcode::Opcode; +use sound::Sound; pub type Address = u16; pub type Constant = u8; @@ -127,7 +127,10 @@ impl System { } fn print_debug(&mut self) { - print!("PC[{:#04x}]\tDELAY[{}]\tSOUND[{}]\tI[{:#03x}]", self.program_counter, self.delay_timer, self.sound_timer, self.address_register); + print!( + "PC[{:#04x}]\tDELAY[{}]\tSOUND[{}]\tI[{:#03x}]", + self.program_counter, self.delay_timer, self.sound_timer, self.address_register + ); for i in 0x0..0x10 { print!("\tV{:X}[{}]", i, self.get_register(i)); } @@ -240,7 +243,6 @@ impl System { self.set_register(first, result); - self.program_counter += WORD_SIZE; } Opcode::SubAssignReg(first, second) => { @@ -501,4 +503,4 @@ impl System { fn set_memory(&mut self, address: Address, value: Constant) { self.memory[address as usize] = value; } -} \ No newline at end of file +} diff --git a/src/input.rs b/src/input.rs index 0e726aa..e075c89 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,49 +1,76 @@ use sdl2; -use sdl2::EventPump; use sdl2::event::Event; use sdl2::keyboard::Keycode; +use sdl2::EventPump; pub struct Input { - event_pump: EventPump + event_pump: EventPump, } impl Input { pub fn new(sdl_context: &sdl2::Sdl) -> Input { let event_pump = sdl_context.event_pump().unwrap(); - Input { - event_pump - } + Input { event_pump } } pub fn handle_input(&mut self) -> Option { for event in self.event_pump.poll_iter() { match event { - Event::Quit { .. } | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { + Event::Quit { .. } + | Event::KeyDown { + keycode: Some(Keycode::Escape), + .. + } => { return Some(InputAction::Quit); } - Event::Quit { .. } | Event::KeyUp { keycode: Some(Keycode::Escape), .. } => { + Event::Quit { .. } + | Event::KeyUp { + keycode: Some(Keycode::Escape), + .. + } => { return Some(InputAction::Quit); } - Event::KeyDown { keycode: Some(Keycode::Return), .. } => { + Event::KeyDown { + keycode: Some(Keycode::Return), + .. + } => { return Some(InputAction::Reset); } - Event::KeyUp { keycode: Some(Keycode::Return), .. } => { + Event::KeyUp { + keycode: Some(Keycode::Return), + .. + } => { return Some(InputAction::Reset); } - Event::KeyDown { keycode: Some(Keycode::Space), .. } => { + Event::KeyDown { + keycode: Some(Keycode::Space), + .. + } => { return Some(InputAction::Pause); } - Event::KeyDown { keycode: Some(Keycode::LeftBracket), .. } => { + Event::KeyDown { + keycode: Some(Keycode::LeftBracket), + .. + } => { return Some(InputAction::DecreaseTick); } - Event::KeyDown { keycode: Some(Keycode::RightBracket), .. } => { + Event::KeyDown { + keycode: Some(Keycode::RightBracket), + .. + } => { return Some(InputAction::IncreaseTick); } - Event::KeyDown { keycode: Some(Keycode::Tab), .. } => { + Event::KeyDown { + keycode: Some(Keycode::Tab), + .. + } => { return Some(InputAction::DebugInfo); } - Event::KeyUp { keycode: Some(Keycode::Tab), .. } => { + Event::KeyUp { + keycode: Some(Keycode::Tab), + .. + } => { return Some(InputAction::DebugInfo); } _ => {} @@ -90,7 +117,7 @@ pub enum InputAction { Pause, DecreaseTick, IncreaseTick, - DebugInfo + DebugInfo, } pub fn key_map(keycode: Keycode) -> Option { @@ -114,6 +141,6 @@ pub fn key_map(keycode: Keycode) -> Option { Keycode::X => Some(0x0), Keycode::C => Some(0xB), Keycode::V => Some(0xF), - _ => None + _ => None, }; -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index e4362fe..141eb54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,13 @@ extern crate clap; extern crate rand; extern crate sdl2; -mod input; -mod sound; -mod opcode; -mod memory; +mod disassembler; mod display; mod emulator; -mod disassembler; +mod input; +mod memory; +mod opcode; +mod sound; use clap::{App, Arg}; @@ -24,24 +24,24 @@ use emulator::System; fn main() { let matches = App::new("alvin") .version(crate_version!()) - .arg(Arg::with_name("file") - .short("f") - .long("file") - .value_name("FILE") - .help("What file to load") - .takes_value(true) - .required(true) - ) - .subcommand(clap::SubCommand::with_name("disassemble")) - .subcommand(clap::SubCommand::with_name("run") - .arg(Arg::with_name("debug") - .long("debug") - .help("Continuously dump emulator state to the command line") - .takes_value(false) - .required(false) - ) - ) - .get_matches(); + .arg( + Arg::with_name("file") + .short("f") + .long("file") + .value_name("FILE") + .help("What file to load") + .takes_value(true) + .required(true), + ).subcommand(clap::SubCommand::with_name("disassemble")) + .subcommand( + clap::SubCommand::with_name("run").arg( + Arg::with_name("debug") + .long("debug") + .help("Continuously dump emulator state to the command line") + .takes_value(false) + .required(false), + ), + ).get_matches(); let filename = matches.value_of("file").expect("file is required"); let file = File::open(filename).expect("file not found"); @@ -54,12 +54,12 @@ fn main() { Some("run") => { let mut system = System::new(buffer); - let dump_state = matches.subcommand_matches("run").unwrap() + let dump_state = matches + .subcommand_matches("run") + .unwrap() .is_present("debug"); system.run(dump_state); } - _ => { - println!("ERROR: command invalid or not provided") - } + _ => println!("ERROR: command invalid or not provided"), } } diff --git a/src/memory.rs b/src/memory.rs index 372cfa2..b8c9995 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,37 +1,22 @@ // Sprite data borrowed from https://github.com/massung/CHIP-8/blob/master/chip8/rom.go const SPRITE_DATA: [u8; 0x1C0] = [ // 4x5 low-res mode font sprites (0-F) - 0xF0, 0x90, 0x90, 0x90, 0xF0, 0x20, 0x60, 0x20, - 0x20, 0x70, 0xF0, 0x10, 0xF0, 0x80, 0xF0, 0xF0, - 0x10, 0xF0, 0x10, 0xF0, 0xA0, 0xA0, 0xF0, 0x20, - 0x20, 0xF0, 0x80, 0xF0, 0x10, 0xF0, 0xF0, 0x80, - 0xF0, 0x90, 0xF0, 0xF0, 0x10, 0x20, 0x40, 0x40, - 0xF0, 0x90, 0xF0, 0x90, 0xF0, 0xF0, 0x90, 0xF0, - 0x10, 0xF0, 0xF0, 0x90, 0xF0, 0x90, 0x90, 0xE0, - 0x90, 0xE0, 0x90, 0xE0, 0xF0, 0x80, 0x80, 0x80, - 0xF0, 0xE0, 0x90, 0x90, 0x90, 0xE0, 0xF0, 0x80, - 0xF0, 0x80, 0xF0, 0xF0, 0x80, 0xF0, 0x80, 0x80, + 0xF0, 0x90, 0x90, 0x90, 0xF0, 0x20, 0x60, 0x20, 0x20, 0x70, 0xF0, 0x10, 0xF0, 0x80, 0xF0, 0xF0, + 0x10, 0xF0, 0x10, 0xF0, 0xA0, 0xA0, 0xF0, 0x20, 0x20, 0xF0, 0x80, 0xF0, 0x10, 0xF0, 0xF0, 0x80, + 0xF0, 0x90, 0xF0, 0xF0, 0x10, 0x20, 0x40, 0x40, 0xF0, 0x90, 0xF0, 0x90, 0xF0, 0xF0, 0x90, 0xF0, + 0x10, 0xF0, 0xF0, 0x90, 0xF0, 0x90, 0x90, 0xE0, 0x90, 0xE0, 0x90, 0xE0, 0xF0, 0x80, 0x80, 0x80, + 0xF0, 0xE0, 0x90, 0x90, 0x90, 0xE0, 0xF0, 0x80, 0xF0, 0x80, 0xF0, 0xF0, 0x80, 0xF0, 0x80, 0x80, // 8x10 high-res mode font sprites (0-F) - 0x3C, 0x7E, 0xE7, 0xC3, 0xC3, 0xC3, 0xC3, 0xE7, - 0x7E, 0x3C, 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x3C, 0x3E, 0x7F, 0xC3, 0x06, - 0x0C, 0x18, 0x30, 0x60, 0xFF, 0xFF, 0x3C, 0x7E, - 0xC3, 0x03, 0x0E, 0x0E, 0x03, 0xC3, 0x7E, 0x3C, - 0x06, 0x0E, 0x1E, 0x36, 0x66, 0xC6, 0xFF, 0xFF, - 0x06, 0x06, 0xFF, 0xFF, 0xC0, 0xC0, 0xFC, 0xFE, - 0x03, 0xC3, 0x7E, 0x3C, 0x3E, 0x7C, 0xC0, 0xC0, - 0xFC, 0xFE, 0xC3, 0xC3, 0x7E, 0x3C, 0xFF, 0xFF, - 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x60, - 0x3C, 0x7E, 0xC3, 0xC3, 0x7E, 0x7E, 0xC3, 0xC3, - 0x7E, 0x3C, 0x3C, 0x7E, 0xC3, 0xC3, 0x7F, 0x3F, - 0x03, 0x03, 0x3E, 0x7C, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3C, 0x7E, 0xE7, 0xC3, 0xC3, 0xC3, 0xC3, 0xE7, 0x7E, 0x3C, 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x3C, 0x3E, 0x7F, 0xC3, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFF, 0xFF, 0x3C, 0x7E, + 0xC3, 0x03, 0x0E, 0x0E, 0x03, 0xC3, 0x7E, 0x3C, 0x06, 0x0E, 0x1E, 0x36, 0x66, 0xC6, 0xFF, 0xFF, + 0x06, 0x06, 0xFF, 0xFF, 0xC0, 0xC0, 0xFC, 0xFE, 0x03, 0xC3, 0x7E, 0x3C, 0x3E, 0x7C, 0xC0, 0xC0, + 0xFC, 0xFE, 0xC3, 0xC3, 0x7E, 0x3C, 0xFF, 0xFF, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x60, + 0x3C, 0x7E, 0xC3, 0xC3, 0x7E, 0x7E, 0xC3, 0xC3, 0x7E, 0x3C, 0x3C, 0x7E, 0xC3, 0xC3, 0x7F, 0x3F, + 0x03, 0x03, 0x3E, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6-bit ASCII character patterns 0x00, // | | 0x10, // | * | @@ -49,7 +34,6 @@ const SPRITE_DATA: [u8; 0x1C0] = [ 0xD0, // |** * | 0xE0, // |*** | 0xF0, // |**** | - // 6-bit ASCII characters from 0x100- 0x46, 0x3E, 0x56, // @ 0x99, 0x9F, 0x4F, // A @@ -135,4 +119,4 @@ pub fn load_program(memory: &mut [u8], program: &[u8]) { memory[current_address] = *byte; current_address += 1; } -} \ No newline at end of file +} diff --git a/src/opcode.rs b/src/opcode.rs index 6ab0956..71123ca 100644 --- a/src/opcode.rs +++ b/src/opcode.rs @@ -49,7 +49,7 @@ impl Opcode { (first_byte & 0xF0) >> 0x4, first_byte & 0xF, (second_byte & 0xF0) >> 0x4, - second_byte & 0xF + second_byte & 0xF, ); match nibbles { @@ -88,7 +88,7 @@ impl Opcode { (0xF, _, 0x3, 0x3) => Ok(Opcode::BinaryCodedDecimal(nibbles.1)), (0xF, _, 0x5, 0x5) => Ok(Opcode::Dump(nibbles.1)), (0xF, _, 0x6, 0x5) => Ok(Opcode::Load(nibbles.1)), - _ => Err(build_data(nibbles)) + _ => Err(build_data(nibbles)), } } } @@ -96,111 +96,45 @@ impl Opcode { impl fmt::Debug for Opcode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Opcode::Call(address) => { - write!(f, "CALL\t{:#03x}", address) - } - Opcode::Clear => { - write!(f, "CLS") - } - Opcode::Return => { - write!(f, "RET") - } - Opcode::Goto(address) => { - write!(f, "JMP\t{:#03x}", address) - } - Opcode::CallFunction(address) => { - write!(f, "CALL\t{:#03x}", address) - } - Opcode::SkipEq(register, constant) => { - write!(f, "SE\tV{:X}\t{}", register, constant) - } - Opcode::SkipNEq(register, constant) => { - write!(f, "SNE\tV{:X}\t{}", register, constant) - } - Opcode::SkipEqReg(first, second) => { - write!(f, "SE\tV{:X}\tV{:X}", first, second) - } - Opcode::Set(register, constant) => { - write!(f, "SET\tV{:X}\t{}", register, constant) - } + Opcode::Call(address) => write!(f, "CALL\t{:#03x}", address), + Opcode::Clear => write!(f, "CLS"), + Opcode::Return => write!(f, "RET"), + Opcode::Goto(address) => write!(f, "JMP\t{:#03x}", address), + Opcode::CallFunction(address) => write!(f, "CALL\t{:#03x}", address), + Opcode::SkipEq(register, constant) => write!(f, "SE\tV{:X}\t{}", register, constant), + Opcode::SkipNEq(register, constant) => write!(f, "SNE\tV{:X}\t{}", register, constant), + Opcode::SkipEqReg(first, second) => write!(f, "SE\tV{:X}\tV{:X}", first, second), + Opcode::Set(register, constant) => write!(f, "SET\tV{:X}\t{}", register, constant), Opcode::AddAssign(register, constant) => { write!(f, "ADDA\tV{:X}\t{}", register, constant) } - Opcode::Copy(to, from) => { - write!(f, "SET\tV{:X}\tV{:X}", to, from) - } - Opcode::Or(first, second) => { - write!(f, "OR\tV{:X}\tV{:X}", first, second) - } - Opcode::And(first, second) => { - write!(f, "AND\tV{:X}\tV{:X}", first, second) - } - Opcode::Xor(first, second) => { - write!(f, "XOR\tV{:X}\tV{:X}", first, second) - } - Opcode::AddAssignReg(first, second) => { - write!(f, "ADDA\tV{:X}\tV{:X}", first, second) - } - Opcode::SubAssignReg(first, second) => { - write!(f, "SUBA\tV{:X}\tV{:X}", first, second) - } - Opcode::ShiftRight(first, second) => { - write!(f, "SHR\tV{:X}\tV{:X}", first, second) - } - Opcode::Subtract(first, second) => { - write!(f, "SUB\tV{:X}\tV{:X}", first, second) - } - Opcode::ShiftLeft(first, second) => { - write!(f, "SHL\tV{:X}\tV{:X}", first, second) - } - Opcode::SkipNEqReg(first, second) => { - write!(f, "SNE\tV{:X}\tV{:X}", first, second) - } - Opcode::SetAddressReg(address) => { - write!(f, "SET\tI\t{:#03x}", address) - } - Opcode::JumpOffset(address) => { - write!(f, "OFF\t{:#03x}", address) - } - Opcode::SetRand(register, constant) => { - write!(f, "RND\tV{:X}\t{}", register, constant) - } + Opcode::Copy(to, from) => write!(f, "SET\tV{:X}\tV{:X}", to, from), + Opcode::Or(first, second) => write!(f, "OR\tV{:X}\tV{:X}", first, second), + Opcode::And(first, second) => write!(f, "AND\tV{:X}\tV{:X}", first, second), + Opcode::Xor(first, second) => write!(f, "XOR\tV{:X}\tV{:X}", first, second), + Opcode::AddAssignReg(first, second) => write!(f, "ADDA\tV{:X}\tV{:X}", first, second), + Opcode::SubAssignReg(first, second) => write!(f, "SUBA\tV{:X}\tV{:X}", first, second), + Opcode::ShiftRight(first, second) => write!(f, "SHR\tV{:X}\tV{:X}", first, second), + Opcode::Subtract(first, second) => write!(f, "SUB\tV{:X}\tV{:X}", first, second), + Opcode::ShiftLeft(first, second) => write!(f, "SHL\tV{:X}\tV{:X}", first, second), + Opcode::SkipNEqReg(first, second) => write!(f, "SNE\tV{:X}\tV{:X}", first, second), + Opcode::SetAddressReg(address) => write!(f, "SET\tI\t{:#03x}", address), + Opcode::JumpOffset(address) => write!(f, "OFF\t{:#03x}", address), + Opcode::SetRand(register, constant) => write!(f, "RND\tV{:X}\t{}", register, constant), Opcode::Draw(first, second, constant) => { write!(f, "DRW\tV{:X}\tV{:X}\t{}", first, second, constant) } - Opcode::SkipKeyPress(register) => { - write!(f, "SKP\tV{:X}", register) - } - Opcode::SkipNoKeyPress(register) => { - write!(f, "SNKP\tV{:X}", register) - } - Opcode::StoreDelayTimer(register) => { - write!(f, "SET\tV{:X}\tDELAY", register) - } - Opcode::StoreKeypress(register) => { - write!(f, "SET\tV{:X}\tKEY", register) - } - Opcode::SetDelayTimer(register) => { - write!(f, "SET\tDELAY\tV{:X}", register) - } - Opcode::SetSoundTimer(register) => { - write!(f, "SET\tSOUND\tV{:X}", register) - } - Opcode::IncrementAddressReg(register) => { - write!(f, "ADD\tI\tV{:X}", register) - } - Opcode::StoreSpriteAddress(register) => { - write!(f, "SPRT\tV{:X}", register) - } - Opcode::BinaryCodedDecimal(register) => { - write!(f, "BCD\tV{:X}", register) - } - Opcode::Dump(register) => { - write!(f, "DUMP\tV{:X}", register) - } - Opcode::Load(register) => { - write!(f, "LOAD\tV{:X}", register) - } + Opcode::SkipKeyPress(register) => write!(f, "SKP\tV{:X}", register), + Opcode::SkipNoKeyPress(register) => write!(f, "SNKP\tV{:X}", register), + Opcode::StoreDelayTimer(register) => write!(f, "SET\tV{:X}\tDELAY", register), + Opcode::StoreKeypress(register) => write!(f, "SET\tV{:X}\tKEY", register), + Opcode::SetDelayTimer(register) => write!(f, "SET\tDELAY\tV{:X}", register), + Opcode::SetSoundTimer(register) => write!(f, "SET\tSOUND\tV{:X}", register), + Opcode::IncrementAddressReg(register) => write!(f, "ADD\tI\tV{:X}", register), + Opcode::StoreSpriteAddress(register) => write!(f, "SPRT\tV{:X}", register), + Opcode::BinaryCodedDecimal(register) => write!(f, "BCD\tV{:X}", register), + Opcode::Dump(register) => write!(f, "DUMP\tV{:X}", register), + Opcode::Load(register) => write!(f, "LOAD\tV{:X}", register), } } } @@ -228,4 +162,4 @@ fn build_address(nibbles: (u8, u8, u8, u8)) -> Address { fn build_constant(nibbles: (u8, u8, u8, u8)) -> Constant { (nibbles.2 << 4) | nibbles.3 -} \ No newline at end of file +} diff --git a/src/sound.rs b/src/sound.rs index 14b58af..c7e1f2c 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -1,8 +1,8 @@ use sdl2; -use sdl2::audio::{AudioDevice, AudioCallback, AudioSpecDesired}; +use sdl2::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; pub struct Sound { - device: AudioDevice + device: AudioDevice, } impl Sound { @@ -12,20 +12,17 @@ impl Sound { let spec = AudioSpecDesired { freq: Some(44100), channels: Some(1), - samples: None + samples: None, }; - let device = audio.open_playback(None, &spec, |spec| { - SquareWave { + let device = audio + .open_playback(None, &spec, |spec| SquareWave { phase_inc: 440.0 / spec.freq as f32, phase: 0.0, - volume: 0.25 - } - }).unwrap(); + volume: 0.25, + }).unwrap(); - Sound { - device - } + Sound { device } } pub fn play(&self) { @@ -40,7 +37,7 @@ impl Sound { struct SquareWave { phase_inc: f32, phase: f32, - volume: f32 + volume: f32, } impl AudioCallback for SquareWave { @@ -49,8 +46,8 @@ impl AudioCallback for SquareWave { fn callback(&mut self, out: &mut [f32]) { for x in out.iter_mut() { *x = match self.phase { - 0.0 ... 0.5 => self.volume, - _ => -self.volume + 0.0...0.5 => self.volume, + _ => -self.volume, }; self.phase = (self.phase + self.phase_inc) % 1.0; }