DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
md Class Reference

List of commands. More...

#include <md.h>

List of all members.

Classes

struct  _carthead_
struct  dgen_debugger_cmd
struct  patch_elem

Public Types

enum  z80_core { Z80_CORE_NONE, Z80_CORE_TOTAL }
enum  cpu_emu { CPU_EMU_NONE, CPU_EMU_TOTAL }

Public Member Functions

void md_set (bool set)
unsigned int vblank ()
void m68k_state_dump ()
void m68k_state_restore ()
void z80_state_dump ()
void z80_state_restore ()
int myfm_write (int a, int v, int md)
uint8_t region_guess ()
 Region to emulate according to dgen_region_order and ROM header.
int one_frame (struct bmap *bm, unsigned char retpal[256], struct sndinfo *sndi)
void pad_update ()
int okay ()
 md (bool pal, char region)
 MD constructor.
 ~md ()
void init_pal ()
 Switch to PAL or NTSC.
bool init_sound ()
 Initialise sound.
int plug_in (unsigned char *cart, int len)
 Plug a cart into the MD.
int unplug ()
 Unplug a cart from the system.
int load (const char *name)
 Load a ROM.
int reset ()
 Resets everything (Z80, M68K, VDP, etc).
uint8_t misc_readbyte (uint32_t a)
 Read a byte from the m68Ks ram.
void misc_writebyte (uint32_t a, uint8_t d)
 write a byte to the m68Ks ram.
uint16_t misc_readword (uint32_t a)
 Read a word from the m68k memory.
void misc_writeword (uint32_t a, uint16_t d)
 Write a word to m68k memory.
void z80_init ()
 Initialise the Z80.
void z80_reset ()
 Reset the Z80.
uint8_t z80_read (uint16_t a)
 Read one byte from the memory space.
void z80_write (uint16_t a, uint8_t d)
 Write one byte to the memory.
uint8_t z80_port_read (uint16_t a)
 Port read to Z80.
void z80_port_write (uint16_t a, uint8_t d)
 Port write to z80 This is a Nop.
void cycle_z80 ()
 Cycle through Z80 CPU implementations.
void cycle_cpu ()
 Cycle between M68K CPU implementations.
int import_gst (FILE *hand)
int export_gst (FILE *hand)
int z80dump ()
 Dump Z80 ram to a file named "dgz80ram".
void fix_rom_checksum ()
 Replace the in-memory ROM checksum with a calculated checksum.
int patch (const char *list, unsigned int *errors, unsigned int *applied, unsigned int *reverted)
 This takes a comma or whitespace-separated list of Game Genie and/or hex codes to patch the ROM with.
int has_save_ram ()
int get_save_ram (FILE *from)
 Get saveram from FILE*.
int put_save_ram (FILE *into)
 Write a saveram to FILE*.
void init_joysticks ()
void deinit_joysticks ()
int debug_despatch_cmd (int n_toks, char **args)
 Dispatch a command to the relevant handler method.
int debug_cmd_cont (int n_args, char **args)
 Continue (cont) command handler.
int debug_cmd_reg (int n_args, char **args)
 Dump registers (reg) command handler.
int debug_cmd_help (int n_args, char **args)
 Help (help) command handler.
int debug_cmd_break (int n_args, char **args)
 Breakpoint (break) command handler.
int debug_cmd_quit (int n_args, char **args)
 Quit (quit) command handler.
int debug_cmd_step (int n_args, char **args)
 Step (step) command handler for the current core.
int debug_cmd_trace (int n_args, char **args)
 Trace toggle (trace) command handler.
int debug_cmd_minus_break (int n_args, char **args)
 Breakpoint removal (-break) command handler.
int debug_cmd_cpu (int n_args, char **args)
 Core/CPU selection (cpu) command.
int debug_cmd_dis (int n_args, char **args)
 Disassemble (dis) command handler.
int debug_cmd_mem (int n_args, char **args)
 Memory dump (mem) command handler.
int debug_cmd_setbwlr (int n_args, char **args, unsigned int type)
 Memory/registers write (setb/setw/setl/setr) commands handler.
int debug_cmd_setb (int n_args, char **args)
 Set byte (setb) command handler, see debug_cmd_setbwlr().
