diff options
Diffstat (limited to 'apps/plugins/pacbox/z80.h')
-rw-r--r-- | apps/plugins/pacbox/z80.h | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/apps/plugins/pacbox/z80.h b/apps/plugins/pacbox/z80.h new file mode 100644 index 0000000000..b6288981d0 --- /dev/null +++ b/apps/plugins/pacbox/z80.h | |||
@@ -0,0 +1,160 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Pacbox - a Pacman Emulator for Rockbox | ||
11 | * | ||
12 | * Based on PIE - Pacman Instructional Emulator | ||
13 | * | ||
14 | * Copyright (c) 1997-2003,2004 Alessandro Scotti | ||
15 | * http://www.ascotti.org/ | ||
16 | * | ||
17 | * All files in this archive are subject to the GNU General Public License. | ||
18 | * See the file COPYING in the source tree root for full license agreement. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | |||
25 | #ifndef Z80_H_ | ||
26 | #define Z80_H_ | ||
27 | |||
28 | /** | ||
29 | Environment for Z80 emulation. | ||
30 | |||
31 | This class implements all input/output functions for the Z80 emulator class, | ||
32 | that is it provides functions to access the system RAM, ROM and I/O ports. | ||
33 | |||
34 | An object of this class corresponds to a system that has no RAM, ROM or ports: | ||
35 | users of the Z80 emulator should provide the desired behaviour by writing a | ||
36 | descendant of this class. | ||
37 | |||
38 | @author Alessandro Scotti | ||
39 | @version 1.0 | ||
40 | */ | ||
41 | |||
42 | /** Sets the CPU cycle counter to the specified value. */ | ||
43 | void setCycles( unsigned value ); | ||
44 | |||
45 | void onReturnFromInterrupt(void); | ||
46 | |||
47 | |||
48 | /** | ||
49 | Z80 software emulator. | ||
50 | |||
51 | @author Alessandro Scotti | ||
52 | @version 1.1 | ||
53 | */ | ||
54 | /** CPU flags */ | ||
55 | enum { | ||
56 | Carry = 0x01, // C | ||
57 | AddSub = 0x02, Subtraction = AddSub, // N | ||
58 | Parity = 0x04, Overflow = Parity, // P/V, same bit used for parity and overflow | ||
59 | Flag3 = 0x08, // Aka XF, not used | ||
60 | Halfcarry = 0x10, // H | ||
61 | Flag5 = 0x20, // Aka YF, not used | ||
62 | Zero = 0x40, // Z | ||
63 | Sign = 0x80 // S | ||
64 | }; | ||
65 | |||
66 | /** | ||
67 | Constructor: creates a Z80 object with the specified environment. | ||
68 | */ | ||
69 | // Z80( Z80Environment & ); | ||
70 | |||
71 | /** | ||
72 | Copy constructor: creates a copy of the specified Z80 object. | ||
73 | */ | ||
74 | // Z80( const Z80 & ); | ||
75 | |||
76 | // /** Destructor. */ | ||
77 | // virtual ~Z80() { | ||
78 | |||
79 | /** | ||
80 | Resets the CPU to its initial state. | ||
81 | |||
82 | The stack pointer (SP) is set to F000h, all other registers are cleared. | ||
83 | */ | ||
84 | void z80_reset(void); | ||
85 | |||
86 | /** | ||
87 | Runs the CPU for the specified number of cycles. | ||
88 | |||
89 | Note that the number of CPU cycles performed by this function may be | ||
90 | actually a little more than the value specified. If that happens then the | ||
91 | function returns the number of extra cycles executed. | ||
92 | |||
93 | @param cycles number of cycles the CPU must execute | ||
94 | |||
95 | @return the number of extra cycles executed by the last instruction | ||
96 | */ | ||
97 | unsigned z80_run( unsigned cycles ); | ||
98 | |||
99 | /** | ||
100 | Executes one instruction. | ||
101 | */ | ||
102 | void z80_step(void); | ||
103 | |||
104 | /** | ||
105 | Invokes an interrupt. | ||
106 | |||
107 | If interrupts are enabled, the current program counter (PC) is saved on | ||
108 | the stack and assigned the specified address. When the interrupt handler | ||
109 | returns, execution resumes from the point where the interrupt occurred. | ||
110 | |||
111 | The actual interrupt address depends on the current interrupt mode and | ||
112 | on the interrupt type. For maskable interrupts, data is as follows: | ||
113 | - mode 0: data is an opcode that is executed (usually RST xxh); | ||
114 | - mode 1: data is ignored and a call is made to address 0x38; | ||
115 | - mode 2: a call is made to the 16 bit address given by (256*I + data). | ||
116 | */ | ||
117 | void z80_interrupt( unsigned char data ); | ||
118 | |||
119 | /** Forces a non-maskable interrupt. */ | ||
120 | void z80_nmi(void); | ||
121 | |||
122 | /** | ||
123 | Copies CPU register from one object to another. | ||
124 | |||
125 | Note that the environment is not copied, only registers. | ||
126 | */ | ||
127 | // Z80 & operator = ( const Z80 & ); | ||
128 | |||
129 | /** Returns the size of the buffer needed to take a snapshot of the CPU. */ | ||
130 | unsigned getSizeOfSnapshotBuffer(void); | ||
131 | |||
132 | /** | ||
133 | Takes a snapshot of the CPU. | ||
134 | |||
135 | A snapshot saves all of the CPU registers and internals. It can be | ||
136 | restored at any time to bring the CPU back to the exact status it | ||
137 | had when the snapshot was taken. | ||
138 | |||
139 | Note: the size of the snapshot buffer must be no less than the size | ||
140 | returned by the getSizeOfSnapshotBuffer() function. | ||
141 | |||
142 | @param buffer buffer where the snapshot data is stored | ||
143 | |||
144 | @return the number of bytes written into the buffer | ||
145 | */ | ||
146 | unsigned takeSnapshot( unsigned char * buffer ); | ||
147 | |||
148 | /** | ||
149 | Restores a snapshot taken with takeSnapshot(). | ||
150 | |||
151 | This function uses the data saved in the snapshot buffer to restore the | ||
152 | CPU status. | ||
153 | |||
154 | @param buffer buffer where the snapshot data is stored | ||
155 | |||
156 | @return the number of bytes read from the buffer | ||
157 | */ | ||
158 | unsigned restoreSnapshot( unsigned char * buffer ); | ||
159 | |||
160 | #endif // Z80_H_ | ||