@@ -8,24 +8,26 @@ use zi::{
8
8
9
9
use crate :: {
10
10
bus:: Proxy ,
11
- x86:: dec:: { fetch_after, fetch_before} ,
11
+ tui:: PaneStatus ,
12
+ x86:: {
13
+ dec:: { fetch_after, fetch_before} ,
14
+ Address ,
15
+ } ,
12
16
} ;
13
17
14
- const FG_EIP : Colour = Colour :: rgb ( 139 , 233 , 253 ) ;
18
+ const FG_EIP : Colour = Colour :: rgb ( 255 , 0 , 127 ) ;
15
19
const STYLE_EIP : Style = Style :: normal ( super :: BG_DARK , FG_EIP ) ;
16
20
17
21
#[ derive( Clone ) ]
18
22
pub struct Properties {
23
+ pub status : PaneStatus ,
19
24
pub proxy : Rc < Proxy > ,
20
- pub attached : bool ,
21
- pub focused : bool ,
22
- pub cs : u16 ,
23
- pub eip : u32 ,
25
+ pub addr : Address ,
24
26
}
25
27
26
28
impl PartialEq for Properties {
27
29
fn eq ( & self , other : & Properties ) -> bool {
28
- self . attached == other. attached && self . focused == other. focused && self . cs == other . cs && self . eip == other . eip
30
+ self . status == other. status && self . addr == other. addr
29
31
}
30
32
}
31
33
@@ -50,10 +52,10 @@ impl Component for Code {
50
52
type Properties = Properties ;
51
53
52
54
fn create ( props : Self :: Properties , frame : Rect , _: ComponentLink < Self > ) -> Self {
53
- let ( code, error) = if !props. attached {
55
+ let ( code, error) = if !props. status . attached {
54
56
( Vec :: new ( ) , Some ( anyhow ! ( "Not attached." ) ) )
55
57
} else {
56
- match fetch_after ( & props. proxy , ( props. cs , props . eip ) . into ( ) , frame. size . height ) {
58
+ match fetch_after ( & props. proxy , props. addr , frame. size . height ) {
57
59
Ok ( c) => ( c, None ) ,
58
60
Err ( e) => ( Vec :: new ( ) , Some ( e) ) ,
59
61
}
@@ -70,29 +72,52 @@ impl Component for Code {
70
72
}
71
73
72
74
fn change ( & mut self , props : Self :: Properties ) -> ShouldRender {
73
- if self . props != props {
75
+ if self . props == props {
76
+ return false . into ( ) ;
77
+ }
78
+
79
+ if !props. status . attached {
74
80
self . props = props;
81
+ return true . into ( ) ;
82
+ }
75
83
76
- if self . props . attached && self . code . is_empty ( ) {
77
- match fetch_after (
78
- & self . props . proxy ,
79
- ( self . props . cs , self . props . eip ) . into ( ) ,
80
- self . frame . size . height ,
81
- ) {
82
- Ok ( c) => self . code = c,
83
- Err ( e) => self . error = Some ( e) ,
84
+ const BOTTOM_PADDING : usize = 4 ; // number of extra rows on the botoom
85
+ let limit = self . frame . height ( ) ;
86
+ let pad = limit. saturating_sub ( BOTTOM_PADDING ) ;
87
+
88
+ let start = self
89
+ . code
90
+ . iter ( )
91
+ . skip ( self . skip )
92
+ . take ( limit)
93
+ . enumerate ( )
94
+ . map ( |( i, ( ins, _) ) | ( i, ins. ip32 ( ) ) )
95
+ . find_map ( |( i, ip) | {
96
+ if ip == props. addr . offset {
97
+ self . code . get ( self . skip + i. saturating_sub ( pad) ) . map ( |( x, _) | x. ip32 ( ) )
98
+ } else {
99
+ None
84
100
}
85
- }
101
+ } )
102
+ . unwrap_or ( props. addr . offset ) ;
86
103
87
- true
88
- } else {
89
- false
104
+ match fetch_after ( & props. proxy , ( props. addr . segment , start) . into ( ) , limit) {
105
+ Ok ( c) => {
106
+ self . code = c;
107
+ self . skip = 0 ;
108
+ self . pos = None ;
109
+ self . error = None ;
110
+ }
111
+ Err ( e) => self . error = Some ( e) ,
90
112
}
91
- . into ( )
113
+
114
+ self . props = props;
115
+
116
+ true . into ( )
92
117
}
93
118
94
119
fn update ( & mut self , message : Self :: Message ) -> ShouldRender {
95
- if !self . props . attached {
120
+ if !self . props . status . attached {
96
121
return false . into ( ) ;
97
122
}
98
123
@@ -111,7 +136,7 @@ impl Component for Code {
111
136
if let Some ( offset) = self . code . first ( ) . map ( |( i, _) | i. ip32 ( ) ) {
112
137
match fetch_before (
113
138
& self . props . proxy ,
114
- ( self . props . cs , offset) . into ( ) ,
139
+ ( self . props . addr . segment , offset) . into ( ) ,
115
140
self . frame . size . height ,
116
141
) {
117
142
Ok ( mut c) if !c. is_empty ( ) => {
@@ -143,7 +168,7 @@ impl Component for Code {
143
168
if let Some ( offset) = self . code . last ( ) . map ( |( i, _) | i. next_ip32 ( ) ) {
144
169
match fetch_after (
145
170
& self . props . proxy ,
146
- ( self . props . cs , offset) . into ( ) ,
171
+ ( self . props . addr . segment , offset) . into ( ) ,
147
172
self . frame . size . height ,
148
173
) {
149
174
Ok ( c) if !c. is_empty ( ) => {
@@ -171,7 +196,7 @@ impl Component for Code {
171
196
}
172
197
173
198
fn bindings ( & self , bindings : & mut Bindings < Self > ) {
174
- bindings. set_focus ( self . props . focused ) ;
199
+ bindings. set_focus ( self . props . status . focused ) ;
175
200
176
201
if !bindings. is_empty ( ) {
177
202
return ;
@@ -207,13 +232,13 @@ impl Component for Code {
207
232
. take ( self . frame . size . height )
208
233
. enumerate ( )
209
234
{
210
- let mut style = if ins. ip32 ( ) == self . props . eip {
235
+ let mut style = if ins. ip32 ( ) == self . props . addr . offset {
211
236
STYLE_EIP
212
237
} else {
213
238
super :: STYLE
214
239
} ;
215
240
216
- if self . props . attached && self . pos == Some ( y) {
241
+ if self . props . status . attached && self . pos == Some ( y) {
217
242
style. background = super :: STYLE_SEL . background ;
218
243
219
244
canvas. clear_region (
@@ -222,7 +247,7 @@ impl Component for Code {
222
247
) ;
223
248
}
224
249
225
- canvas. draw_str ( 0 , y, style, & format ! ( "{:04X}" , self . props. cs ) ) ;
250
+ canvas. draw_str ( 0 , y, style, & format ! ( "{:04X}" , self . props. addr . segment ) ) ;
226
251
canvas. draw_str ( 6 , y, style, & format ! ( "{:04X}" , ins. ip16( ) ) ) ;
227
252
canvas. draw_str (
228
253
12 ,
0 commit comments