diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-08-20 17:39:42 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-08-20 17:39:42 +0000 |
commit | 87ace20633ba711243e336630e2c9a8546516598 (patch) | |
tree | a9c624a08ae8ccc16086781fb009a6709b7a2913 /z80_private.h | |
parent | 2a5a38a8bd0295b841343062baec242d40267d93 (diff) |
This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'z80_private.h')
-rw-r--r-- | z80_private.h | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/z80_private.h b/z80_private.h new file mode 100644 index 0000000..08dc543 --- /dev/null +++ b/z80_private.h @@ -0,0 +1,209 @@ +/* + + z80 - Z80 emulation + + Copyright (C) 2006 Ian Cowburn (ianc@noddybox.demon.co.uk) + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ + + Private macros for Z80 + +*/ + +#ifndef Z80_PRIVATE_H +#define Z80_PRIVATE_H "$Id$" + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#define MAX_PER_CALLBACK 10 + + +/* ---------------------------------------- TYPES +*/ + +struct Z80 +{ + Z80Val cycle; + + Z80Word PC; + + Z80Byte A; + Z80Byte F; + Z80Word BC; + Z80Word DE; + Z80Word HL; + + Z80Word AF_; + Z80Word BC_; + Z80Word DE_; + Z80Word HL_; + + Z80Word IX; + Z80Word IY; + + Z80Word SP; + + Z80Byte IFF1; + Z80Byte IFF2; + Z80Byte IM; + Z80Byte I; + Z80Byte R; + int halt; + + int use_cb_off; + Z80Relative cb_off; + + Z80Byte shift; + + int raise; + Z80Byte devbyte; + int nmi; + + Z80Byte *memory; + int *memctrl; + + Z80ReadPort pread; + Z80WritePort pwrite; + + Z80Callback callback[eZ80_NO_CALLBACK][MAX_PER_CALLBACK]; + + int last_cb; +}; + + +/* ---------------------------------------- MACROS +*/ + +/* NOTE: A lot of these macros assume you have a variable called 'cpu' + which is a pointer to Z80 +*/ + + +/* HI/LO +*/ +#define SET_HI(reg,v) reg = (reg & 0x00ff) | ((v) << 8) +#define SET_LO(reg,v) reg = (reg & 0xff00) | ((v) & 0xff) +#define GET_HI(reg,v) ((reg & 0xff00) >> 8) +#define GET_LO(reg,v) (reg & 0xff) + +/* Invoke a callback class +*/ +#define CALLBACK(r,d) do \ + { \ + int f; \ + \ + for(f=0;f<MAX_PER_CALLBACK;f++) \ + if (cpu->callback[r][f]) \ + cpu->callback[r][f](cpu,d); \ + } while(0) + +/* Flag register +*/ +#define C_Z80 0x01 +#define N_Z80 0x02 +#define P_Z80 0x04 +#define V_Z80 P_Z80 +#define H_Z80 0x10 +#define Z_Z80 0x40 +#define S_Z80 0x80 + +#define B3_Z80 0x08 +#define B5_Z80 0x20 + + +#define SET(v,b) v|=b +#define CLR(v,b) v&=~(b) + +#define SETFLAG(f) SET(cpu->F,f) +#define CLRFLAG(f) CLR(cpu->F,f) + +#define PEEK(addr) (cpu->memory[addr]) +#define PEEKW(addr) (PEEK(addr) | (Z80Word)PEEK(addr+1)<<8) + +#define POKE(addr,val) do \ + { \ + if (cpu->memctrl[(addr)/256]) \ + { \ + cpu->memory[addr]=val; \ + } \ + while (0)(cpu->write(cpu,addr,val)) +#define POKEW(addr,val) do \ + { \ + POKE(addr,val); \ + POKE(addr+1,val>>8); \ + } while(0) + +#define FETCH_BYTE (cpu->memory[cpu->PC++]) +#define FETCH_WORD (cpu->PC+=2, \ + cpu->memory[cpu->PC-2]| \ + ((Z80Word)cpu->memory[cpu->PC-1]<<8)) + +#define IS_C (cpu->F&C_Z80) +#define IS_N (cpu->F&N_Z80) +#define IS_P (cpu->F&P_Z80) +#define IS_H (cpu->F&H_Z80) +#define IS_Z (cpu->F&Z_Z80) +#define IS_S (cpu->F&S_Z80) + +#define CARRY IS_C + +#define TSTATE(n) cpu->cycle+=n + +#define ADD_R(v) cpu->R=((cpu->R&0x80)|((cpu->R+(v))&0x7f)) +#define INC_R ADD_R(1) + +#define PUSH(REG) do \ + { \ + cpu->SP-=2; \ + POKEW(cpu->SP,REG); \ + } while(0) +#define POP(REG) do \ + { \ + REG=PEEKW(cpu->SP); \ + cpu->SP+=2; \ + } while(0) + +#define SETHIDDEN(res) cpu->F=(cpu->F&~(B3_Z80|B5_Z80))|\ + ((res)&(B3_Z80|B5_Z80)) + + + +/* ---------------------------------------- FLAG TABLES +*/ +extern Z80Byte PSZtable[512]; +extern Z80Byte SZtable[512]; +extern Z80Byte Ptable[512]; +extern Z80Byte Stable[512]; +extern Z80Byte Ztable[512]; + + +/* ---------------------------------------- GLOBAL GENERAL OPCODES/ROUTINES +*/ +void Z80_Decode(Z80 *cpu); + + +#endif + +/* END OF FILE */ |