4 * Copyright (C) 2003, 2004 Jonathan Campbell <jcampbell@mdjk.com>
6 * Decompiler and executioneer for the INC/DEC instructions.
8 ***********************************************************************************
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ************************************************************************************/
31 sx86_ubyte
op_dec8(softx86_ctx
* ctx
,sx86_ubyte src
)
35 /* peform the subtraction */
38 /* apparently CF is not touched by this instruction */
40 /* if result treated as signed value is negative */
41 if (ret
& 0x80) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
42 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
44 /* if result is zero */
45 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
46 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
48 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
49 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
52 apparently aux is set if:
53 given operation a - b = c, ((a AND 0Fh) - (b AND 0Fh) < 0).
54 in other words, if the lowest nibbles subtracted cause carry. */
56 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
58 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
60 /* finally, compute parity for parity bit */
61 if (softx86_parity8(ret
))
62 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
64 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
69 sx86_uword
op_dec16(softx86_ctx
* ctx
,sx86_uword src
)
73 /* peform the subtraction */
76 /* apparently CF is not touched by this instruction */
78 /* if result treated as signed value is negative */
80 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
82 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
84 /* if result is zero */
85 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
86 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
88 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
89 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
92 apparently aux is set if:
93 given operation a - b = c, ((a AND 0Fh) - (b AND 0Fh) < 0).
94 in other words, if the lowest nibbles subtracted cause carry. */
96 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
98 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
100 /* finally, compute parity for parity bit */
101 if (softx86_parity16(ret
))
102 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
104 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
109 sx86_udword
op_dec32(softx86_ctx
* ctx
,sx86_udword src
)
113 /* peform the subtraction */
116 /* apparently CF is not touched by this instruction */
118 /* if result treated as signed value is negative */
119 if (ret
& 0x80000000)
120 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
122 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
124 /* if result is zero */
125 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
126 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
128 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
129 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
132 apparently aux is set if:
133 given operation a - b = c, ((a AND 0Fh) - (b AND 0Fh) < 0).
134 in other words, if the lowest nibbles subtracted cause carry. */
136 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
138 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
140 /* finally, compute parity for parity bit */
141 if (softx86_parity16(ret
))
142 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
144 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
149 sx86_ubyte
op_inc8(softx86_ctx
* ctx
,sx86_ubyte src
)
153 /* peform the addition */
156 /* apparently CF is not touched by this instruction */
158 /* if result treated as signed value is negative */
159 if (ret
& 0x80) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
160 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
162 /* if result is zero */
163 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
164 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
166 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
167 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
170 apparently aux is set if:
171 given operation a + b = c, ((b AND 0Fh) + (a AND 0Fh) >= 0x10).
172 in other words, if the lowest nibbles added together overflow. */
173 if ((1+(src
&0xF)) >= 0x10)
174 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
176 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
178 /* finally, compute parity for parity bit */
179 if (softx86_parity8(ret
))
180 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
182 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
187 sx86_uword
op_inc16(softx86_ctx
* ctx
,sx86_uword src
)
191 /* peform the addition */
194 /* apparently CF is not touched by this instruction */
196 /* if result treated as signed value is negative */
198 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
200 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
202 /* if result is zero */
203 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
204 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
206 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
207 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
210 apparently aux is set if:
211 given operation a + b = c, ((b AND 0Fh) + (a AND 0Fh) >= 0x10).
212 in other words, if the lowest nibbles added together overflow. */
213 if ((1+(src
&0xF)) >= 0x10)
214 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
216 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
218 /* finally, compute parity for parity bit */
219 if (softx86_parity16(ret
))
220 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
222 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
227 sx86_udword
op_inc32(softx86_ctx
* ctx
,sx86_udword src
)
231 /* peform the addition */
234 /* apparently CF is not touched by this instruction */
236 /* if result treated as signed value is negative */
237 if (ret
& 0x80000000)
238 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_SIGN
;
240 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_SIGN
;
242 /* if result is zero */
243 if (!ret
) ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_ZERO
;
244 else ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_ZERO
;
246 /* auxiliary flag emulation (not defined by Intel's documentation, but observed
247 from many trials in DEBUG on an old Pentium Pro 166MHz I have kickin' around
250 apparently aux is set if:
251 given operation a + b = c, ((b AND 0Fh) + (a AND 0Fh) >= 0x10).
252 in other words, if the lowest nibbles added together overflow. */
253 if ((1+(src
&0xF)) >= 0x10)
254 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_AUX
;
256 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_AUX
;
258 /* finally, compute parity for parity bit */
259 if (softx86_parity16(ret
))
260 ctx
->state
->reg_flags
.val
|= SX86_CPUFLAG_PARITY
;
262 ctx
->state
->reg_flags
.val
&= ~SX86_CPUFLAG_PARITY
;
267 int Sfx86OpcodeExec_inc(sx86_ubyte opcode
,softx86_ctx
* ctx
)
269 if ((opcode
&0xF8) == 0x40) { // INC [reg]
273 w
= ctx
->state
->general_reg
[i
].w
.lo
;
274 ctx
->state
->general_reg
[i
].w
.lo
= op_inc16(ctx
,w
);
277 else if ((opcode
&0xF8) == 0x48) { // DEC [reg]
281 w
= ctx
->state
->general_reg
[i
].w
.lo
;
282 ctx
->state
->general_reg
[i
].w
.lo
= op_dec16(ctx
,w
);
289 int Sfx86OpcodeDec_inc(sx86_ubyte opcode
,softx86_ctx
* ctx
,char buf
[128])
291 if ((opcode
&0xF8) == 0x40) { // INC [reg]
292 sprintf(buf
,"INC %s",sx86_regs16
[opcode
-0x40]);
295 else if ((opcode
&0xF8) == 0x48) { // DEC [reg]
296 sprintf(buf
,"DEC %s",sx86_regs16
[opcode
-0x48]);