Skip to content

Commit

Permalink
[cpclib-asm] Add STEP parameter to breakpoint as in EdouardBERGE/rasm@7…
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty/Benediction committed Nov 19, 2024
1 parent fd67d08 commit a536cfe
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 20 deletions.
11 changes: 10 additions & 1 deletion cpclib-asm/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ impl Env {
value_mask: Option<&E>,
condition: Option<&E>,
name: Option<&E>,
step: Option<&E>,
span: Option<&Z80Span>
) -> Result<(), AssemblerError> {
let brk = if r#type.is_none()
Expand All @@ -1953,6 +1954,7 @@ impl Env {
&& value_mask.is_none()
&& condition.is_none()
&& name.is_none()
&& step.is_none()
{
// here we manipulate a very simple breakpoint
let (current_address, page): (u16, u8) = if let Some(exp) = address {
Expand Down Expand Up @@ -2040,6 +2042,11 @@ impl Env {
.resolve_expr_may_fail_in_first_pass(value_mask)?
.int()? as u8;
}
if let Some(step) = step {
brk.step = Some(self
.resolve_expr_may_fail_in_first_pass(step)?
.int()? as _);
}
if let Some(condition) = condition {
let cond = self.resolve_expr_may_fail_in_first_pass(condition)?;
let cond = cond.string()?;
Expand Down Expand Up @@ -3474,7 +3481,8 @@ macro_rules! visit_token_impl {
value,
value_mask,
condition,
name
name,
step
} => {
$env.visit_breakpoint(
address.as_ref(),
Expand All @@ -3487,6 +3495,7 @@ macro_rules! visit_token_impl {
value_mask.as_ref(),
condition.as_ref(),
name.as_ref(),
step.as_ref(),
$span
)
},
Expand Down
3 changes: 2 additions & 1 deletion cpclib-asm/src/parser/obtained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@ pub enum LocatedTokenInner {
value: Option<LocatedExpr>,
value_mask: Option<LocatedExpr>,
condition: Option<LocatedExpr>,
name: Option<LocatedExpr>
name: Option<LocatedExpr>,
step: Option<LocatedExpr>
},
BuildCpr,
BuildSna(Option<SnapshotVersion>),
Expand Down
45 changes: 34 additions & 11 deletions cpclib-asm/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
let value_mask = Rc::new(RefCell::new(None));
let condition = Rc::new(RefCell::new(None));
let name = Rc::new(RefCell::new(None));
let step = Rc::new(RefCell::new(None));

let first = std::rc::Rc::new(std::cell::RefCell::new(true));

Expand All @@ -2850,7 +2851,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Address { arg, value } => {
let mut address = address.borrow_mut();
let address = address.deref_mut();
if let Some(address) = address {
if address.is_some() {
false
}
else {
Expand All @@ -2862,7 +2863,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Type { arg, value } => {
let mut r#type = r#type.borrow_mut();
let r#type = r#type.deref_mut();
if let Some(r#type) = r#type {
if r#type.is_some() {
false
}
else {
Expand All @@ -2874,7 +2875,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Access { arg, value } => {
let mut access = access.borrow_mut();
let access = access.deref_mut();
if let Some(access) = access {
if access.is_some() {
false
}
else {
Expand All @@ -2886,7 +2887,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Run { arg, value } => {
let mut run = run.borrow_mut();
let run = run.deref_mut();
if let Some(run) = run {
if run.is_some() {
false
}
else {
Expand All @@ -2898,7 +2899,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Mask { arg, value } => {
let mut item = mask.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
Expand All @@ -2910,7 +2911,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Size { arg, value } => {
let mut item = size.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
Expand All @@ -2922,7 +2923,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Value { arg, value: val } => {
let mut item = value.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
Expand All @@ -2934,7 +2935,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::ValueMask { arg, value } => {
let mut item = value_mask.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
Expand All @@ -2946,7 +2947,7 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Name { arg, value } => {
let mut item = name.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
Expand All @@ -2958,14 +2959,26 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
BreakPointArgument::Condition { arg, value } => {
let mut item = condition.borrow_mut();
let item = item.deref_mut();
if let Some(item) = item {
if item.is_some() {
false
}
else {
item.replace((*arg, value.clone()));
true
}
},

BreakPointArgument::Step { arg, value } => {
let mut item = step.borrow_mut();
let item = item.deref_mut();
if item.is_some() {
false
} else {
item.replace((*arg, value.clone()));
true
}
},

_ => true // TODO implement the tests
}
}
Expand Down Expand Up @@ -2997,7 +3010,8 @@ pub fn parse_breakpoint(input: &mut InnerZ80Span) -> PResult<LocatedTokenInner,
.into_inner()
.map(|a| a.1),
condition: Rc::into_inner(condition).unwrap().into_inner().map(|a| a.1),
name: Rc::into_inner(name).unwrap().into_inner().map(|a| a.1)
name: Rc::into_inner(name).unwrap().into_inner().map(|a| a.1),
step: Rc::into_inner(step).unwrap().into_inner().map(|a| a.1)
};

Ok(brk)
Expand Down Expand Up @@ -3044,6 +3058,10 @@ pub enum BreakPointArgument {
Name {
arg: InnerZ80Span,
value: LocatedExpr
},
Step {
arg: InnerZ80Span,
value: LocatedExpr
}
}

Expand All @@ -3070,6 +3088,8 @@ pub fn parse_breakpoint_argument(
.map(|(k, v)| BreakPointArgument::Value { arg: k, value: v }),
parse_argname_and_value("VALMASK", &located_expr)
.map(|(k, v)| BreakPointArgument::ValueMask { arg: k, value: v }),
parse_argname_and_value("STEP", &located_expr)
.map(|(k, v)| BreakPointArgument::Step { arg: k, value: v }),
parse_argname_and_value("CONDITION", &located_expr)
.map(|(k, v)| BreakPointArgument::Condition { arg: k, value: v }),
parse_argname_and_value("NAME", &located_expr)
Expand Down Expand Up @@ -6552,6 +6572,9 @@ endif"
assert!(dbg!(parse_test(parse_breakpoint, "VALMASK=1")).is_ok());
assert!(dbg!(parse_test(parse_breakpoint, "condition=\"fdfdfd\"")).is_ok());
assert!(dbg!(parse_test(parse_breakpoint, "name=\"fdfdfd\"")).is_ok());

assert!(dbg!(parse_test(parse_breakpoint, "step=10,name=\"fdfdfd\"")).is_ok());

}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion cpclib-basm/tests/asm/good_breakpoint.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ label
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5, valmask=5
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5, valmask=5, condition="HL=5"
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5, valmask=5, condition="HL=5", name="hello"
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5, valmask=5, condition="HL=5", name="hello"
breakpoint type=mem, access=write, runmode=stop, mask=&ff00, size=10, value=5, valmask=5, condition="HL=5", name="hello", step=30
3 changes: 2 additions & 1 deletion cpclib-basm/tests/asm/rasm_comparison/breakpoint.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ org 0
; on doit avoir 3 breakpoints
BREAKPOINT EXEC,ADDR=100
BREAKPOINT name="breakpoint1",condition="C3H<>22",addr=$
BREAKPOINT addr=2,mask=0x00ff
BREAKPOINT addr=2,mask=0x00ff
BREAKPOINT addr=20,step=5
14 changes: 10 additions & 4 deletions cpclib-sna/src/chunks/remu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ pub struct AdvancedRemuBreakPoint {
pub value: u8,
pub val_mask: u8,
pub condition: Option<String127>,
pub name: Option<String127>
pub name: Option<String127>,
pub step: Option<u16>
}

impl Default for AdvancedRemuBreakPoint {
Expand All @@ -80,7 +81,8 @@ impl Default for AdvancedRemuBreakPoint {
value: 0,
val_mask: 0,
condition: None,
name: None
name: None,
step: None
}
}
}
Expand All @@ -90,7 +92,7 @@ impl Display for AdvancedRemuBreakPoint {
let brk = self;
write!(
f,
"{},{},{},addr={},mask={},size={},value={},valmask={},name={},condition={}",
"{},{},{},addr={},mask={},size={},value={},valmask={},name={},condition={},step={}",
<&RemuBreakPointType as Into<&'static str>>::into(&brk.brk_type),
<&RemuBreakPointAccessMode as Into<&'static str>>::into(&brk.access_mode),
<&RemuBreakPointRunMode as Into<&'static str>>::into(&brk.run_mode),
Expand All @@ -106,7 +108,11 @@ impl Display for AdvancedRemuBreakPoint {
brk.condition
.as_ref()
.map(|s| format!("\"{}\"", s.as_ref()))
.unwrap_or("".to_owned())
.unwrap_or("".to_owned()),
brk.step
.as_ref()
.map(|s| format!("{s}"))
.unwrap_or("".to_owned()),
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion cpclib-tokens/src/tokens/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ pub enum Token {
value: Option<Expr>,
value_mask: Option<Expr>,
condition: Option<Expr>,
name: Option<Expr>
name: Option<Expr>,
step: Option<Expr>
},
BuildCpr,
BuildSna(Option<SnapshotVersion>),
Expand Down

0 comments on commit a536cfe

Please sign in to comment.