DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/cpu/lazyflags.h
00001 /*
00002  *  Copyright (C) 2002-2020  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef DOSBOX_LAZYFLAGS_H
00020 #define DOSBOX_LAZYFLAGS_H
00021 
00022 //Flag Handling
00023 Bit32u get_CF(void);
00024 Bit32u get_AF(void);
00025 Bit32u get_ZF(void);
00026 Bit32u get_SF(void);
00027 Bit32u get_OF(void);
00028 Bit32u get_PF(void);
00029 
00030 Bitu FillFlags(void);
00031 void FillFlagsNoCFOF(void);
00032 void DestroyConditionFlags(void);
00033 
00034 #ifndef DOSBOX_REGS_H
00035 #include "regs.h"
00036 #endif
00037 
00038 struct LazyFlags {
00039     GenReg32 var1,var2,res;
00040         Bitu type;
00041         Bitu prev_type;
00042         Bit8u oldcf;
00043 };
00044 
00045 extern LazyFlags lfags;
00046 
00047 #define lf_var1b lflags.var1.byte[BL_INDEX]
00048 #define lf_var2b lflags.var2.byte[BL_INDEX]
00049 #define lf_resb lflags.res.byte[BL_INDEX]
00050 
00051 #define lf_var1w lflags.var1.word[W_INDEX]
00052 #define lf_var2w lflags.var2.word[W_INDEX]
00053 #define lf_resw lflags.res.word[W_INDEX]
00054 
00055 #define lf_var1d lflags.var1.dword[DW_INDEX]
00056 #define lf_var2d lflags.var2.dword[DW_INDEX]
00057 #define lf_resd lflags.res.dword[DW_INDEX]
00058 
00059 
00060 extern LazyFlags lflags;
00061 
00062 #define SETFLAGSb(FLAGB)                                                                                                        \
00063 {                                                                                                                                                       \
00064         SETFLAGBIT(OF,get_OF());                                                                                                \
00065         lflags.type=t_UNKNOWN;                                                                                                  \
00066         CPU_SetFlags(FLAGB,FMASK_NORMAL & 0xff);                                                                \
00067 }
00068 
00069 #define SETFLAGSw(FLAGW)                                                                                                        \
00070 {                                                                                                                                                       \
00071         lflags.type=t_UNKNOWN;                                                                                                  \
00072         CPU_SetFlagsw(FLAGW);                                                                                                   \
00073 }
00074 
00075 #define SETFLAGSd(FLAGD)                                                                                                        \
00076 {                                                                                                                                                       \
00077         lflags.type=t_UNKNOWN;                                                                                                  \
00078         CPU_SetFlagsd(FLAGD);                                                                                                   \
00079 }
00080 
00081 #define LoadCF SETFLAGBIT(CF,get_CF());
00082 #define LoadZF SETFLAGBIT(ZF,get_ZF());
00083 #define LoadSF SETFLAGBIT(SF,get_SF());
00084 #define LoadOF SETFLAGBIT(OF,get_OF());
00085 #define LoadAF SETFLAGBIT(AF,get_AF());
00086 
00087 #define TFLG_O          (get_OF())
00088 #define TFLG_NO         (!get_OF())
00089 #define TFLG_B          (get_CF())
00090 #define TFLG_NB         (!get_CF())
00091 #define TFLG_Z          (get_ZF())
00092 #define TFLG_NZ         (!get_ZF())
00093 #define TFLG_BE         (get_CF() || get_ZF())
00094 #define TFLG_NBE        (!get_CF() && !get_ZF())
00095 #define TFLG_S          (get_SF())
00096 #define TFLG_NS         (!get_SF())
00097 #define TFLG_P          (get_PF())
00098 #define TFLG_NP         (!get_PF())
00099 #define TFLG_L          ((get_SF()!=0) != (get_OF()!=0))
00100 #define TFLG_NL         ((get_SF()!=0) == (get_OF()!=0))
00101 #define TFLG_LE         (get_ZF()  || ((get_SF()!=0) != (get_OF()!=0)))
00102 #define TFLG_NLE        (!get_ZF() && ((get_SF()!=0) == (get_OF()!=0)))
00103 
00104 //Types of Flag changing instructions
00105 enum {
00106         t_UNKNOWN=0,
00107         t_ADDb,t_ADDw,t_ADDd, 
00108         t_ORb,t_ORw,t_ORd, 
00109         t_ADCb,t_ADCw,t_ADCd,
00110         t_SBBb,t_SBBw,t_SBBd,
00111         t_ANDb,t_ANDw,t_ANDd,
00112         t_SUBb,t_SUBw,t_SUBd,
00113         t_XORb,t_XORw,t_XORd,
00114         t_CMPb,t_CMPw,t_CMPd,
00115         t_INCb,t_INCw,t_INCd,
00116         t_DECb,t_DECw,t_DECd,
00117         t_TESTb,t_TESTw,t_TESTd,
00118         t_SHLb,t_SHLw,t_SHLd,
00119         t_SHRb,t_SHRw,t_SHRd,
00120         t_SARb,t_SARw,t_SARd,
00121         t_ROLb,t_ROLw,t_ROLd,
00122         t_RORb,t_RORw,t_RORd,
00123         t_RCLb,t_RCLw,t_RCLd,
00124         t_RCRb,t_RCRw,t_RCRd,
00125         t_NEGb,t_NEGw,t_NEGd,
00126         
00127         t_DSHLw,t_DSHLd,
00128         t_DSHRw,t_DSHRd,
00129         t_MUL,t_DIV,
00130         t_NOTDONE,
00131         t_LASTFLAG
00132 };
00133 
00134 #endif