libretro / mame2003-plus-libretro

Updated 2018 version of MAME (0.78) for libretro. with added game support plus many fixes and improvements
Other
183 stars 109 forks source link

Port Target Jaleco's Top Roller #1703

Closed arcadez2003 closed 3 months ago

arcadez2003 commented 3 months ago

@grant2258 So there's this wee game i'd like to port across to here i'd do the driver and video code there is one stumbling block a small Sega decryption table more or less which would need to be rolled back for use here..........

void toprollr_decode(void) { / same tables as in Yamato, but encrypted ROM is banked / UINT8 *decrypted;

static const unsigned char convtable[32][4] =
{
    /*       opcode                   data                     address      */
    /*  A    B    C    D         A    B    C    D                           */
    { 0x88,0xa8,0x08,0x28 }, { 0x88,0xa8,0x80,0xa0 },   /* ...0...0...0...0 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x88,0xa8,0x80,0xa0 },   /* ...0...0...0...1 */
    { 0x88,0xa8,0x80,0xa0 }, { 0x88,0xa8,0x80,0xa0 },   /* ...0...0...1...0 */
    { 0x88,0xa8,0x80,0xa0 }, { 0x20,0xa0,0x28,0xa8 },   /* ...0...0...1...1 */
    { 0x88,0xa8,0x08,0x28 }, { 0x88,0xa8,0x08,0x28 },   /* ...0...1...0...0 */
    { 0x88,0xa8,0x80,0xa0 }, { 0x88,0xa8,0x80,0xa0 },   /* ...0...1...0...1 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x20,0xa0,0x28,0xa8 },   /* ...0...1...1...0 */
    { 0x88,0xa8,0x80,0xa0 }, { 0x88,0xa8,0x80,0xa0 },   /* ...0...1...1...1 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x88,0xa8,0x08,0x28 },   /* ...1...0...0...0 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x28,0x20,0xa8,0xa0 },   /* ...1...0...0...1 */
    { 0xa0,0x20,0x80,0x00 }, { 0x20,0xa0,0x28,0xa8 },   /* ...1...0...1...0 */
    { 0x28,0x20,0xa8,0xa0 }, { 0x20,0xa0,0x28,0xa8 },   /* ...1...0...1...1 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x88,0xa8,0x08,0x28 },   /* ...1...1...0...0 */
    { 0x88,0xa8,0x08,0x28 }, { 0x88,0xa8,0x08,0x28 },   /* ...1...1...0...1 */
    { 0xa0,0x20,0x80,0x00 }, { 0x88,0x08,0x80,0x00 },   /* ...1...1...1...0 */
    { 0x20,0xa0,0x28,0xa8 }, { 0x00,0x08,0x20,0x28 }    /* ...1...1...1...1 */
};

int A;

UINT8 *rom = memory_region(REGION_USER1);
int bankstart;
decrypted = auto_malloc(0x6000*3);

for(bankstart=0;bankstart<0x6000*3;bankstart+=0x6000)
for (A = 0x0000;A < 0x6000;A++)
{
    int xor = 0;

    UINT8 src = rom[A+bankstart];

    /* pick the translation table from bits 0, 4, 8 and 12 of the address */
    int row = (A & 1) + (((A >> 4) & 1) << 1) + (((A >> 8) & 1) << 2) + (((A >> 12) & 1) << 3);

    /* pick the offset in the table from bits 3 and 5 of the source data */
    int col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
    /* the bottom half of the translation table is the mirror image of the top */
    if (src & 0x80)
    {
        col = 3 - col;
        xor = 0xa8;
    }

    /* decode the opcodes */
    decrypted[A+bankstart] = (src & ~0xa8) | (convtable[2*row][col] ^ xor);

    /* decode the data */
    rom[A+bankstart] = (src & ~0xa8) | (convtable[2*row+1][col] ^ xor);
}

memory_configure_bank(1,0,3, memory_region(REGION_USER1),0x6000);
memory_configure_bank_decrypted(1,0,3,decrypted,0x6000);
memory_set_decrypted_region(0, 0x0000, 0x5fff, decrypted);
memory_set_bank(1, 0);

}

You've done a fair few of these already so i wanted to ask ya if you get the time and it's not too much hastle could you look at the above to see if it's possible to convert it for use here

Regards

arcadez2003 commented 3 months ago

Oh forgot to say this is the game in question.......... http://adb.arcadeitalia.net/dettaglio_mame.php?game_name=toprollr&arcade_only=0&autosearch=1

grant2258 commented 3 months ago

Looks like its doable no guarantees though if its not a lot of work on your part to do the rest Ill certainly give it a go.

arcadez2003 commented 3 months ago

Thanks for taking a look i'll have the code done and send you the files likely by the weekend

arcadez2003 commented 3 months ago

Ok @grant2258 that's the driver and video done for MAME78 all that is left is the decryption if you can get it to play great if not then it's no biggie thanks man. toprollr WIP.zip

MAME WIP

0.105u2: Fixes to Top Roller [Tomasz Slanina]: Correct colors. Fixed gfx bugs. Better audio (added rom with samples). There's still minor problem with fg text layer colors. Added Samples sound. Added sound1 rom and PROMs ($0, 20, 40, 60, 80 and a0 - big sprites, sprites+fg, sprites, 2x bg and unknown). Changed visible area to 224x240 and palettesize to 160 colors. 17th April 2006: Tomasz Slanina - Correct (almost) colors in Top Roller - there are still minor probs (text layer). 0.102u5: Tomasz Slanina added 'Top Roller' (Jaleco 1983).

It seems Yamato also benefits

