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

  1. /* CallRet.c: call & return logic 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. #include "env.h"
  21.  
  22. /*=========================================================================*
  23.  *                            call_nn                                      *
  24.  *=========================================================================*/
  25. void call_nn()
  26. {
  27. #define call_nn() T(17);push((USHORT)((USHORT)PC+(USHORT)2));PutPC(Getnextword())
  28.  
  29.    call_nn();
  30. }
  31.  
  32. /*=========================================================================*
  33.  *                            call_cc_nn                                   *
  34.  *=========================================================================*/
  35.  
  36. #define call_cc_nn(flag) { \
  37.    if(flag) \
  38.    { \
  39.       call_nn(); \
  40.    } \
  41.    else \
  42.    { \
  43.      T(10); \
  44.      PC += 2; \
  45.    } \
  46. }
  47.  
  48.  
  49. void call_nz_nn() call_cc_nn(!flags._Z);
  50. void call_z_nn() call_cc_nn(flags._Z);
  51. void call_nc_nn() call_cc_nn(!flags._C);
  52. void call_c_nn() call_cc_nn(flags._C);
  53. void call_po_nn() call_cc_nn(!flags._P);
  54. void call_pe_nn() call_cc_nn(flags._P);
  55. void call_p_nn() call_cc_nn(!flags._S);
  56. void call_m_nn() call_cc_nn(flags._S);
  57.  
  58. #undef call_cc_nn
  59. #undef call_nn
  60.  
  61. /*=========================================================================*
  62.  *                            ret                                          *
  63.  *=========================================================================*/
  64. void ret()
  65. {
  66. #define ret() PutPC(pop())
  67.  
  68.    T(10);
  69.    ret();
  70. }
  71.  
  72. /*=========================================================================*
  73.  *                            ret_cc                                       *
  74.  *=========================================================================*/
  75.  
  76. #define ret_cc(flag) { \
  77.    if(flag) \
  78.    { \
  79.       T(11); \
  80.       ret(); \
  81.    } \
  82.    else \
  83.       T(5); \
  84. }
  85.  
  86.  
  87. void ret_nz() ret_cc(!flags._Z);
  88. void ret_z() ret_cc(flags._Z);
  89. void ret_nc() ret_cc(!flags._C);
  90. void ret_c() ret_cc(flags._C);
  91. void ret_po() ret_cc(!flags._P);
  92. void ret_pe() ret_cc(flags._P);
  93. void ret_p() ret_cc(!flags._S);
  94. void ret_m() ret_cc(flags._S);
  95.  
  96. #undef ret_cc
  97.  
  98. /*=========================================================================*
  99.  *                            reti                                         *
  100.  *=========================================================================*/
  101. void reti()
  102. {
  103.    T(14);
  104.    ret();
  105. }
  106.  
  107. /*=========================================================================*
  108.  *                            retn                                         *
  109.  *=========================================================================*/
  110. void retn()
  111. {
  112.    T(14);
  113.  
  114.    /* Restore interrupt state */
  115.    IFF1 = IFF2;
  116.    ret();
  117. }
  118.  
  119. #undef ret
  120.  
  121. /*=========================================================================*
  122.  *                            rst_p                                        *
  123.  *=========================================================================*/
  124.  
  125. #define rst_p(p) { \
  126.    T(11); \
  127.    push((USHORT)PC); \
  128.    PutPC(p); \
  129. }
  130.  
  131. void rst_0() rst_p(0);
  132. void rst_8() rst_p(8);
  133. void rst_10() rst_p(0x10);
  134. void rst_18() rst_p(0x18);
  135. void rst_20() rst_p(0x20);
  136. void rst_28() rst_p(0x28);
  137. void rst_30() rst_p(0x30);
  138. void rst_38() rst_p(0x38);
  139.  
  140. #undef rst_p
  141.  
  142. /* EOF: CallRet.c */
  143.