home *** CD-ROM | disk | FTP | other *** search
- /* InOut.c: I/O instructions emulation.
- *
- * Copyright 1996 Rui Fernando Ferreira Ribeiro.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-
- #include "env.h"
-
- /*=========================================================================*
- * in_a_pn *
- *=========================================================================*/
- void in_a_pn()
- {
- T(11);
- A = readport( (USHORT) (Getnextbyte() | ( A << 8) ) );
- }
-
- /*=========================================================================*
- * in_r_pc *
- *=========================================================================*/
-
- #define in_r_pc(R) { \
- T(12); \
- flags._N = 0; \
- flags._P = parity((R) = readport(BC)); \
- flags._S = ((R) & (UCHAR)BIT_7); \
- flags._Z = !(R); \
- flags._X = (R) & (UCHAR)BIT_5; \
- flags._Y = (R) & (UCHAR)BIT_3; \
- }
-
- void in_b_pc() in_r_pc(B);
- void in_c_pc() in_r_pc(C);
- void in_d_pc() in_r_pc(D);
- void in_e_pc() in_r_pc(E);
- void in_h_pc() in_r_pc(H);
- void in_l_pc() in_r_pc(L);
- void in_a_pc() in_r_pc(A);
-
- /* Is that way? */
- void in_f_pc()
- {
- static UCHAR tmp;
-
- T(12);
- flags._N = 0;
- flags._P = parity(tmp = readport((USHORT)0));
- flags._S = (tmp & (UCHAR)BIT_7);
- flags._Z = !tmp;
- flags._X = tmp & (UCHAR)BIT_5;
- flags._Y = tmp & (UCHAR)BIT_3;
- }
-
- #undef in_r_pc
-
- /*=========================================================================*
- * ini *
- *=========================================================================*/
- void ini()
- {
- #define ini \
- T(16); \
- writebyte(HL++, readport(BC) ); \
- dec_b();
-
- ini
- }
-
- /*=========================================================================*
- * inir *
- *=========================================================================*/
- void inir()
- {
- ini
- if(!flags._Z)
- {
- T(5);
- PC -= 2;
- }
- }
-
- #undef ini
-
- /*=========================================================================*
- * ind *
- *=========================================================================*/
- void ind()
- {
- #define ind \
- T(16); \
- writebyte(HL--, readport(BC) ); \
- dec_b();
-
- ind
- }
-
- /*=========================================================================*
- * indr *
- *=========================================================================*/
- void indr()
- {
- ind
- if(!flags._Z)
- {
- T(5);
- PC -= 2;
- }
- }
-
- /*=========================================================================*
- * out_pn_a *
- *=========================================================================*/
- void out_pn_a()
- {
- T(11);
- writeport( (USHORT) (Getnextbyte() | (A << 8) ), A);
- }
-
- /*=========================================================================*
- * out_pc_r *
- *=========================================================================*/
-
- #define out_pc_r(R) { \
- T(12); \
- writeport(BC, (R)); \
- }
-
- void out_pc_b() out_pc_r(B);
- void out_pc_c() out_pc_r(C);
- void out_pc_d() out_pc_r(D);
- void out_pc_e() out_pc_r(E);
- void out_pc_h() out_pc_r(H);
- void out_pc_l() out_pc_r(L);
- void out_pc_a() out_pc_r(A);
-
- #undef out_pc_r
-
- /* What's this instruction? (ED71)
- In Spectrum appears to write 0 to port 0
- (or any other even port)
- */
- void out_pc_f()
- {
- T(12);
- writeport((USHORT)0, (UCHAR)0);
- }
-
- /*=========================================================================*
- * outi *
- *=========================================================================*/
- void outi()
- {
- #define outi \
- T(12); \
- writeport(BC, readbyte(HL++) ); \
- dec_b();
- }
-
- /*=========================================================================*
- * otir *
- *=========================================================================*/
- void otir()
- {
- outi
- if(!flags._Z)
- {
- T(5);
- PC -= 2;
- }
- }
-
- #undef outi
-
- /*=========================================================================*
- * outd *
- *=========================================================================*/
- void outd()
- {
- #define outd \
- T(16); \
- writeport(BC, readbyte(HL--) ); \
- dec_b();
- }
-
- /*=========================================================================*
- * otdr *
- *=========================================================================*/
- void otdr()
- {
- outd
- if(!flags._Z)
- {
- T(5);
- PC -= 2;
- }
- }
-
- #undef outd
-
- /* EOF: InOut.C */
-