int debug_cmd_setw (int n_args, char **args)
 Set word (setw) command handler, see debug_cmd_setbwlr().
int debug_cmd_setl (int n_args, char **args)
 Set long word (setl) command handler, see debug_cmd_setbwlr().
int debug_cmd_setr (int n_args, char **args)
 Set register (setr) command handler, see debug_cmd_setbwlr().
int debug_cmd_watch (int n_args, char **args)
 Watchpoints (watch) command handler.
int debug_cmd_minus_watch (int n_args, char **args)
 Watchpoint removal (-watch) command handler.
void debug_enter (void)
 Enter debugger and show command prompt.
void debug_leave (void)
 Leave debugger.
void debug_update_wp_cache (struct dgen_wp *w)
 Update the data pointer of a single watchpoint.
void debug_update_fired_wps (void)
 Resynchronise all watchpoints based on actual data.
void debug_set_wp_m68k (uint32_t start_addr, uint32_t end_addr)
 Add a M68K watchpoint to a range of addresses.
void debug_print_disassemble (uint32_t from, int len)
 Pretty print a M68K disassembly.
void debug_show_m68k_regs (void)
 Pretty print the M68K registers using m68k_state from class md.
void debug_show_z80_regs (void)
 Pretty print Z80 registers using z80_state from class md.
void debug_dump_mem (uint32_t addr, uint32_t len)
 Pretty print a block of memory as a hex dump.

Static Public Member Functions

static void region_info (uint8_t region, int *pal, int *hz, int *vblank, int *lines, uint8_t *mem)

Public Attributes

char * break
unsigned int mclk
unsigned int clk0
unsigned int clk1
unsigned int lines
unsigned int vhz
unsigned int pal: 1
md_vdp vdp
m68k_state_t m68k_state
z80_state_t z80_state
struct md::_carthead_ cart_head
char region
int pad [2]
uint8_t pad_com [2]
unsigned char coo4
unsigned char coo5
bool plugged
enum md::z80_core z80_core
enum md::cpu_emu cpu_emu
char romname [256]
struct md::patch_elempatch_elem
unsigned long debug_m68k_instr_count
bool debug_trap
int m68k
int m68k_max
int z80
int z80_max

Static Public Attributes

static const uint8_t no_rom []
 This is the default ROM, used when nothing is loaded.
static const size_t no_rom_size = sizeof(no_rom)
static const struct
md::dgen_debugger_cmd 
debug_cmd_list []

Private Member Functions

unsigned char calculate_coo8 ()
unsigned char calculate_coo9 ()
int may_want_to_get_pic (struct bmap *bm, unsigned char retpal[256], int mark)
int may_want_to_get_sound (struct sndinfo *sndi)
int m68k_odo ()
void m68k_run ()
void m68k_busreq_request ()
void m68k_busreq_cancel ()
void m68k_irq (int i)
void m68k_vdp_irq_trigger ()
void m68k_vdp_irq_handler ()
int z80_odo ()
void z80_run ()
void z80_sync (int fake)
void z80_irq (int vector)
void z80_irq_clear ()
unsigned int frame_usecs ()
int fm_timer_callback ()
int myfm_read (int a)
int mysn_write (int v)
void fm_reset ()
void dac_init ()
void dac_clear ()
void dac_submit (int d)
void dac_enable (int d)
uint8_t m68k_ROM_read (uint32_t a)
uint8_t m68k_IO_read (uint32_t a)
uint8_t m68k_VDP_read (uint32_t a)
void m68k_ROM_write (uint32_t, uint8_t)
void m68k_IO_write (uint32_t, uint8_t)

Private Attributes

