@@ -246,6 +246,7 @@ impl Core {
246246 } else {
247247 self . view . right_pane = crate :: view_state:: RightPane :: HexDump ;
248248 self . view . active_pane = crate :: view_state:: ActivePane :: HexDump ;
249+ self . sync_pane_cursor_to_disassembly ( ) ;
249250 events. push ( CoreEvent :: StatusMessage ( "Hex Dump View Shown" . to_string ( ) ) ) ;
250251 }
251252 events. push ( CoreEvent :: ViewChanged ) ;
@@ -260,6 +261,7 @@ impl Core {
260261 } else {
261262 self . view . right_pane = crate :: view_state:: RightPane :: Sprites ;
262263 self . view . active_pane = crate :: view_state:: ActivePane :: Sprites ;
264+ self . sync_pane_cursor_to_disassembly ( ) ;
263265 events. push ( CoreEvent :: StatusMessage ( "Sprites View Shown" . to_string ( ) ) ) ;
264266 }
265267 events. push ( CoreEvent :: ViewChanged ) ;
@@ -274,6 +276,7 @@ impl Core {
274276 } else {
275277 self . view . right_pane = crate :: view_state:: RightPane :: Charset ;
276278 self . view . active_pane = crate :: view_state:: ActivePane :: Charset ;
279+ self . sync_pane_cursor_to_disassembly ( ) ;
277280 events. push ( CoreEvent :: StatusMessage ( "Charset View Shown" . to_string ( ) ) ) ;
278281 }
279282 events. push ( CoreEvent :: ViewChanged ) ;
@@ -288,6 +291,7 @@ impl Core {
288291 } else {
289292 self . view . right_pane = crate :: view_state:: RightPane :: Bitmap ;
290293 self . view . active_pane = crate :: view_state:: ActivePane :: Bitmap ;
294+ self . sync_pane_cursor_to_disassembly ( ) ;
291295 events. push ( CoreEvent :: StatusMessage ( "Bitmap View Shown" . to_string ( ) ) ) ;
292296 }
293297 events. push ( CoreEvent :: ViewChanged ) ;
@@ -652,6 +656,7 @@ impl Core {
652656 } else {
653657 self . view . right_pane = crate :: view_state:: RightPane :: Blocks ;
654658 self . view . active_pane = crate :: view_state:: ActivePane :: Blocks ;
659+ self . sync_pane_cursor_to_disassembly ( ) ;
655660 events. push ( CoreEvent :: StatusMessage ( "Blocks View Shown" . to_string ( ) ) ) ;
656661 }
657662 events. push ( CoreEvent :: ViewChanged ) ;
@@ -1167,6 +1172,102 @@ impl Core {
11671172 events
11681173 }
11691174
1175+ /// Sync the newly-opened right pane's cursor to the current disassembly
1176+ /// cursor address, if the corresponding sync setting is enabled.
1177+ ///
1178+ /// Call this once when a side panel is first opened so the user sees the
1179+ /// panel already scrolled to the address they are looking at.
1180+ fn sync_pane_cursor_to_disassembly ( & mut self ) {
1181+ let Some ( line) = self . state . disassembly . get ( self . view . cursor_index ) else {
1182+ return ;
1183+ } ;
1184+ let target_addr = line. address ;
1185+
1186+ match self . view . right_pane {
1187+ crate :: view_state:: RightPane :: Blocks => {
1188+ if self . state . system_config . sync_blocks_view
1189+ && let Some ( idx) = self
1190+ . state
1191+ . get_block_index_for_address ( target_addr, line. mnemonic == "{splitter}" )
1192+ {
1193+ self . view . blocks_selected_index = Some ( idx) ;
1194+ }
1195+ }
1196+ crate :: view_state:: RightPane :: HexDump => {
1197+ if self . state . system_config . sync_hex_dump {
1198+ let origin = self . state . origin . 0 as usize ;
1199+ let alignment_padding = origin % 16 ;
1200+ let aligned_origin = origin - alignment_padding;
1201+ let addr = target_addr. 0 as usize ;
1202+
1203+ if addr >= aligned_origin {
1204+ let offset = addr - aligned_origin;
1205+ let row = offset / 16 ;
1206+ let total_len = self . state . raw_data . len ( ) + alignment_padding;
1207+ let max_rows = total_len. div_ceil ( 16 ) ;
1208+ if row < max_rows {
1209+ self . view . hex_cursor_index = row;
1210+ }
1211+ }
1212+ }
1213+ }
1214+ crate :: view_state:: RightPane :: Charset => {
1215+ if self . state . system_config . sync_charset_view {
1216+ let origin = self . state . origin . 0 as usize ;
1217+ let base_alignment = 0x400 ;
1218+ let aligned_start_addr = ( origin / base_alignment) * base_alignment;
1219+ let addr = target_addr. 0 as usize ;
1220+
1221+ if addr >= aligned_start_addr {
1222+ let char_offset = addr - aligned_start_addr;
1223+ let idx = char_offset / 8 ;
1224+ let end_addr = origin + self . state . raw_data . len ( ) ;
1225+ let total_chars = ( end_addr. saturating_sub ( aligned_start_addr) ) . div_ceil ( 8 ) ;
1226+ if idx < total_chars {
1227+ self . view . charset_cursor_index = idx;
1228+ }
1229+ }
1230+ }
1231+ }
1232+ crate :: view_state:: RightPane :: Sprites => {
1233+ if self . state . system_config . sync_sprites_view {
1234+ let origin = self . state . origin . 0 as usize ;
1235+ let aligned_origin = ( origin / 64 ) * 64 ;
1236+ let addr = target_addr. 0 as usize ;
1237+
1238+ if addr >= aligned_origin {
1239+ let offset = addr - aligned_origin;
1240+ let idx = offset / 64 ;
1241+ let end_addr = origin + self . state . raw_data . len ( ) ;
1242+ let total_sprites = ( end_addr. saturating_sub ( aligned_origin) ) . div_ceil ( 64 ) ;
1243+ if idx < total_sprites {
1244+ self . view . sprites_cursor_index = idx;
1245+ }
1246+ }
1247+ }
1248+ }
1249+ crate :: view_state:: RightPane :: Bitmap => {
1250+ if self . state . system_config . sync_bitmap_view {
1251+ let origin = self . state . origin . 0 as usize ;
1252+ let addr = target_addr. 0 as usize ;
1253+ let first_aligned_addr = ( origin / 8192 ) * 8192 ;
1254+
1255+ if addr >= first_aligned_addr {
1256+ let offset = addr - first_aligned_addr;
1257+ let idx = offset / 8192 ;
1258+ let end_addr = origin + self . state . raw_data . len ( ) ;
1259+ let total_bitmaps =
1260+ ( end_addr. saturating_sub ( first_aligned_addr) ) . div_ceil ( 8192 ) ;
1261+ if idx < total_bitmaps {
1262+ self . view . bitmap_cursor_index = idx;
1263+ }
1264+ }
1265+ }
1266+ }
1267+ crate :: view_state:: RightPane :: None | crate :: view_state:: RightPane :: Debugger => { }
1268+ }
1269+ }
1270+
11701271 fn cycle_immediate_format ( & mut self , forward : bool , events : & mut Vec < CoreEvent > ) {
11711272 use crate :: state:: types:: ImmediateFormat ;
11721273 if let Some ( line) = self . state . disassembly . get ( self . view . cursor_index ) {
0 commit comments