reg_data

union reg_data

Represent a register.  It is useless, but in use.  No overhead anyway, just longer code.

See Also

CPU

Summary
reg_dataRepresent a register.
Variables
WThe value of the register
CPUThis class represents an ARM7TDMI CPU running at 16.78MHZ with 32 bit registers and two execution modes (ARM32bit, THUMB16bit).
Variables
mMemoryPointer to the GBA Memory Structure.
mGPRegistersThe general purpose registers.
mCPSRThe Current Program Status Register
mSPSRThe Saved Program Status Registers of all the modes that support it.
mPrefetchThe pipeline instruction prefetch of the CPU.
Functions
CPUInitializes the CPU.
InitializeSet the cpu to a starting state
GetOperationNameConverts arm opcode into assembly language.
ExecuteThumbAluOperationExecutes an Alu operation in THUMB Mode.
ExecuteOperationExecutes the next operation.
WriteRegisterNameObsolete Function, now not working.
InterruptWrites to the IF Register the interrupt code.
CpsrGetCarryGetter for the Carry Flag.
CpsrGetOverflowGetter for the Overflow Flag.
CpsrGetZeroGetter for the Zero Flag.
CpsrGetSignGetter for the Sign Flag.
CpsrGetIRQDisableGetter for the Interrupt Disable Flag.
CpsrGetFIQDisableGetter for the Fast Interrupt Disable Flag.
CpsrGetThumbModeGetter for the Thumb Mode Flag.
CpsrGetModeGetter for the CPU Mode.
CpsrSetCarrySetter for the Carry Flag.
CpsrSetOverflowSetter for the Overflow Flag.
CpsrSetZeroSetter for the Zero Flag.
CpsrSetSignSetter for the Sign Flag.
CpsrSetSignByValSets the sign flag according to a value.
CpsrSetZeroByValSets the zero flag according to a value.
CpsrSetOverflowByValsSets the overflow flag looking at the operands.
CpsrSetCarryByAddValsSets the carry flag looking at the operands of an addition.
CpsrSetCarryByAddValsSets the carry flag looking at the operands of a subtraction.
CpsrSetIRQDisableSetter for the I Flag.
CpsrSetFIQDisableSetter for the F Flag.
CpsrSetThumbModeSetter for the T Flag.
CpsrSetModeSetter for the Mode field of the CPSR.
GetGPRegisterIDGets the id of a GP register depending on the current mode.
GetCpsrRetrieve Current Program Status Register
GetSpsrIDGets the ID of the register SPSR with a particular mode.
GetSpsrValRetrieves the value of SPSR.
GetGPRegValueReturns the value contained inside a register (in the current mode).
SetAddFlagsSets the correct flags after an addition.
SetSubFlagsByValSets the correct flags after a subtraction.
SetSubFlagsSets the correct flags after a subtraction.
SetAddFlagsByValSets the correct flags after an addition.
SetGPRegisterValueSet the value of a register in current Mode.
GetPrefetchRetrieves pipeline prefetch.
SetPCSets the program counter.
SWI_CpuSetFastly executes Software Interrupt 0xB (CpuSet).
SWI_CpuFastSetFastly executes Software Interrupt 0xC (CpuFastSet).
SoftwareInterruptGenerates a Software Interrupt.

Variables

W

uint32_t W

The value of the register

See Also

CPU

CPU

class CPU

This class represents an ARM7TDMI CPU running at 16.78MHZ with 32 bit registers and two execution modes (ARM32bit, THUMB16bit).

See Also

Memory GBA reg_data

