uint8_t debug_read_byte(uint32_t address) { uint8_t *ptr, value = 0; address &= 0xFFFFFF; if (address < 0xE00000) { if ((ptr = phys_mem_ptr(address, 1))) { value = *ptr; } } else { value = debug_port_read_byte(mmio_range(address)<<12 | addr_range(address)); } if (debugger.data.block[address]) { disasmHighlight.hit_read_breakpoint = debugger.data.block[address] & DBG_READ_BREAKPOINT; disasmHighlight.hit_write_breakpoint = debugger.data.block[address] & DBG_WRITE_BREAKPOINT; disasmHighlight.hit_exec_breakpoint = debugger.data.block[address] & DBG_EXEC_BREAKPOINT; disasmHighlight.hit_run_breakpoint = debugger.data.block[address] & DBG_RUN_UNTIL_BREAKPOINT; } if (cpu.registers.PC == address) { disasmHighlight.hit_pc = true; } return value; }
void debug_write_byte(uint32_t address, uint8_t value) { uint8_t *ptr; address &= 0xFFFFFF; if (address < 0xE00000) { if ((ptr = phys_mem_ptr(address, 1))) { *ptr = value; } } else { debug_port_write_byte(mmio_range(address)<<12 | addr_range(address), value); } }
void *virt_mem_ptr(uint32_t addr, uint32_t size) { // Note: this is not guaranteed to be correct when range crosses page boundary return (void *)(intptr_t)phys_mem_ptr(mmu_translate(addr, false, NULL, NULL), size); }
/* Proper USB emulation should really be a thing at some point :P */ bool sendVariableLink(const char *var_name) { FILE *file; uint8_t tmp_buf[0x80]; uint8_t var_size_low, var_size_high, var_type, var_arc; uint8_t *run_asm_safe = phys_mem_ptr(safe_ram_loc, 1), *cxCurApp = phys_mem_ptr(0xD007E0, 1), *op1 = phys_mem_ptr(0xD005F8, 1), *var_ptr; uint16_t var_size; const size_t h_size = sizeof(header_data); const size_t op_size = 9; /* Return if we are at an error menu */ if(*cxCurApp == 0x52) { return false; } file = fopen_utf8(var_name,"rb"); if (!file) return false; if (fread(tmp_buf, 1, h_size, file) != h_size) goto r_err; if (memcmp(tmp_buf, header_data, h_size)) goto r_err; if (fseek(file, 0x48, 0)) goto r_err; if (fread(&var_size_low, 1, 1, file) != 1) goto r_err; if (fread(&var_size_high, 1, 1, file) != 1) goto r_err; if (fseek(file, 0x3B, 0)) goto r_err; if (fread(&var_type, 1, 1, file) != 1) goto r_err; if (fseek(file, 0x45, 0)) goto r_err; if (fread(&var_arc, 1, 1, file) != 1) goto r_err; cpu.halted = cpu.IEF_wait = 0; cpu.registers.PC = safe_ram_loc; memcpy(run_asm_safe, jforcegraph, sizeof(jforcegraph)); cycle_count_delta = -5000000; cpu_execute(); if (fseek(file, 0x3B, 0)) goto r_err; if (fread(op1, 1, op_size, file) != op_size) goto r_err; cpu.halted = cpu.IEF_wait = 0; cpu.registers.PC = safe_ram_loc; run_asm_safe[0] = 0x21; run_asm_safe[1] = var_size_low; run_asm_safe[2] = var_size_high; run_asm_safe[3] = 0x00; run_asm_safe[4] = 0x3E; run_asm_safe[5] = var_type; memcpy(&run_asm_safe[6], pgrm_loader, sizeof(pgrm_loader)); cycle_count_delta = -10000000; cpu_execute(); var_ptr = phys_mem_ptr((run_asm_safe[0]) | (run_asm_safe[1] << 8) | (run_asm_safe[2] << 16), 1); var_size = (var_size_high << 8) | var_size_low; if (fseek(file, 0x4A, 0)) goto r_err; if (fread(var_ptr, 1, var_size, file) != var_size) goto r_err; if (var_arc == 0x80) { cpu.halted = cpu.IEF_wait = 0; cpu.registers.PC = safe_ram_loc; memcpy(run_asm_safe, archivevar, sizeof(archivevar)); cycle_count_delta = -1000000; cpu_execute(); } cpu.halted = cpu.IEF_wait = 0; cpu.registers.PC = safe_ram_loc; memcpy(run_asm_safe, jforcehome, sizeof(jforcehome)); cycle_count_delta = -5000000; cpu_execute(); return !fclose(file); r_err: fclose(file); return false; }
static uint32_t get_ptr(uint32_t address) { return *phys_mem_ptr(address, 1) | *phys_mem_ptr(address + 1, 1) << 8 | *phys_mem_ptr(address + 2, 1) << 16; }