+ case PI_CMD_MEMCPY:
+ //DEBUG("[PISTORM-DEV} Write to MEMCPY: %d (%.8X)\n", val, val);
+ if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
+ printf("[PISTORM-DEV] MEMCPY from/to null pointer not allowed. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else if (val == 0) {
+ printf("[PISTORM-DEV] MEMCPY called with size 0. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else {
+ int32_t src = get_mapped_item_by_address(cfg, pi_ptr[0]);
+ int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[1]);
+ if (dst != -1 && src != -1) {
+ uint8_t *src_ptr = &cfg->map_data[src][(pi_ptr[0] - cfg->map_offset[src])];
+ uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[1] - cfg->map_offset[dst])];
+ memcpy(dst_ptr, src_ptr, val);
+ } else {
+ uint8_t tmp = 0;
+ uint16_t tmps = 0;
+ for (uint32_t i = 0; i < val; i++) {
+ while (i + 2 < val) {
+ if (src == -1) tmps = (uint16_t)m68k_read_memory_16(pi_ptr[0] + i);
+ else memcpy(&tmps, &cfg->map_data[src][pi_ptr[0] - cfg->map_offset[src] + i], 2);
+
+ if (dst == -1) m68k_write_memory_16(pi_ptr[1] + i, tmps);
+ else memcpy(&cfg->map_data[dst][pi_ptr[1] - cfg->map_offset[dst] + i], &tmps, 2);
+ i += 2;
+ }
+ if (src == -1) tmp = (uint8_t)m68k_read_memory_8(pi_ptr[0] + i);
+ else tmp = cfg->map_data[src][pi_ptr[0] - cfg->map_offset[src] + i];
+
+ if (dst == -1) m68k_write_memory_8(pi_ptr[1] + i, tmp);
+ else cfg->map_data[dst][pi_ptr[1] - cfg->map_offset[dst] + i] = tmp;
+ }
+ }
+ //DEBUG("[PISTORM-DEV] Copied %d bytes from $%.8X to $%.8X\n", val, pi_ptr[0], pi_ptr[1]);
+ }
+ break;
+ case PI_CMD_MEMSET:
+ //DEBUG("[PISTORM-DEV} Write to MEMSET: %d (%.8X)\n", val, val);
+ if (pi_ptr[0] == 0) {
+ printf("[PISTORM-DEV] MEMSET with null pointer not allowed. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else if (val == 0) {
+ printf("[PISTORM-DEV] MEMSET called with size 0. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else {
+ int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[0]);
+ if (dst != -1) {
+ uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[0] - cfg->map_offset[dst])];
+ memset(dst_ptr, pi_byte[0], val);
+ } else {
+ for (uint32_t i = 0; i < val; i++) {
+ m68k_write_memory_8(pi_ptr[0] + i, pi_byte[0]);
+ }
+ }
+ }
+ break;
+ case PI_CMD_COPYRECT:
+ case PI_CMD_COPYRECT_EX:
+ if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
+ printf("[PISTORM-DEV] COPYRECT/EX from/to null pointer not allowed. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else if (pi_word[2] == 0 || pi_word[3] == 0) {
+ printf("[PISTORM-DEV] COPYRECT/EX called with a width/height of 0. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else {
+ int32_t src = get_mapped_item_by_address(cfg, pi_ptr[0]);
+ int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[1]);
+
+ if (addr != PI_CMD_COPYRECT_EX) {
+ // Clear out the src/dst coordinates in case something else set them previously.
+ pi_word[4] = pi_word[5] = pi_word[6] = pi_word[7] = 0;
+ }
+
+ if (dst != -1 && src != -1) {
+ uint8_t *src_ptr = &cfg->map_data[src][(pi_ptr[0] - cfg->map_offset[src])];
+ uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[1] - cfg->map_offset[dst])];