4 * Copyright (C) 2003, 2004 Jonathan Campbell <jcampbell@mdjk.com>
6 * Decompiler and executioneer for IN/OUT 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 int Sfx86OpcodeExec_io(sx86_ubyte opcode
,softx86_ctx
* ctx
)
33 if ((opcode
&0xFE) == 0xE4) { // IN AL/AX,imm8
37 /* TODO: If emulating 386+ and protected/v86 mode check I/O permission bitmap */
40 ionum
= softx86_fetch_exec_byte(ctx
); // get imm8
42 if (w16
) { /* NOTE: It is always assumed that it is in Little Endian */
45 ctx
->callbacks
->on_read_io(ctx
,ionum
,(sx86_ubyte
*)(&rw
),2);
46 SWAP_WORD_FROM_LE(rw
);
47 ctx
->state
->general_reg
[SX86_REG_AX
].w
.lo
= rw
;
52 ctx
->callbacks
->on_read_io(ctx
,ionum
,(sx86_ubyte
*)(&rb
),1);
53 ctx
->state
->general_reg
[SX86_REG_AX
].b
.lo
= rb
;
58 else if ((opcode
&0xFE) == 0xEC) { // IN AL/AX,DX
61 /* TODO: If emulating 386+ and protected/v86 mode check I/O permission bitmap */
64 if (w16
) { /* NOTE: It is always assumed that it is in Little Endian */
67 ctx
->callbacks
->on_read_io(ctx
,ctx
->state
->general_reg
[SX86_REG_DX
].w
.lo
,(sx86_ubyte
*)(&rw
),2);
68 SWAP_WORD_FROM_LE(rw
);
69 ctx
->state
->general_reg
[SX86_REG_AX
].w
.lo
= rw
;
74 ctx
->callbacks
->on_read_io(ctx
,ctx
->state
->general_reg
[SX86_REG_DX
].w
.lo
,(sx86_ubyte
*)(&rb
),1);
75 ctx
->state
->general_reg
[SX86_REG_AX
].b
.lo
= rb
;
80 else if ((opcode
&0xFE) == 0xE6) { // OUT AL/AX,imm8
84 /* TODO: If emulating 386+ and protected/v86 mode check I/O permission bitmap */
87 ionum
= softx86_fetch_exec_byte(ctx
); // get imm8
89 if (w16
) { /* NOTE: It is always assumed that it is in Little Endian */
92 rw
= ctx
->state
->general_reg
[SX86_REG_AX
].w
.lo
;
94 ctx
->callbacks
->on_write_io(ctx
,ionum
,(sx86_ubyte
*)(&rw
),2);
99 rb
= ctx
->state
->general_reg
[SX86_REG_AX
].b
.lo
;
100 ctx
->callbacks
->on_write_io(ctx
,ionum
,(sx86_ubyte
*)(&rb
),1);
105 else if ((opcode
&0xFE) == 0xEE) { // OUT AL/AX,DX
108 /* TODO: If emulating 386+ and protected/v86 mode check I/O permission bitmap */
111 if (w16
) { /* NOTE: It is always assumed that it is in Little Endian */
114 rw
= ctx
->state
->general_reg
[SX86_REG_AX
].w
.lo
;
116 ctx
->callbacks
->on_write_io(ctx
,ctx
->state
->general_reg
[SX86_REG_DX
].w
.lo
,(sx86_ubyte
*)(&rw
),2);
121 rb
= ctx
->state
->general_reg
[SX86_REG_AX
].b
.lo
;
122 ctx
->callbacks
->on_write_io(ctx
,ctx
->state
->general_reg
[SX86_REG_DX
].w
.lo
,(sx86_ubyte
*)(&rb
),1);
131 int Sfx86OpcodeDec_io(sx86_ubyte opcode
,softx86_ctx
* ctx
,char buf
[128])
133 if ((opcode
&0xFE) == 0xE4) { // IN AL/AX,imm8
138 ionum
= softx86_fetch_dec_byte(ctx
); // get imm8
140 sprintf(buf
,"IN %s,%02Xh",w16
? "AX" : "AL",ionum
);
143 else if ((opcode
&0xFE) == 0xEC) { // IN AL/AX,DX
147 sprintf(buf
,"IN %s,DX",w16
? "AX" : "AL");
150 else if ((opcode
&0xFE) == 0xE6) { // OUT AL/AX,imm8
155 ionum
= softx86_fetch_dec_byte(ctx
); // get imm8
157 sprintf(buf
,"OUT %02Xh,%s",ionum
,w16
? "AX" : "AL");
160 else if ((opcode
&0xFE) == 0xEE) { // OUT AL/AX,DX
164 sprintf(buf
,"OUT DX,%s",w16
? "AX" : "AL");