Implement dynarec mode check for ROM code

This allows the emulator to recompile the same block as ARM and Thumb.
Some games do execute some code both as ARM and Thumb if you can believe
it! Also the dynarec can be a bit aggressive at pre-compiling some
blocks and can misunderstand branches in the wrong mode.

This fixes NBA Jam 2002 for all dynarec backends.
This commit is contained in:
David Guillen Fandos 2022-01-03 01:18:47 +01:00
parent ef399b9315
commit 908fb831e0
1 changed files with 6 additions and 3 deletions

View File

@ -2514,9 +2514,11 @@ void translate_icache_sync() {
// ARM or Thumb mode.
#define block_lookup_address_pc_arm() \
u32 thumb = 0; \
pc &= ~0x03
#define block_lookup_address_pc_thumb() \
u32 thumb = 1; \
pc &= ~0x01 \
#define block_lookup_address_pc_dual() \
@ -2641,7 +2643,8 @@ u8 function_cc *block_lookup_address_##type(u32 pc) \
case 0x0: \
case 0x8 ... 0xD: \
{ \
u32 hash_target = ((pc * 2654435761U) >> (32 - ROM_BRANCH_HASH_BITS)) \
u32 key = pc | thumb; \
u32 hash_target = ((key * 2654435761U) >> (32 - ROM_BRANCH_HASH_BITS)) \
& (ROM_BRANCH_HASH_SIZE - 1); \
\
hashhdr_type *bhdr; \
@ -2650,7 +2653,7 @@ u8 function_cc *block_lookup_address_##type(u32 pc) \
while(blk_offset) \
{ \
bhdr = (hashhdr_type*)&rom_translation_cache[blk_offset]; \
if(bhdr->pc_value == pc) \
if(bhdr->pc_value == key) \
{ \
block_address = &rom_translation_cache[blk_offset + \
sizeof(hashhdr_type) + block_prologue_size]; \
@ -2668,7 +2671,7 @@ u8 function_cc *block_lookup_address_##type(u32 pc) \
\
translation_recursion_level++; \
bhdr = (hashhdr_type*)rom_translation_ptr; \
bhdr->pc_value = pc; \
bhdr->pc_value = key; \
bhdr->next_entry = 0; \
*blk_offset_addr = (u32)(rom_translation_ptr - rom_translation_cache);\
rom_translation_ptr += sizeof(hashhdr_type); \