libz80 with compilation problems (uses up to much ram)

Committer:
gertk
Date:
Thu Mar 10 20:32:59 2011 +0000
Revision:
0:b612024f5aee
not yet functional !

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gertk 0:b612024f5aee 1 /* =============================================================================
gertk 0:b612024f5aee 2 * libz80 - Z80 emulation library
gertk 0:b612024f5aee 3 * =============================================================================
gertk 0:b612024f5aee 4 *
gertk 0:b612024f5aee 5 * (C) Gabriel Gambetta (ggambett@adinet.com.uy) 2000 - 2002
gertk 0:b612024f5aee 6 *
gertk 0:b612024f5aee 7 * Version 1.99
gertk 0:b612024f5aee 8 *
gertk 0:b612024f5aee 9 * -----------------------------------------------------------------------------
gertk 0:b612024f5aee 10 *
gertk 0:b612024f5aee 11 * This program is free software; you can redistribute it and/or modify
gertk 0:b612024f5aee 12 * it under the terms of the GNU General Public License as published by
gertk 0:b612024f5aee 13 * the Free Software Foundation; either version 2 of the License, or
gertk 0:b612024f5aee 14 * (at your option) any later version.
gertk 0:b612024f5aee 15 *
gertk 0:b612024f5aee 16 * This program is distributed in the hope that it will be useful,
gertk 0:b612024f5aee 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gertk 0:b612024f5aee 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
gertk 0:b612024f5aee 19 * GNU General Public License for more details.
gertk 0:b612024f5aee 20 *
gertk 0:b612024f5aee 21 * You should have received a copy of the GNU General Public License
gertk 0:b612024f5aee 22 * along with this program; if not, write to the Free Software
gertk 0:b612024f5aee 23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
gertk 0:b612024f5aee 24 */
gertk 0:b612024f5aee 25
gertk 0:b612024f5aee 26 #ifndef _Z80_H_
gertk 0:b612024f5aee 27 #define _Z80_H_
gertk 0:b612024f5aee 28
gertk 0:b612024f5aee 29 #include "stdio.h"
gertk 0:b612024f5aee 30
gertk 0:b612024f5aee 31 typedef unsigned short ushort;
gertk 0:b612024f5aee 32 typedef unsigned char byte;
gertk 0:b612024f5aee 33
gertk 0:b612024f5aee 34
gertk 0:b612024f5aee 35 /** Function type to emulate data read. */
gertk 0:b612024f5aee 36 typedef byte (*Z80DataIn) (int param, ushort address);
gertk 0:b612024f5aee 37
gertk 0:b612024f5aee 38
gertk 0:b612024f5aee 39 /** Function type to emulate data write. */
gertk 0:b612024f5aee 40 typedef void (*Z80DataOut) (int param, ushort address, byte data);
gertk 0:b612024f5aee 41
gertk 0:b612024f5aee 42
gertk 0:b612024f5aee 43 /**
gertk 0:b612024f5aee 44 * A Z80 register set.
gertk 0:b612024f5aee 45 * An union is used since we want independent access to the high and low bytes of the 16-bit registers.
gertk 0:b612024f5aee 46 */
gertk 0:b612024f5aee 47 typedef union
gertk 0:b612024f5aee 48 {
gertk 0:b612024f5aee 49 /** Word registers. */
gertk 0:b612024f5aee 50 struct
gertk 0:b612024f5aee 51 {
gertk 0:b612024f5aee 52 ushort AF, BC, DE, HL, IX, IY, SP;
gertk 0:b612024f5aee 53 } wr;
gertk 0:b612024f5aee 54
gertk 0:b612024f5aee 55 /** Byte registers. Note that SP can't be accesed partially. */
gertk 0:b612024f5aee 56 struct
gertk 0:b612024f5aee 57 {
gertk 0:b612024f5aee 58 byte F, A, C, B, E, D, L, H, IXl, IXh, IYl, IYh;
gertk 0:b612024f5aee 59 } br;
gertk 0:b612024f5aee 60 } Z80Regs;
gertk 0:b612024f5aee 61
gertk 0:b612024f5aee 62
gertk 0:b612024f5aee 63 /** The Z80 flags */
gertk 0:b612024f5aee 64 typedef enum
gertk 0:b612024f5aee 65 {
gertk 0:b612024f5aee 66 F_ = 0,
gertk 0:b612024f5aee 67 F_C = 1, /**< Carry */
gertk 0:b612024f5aee 68 F_N = 2, /**< Sub / Add */
gertk 0:b612024f5aee 69 F_PV = 4, /**< Parity / Overflow */
gertk 0:b612024f5aee 70 F_3 = 8, /**< Reserved */
gertk 0:b612024f5aee 71 F_H = 16, /**< Half carry */
gertk 0:b612024f5aee 72 F_5 = 32, /**< Reserved */
gertk 0:b612024f5aee 73 F_Z = 64, /**< Zero */
gertk 0:b612024f5aee 74 F_S = 128 /**< Sign */
gertk 0:b612024f5aee 75 } Z80Flags;
gertk 0:b612024f5aee 76
gertk 0:b612024f5aee 77
gertk 0:b612024f5aee 78 /** A Z80 execution context. */
gertk 0:b612024f5aee 79 typedef struct
gertk 0:b612024f5aee 80 {
gertk 0:b612024f5aee 81 Z80Regs R1; /**< Main register set (R) */
gertk 0:b612024f5aee 82 Z80Regs R2; /**< Alternate register set (R') */
gertk 0:b612024f5aee 83 ushort PC; /**< Program counter */
gertk 0:b612024f5aee 84 byte R; /**< Refresh */
gertk 0:b612024f5aee 85 byte I;
gertk 0:b612024f5aee 86 byte IFF1; /**< Interrupt Flipflop 1 */
gertk 0:b612024f5aee 87 byte IFF2; /**< Interrupt Flipflop 2 */
gertk 0:b612024f5aee 88 byte IM; /**< Instruction mode */
gertk 0:b612024f5aee 89
gertk 0:b612024f5aee 90 Z80DataIn memRead;
gertk 0:b612024f5aee 91 Z80DataOut memWrite;
gertk 0:b612024f5aee 92 int memParam;
gertk 0:b612024f5aee 93
gertk 0:b612024f5aee 94 Z80DataIn ioRead;
gertk 0:b612024f5aee 95 Z80DataOut ioWrite;
gertk 0:b612024f5aee 96 int ioParam;
gertk 0:b612024f5aee 97 } Z80Context;
gertk 0:b612024f5aee 98
gertk 0:b612024f5aee 99
gertk 0:b612024f5aee 100 /** Execute the next instruction. */
gertk 0:b612024f5aee 101 void Z80Execute (Z80Context* ctx);
gertk 0:b612024f5aee 102
gertk 0:b612024f5aee 103 /** Decode the next instruction to be executed.
gertk 0:b612024f5aee 104 * dump and decode can be NULL if such information is not needed
gertk 0:b612024f5aee 105 *
gertk 0:b612024f5aee 106 * @param dump A buffer which receives the hex dump
gertk 0:b612024f5aee 107 * @param decode A buffer which receives the decoded instruction
gertk 0:b612024f5aee 108 */
gertk 0:b612024f5aee 109 void Z80Debug (Z80Context* ctx, char* dump, char* decode);
gertk 0:b612024f5aee 110
gertk 0:b612024f5aee 111 /** Resets the processor. */
gertk 0:b612024f5aee 112 void Z80RESET (Z80Context* ctx);
gertk 0:b612024f5aee 113
gertk 0:b612024f5aee 114 /** Generates a hardware interrupt.
gertk 0:b612024f5aee 115 * Some interrupt modes read a value from the data bus; this value must be provided in this function call, even
gertk 0:b612024f5aee 116 * if the processor ignores that value in the current interrupt mode.
gertk 0:b612024f5aee 117 *
gertk 0:b612024f5aee 118 * @param value The value to read from the data bus
gertk 0:b612024f5aee 119 */
gertk 0:b612024f5aee 120 void Z80INT (Z80Context* ctx, byte value);
gertk 0:b612024f5aee 121
gertk 0:b612024f5aee 122
gertk 0:b612024f5aee 123 /** Generates a non-maskable interrupt. */
gertk 0:b612024f5aee 124 void Z80NMI (Z80Context* ctx);
gertk 0:b612024f5aee 125
gertk 0:b612024f5aee 126
gertk 0:b612024f5aee 127 #endif