Browse Source

Fix a bug in VDP control port writes; rename 'last_index' to 'regs.ixy'.

master
Ben Kurtovic 8 years ago
parent
commit
67e3133f14
4 changed files with 34 additions and 17 deletions
  1. +8
    -4
      src/vdp.c
  2. +4
    -2
      src/z80.c
  3. +3
    -1
      src/z80.h
  4. +19
    -10
      src/z80_ops.inc.c

+ 8
- 4
src/vdp.c View File

@@ -184,11 +184,13 @@ void vdp_write_control(VDP *vdp, uint8_t byte)
{
if (!vdp->control_flag) { // First byte
vdp->control_addr = (vdp->control_addr & 0x3F00) + byte;
} else { // Second byte
vdp->control_addr = ((byte & 0x3F) << 8) + (vdp->control_addr & 0xFF);
vdp->control_code = byte >> 6;
vdp->control_flag = true;
return;
}

vdp->control_addr = ((byte & 0x3F) << 8) + (vdp->control_addr & 0xFF);
vdp->control_code = byte >> 6;

if (vdp->control_code == CODE_VRAM_READ) {
vdp->read_buf = vdp->vram[vdp->control_addr];
vdp->control_addr = (vdp->control_addr + 1) % 0x3FFF;
@@ -198,7 +200,7 @@ void vdp_write_control(VDP *vdp, uint8_t byte)
vdp->regs[reg] = vdp->control_addr & 0xFF;
}

vdp->control_flag = !vdp->control_flag;
vdp->control_flag = false;
}

/*
@@ -238,6 +240,7 @@ void vdp_write_data(VDP *vdp, uint8_t byte)
*/
bool vdp_assert_irq(VDP *vdp)
{
// TODO: line interrupts
return vdp->stat_int && should_frame_interrupt(vdp);
}

@@ -250,6 +253,7 @@ void vdp_dump_registers(const VDP *vdp)
const uint8_t *regs = vdp->regs;
DEBUG("Dumping VDP register values:")

// TODO: show flags
DEBUG("- $00: 0x%02X (" BINARY_FMT ")", regs[0x00], BINARY_VAL(regs[0]))
DEBUG("- $01: 0x%02X (" BINARY_FMT ")", regs[0x01], BINARY_VAL(regs[1]))



+ 4
- 2
src/z80.c View File

@@ -60,8 +60,10 @@ void z80_power(Z80 *z80)
z80->regs.im_a = z80->regs.im_b = 0;
z80->regs.iff1 = z80->regs.iff2 = 0;

z80->regs.ixy = NULL;
z80->regs.ih = z80->regs.il = NULL;

z80->except = false;
z80->last_index = NULL;
z80->pending_cycles = 0;

z80->trace.fresh = true;
@@ -206,7 +208,7 @@ static inline bool extract_cond(const Z80 *z80, uint8_t opcode)
*/
static inline uint16_t get_index_addr(Z80 *z80, uint16_t offset_addr)
{
return *z80->last_index + ((int8_t) mmu_read_byte(z80->mmu, offset_addr));
return *z80->regs.ixy + ((int8_t) mmu_read_byte(z80->mmu, offset_addr));
}

/*


+ 3
- 1
src/z80.h View File

@@ -50,6 +50,9 @@ typedef struct {
uint8_t i, r;
bool im_a, im_b;
bool iff1, iff2;

uint16_t *ixy;
uint8_t *ih, *il;
} Z80RegFile;

typedef struct {
@@ -64,7 +67,6 @@ typedef struct {
IO *io;
bool except;
uint8_t exc_code, exc_data;
uint16_t *last_index;
double pending_cycles;
Z80TraceInfo trace;
} Z80;


+ 19
- 10
src/z80_ops.inc.c View File

@@ -246,7 +246,7 @@ static uint8_t z80_inst_ld_dd_nn(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_ld_ixy_nn(Z80 *z80, uint8_t opcode)
{
(void) opcode;
*z80->last_index = mmu_read_double(z80->mmu, ++z80->regs.pc);
*z80->regs.ixy = mmu_read_double(z80->mmu, ++z80->regs.pc);
z80->regs.pc += 2;
return 14;
}
@@ -284,7 +284,7 @@ static uint8_t z80_inst_ld_ixy_inn(Z80 *z80, uint8_t opcode)
{
(void) opcode;
uint16_t addr = mmu_read_double(z80->mmu, ++z80->regs.pc);
*z80->last_index = mmu_read_double(z80->mmu, addr);
*z80->regs.ixy = mmu_read_double(z80->mmu, addr);
z80->regs.pc += 2;
return 20;
}
@@ -322,7 +322,7 @@ static uint8_t z80_inst_ld_inn_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
uint16_t addr = mmu_read_double(z80->mmu, ++z80->regs.pc);
mmu_write_double(z80->mmu, addr, *z80->last_index);
mmu_write_double(z80->mmu, addr, *z80->regs.ixy);
z80->regs.pc += 2;
return 20;
}
@@ -345,7 +345,7 @@ static uint8_t z80_inst_ld_sp_hl(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_ld_sp_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
*z80->last_index = z80->regs.hl;
*z80->regs.ixy = z80->regs.hl;
return 10;
}

@@ -367,7 +367,7 @@ static uint8_t z80_inst_push_qq(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_push_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
stack_push(z80, *z80->last_index);
stack_push(z80, *z80->regs.ixy);
z80->regs.pc++;
return 15;
}
@@ -390,7 +390,7 @@ static uint8_t z80_inst_pop_qq(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_pop_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
*z80->last_index = stack_pop(z80);
*z80->regs.ixy = stack_pop(z80);
z80->regs.pc++;
return 14;
}
@@ -463,8 +463,8 @@ static uint8_t z80_inst_ex_sp_hl(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_ex_sp_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
uint16_t ixy = *z80->last_index, sp = z80->regs.sp;
*z80->last_index = mmu_read_double(z80->mmu, sp);
uint16_t ixy = *z80->regs.ixy, sp = z80->regs.sp;
*z80->regs.ixy = mmu_read_double(z80->mmu, sp);
mmu_write_double(z80->mmu, sp, ixy);
z80->regs.pc++;
return 23;
@@ -1210,7 +1210,7 @@ static uint8_t z80_inst_jp_hl(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_jp_ixy(Z80 *z80, uint8_t opcode)
{
(void) opcode;
z80->regs.pc = *z80->last_index;
z80->regs.pc = *z80->regs.ixy;
return 8;
}

@@ -1546,7 +1546,16 @@ static uint8_t z80_prefix_bits(Z80 *z80, uint8_t opcode)
*/
static uint8_t z80_prefix_index(Z80 *z80, uint8_t opcode)
{
z80->last_index = (opcode == 0xDD) ? &z80->regs.ix : &z80->regs.iy;
if (opcode == 0xDD) {
z80->regs.ixy = &z80->regs.ix;
z80->regs.ih = &z80->regs.ixh;
z80->regs.il = &z80->regs.ixl;
} else {
z80->regs.ixy = &z80->regs.iy;
z80->regs.ih = &z80->regs.iyh;
z80->regs.il = &z80->regs.iyl;
}

opcode = mmu_read_byte(z80->mmu, ++z80->regs.pc);
return (*instruction_table_index[opcode])(z80, opcode);
}


Loading…
Cancel
Save