A solution that switches to native mode (6 bytes):
Code:
; copy e flag to carry
;
; no flags (other than c) or registers affected
;
clc ; switch to native mode
xce
bcc =.1 ; if we were already in native mode, carry will be clear and we're done
xce ; restore emulation mode
sec ; set carry
.1
Without switching modes (13 bytes):
Code:
; copy e flag to carry
;
; no registers affected
; flags affected: z (and c, of course)
;
clc
bit ## $3800 ; this is BIT #$00 SEC if we're in 8-bit accumulator mode
bcc =.1 ; if we're in 16-bit accumulator mode, then we must be in native mode, so we're done
rep # $21 ; clear carry and (try to) switch to 16-bit accumulator mode
bit ## $3800 ; this is BIT #$00 SEC if we're still in 8-bit mode (and thus in emulation mode)
sep # $20 ; restore 8-bit accumulator mode
.1