SegaCD debugging emulator?

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

Post Reply
DarkMorford
Interested
Posts: 15
Joined: Tue Mar 17, 2015 4:09 pm
Location: Redmond, WA

SegaCD debugging emulator?

Post by DarkMorford » Thu Mar 26, 2015 11:00 pm

I'm putting the finishing touches on the framework for my first Sega homebrew, and I'm thinking I'd like to move it over to the SegaCD platform because it'll be easier to test that on actual hardware compared to finding dev cartridges for a normal Genesis ROM. I've read through the Rex Sabio docs on the SegaCD, and I think I understand most of it, but I'm stuck trying to figure out what happened when it inevitably breaks.

I've been using ReGen and (increasingly) Exodus for debugging my code, but neither of those programs emulate the SegaCD; on the other hand, Kega Fusion has excellent SegaCD support, but no debugging functions.

What do you use for testing/debugging your SegaCD code, and how difficult is it to port existing Genesis code to work on the CD platform?

(Somewhat related, I'm assuming Genesis-based audio libraries like GEMS aren't viable for the SegaCD due to the amount of memory required. Are there any similarly well-known audio engines for the SCD?)

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sun Mar 29, 2015 10:23 pm

Did you notice GensKMod support Genny, SegaCD and 3X debug ? ;)

HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Post by HCKTROX » Sat Apr 04, 2015 6:06 am

not to be negative (it's the least I currently want), but a strong problem Gens still have is that it shouldn't allow access of WordRAM from both processors at same time (It's my biggest issue currently). Sometimes I see no better way than trial-and-error against real hardware
skype: hcktrox

DarkMorford
Interested
Posts: 15
Joined: Tue Mar 17, 2015 4:09 pm
Location: Redmond, WA

Post by DarkMorford » Tue Apr 07, 2015 4:36 pm

KanedaFr wrote:Did you notice GensKMod support Genny, SegaCD and 3X debug ? ;)
I did not notice that. Thanks!

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Apr 07, 2015 9:15 pm

HCKTROX wrote:not to be negative (it's the least I currently want), but a strong problem Gens still have is that it shouldn't allow access of WordRAM from both processors at same time (It's my biggest issue currently). Sometimes I see no better way than trial-and-error against real hardware
Ho!
in fact, I had almost no feedback on the SegaCD side and not really aware of the tech details so, sure, there could be some errors
just let me know ;)

HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Post by HCKTROX » Thu Apr 09, 2015 12:52 am

Heh, sure =D. Though that's the only "big issue" I have found so far (apart of not emulating the illegal addressing issues, but that's usually something the ASM compiler I use do take care of :P ). I have already tried to insert the check in both KMod and GenGX+ source codes, but everything went on disaster (crashes where it shouldn't, random bugs I have no clue HOW may happen, and so on :V, I'm not totally used at C)
skype: hcktrox

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Thu Apr 16, 2015 2:18 pm

HCKTROX wrote:I have already tried to insert the check in both KMod and GenGX+ source codes, but everything went on disaster (crashes where it shouldn't, random bugs I have no clue HOW may happen, and so on :V, I'm not totally used at C)
I you want to give it a try, here is an easy change that should work (though not very clean and much optimized).

in scd.c

Change this, in word_ram_switch function:

Code: Select all

    for (i=scd.cartridge.boot+0x22; i<scd.cartridge.boot+0x24; i++)
    {
      m68k.memory_map[i].read8   = NULL;
      m68k.memory_map[i].read16  = NULL;
      m68k.memory_map[i].write8  = NULL;
      m68k.memory_map[i].write16 = NULL;
      zbank_memory_map[i].read   = NULL;
      zbank_memory_map[i].write  = NULL;
    }
to this

Code: Select all

    for (i=scd.cartridge.boot+0x20; i<scd.cartridge.boot+0x24; i++)
    {
      m68k.memory_map[i].read8   = m68k_read_bus_8;
      m68k.memory_map[i].read16  = m68k_read_bus_16;
      m68k.memory_map[i].write8  = m68k_unused_8_w;
      m68k.memory_map[i].write16 = m68k_unused_16_w;
      zbank_memory_map[i].read   = zbank_unused_r;
      zbank_memory_map[i].write  = zbank_unused_w;
    }
then add the following code :

Code: Select all

    for (i=scd.cartridge.boot+0x20; i<scd.cartridge.boot+0x24; i++)
    {
      m68k.memory_map[i].read8   = NULL;
      m68k.memory_map[i].read16  = NULL;
      m68k.memory_map[i].write8  = NULL;
      m68k.memory_map[i].write16 = NULL;
      zbank_memory_map[i].read   = NULL;
      zbank_memory_map[i].write  = NULL;
    }

    for (i=0x08; i<0x0c; i++)
    {
      s68k.memory_map[i].read8   = s68k_read_bus_8;
      s68k.memory_map[i].read16  = s68k_read_bus_16;
      s68k.memory_map[i].write8  = m68k_unused_8_w;
      s68k.memory_map[i].write16 = m68k_unused_16_w;
    }
1) in BOTH scd_write_byte & scd_write_word functions, within this IF block (before return off course)

Code: Select all

          /* RET bit set in 2M mode */
          if (data & 0x01)
          {
            /* Word-RAM is returned to MAIN-CPU */
            scd.dmna = 0;

            /* clear DMNA bit */
            scd.regs[0x02 >> 1].byte.l = (scd.regs[0x02 >> 1].byte.l & ~0x1f) | (data & 0x1d);
            return;
          }

2) in scd_reset, after the call to word_ram_switch(0)


in mem68k.c, add the following code :

Code: Select all

    for (i=scd.cartridge.boot+0x20; i<scd.cartridge.boot+0x24; i++)
    {
      m68k.memory_map[i].read8   = m68k_read_bus_8;
      m68k.memory_map[i].read16  = m68k_read_bus_16;
      m68k.memory_map[i].write8  = m68k_unused_8_w;
      m68k.memory_map[i].write16 = m68k_unused_16_w;
      zbank_memory_map[i].read   = zbank_unused_r;
      zbank_memory_map[i].write  = zbank_unused_w;
    }

    for (i=0x08; i<0x0c; i++)
    {
      s68k.memory_map[i].read8   = NULL;
      s68k.memory_map[i].read16  = NULL;
      s68k.memory_map[i].write8  = NULL;
      s68k.memory_map[i].write16 = NULL;
    }
in BOTH ctrl_io_write_byte & ctrl_io_write_word functions, within this IF block:

Code: Select all

             if (data & 0x02)
              {
                /* Word-RAM is assigned to SUB-CPU */
                scd.dmna = 1;

                /* clear RET bit */
                scd.regs[0x02>>1].w = (scd.regs[0x02>>1].w & ~0xffc3) | (data & 0xffc2);
                return;
              }

HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Post by HCKTROX » Thu Apr 16, 2015 11:06 pm

Yay!, as soon as classes finished today, I RAN to my PC to try it up. Works perfectly.

Thank you!

EDIT: A remainder, if anyone else try it: some "for" blocks gave me build errors, to fix I put "int i;" just before them.
skype: hcktrox

Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Post by Orion_ » Mon Apr 20, 2015 12:33 pm

can you post the compiled/modified exe ?
because I don't have Visual C++ and I can't compile the source :(

I had similar problem when trying to debug sega cd code, the only debugger compatible with CD is Gens Kmod, but the word ram have a strange behavior, and doesn't seems to reflect the real word ram status (especially when using 1M mode with switching both buffers)
Retro game programming !

HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Post by HCKTROX » Mon Apr 20, 2015 9:12 pm

Hmmm... the truth is that I don't use a Windows OS... and I don't really know how to edit the libretro's makefile to output a DLL... I use Ubuntu, and by default a .SO file is generated upon build. I just don't know how to let it build a .DLL file, but I may check it some time. What I can do however, is compile the Wii/GC versions, so you can try it on your console or Dolphin emu....

But even yet, I'm still unsure of doing this, especially due to the following:
However, I would appreciate if you respect the following points:
  • current SVN build should always be considered as unstable and work in progress: you are free to compile the current source code to test it and help debugging it by reporting issues but don't distribute these builds publically. You can always get the last stable code from the tagged versions.
  • you can modify the sourcecode as you want but in order to keep this project clean and structured, I would ask you to keep ANY private build for yourself to avoid public distribution of derivative works or forks. This project is still actively maintained so If you think the modification you made should be implemented in an official release, please contact me: I would eventually include it and obviously give credits when it is due.
... though I suposse there's no probs with sending builds through PMs.
skype: hcktrox

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Tue Apr 21, 2015 10:00 am

@HCTROX: this is actually a very old statement that I made years ago for the Wii/GC version because I was annoyed by users reporting issues on versions quickly patched by others to use Wii features before it got properly implemented and tested.

I should probably remove it to avoid confusion, this is not so much active anymore so I don't really care about people distributing builds in the wild :wink:

HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Post by HCKTROX » Wed Apr 22, 2015 2:42 pm

Okay. Here are the files I have built:

-Wii version
-Game Cube version
-Linux-based RetroArch version

http://www.mediafire.com/download/tg7qc ... ash.tar.gz

I'll try compile the Windows-based RetroArch version (the .DLL module) as soon as I get free from the pile of work university give me everytime.

Some notes: For all versions here, I have tried to freeze the processor upon the first memory error found... though it doesn't always work (it lags for a while and may keep running). To workaround this issue, before compiling the Libretro/Retroarch version, I forced the code so it always logs (commented out those "ifdef"s) the memory errors to Terminal/Console (the latter when I get to compile the DLL, of course).
Obviously you'll see the error logs, only if you open retroarch through the Terminal (or from Windows' Command Line for when DLL get compiled).

Enjoy, and sorry the delay
skype: hcktrox

Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Post by Orion_ » Wed Apr 22, 2015 7:39 pm

sorry, I thought you recompiled Gens KMod
Retro game programming !

Post Reply