home *** CD-ROM | disk | FTP | other *** search
- /* CallRet.c: call & return logic 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"
-
- /*=========================================================================*
- * call_nn *
- *=========================================================================*/
- void call_nn()
- {
- #define call_nn() T(17);push((USHORT)((USHORT)PC+(USHORT)2));PutPC(Getnextword())
-
- call_nn();
- }
-
- /*=========================================================================*
- * call_cc_nn *
- *=========================================================================*/
-
- #define call_cc_nn(flag) { \
- if(flag) \
- { \
- call_nn(); \
- } \
- else \
- { \
- T(10); \
- PC += 2; \
- } \
- }
-
-
- void call_nz_nn() call_cc_nn(!flags._Z);
- void call_z_nn() call_cc_nn(flags._Z);
- void call_nc_nn() call_cc_nn(!flags._C);
- void call_c_nn() call_cc_nn(flags._C);
- void call_po_nn() call_cc_nn(!flags._P);
- void call_pe_nn() call_cc_nn(flags._P);
- void call_p_nn() call_cc_nn(!flags._S);
- void call_m_nn() call_cc_nn(flags._S);
-
- #undef call_cc_nn
- #undef call_nn
-
- /*=========================================================================*
- * ret *
- *=========================================================================*/
- void ret()
- {
- #define ret() PutPC(pop())
-
- T(10);
- ret();
- }
-
- /*=========================================================================*
- * ret_cc *
- *=========================================================================*/
-
- #define ret_cc(flag) { \
- if(flag) \
- { \
- T(11); \
- ret(); \
- } \
- else \
- T(5); \
- }
-
-
- void ret_nz() ret_cc(!flags._Z);
- void ret_z() ret_cc(flags._Z);
- void ret_nc() ret_cc(!flags._C);
- void ret_c() ret_cc(flags._C);
- void ret_po() ret_cc(!flags._P);
- void ret_pe() ret_cc(flags._P);
- void ret_p() ret_cc(!flags._S);
- void ret_m() ret_cc(flags._S);
-
- #undef ret_cc
-
- /*=========================================================================*
- * reti *
- *=========================================================================*/
- void reti()
- {
- T(14);
- ret();
- }
-
- /*=========================================================================*
- * retn *
- *=========================================================================*/
- void retn()
- {
- T(14);
-
- /* Restore interrupt state */
- IFF1 = IFF2;
- ret();
- }
-
- #undef ret
-
- /*=========================================================================*
- * rst_p *
- *=========================================================================*/
-
- #define rst_p(p) { \
- T(11); \
- push((USHORT)PC); \
- PutPC(p); \
- }
-
- void rst_0() rst_p(0);
- void rst_8() rst_p(8);
- void rst_10() rst_p(0x10);
- void rst_18() rst_p(0x18);
- void rst_20() rst_p(0x20);
- void rst_28() rst_p(0x28);
- void rst_30() rst_p(0x30);
- void rst_38() rst_p(0x38);
-
- #undef rst_p
-
- /* EOF: CallRet.c */
-