Browse Source

Add VDP register parsing and dumping.

master
Ben Kurtovic 8 years ago
parent
commit
1227d7caa5
5 changed files with 71 additions and 11 deletions
  1. +1
    -0
      src/gamegear.c
  2. +11
    -0
      src/util.h
  3. +56
    -0
      src/vdp.c
  4. +2
    -0
      src/vdp.h
  5. +1
    -11
      src/z80.c

+ 1
- 0
src/gamegear.c View File

@@ -206,4 +206,5 @@ const char* gamegear_get_exception(GameGear *gg)
void gamegear_print_state(const GameGear *gg) void gamegear_print_state(const GameGear *gg)
{ {
z80_dump_registers(&gg->cpu); z80_dump_registers(&gg->cpu);
vdp_dump_registers(&gg->vdp);
} }

+ 11
- 0
src/util.h View File

@@ -10,6 +10,17 @@


#define INVALID_SIZE_CODE 0x8 #define INVALID_SIZE_CODE 0x8


#define BINARY_FMT "0b%u%u%u%u%u%u%u%u" // Used by register dumpers
#define BINARY_VAL(data) \
(data & (1 << 7) ? 1 : 0), \
(data & (1 << 6) ? 1 : 0), \
(data & (1 << 5) ? 1 : 0), \
(data & (1 << 4) ? 1 : 0), \
(data & (1 << 3) ? 1 : 0), \
(data & (1 << 2) ? 1 : 0), \
(data & (1 << 1) ? 1 : 0), \
(data & (1 << 0) ? 1 : 0)

/* Functions */ /* Functions */


uint8_t bcd_encode(uint8_t); uint8_t bcd_encode(uint8_t);


+ 56
- 0
src/vdp.c View File

@@ -60,6 +60,38 @@ void vdp_power(VDP *vdp)
} }


/* /*
Return the base address of the pattern name table.
*/
static uint16_t get_pnt_base(const VDP *vdp)
{
return (vdp->regs[0x02] & 0x0E) << 10;
}

/*
Return the base address of the sprite attribute table.
*/
static uint16_t get_sat_base(const VDP *vdp)
{
return (vdp->regs[0x05] & 0x7E) << 7;
}

/*
Return the base address of the sprite generator table.
*/
static uint16_t get_sgt_base(const VDP *vdp)
{
return (vdp->regs[0x06] & 0x04) << 11;
}

/*
Return the CRAM address of the backdrop color.
*/
static uint8_t get_backdrop_addr(const VDP *vdp)
{
return ((vdp->regs[0x07] & 0x0F) << 1) + 0x20;
}

/*
Advance the V counter for the next scanline. Advance the V counter for the next scanline.
*/ */
static void advance_scanline(VDP *vdp) static void advance_scanline(VDP *vdp)
@@ -83,6 +115,7 @@ void vdp_simulate_line(VDP *vdp)
if (vdp->v_counter >= 0x18 && vdp->v_counter < 0xA8) { if (vdp->v_counter >= 0x18 && vdp->v_counter < 0xA8) {
// TODO: draw current line // TODO: draw current line
} }
// TODO: if (...) IRQ
advance_scanline(vdp); advance_scanline(vdp);
} }


@@ -190,3 +223,26 @@ void vdp_write_data(VDP *vdp, uint8_t byte)
vdp->control_flag = false; vdp->control_flag = false;
vdp->read_buf = byte; vdp->read_buf = byte;
} }

/*
@DEBUG_LEVEL
Print out all register values to stdout.
*/
void vdp_dump_registers(const VDP *vdp)
{
const uint8_t *regs = vdp->regs;
DEBUG("Dumping VDP register values:")

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

DEBUG("- $02: 0x%02X (PNT: 0x%04X)", regs[0x02], get_pnt_base(vdp))
DEBUG("- $03: 0x%02X (CT)", regs[0x03])
DEBUG("- $04: 0x%02X (BPG)", regs[0x04])
DEBUG("- $05: 0x%02X (SAT: 0x%04X)", regs[0x05], get_sat_base(vdp))
DEBUG("- $06: 0x%02X (SGT: 0x%04X)", regs[0x06], get_sgt_base(vdp))
DEBUG("- $07: 0x%02X (BDC: 0x%02X)", regs[0x07], get_backdrop_addr(vdp))
DEBUG("- $08: 0x%02X (HS)", regs[0x08])
DEBUG("- $09: 0x%02X (VS)", regs[0x09])
DEBUG("- $0A: 0x%02X (LC)", regs[0x0A])
}

+ 2
- 0
src/vdp.h View File

@@ -41,3 +41,5 @@ uint8_t vdp_read_control(VDP*);
uint8_t vdp_read_data(VDP*); uint8_t vdp_read_data(VDP*);
void vdp_write_control(VDP*, uint8_t); void vdp_write_control(VDP*, uint8_t);
void vdp_write_data(VDP*, uint8_t); void vdp_write_data(VDP*, uint8_t);

void vdp_dump_registers(const VDP*);

+ 1
- 11
src/z80.c View File

@@ -4,6 +4,7 @@
#include "z80.h" #include "z80.h"
#include "disassembler.h" #include "disassembler.h"
#include "logging.h" #include "logging.h"
#include "util.h"


#define REG_AF 0 #define REG_AF 0
#define REG_BC 1 #define REG_BC 1
@@ -25,17 +26,6 @@
#define FLAG_ZERO 6 #define FLAG_ZERO 6
#define FLAG_SIGN 7 #define FLAG_SIGN 7


#define BINARY_FMT "0b%u%u%u%u%u%u%u%u" // Used by z80_dump_registers()
#define BINARY_VAL(data) \
(data & (1 << 7) ? 1 : 0), \
(data & (1 << 6) ? 1 : 0), \
(data & (1 << 5) ? 1 : 0), \
(data & (1 << 4) ? 1 : 0), \
(data & (1 << 3) ? 1 : 0), \
(data & (1 << 2) ? 1 : 0), \
(data & (1 << 1) ? 1 : 0), \
(data & (1 << 0) ? 1 : 0)

/* /*
Initialize a Z80 object. Initialize a Z80 object.




Loading…
Cancel
Save