unsigned int ok: 1
unsigned int ok_ym2612: 1
unsigned int ok_sn76496: 1
unsigned int romlen
unsigned char * mem
unsigned char * rom
unsigned char * ram
unsigned char * z80ram
unsigned char * saveram
unsigned save_start
unsigned save_len
int save_prot
int save_active
uint32_t z80_bank68k
unsigned int z80_st_busreq: 1
unsigned int z80_st_reset: 1
unsigned int z80_st_running: 1
unsigned int z80_st_irq: 1
unsigned int m68k_st_running: 1
int z80_irq_vector
struct {
   int   m68k
   int   m68k_max
   int   z80
   int   z80_max
odo
int ras
int aoo3_toggle
int aoo5_toggle
int aoo3_six
int aoo5_six
int aoo3_six_timeout
int aoo5_six_timeout
uint8_t hc_table [512][2]
uint8_t fm_sel [2]
uint8_t fm_tover
int fm_ticker [4]
signed short fm_reg [2][0x100]
int dac_data [0x138]
int dac_enabled
int dac_last

Static Private Attributes

static bool lock = false

Detailed Description

List of commands.


Member Enumeration Documentation

Enumerator:
CPU_EMU_NONE 
CPU_EMU_TOTAL 
Enumerator:
Z80_CORE_NONE 
Z80_CORE_TOTAL 

Constructor & Destructor Documentation

md::md ( bool  pal,
char  region 
)

MD constructor.

Parameters:
palTrue if we are running the MD in PAL mode.
regionRegion to emulate ('J', 'U', or 'E').
md::~md ( )

Member Function Documentation

uint8_t md::calculate_coo8 ( )
private
uint8_t md::calculate_coo9 ( )
private
void md::cycle_cpu ( )

Cycle between M68K CPU implementations.

void md::cycle_z80 ( )

Cycle through Z80 CPU implementations.

void md::dac_clear ( )
inlineprivate
void md::dac_enable ( int  d)
inlineprivate
void md::dac_init ( )
inlineprivate
void md::dac_submit ( int  d)
inlineprivate
char & md::debug_cmd_break ( int  n_args,
char **  args 
)

Breakpoint (break) command handler.

  • If n_args == 0, list breakpoints.
  • If n_args == 1, set a breakpoint at address args[0].
Parameters:
n_argsNumber of arguments.
[in]argsList of arguments.
Returns:
Always 1.
int md::debug_cmd_cont ( int  n_args,
char **  args 
)

Continue (cont) command handler.

This command drops out of debug mode.

Parameters:
n_argsNumber of arguments (ignored).
argsArguments (ignored).
Returns:
Always 0 (debugger should exit).
int md::debug_cmd_cpu ( int  n_args,
char **  args 
)

Core/CPU selection (cpu) command.

Switch to the core/CPU given in args[0].

Parameters:
n_argsNumber of arguments (should always be 1).
argsList of arguments.
Returns:
Always 1.
int md::debug_cmd_dis ( int  n_args,
char **  args 
)

Disassemble (dis) command handler.

  • If n_args == 0, do nothing.
  • If n_args == 1 start disassembling from address args[0] for DEBUG_DFLT_DASM_LEN instructions.
  • If n_args == 2 start disassembling from address args[0] for args[1] instructions.
Parameters:
n_argsNumber of arguments.
[in]argsArguments list.
Returns:
Always 1.
int md::debug_cmd_help ( int  n_args,
char **  args 
)

Help (help) command handler.

Parameters:
n_argsNumber of arguments (ignored).
argsList of arguments (ignored).
Returns:
Always 1.
int md::debug_cmd_mem ( int  n_args,
char **  args 
)

Memory dump (mem) command handler.

  • If n_args == 1 then args[0] is start address to dump from for DEBUG_DFLT_MEMDUMP_LEN bytes.
  • If n_args == 2 then args[0] is start address and args[1] is number of bytes to dump.
Parameters:
n_argsNumber of arguments.
argsArguments, see above.
Returns:
Always 1.
int md::debug_cmd_minus_break ( int  n_args,
char **  args 
)

Breakpoint removal (-break) command handler.

If args[0] starts with a #, remove a breakpoint by ID. Otherwise, remove it by address.

Parameters:
n_argsNumber of arguments (always 1).
argsList of arguments.
Returns:
Always 1.
int md::debug_cmd_minus_watch ( int  n_args,
char **  args 
)

Watchpoint removal (-watch) command handler.

If args[0] starts with a #, remove a watchpoint by ID. Otherwise, remove it by address.

Parameters:
n_argsNumber of arguments (always 1).
[in]argsList of arguments.
Returns:
Always 1.
int md::debug_cmd_quit ( int  n_args,
char **  args 
)

Quit (quit) command handler.

This command makes DGen/SDL quit.

Parameters:
n_argsNumber of arguments (ignored).
argsList of arguments (ignored).
Returns:
Always 1.
int md::debug_cmd_reg ( int  n_args,
char **  args 
)

Dump registers (reg) command handler.

This command pretty prints registers for the current context.

Parameters:
n_argsNumber of arguments (ignored).
[in]argsList of arguments (ignored).
Returns:
Always 1.
int md::debug_cmd_setb ( int  n_args,
char **  args 
)

Set byte (setb) command handler, see debug_cmd_setbwlr().

Returns:
Always 1.
int md::debug_cmd_setbwlr ( int  n_args,
char **  args,
unsigned int  type 
)

Memory/registers write (setb/setw/setl/setr) commands handler.

