summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-10-27 09:23:03 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-10-27 09:23:03 (GMT)
commitaa62f9e12b5087bef8d2b72fb85f0a2ad7dc6420 (patch)
tree6697caa0e908093f39d4b51892b912131653072c
parent0e79a72b0074b43be97771f39f79150ef0771587 (diff)
downloadabc80sim-aa62f9e12b5087bef8d2b72fb85f0a2ad7dc6420.zip
abc80sim-aa62f9e12b5087bef8d2b72fb85f0a2ad7dc6420.tar.gz
abc80sim-aa62f9e12b5087bef8d2b72fb85f0a2ad7dc6420.tar.bz2
abc80sim-aa62f9e12b5087bef8d2b72fb85f0a2ad7dc6420.tar.xz
z80: optimize the handling of register R
Optimize the handling of register R by keeping the counting and the fixed parts separate, and only merge them when reading out the value. Since this is pretty rare, and incrementing is common, it is much more efficient. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--z80.c11
-rw-r--r--z80.h5
2 files changed, 8 insertions, 8 deletions
diff --git a/z80.c b/z80.c
index 0931ccc..4b029ff 100644
--- a/z80.c
+++ b/z80.c
@@ -127,8 +127,7 @@ static int parity(unsigned value)
static void add_r(uint8_t jump)
{
- /* Only the low 7 bits are incremented */
- REG_R = ((REG_R + jump) & 0x7f) | (REG_R & 0x80);
+ z80_state.rc += jump;
}
static void inc_r(void)
@@ -904,7 +903,7 @@ static void do_ldir(void)
mem_block_transfer(REG_DE, REG_HL, 1, REG_BC);
/* set registers to final values */
- inc_r((REG_BC-1) << 1);
+ add_r((REG_BC-1) << 1);
REG_DE += REG_BC;
REG_HL += REG_BC;
REG_BC = 0;
@@ -920,7 +919,7 @@ static void do_lddr(void)
mem_block_transfer(REG_DE, REG_HL, -1, REG_BC);
/* set registers to final values */
- inc_r((REG_BC-1) << 1);
+ add_r((REG_BC-1) << 1);
REG_DE -= REG_BC;
REG_HL -= REG_BC;
REG_BC = 0;
@@ -2366,7 +2365,7 @@ static void do_ED_instruction(wordregister *ix)
do_ld_a_ir(REG_R);
break;
case 0x4F: /* ld r, a */
- REG_R = REG_A;
+ z80_state.rf = z80_state.rc = REG_A;
break;
case 0x4B: /* ld bc, (address) */
@@ -2562,7 +2561,7 @@ int z80_run(int continuous)
indexed:
instruction = mem_read(REG_PC++);
- REG_R++;
+ inc_r();
switch(instruction)
{
diff --git a/z80.h b/z80.h
index 4056f92..3ff8cda 100644
--- a/z80.h
+++ b/z80.h
@@ -57,7 +57,8 @@ struct z80_state_struct
wordregister hl_prime;
uint8_t i; /* interrupt-page address register */
- uint8_t r; /* memory-refresh register */
+ uint8_t rc; /* counting part of register R (bits 6-0) */
+ uint8_t rf; /* fixed part of register R (bit 7) */
uint8_t iff1, iff2;
uint8_t interrupt_mode;
@@ -106,7 +107,7 @@ struct z80_state_struct
#define REG_IY (z80_state.iy.word)
#define REG_I (z80_state.i)
-#define REG_R (z80_state.r)
+#define REG_R ((z80_state.rc & 0x7f) | (z80_state.rf & 0x80))
/*
* Flag accessors: