Prepare new maemo release
[maemo-rb.git] / apps / plugins / pacbox / z80.h
blob02d8f184e0d7492fe8a03dbb5e73245810145887
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Pacbox - a Pacman Emulator for Rockbox
12 * Based on PIE - Pacman Instructional Emulator
14 * Copyright (c) 1997-2003,2004 Alessandro Scotti
15 * http://www.ascotti.org/
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
27 #ifndef Z80_H_
28 #define Z80_H_
30 /**
31 Environment for Z80 emulation.
33 This class implements all input/output functions for the Z80 emulator class,
34 that is it provides functions to access the system RAM, ROM and I/O ports.
36 An object of this class corresponds to a system that has no RAM, ROM or ports:
37 users of the Z80 emulator should provide the desired behaviour by writing a
38 descendant of this class.
40 @author Alessandro Scotti
41 @version 1.0
44 /** Sets the CPU cycle counter to the specified value. */
45 void setCycles( unsigned value );
47 void onReturnFromInterrupt(void);
50 /**
51 Z80 software emulator.
53 @author Alessandro Scotti
54 @version 1.1
56 /** CPU flags */
57 enum {
58 Carry = 0x01, // C
59 AddSub = 0x02, Subtraction = AddSub, // N
60 Parity = 0x04, Overflow = Parity, // P/V, same bit used for parity and overflow
61 Flag3 = 0x08, // Aka XF, not used
62 Halfcarry = 0x10, // H
63 Flag5 = 0x20, // Aka YF, not used
64 Zero = 0x40, // Z
65 Sign = 0x80 // S
68 /**
69 Constructor: creates a Z80 object with the specified environment.
71 // Z80( Z80Environment & );
73 /**
74 Copy constructor: creates a copy of the specified Z80 object.
76 // Z80( const Z80 & );
78 // /** Destructor. */
79 // virtual ~Z80() {
81 /**
82 Resets the CPU to its initial state.
84 The stack pointer (SP) is set to F000h, all other registers are cleared.
86 void z80_reset(void);
88 /**
89 Runs the CPU for the specified number of cycles.
91 Note that the number of CPU cycles performed by this function may be
92 actually a little more than the value specified. If that happens then the
93 function returns the number of extra cycles executed.
95 @param cycles number of cycles the CPU must execute
97 @return the number of extra cycles executed by the last instruction
99 unsigned z80_run( unsigned cycles );
102 Executes one instruction.
104 void z80_step(void);
107 Invokes an interrupt.
109 If interrupts are enabled, the current program counter (PC) is saved on
110 the stack and assigned the specified address. When the interrupt handler
111 returns, execution resumes from the point where the interrupt occurred.
113 The actual interrupt address depends on the current interrupt mode and
114 on the interrupt type. For maskable interrupts, data is as follows:
115 - mode 0: data is an opcode that is executed (usually RST xxh);
116 - mode 1: data is ignored and a call is made to address 0x38;
117 - mode 2: a call is made to the 16 bit address given by (256*I + data).
119 void z80_interrupt( unsigned char data );
121 /** Forces a non-maskable interrupt. */
122 void z80_nmi(void);
125 Copies CPU register from one object to another.
127 Note that the environment is not copied, only registers.
129 // Z80 & operator = ( const Z80 & );
131 /** Returns the size of the buffer needed to take a snapshot of the CPU. */
132 unsigned getSizeOfSnapshotBuffer(void);
134 /**
135 Takes a snapshot of the CPU.
137 A snapshot saves all of the CPU registers and internals. It can be
138 restored at any time to bring the CPU back to the exact status it
139 had when the snapshot was taken.
141 Note: the size of the snapshot buffer must be no less than the size
142 returned by the getSizeOfSnapshotBuffer() function.
144 @param buffer buffer where the snapshot data is stored
146 @return the number of bytes written into the buffer
148 unsigned takeSnapshot( unsigned char * buffer );
151 Restores a snapshot taken with takeSnapshot().
153 This function uses the data saved in the snapshot buffer to restore the
154 CPU status.
156 @param buffer buffer where the snapshot data is stored
158 @return the number of bytes read from the buffer
160 unsigned restoreSnapshot( unsigned char * buffer );
162 #endif // Z80_H_