Summary
Variables
mMemoryPointer to the GBA Memory Structure.
mGPRegistersThe general purpose registers.
mCPSRThe Current Program Status Register
mSPSRThe Saved Program Status Registers of all the modes that support it.
mPrefetchThe pipeline instruction prefetch of the CPU.
Functions
CPUInitializes the CPU.
InitializeSet the cpu to a starting state
GetOperationNameConverts arm opcode into assembly language.
ExecuteThumbAluOperationExecutes an Alu operation in THUMB Mode.
ExecuteOperationExecutes the next operation.
WriteRegisterNameObsolete Function, now not working.
InterruptWrites to the IF Register the interrupt code.
CpsrGetCarryGetter for the Carry Flag.
CpsrGetOverflowGetter for the Overflow Flag.
CpsrGetZeroGetter for the Zero Flag.
CpsrGetSignGetter for the Sign Flag.
CpsrGetIRQDisableGetter for the Interrupt Disable Flag.
CpsrGetFIQDisableGetter for the Fast Interrupt Disable Flag.
CpsrGetThumbModeGetter for the Thumb Mode Flag.
CpsrGetModeGetter for the CPU Mode.
CpsrSetCarrySetter for the Carry Flag.
CpsrSetOverflowSetter for the Overflow Flag.
CpsrSetZeroSetter for the Zero Flag.
CpsrSetSignSetter for the Sign Flag.
CpsrSetSignByValSets the sign flag according to a value.
CpsrSetZeroByValSets the zero flag according to a value.
CpsrSetOverflowByValsSets the overflow flag looking at the operands.
CpsrSetCarryByAddValsSets the carry flag looking at the operands of an addition.
CpsrSetCarryByAddValsSets the carry flag looking at the operands of a subtraction.
CpsrSetIRQDisableSetter for the I Flag.
CpsrSetFIQDisableSetter for the F Flag.
CpsrSetThumbModeSetter for the T Flag.
CpsrSetModeSetter for the Mode field of the CPSR.
GetGPRegisterIDGets the id of a GP register depending on the current mode.
GetCpsrRetrieve Current Program Status Register
GetSpsrIDGets the ID of the register SPSR with a particular mode.
GetSpsrValRetrieves the value of SPSR.
GetGPRegValueReturns the value contained inside a register (in the current mode).
SetAddFlagsSets the correct flags after an addition.
SetSubFlagsByValSets the correct flags after a subtraction.
SetSubFlagsSets the correct flags after a subtraction.
SetAddFlagsByValSets the correct flags after an addition.
SetGPRegisterValueSet the value of a register in current Mode.
GetPrefetchRetrieves pipeline prefetch.
SetPCSets the program counter.
SWI_CpuSetFastly executes Software Interrupt 0xB (CpuSet).
SWI_CpuFastSetFastly executes Software Interrupt 0xC (CpuFastSet).
SoftwareInterruptGenerates a Software Interrupt.

Variables

mMemory

Memory* mMemory

Pointer to the GBA Memory Structure.

See Also

GBA Memory

mGPRegisters

reg_data mGPRegisters[29]

The general purpose registers.  0-15 USR, FIQ 16-22, SVC 23-24, IRQ 25-26, UND 27-28.

mCPSR

reg_data mCPSR

The Current Program Status Register

mSPSR

reg_data mSPSR[4]

The Saved Program Status Registers of all the modes that support it.

mPrefetch

uint32_t mPrefetch

The pipeline instruction prefetch of the CPU.

Functions

CPU

CPU(Memory *mem)

Initializes the CPU.

Parameters

memA pointer to the memory.  A CPU without memory is quite useless.

Initialize

void Initialize()

Set the cpu to a starting state

GetOperationName

void GetOperationName(char *buffer,  
int opcode,  
int opaddr,  
bool thumb =  false,
char *comment = nullptr)

Converts arm opcode into assembly language.  Effectively it is a disassembler function.

Parameters

bufferWhere the disassembled instruction is placed.  The caller have to allocate it.
opcodeThe opcode you want to disassembly
opaddrThe address of the operation (in parameter) useful for computing branch addresses
thumbA boolean value that tells wether it should consider the opcode a thumb instruction or not
commentAn optional comment (like DEC-to-HEX translations of values).  You have to allocate it.

See Also

ExecuteOperation

