~thestr4ng3r/rz-commodore

e2fbce702ec0fca3cf1d5c1d0425a516cd6e4aba — Florian Märkl 2 months ago 0d3530e
Finish VICE Mem Get
2 files changed, 30 insertions(+), 29 deletions(-)

M src/io_vice.c
M src/vice.c
M src/io_vice.c => src/io_vice.c +5 -2
@@ 76,6 76,9 @@ err_v:
	return NULL;
}

#define SPACE RZ_VICE_MON_MEM_SPACE_MAIN
#define BANK  RZ_VICE_MON_BANK_CPU

static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) {
	return -1;
}


@@ 99,8 102,8 @@ static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) {
	RzVICEDesc *desc = fd->data;
	memset(buf, 0xff, count);

	RzVICEMonMemSpace space = RZ_VICE_MON_MEM_SPACE_MAIN;
	ut16 bank_id = rz_vice_mon_get_bank_id(desc->mon, RZ_VICE_MON_BANK_DEFAULT);
	RzVICEMonMemSpace space = SPACE;
	ut16 bank_id = rz_vice_mon_get_bank_id(desc->mon, BANK);

	ut64 end64 = desc->off + count - 1;
	if (desc->off < UT16_MAX) {

M src/vice.c => src/vice.c +25 -27
@@ 5,6 5,8 @@

#include <uv.h>

#define DEBUG_RAW 0

#define RZ_VICE_MON_STX               '\x02'
#define RZ_VICE_MON_API_VERSION_ID    0x01
#define RZ_VICE_MON_RESPONSE_ID_EVENT 0xffffffffu


@@ 499,6 501,7 @@ static void open_banks_resp_cb(RzVICEMon *mon, RzVICEMonErr r, RzVICEMonResponse
			} else if (!strcmp(bn, "cart")) {
				type = RZ_VICE_MON_BANK_CART;
			}
			mon->banks[i].type = type;
		}
	}
	open_ctx_finish_and_free(mon, ctx, RZ_VICE_MON_ERR_SUCCESS);


@@ 621,6 624,19 @@ static RzVICEMonErr mon_send_raw(RzVICEMon *mon, RzVICEMonCommandRaw *cmd,
	ctx->buf = buf;
	write->data = ctx;
	uv_buf_t ubuf = { .base = (char *)buf, .len = buf_sz };
#if DEBUG_RAW
	eprintf("--\nsend command type %u with req_id %#x\n",
		(unsigned int)cmd->type, (unsigned int)req_id);
	if (cmd->body) {
		char *hex = rz_hex_bin2strdup(buf, RZ_VICE_MON_REQ_HEADER_SZ);
		eprintf("  header: %s\n", hex);
		free(hex);
		hex = rz_hex_bin2strdup(cmd->body, cmd->body_sz);
		eprintf("  body: %s\n", hex);
		free(hex);
	}
	eprintf("--\n");
#endif
	uv_write(write, (uv_stream_t *)mon->tcp, &ubuf, 1, send_raw_write_cb);
	*req_id_out = req_id;
	return RZ_VICE_MON_ERR_SUCCESS;


@@ 835,36 851,18 @@ beach:
static RzVICEMonErr parse_response(RzVICEMonResponse *resp, RzVICEMonResponseRaw *raw);

static void read_handle_resp_raw(RzVICEMon *mon, RzVICEMonResponseRaw *resp_raw) {
	RzVICEMonResponse resp;
	RzVICEMonErr err = parse_response(&resp, resp_raw);
	if (err != RZ_VICE_MON_ERR_SUCCESS) {
		printf("--\nparse failed: received type: %#x, error_code: %#x, req_id: %" PFMT32x ", body sz: %#llx\n",
			(unsigned int)resp_raw->type, (unsigned int)resp_raw->error_code, resp_raw->req_id,
			(unsigned long long)resp_raw->body_sz);
#if DEBUG_RAW
	eprintf("--\nreceived response type %u with req_id %#x, error_code %#x\n",
		(unsigned int)resp_raw->type, (unsigned int)resp_raw->req_id, (unsigned int)resp_raw->error_code);
	if (resp_raw->body) {
		char *hex = rz_hex_bin2strdup(resp_raw->body, resp_raw->body_sz);
		printf("body: %s\n--\n", hex);
		eprintf("  body: %s\n", hex);
		free(hex);
	} else {
		switch (resp.type) {
		case RZ_VICE_MON_RESPONSE_CHECKPOINT_INFO:
			printf("got checkpoint info\n");
			break;
		case RZ_VICE_MON_RESPONSE_REGISTER_INFO:
			printf("got register info\n");
			break;
		case RZ_VICE_MON_RESPONSE_JAM:
			printf("got jam\n");
			break;
		case RZ_VICE_MON_RESPONSE_STOPPED:
			printf("got stopped\n");
			break;
		case RZ_VICE_MON_RESPONSE_RESUMED:
			printf("got resumed\n");
			break;
		default:
			break;
		}
	}
	eprintf("--\n");
#endif
	RzVICEMonResponse resp;
	RzVICEMonErr err = parse_response(&resp, resp_raw);
	if (resp_raw->req_id != RZ_VICE_MON_RESPONSE_ID_EVENT) {
		finalize_req_resp(mon, resp_raw->req_id, err, &resp);
	}