mirror of
https://github.com/captain-amygdala/pistorm.git
synced 2026-04-16 00:20:51 +00:00
Add memset to PiStorm API, robustify some things to not destroy the bus
This commit is contained in:
@@ -30,6 +30,7 @@ enum pistorm_dev_cmds {
|
||||
PI_CMD_GET_FB = 0x010C, // [R] Get the current framebuffer address.
|
||||
PI_CMD_COPYRECT = 0x0110, // [W] Generic memory copyrect with source and destination pitch.
|
||||
PI_CMD_COPYRECT_EX = 0x0112, // [W] Extended memory copyrect with additional source/destination X/Y coordinates.
|
||||
PI_CMD_MEMSET = 0x0114, // [W] Accelerated memset functionality to quickly clear a region of memory to a specific value.
|
||||
|
||||
PI_CMD_QBASIC = 0x0FFC, // QBasic
|
||||
PI_CMD_NIBBLES = 0x0FFE, // Nibbles
|
||||
|
||||
@@ -61,7 +61,7 @@ int32_t grab_amiga_string(uint32_t addr, uint8_t *dest, uint32_t str_max_len) {
|
||||
if (r == -1) {
|
||||
DEBUG("[GRAB_AMIGA_STRING] No mapped range found for address $%.8X. Grabbing string data over the bus.\n", addr);
|
||||
do {
|
||||
dest[index] = read8(addr + index);
|
||||
dest[index] = (unsigned char)m68k_read_memory_8(addr + index);
|
||||
index++;
|
||||
} while (dest[index - 1] != 0x00 && index < str_max_len);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ int32_t amiga_transfer_file(uint32_t addr, char *filename) {
|
||||
|
||||
for (uint32_t i = 0; i < filesize; i++) {
|
||||
tmp_read = (uint8_t)fgetc(in);
|
||||
write8(addr + i, tmp_read);
|
||||
m68k_write_memory_8(addr + i, tmp_read);
|
||||
}
|
||||
} else {
|
||||
uint8_t *dst = cfg->map_data[r] + (addr - cfg->map_offset[r]);
|
||||
@@ -200,16 +200,36 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
|
||||
printf("!!! doing manual memcpy\n");
|
||||
uint8_t tmp = 0;
|
||||
for (uint32_t i = 0; i < val; i++) {
|
||||
if (src == -1) tmp = read8(pi_ptr[0] + i);
|
||||
if (src == -1) tmp = (unsigned char)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) write8(pi_ptr[1] + i, tmp);
|
||||
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, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PI_CMD_COPYRECT:
|
||||
case PI_CMD_COPYRECT_EX:
|
||||
if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
|
||||
@@ -256,10 +276,10 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
|
||||
|
||||
for (uint32_t y = 0; y < pi_word[3]; y++) {
|
||||
for (uint32_t x = 0; x < pi_word[2]; x++) {
|
||||
if (src == -1) tmp = read8(pi_ptr[0] + src_offset + x);
|
||||
if (src == -1) tmp = (unsigned char)m68k_read_memory_8(pi_ptr[0] + src_offset + x);
|
||||
else tmp = cfg->map_data[src][(pi_ptr[0] + src_offset + x) - cfg->map_offset[src]];
|
||||
|
||||
if (dst == -1) write8(pi_ptr[1] + dst_offset + x, tmp);
|
||||
if (dst == -1) m68k_write_memory_8(pi_ptr[1] + dst_offset + x, tmp);
|
||||
else cfg->map_data[dst][(pi_ptr[1] + dst_offset + x) - cfg->map_offset[dst]] = tmp;
|
||||
}
|
||||
src_offset += pi_word[0];
|
||||
|
||||
Binary file not shown.
@@ -115,6 +115,14 @@ unsigned short pi_memcpy(unsigned char *dst, unsigned char *src, unsigned int si
|
||||
RETURN_CMDRES;
|
||||
}
|
||||
|
||||
unsigned short pi_memset(unsigned char *dst, unsigned char val, unsigned int size) {
|
||||
WRITELONG(PI_PTR1, (unsigned int)dst);
|
||||
WRITEBYTE(PI_BYTE1, val);
|
||||
WRITELONG(PI_CMD_MEMSET, size);
|
||||
|
||||
RETURN_CMDRES;
|
||||
}
|
||||
|
||||
// Generic memory copyrect, assuming that the src/dst offsets are already adjusted for X/Y coordinates.
|
||||
void pi_copyrect(unsigned char *dst, unsigned char *src,
|
||||
unsigned short src_pitch, unsigned short dst_pitch,
|
||||
|
||||
@@ -25,6 +25,7 @@ unsigned short pi_piscsi_eject_media(unsigned char index);
|
||||
unsigned short pi_get_filesize(char *filename, unsigned int *file_size);
|
||||
unsigned short pi_transfer_file(char *filename, unsigned char *dest_ptr);
|
||||
unsigned short pi_memcpy(unsigned char *dst, unsigned char *src, unsigned int size);
|
||||
unsigned short pi_memset(unsigned char *dst, unsigned char val, unsigned int size);
|
||||
void pi_copyrect(unsigned char *dst, unsigned char *src, unsigned short src_pitch, unsigned short dst_pitch, unsigned short w, unsigned short h);
|
||||
void pi_copyrect_ex(unsigned char *dst, unsigned char *src, unsigned short src_pitch, unsigned short dst_pitch, unsigned short src_x, unsigned short src_y, unsigned short dst_x, unsigned short dst_y, unsigned short w, unsigned short h);
|
||||
unsigned int pi_get_fb(void);
|
||||
|
||||
Reference in New Issue
Block a user