Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libretro achievements not working #48

Closed
andres-asm opened this issue Mar 20, 2018 · 28 comments
Closed

Libretro achievements not working #48

andres-asm opened this issue Mar 20, 2018 · 28 comments

Comments

@andres-asm
Copy link
Contributor

The mmaps are set properly as far as I can see, but achievements are not triggering. The games are identified correctly.

@leiradel I think this worked before right?

@andres-asm
Copy link
Contributor Author

Ok have some more info

Pokemon Blue achievements didn't unlock when running in GBC mode, they unlocked properly in GB mode
Pokemon Silver achievements didn't unlock in GBC mode, they unlocked properly in GB mode

So it seems to be an issue with GBC

@LIJI32 maybe the offsets are different?

@andres-asm
Copy link
Contributor Author

Same thing seems to happen in gearboy, he hooked up achievements recently and I guess it's a similar prob

https://github.com/drhelius/Gearboy/blob/master/platforms/libretro/libretro.cpp#L349

He even adds a note about it.

@andres-asm
Copy link
Contributor Author

andres-asm commented Mar 20, 2018

Confirmed without a save but by playing this level twice in either mode:

image

It only unlocked in DMG mode

@LIJI32
Copy link
Owner

LIJI32 commented Mar 20, 2018

Can you give any example to an achievement definition that does not work on CGB mode, but works on DMG mode?

@andres-asm
Copy link
Contributor Author

andres-asm commented Mar 20, 2018

Not sure how the achievements are defined exactly @leiradel would have to help there.
All the achievements I tried last night worked in DMG but not CGB (even for CGB games)

http://retroachievements.org/user/Radius4 see all the GB games on top, I reset all of those and tried in CGB (and never triggered) and DMG (all of those triggered), the pokemon ones triggered because I have SRM.

The one in the screenshot is "beat level 1 in normal difficulty" in Kirby's Dream Land. I asked on the RetroAchievements.org discord, awaiting a response now.

@leiradel
Copy link
Contributor

I'm sorry, I've been busy with RL...

In this line

descs[3].ptr = core->IsCGB() ? (core->GetMemory()->GetCGBRAM() + (0x1000 * core->GetMemory()->GetCurrentCGBRAMBank())) : (core->GetMemory()->GetMemoryMap() + 0xD000);

What core->GetMemory()->GetCurrentCGBRAMBank() returns? This descriptor should always be the RAM bank 1, i.e.

descs[3].ptr = core->IsCGB() ? (core->GetMemory()->GetCGBRAM() + 0x1000) : (core->GetMemory()->GetMemoryMap() + 0xD000);

@LIJI32
Copy link
Owner

LIJI32 commented Mar 21, 2018

That's not SameBoy code. :)

@leiradel
Copy link
Contributor

Ugh, that's from Gearboy! Sorry for the confusion.

I believe this descriptor gets RAM banks 0 and 1, right? Bank 1 is needed when available.

descs[2].ptr   = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_RAM, &size, &bank);
descs[2].start = 0xC000;
descs[2].len = 0x2000;

Also, I'm not 100% sure but I think some cheevos rely on the IE register at 0xFFFF, is it updated in the memory location saved on descs[0]?

@LIJI32
Copy link
Owner

LIJI32 commented Mar 21, 2018

This descriptor gets both banks 0 and 1. IE is also updated in the same memory location.

@LIJI32
Copy link
Owner

LIJI32 commented Mar 21, 2018

Also, can you give examples of which memory address are being queried for an achievement working in DMG mode but not in CGB mode? And, are you using the SameBoy CGB boot ROM or the original one?

@andres-asm
Copy link
Contributor Author

An easy test is this achievement:
http://retroachievements.org/Achievement/1785

I don't know how to get conditions it uses to unlock, maybe I need their developer tools but I'm sure @leiradel knows how

@leiradel
Copy link
Contributor

This is the expression for that achievement:

0xHd03b=0.1._R:0xHd03b!=0.1._0xHd03e=4.1._R:0xHd03e!=4.1._0xHd02d=10.1._R:0xHd02d!=10.1._0xHd03a=0.1._R:0xHd03a!=0.1.

The explanation is this:

    8-bit 0xd03b is equal to 0(1)
     -  ( 0xd03b = 8-bit: Level )
    Reset If: 8-bit 0xd03b is not equal to 0(1)
     -  ( 0xd03b = 8-bit: Level )
    8-bit 0xd03e is equal to 4(1)
     -  ( 0xd03e = 8-bit: Map ID )
    Reset If: 8-bit 0xd03e is not equal to 4(1)
     -  ( 0xd03e = 8-bit: Map ID )
    8-bit 0xd02d is equal to 10(1)
    Reset If: 8-bit 0xd02d is not equal to 10(1)
    8-bit 0xd03a is equal to 0(1)
     -  ( 0xd03a = 8-bit: Difficulty, 0=normal, 1=extra game )
    Reset If: 8-bit 0xd03a is not equal to 0(1)
     -  ( 0xd03a = 8-bit: Difficulty, 0=normal, 1=extra game )

It only uses addresses in the 0xD000-0xDFFF range, so it should be working.

@andres-asm
Copy link
Contributor Author

I'm pretty sure we (as in libretro) added achievements not @LIJI32.
Anyway, same thing was happening on gearboy (which was amusing since both ports happened at roughly the same time)

He fixed it here:
libretro/Gearboy@6831805

I see that he has 2 banks for RAM and that the addresses have different offsets? depending on model
Maybe that should give an idea of what needs to be done.

@andres-asm
Copy link
Contributor Author

Here is an easy test case, load the game, load SRM and it should unlock a ton

It actually does in B&W mode but not in Color mode
Pokemon - Blue Version (USA, Europe) (SGB Enhanced).zip

@leiradel
Copy link
Contributor

So the only difference is that Gearboy maps the CGB RAM banks 0 and 1 separately, from 0xC000 to 0xCFFFF and from 0xD000 to 0xDFFF, and SameBoy maps both banks in one go, from 0xC000 to 0xDFFF?

It shouldn't make any difference for the cheevos code. I'll check the RetroArch log for both cores and see how it's reporting the memory descriptors for clues.

@andres-asm
Copy link
Contributor Author

andres-asm commented Mar 22, 2018

Sameboy in GBC mode (Link Adventure DX)

INFO] Environ SET_MEMORY_MAPS.
[INFO]    ndx flags  ptr              offset   start    select   disconn  len      addrspace
[INFO]    001 M1A1bc 000000006CF5CDB5 00000000 0000FFFF 0000FFFF 00000000 00000001
[INFO]    002 M1A1bc 000000006CF64DC0 00000000 0000FF80 0000FF80 00000000 00000080
[INFO]    003 M1A1bc 000000000EB71580 00000000 0000C000 0000E000 00000000 00002000
[INFO]    004 M1A1bc 0000000000000000 00000000 0000A000 0000E000 00000000 00002000
[INFO]    005 M1A1bc 000000000686B930 00000000 00008000 0000E000 00000000 00002000
[INFO]    006 M1A1bC 0000000000000000 00000000 00000000 0000C000 00000000 00004000
[INFO]    007 M1A1bc 000000006CF64F65 00000000 0000FE00 00000000 00000000 000000A0

[CHEEVOS]: system RAM: 000000000EB71580 65536
[INFO] [CHEEVOS]: save RAM:   000000000EAC4BA0 32768
[INFO] [CHEEVOS]: video RAM:  000000000686B930 16384
[INFO] [CHEEVOS]: RTC:        000000006CF64F40 5

@andres-asm
Copy link
Contributor Author

andres-asm commented Mar 22, 2018

Gearboy in GBC mode (Link Adventure DX)

INFO] Environ SET_MEMORY_MAPS.
[INFO]    ndx flags  ptr              offset   start    select   disconn  len      addrspace
[INFO]    001 M1A1bc 000000000697DFFF 00000000 0000FFFF 0000FFFF 00000000 00000001
[INFO]    002 M1A1bc 000000000697DF80 00000000 0000FF80 0000FF80 00000000 00000080
[INFO]    003 M1A1bc 000000000EE93C20 00000000 0000C000 0000F000 00000000 00001000
[INFO]    004 M1A1bc 000000000EE94C20 00000000 0000D000 0000F000 00000000 00001000
[INFO]    005 M1A1bc 0000000006891010 00000000 0000A000 0000E000 00000000 00002000
[INFO]    006 M1A1bc 0000000006976000 00000000 00008000 0000E000 00000000 00002000
[INFO]    007 M1A1bc 000000000696E000 00000000 00000000 0000C000 00000000 00004000
[INFO]    008 M1A1bc 000000000E8C8040 00000000 00004000 0000C000 00000000 00004000
[INFO]    009 M1A1bc 000000000697DE00 00000000 0000FE00 00000000 00000000 000000A0