0.102u5: Changed region cpu1 ($f000) to user1. Changed palettesize to 352 colors. 17th December 2005: Tomasz Slanina added temporary BG gradient (bad colors/offset). Gradient table are stored in two(?) ROMs. Each table is 256 bytes long: 128 for normal and 128 bytes for flipped screen. Color format is unknown - probably direct RGB mapping of 8 or 16 (both roms) bits. Also table selection source is unknown. 18th November 2005: Tomasz Slanina - Trying to add missing background, but colors are guess.

grant2258 commented 3 months ago

That was quick work as usual on your part as usual. I have a look at this when I get the time. I need to do some Friday shopping I dont know why she picks the busiest days of the week to do it but its easier just going with it.

arcadez2003 commented 3 months ago

Nae worries i had some time last night so decided to get on and do it, and happy shopping :)

grant2258 commented 3 months ago

what version of mame did you grab this from I want to check the segacrpt on it m8

arcadez2003 commented 3 months ago

102.u5 then some extra fixes from 105.u2 as you know the cpu decryption was rewritten circa MAME101.u3 if this had been added several versions earlier or an unencrypted version would have turned up we'd not have to worry about this.

https://github.com/mamedev/historic-mame/commits/10ac829dea486777befdb0b9ee757a796d08520d/src/machine/segacrpt.c

grant2258 commented 3 months ago

thanks for that mate one problem in this core is that the 0x6000 3 is outwith the 0xffff memory range not sure if we can use a continuous 0x6000 3 in our ole core unless its split into 0x2000 chucks will need to check the banking code on that version of mame

grant2258 commented 3 months ago

This ones a bit of a stinker. If you change the opcode base to the decrypted the non banking rom code will be effectively be on the wrong place for opcodes. Ill need to search the code base for this king of banking to see if there is any examples of banking decoding. There is also no way to be sure whats an opcode to just decode it in place. Another little brain teaser!

arcadez2003 commented 3 months ago

Trust me to drop this on ya if it's gonna be too much hastle buddy then best to not knock yourself out here unless you wanna jump down another rabbit hole of my creation ha ha. seriously though it was only an hours work my side either that or the Apprentice so not the end of the world if this cannot be done without a bucketload of hastle.

grant2258 commented 3 months ago

Just get messy gfx and an annoying starting sound. https://github.com/grant2258/mame2003-plus-libretro/commit/699cf9a8d739741ff730416b66b0a3fb5bef2890 ill check over any other changes. If nothing pops ill give up haha.

edit: This is odd I was sure the banking was right its works on arm but not in x86 which I was testing on.

arcadez2003 commented 3 months ago

Some progress eh but what a nightmare :) im sure the gfx will be sorted with the correct decryption calls as for the sound i was hoping it would be passable but it's not 100% until way later MAME builds and well the code is not compatable for here.

EDIT as per this video from 8 years back this is what i'd expect from Top Roller emulation wise provided i didnt mess up some of the code when backporting it https://www.youtube.com/shorts/9d1vV4aSgvk

arcadez2003 commented 3 months ago

Obviously decryption conversion is not my strong point but i noticed you have some CPU1 calls in there while the original decryption code always calls USER1 unless ofcourse it's sharing between the two.

EDIT never mind i see it now silly me cpu_setbank(1, jaleco_rombank);

grant2258 commented 3 months ago

its not working on arm sorry about that had a blonde moment. I was booting yamato I guess I was looking at the filename I was editing haha. The banking would be a walk in the park if it wasnt encrpted. Im going to try put it all in cpu 1 and see if it works that way.

grant2258 commented 3 months ago

Well ive ported it to my core although it has the same issues. The banking is done that was easy im just not sure how to point the decrypted opcodes in a bank on these old cores. I tried doing it in REGION cpu1 see segacrpt. c. I checked fbneo it doesnt have this game either. https://github.com/libretro/mame2003-plus-libretro. It is switching but has a messed up screen. Got the game to boot I think I have a solution using memcopy tom follery got the game booting without bank switching.

arcadez2003 commented 3 months ago

Damn if i'd known you'd have this much hastle i would never have attempted to add this one, but i feel you might be close to cracking the puzzle dont knock yourself out over it though, if you get it to work then great if not then it's not the end of the world emulation wise :)

grant2258 commented 3 months ago

it done got it working :)

arcadez2003 commented 3 months ago

Good on ya and well done :)

arcadez2003 commented 3 months ago

You mentioned something about a CRC on the commit one of the gfx roms was redumped i suppose we should add it to match up to the latest roms plus it was likely redumped to fix some issue.

grant2258 commented 3 months ago

yea i added that already the new crc is in the pull request:)

arcadez2003 commented 3 months ago

Aye you dont miss much ha ha ha ok i suppose this is another happy ending and we can close this down.

arcadez2003 commented 3 months ago

@grant2258 can i ask you one more decrypted related favour.?? it's code you've worked on before namely the decryption for Ms Pacman Twin, i've ported this across to advanceMAME but forgot being based off MAME106 the code would need to be reworked slightly.

So i wanted to ask would you be able to take a peek at this sometime.?? if not then it's no problem i can simply roll back on the commit, at the moment andrea has disabled the memory_setopcode_base which by 106 is obsolete and im not sure how to update to the newer decryption.

https://github.com/amadvance/advancemame/commit/078df50cd6a84dc9e35653d4078d5e7dd2abe266

EDIT i've done this but it might not be enough...... https://github.com/amadvance/advancemame/pull/131/commits/942e5fd623a9afe8932c65a7502a0e707c8a79ea

grant2258 commented 3 months ago

what version of mame is advancemame using? How this is dealt with really depends on what version of mame your using.

arcadez2003 commented 3 months ago

Hi @grant2258 advancemame is 106, i've tried a few things but it's above my level TBH at the moment it's locking into service on boot.