Dave Chapman | a814584 | 2006-03-11 15:44:35 +0000 | [diff] [blame] | 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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Dave Chapman | a814584 | 2006-03-11 15:44:35 +0000 | [diff] [blame] | 21 | * |
| 22 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 23 | * KIND, either express or implied. |
| 24 | * |
| 25 | ****************************************************************************/ |
| 26 | |
| 27 | #ifndef Z80_H_ |
| 28 | #define Z80_H_ |
| 29 | |
| 30 | /** |
| 31 | Environment for Z80 emulation. |
| 32 | |
| 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. |
| 35 | |
| 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. |
| 39 | |
| 40 | @author Alessandro Scotti |
| 41 | @version 1.0 |
| 42 | */ |
| 43 | |
| 44 | /** Sets the CPU cycle counter to the specified value. */ |
| 45 | void setCycles( unsigned value ); |
| 46 | |
| 47 | void onReturnFromInterrupt(void); |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | Z80 software emulator. |
| 52 | |
| 53 | @author Alessandro Scotti |
| 54 | @version 1.1 |
| 55 | */ |
| 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 |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | Constructor: creates a Z80 object with the specified environment. |
| 70 | */ |
| 71 | // Z80( Z80Environment & ); |
| 72 | |
| 73 | /** |
| 74 | Copy constructor: creates a copy of the specified Z80 object. |
| 75 | */ |
| 76 | // Z80( const Z80 & ); |
| 77 | |
| 78 | // /** Destructor. */ |
| 79 | // virtual ~Z80() { |
| 80 | |
| 81 | /** |
| 82 | Resets the CPU to its initial state. |
| 83 | |
| 84 | The stack pointer (SP) is set to F000h, all other registers are cleared. |
| 85 | */ |
| 86 | void z80_reset(void); |
| 87 | |
| 88 | /** |
| 89 | Runs the CPU for the specified number of cycles. |
| 90 | |
| 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. |
| 94 | |
| 95 | @param cycles number of cycles the CPU must execute |
| 96 | |
| 97 | @return the number of extra cycles executed by the last instruction |
| 98 | */ |
| 99 | unsigned z80_run( unsigned cycles ); |
| 100 | |
| 101 | /** |
| 102 | Executes one instruction. |
| 103 | */ |
| 104 | void z80_step(void); |
| 105 | |
| 106 | /** |
| 107 | Invokes an interrupt. |
| 108 | |
| 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. |
| 112 | |
| 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). |
| 118 | */ |
| 119 | void z80_interrupt( unsigned char data ); |
| 120 | |
| 121 | /** Forces a non-maskable interrupt. */ |
| 122 | void z80_nmi(void); |
| 123 | |
| 124 | /** |
| 125 | Copies CPU register from one object to another. |
| 126 | |
| 127 | Note that the environment is not copied, only registers. |
| 128 | */ |
| 129 | // Z80 & operator = ( const Z80 & ); |
| 130 | |
| 131 | /** Returns the size of the buffer needed to take a snapshot of the CPU. */ |
| 132 | unsigned getSizeOfSnapshotBuffer(void); |
| 133 | |
| 134 | /** |
| 135 | Takes a snapshot of the CPU. |
| 136 | |
| 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. |
| 140 | |
| 141 | Note: the size of the snapshot buffer must be no less than the size |
| 142 | returned by the getSizeOfSnapshotBuffer() function. |
| 143 | |
| 144 | @param buffer buffer where the snapshot data is stored |
| 145 | |
| 146 | @return the number of bytes written into the buffer |
| 147 | */ |
| 148 | unsigned takeSnapshot( unsigned char * buffer ); |
| 149 | |
| 150 | /** |
| 151 | Restores a snapshot taken with takeSnapshot(). |
| 152 | |
| 153 | This function uses the data saved in the snapshot buffer to restore the |
| 154 | CPU status. |
| 155 | |
| 156 | @param buffer buffer where the snapshot data is stored |
| 157 | |
| 158 | @return the number of bytes read from the buffer |
| 159 | */ |
| 160 | unsigned restoreSnapshot( unsigned char * buffer ); |
| 161 | |
| 162 | #endif // Z80_H_ |