Mercurial > repos > blastem
comparison z80_to_x86.c @ 1142:5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Jan 2017 23:35:40 -0800 |
parents | 136b1676109b |
children | 06468b25a543 |
comparison
equal
deleted
inserted
replaced
1141:7e199bebde2f | 1142:5c8b1c33ca10 |
---|---|
2903 } | 2903 } |
2904 | 2904 |
2905 uint8_t z80_get_native_inst_size(z80_options * opts, uint32_t address) | 2905 uint8_t z80_get_native_inst_size(z80_options * opts, uint32_t address) |
2906 { | 2906 { |
2907 uint32_t meta_off; | 2907 uint32_t meta_off; |
2908 memmap_chunk const *chunk = find_map_chunk(address, &opts->gen, MMAP_WRITE | MMAP_CODE, &meta_off); | 2908 memmap_chunk const *chunk = find_map_chunk(address, &opts->gen, MMAP_CODE, &meta_off); |
2909 if (chunk) { | 2909 if (chunk) { |
2910 meta_off += (address - chunk->start) & chunk->mask; | 2910 meta_off += (address - chunk->start) & chunk->mask; |
2911 } | 2911 } |
2912 uint32_t slot = meta_off/1024; | 2912 uint32_t slot = meta_off/1024; |
2913 return opts->gen.ram_inst_sizes[slot][meta_off%1024]; | 2913 return opts->gen.ram_inst_sizes[slot][meta_off%1024]; |
2917 { | 2917 { |
2918 uint32_t orig_address = address; | 2918 uint32_t orig_address = address; |
2919 | 2919 |
2920 z80_options * opts = context->options; | 2920 z80_options * opts = context->options; |
2921 uint32_t meta_off; | 2921 uint32_t meta_off; |
2922 memmap_chunk const *mem_chunk = find_map_chunk(address, &opts->gen, MMAP_WRITE | MMAP_CODE, &meta_off); | 2922 memmap_chunk const *mem_chunk = find_map_chunk(address, &opts->gen, MMAP_CODE, &meta_off); |
2923 if (mem_chunk) { | 2923 if (mem_chunk) { |
2924 if ((mem_chunk->flags & (MMAP_WRITE | MMAP_CODE)) == (MMAP_WRITE | MMAP_CODE)) { | 2924 if (mem_chunk->flags & MMAP_CODE) { |
2925 uint32_t masked = (address & mem_chunk->mask); | 2925 uint32_t masked = (address & mem_chunk->mask); |
2926 uint32_t final_off = masked + meta_off; | 2926 uint32_t final_off = masked + meta_off; |
2927 uint32_t ram_flags_off = final_off >> (opts->gen.ram_flags_shift + 3); | 2927 uint32_t ram_flags_off = final_off >> (opts->gen.ram_flags_shift + 3); |
2928 context->ram_code_flags[ram_flags_off] |= 1 << ((final_off >> opts->gen.ram_flags_shift) & 7); | 2928 context->ram_code_flags[ram_flags_off] |= 1 << ((final_off >> opts->gen.ram_flags_shift) & 7); |
2929 | 2929 |
3004 dprintf("patching code at %p for Z80 instruction at %X due to write to %X\n", code.cur, inst_start, address); | 3004 dprintf("patching code at %p for Z80 instruction at %X due to write to %X\n", code.cur, inst_start, address); |
3005 mov_ir(&code, inst_start, opts->gen.scratch1, SZ_D); | 3005 mov_ir(&code, inst_start, opts->gen.scratch1, SZ_D); |
3006 call(&code, opts->retrans_stub); | 3006 call(&code, opts->retrans_stub); |
3007 } | 3007 } |
3008 return context; | 3008 return context; |
3009 } | |
3010 | |
3011 void z80_invalidate_code_range(z80_context *context, uint32_t start, uint32_t end) | |
3012 { | |
3013 z80_options *opts = context->options; | |
3014 native_map_slot * native_code_map = opts->gen.native_code_map; | |
3015 memmap_chunk const *mem_chunk = find_map_chunk(start, &opts->gen, 0, NULL); | |
3016 if (mem_chunk) { | |
3017 //calculate the lowest alias for this address | |
3018 start = mem_chunk->start + ((start - mem_chunk->start) & mem_chunk->mask); | |
3019 } | |
3020 mem_chunk = find_map_chunk(end, &opts->gen, 0, NULL); | |
3021 if (mem_chunk) { | |
3022 //calculate the lowest alias for this address | |
3023 end = mem_chunk->start + ((end - mem_chunk->start) & mem_chunk->mask); | |
3024 } | |
3025 uint32_t start_chunk = start / NATIVE_CHUNK_SIZE, end_chunk = end / NATIVE_CHUNK_SIZE; | |
3026 for (uint32_t chunk = start_chunk; chunk <= end_chunk; chunk++) | |
3027 { | |
3028 if (native_code_map[chunk].base) { | |
3029 uint32_t start_offset = chunk == start_chunk ? start % NATIVE_CHUNK_SIZE : 0; | |
3030 uint32_t end_offset = chunk == end_chunk ? end % NATIVE_CHUNK_SIZE : NATIVE_CHUNK_SIZE; | |
3031 for (uint32_t offset = start_offset; offset < end_offset; offset++) | |
3032 { | |
3033 if (native_code_map[chunk].offsets[offset] != INVALID_OFFSET && native_code_map[chunk].offsets[offset] != EXTENSION_WORD) { | |
3034 code_info code; | |
3035 code.cur = native_code_map[chunk].base + native_code_map[chunk].offsets[offset]; | |
3036 code.last = code.cur + 32; | |
3037 code.stack_off = 0; | |
3038 mov_ir(&code, chunk * NATIVE_CHUNK_SIZE + offset, opts->gen.scratch1, SZ_D); | |
3039 call(&code, opts->retrans_stub); | |
3040 } | |
3041 } | |
3042 } | |
3043 } | |
3009 } | 3044 } |
3010 | 3045 |
3011 uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) | 3046 uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) |
3012 { | 3047 { |
3013 uint8_t * addr = z80_get_native_address(context, address); | 3048 uint8_t * addr = z80_get_native_address(context, address); |