cpu: re-indent the file
Running text editors in different environments led to some variations in indentation.
This commit is contained in:
132
src/gbemu/cpu.c
132
src/gbemu/cpu.c
@@ -13,7 +13,7 @@
|
|||||||
#define SET_BIT(x, idx) do {(x) |= (1 << (idx));} while (0)
|
#define SET_BIT(x, idx) do {(x) |= (1 << (idx));} while (0)
|
||||||
#define CLR_BIT(x, idx) do {(x) &= ~(1 << (idx));} while (0)
|
#define CLR_BIT(x, idx) do {(x) &= ~(1 << (idx));} while (0)
|
||||||
#define GET_BIT(x, bit) (((x) >> (bit)) & 1)
|
#define GET_BIT(x, bit) (((x) >> (bit)) & 1)
|
||||||
#define WRITE_BIT(x, idx, bit) \
|
#define WRITE_BIT(x, idx, bit) \
|
||||||
do {(x) &= (~(1 << (idx)) | ((bit) << (idx)));} while(0)
|
do {(x) &= (~(1 << (idx)) | ((bit) << (idx)));} while(0)
|
||||||
|
|
||||||
#define CALC_H_ADD(a, b) ((((a) & 0xf) + ((b) & 0xf)) > 0xf)
|
#define CALC_H_ADD(a, b) ((((a) & 0xf) + ((b) & 0xf)) > 0xf)
|
||||||
@@ -126,30 +126,30 @@ static const unsigned int cb_extra_cycles[256] = { 0 };
|
|||||||
|
|
||||||
/* TODO: optimize macros with temp variables so mem_read() doesn't expand multiple times */
|
/* TODO: optimize macros with temp variables so mem_read() doesn't expand multiple times */
|
||||||
#define INC_8(cpu, reg) \
|
#define INC_8(cpu, reg) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->nf = 0; \
|
(cpu)->nf = 0; \
|
||||||
(cpu)->hf = CALC_H_ADD(reg, 1); \
|
(cpu)->hf = CALC_H_ADD(reg, 1); \
|
||||||
(reg)++; \
|
(reg)++; \
|
||||||
(cpu)->zf = (reg) == 0; \
|
(cpu)->zf = (reg) == 0; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define DEC_8(cpu, reg) \
|
#define DEC_8(cpu, reg) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->nf = 1; \
|
(cpu)->nf = 1; \
|
||||||
(cpu)->hf = CALC_H_SUB(reg, 1); \
|
(cpu)->hf = CALC_H_SUB(reg, 1); \
|
||||||
(reg)--; \
|
(reg)--; \
|
||||||
(cpu)->zf = (reg) == 0; \
|
(cpu)->zf = (reg) == 0; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LD_D8(cpu, reg) \
|
#define LD_D8(cpu, reg) \
|
||||||
do { \
|
do { \
|
||||||
(reg) = (cpu)->mem_read((cpu), (cpu)->pc++); \
|
(reg) = (cpu)->mem_read((cpu), (cpu)->pc++); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LD_D16(cpu, reg) \
|
#define LD_D16(cpu, reg) \
|
||||||
do { \
|
do { \
|
||||||
(reg) = (cpu)->mem_read((cpu), (cpu)->pc++); \
|
(reg) = (cpu)->mem_read((cpu), (cpu)->pc++); \
|
||||||
(reg) |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->pc++) << 8; \
|
(reg) |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->pc++) << 8; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ADD_8(cpu, dst, src) \
|
#define ADD_8(cpu, dst, src) \
|
||||||
@@ -236,69 +236,69 @@ static const unsigned int cb_extra_cycles[256] = { 0 };
|
|||||||
(cpu)->zf = ((dst) == 0); \
|
(cpu)->zf = ((dst) == 0); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CP_8(cpu, dst, src) \
|
#define CP_8(cpu, dst, src) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t _tmp; \
|
uint8_t _tmp; \
|
||||||
uint8_t _dst = dst; \
|
uint8_t _dst = dst; \
|
||||||
uint8_t _src = src; \
|
uint8_t _src = src; \
|
||||||
(cpu)->nf = 1; \
|
(cpu)->nf = 1; \
|
||||||
(cpu)->hf = CALC_H_SUB((_dst), (_src)); \
|
(cpu)->hf = CALC_H_SUB((_dst), (_src)); \
|
||||||
(cpu)->cf = CALC_C_SUB((_dst), (_src)); \
|
(cpu)->cf = CALC_C_SUB((_dst), (_src)); \
|
||||||
_tmp = (_dst) - (_src); \
|
_tmp = (_dst) - (_src); \
|
||||||
(cpu)->zf = ((_tmp) == 0); \
|
(cpu)->zf = ((_tmp) == 0); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define JR_8(cpu) \
|
#define JR_8(cpu) \
|
||||||
do { \
|
do { \
|
||||||
val_16 = cpu->mem_read(cpu, cpu->pc++); \
|
val_16 = cpu->mem_read(cpu, cpu->pc++); \
|
||||||
/* sign-extend */ \
|
/* sign-extend */ \
|
||||||
val_16 |= GET_BIT(val_16, 7) ? 0xff00 : 0; \
|
val_16 |= GET_BIT(val_16, 7) ? 0xff00 : 0; \
|
||||||
cpu->pc += val_16; \
|
cpu->pc += val_16; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* TODO: In general, check that we pop/push things correctly */
|
/* TODO: In general, check that we pop/push things correctly */
|
||||||
#define POP_16(cpu, dst) \
|
#define POP_16(cpu, dst) \
|
||||||
do { \
|
do { \
|
||||||
(dst) = (cpu)->mem_read((cpu), (cpu)->sp++); \
|
(dst) = (cpu)->mem_read((cpu), (cpu)->sp++); \
|
||||||
(dst) |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->sp++) << 8; \
|
(dst) |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->sp++) << 8; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PUSH_16(cpu, src) \
|
#define PUSH_16(cpu, src) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->mem_write(cpu, --cpu->sp, src); \
|
(cpu)->mem_write(cpu, --cpu->sp, src); \
|
||||||
(cpu)->mem_write(cpu, --cpu->sp, src >> 8); \
|
(cpu)->mem_write(cpu, --cpu->sp, src >> 8); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CALL(cpu) \
|
#define CALL(cpu) \
|
||||||
do { \
|
do { \
|
||||||
uint16_t pc_base; \
|
uint16_t pc_base; \
|
||||||
cpu->mem_write(cpu, --cpu->sp, cpu->pc); \
|
cpu->mem_write(cpu, --cpu->sp, cpu->pc); \
|
||||||
cpu->mem_write(cpu, --cpu->sp, cpu->pc >> 8); \
|
cpu->mem_write(cpu, --cpu->sp, cpu->pc >> 8); \
|
||||||
pc_base = cpu->mem_read(cpu, cpu->pc++); \
|
pc_base = cpu->mem_read(cpu, cpu->pc++); \
|
||||||
pc_base |= (uint16_t) cpu->mem_read(cpu, cpu->pc) << 8; \
|
pc_base |= (uint16_t) cpu->mem_read(cpu, cpu->pc) << 8; \
|
||||||
cpu->pc = pc_base; \
|
cpu->pc = pc_base; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define RET(cpu) \
|
#define RET(cpu) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->pc = 0; \
|
(cpu)->pc = 0; \
|
||||||
(cpu)->pc |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->sp++) << 8; \
|
(cpu)->pc |= (uint16_t) (cpu)->mem_read((cpu), (cpu)->sp++) << 8; \
|
||||||
(cpu)->pc |= (cpu)->mem_read((cpu), (cpu)->sp++); \
|
(cpu)->pc |= (cpu)->mem_read((cpu), (cpu)->sp++); \
|
||||||
(cpu)->pc += 2; \
|
(cpu)->pc += 2; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define RST(cpu, n) \
|
#define RST(cpu, n) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->mem_write((cpu), (cpu)->sp++, (cpu)->pc >> 8); \
|
(cpu)->mem_write((cpu), (cpu)->sp++, (cpu)->pc >> 8); \
|
||||||
(cpu)->mem_write((cpu), (cpu)->sp++, (cpu)->pc); \
|
(cpu)->mem_write((cpu), (cpu)->sp++, (cpu)->pc); \
|
||||||
(cpu)->pc = (n); \
|
(cpu)->pc = (n); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define BIT(cpu, reg, bit) \
|
#define BIT(cpu, reg, bit) \
|
||||||
do { \
|
do { \
|
||||||
(cpu)->zf = !GET_BIT(reg, bit); \
|
(cpu)->zf = !GET_BIT(reg, bit); \
|
||||||
(cpu)->nf = 0; \
|
(cpu)->nf = 0; \
|
||||||
(cpu)->hf = 1; \
|
(cpu)->hf = 1; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define RES(reg, bit) \
|
#define RES(reg, bit) \
|
||||||
@@ -311,16 +311,16 @@ static const unsigned int cb_extra_cycles[256] = { 0 };
|
|||||||
SET_BIT(reg, bit); \
|
SET_BIT(reg, bit); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define RL(cpu, reg) \
|
#define RL(cpu, reg) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t ci = (cpu)->cf; \
|
uint8_t ci = (cpu)->cf; \
|
||||||
uint8_t tmp = reg; \
|
uint8_t tmp = reg; \
|
||||||
(cpu)->nf = 0; \
|
(cpu)->nf = 0; \
|
||||||
(cpu)->hf = 0; \
|
(cpu)->hf = 0; \
|
||||||
(cpu)->cf = GET_BIT(tmp, 7); \
|
(cpu)->cf = GET_BIT(tmp, 7); \
|
||||||
tmp = tmp << 1; \
|
tmp = tmp << 1; \
|
||||||
(tmp) |= ci; \
|
(tmp) |= ci; \
|
||||||
(cpu)->zf = (tmp) == 0; \
|
(cpu)->zf = (tmp) == 0; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int lr35902_cycle(struct lr35902_state *cpu)
|
int lr35902_cycle(struct lr35902_state *cpu)
|
||||||
|
|||||||
Reference in New Issue
Block a user