Skip to content

Commit

Permalink
cpc.h: remote debugging support wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 28, 2023
1 parent 0b5cb26 commit dd06e21
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
42 changes: 33 additions & 9 deletions systems/cpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ void cpc_joystick(cpc_t* sys, uint8_t mask);
// get current joystick bitmask state
uint8_t cpc_joystick_mask(cpc_t* sys);
// load a snapshot file (.sna or .bin) into the emulator
bool cpc_quickload(cpc_t* cpc, chips_range_t data);
bool cpc_quickload(cpc_t* cpc, chips_range_t data, bool start);
// return the exec address of a quickload file (.sna or .bin)
uint16_t cpc_quickload_exec_addr(chips_range_t data);
// return the return-address for a quickloaded file
uint16_t cpc_quickload_return_addr(void);
// insert a disk image file (.dsk)
bool cpc_insert_disc(cpc_t* cpc, chips_range_t data);
// remove current disc
Expand Down Expand Up @@ -862,7 +866,7 @@ static bool _cpc_is_valid_bin(chips_range_t data) {
return true;
}

static bool _cpc_load_bin(cpc_t* sys, chips_range_t data) {
static bool _cpc_load_bin(cpc_t* sys, chips_range_t data, bool start) {
const uint8_t* ptr = (uint8_t*) data.ptr;
const _cpc_bin_header* hdr = (const _cpc_bin_header*) ptr;
ptr += sizeof(_cpc_bin_header);
Expand All @@ -872,26 +876,46 @@ static bool _cpc_load_bin(cpc_t* sys, chips_range_t data) {
for (uint16_t i = 0; i < len; i++) {
mem_wr(&sys->mem, load_addr+i, *ptr++);
}
sys->cpu.iff1 = true;
sys->cpu.iff2 = true;
sys->cpu.c = 0; // FIXME: "ROM select number"
sys->cpu.hl = start_addr;
sys->pins = z80_prefetch(&sys->cpu, 0xBD16); // MC START PROGRAM
if (start) {
// FIXME: alternatively via CALL xxxx?
sys->cpu.iff1 = true;
sys->cpu.iff2 = true;
sys->cpu.c = 0; // FIXME: "ROM select number"
sys->cpu.hl = start_addr;
sys->pins = z80_prefetch(&sys->cpu, 0xBD16); // MC START PROGRAM
}
return true;
}

bool cpc_quickload(cpc_t* sys, chips_range_t data) {
bool cpc_quickload(cpc_t* sys, chips_range_t data, bool start) {
CHIPS_ASSERT(sys && sys->valid && data.ptr && (data.size > 0));
if (_cpc_is_valid_sna(data)) {
return _cpc_load_sna(sys, data);
} else if (_cpc_is_valid_bin(data)) {
return _cpc_load_bin(sys, data);
return _cpc_load_bin(sys, data, start);
} else {
// not a known file type, or not enough data
return false;
}
}

uint16_t cpc_quickload_return_addr(void) {
// FIXME!
return 0xFFFF;
}

uint16_t cpc_quickload_exec_addr(chips_range_t data) {
uint16_t start_addr = 0xFFFF;
if (_cpc_is_valid_sna(data)) {
const _cpc_sna_header* hdr = (const _cpc_sna_header*)data.ptr;
start_addr = (hdr->PC_h<<8) | hdr->PC_l;
} else if (_cpc_is_valid_bin(data)) {
const _cpc_bin_header* hdr = (const _cpc_bin_header*)data.ptr;
start_addr = (hdr->start_addr_h<<8)|hdr->start_addr_l;
}
return start_addr;
}

/*=== FLOPPY DISC SUPPORT ====================================================*/
static int _cpc_fdc_seektrack(int drive, int track, void* user_data) {
if (0 == drive) {
Expand Down
35 changes: 13 additions & 22 deletions ui/ui_cpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef struct {
cpc_t* cpc;
ui_cpc_boot_t boot_cb; // user-provided callback to reboot to different config
ui_dbg_texture_callbacks_t dbg_texture; // debug texture create/update/destroy callbacks
ui_dbg_debug_callbacks_t dbg_debug; // user-provided debugger callbacks
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
ui_snapshot_desc_t snapshot; // snapshot ui setup params
} ui_cpc_desc_t;
Expand Down Expand Up @@ -145,8 +146,7 @@ static void _ui_cpc_draw_menu(ui_cpc_t* ui) {
if (ImGui::MenuItem("Joystick", 0, ui->cpc->joystick_type != CPC_JOYSTICK_NONE)) {
if (ui->cpc->joystick_type == CPC_JOYSTICK_NONE) {
ui->cpc->joystick_type = CPC_JOYSTICK_DIGITAL;
}
else {
} else {
ui->cpc->joystick_type = CPC_JOYSTICK_NONE;
}
}
Expand Down Expand Up @@ -242,8 +242,7 @@ static void _ui_cpc_update_memmap(ui_cpc_t* ui) {
ui_memmap_region(&ui->memmap, "RAM 1", 0x4000, 0x4000, true);
ui_memmap_region(&ui->memmap, "RAM 2", 0x8000, 0x4000, true);
ui_memmap_region(&ui->memmap, "RAM 3 (Screen)", 0xC000, 0x4000, true);
}
else {
} else {
const uint8_t ram_config_index = cpc->ga.ram_config & 7;
const uint8_t rom_select = cpc->ga.rom_select;
ui_memmap_layer(&ui->memmap, "ROM Layer 0");
Expand Down Expand Up @@ -272,27 +271,21 @@ static uint8_t* _ui_cpc_memptr(cpc_t* cpc, int layer, uint16_t addr) {
if (layer == _UI_CPC_MEMLAYER_GA) {
uint8_t* ram = &cpc->ram[0][0];
return ram + addr;
}
else if (layer == _UI_CPC_MEMLAYER_ROMS) {
} else if (layer == _UI_CPC_MEMLAYER_ROMS) {
if (addr < 0x4000) {
return &cpc->rom_os[addr];
}
else if (addr >= 0xC000) {
} else if (addr >= 0xC000) {
return &cpc->rom_basic[addr - 0xC000];
}
else {
} else {
return 0;
}
}
else if (layer == _UI_CPC_MEMLAYER_AMSDOS) {
} else if (layer == _UI_CPC_MEMLAYER_AMSDOS) {
if ((CPC_TYPE_6128 == cpc->type) && (addr >= 0xC000)) {
return &cpc->rom_amsdos[addr - 0xC000];
}
else {
} else {
return 0;
}
}
else {
} else {
/* one of the 7 RAM layers */
CHIPS_ASSERT((layer >= _UI_CPC_MEMLAYER_RAM0) && (layer <= _UI_CPC_MEMLAYER_RAM7));
const int ram_config_index = (CPC_TYPE_6128 == cpc->type) ? (cpc->ga.ram_config & 7) : 0;
Expand Down Expand Up @@ -329,13 +322,11 @@ static uint8_t _ui_cpc_mem_read(int layer, uint16_t addr, void* user_data) {
if (layer == _UI_CPC_MEMLAYER_CPU) {
/* CPU mapped RAM layer */
return mem_rd(&cpc->mem, addr);
}
else {
} else {
uint8_t* ptr = _ui_cpc_memptr(cpc, layer, addr);
if (ptr) {
return *ptr;
}
else {
} else {
return 0xFF;
}
}
Expand All @@ -347,8 +338,7 @@ static void _ui_cpc_mem_write(int layer, uint16_t addr, uint8_t data, void* user
cpc_t* cpc = ui_cpc->cpc;
if (layer == _UI_CPC_MEMLAYER_CPU) {
mem_wr(&cpc->mem, addr, data);
}
else {
} else {
uint8_t* ptr = _ui_cpc_memptr(cpc, layer, addr);
if (ptr) {
*ptr = data;
Expand Down Expand Up @@ -600,6 +590,7 @@ void ui_cpc_init(ui_cpc_t* ui, const ui_cpc_desc_t* ui_desc) {
desc.read_cb = _ui_cpc_mem_read;
desc.break_cb = _ui_cpc_eval_bp;
desc.texture_cbs = ui_desc->dbg_texture;
desc.debug_cbs = ui_desc->dbg_debug;
desc.keys = ui_desc->dbg_keys;
desc.user_data = ui;
/* custom breakpoint types */
Expand Down

0 comments on commit dd06e21

Please sign in to comment.