I am writing the CPU for my NES emulator in assembly, but I am getting confused by the difference between the assembly I am coding in and the 6502 assembly that the NES uses, particularly the flags.
This is my code for setting/clearing flags:
Does this create separate flags or use the existing flags of the assembly language I am coding in? If it's the latter, is there a way to keep certain instructions from setting flags? Any general information on this would be appreciated.
This is my code for setting/clearing flags:
Code:
MODIFYFLAGS MACRO Sign, Overflow, Zero, Carry
; Clear all the flags if they are passed.
pushfd
IFNB <Sign>
and CPU.F, 01111111b
ENDIF
IFNB <Overflow>
and CPU.F, 10111111b
ENDIF
IFNB <Zero>
and CPU.F, 11111101b
ENDIF
IFNB <Carry>
and CPU.F, 11111110b
ENDIF
popfd
; Set the flags that are passed to the macro.
IFNB <Sign>
pushfd
sets dl
shl dl, 7
or CPU.F, dl
popfd
ENDIF
IFNB <Overflow>
pushfd
seto dl
shl dl, 6
or CPU.F, dl
popfd
ENDIF
IFNB <Zero>
pushfd
setz dl
shl dl, 1
or CPU.F, dl
popfd
ENDIF
IFNB <Carry>
pushfd
setc dl
or CPU.F, dl
popfd
ENDIF
ENDM
; Clear all the flags if they are passed.
pushfd
IFNB <Sign>
and CPU.F, 01111111b
ENDIF
IFNB <Overflow>
and CPU.F, 10111111b
ENDIF
IFNB <Zero>
and CPU.F, 11111101b
ENDIF
IFNB <Carry>
and CPU.F, 11111110b
ENDIF
popfd
; Set the flags that are passed to the macro.
IFNB <Sign>
pushfd
sets dl
shl dl, 7
or CPU.F, dl
popfd
ENDIF
IFNB <Overflow>
pushfd
seto dl
shl dl, 6
or CPU.F, dl
popfd
ENDIF
IFNB <Zero>
pushfd
setz dl
shl dl, 1
or CPU.F, dl
popfd
ENDIF
IFNB <Carry>
pushfd
setc dl
or CPU.F, dl
popfd
ENDIF
ENDM
Does this create separate flags or use the existing flags of the assembly language I am coding in? If it's the latter, is there a way to keep certain instructions from setting flags? Any general information on this would be appreciated.