home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1996 December / PC_Shareware-1996-12.iso / windows / spectrum / sources / z80 / inout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-10  |  5.8 KB  |  215 lines

  1. /* InOut.c: I/O instructions emulation.
  2.  *
  3.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. #include "env.h"
  22.  
  23. /*=========================================================================*
  24.  *                            in_a_pn                                      *
  25.  *=========================================================================*/
  26. void in_a_pn()
  27. {
  28.    T(11);
  29.    A = readport( (USHORT) (Getnextbyte() | ( A << 8) ) );
  30. }
  31.  
  32. /*=========================================================================*
  33.  *                            in_r_pc                                      *
  34.  *=========================================================================*/
  35.  
  36. #define in_r_pc(R) { \
  37.    T(12); \
  38.    flags._N = 0; \
  39.    flags._P = parity((R) = readport(BC)); \
  40.    flags._S = ((R) & (UCHAR)BIT_7); \
  41.    flags._Z = !(R); \
  42.    flags._X = (R) & (UCHAR)BIT_5;  \
  43.    flags._Y = (R) & (UCHAR)BIT_3; \
  44. }
  45.  
  46. void in_b_pc() in_r_pc(B);
  47. void in_c_pc() in_r_pc(C);
  48. void in_d_pc() in_r_pc(D);
  49. void in_e_pc() in_r_pc(E);
  50. void in_h_pc() in_r_pc(H);
  51. void in_l_pc() in_r_pc(L);
  52. void in_a_pc() in_r_pc(A);
  53.  
  54. /* Is that way? */
  55. void in_f_pc()
  56. {
  57.    static UCHAR tmp;
  58.  
  59.    T(12);
  60.    flags._N = 0;
  61.    flags._P = parity(tmp = readport((USHORT)0));
  62.    flags._S = (tmp & (UCHAR)BIT_7);
  63.    flags._Z = !tmp;
  64.    flags._X = tmp & (UCHAR)BIT_5;
  65.    flags._Y = tmp & (UCHAR)BIT_3;
  66. }
  67.  
  68. #undef in_r_pc
  69.  
  70. /*=========================================================================*
  71.  *                            ini                                          *
  72.  *=========================================================================*/
  73. void ini()
  74. {
  75. #define ini \
  76.    T(16); \
  77.    writebyte(HL++, readport(BC) ); \
  78.    dec_b();
  79.  
  80.    ini
  81. }
  82.  
  83. /*=========================================================================*
  84.  *                            inir                                         *
  85.  *=========================================================================*/
  86. void inir()
  87. {
  88.    ini
  89.    if(!flags._Z)
  90.    {
  91.       T(5);
  92.       PC -= 2;
  93.    }
  94. }
  95.  
  96. #undef ini
  97.  
  98. /*=========================================================================*
  99.  *                            ind                                          *
  100.  *=========================================================================*/
  101. void ind()
  102. {
  103. #define ind \
  104.    T(16); \
  105.    writebyte(HL--, readport(BC) ); \
  106.    dec_b();
  107.  
  108.    ind
  109. }
  110.  
  111. /*=========================================================================*
  112.  *                            indr                                         *
  113.  *=========================================================================*/
  114. void indr()
  115. {
  116.    ind
  117.    if(!flags._Z)
  118.    {
  119.       T(5);
  120.       PC -= 2;
  121.    }
  122. }
  123.  
  124. /*=========================================================================*
  125.  *                            out_pn_a                                     *
  126.  *=========================================================================*/
  127. void out_pn_a()
  128. {
  129.    T(11);
  130.    writeport( (USHORT) (Getnextbyte() | (A << 8) ), A);
  131. }
  132.  
  133. /*=========================================================================*
  134.  *                            out_pc_r                                     *
  135.  *=========================================================================*/
  136.  
  137. #define out_pc_r(R) { \
  138.    T(12); \
  139.    writeport(BC, (R)); \
  140. }
  141.  
  142. void out_pc_b() out_pc_r(B);
  143. void out_pc_c() out_pc_r(C);
  144. void out_pc_d() out_pc_r(D);
  145. void out_pc_e() out_pc_r(E);
  146. void out_pc_h() out_pc_r(H);
  147. void out_pc_l() out_pc_r(L);
  148. void out_pc_a() out_pc_r(A);
  149.  
  150. #undef out_pc_r
  151.  
  152. /* What's this instruction? (ED71)
  153.   In Spectrum appears to write 0 to port 0
  154.   (or any other even port)
  155. */
  156. void out_pc_f()
  157. {
  158.    T(12);
  159.    writeport((USHORT)0, (UCHAR)0);
  160. }
  161.  
  162. /*=========================================================================*
  163.  *                            outi                                         *
  164.  *=========================================================================*/
  165. void outi()
  166. {
  167. #define outi \
  168.    T(12); \
  169.    writeport(BC, readbyte(HL++) ); \
  170.    dec_b();
  171. }
  172.  
  173. /*=========================================================================*
  174.  *                            otir                                         *
  175.  *=========================================================================*/
  176. void otir()
  177. {
  178.    outi
  179.    if(!flags._Z)
  180.    {
  181.       T(5);
  182.       PC -= 2;
  183.    }
  184. }
  185.  
  186. #undef outi
  187.  
  188. /*=========================================================================*
  189.  *                            outd                                         *
  190.  *=========================================================================*/
  191. void outd()
  192. {
  193. #define outd \
  194.    T(16); \
  195.    writeport(BC, readbyte(HL--) ); \
  196.    dec_b();
  197. }
  198.  
  199. /*=========================================================================*
  200.  *                            otdr                                         *
  201.  *=========================================================================*/
  202. void otdr()
  203. {
  204.    outd
  205.    if(!flags._Z)
  206.    {
  207.       T(5);
  208.       PC -= 2;
  209.    }
  210. }
  211.  
  212. #undef outd
  213.  
  214. /* EOF: InOut.C */
  215.