@@ -43,6 +43,7 @@ use serialport::{ClearBuffer, SerialPort};
4343use thiserror:: Error ;
4444
4545pub const ARDUINO_BAUD : u32 =1000000 ;
46+ pub use binrw:: BinWrite ;
4647pub use cycle_state:: * ;
4748pub use register_printer:: * ;
4849pub use registers:: * ;
@@ -67,6 +68,7 @@ impl ServerFlags {
6768pub const ENABLE_DEBUG : u32 =0x0000_0040 ; // Enable debug serial output
6869pub const ENABLE_CYCLE_LOGGING : u32 =0x0000_0080 ; // Enable cycle logging
6970pub const ENABLE_ALE_INTERRUPT : u32 =0x0000_0100 ; // Enable ALE interrupt to arbitrate READY line
71+ pub const RESOLVE_BUS_STEP : u32 =0x0000_0200 ; // Resolve bus step on each cycle
7072}
7173
7274/// [ServerCommand] represents the commands that can be sent to the Arduino808X server.
@@ -464,6 +466,17 @@ pub enum RegisterSetType {
464466Intel386Smm ,
465467}
466468
469+ impl RegisterSetType {
470+ pub fn size ( & self ) ->usize {
471+ match self {
472+ RegisterSetType :: Intel8088 =>28 ,
473+ RegisterSetType :: Intel286 =>102 ,
474+ RegisterSetType :: Intel386 =>204 ,
475+ RegisterSetType :: Intel386Smm =>208 ,
476+ }
477+ }
478+ }
479+
467480impl From < & RemoteCpuRegisters > for RegisterSetType {
468481fn from ( value : & RemoteCpuRegisters ) ->Self {
469482match value{
@@ -748,6 +761,7 @@ impl CpuClient {
748761/// Try to open the specified serial port and query it for an Arduino808X server.
749762pub fn try_port ( port_info : serialport:: SerialPortInfo , timeout : u64 ) ->Option < Box < dyn SerialPort > > {
750763let port_result = serialport:: new ( port_info. port_name . clone ( ) , 0 )
764+ . dtr_on_open ( true )
751765. baud_rate ( 0 )
752766. timeout ( std:: time:: Duration :: from_millis ( timeout) )
753767. stop_bits ( serialport:: StopBits :: One )
@@ -846,12 +860,12 @@ impl CpuClient {
846860Ok ( true )
847861}
848862else {
849- log:: error!( "read_result_code: command returned failure: {:02X}" , buf[ 0 ] ) ;
863+ log:: error!( "read_result_code() : command{:?} returned failure: {:02X}" , cmd , buf[ 0 ] ) ;
850864Err ( CpuClientError :: CommandFailed ( cmd) )
851865}
852866}
853867Err ( e) =>{
854- log:: error!( "read_result_code: read operation failed: {}" , e) ;
868+ log:: error!( "read_result_code(): command {:?}: read operation failed: {}" , cmd , e) ;
855869Err ( CpuClientError :: ReadFailure )
856870}
857871}
@@ -912,7 +926,17 @@ impl CpuClient {
912926let mut buf: [ u8 ; 1 ] =[ 0 ; 1 ] ;
913927 buf[ 0 ] = reg_type. into ( ) ;
914928self . send_buf ( & buf) ?;
915- self . send_buf ( reg_data) ?;
929+
930+ let expected_buf_size = reg_type. size ( ) ;
931+ if reg_data. len ( ) < expected_buf_size{
932+ return Err ( CpuClientError :: BadParameter ( format ! (
933+ "Expected at least {} byte buffer for register data, got: {}" ,
934+ expected_buf_size,
935+ reg_data. len( )
936+ ) ) ) ;
937+ }
938+
939+ self . send_buf ( & reg_data[ 0 ..expected_buf_size] ) ?;
916940self . read_result_code ( ServerCommand :: CmdLoad )
917941}
918942