Skip to content

Commit 75f9e9b

Browse files
committed
feat(registers): add flags
1 parent 26c9970 commit 75f9e9b

File tree

5 files changed

+135
-54
lines changed

5 files changed

+135
-54
lines changed

src/bus.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ pub struct Regs {
6161
pub cs: u16,
6262
pub ds: u16,
6363
pub es: u16,
64-
pub _fs: u16,
65-
pub _gs: u16,
64+
pub fs: u16,
65+
pub gs: u16,
6666
pub ss: u16,
67-
pub _cf: bool,
68-
pub _pf: bool,
69-
pub _af: bool,
67+
pub cf: bool,
68+
pub pf: bool,
69+
pub af: bool,
7070
pub zf: bool,
71-
pub _sf: bool,
72-
pub _tf: bool,
73-
pub _if: bool,
74-
pub _df: bool,
75-
pub _of: bool,
71+
pub sf: bool,
72+
pub tf: bool,
73+
pub r#if: bool,
74+
pub df: bool,
75+
pub of: bool,
7676
pub _iopl: u8,
7777
pub _nt: bool,
7878
pub _vm: bool,

src/tui/code.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ use crate::{
1515
},
1616
};
1717

18-
const FG_EIP: Colour = Colour::rgb(255, 0, 127);
19-
const STYLE_EIP: Style = Style::normal(super::BG_DARK, FG_EIP);
20-
2118
#[derive(Clone)]
2219
pub struct Properties {
2320
pub status: PaneStatus,
@@ -212,14 +209,14 @@ impl Component for Code {
212209
if let Some(e) = &self.error {
213210
return Text::with(
214211
TextProperties::new()
215-
.style(super::STYLE)
212+
.style(super::ST_NORMAL)
216213
.align(TextAlign::Centre)
217214
.content(e.to_string()),
218215
);
219216
}
220217

221218
let mut canvas = Canvas::new(self.frame.size);
222-
canvas.clear(super::STYLE);
219+
canvas.clear(super::ST_NORMAL);
223220

224221
let mut fmt = IntelFormatter::new();
225222
fmt.options_mut().set_space_after_operand_separator(true);
@@ -233,13 +230,13 @@ impl Component for Code {
233230
.enumerate()
234231
{
235232
let mut style = if ins.ip32() == self.props.addr.offset {
236-
STYLE_EIP
233+
super::ST_ACTIVE
237234
} else {
238-
super::STYLE
235+
super::ST_NORMAL
239236
};
240237

241238
if self.props.status.attached && self.pos == Some(y) {
242-
style.background = super::STYLE_SEL.background;
239+
style.background = super::ST_SELECTED.background;
243240

244241
canvas.clear_region(
245242
Rect::new(Position::new(0, y), Size::new(self.frame.size.width, 1)),

src/tui/data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ impl Component for Data {
196196
if let Some(e) = &self.error {
197197
return Text::with(
198198
TextProperties::new()
199-
.style(super::STYLE)
199+
.style(super::ST_NORMAL)
200200
.align(TextAlign::Centre)
201201
.content(e.to_string()),
202202
);
203203
}
204204

205205
let mut canvas = Canvas::new(self.frame.size);
206-
canvas.clear(super::STYLE);
206+
canvas.clear(super::ST_NORMAL);
207207

208208
for (y, bytes) in self.data.chunks(BYTES_PER_LINE).skip(self.skip).enumerate() {
209-
let mut style = super::STYLE;
209+
let mut style = super::ST_NORMAL;
210210

211211
if self.pos == Some(y) {
212-
style.background = super::STYLE_SEL.background;
212+
style.background = super::ST_SELECTED.background;
213213

214214
canvas.clear_region(
215215
Rect::new(Position::new(0, y), Size::new(self.frame.size.width, 1)),

src/tui/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ pub mod status_bar;
88

99
const BG_GRAY: Colour = Colour::rgb(33, 34, 44);
1010
const BG_DARK: Colour = Colour::rgb(14, 20, 25);
11-
const FG_GRAY: Colour = Colour::rgb(248, 248, 242);
12-
const STYLE: Style = Style::normal(BG_DARK, FG_GRAY);
13-
const STYLE_SEL: Style = Style::normal(BG_GRAY, FG_GRAY);
11+
const FG_GRAY: Colour = Colour::rgb(224, 224, 224);
12+
13+
const ST_NORMAL: Style = Style::normal(BG_DARK, FG_GRAY);
14+
const ST_SELECTED: Style = Style::normal(BG_GRAY, FG_GRAY);
15+
const ST_CAPTION: Style = Style::normal(BG_DARK, Colour::rgb(127, 109, 92));
16+
const ST_CHANGED: Style = Style::normal(BG_DARK, Colour::rgb(170, 170, 255));
17+
const ST_ACTIVE: Style = Style::normal(BG_DARK, Colour::rgb(255, 0, 127));
1418

1519
#[derive(Clone, PartialEq, Eq)]
1620
pub struct PaneStatus {

src/tui/registers.rs

Lines changed: 109 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use zi::prelude::*;
22

33
use crate::bus::Regs;
44

5-
// const FG_CHANGED: Colour = Colour::rgb(84, 252, 84);
6-
75
pub struct Registers {
86
regs: Regs,
7+
prev: Regs,
98
frame: Rect,
109
}
1110

@@ -14,54 +13,135 @@ impl Component for Registers {
1413
type Properties = Regs;
1514

1615
fn create(regs: Self::Properties, frame: Rect, _: ComponentLink<Self>) -> Self {
17-
Self { regs, frame }
16+
Self {
17+
regs,
18+
prev: regs,
19+
frame,
20+
}
1821
}
1922

2023
fn change(&mut self, regs: Self::Properties) -> ShouldRender {
21-
if self.regs != regs {
22-
self.regs = regs;
23-
24-
true
25-
} else {
26-
false
24+
if self.regs == regs {
25+
return false.into();
2726
}
28-
.into()
27+
28+
self.prev = self.regs;
29+
self.regs = regs;
30+
31+
true.into()
2932
}
3033

3134
fn view(&self) -> Layout {
32-
let r = self.regs;
35+
let (r, p) = (self.regs, self.prev);
3336

3437
let regs = [
35-
[("EAX", r.eax), ("EBX", r.ebx), ("ECX", r.ecx), ("EDX", r.edx)],
36-
[("ESI", r.esi), ("EDI", r.edi), ("EBP", r.ebp), ("ESP", r.esp)],
3738
[
38-
("CS", r.cs.into()),
39-
("DS", r.ds.into()),
40-
("ES", r.es.into()),
41-
("SS", r.ss.into()),
39+
("EAX", r.eax, p.eax),
40+
("EBX", r.ebx, p.ebx),
41+
("ECX", r.ecx, p.ecx),
42+
("EDX", r.edx, p.edx),
43+
],
44+
[
45+
("ESI", r.esi, p.esi),
46+
("EDI", r.edi, p.edi),
47+
("EBP", r.ebp, p.ebp),
48+
("ESP", r.esp, p.esp),
49+
],
50+
[
51+
("CS", r.cs.into(), p.cs.into()),
52+
("DS", r.ds.into(), p.ds.into()),
53+
("ES", r.es.into(), p.es.into()),
54+
("SS", r.ss.into(), p.ss.into()),
4255
],
4356
];
4457

4558
let mut canvas = Canvas::new(self.frame.size);
46-
canvas.clear(super::STYLE);
59+
canvas.clear(super::ST_NORMAL);
4760

4861
let col_width = self.frame.size.width / regs.len();
4962

5063
for (x, col) in regs.iter().enumerate() {
51-
for (y, (name, value)) in col.iter().enumerate() {
52-
canvas.draw_str(
53-
x * col_width,
54-
y,
55-
super::STYLE,
56-
&if name.len() == 2 {
57-
format!("{name}={value:04X}")
58-
} else {
59-
format!("{name}={value:08X}")
60-
},
61-
);
64+
for (y, (name, value, prev)) in col.iter().enumerate() {
65+
print_reg(&mut canvas, x * col_width, y, name, *value, *prev);
6266
}
6367
}
6468

69+
let y = regs[0].len() + 1;
70+
print_reg(&mut canvas, 0, y, "EIP", r.eip, p.eip);
71+
print_reg(&mut canvas, col_width, y, "FS", r.fs.into(), p.fs.into());
72+
print_reg(&mut canvas, col_width * 2, y, "GS", r.gs.into(), p.gs.into());
73+
74+
let regs = [
75+
("C", r.cf, p.cf),
76+
("Z", r.zf, p.zf),
77+
("S", r.sf, p.sf),
78+
("O", r.of, p.of),
79+
("A", r.af, p.af),
80+
("P", r.pf, p.pf),
81+
("D", r.df, p.df),
82+
("I", r.r#if, p.r#if),
83+
("T", r.tf, p.tf),
84+
];
85+
86+
let y = y + 2;
87+
88+
for (x, (name, value, prev)) in regs.into_iter().enumerate() {
89+
let x = x * 4;
90+
91+
canvas.draw_str(x, y, super::ST_CAPTION, name);
92+
canvas.draw_str(
93+
x + 1,
94+
y,
95+
if value != prev {
96+
super::ST_ACTIVE
97+
} else if value {
98+
super::ST_CHANGED
99+
} else {
100+
super::ST_NORMAL
101+
},
102+
if value { "1" } else { "0" },
103+
);
104+
}
105+
65106
canvas.into()
66107
}
67108
}
109+
110+
fn print_reg(canvas: &mut Canvas, x: usize, y: usize, name: &str, value: u32, prev: u32) {
111+
let mut x = x;
112+
113+
if value != prev {
114+
let (val, pre) = &if name.len() == 2 {
115+
(format!("{value:04X}"), format!("{prev:04X}"))
116+
} else {
117+
(format!("{value:08X}"), format!("{prev:08X}"))
118+
};
119+
120+
let i = val
121+
.chars()
122+
.zip(pre.chars())
123+
.enumerate()
124+
.find_map(|(i, (v, p))| if v != p { Some(i) } else { None });
125+
126+
canvas.draw_str(x, y, super::ST_CAPTION, name);
127+
x += name.len() + 1;
128+
129+
if let Some(i) = i {
130+
canvas.draw_str(x, y, super::ST_CHANGED, &val[..i]);
131+
x += i;
132+
canvas.draw_str(x, y, super::ST_ACTIVE, &val[i..]);
133+
} else {
134+
canvas.draw_str(x, y, super::ST_NORMAL, val);
135+
}
136+
} else {
137+
let val = &if name.len() == 2 {
138+
format!("{value:04X}")
139+
} else {
140+
format!("{value:08X}")
141+
};
142+
143+
canvas.draw_str(x, y, super::ST_CAPTION, name);
144+
x += name.len() + 1;
145+
canvas.draw_str(x, y, super::ST_NORMAL, val);
146+
}
147+
}

0 commit comments

Comments
 (0)