Merge pull request #29 from TASEmulators/main

Fix incorrect code mapping logic
This commit is contained in:
Sergio Martin 2024-05-29 21:00:07 +02:00 committed by GitHub
commit 7b4ff9786a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -146,12 +146,12 @@ void Cpu::reset( void const* unmapped_page )
irq_time_ = LONG_MAX / 2 + 1;
end_time_ = LONG_MAX / 2 + 1;
code_map [0] = low_mem;
code_map [1] = low_mem - 1 * page_size;
code_map [2] = low_mem - 2 * page_size;
code_map [3] = low_mem - 3 * page_size;
set_code_page(0, low_mem);
set_code_page(1, low_mem);
set_code_page(2, low_mem);
set_code_page(3, low_mem);
for ( int32_t i = 4; i < page_count + 1; i++ )
code_map [i] = (uint8_t*) unmapped_page;
set_code_page(i, (uint8_t *) unmapped_page);
isCorrectExecution = true;
}

View File

@ -51,11 +51,16 @@ class Cpu
// Clear registers, unmap memory, and map code pages to unmapped_page.
void reset(void const *unmapped_page = 0);
inline void set_code_page(int i, uint8_t const *p)
{
code_map[i] = p - (unsigned)i * page_size;
}
inline void map_code(nes_addr_t start, unsigned size, const void *data)
{
unsigned first_page = start / page_size;
const uint8_t *newPtr = (uint8_t *)data - start;
for (unsigned i = size / page_size; i--;) code_map[first_page + i] = newPtr;
for (unsigned i = size / page_size; i--;)
set_code_page(first_page + i, (uint8_t *)data + i * page_size);
}
// Access memory as the emulated CPU does.