Skip to content

Commit f9cab20

Browse files
committed
add dasm command to repl
1 parent 5d2e3e1 commit f9cab20

File tree

3 files changed

+22
-38
lines changed

3 files changed

+22
-38
lines changed

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn peek(
3030
} else {
3131
matrix65::io::hexdump(&bytes, 8);
3232
}
33-
},
33+
}
3434
};
3535
Ok(())
3636
}

src/lib/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
//! Routines for file; url; and terminal I/O
1616
17-
use disasm6502;
1817
use anyhow::Result;
1918
use cbm::disk;
2019
use cbm::disk::file::FileOps;
20+
use disasm6502;
2121
use log::debug;
2222
use std::fs::File;
2323
use std::io::{self, Read, Write};
@@ -172,4 +172,4 @@ pub fn disassemble(bytes: &[u8], start_address: u32) {
172172
for i in instructions {
173173
println!("{}", i);
174174
}
175-
}
175+
}

src/repl.rs

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,65 +35,49 @@ pub fn start_repl(port: &mut Box<dyn SerialPort>) -> Result<()> {
3535
repl.run()
3636
}
3737

38-
/// Wrap peek command
39-
fn peek(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
40-
let address = _args.value_of("address").unwrap().to_string();
41-
let length = _args.value_of("length").unwrap_or("1").to_string().parse::<usize>()?;
42-
match commands::peek(context.port, address, length, None, true) {
38+
/// Helper function to convert error type
39+
fn handle_result(result: core::result::Result<(), anyhow::Error>) -> Result<Option<String>> {
40+
match result {
4341
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
4442
err.to_string(),
4543
)),
4644
Ok(()) => Ok(None),
4745
}
4846
}
4947

48+
/// Wrap peek command
49+
fn peek(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
50+
let address = _args.value_of("address").unwrap().to_string();
51+
let length = _args
52+
.value_of("length")
53+
.unwrap_or("1")
54+
.to_string()
55+
.parse::<usize>()?;
56+
let result = commands::peek(context.port, address, length, None, true);
57+
handle_result(result)
58+
}
5059

5160
/// Wrap reset command
5261
fn reset(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
53-
match commands::reset(context.port, false) {
54-
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
55-
err.to_string(),
56-
)),
57-
Ok(()) => Ok(None),
58-
}
62+
handle_result(commands::reset(context.port, false))
5963
}
6064

6165
/// Wrap go64 command
6266
fn go64(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
63-
match serial::go64(context.port) {
64-
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
65-
err.to_string(),
66-
)),
67-
Ok(()) => Ok(None),
68-
}
67+
handle_result(serial::go64(context.port))
6968
}
7069

7170
/// Wrap stop cpu command
7271
fn stop(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
73-
match serial::stop_cpu(context.port) {
74-
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
75-
err.to_string(),
76-
)),
77-
Ok(()) => Ok(None),
78-
}
72+
handle_result(serial::stop_cpu(context.port))
7973
}
8074

8175
/// Wrap start cpu command
8276
fn start(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
83-
match serial::start_cpu(context.port) {
84-
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
85-
err.to_string(),
86-
)),
87-
Ok(()) => Ok(None),
88-
}
77+
handle_result(serial::start_cpu(context.port))
8978
}
9079

9180
/// Wrap filehost command
9281
fn filehost(_args: ArgMatches, context: &mut Context) -> Result<Option<String>> {
93-
match commands::filehost(context.port) {
94-
Err(err) => Err(reedline_repl_rs::Error::IllegalDefaultError(
95-
err.to_string(),
96-
)),
97-
Ok(()) => Ok(None),
98-
}
82+
handle_result(commands::filehost(context.port))
9983
}

0 commit comments

Comments
 (0)