[INFO] [CHEEVOS]: system RAM: 000000000EE93C20 32768
[INFO] [CHEEVOS]: save RAM:   0000000006891010 32768
[INFO] [CHEEVOS]: video RAM:  0000000000000000 0
[INFO] [CHEEVOS]: RTC:        0000000000000000 0```

@LIJI32
Copy link
Owner

LIJI32 commented Mar 22, 2018

Both seem fine to me. I haven't tested anything myself (No clue how to configure libretro achievements 😳), but any chance the libretro fork uses an old CGB SameBoy boot ROM? Old versions of the boot ROM incorrectly switched the CGB RAM bank to bank 2 (instead of the usual 1 used for DMG games), and if that's the case RetroArch would read all zeros from D000 to E000 (As it'll read from the unused bank 1)

@andres-asm
Copy link
Contributor Author

we do use the sameboy boot rom yeah, I updated a few months ago, maybe I should again, let me try that

@andres-asm
Copy link
Contributor Author

andres-asm commented Mar 22, 2018

[libretro INFO] Loading boot image: D:\GameData\EmulatorData\System\cgb_boot.bin
[INFO] Environ SET_MEMORY_MAPS.
[INFO]    ndx flags  ptr              offset   start    select   disconn  len      addrspace
[INFO]    001 M1A1bc 000000006CF5CDB5 00000000 0000FFFF 0000FFFF 00000000 00000001
[INFO]    002 M1A1bc 000000006CF64DC0 00000000 0000FF80 0000FF80 00000000 00000080
[INFO]    003 M1A1bc 0000000006371800 00000000 0000C000 0000E000 00000000 00002000
[INFO]    004 M1A1bc 0000000000000000 00000000 0000A000 0000E000 00000000 00002000
[INFO]    005 M1A1bc 0000000006A97920 00000000 00008000 0000E000 00000000 00002000
[INFO]    006 M1A1bC 0000000000000000 00000000 00000000 0000C000 00000000 00004000
[INFO]    007 M1A1bc 000000006CF64F65 00000000 0000FE00 00000000 00000000 000000A0

[INFO] [CHEEVOS]: system RAM: 0000000006371800 65536
[INFO] [CHEEVOS]: save RAM:   0000000006C10F60 32768
[INFO] [CHEEVOS]: video RAM:  0000000006A97920 16384
[INFO] [CHEEVOS]: RTC:        000000006CF64F40 5

With updated bootroms. I'll test again with some achievements.

@leiradel
Copy link
Contributor

SameBoy is returning a NULL pointer for the Cartridge RAM at 0xA000. Reads from this memory will return 0.

@andres-asm
Copy link
Contributor Author

I tried with the updated bootroms but doesn't seem to make a difference

@LIJI32
Copy link
Owner

LIJI32 commented Mar 22, 2018

Cartrdige RAM should be NULL if the game doesn’t come with a RAM chip on the cartridge, it’s normal. I wonder if it somehow breaks RetroArch though.

@andres-asm
Copy link
Contributor Author

@LIJI32 basically you create an account in retroachievements.org, and then enter your username and password in settings / achievements and (enable the achievements toggle)

You have to reload it after that of course.

@leiradel
Copy link
Contributor

I was trying to add SameBoy to RALibretro so I could see the memory live while a game was running, but it crashes after the game is loaded.

I'm not sure what could be wrong, I'll try to compile it myself and debug the issue.

@ghost
Copy link

ghost commented Oct 27, 2018

This may sound silly but gbc achievements work if you split c000, d000.

    descs[2].ptr   = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_RAM, &size, &bank);
    descs[2].start = 0xC000;
    descs[2].len   = 0x1000;

    descs[7].ptr   = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_RAM, &size, &bank) + 0x1000;
    descs[7].start = 0xD000;
    descs[7].len   = 0x1000;

Maybe because D000 can swap banks 1-7? Whereas C000-DFFF only checks banks 0-1?

@LIJI32
Copy link
Owner

LIJI32 commented Oct 27, 2018

@fr500 Can you check if the latest commit solved this?

@andres-asm
Copy link
Contributor Author

andres-asm commented Nov 5, 2018

I just tried at commit 639d2a8 with kirby's dreamland.

I unlocked these two wrongly in color mode
https://retroachievements.org/achievement/1800
https://retroachievements.org/Achievement/1801

ie: they shouldn't have triggered.

And beating stage 1 didn't trigger the correct achievement in either mode.

@ghost ghost mentioned this issue Apr 6, 2019
@LIJI32 LIJI32 closed this as completed Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants