Author Topic: Need some help with my libretro port  (Read 48763 times)

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #135 on: November 07, 2016, 11:20:14 AM »
Even better, which a breakpoint at this line and some print :
Code: [Select]
Breakpoint 1, MSM6295ReadData (nChip=1, nAddress=72)
    at src/burn/snd/msm6295.cpp:73
73 return pBankPointer[nChip][(nAddress >> 8)][(nAddress & 0xff)];
(gdb) print nChip
$1 = 1
(gdb) print (nAddress >> 8)
$2 = 0
(gdb) print (nAddress & 0xff)
$3 = 72
(gdb) print pBankPointer[nChip][(nAddress >> 8)][(nAddress & 0xff)]
Cannot access memory at address 0x3020448

Offline Barry Harris

  • dontbeabarry
  • *
  • Posts: 1785
  • Karma: +0/-65535
  • I'm Barry Harris and I like to f*** people over
Re: Need some help with my libretro port
« Reply #136 on: November 07, 2016, 11:59:52 AM »
nAddress is a UINT32.

Instead of;

Code: [Select]
(nAddress >> 8)
try;

Code: [Select]
((nAddress & 0xffff) >> 8)
Account of Barry Harris; the traitor.
Send me an e-mail at barry@fbalpha.com letting me know how big of a piece of sh** I am.

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #137 on: November 07, 2016, 02:24:27 PM »
Still the same issue/values, i also tried to print the following values :
Code: [Select]
(gdb) print pBankPointer[nChip][((nAddress & 0xff) >> 8)]
$5 = (UINT8 *) 0x3020400 <error: Cannot access memory at address 0x3020400>
(gdb) print pBankPointer[nChip][1]
$7 = (UINT8 *) 0x72120500 "\n\001\222\032\202\300\036\201\260J5\004\062C\"0\211\312λ\273\274\260\251\061\026\023Q\"\023  \201\211\t\271\253\253\272\273\253\230\201\021\064%\"32\020\211\212\253ʺʩ\250\t\"\223#J\202\252.\263\311\071\247\001Q\022!(\211\255\254ʻ\252\261\211b\003AQ\002"
(gdb) print pBankPointer[nChip][2]
$8 = (UINT8 *) 0x72040600 "\003\002\002\002\002\002\003\003"
Seems to me like anything else than "pBankPointer[nChip][1]" and "pBankPointer[nChip][2]" will return the same "Cannot access memory at address 0x3020400".
Also, i mentioned :
Quote
- i tried bprinting a few things in nmk112, and i got really weird results ! Just adding a few bprint in "NMK112_okibank_write" (nothing else) actually fixed the "insert coin" issue, but the game will then segfault when i "press start", as if adding those bprint actually delayed something which would not be properly initialized without those bprint.
Could this pBankPointer pointer be filled by another process, which "doesn't run fast enough" ?

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #138 on: November 07, 2016, 05:52:58 PM »
Try some debug code in nmk112.cpp to see what's getting mapped, then we can see why its not getting mapped. (might have to change all %X to %x depending on compiler).  Then post the log here, I'll compare it with mine.

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #139 on: November 08, 2016, 02:38:26 PM »
Here is the output when i press nothing (game will crash after a few seconds when the game reach the title screen) :
Code: [Select]
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 0 end FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 20000 end 2FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 30000 end 3FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019408 start 400 end FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 0 end FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019108 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 20000 end 2FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019208 start 200 end 2FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 30000 end 3FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019308 start 300 end 3FF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 0 end FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 20000 end 2FFFF
RetroArch [libretro DEBUG] :: chip 0 rom 72119008 start 30000 end 3FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019408 start 400 end FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 0 end FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019108 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 20000 end 2FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019208 start 200 end 2FF
RetroArch [libretro DEBUG] :: chip 1 rom 72019008 start 30000 end 3FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72019308 start 300 end 3FF
RetroArch [libretro DEBUG] :: chip 1 rom 72020108 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72020208 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72020108 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72020208 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72020108 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72020208 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72010500 start 400 end FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72010100 start 0 end FF
RetroArch [libretro DEBUG] :: chip 1 rom 72050400 start 10000 end 1FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72050500 start 100 end 1FF
RetroArch [libretro DEBUG] :: chip 1 rom 72040400 start 20000 end 2FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 72040600 start 200 end 2FF
RetroArch [libretro DEBUG] :: chip 1 rom 3050400 start 30000 end 3FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 3050700 start 300 end 3FF
RetroArch [libretro DEBUG] :: chip 1 rom 3020800 start 400 end FFFF
RetroArch [libretro DEBUG] :: chip 1 rom 3020400 start 0 end FF
"rom" value seems strange.

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #140 on: November 08, 2016, 03:07:45 PM »
Yea, the last couple values are funky, hrm,  lets see here....

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #141 on: November 08, 2016, 03:39:48 PM »
in d_donpachi.cpp function LoadRoms(), check the return values for BurnLoadRom() for the samples:
// Load MSM6295 ADPCM data
INT32 rc =BurnLoadRom(MSM6295ROM + 0x000000, 6, 1); // OKI #1 ONLY
bprintf(0, _T("loadrom  0 rc = %d"), rc);
rc = BurnLoadRom(MSM6295ROM + 0x100000, 7, 1); // OKI #0 & #1
bprintf(0, _T("loadrom  1 rc = %d"), rc);

If they seem OK, try putting tons of debug code in nmk112.cpp to see where those odd addresses (3050400 etc) are coming from, for example put debug code in NMK112_init() also.

best regards,
- dink

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #142 on: November 08, 2016, 10:22:31 PM »
I see a problem in nmk112.cpp, there's a bit of an out-of-bounds issue.

see:
d_donpachi.cpp:
Code: [Select]
case 0xB00020:
case 0xB00021:
case 0xB00022:
case 0xB00023:
case 0xB00024:
case 0xB00025:
case 0xB00026:
case 0xB00027:
case 0xB00028:
case 0xB00029:
case 0xB0002A:
case 0xB0002B:
case 0xB0002C:
case 0xB0002D:
case 0xB0002E:
case 0xB0002F: {
NMK112_okibank_write((sekAddress / 2) & 0x1f, byteValue);
break;
}

and nmk112.cpp in devices:
Code: [Select]
static UINT8 page_mask;
static UINT8 current_bank[8];
static UINT32 romlen[2];
static UINT8 *romdata[2];

void NMK112_okibank_write(INT32 offset, UINT8 data)
{
current_bank[offset] = data;

explanation: current_bank is overflowing into the romlen and romdata variables, corrupting them.

try: edit: don't do this - see next message!
static UINT8 current_bank[8]; -> static UINT8 current_bank[0x20];

best regards,
- dink
« Last Edit: November 08, 2016, 10:45:21 PM by dink »

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #143 on: November 08, 2016, 10:39:10 PM »
Sorry, I'm wrong about the error being in nmk112.cpp.  The problem is definitely happening in nmk112.cpp by an overflow of the variable array, but, the overflow & bug is coming from d_donpachi.cpp.
find: (hint, there are 2 occurrences of this)
NMK112_okibank_write((sekAddress / 2) & 0x1f, byteValue);

replace with: (0x1f -> 0x07)
NMK112_okibank_write((sekAddress / 2) & 0x07, byteValue);

edit: funny trivia: my inputs kept getting corrupted when I played Donpachi.  I was starting to think that fixing this was impossible, but, I'm happy to say this solved the problem for me. yay!
edit #2: don't forget to revert your nmk112.cpp back to the release version.

best regards,
- dink
« Last Edit: November 08, 2016, 10:44:50 PM by dink »

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #144 on: November 08, 2016, 11:01:49 PM »
Thanks, that fixed it :). I'll check if i can find something similar in speedspn.

Edit: Nevermind, someone reported speedspn having the same issue as donpachi (actually the same guy reported both), but i don't have his issue so i think it's setup related.
« Last Edit: November 09, 2016, 12:36:53 AM by barbudreadmon »

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #145 on: November 08, 2016, 11:35:35 PM »
awesome, glad it worked out!

regarding speedspn, it doesn't have any sounds on my side, so there definitely is something wrong here.  I will look into it tomorow (its getting late).  also the sounds work fine an old fba binary. hrmm.

best regards,
- dink

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #146 on: November 09, 2016, 01:29:42 AM »
My bad, there does seem to be an issue with speedspn, the following crash will happen when not built with "-DFBA_DEBUG" :
Code: [Select]
Program received signal SIGSEGV, Segmentation fault.
0x00007fffdcec8a90 in MSM6295Command (nChip=0, nCommand=2 '\002') at src/burn/snd/msm6295.cpp:396
396 nSampleStart  = MSM6295ReadData(nChip, (MSM6295[nChip].nSampleInfo & 0x03ff) + 0) << 17;
The crash happen on my x86 (_64) too.

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #147 on: November 09, 2016, 08:18:06 AM »
For SpeedSpin:
in oki_setbank() replace the SetBank() call with:
   MSM6295SetBank(0, DrvSndROM + ((data & 3) * 0x20000), 0x20000, 0x3ffff);
in DrvInit() under MSM6295Init() add a new line:
   MSM6295SetBank(0, DrvSndROM, 0, 0x3ffff);

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1094
  • Karma: +59/-1
  • Helper
Re: Need some help with my libretro port
« Reply #148 on: November 09, 2016, 02:31:16 PM »
Fixed, thanks :)

Offline dink

  • Administrator
  • *****
  • Posts: 5024
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Need some help with my libretro port
« Reply #149 on: November 09, 2016, 08:23:20 PM »
you're welcome :)