Author Topic: I need help reading some memory from mame.  (Read 12542 times)

Offline AtomR

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
I need help reading some memory from mame.
« on: November 23, 2011, 01:09:51 PM »
Good afternoon,
I've been trying for two very troublesome days to understand the inner workings of mame. I think I finally got a good grasp of how to access info on the emulated ram.
First off I'm specifically working with the pbaction driver. Which has the following memory setup
Code: [Select]
static ADDRESS_MAP_START( pbaction_map, AS_PROGRAM, 8 )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0xbfff) AM_ROM
AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE_MEMBER(pbaction_state, m_work_ram)
AM_RANGE(0xd000, 0xd3ff) E(pbaction_videoram2_w) AM_BASE_MEMBER(pbaction_state, m_videoram2)
AM_RANGE(0xd400, 0xd7ff) AM_RAM_WRITE(pbaction_colorram2_w) AM_BASE_MEMBER(pbaction_state, m_colorram2)
AM_RANGE(0xd800, 0xdbff) AM_RAM_WRITE(pbaction_videoram_w) AM_BASE_MEMBER(pbaction_state, m_videoram)
AM_RANGE(0xdc00, 0xdfff) AM_RAM_WRITE(pbaction_colorram_w) AM_BASE_MEMBER(pbaction_state, m_colorram)
AM_RANGE(0xe000, 0xe07f) AM_RAM AM_BASE_SIZE_MEMBER(pbaction_state, m_spriteram, m_spriteram_size)
AM_RANGE(0xe400, 0xe5ff) AM_RAM_WRITE(paletteram_xxxxBBBBGGGGRRRR_le_w) AM_BASE_GENERIC(paletteram)
AM_RANGE(0xe600, 0xe600) AM_READ_PORT("P1") AM_WRITE(interrupt_enable_w)
AM_RANGE(0xe601, 0xe601) AM_READ_PORT("P2")
AM_RANGE(0xe602, 0xe602) AM_READ_PORT("SYSTEM")
AM_RANGE(0xe604, 0xe604) AM_READ_PORT("DSW1") AM_WRITE(pbaction_flipscreen_w)
AM_RANGE(0xe605, 0xe605) AM_READ_PORT("DSW2")
AM_RANGE(0xe606, 0xe606) AM_READNOP /* ??? */ AM_WRITE(pbaction_scroll_w)
AM_RANGE(0xe800, 0xe800) AM_WRITE(pbaction_sh_command_w)
ADDRESS_MAP_END

So I've put in the running_machine::run method the following code, inside the if(!m_paused)
Code: [Select]
memory_region *r = m_regionlist.find("maincpu");
if(r!=NULL)
{
printf("%s\n",r->name());
for(int i=0xC000;i<0xC010;i++)
printf("%02X",r->u8(i));
}
printf("\n");

Basically my question is, why is it that memory data below address 0xC000 shows exactly as the dump file does, but anything above that address just comes out 00 when I can see in the dumpfile that there is actual data there? :(

I appreciate any help you can give. Thanks.

Offline iq_132

  • Administrator
  • *****
  • Posts: 3732
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: I need help reading some memory from mame.
« Reply #1 on: November 24, 2011, 12:00:45 AM »
Good afternoon,
I've been trying for two very troublesome days to understand the inner workings of mame. I think I finally got a good grasp of how to access info on the emulated ram.
First off I'm specifically working with the pbaction driver. Which has the following memory setup
Code: [Select]
static ADDRESS_MAP_START( pbaction_map, AS_PROGRAM, 8 )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0xbfff) AM_ROM
AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE_MEMBER(pbaction_state, m_work_ram)
AM_RANGE(0xd000, 0xd3ff) E(pbaction_videoram2_w) AM_BASE_MEMBER(pbaction_state, m_videoram2)
AM_RANGE(0xd400, 0xd7ff) AM_RAM_WRITE(pbaction_colorram2_w) AM_BASE_MEMBER(pbaction_state, m_colorram2)
AM_RANGE(0xd800, 0xdbff) AM_RAM_WRITE(pbaction_videoram_w) AM_BASE_MEMBER(pbaction_state, m_videoram)
AM_RANGE(0xdc00, 0xdfff) AM_RAM_WRITE(pbaction_colorram_w) AM_BASE_MEMBER(pbaction_state, m_colorram)
AM_RANGE(0xe000, 0xe07f) AM_RAM AM_BASE_SIZE_MEMBER(pbaction_state, m_spriteram, m_spriteram_size)
AM_RANGE(0xe400, 0xe5ff) AM_RAM_WRITE(paletteram_xxxxBBBBGGGGRRRR_le_w) AM_BASE_GENERIC(paletteram)
AM_RANGE(0xe600, 0xe600) AM_READ_PORT("P1") AM_WRITE(interrupt_enable_w)
AM_RANGE(0xe601, 0xe601) AM_READ_PORT("P2")
AM_RANGE(0xe602, 0xe602) AM_READ_PORT("SYSTEM")
AM_RANGE(0xe604, 0xe604) AM_READ_PORT("DSW1") AM_WRITE(pbaction_flipscreen_w)
AM_RANGE(0xe605, 0xe605) AM_READ_PORT("DSW2")
AM_RANGE(0xe606, 0xe606) AM_READNOP /* ??? */ AM_WRITE(pbaction_scroll_w)
AM_RANGE(0xe800, 0xe800) AM_WRITE(pbaction_sh_command_w)
ADDRESS_MAP_END

So I've put in the running_machine::run method the following code, inside the if(!m_paused)
Code: [Select]
memory_region *r = m_regionlist.find("maincpu");
if(r!=NULL)
{
printf("%s\n",r->name());
for(int i=0xC000;i<0xC010;i++)
printf("%02X",r->u8(i));
}
printf("\n");

Basically my question is, why is it that memory data below address 0xC000 shows exactly as the dump file does, but anything above that address just comes out 00 when I can see in the dumpfile that there is actual data there? :(

I appreciate any help you can give. Thanks.

You're not quite understanding how the memory maps work.  The region finding function only returns rom data.  Area 0xc000-0xcfff points to m_work_ram.  You can do

int i;
UINT8 *r = m_work_ram;
for (i = 0; i < 0x0000; i < 0x1000; i++) {
printf ("%2.2x", i);
}

if you want to do a complete cpu memory address dump, you can do
space->read_byte(address);  or read_word for 16-bit cpu or read_dword for 32.


Offline Haze

  • MAME Devs
  • *****
  • Posts: 184
  • Karma: +47/-0
Re: I need help reading some memory from mame.
« Reply #2 on: November 24, 2011, 03:44:00 AM »
Indeed

'maincpu' is just the region containing the ROMs for the MainCPU, as defined in the rom loading.

It is not tied to the actual memory map which is much more complex than a simple linear space.


Offline AtomR

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
Re: I need help reading some memory from mame.
« Reply #3 on: November 24, 2011, 07:55:51 AM »
Thank you for your help.
After I posted my message I remembered that since the debugger can actually read and dump all the memory into a file then I can check there how it does it. and I found about the space and finally read the memory addresses I needed. Thanks again.