Fixed warnings and whitespace

This commit is contained in:
Bart Trzynadlowski 2016-03-22 01:16:46 +00:00
parent f0488a3c94
commit bd09b3b68b
2 changed files with 4047 additions and 4042 deletions
Src/CPU/Z80

File diff suppressed because it is too large Load diff

View file

@ -27,17 +27,17 @@
* *
* Known inaccuracies: * Known inaccuracies:
* *
* - Interrupts are accepted immediately after EI instruction. In reality, * - Interrupts are accepted immediately after EI instruction. In reality,
* interrupts become enabled after the instruction following EI. This * interrupts become enabled after the instruction following EI. This
* could be implemented with a state machine in Run() if needed. * could be implemented with a state machine in Run() if needed.
* This feature exists to prevent interrupts from occuring before a RETI * This feature exists to prevent interrupts from occuring before a RETI
* instruction executes in the interrupt handler. Interrupt callbacks * instruction executes in the interrupt handler. Interrupt callbacks
* should take care to immediately clear the interrupt line, otherwise, * should take care to immediately clear the interrupt line, otherwise,
* an improperly timed interrupt may occur right after an EI instruction * an improperly timed interrupt may occur right after an EI instruction
* but before the service routine has a chance to return. * but before the service routine has a chance to return.
* - HALT instruction is not implemented (it just exits). * - HALT instruction is not implemented (it just exits).
* - 16-bit words are read as two bytes but these reads may not occur in * - 16-bit words are read as two bytes but these reads may not occur in
* the exact same order as the real device. Needs to be checked. * the exact same order as the real device. Needs to be checked.
*/ */
#ifndef INCLUDED_Z80_H #ifndef INCLUDED_Z80_H
@ -55,14 +55,14 @@
* supplied, and this is the only supported behavior here. The interrupt * supplied, and this is the only supported behavior here. The interrupt
* callback must return one of these values when the Z80 is in mode 0. * callback must return one of these values when the Z80 is in mode 0.
*/ */
#define Z80_INT_RST_00 0xC7 // RST 0x00 (jumps to 0x0000) #define Z80_INT_RST_00 0xC7 // RST 0x00 (jumps to 0x0000)
#define Z80_INT_RST_08 0xCF // RST 0x08 (jumps to 0x0008) #define Z80_INT_RST_08 0xCF // RST 0x08 (jumps to 0x0008)
#define Z80_INT_RST_10 0xD7 // RST 0x10 (...) #define Z80_INT_RST_10 0xD7 // RST 0x10 (...)
#define Z80_INT_RST_18 0xDF // RST 0x18 #define Z80_INT_RST_18 0xDF // RST 0x18
#define Z80_INT_RST_20 0xE7 // RST 0x20 #define Z80_INT_RST_20 0xE7 // RST 0x20
#define Z80_INT_RST_28 0xEF // RST 0x28 #define Z80_INT_RST_28 0xEF // RST 0x28
#define Z80_INT_RST_30 0xF7 // RST 0x30 #define Z80_INT_RST_30 0xF7 // RST 0x30
#define Z80_INT_RST_38 0xFF // RST 0x38 #define Z80_INT_RST_38 0xFF // RST 0x38
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
// Extra interrupt types // Extra interrupt types
@ -99,7 +99,9 @@
#define Z80_REG16_DE_ 11 #define Z80_REG16_DE_ 11
#define Z80_REG16_HL_ 12 #define Z80_REG16_HL_ 12
class Debugger::CZ80Debug; namespace Debugger {
class CZ80Debug;
}
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
/* /*
@ -110,229 +112,228 @@ class Debugger::CZ80Debug;
class CZ80 class CZ80
{ {
public: public:
/* /*
* Run(numCycles): * Run(numCycles):
* *
* Runs the Z80 for the specified number of instruction cycles. * Runs the Z80 for the specified number of instruction cycles.
* *
* Parameters: * Parameters:
* numCycles Number of instruction cycles to execute. * numCycles Number of instruction cycles to execute.
* *
* Returns: * Returns:
* Number of instruction cycles actually executed. * Number of instruction cycles actually executed.
*/ */
int Run(int numCycles); int Run(int numCycles);
/* /*
* TriggerNMI(void): * TriggerNMI(void):
* *
* Triggers a non-maskable interrupt. This is equivalent to a high-to-low * Triggers a non-maskable interrupt. This is equivalent to a high-to-low
* transition on the NMI pin (NMI pin is triggered on falling edges). This * transition on the NMI pin (NMI pin is triggered on falling edges). This
* may be called while the Z80 is running. NMIs are always higher priority * may be called while the Z80 is running. NMIs are always higher priority
* than interrupts and are taken first. * than interrupts and are taken first.
*/ */
void TriggerNMI(void); void TriggerNMI(void);
/* /*
* SetINT(state): * SetINT(state):
* *
* Set or clear the interrupt request. This may be called from memory * Set or clear the interrupt request. This may be called from memory
* handlers while the Z80 is running and should be used by interrupt * handlers while the Z80 is running and should be used by interrupt
* callbacks to clear interrupts. * callbacks to clear interrupts.
* *
* Parameters: * Parameters:
* state If TRUE, this is equivalent to /INT being asserted on the * state If TRUE, this is equivalent to /INT being asserted on the
* Z80 (INT line low, which triggers an interrupt). If FALSE, * Z80 (INT line low, which triggers an interrupt). If FALSE,
* this deasserts /INT (INT line high, no interrupt pending). * this deasserts /INT (INT line high, no interrupt pending).
*/ */
void SetINT(bool state); void SetINT(bool state);
/* /*
* GetPC(void): * GetPC(void):
* *
* Returns the current PC value. * Returns the current PC value.
* *
* Returns: * Returns:
* Current value of PC register. * Current value of PC register.
*/ */
UINT16 GetPC(void); UINT16 GetPC(void);
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
/* /*
* GetReg8(reg8): * GetReg8(reg8):
* *
* Reads an 8-bit register. * Reads an 8-bit register.
* *
* Parameters: * Parameters:
* reg8 Register number (use Z80_REG8_* macros). * reg8 Register number (use Z80_REG8_* macros).
* *
* Returns: * Returns:
* Value of given 8-bit register. * Value of given 8-bit register.
*/ */
UINT8 GetReg8(unsigned reg8); UINT8 GetReg8(unsigned reg8);
/* /*
* SetReg8(reg8, value): * SetReg8(reg8, value):
* *
* Sets value of given 8-bit register. * Sets value of given 8-bit register.
* *
* Parameters: * Parameters:
* reg8 Register number. * reg8 Register number.
* value Value to write. * value Value to write.
* *
* Returns: * Returns:
* True if succeeded, false if invalid register. * True if succeeded, false if invalid register.
*/ */
bool SetReg8(unsigned reg8, UINT8 value); bool SetReg8(unsigned reg8, UINT8 value);
/* /*
* GetReg16(reg16, value): * GetReg16(reg16, value):
* *
* Reads a 16-bit register. * Reads a 16-bit register.
* *
* Parameters: * Parameters:
* reg16 Register number (use Z80_REG16_* macros). * reg16 Register number (use Z80_REG16_* macros).
* *
* Returns: * Returns:
* Value of given 16-bit register. * Value of given 16-bit register.
*/ */
UINT16 GetReg16(unsigned reg16); UINT16 GetReg16(unsigned reg16);
/* /*
* SetReg16(state): * SetReg16(state):
* *
* Sets value of given 16-bit register. * Sets value of given 16-bit register.
* *
* Parameters: * Parameters:
* reg16 Register. * reg16 Register.
* value Value to write. * value Value to write.
* *
* Returns: * Returns:
* True if succeeded, false if invalid register. * True if succeeded, false if invalid register.
*/ */
bool SetReg16(unsigned reg16, UINT16 value); bool SetReg16(unsigned reg16, UINT16 value);
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
/* /*
* Reset(void): * Reset(void):
* *
* Resets the Z80, clearing all registers and pending interrupt requests. * Resets the Z80, clearing all registers and pending interrupt requests.
*/ */
void Reset(void); void Reset(void);
/* /*
* SaveState(StateFile, name): * SaveState(StateFile, name):
* *
* Saves the CPU state to the block file. * Saves the CPU state to the block file.
* *
* Parameters: * Parameters:
* StateFile Block file. * StateFile Block file.
* name Name of block to create (e.g. "Main Z80"), to facilitate * name Name of block to create (e.g. "Main Z80"), to facilitate
* multiple Z80 states in the same file. * multiple Z80 states in the same file.
*/ */
void SaveState(CBlockFile *StateFile, const char *name); void SaveState(CBlockFile *StateFile, const char *name);
/* /*
* LoadState(StateFile, name): * LoadState(StateFile, name):
* *
* Loads the CPU state. * Loads the CPU state.
* *
* Parameters: * Parameters:
* StateFile Block file. * StateFile Block file.
* name Name of block to load. * name Name of block to load.
*/ */
void LoadState(CBlockFile *StateFile, const char *name); void LoadState(CBlockFile *StateFile, const char *name);
/* /*
* Init(BusPtr, INTF): * Init(BusPtr, INTF):
* *
* One-time initialization of the Z80 emulator. Must be called first. * One-time initialization of the Z80 emulator. Must be called first.
* *
* A bus object must be supplied which will be used to handle all memory * A bus object must be supplied which will be used to handle all memory
* and IO accesses. The Read8, Write8, IORead8, and IOWrite8 members need * and IO accesses. The Read8, Write8, IORead8, and IOWrite8 members need
* to be defined. Addresses are automatically clamped to 16 bits for memory * to be defined. Addresses are automatically clamped to 16 bits for memory
* and 8 bits for IO accesses. * and 8 bits for IO accesses.
* *
* An interrupt callback, which is called each time an interrupt occurs, * An interrupt callback, which is called each time an interrupt occurs,
* should also be supplied. The interrupt callback should explicitly clear * should also be supplied. The interrupt callback should explicitly clear
* the INT status (using SetINT(FALSE)) and then return the appropriate * the INT status (using SetINT(FALSE)) and then return the appropriate
* vector depending on the interrupt mode that is used by the system. * vector depending on the interrupt mode that is used by the system.
* *
* For mode 0, only Z80_INT_RST_* values are acceptable. For mode 1, the * For mode 0, only Z80_INT_RST_* values are acceptable. For mode 1, the
* return value is discarded because the Z80 will always use vector 0x0038. * return value is discarded because the Z80 will always use vector 0x0038.
* In mode 2, an 8-bit value supplying the lower 8-bits of the interrupt * In mode 2, an 8-bit value supplying the lower 8-bits of the interrupt
* vector address must be returned. Bit 0 will be ignored in this case (0 * vector address must be returned. Bit 0 will be ignored in this case (0
* is used). * is used).
* *
* If a callback is not installed, the interrupt status will automatically * If a callback is not installed, the interrupt status will automatically
* be cleared and interrupts will not be taken when the Z80 is in a mode * be cleared and interrupts will not be taken when the Z80 is in a mode
* that requires vector data from the callback. In mode 1, the interrupt * that requires vector data from the callback. In mode 1, the interrupt
* callback (if one is provided) should explicitly clear the interrupt. The * callback (if one is provided) should explicitly clear the interrupt. The
* value returned will be unused. * value returned will be unused.
* *
* Parameters: * Parameters:
* BusPtr Pointer to a bus object. * BusPtr Pointer to a bus object.
* INTF Pointer to callback function. The function accepts a * INTF Pointer to callback function. The function accepts a
* a pointer to the Z80 object that received the interrupt. * a pointer to the Z80 object that received the interrupt.
*/ */
void Init(CBus *BusPtr, int (*INTF)(CZ80 *Z80)); void Init(CBus *BusPtr, int (*INTF)(CZ80 *Z80));
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
/* /*
* AttachDebugger(DebugPtr): * AttachDebugger(DebugPtr):
* *
* Attaches debugger to CPU. * Attaches debugger to CPU.
*/ */
void AttachDebugger(Debugger::CZ80Debug *DebugPtr); void AttachDebugger(Debugger::CZ80Debug *DebugPtr);
/* /*
* DetachDebugger(): * DetachDebugger():
* *
* Detaches debugger from CPU. * Detaches debugger from CPU.
*/ */
void DetachDebugger(); void DetachDebugger();
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
/* /*
* CZ80(void): * CZ80(void):
* ~CZ80(void): * ~CZ80(void):
* *
* Constructor and destructor. * Constructor and destructor.
*/ */
CZ80(void); CZ80(void);
~CZ80(void); ~CZ80(void);
private: private:
// Registers // Registers
struct GPR { // general purpose registers struct GPR { // general purpose registers
UINT16 bc; UINT16 bc;
UINT16 de; UINT16 de;
UINT16 hl; UINT16 hl;
} regs[2]; // two sets: primary (0) and alternate (1) } regs[2]; // two sets: primary (0) and alternate (1)
UINT16 af[2]; // AF (primary and alternate) UINT16 af[2]; // AF (primary and alternate)
UINT16 ir; // interrupt vector (I) and memory refresh (R) UINT16 ir; // interrupt vector (I) and memory refresh (R)
UINT16 ix; // index register X UINT16 ix; // index register X
UINT16 iy; // index register Y UINT16 iy; // index register Y
UINT16 sp; // stack pointer UINT16 sp; // stack pointer
UINT16 pc; // program counter UINT16 pc; // program counter
UINT8 iff; // interrupt flip flops (bit 1: IFF2, 0: IFF1) UINT8 iff; // interrupt flip flops (bit 1: IFF2, 0: IFF1)
UINT8 im; // interrupt mode (0, 1, or 2 only) UINT8 im; // interrupt mode (0, 1, or 2 only)
int regs_sel; // active register set (primary or alternate) int regs_sel; // active register set (primary or alternate)
int af_sel; // active AF int af_sel; // active AF
// Memory and IO bus // Memory and IO bus
CBus *Bus; CBus *Bus;
// Interrupts // Interrupts
bool nmiTrigger; bool nmiTrigger;
bool intLine; bool intLine;
int (*INTCallback)(CZ80 *Z80); int (*INTCallback)(CZ80 *Z80);
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
int lastCycles; int lastCycles;
Debugger::CZ80Debug *Debug;
Debugger::CZ80Debug *Debug;
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
}; };
#endif // INCLUDED_Z80_H #endif // INCLUDED_Z80_H