ExecuteThumbAluOperation

inline void ExecuteThumbAluOperation(int op,
int rd,
int op1,
int op2)

Executes an Alu operation in THUMB Mode.

Parameters

opThe alu operation code
rdThe destination register id
op1The first operand (passed as direct value even if in all arm opcodes it is a register)
op2The second operand (passed as direct value)

See Also

<ExecuteAluOperation> ExecuteOperation

ExecuteOperation

int ExecuteOperation()

Executes the next operation.

Returns

The number of consumed cycles.

See Also

<ExecuteAluOperation> ExecuteThumbAluOperation

WriteRegisterName

void WriteRegisterName(char *buffer,
int id)

Obsolete Function, now not working.

Parameters

bufferThe buffer where to store the name
idThe id of the register

See Also

GetOperationName

Interrupt

inline void Interrupt(int code)

Writes to the IF Register the interrupt code.  It will be acknowledged by the cpu in the next cycles.

Parameters

codeThe interrupt code

CpsrGetCarry

inline bool CpsrGetCarry()

Getter for the Carry Flag.

Returns

The C Flag state.

CpsrGetOverflow

inline bool CpsrGetOverflow()

Getter for the Overflow Flag.

Returns

The V Flag state.

CpsrGetZero

inline bool CpsrGetZero()

Getter for the Zero Flag.

Returns

The Z Flag state.

CpsrGetSign

inline bool CpsrGetSign()

Getter for the Sign Flag.

Returns

The N Flag state.

CpsrGetIRQDisable

inline bool CpsrGetIRQDisable()

Getter for the Interrupt Disable Flag.

Returns

The I Flag state.

CpsrGetFIQDisable

inline bool CpsrGetFIQDisable()

Getter for the Fast Interrupt Disable Flag.

Returns

The F Flag state.

CpsrGetThumbMode

inline bool CpsrGetThumbMode()

Getter for the Thumb Mode Flag.

Returns

The T Flag state.

CpsrGetMode

inline int CpsrGetMode()

Getter for the CPU Mode.

Returns

The CPU current Mode.

CpsrSetCarry

inline void CpsrSetCarry(bool value)

Setter for the Carry Flag.

Parameters

valueThe value to write.

CpsrSetOverflow

inline void CpsrSetOverflow(bool value)

Setter for the Overflow Flag.

Parameters

valueThe value to write.

CpsrSetZero

inline void CpsrSetZero(bool value)

Setter for the Zero Flag.

Parameters

valueThe value to write.

CpsrSetSign

inline void CpsrSetSign(bool value)

Setter for the Sign Flag.

Parameters

valueThe value to write.

CpsrSetSignByVal

inline void CpsrSetSignByVal(int val)

Sets the sign flag according to a value.

Parameters

valThe value to check.

CpsrSetZeroByVal

inline void CpsrSetZeroByVal(int val)

Sets the zero flag according to a value.

Parameters

valThe value to check.

CpsrSetOverflowByVals

inline void CpsrSetOverflowByVals(int op1,
int op2,
int res)

Sets the overflow flag looking at the operands.

Parameters

op1The first operand.
op2The second operand.
resThe result.

CpsrSetCarryByAddVals

inline void CpsrSetCarryByAddVals(int op1,
int op2,
int res)

Sets the carry flag looking at the operands of an addition.

Parameters

op1The first operand.
op2The second operand.
resThe result.

CpsrSetCarryByAddVals

Sets the carry flag looking at the operands of a subtraction.

Parameters

op1The first operand.
op2The second operand.

CpsrSetIRQDisable

inline void CpsrSetIRQDisable(bool value)

Setter for the I Flag.

Parameters

valueThe value to write.

CpsrSetFIQDisable

inline void CpsrSetFIQDisable(bool value)

Setter for the F Flag.

Parameters

valueThe value to write.

CpsrSetThumbMode

inline void CpsrSetThumbMode(bool value)

Setter for the T Flag.

Parameters

valueThe value to write.

CpsrSetMode

inline void CpsrSetMode(int value)

Setter for the Mode field of the CPSR.

Parameters

valueThe value to write.

GetGPRegisterID

inline int GetGPRegisterID(int regid,
int mode)

Gets the id of a GP register depending on the current mode.  Has to be optimized with some sort of lookup tables.

Parameters

regidThe register apparent id.
modeThe mode to use while searching.

Returns

The register ID with the selected mode.

GetCpsr

inline uint32_t GetCpsr()

Retrieve Current Program Status Register

Returns

The CPSR of the CPU.

GetSpsrID

inline int GetSpsrID(int mode)

Gets the ID of the register SPSR with a particular mode.

Parameters

modeThe mode to consider.

Returns

The id of the register.

GetSpsrVal

inline int GetSpsrVal()

Retrieves the value of SPSR.

Returns

The value of the SPSR in current mode.  If the mode hasn’t a SPSR, returns SPSR_fiq.

GetGPRegValue

inline uint32_t GetGPRegValue(int regid,  
int pcOff =  8)

Returns the value contained inside a register (in the current mode).

Parameters

regidThe ID of the register.
pcOffThe offset that the PC has (due to pipeline issues).

SetAddFlags

inline void SetAddFlags(int op1,
int op2,
int destinationID)

Sets the correct flags after an addition.

Parameters

op1The first operand.
op2The second operand.
destinationIDThe destination register ID

SetSubFlagsByVal

inline void SetSubFlagsByVal(int op1,
int op2,
uint32_t val)

Sets the correct flags after a subtraction.

Parameters

op1The first operand.
op2The second operand.
valThe result of the operation.

SetSubFlags

inline void SetSubFlags(int op1,
int op2,
int destinationID)

Sets the correct flags after a subtraction.

Parameters

op1The first operand.
op2The second operand.
destinationIDThe destination register ID

SetAddFlagsByVal

inline void SetAddFlagsByVal(int op1,
int op2,
uint32_t val)

Sets the correct flags after an addition.

Parameters

op1The first operand.
op2The second operand.
valThe result of the operation.

SetGPRegisterValue

inline void SetGPRegisterValue(int regid,
uint32_t val)

Set the value of a register in current Mode.

Parameters

regidThe register ID.
valThe value that will be written.

GetPrefetch

inline uint32_t GetPrefetch()

Retrieves pipeline prefetch.

Returns

The instruction that has to be executed.

SetPC

inline void SetPC(uint32_t val)

Sets the program counter.

Parameters

valThe value that will be written.

SWI_CpuSet

inline void SWI_CpuSet()

Fastly executes Software Interrupt 0xB (CpuSet).  This is one of the most called interrupts, so it is better to have a fast version.

See Also

SWI_CpuFastSet SoftwareInterrupt

SWI_CpuFastSet

inline void SWI_CpuFastSet()

Fastly executes Software Interrupt 0xC (CpuFastSet).  This is one of the most called interrupts, so it is better to have a fast version.

See Also

SWI_CpuSet SoftwareInterrupt

SoftwareInterrupt

inline void SoftwareInterrupt(uint8_t id,
int pcOff)

Generates a Software Interrupt.

Parameters

idThe id of the interrupt.
pcOffThe offset of the Program Counter (account for the current mode for instance)

See Also

SWI_CpuFastSet SWI_CpuSet

