@@ -21,11 +21,12 @@ use mindustry_rs::logic::vm::LVar;
2121use mindustry_rs:: {
2222 logic:: vm:: {
2323 Building , BuildingData , LValue , LogicVM , LogicVMBuilder , MEMORY_BANK , MESSAGE ,
24- MICRO_PROCESSOR , Processor , SWITCH , WORLD_PROCESSOR , decode_utf16 ,
24+ MICRO_PROCESSOR , Processor , SWITCH , WORLD_PROCESSOR ,
2525 } ,
2626 types:: { Object , Point2 , ProcessorConfig , Schematic } ,
2727} ;
2828use serde:: Deserialize ;
29+ use widestring:: { U16String , u16str} ;
2930
3031// tx/rx are from our perspective, not the processor's
3132const UART_TX_READ : usize = 254 ;
@@ -121,7 +122,7 @@ fn get_building<'a>(vm: &'a LogicVM, position: MetaPoint2, name: &str) -> &'a Bu
121122 let Some ( building) = vm. building ( position. into ( ) ) else {
122123 panic ! ( "{name} not found at {position}" ) ;
123124 } ;
124- assert_eq ! ( building. block. name, name) ;
125+ assert_eq ! ( building. block. name. as_str ( ) , name) ;
125126 building
126127}
127128
@@ -145,14 +146,14 @@ enum VMCommand {
145146 Continue ,
146147 Restart ,
147148 SetBreakpoint ( Option < u32 > ) ,
148- PrintVar ( String , Option < String > ) ,
149+ PrintVar ( U16String , Option < String > ) ,
149150}
150151
151152struct VMState {
152153 power : bool ,
153154 pause : bool ,
154155 single_step : bool ,
155- state : Option < String > ,
156+ state : Option < U16String > ,
156157 pc : u32 ,
157158 mtime : u32 ,
158159 mcycle : u32 ,
@@ -273,7 +274,7 @@ fn tui(stdout: TextContent, debug: TextContent, tx: Sender<VMCommand>, rx: Recei
273274 siv. call_on_name ( "pause" , |v : & mut Checkbox | v. set_checked ( pause) ) ;
274275 siv. call_on_name ( "single_step" , |v : & mut Checkbox | v. set_checked ( single_step) ) ;
275276 siv. call_on_name ( "state" , |v : & mut TextView | match state {
276- Some ( state) => v. set_content ( state) ,
277+ Some ( state) => v. set_content ( state. to_string_lossy ( ) ) ,
277278 None => v. set_content ( "???" ) ,
278279 } ) ;
279280 siv. call_on_name ( "pc" , |v : & mut TextView | {
@@ -309,9 +310,10 @@ fn process_cmd(out: &TextContent, cmd: &str) -> Option<VMCommand> {
309310 }
310311 } ,
311312 } ,
312- "p" | "print" | "v" | "var" if cmd. len ( ) >= 2 => {
313- VMCommand :: PrintVar ( cmd[ 1 ] . to_string ( ) , cmd. get ( 2 ) . map ( |s| s. to_string ( ) ) )
314- }
313+ "p" | "print" | "v" | "var" if cmd. len ( ) >= 2 => VMCommand :: PrintVar (
314+ U16String :: from_str ( cmd[ 1 ] ) ,
315+ cmd. get ( 2 ) . map ( |s| s. to_string ( ) ) ,
316+ ) ,
315317 /*
316318 "i" | "inspect" if cmd.len() >= 3 => {
317319 let Ok(x) = cmd[1].parse() else {
@@ -472,17 +474,21 @@ fn main() -> Result<(), Box<dyn Error>> {
472474 } ) ;
473475 }
474476
475- let print_var = |processor : & Processor , name : String , radix : Option < String > | {
477+ let print_var = |processor : & Processor , name : U16String , radix : Option < String > | {
476478 match processor
477479 . variable ( & name)
478480 . or_else ( || globals. get ( & name) . map ( |v| v. get ( & processor. state ) ) )
479481 {
480482 Some ( value) => match radix. as_deref ( ) {
481- Some ( "x" ) => tui_println ! ( debug, "{name} = {:#010x}" , value. num( ) as u32 ) ,
482- Some ( "b" ) => tui_println ! ( debug, "{name} = {:#034b}" , value. num( ) as u32 ) ,
483- _ => tui_println ! ( debug, "{name} = {value:?}" ) ,
483+ Some ( "x" ) => {
484+ tui_println ! ( debug, "{} = {:#010x}" , name. display( ) , value. num( ) as u32 )
485+ }
486+ Some ( "b" ) => {
487+ tui_println ! ( debug, "{} = {:#034b}" , name. display( ) , value. num( ) as u32 )
488+ }
489+ _ => tui_println ! ( debug, "{} = {value:?}" , name. display( ) ) ,
484490 } ,
485- None => tui_println ! ( debug, "{name } = <undefined>" ) ,
491+ None => tui_println ! ( debug, "{} = <undefined>" , name . display ( ) ) ,
486492 } ;
487493 } ;
488494
@@ -556,19 +562,19 @@ fn main() -> Result<(), Box<dyn Error>> {
556562 * single_step = false ;
557563 }
558564 VMCommand :: Restart => {
559- controller. set_variable ( "pc" , 0 . into ( ) ) ?;
565+ controller. set_variable ( u16str ! ( "pc" ) , 0 . into ( ) ) ?;
560566 * power = true ;
561567 * pause = false ;
562568 * single_step = false ;
563569 start = Instant :: now ( ) ;
564570 next_state_update = start;
565571 }
566572 VMCommand :: SetBreakpoint ( Some ( value) ) => {
567- config. set_variable ( "BREAKPOINT_ADDRESS" , value. into ( ) ) ?;
573+ config. set_variable ( u16str ! ( "BREAKPOINT_ADDRESS" ) , value. into ( ) ) ?;
568574 tui_println ! ( debug, "Breakpoint set: {value:#010x}" ) ;
569575 }
570576 VMCommand :: SetBreakpoint ( None ) => {
571- config. set_variable ( "BREAKPOINT_ADDRESS" , LValue :: Null ) ?;
577+ config. set_variable ( u16str ! ( "BREAKPOINT_ADDRESS" ) , LValue :: Null ) ?;
572578 tui_println ! ( debug, "Breakpoint cleared." ) ;
573579 }
574580 VMCommand :: PrintVar ( name, radix) => print_var ( controller, name, radix) ,
@@ -580,14 +586,14 @@ fn main() -> Result<(), Box<dyn Error>> {
580586 power : * power,
581587 pause : * pause,
582588 single_step : * single_step,
583- state : match controller. variable ( "state" ) . unwrap ( ) {
584- LValue :: String ( state) => Some ( state. to_string ( ) ) ,
589+ state : match controller. variable ( u16str ! ( "state" ) ) . unwrap ( ) {
590+ LValue :: String ( state) => Some ( state. to_ustring ( ) ) ,
585591 _ => None ,
586592 } ,
587- pc : controller. variable ( "pc" ) . unwrap ( ) . numu ( ) ,
588- mcycle : controller. variable ( "csr_mcycle" ) . unwrap ( ) . numu ( ) ,
589- mtime : controller. variable ( "csr_mtime" ) . unwrap ( ) . numu ( ) ,
590- minstret : controller. variable ( "csr_minstret" ) . unwrap ( ) . numu ( ) ,
593+ pc : controller. variable ( u16str ! ( "pc" ) ) . unwrap ( ) . numu ( ) ,
594+ mcycle : controller. variable ( u16str ! ( "csr_mcycle" ) ) . unwrap ( ) . numu ( ) ,
595+ mtime : controller. variable ( u16str ! ( "csr_mtime" ) ) . unwrap ( ) . numu ( ) ,
596+ minstret : controller. variable ( u16str ! ( "csr_minstret" ) ) . unwrap ( ) . numu ( ) ,
591597 } ) ?;
592598
593599 if * power != prev_power {
@@ -597,7 +603,7 @@ fn main() -> Result<(), Box<dyn Error>> {
597603 } else {
598604 tui_println ! ( debug, "Processor halted." ) ;
599605 if !error_output. is_empty ( ) {
600- tui_println ! ( debug, "Error output: {}" , decode_utf16 ( error_output) ) ;
606+ tui_println ! ( debug, "Error output: {}" , error_output. display ( ) ) ;
601607 }
602608 tui_println ! ( debug, "Runtime: {time:?}" ) ;
603609 tui_println ! ( debug, "Ticks completed: {ticks}" ) ;
0 commit comments