change how flags works
This commit is contained in:
15
src/emu.c
15
src/emu.c
@@ -5,13 +5,14 @@ static inline Instruction fetchInst(Emulator* emu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void updateFlagsRegister(Emulator* emu, int32_t value) {
|
static inline void updateFlagsRegister(Emulator* emu, int32_t value) {
|
||||||
if (value == 0) {
|
|
||||||
emu->regs[REG_F] = FLAG_ZERO;
|
FlagsRegister flags = (FlagsRegister)emu->regs[REG_F];
|
||||||
} else if (value < 0) {
|
|
||||||
emu->regs[REG_F] = FLAG_NEGATIVE;
|
flags.fields.zero = value == 0;
|
||||||
} else if (value > UINT16_MAX) {
|
flags.fields.negative = value < 0;
|
||||||
emu->regs[REG_F] = FLAG_OVERFLOW;
|
flags.fields.overflow = value > UINT16_MAX;
|
||||||
}
|
|
||||||
|
emu->regs[REG_F] = flags.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void updateDevices(Emulator* emu) {
|
static inline void updateDevices(Emulator* emu) {
|
||||||
|
|||||||
12
src/emu.h
12
src/emu.h
@@ -24,9 +24,21 @@ typedef struct {
|
|||||||
uint32_t ihp;
|
uint32_t ihp;
|
||||||
uint32_t sp;
|
uint32_t sp;
|
||||||
|
|
||||||
|
bool irq;
|
||||||
bool halted;
|
bool halted;
|
||||||
} Emulator;
|
} Emulator;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct {
|
||||||
|
uint16_t zero : 1;
|
||||||
|
uint16_t overflow : 1;
|
||||||
|
uint16_t negative : 1;
|
||||||
|
uint16_t interrupts : 1;
|
||||||
|
} fields;
|
||||||
|
|
||||||
|
uint16_t raw;
|
||||||
|
} FlagsRegister;
|
||||||
|
|
||||||
// -- FUNCTIONS -- //
|
// -- FUNCTIONS -- //
|
||||||
Emulator* initEmulator(uint32_t memorySize);
|
Emulator* initEmulator(uint32_t memorySize);
|
||||||
void freeEmulator(Emulator* emu);
|
void freeEmulator(Emulator* emu);
|
||||||
|
|||||||
Reference in New Issue
Block a user