  • args[1] is the numerical value to write to registers/memory.
  • If type == ~0u, args[0] is a register name.
  • If type == 1, args[0] is the address of a byte.
  • If type == 2, args[0] is the address of a word.
  • If type == 4, args[0] is the address of a long word.
Parameters:
n_argsNumber of arguments (ignored, always 2).
argsArguments, see above.
typeData type to write, see above.
Returns:
Always 1.
int md::debug_cmd_setl ( int  n_args,
char **  args 
)

Set long word (setl) command handler, see debug_cmd_setbwlr().

Returns:
Always 1.
int md::debug_cmd_setr ( int  n_args,
char **  args 
)

Set register (setr) command handler, see debug_cmd_setbwlr().

Returns:
Always 1.
int md::debug_cmd_setw ( int  n_args,
char **  args 
)

Set word (setw) command handler, see debug_cmd_setbwlr().

Returns:
Always 1.
int md::debug_cmd_step ( int  n_args,
char **  args 
)

Step (step) command handler for the current core.

  • If n_args == 0, step one instruction.
  • If n_args == 1, step args[0] instructions.
Parameters:
n_argsNumber of arguments.
argsList of arguments.
Returns:
0 if execution should continue, 1 otherwise.
int md::debug_cmd_trace ( int  n_args,
char **  args 
)

Trace toggle (trace) command handler.

  • If n_args == 0, toggle (enable/disable) instructions tracing permanently.
  • If n_args == 1 and args[0] is a number, enable instructions tracing for this number of instructions.
  • If n_args == 1 and args[0] is a boolean string, toggle instructions tracing accordingly.
Parameters:
n_argsNumber of arguments.
argsArguments.
Returns:
Always 1.
int md::debug_cmd_watch ( int  n_args,
char **  args 
)

Watchpoints (watch) command handler.

