comparison backend_x86.c @ 2237:f82c090c1e89

Implement MMAP_ONLY_ODD/EVEN in combination with MMAP_PTR_IDX. Fixes games that have SRAM when a system with TMSS is selected
author Michael Pavone <pavone@retrodev.com>
date Sat, 17 Sep 2022 15:38:40 -0700
parents b6338e18787e
children 5b308c7b098c
comparison
equal deleted inserted replaced
2236:c149c929361c 2237:f82c090c1e89
218 break; 218 break;
219 default: 219 default:
220 cfun = NULL; 220 cfun = NULL;
221 } 221 }
222 if(memmap[chunk].flags & access_flag) { 222 if(memmap[chunk].flags & access_flag) {
223 uint8_t tmp_size = size;
223 if (memmap[chunk].flags & MMAP_PTR_IDX) { 224 if (memmap[chunk].flags & MMAP_PTR_IDX) {
224 if (memmap[chunk].flags & MMAP_FUNC_NULL) { 225 if (memmap[chunk].flags & MMAP_FUNC_NULL) {
225 cmp_irdisp(code, 0, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, SZ_PTR); 226 cmp_irdisp(code, 0, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, SZ_PTR);
226 code_ptr not_null = code->cur + 1; 227 code_ptr not_null = code->cur + 1;
227 jcc(code, CC_NZ, code->cur + 2); 228 jcc(code, CC_NZ, code->cur + 2);
237 } 238 }
238 jmp(code, opts->load_context); 239 jmp(code, opts->load_context);
239 240
240 *not_null = code->cur - (not_null + 1); 241 *not_null = code->cur - (not_null + 1);
241 } 242 }
242 if ((opts->byte_swap || memmap[chunk].flags & MMAP_BYTESWAP) && size == SZ_B) { 243 if (size == SZ_B) {
243 xor_ir(code, 1, adr_reg, opts->address_size); 244 if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) {
245 bt_ir(code, 0, adr_reg, opts->address_size);
246 code_ptr good_addr = code->cur + 1;
247 jcc(code, (memmap[chunk].flags & MMAP_ONLY_ODD) ? CC_C : CC_NC, code->cur + 2);
248 if (!is_write) {
249 mov_ir(code, 0xFF, opts->scratch1, SZ_B);
250 }
251 retn(code);
252 *good_addr = code->cur - (good_addr + 1);
253 shr_ir(code, 1, adr_reg, opts->address_size);
254 } else if (opts->byte_swap || memmap[chunk].flags & MMAP_BYTESWAP) {
255 xor_ir(code, 1, adr_reg, opts->address_size);
256 }
257 } else if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) {
258 tmp_size = SZ_B;
259 shr_ir(code, 1, adr_reg, opts->address_size);
260 if ((memmap[chunk].flags & MMAP_ONLY_EVEN) && is_write) {
261 shr_ir(code, 8, opts->scratch1, SZ_W);
262 }
244 } 263 }
245 if (opts->address_size != SZ_D) { 264 if (opts->address_size != SZ_D) {
246 movzx_rr(code, adr_reg, adr_reg, opts->address_size, SZ_D); 265 movzx_rr(code, adr_reg, adr_reg, opts->address_size, SZ_D);
247 } 266 }
248 if (!need_addr_pop && is_write && (memmap[chunk].flags & MMAP_CODE)) { 267 if (!need_addr_pop && is_write && (memmap[chunk].flags & MMAP_CODE)) {
249 push_r(code, adr_reg); 268 push_r(code, adr_reg);
250 need_addr_pop = 1; 269 need_addr_pop = 1;
251 } 270 }
252 add_rdispr(code, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, adr_reg, SZ_PTR); 271 add_rdispr(code, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, adr_reg, SZ_PTR);
253 if (is_write) { 272 if (is_write) {
254 mov_rrind(code, opts->scratch1, opts->scratch2, size); 273 mov_rrind(code, opts->scratch1, opts->scratch2, tmp_size);
255 } else { 274 } else {
256 mov_rindr(code, opts->scratch1, opts->scratch1, size); 275 mov_rindr(code, opts->scratch1, opts->scratch1, tmp_size);
257 } 276 }
258 } else { 277 if (size != tmp_size && !is_write) {
259 uint8_t tmp_size = size; 278 if (memmap[chunk].flags & MMAP_ONLY_EVEN) {
279 shl_ir(code, 8, opts->scratch1, SZ_W);
280 mov_ir(code, 0xFF, opts->scratch1, SZ_B);
281 } else {
282 or_ir(code, 0xFF00, opts->scratch1, SZ_W);
283 }
284 }
285 } else {
260 if (size == SZ_B) { 286 if (size == SZ_B) {
261 if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) { 287 if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) {
262 bt_ir(code, 0, adr_reg, opts->address_size); 288 bt_ir(code, 0, adr_reg, opts->address_size);
263 code_ptr good_addr = code->cur + 1; 289 code_ptr good_addr = code->cur + 1;
264 jcc(code, (memmap[chunk].flags & MMAP_ONLY_ODD) ? CC_C : CC_NC, code->cur + 2); 290 jcc(code, (memmap[chunk].flags & MMAP_ONLY_ODD) ? CC_C : CC_NC, code->cur + 2);