union reg_data
Represent a register.
uint32_t W
The value of the register
class CPU
This class represents an ARM7TDMI CPU running at 16.78MHZ with 32 bit registers and two execution modes (ARM32bit, THUMB16bit).
Memory* mMemory
Pointer to the GBA Memory Structure.
reg_data mGPRegisters[29]
The general purpose registers.
reg_data mCPSR
The Current Program Status Register
reg_data mSPSR[4]
The Saved Program Status Registers of all the modes that support it.
uint32_t mPrefetch
The pipeline instruction prefetch of the CPU.
CPU(Memory *mem)
Initializes the CPU.
void Initialize()
Set the cpu to a starting state
void GetOperationName(char *buffer,  
int opcode,  
int opaddr,  
bool thumb =  false,
char *comment = nullptr)
Converts arm opcode into assembly language.
inline void ExecuteThumbAluOperation(int op,
int rd,
int op1,
int op2)
Executes an Alu operation in THUMB Mode.
int ExecuteOperation()
Executes the next operation.
void WriteRegisterName(char *buffer,
int id)
Obsolete Function, now not working.
inline void Interrupt(int code)
Writes to the IF Register the interrupt code.
inline bool CpsrGetCarry()
Getter for the Carry Flag.
inline bool CpsrGetOverflow()
Getter for the Overflow Flag.
inline bool CpsrGetZero()
Getter for the Zero Flag.
inline bool CpsrGetSign()
Getter for the Sign Flag.
inline bool CpsrGetIRQDisable()
Getter for the Interrupt Disable Flag.
inline bool CpsrGetFIQDisable()
Getter for the Fast Interrupt Disable Flag.
inline bool CpsrGetThumbMode()
Getter for the Thumb Mode Flag.
inline int CpsrGetMode()
Getter for the CPU Mode.
inline void CpsrSetCarry(bool value)
Setter for the Carry Flag.
inline void CpsrSetOverflow(bool value)
Setter for the Overflow Flag.
inline void CpsrSetZero(bool value)
Setter for the Zero Flag.
inline void CpsrSetSign(bool value)
Setter for the Sign Flag.
inline void CpsrSetSignByVal(int val)
Sets the sign flag according to a value.
inline void CpsrSetZeroByVal(int val)
Sets the zero flag according to a value.
inline void CpsrSetOverflowByVals(int op1,
int op2,
int res)
Sets the overflow flag looking at the operands.
inline void CpsrSetCarryByAddVals(int op1,
int op2,
int res)
Sets the carry flag looking at the operands of an addition.
inline void CpsrSetIRQDisable(bool value)
Setter for the I Flag.
inline void CpsrSetFIQDisable(bool value)
Setter for the F Flag.
inline void CpsrSetThumbMode(bool value)
Setter for the T Flag.
inline void CpsrSetMode(int value)
Setter for the Mode field of the CPSR.
inline int GetGPRegisterID(int regid,
int mode)
Gets the id of a GP register depending on the current mode.
inline uint32_t GetCpsr()
Retrieve Current Program Status Register
inline int GetSpsrID(int mode)
Gets the ID of the register SPSR with a particular mode.
inline int GetSpsrVal()
Retrieves the value of SPSR.
inline uint32_t GetGPRegValue(int regid,  
int pcOff =  8)
Returns the value contained inside a register (in the current mode).
inline void SetAddFlags(int op1,
int op2,
int destinationID)
Sets the correct flags after an addition.
inline void SetSubFlagsByVal(int op1,
int op2,
uint32_t val)
Sets the correct flags after a subtraction.
inline void SetSubFlags(int op1,
int op2,
int destinationID)
Sets the correct flags after a subtraction.
inline void SetAddFlagsByVal(int op1,
int op2,
uint32_t val)
Sets the correct flags after an addition.
inline void SetGPRegisterValue(int regid,
uint32_t val)
Set the value of a register in current Mode.
inline uint32_t GetPrefetch()
Retrieves pipeline prefetch.
inline void SetPC(uint32_t val)
Sets the program counter.
inline void SWI_CpuSet()
Fastly executes Software Interrupt 0xB (CpuSet).
inline void SWI_CpuFastSet()
Fastly executes Software Interrupt 0xC (CpuFastSet).
inline void SoftwareInterrupt(uint8_t id,
int pcOff)
Generates a Software Interrupt.
struct Memory
Represents the entire address space of the GBA.
class GBA
This is the class representing the entire device.
Close