DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/cpu/core_dyn_x86/helpers.h
00001 /*
00002  *  Copyright (C) 2002-2013  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 static bool dyn_helper_divb(Bit8u val) {
00020         if (!val) return CPU_PrepareException(0,0);
00021         Bitu quo=reg_ax / val;
00022         Bit8u rem=(Bit8u)(reg_ax % val);
00023         Bit8u quo8=(Bit8u)(quo&0xff);
00024         if (quo>0xff) return CPU_PrepareException(0,0);
00025         reg_ah=rem;
00026         reg_al=quo8;
00027         return false;
00028 }
00029 
00030 static bool dyn_helper_idivb(Bit8s val) {
00031         if (!val) return CPU_PrepareException(0,0);
00032         Bits quo=(Bit16s)reg_ax / val;
00033         Bit8s rem=(Bit8s)((Bit16s)reg_ax % val);
00034         Bit8s quo8s=(Bit8s)(quo&0xff);
00035         if (quo!=(Bit16s)quo8s) return CPU_PrepareException(0,0);
00036         reg_ah=rem;
00037         reg_al=quo8s;
00038         return false;
00039 }
00040 
00041 static bool dyn_helper_divw(Bit16u val) {
00042         if (!val) return CPU_PrepareException(0,0);
00043         Bitu num=(reg_dx<<16)|reg_ax;
00044         Bitu quo=num/val;
00045         Bit16u rem=(Bit16u)(num % val);
00046         Bit16u quo16=(Bit16u)(quo&0xffff);
00047         if (quo!=(Bit32u)quo16) return CPU_PrepareException(0,0);
00048         reg_dx=rem;
00049         reg_ax=quo16;
00050         return false;
00051 }
00052 
00053 static bool dyn_helper_idivw(Bit16s val) {
00054         if (!val) return CPU_PrepareException(0,0);
00055         Bits num=(reg_dx<<16)|reg_ax;
00056         Bits quo=num/val;
00057         Bit16s rem=(Bit16s)(num % val);
00058         Bit16s quo16s=(Bit16s)quo;
00059         if (quo!=(Bit32s)quo16s) return CPU_PrepareException(0,0);
00060         reg_dx=rem;
00061         reg_ax=quo16s;
00062         return false;
00063 }
00064 
00065 static bool dyn_helper_divd(Bit32u val) {
00066         if (!val) return CPU_PrepareException(0,0);
00067         Bit64u num=(((Bit64u)reg_edx)<<32)|reg_eax;
00068         Bit64u quo=num/val;
00069         Bit32u rem=(Bit32u)(num % val);
00070         Bit32u quo32=(Bit32u)(quo&0xffffffff);
00071         if (quo!=(Bit64u)quo32) return CPU_PrepareException(0,0);
00072         reg_edx=rem;
00073         reg_eax=quo32;
00074         return false;
00075 }
00076 
00077 static bool dyn_helper_idivd(Bit32s val) {
00078         if (!val) return CPU_PrepareException(0,0);
00079         Bit64s num=(((Bit64u)reg_edx)<<32)|reg_eax;
00080         Bit64s quo=num/val;
00081         Bit32s rem=(Bit32s)(num % val);
00082         Bit32s quo32s=(Bit32s)(quo&0xffffffff);
00083         if (quo!=(Bit64s)quo32s) return CPU_PrepareException(0,0);
00084         reg_edx=rem;
00085         reg_eax=quo32s;
00086         return false;
00087 }