  • If n_args == 0 then list watchpoints.
  • If n_args == 1 then add a watchpoint with length 1 with start address defined in args[0].
  • If n_args == 2 then add a watch point with start address args[0] and length args[1].
Parameters:
n_argsNumber of arguments.
argsArguments, see above.
Returns:
Always 1.
int md::debug_despatch_cmd ( int  n_toks,
char **  toks 
)

Dispatch a command to the relevant handler method.

Parameters:
n_toksNumber of tokens (arguments).
toksList of tokens (arguments).
Returns:
1 if n_toks is 0, otherwise the command handler's return value.
void md::debug_dump_mem ( uint32_t  addr,
uint32_t  len 
)

Pretty print a block of memory as a hex dump.

Parameters:
addrStart address.
lenLength (in bytes) to dump.
void md::debug_enter ( void  )

Enter debugger and show command prompt.

void md::debug_leave ( void  )

Leave debugger.

void md::debug_print_disassemble ( uint32_t  from,
int  len 
)

Pretty print a M68K disassembly.

Parameters:
fromAddress to start disassembling from.
lenNumber of instructions to disassemble.
void md::debug_set_wp_m68k ( uint32_t  start_addr,
uint32_t  end_addr 
)

Add a M68K watchpoint to a range of addresses.

Parameters:
start_addrStart address of watchpoint range.
end_addrEnd address of watchpoint range.
void md::debug_show_m68k_regs ( void  )

Pretty print the M68K registers using m68k_state from class md.

void md::debug_show_z80_regs ( void  )

Pretty print Z80 registers using z80_state from class md.

void md::debug_update_fired_wps ( void  )

Resynchronise all watchpoints based on actual data.

void md::debug_update_wp_cache ( struct dgen_wp w)

Update the data pointer of a single watchpoint.

Parameters:
wWatchpoint to update.
void md::deinit_joysticks ( )
int md::export_gst ( FILE *  hand)
void md::fix_rom_checksum ( )

Replace the in-memory ROM checksum with a calculated checksum.

void md::fm_reset ( )
private
int md::fm_timer_callback ( )
private
unsigned int md::frame_usecs ( )
private
int md::get_save_ram ( FILE *  from)

Get saveram from FILE*.

Parameters:
fromFile to read from.
Returns:
0 on success.
int md::has_save_ram ( )
inline
int md::import_gst ( FILE *  hand)
void md::init_joysticks ( )
void md::init_pal ( )

Switch to PAL or NTSC.

This method's name is a bit misleading. This switches to PAL or not depending on "md::pal".

bool md::init_sound ( )

Initialise sound.

Returns:
True when successful.
int md::load ( const char *  name)

Load a ROM.

Parameters:
[in]nameFile name of cart to load.
Returns:
0 on success.
void md::m68k_busreq_cancel ( )
private
void md::m68k_busreq_request ( )
private
uint8_t md::m68k_IO_read ( uint32_t  a)
private
void md::m68k_IO_write ( uint32_t  a,
uint8_t  d 
)
private
void md::m68k_irq ( int  i)
private
int md::m68k_odo ( )
private
uint8_t md::m68k_ROM_read ( uint32_t  a)
private
void md::m68k_ROM_write ( uint32_t  a,
uint8_t  d 
)
private
void md::m68k_run ( )
private
void md::m68k_state_dump ( )
void md::m68k_state_restore ( )
void md::m68k_vdp_irq_handler ( )
private
void md::m68k_vdp_irq_trigger ( )
private
uint8_t md::m68k_VDP_read ( uint32_t  a)
private
int md::may_want_to_get_pic ( struct bmap bm,
unsigned char  retpal[256],
int  mark 
)
inlineprivate
int md::may_want_to_get_sound ( struct sndinfo sndi)
private
void md::md_set ( bool  set)
uint8_t md::misc_readbyte ( uint32_t  a)

Read a byte from the m68Ks ram.

Parameters:
aAddress to read.
uint16_t md::misc_readword ( uint32_t  a)

Read a word from the m68k memory.

There are quirks with word wide reads see section 1.2 of http://cgfm2.emuviews.com/txt/gen-hw.txt

Parameters:
aAddress to read
Returns:
word from memory.
void md::misc_writebyte ( uint32_t  a,
uint8_t  d 
)

write a byte to the m68Ks ram.

Parameters:
aAddress to write.
dDate (byte) two write.
void md::misc_writeword ( uint32_t  a,
uint16_t  d 
)

Write a word to m68k memory.

Parameters:
aAddress to write to.
dData to write.
int md::myfm_read ( int  a)
private
int md::myfm_write ( int  a,
int  v,
int  md 
)
int md::mysn_write ( int  v)
private
int md::okay ( )
inline
int md::one_frame ( struct bmap bm,
unsigned char  retpal[256],
struct sndinfo sndi 
)
void md::pad_update ( )
int md::patch ( const char *  list,
unsigned int *  errors,
unsigned int *  applied,
unsigned int *  reverted 
)

This takes a comma or whitespace-separated list of Game Genie and/or hex codes to patch the ROM with.

Parameters:
[in]listList of codes separated by '\t', '\n', or ','.
[out]errorsNumber of codes that failed to apply.
[out]appliedNumber of codes that applied correctly.
[out]revertedNumber of codes that were reverted.
Returns:
0 on success.
int md::plug_in ( unsigned char *  cart,
int  len 
)

Plug a cart into the MD.

Parameters:
[in]cartCart's memory as a byte array.
lenLength of the cart.
Returns:
0 on success.
int md::put_save_ram ( FILE *  into)

Write a saveram to FILE*.

Parameters:
intoFile to write to.
Returns:
0 on success.
uint8_t md::region_guess ( )

Region to emulate according to dgen_region_order and ROM header.

Returns:
Region identifier ('J', 'U' or 'E').
static void md::region_info ( uint8_t  region,
int *  pal,
int *  hz,
int *  vblank,
int *  lines,
uint8_t *  mem 
)
inlinestatic
int md::reset ( )

Resets everything (Z80, M68K, VDP, etc).

Returns:
0 on success
int md::unplug ( )

Unplug a cart from the system.

Returns:
0 on success.
unsigned int md::vblank ( )
void md::z80_init ( )

Initialise the Z80.

void md::z80_irq ( int  vector)
private
void md::z80_irq_clear ( )
private
int md::z80_odo ( )
private
uint8_t md::z80_port_read ( uint16_t  a)

Port read to Z80.

This is a NOP

Parameters:
aaddress (ignored)
Returns:
always returns 0xff
void md::z80_port_write ( uint16_t  a,
uint8_t  d 
)

Port write to z80 This is a Nop.

Parameters:
aaddress (ignored)
ddata (ignored)
uint8_t md::z80_read ( uint16_t  a)

Read one byte from the memory space.

Parameters:
aAddress to read
Returns:
byte or 0 if invalid.
void md::z80_reset ( )

Reset the Z80.

void md::z80_run ( )
private
void md::z80_state_dump ( )
void md::z80_state_restore ( )
void md::z80_sync ( int  fake)
private
void md::z80_write ( uint16_t  a,
uint8_t  d 
)

Write one byte to the memory.

Parameters:
aAddress to read
dData (byte) to write.
int md::z80dump ( )

Dump Z80 ram to a file named "dgz80ram".

Returns:
Always returns 0.

Member Data Documentation

int md::aoo3_six
private
int md::aoo3_six_timeout
private
int md::aoo3_toggle
private
int md::aoo5_six
private
int md::aoo5_six_timeout
private
int md::aoo5_toggle
private
char* md::break
struct md::_carthead_ md::cart_head
unsigned int md::clk0
unsigned int md::clk1
unsigned char md::coo4
unsigned char md::coo5
int md::dac_data[0x138]
private
int md::dac_enabled
private
int md::dac_last
private
const struct md::dgen_debugger_cmd md::debug_cmd_list[]
static
unsigned long md::debug_m68k_instr_count
bool md::debug_trap
signed short md::fm_reg[2][0x100]
private
uint8_t md::fm_sel[2]
private
int md::fm_ticker[4]
private
uint8_t md::fm_tover
private
uint8_t md::hc_table[512][2]
private
unsigned int md::lines
bool md::lock = false
staticprivate
int md::m68k
int md::m68k_max
unsigned int md::m68k_st_running
private
m68k_state_t md::m68k_state
unsigned int md::mclk
unsigned char* md::mem
private
const uint8_t md::no_rom
static
Initial value:
{
"\x72\x4e" "\xff\xff"
"\x71\x4e"
"\x71\x4e"
"\xf6\x60"
}

This is the default ROM, used when nothing is loaded.

const size_t md::no_rom_size = sizeof(no_rom)
static
struct { ... } md::odo
unsigned int md::ok
private
unsigned int md::ok_sn76496
private
unsigned int md::ok_ym2612
private
int md::pad[2]
uint8_t md::pad_com[2]
unsigned int md::pal
bool md::plugged
unsigned char * md::ram
private
int md::ras
private
char md::region
unsigned char * md::rom
private
unsigned int md::romlen
private
char md::romname[256]
int md::save_active
private
unsigned md::save_len
private
int md::save_prot
private
unsigned md::save_start
private
unsigned char* md::saveram
private
md_vdp md::vdp
unsigned int md::vhz
int md::z80
uint32_t md::z80_bank68k
private
int md::z80_irq_vector
private
int md::z80_max
unsigned int md::z80_st_busreq
private
unsigned int md::z80_st_irq
private
unsigned int md::z80_st_reset
private
unsigned int md::z80_st_running
private
z80_state_t md::z80_state
unsigned char * md::z80ram
private

The documentation for this class was generated from the following files: