@@ -3608,6 +3608,40 @@ def test_71_7c_mov1_cy_sfr_bit7(self):
36083608 self .assertEqual (proc .pc , len (code ))
36093609 self .assertEqual (proc .read_psw (), Flags .CY )
36103610
3611+ # mov1 cy,sfr.bit preserves other PSW bits
3612+ def test_71_0c_mov1_cy_sfr_preserves_psw (self ):
3613+ proc , _ = _make_processor ()
3614+ code = [0x71 , 0x2c , 0xfe ] # mov1 cy,0fffeh.2
3615+ proc .write_memory_bytes (0 , code )
3616+ proc .write_memory (0xfffe , 0x04 ) # bit 2 set
3617+ proc .write_psw (Flags .IE | Flags .Z ) # set IE and Z
3618+ proc .write_gp_reg (Registers .A , 0x00 ) # A=0 (different from PSW)
3619+ proc .step ()
3620+ # CY should be set, IE and Z should be preserved
3621+ self .assertEqual (proc .read_psw (), Flags .IE | Flags .Z | Flags .CY )
3622+
3623+ def test_71_0c_mov1_cy_sfr_clears_cy (self ):
3624+ proc , _ = _make_processor ()
3625+ code = [0x71 , 0x2c , 0xfe ] # mov1 cy,0fffeh.2
3626+ proc .write_memory_bytes (0 , code )
3627+ proc .write_memory (0xfffe , 0x00 ) # bit 2 clear
3628+ proc .write_psw (Flags .IE | Flags .CY ) # IE set, CY set
3629+ proc .write_gp_reg (Registers .A , 0xFF ) # A=FF (different from PSW)
3630+ proc .step ()
3631+ # CY should be cleared, IE should be preserved, A should not affect PSW
3632+ self .assertEqual (proc .read_psw (), Flags .IE )
3633+
3634+ def test_71_0c_mov1_cy_sfr_does_not_use_register_a (self ):
3635+ proc , _ = _make_processor ()
3636+ code = [0x71 , 0x0c , 0xfe ] # mov1 cy,0fffeh.0
3637+ proc .write_memory_bytes (0 , code )
3638+ proc .write_memory (0xfffe , 0x01 ) # bit 0 set
3639+ proc .write_psw (Flags .IE ) # PSW = 0x80
3640+ proc .write_gp_reg (Registers .A , 0x20 ) # A = 0x20 (RBS1 bit)
3641+ proc .step ()
3642+ # Should set CY and preserve IE. Must NOT set RBS1 from A.
3643+ self .assertEqual (proc .read_psw (), Flags .IE | Flags .CY )
3644+
36113645 # mov1 0fffeh.0,cy ;71 09 fe sfr
36123646 def test_71_09_mov1_sfr_bit_0_cy (self ):
36133647 proc , _ = _make_processor ()
0 commit comments