Skip to content

Commit

Permalink
remove need for . in symbol names, expr registers now called .xr,.pc etc
Browse files Browse the repository at this point in the history
  • Loading branch information
pm100 committed Jan 7, 2024
1 parent 65e48f8 commit 5b8f5d2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 35 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,20 @@ loads a binary file that was output by ld65 for sim65. It expects to see the sim

loads symbol file output by ld65 for VICE. Generated by ld65 switches `-g -Ln <file>`


`>> ll <file name>`

you dont need to load symbols but its much easier with symbols

### list symbols (ls)

List symbols, option matching a substring

`>> ls [str]`

list all symbols containg the substring 'main' - `ls main`


### run

runs the code starting at the address found in the binary file header
Expand All @@ -135,7 +145,7 @@ Sets a breakpoint

Examples

`>> b ._main`
`>> b _main`

`>> b $27ba`

Expand Down Expand Up @@ -179,7 +189,7 @@ watch for memory read or write. Will break on the read or write of a location

example

`>> w -w .sreg`
`>> w -w sreg`

will break when a write it made to .sreg

Expand Down Expand Up @@ -237,15 +247,17 @@ Write one byte to memory

Expression evaluator. Anywhere that an address can be given you can have an expression

Registers are available they are called .ac, .pc, .xr, .xy., .sr, .sp

The expr command evaluates an expression, this can be useful for inspecting things or just checking expression syntax

An expression starts with '='. You can then have numbers, symbols, parantheses, registers, plus dereference operations

- `=xr` returns the x register
- `=.ptr1+0x20` returns that symbol plus 0x20
- `=@(.ptr1)` returns what ptr1 points at
- `=@ @(.ptr1)` returns what the ptr1 at ptr1 points to
- `=@(.ptr1+xr)` returns what ptr1 + xr points to
- `=.xr` returns the x register
- `=ptr1+0x20` returns that symbol plus 0x20
- `=@(ptr1)` returns what ptr1 points at
- `=@ @(ptr1)` returns what the ptr1 at ptr1 points to
- `=@(ptr1+.xr)` returns what ptr1 + xr points to

`@` is the dereference operation for a word

Expand All @@ -254,8 +266,9 @@ An expression starts with '='. You can then have numbers, symbols, parantheses,

Useful quickies

`dis =pc`
`expr =xr`
`dis =.pc`

`expr =.xr`

Note that you may need to enclose the whole expression in quotes so that it doesnt look like command arguments to the line parser

Expand Down
29 changes: 19 additions & 10 deletions src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ the same functionality as the cli shell.
*/

use anyhow::{anyhow, bail, Result};
use core::num;
use evalexpr::Value;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -144,7 +145,11 @@ impl Debugger {
let addr_str = spl.next().ok_or(anyhow!("invalid symbol file"))?.trim_end();
let name = spl.next().ok_or(anyhow!("invalid symbol file"))?.trim_end();
let addr = u16::from_str_radix(addr_str, 16)?;
self.symbols.insert(name.to_string(), addr);
if let Some(nm) = name.strip_prefix('.') {
self.symbols.insert(nm.to_string(), addr);
} else {
self.symbols.insert(name.to_string(), addr);
}
}
}
}
Expand Down Expand Up @@ -252,22 +257,26 @@ impl Debugger {
// if string starts with '$' it is a hex number
// else it is a decimal number
pub fn convert_addr(&self, addr_str: &str) -> Result<(u16, String)> {
if addr_str.starts_with('.') {
if let Some(sym) = self.symbols.get(addr_str) {
return Ok((*sym, addr_str.to_string()));
} else {
bail!("Symbol {} not found", addr_str);
}
}

// is this a hex number?
if let Some(hex) = addr_str.strip_prefix('$').or_else(|| {
addr_str
.strip_prefix("0x")
.or_else(|| addr_str.strip_prefix("0X"))
}) {
return Ok((u16::from_str_radix(hex, 16)?, String::new()));
}
Ok((addr_str.parse::<u16>()?, String::new()))

// a decimal number?
if addr_str.chars().next().unwrap().is_digit(10) {
return Ok((addr_str.parse::<u16>()?, String::new()));
}

// is it a symbol?
if let Some(sym) = self.symbols.get(addr_str) {
return Ok((*sym, addr_str.to_string()));
} else {
bail!("Symbol {} not found", addr_str);
}
}

// reverse of convert_addr.
Expand Down
12 changes: 6 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ impl DB65Context {
impl Context for DB65Context {
fn get_value(&self, key: &str) -> Option<&Value> {
match key {
"ac" => Some(&self.ac),
"xr" => Some(&self.xr),
"yr" => Some(&self.yr),
"sp" => Some(&self.sp),
"pc" => Some(&self.pc),
"sr" => Some(&self.sr),
".ac" => Some(&self.ac),
".xr" => Some(&self.xr),
".yr" => Some(&self.yr),
".sp" => Some(&self.sp),
".pc" => Some(&self.pc),
".sr" => Some(&self.sr),
_ => self.symbols.get(key),
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,21 @@ can be used to test an expression and also to inspect values.
Examples:
expr =0x20 evaluates to 0x20 (redundant)
expr =xr the xr register
expr =xr+1 the xr register plus 1
dis =pc-6 disassemble from pc-6
m =xr+0x20 display memory at xr+0x20
m .ptr display memory at pointer (raw symbols just work anyway)
m =@(.ptr) dereference a pointer
m =@(.ptr+0x20) do math on a pointer
m =@(.p1+(2*yr)) more math
p -s =@(.sreg) print a string pointed to by sreg, sreg+1
expr =.xr the xr register
expr =.xr+1 the xr register plus 1
dis =.pc-6 disassemble from pc-6
m =.xr+0x20 display memory at xr+0x20
m ptr display memory at pointer (raw symbols just work anyway)
m =@(ptr) dereference a pointer
m =@(ptr+0x20) do math on a pointer
m =@(p1+(2*.yr)) more math
p -s =@(sreg) print a string pointed to by sreg, sreg+1
@ is the dereference operator for a word
@b is the dereference operator for a byte
Note if there are spaces in the expression, you must quote it:
mem '=@(.ptr + 0x20)'
mem '=@(ptr + 0x20)'
"#,
),
Expand Down

0 comments on commit 5b8f5d2

Please sign in to comment.