summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-10-27 08:54:00 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-10-27 08:54:00 (GMT)
commit69a213dcd49bce97a442f6c6f9bd534fa789c037 (patch)
treee426085fa00f8207e3ecb08247435f7584590504
parent3add6c43f43a93c0068727291f076e8d61cff70a (diff)
downloadabc80sim-69a213dcd49bce97a442f6c6f9bd534fa789c037.zip
abc80sim-69a213dcd49bce97a442f6c6f9bd534fa789c037.tar.gz
abc80sim-69a213dcd49bce97a442f6c6f9bd534fa789c037.tar.bz2
abc80sim-69a213dcd49bce97a442f6c6f9bd534fa789c037.tar.xz
z80: increment the R register properly
Bit 7 in R doesn't increment, but it *can* be programmed, confusingly enough. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--z80.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/z80.c b/z80.c
index bcf999d..16c5e58 100644
--- a/z80.c
+++ b/z80.c
@@ -125,6 +125,12 @@ static int parity(unsigned value)
return(parity_table[value]);
}
+static void inc_r(void)
+{
+ /* Only the low 7 bits are incremented */
+ REG_R = ((REG_R + 1) & 0x7f) | (REG_R & 0x80);
+}
+
static void do_add_flags(int a, int b, int result)
{
/*
@@ -1351,7 +1357,7 @@ static void do_CB_instruction(wordregister *ix)
*/
instruction = mem_read(REG_PC++);
- REG_R++;
+ inc_r();
switch(instruction)
{
@@ -2147,7 +2153,7 @@ static void do_CB_instruction(wordregister *ix)
addr = ix->word + (int8_t)mem_read(REG_PC++);
instruction = mem_read(REG_PC++);
- REG_R++;
+ inc_r();
data = mem_read(addr);
@@ -2250,7 +2256,7 @@ static void do_ED_instruction(wordregister *ix)
*/
instruction = mem_read(REG_PC++);
- REG_R++;
+ inc_r();
switch(instruction)
{
@@ -2339,7 +2345,7 @@ static void do_ED_instruction(wordregister *ix)
break;
case 0x5F: /* ld a, r */
- do_ld_a_ir(REG_R & 0x7f); /* The real R register is only 7 bits */
+ do_ld_a_ir(REG_R);
break;
case 0x4F: /* ld r, a */
REG_R = REG_A;