messing around with glyphbrush

This commit is contained in:
Daniel Bauer
2019-12-26 11:58:12 +01:00
parent 149df4ee35
commit e57d400d16
5 changed files with 374 additions and 217 deletions

75
Cargo.lock generated
View File

@@ -6,10 +6,13 @@ version = "0.1.0"
dependencies = [ dependencies = [
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_device_gl 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_glyph 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"piston2d-opengl_graphics 0.70.0 (registry+https://github.com/rust-lang/crates.io-index)", "piston2d-opengl_graphics 0.70.0 (registry+https://github.com/rust-lang/crates.io-index)",
"piston_window 0.105.0 (registry+https://github.com/rust-lang/crates.io-index)", "piston_window 0.105.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"simple_logger 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -366,6 +369,18 @@ dependencies = [
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "gfx_glyph"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"glyph_brush 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "gif" name = "gif"
version = "0.10.3" version = "0.10.3"
@@ -486,6 +501,28 @@ dependencies = [
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "glyph_brush"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"glyph_brush_layout 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glyph_brush_layout"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"xi-unicode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.5" version = "0.1.5"
@@ -569,6 +606,11 @@ dependencies = [
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "linked-hash-map"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.3.2" version = "0.3.2"
@@ -1083,6 +1125,14 @@ name = "rustc-demangle"
version = "0.1.16" version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-hash"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.2.3" version = "0.2.3"
@@ -1106,7 +1156,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -1272,6 +1327,14 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "twox-hash"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.1.0" version = "0.1.0"
@@ -1431,6 +1494,11 @@ name = "xdg"
version = "2.2.0" version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "xi-unicode"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "xml-rs" name = "xml-rs"
version = "0.8.0" version = "0.8.0"
@@ -1481,6 +1549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "75fbddaef2e12b4995900539d7209d947b988a3d87ee8737484d049b526e5441" "checksum gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "75fbddaef2e12b4995900539d7209d947b988a3d87ee8737484d049b526e5441"
"checksum gfx_device_gl 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "109c385fa380c18888633aa27d1e16cbae518469702a2f69dcb5f52d5378bebc" "checksum gfx_device_gl 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "109c385fa380c18888633aa27d1e16cbae518469702a2f69dcb5f52d5378bebc"
"checksum gfx_gl 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8525888d909a6424b04f9136976f07a85fc1f3704555c1a73897e258326c8319" "checksum gfx_gl 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8525888d909a6424b04f9136976f07a85fc1f3704555c1a73897e258326c8319"
"checksum gfx_glyph 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d327b1b1d6c3846a48a931eb2d793c0a35a7e094a5ca29cc9770432dc2192c32"
"checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" "checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af"
"checksum gl 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7d8c8e25e8ed44d4813809205090162723a866fb4be3a9d8bb983c9a0bf98f1" "checksum gl 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7d8c8e25e8ed44d4813809205090162723a866fb4be3a9d8bb983c9a0bf98f1"
"checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604" "checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604"
@@ -1493,6 +1562,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum glutin_gles2_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89996c30857ae1b4de4b5189abf1ea822a20a9fe9e1c93e5e7b862ff0bdd5cdf" "checksum glutin_gles2_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89996c30857ae1b4de4b5189abf1ea822a20a9fe9e1c93e5e7b862ff0bdd5cdf"
"checksum glutin_glx_sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1290a5ca5e46fcfa7f66f949cc9d9194b2cb6f2ed61892c8c2b82343631dba57" "checksum glutin_glx_sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1290a5ca5e46fcfa7f66f949cc9d9194b2cb6f2ed61892c8c2b82343631dba57"
"checksum glutin_wgl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f801bbc91efc22dd1c4818a47814fc72bf74d024510451b119381579bfa39021" "checksum glutin_wgl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f801bbc91efc22dd1c4818a47814fc72bf74d024510451b119381579bfa39021"
"checksum glyph_brush 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec4a0787fffc6692ec1ccef9fe09a8e02df1b7fc8fadd5af96662dc979473f9"
"checksum glyph_brush_layout 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "62b6d460a62dc8a2d3402689b02824ca03d40ec6f1673b9d2016d1f30ce5cb62"
"checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7" "checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7"
"checksum image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4be8aaefbe7545dc42ae925afb55a0098f226a3fe5ef721872806f44f57826" "checksum image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4be8aaefbe7545dc42ae925afb55a0098f226a3fe5ef721872806f44f57826"
"checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" "checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
@@ -1504,6 +1575,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
"checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" "checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9"
"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" "checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
@@ -1562,6 +1634,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum read_color 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f4c8858baa4ad3c8bcc156ae91a0ffe22b76a3975c40c49b4f04c15c6bce0da" "checksum read_color 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f4c8858baa4ad3c8bcc156ae91a0ffe22b76a3975c40c49b4f04c15c6bce0da"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" "checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5"
"checksum rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14a911032fb5791ccbeec9f28fdcb9bf0983b81f227bafdfd227c658d0731c8a" "checksum rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14a911032fb5791ccbeec9f28fdcb9bf0983b81f227bafdfd227c658d0731c8a"
@@ -1584,6 +1657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
"checksum tiff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b7c2cfc4742bd8a32f2e614339dd8ce30dbcf676bb262bd63a2327bc5df57d" "checksum tiff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b7c2cfc4742bd8a32f2e614339dd8ce30dbcf676bb262bd63a2327bc5df57d"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "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 unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum vecmath 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "956ae1e0d85bca567dee1dcf87fb1ca2e792792f66f87dced8381f99cd91156a" "checksum vecmath 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "956ae1e0d85bca567dee1dcf87fb1ca2e792792f66f87dced8381f99cd91156a"
@@ -1602,4 +1676,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum winit 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e96eb4bb472fa43e718e8fa4aef82f86cd9deac9483a1e1529230babdb394a8" "checksum winit 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e96eb4bb472fa43e718e8fa4aef82f86cd9deac9483a1e1529230babdb394a8"
"checksum x11-dl 2.18.4 (registry+https://github.com/rust-lang/crates.io-index)" = "be65e1342a3baae65439cd03306778831a3d133b0d20243a7fb83fd5cf403c58" "checksum x11-dl 2.18.4 (registry+https://github.com/rust-lang/crates.io-index)" = "be65e1342a3baae65439cd03306778831a3d133b0d20243a7fb83fd5cf403c58"
"checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" "checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
"checksum xi-unicode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7395cdb9d0a6219fa0ea77d08c946adf9c1984c72fcd443ace30365f3daadef7"
"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" "checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5"

View File

@@ -15,3 +15,6 @@ failure = "0.1.*"
piston_window = "0.105.*" piston_window = "0.105.*"
piston2d-opengl_graphics = "0.70.*" piston2d-opengl_graphics = "0.70.*"
gfx_core = "0.9.2" gfx_core = "0.9.2"
gfx_device_gl = "*"
gfx_glyph = "*"
rand = "*"

View File

@@ -5,6 +5,7 @@ extern crate phf;
extern crate piston_window; extern crate piston_window;
mod nes; mod nes;
mod render;
use std::path::Path; use std::path::Path;
use piston_window::*; use piston_window::*;
@@ -16,6 +17,11 @@ use nes::disasm::*;
use opengl_graphics::OpenGL; use opengl_graphics::OpenGL;
use log::Level; use log::Level;
use piston_window::Text; use piston_window::Text;
use render::*;
use gfx_glyph::{Section, GlyphBrushBuilder,GlyphBrush};
use gfx_device_gl::{Factory,Resources};
// font options // font options
const FT_SIZE_PT: u32 = 6; const FT_SIZE_PT: u32 = 6;
@@ -25,14 +31,8 @@ const FT_COLOR_RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
const FT_COLOR_GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; const FT_COLOR_GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
const FT_LINE_DISTANCE: f64 = FT_SIZE_PX * 0.5; const FT_LINE_DISTANCE: f64 = FT_SIZE_PX * 0.5;
// font for text drawing
fn get_glyphs(window: &mut PistonWindow) -> Glyphs {
let font_path = Path::new("resources/fonts/PressStart2P.ttf");
window.load_font(font_path).unwrap()
}
fn main() { fn main() {
simple_logger::init_with_level(Level::Debug).unwrap(); simple_logger::init_with_level(Level::Error).unwrap();
let mut bus = MemoryBus::new(); let mut bus = MemoryBus::new();
let cartridge = Path::new("test_roms/registers.nes"); let cartridge = Path::new("test_roms/registers.nes");
@@ -71,250 +71,283 @@ fn main() {
.exit_on_esc(true).graphics_api(OpenGL::V3_2).build().unwrap(); .exit_on_esc(true).graphics_api(OpenGL::V3_2).build().unwrap();
let mut event_settings = EventSettings::new(); let mut event_settings = EventSettings::new();
event_settings.max_fps = 60; event_settings.max_fps = 60;
event_settings.ups = 107400;
let mut events = Events::new(event_settings); let mut events = Events::new(event_settings);
let mut glyphs = get_glyphs(&mut window); let ft: &[u8] = include_bytes!("../resources/fonts/PressStart2P.ttf");
let mut glyphs = GlyphBrushBuilder::using_font_bytes(ft)
.initial_cache_size((256, 256))
.build(window.factory.clone());
let mut cpu_renderer = CPURenderer::new(&cpu);
// Main loop // Main loop
let mut run = false;
while let Some(event) = events.next(&mut window) { while let Some(event) = events.next(&mut window) {
if let Some(_) = event.render_args() { if let Some(_) = event.render_args() {
render(&mut window, &event, &mut glyphs, &cpu, &bus, &disasm); cpu_renderer.update(&cpu);
render(&mut window, &event, &mut glyphs, &mut cpu_renderer, &bus, &disasm);
}
if let Some(_) = event.update_args() {
if run {
cpu.clock(&mut bus);
// while cpu.is_ahead() {
// cpu.clock(&mut bus);
// }
}
} }
if let Some(Button::Keyboard(key)) = event.press_args() { if let Some(Button::Keyboard(key)) = event.press_args() {
match key { match key {
Key::C => cpu.clock(&mut bus), // advance one clock Key::C => cpu.clock(&mut bus), // advance one clock
Key::Space => { // advance to next instruction Key::S => { // advance to next instruction
cpu.clock(&mut bus); cpu.clock(&mut bus);
while cpu.is_ahead() { while cpu.is_ahead() {
cpu.clock(&mut bus); cpu.clock(&mut bus);
} }
} }
Key::R => cpu.reset(&mut bus), Key::R => cpu.reset(&mut bus),
Key::Space => run = !run,
Key::Up => {
event_settings.ups = (event_settings.ups as f64 * 1.1) as u64 + 1;
events = Events::new(event_settings);
debug!("UPS: {}", event_settings.ups);
}
Key::Down => {
event_settings.ups = (event_settings.ups as f64 * 0.91) as u64;
events = Events::new(event_settings);
debug!("UPS: {}", event_settings.ups);
}
_ => { } _ => { }
} }
} }
} }
} }
fn render(window: &mut PistonWindow, event: &Event, glyphs: &mut Glyphs, cpu: &CPU, bus: &MemoryBus, disasm: &Disasm) { fn render(window: &mut PistonWindow, event: &Event,
glyphs: &mut GlyphBrush<Resources, Factory>,
cpu_renderer: &mut CPURenderer, bus: &MemoryBus, disasm: &Disasm) {
window.draw_2d(event, |c, g, d| { window.draw_2d(event, |c, g, d| {
clear([0.0, 0.0, 1.0, 1.0], g); clear([0.0, 0.0, 1.0, 1.0], g);
let debug_offset = [10.0, 10.0];
render_cpu(&c, g, glyphs, cpu, debug_offset);
render_disasm(&c, g, glyphs, disasm, cpu.regs.pc,
[debug_offset[0], debug_offset[1] + (7.0 * (FT_LINE_DISTANCE+FT_SIZE_PX))]);
render_memory(&c, g, glyphs, bus,
[debug_offset[0] + 300.0, debug_offset[1]]);
glyphs.factory.encoder.flush(d); // let debug_offset = [10.0, 10.0];
// render_cpu(&c, g, glyphs, cpu, debug_offset);
// render_disasm(&c, g, glyphs, disasm, cpu.regs.pc,
// [debug_offset[0], debug_offset[1] + (7.0 * (FT_LINE_DISTANCE+FT_SIZE_PX))]);
// render_memory(&c, g, glyphs, bus,
// [debug_offset[0] + 300.0, debug_offset[1]]);
// glyphs.factory.encoder.flush(d);
}); });
cpu_renderer.draw(glyphs);
glyphs.use_queue().draw(&mut window.encoder, &window.output_color);
window.encoder.flush(&mut window.device);
} }
fn render_cpu(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, cpu: &CPU, offset: [f64; 2]) { // fn render_cpu(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, cpu: &CPU, offset: [f64; 2]) {
let mut transform = c.transform // let mut transform = c.transform
.trans(offset[0], offset[1] + FT_SIZE_PX); // .trans(offset[0], offset[1] + FT_SIZE_PX);
let text_white = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT); // let text_white = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT);
let text_on = Text::new_color(FT_COLOR_GREEN, FT_SIZE_PT); // let text_on = Text::new_color(FT_COLOR_GREEN, FT_SIZE_PT);
let text_off = Text::new_color(FT_COLOR_RED, FT_SIZE_PT); // let text_off = Text::new_color(FT_COLOR_RED, FT_SIZE_PT);
let mut text = text_white; // let mut text = text_white;
text.draw( // text.draw(
&"Flags:", // &"Flags:",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(70.0, 0.0); // transform = transform.trans(70.0, 0.0);
text = if cpu.get_flag(NEGATIVE) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(NEGATIVE) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"N", // &"N",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(OVERFLOW) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(OVERFLOW) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"V", // &"V",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text_white.draw( // text_white.draw(
&"-", // &"-",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(BREAK) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(BREAK) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"B", // &"B",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(DECIMAL) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(DECIMAL) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"D", // &"D",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(IRQ) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(IRQ) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"I", // &"I",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(ZERO) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(ZERO) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"Z", // &"Z",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text = if cpu.get_flag(CARRY) == 1 { text_on } else { text_off }; // text = if cpu.get_flag(CARRY) == 1 { text_on } else { text_off };
text.draw( // text.draw(
&"C", // &"C",
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
transform = transform.trans(16.0, 0.0); // transform = transform.trans(16.0, 0.0);
text_white.draw( // text_white.draw(
&format!("({:#4x})", cpu.regs.flags), // &format!("({:#4x})", cpu.regs.flags),
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
let cpu_register_texts = [ // let cpu_register_texts = [
&format!("A: {0:#x} ({0})", cpu.regs.a), // &format!("A: {0:#x} ({0})", cpu.regs.a),
&format!("X: {0:#x} ({0})", cpu.regs.x), // &format!("X: {0:#x} ({0})", cpu.regs.x),
&format!("Y: {0:#x} ({0})", cpu.regs.y), // &format!("Y: {0:#x} ({0})", cpu.regs.y),
&format!("Stack P: {0:#x} ({0})", cpu.regs.sp), // &format!("Stack P: {0:#x} ({0})", cpu.regs.sp),
&format!("Program P: {:#x}", cpu.regs.pc), // &format!("Program P: {:#x}", cpu.regs.pc),
]; // ];
for (i, &text) in cpu_register_texts.iter().enumerate() { // for (i, &text) in cpu_register_texts.iter().enumerate() {
let y_offset = (i+2) as f64 * (FT_LINE_DISTANCE + FT_SIZE_PX); // let y_offset = (i+2) as f64 * (FT_LINE_DISTANCE + FT_SIZE_PX);
let transform = c.transform.trans(offset[0], offset[1] + y_offset); // let transform = c.transform.trans(offset[0], offset[1] + y_offset);
text_white.draw( // text_white.draw(
&text, // &text,
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
} // }
} // }
fn render_disasm(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, disasm: &Disasm, pc: Addr, offset: [f64; 2]) { // fn render_disasm(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, disasm: &Disasm, pc: Addr, offset: [f64; 2]) {
let pc_position = disasm.addresses.iter().position(|&pos| pos == pc); // let pc_position = disasm.addresses.iter().position(|&pos| pos == pc);
if let None = pc_position { // if let None = pc_position {
return; // return;
} // }
let pc_position = pc_position.unwrap(); // let pc_position = pc_position.unwrap();
let lines_above_below: usize = 12; // let lines_above_below: usize = 12;
let start = if (pc_position as i32 - lines_above_below as i32) < 0 { // let start = if (pc_position as i32 - lines_above_below as i32) < 0 {
0 // 0
} else { // } else {
pc_position - lines_above_below // pc_position - lines_above_below
}; // };
let mut transform = c.transform.trans(offset[0], offset[1]); // let mut transform = c.transform.trans(offset[0], offset[1]);
let text_current = Text::new_color(FT_COLOR_RED, FT_SIZE_PT); // let text_current = Text::new_color(FT_COLOR_RED, FT_SIZE_PT);
let text_other = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT); // let text_other = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT);
for i in (start..disasm.addresses.len()).take(lines_above_below*2+1) { // for i in (start..disasm.addresses.len()).take(lines_above_below*2+1) {
let addr = disasm.addresses[i]; // let addr = disasm.addresses[i];
let txt = &disasm.instructions[i]; // let txt = &disasm.instructions[i];
transform = transform.trans(0.0, FT_LINE_DISTANCE + FT_SIZE_PX); // transform = transform.trans(0.0, FT_LINE_DISTANCE + FT_SIZE_PX);
let text = if addr == pc { // let text = if addr == pc {
text_current // text_current
} else { // } else {
text_other // text_other
}; // };
text.draw( // text.draw(
txt, // txt,
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform, // transform,
g // g
).unwrap(); // ).unwrap();
} // }
} // }
fn render_memory(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, bus: &MemoryBus, offset: [f64; 2]) { // fn render_memory(c: &Context, g: &mut G2d, glyphs: &mut Glyphs, bus: &MemoryBus, offset: [f64; 2]) {
let mut transform_y = c.transform.trans(offset[0], offset[1]); // let mut transform_y = c.transform.trans(offset[0], offset[1]);
let text = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT); // let text = Text::new_color(FT_COLOR_WHITE, FT_SIZE_PT);
for page in (0x0000..0x01FF).step_by(16) { // for page in (0x0000..0x01FF).step_by(16) {
transform_y = transform_y.trans(0.0, FT_LINE_DISTANCE+FT_SIZE_PX); // transform_y = transform_y.trans(0.0, FT_LINE_DISTANCE+FT_SIZE_PX);
text.draw( // text.draw(
&format!("{:#06x}:", page), // &format!("{:#06x}:", page),
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform_y, // transform_y,
g // g
).unwrap(); // ).unwrap();
let mut transform_x = transform_y.trans(40.0, 0.0); // let mut transform_x = transform_y.trans(40.0, 0.0);
for offset in 0u16..16u16 { // for offset in 0u16..16u16 {
transform_x = transform_x.trans(20.0, 0.0); // transform_x = transform_x.trans(20.0, 0.0);
let addr = page + offset; // let addr = page + offset;
text.draw( // text.draw(
&format!("{:02x}", bus.readb(addr)), // &format!("{:02x}", bus.readb(addr)),
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform_x, // transform_x,
g // g
).unwrap(); // ).unwrap();
} // }
} // }
transform_y = transform_y.trans(0.0, (FT_LINE_DISTANCE+FT_SIZE_PX) * 1.5); // transform_y = transform_y.trans(0.0, (FT_LINE_DISTANCE+FT_SIZE_PX) * 1.5);
for page in (0x6000..0x6030).step_by(16) { // for page in (0x6000..0x6030).step_by(16) {
transform_y = transform_y.trans(0.0, (FT_LINE_DISTANCE+FT_SIZE_PX)); // transform_y = transform_y.trans(0.0, (FT_LINE_DISTANCE+FT_SIZE_PX));
text.draw( // text.draw(
&format!("{:#06x}:", page), // &format!("{:#06x}:", page),
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform_y, // transform_y,
g // g
).unwrap(); // ).unwrap();
let mut transform_x = transform_y.trans(40.0, 0.0); // let mut transform_x = transform_y.trans(40.0, 0.0);
for offset in 0u16..16u16 { // for offset in 0u16..16u16 {
transform_x = transform_x.trans(20.0, 0.0); // transform_x = transform_x.trans(20.0, 0.0);
let addr = page + offset; // let addr = page + offset;
text.draw( // text.draw(
&format!("{:02x}", bus.readb(addr)), // &format!("{:02x}", bus.readb(addr)),
glyphs, // glyphs,
&c.draw_state, // &c.draw_state,
transform_x, // transform_x,
g // g
).unwrap(); // ).unwrap();
} // }
} // }
} // }

View File

@@ -454,8 +454,12 @@ impl CPU {
unimplemented!() unimplemented!()
} }
fn op_INC<T: Memory>(&mut self, bus: &T, val: Word) { fn op_INC<T: Memory>(&mut self, bus: &mut T, addr: Word) {
unimplemented!() let val = self.readb(bus, addr);
let val = val.wrapping_add(1);
self.writeb(bus, addr, val);
self.set_flag(ZERO, val == 0);
self.set_flag(NEGATIVE, (val & 0x80) != 0)
} }
fn op_INX<T: Memory>(&mut self, bus: &T) { fn op_INX<T: Memory>(&mut self, bus: &T) {

42
src/render.rs Normal file
View File

@@ -0,0 +1,42 @@
use gfx_device_gl::Factory;
use gfx_device_gl::Resources;
use crate::nes::cpu::CPU;
use gfx_glyph::{Section,GlyphBrush};
pub trait Draw {
fn draw(&mut self, glyphs: &mut GlyphBrush<Resources,Factory>);
}
pub struct CPURenderer<'a> {
registers_text: String,
registers_section: Section<'a>,
}
impl<'a> CPURenderer<'a> {
pub fn new(cpu: &CPU) -> Self {
let registers_text = String::from("A: 0x00 (000)");
let registers_section = Section {
text: "xxx",
screen_position: (100.0, 100.0),
color: [1.0; 4],
..Section::default()
};
CPURenderer {
registers_text: registers_text,
registers_section: registers_section,
}
}
}
impl<'a> CPURenderer<'a> {
pub fn update(&mut self, cpu: &CPU) {
self.registers_text.replace_range(3..7, "txtx");
// self.registers_section.text = &self.registers_text;
}
}
impl<'a> Draw for CPURenderer<'a> {
fn draw(&mut self, glyphs: &mut GlyphBrush<Resources,Factory>) {
glyphs.queue(self.registers_section);
}
}