1 // SPDX-License-Identifier: MIT
8 #include "pistorm-dev.h"
9 #include "pistorm-dev-enums.h"
10 #include "platforms/platforms.h"
11 #include "gpio/ps_protocol.h"
12 #include "platforms/amiga/rtg/rtg.h"
13 #include "platforms/amiga/piscsi/piscsi.h"
14 #include "platforms/amiga/net/pi-net.h"
16 #include <linux/reboot.h>
17 #include <sys/reboot.h>
19 #define DEBUG_PISTORM_DEVICE
21 #ifdef DEBUG_PISTORM_DEVICE
24 #define PIDEV_SWREV 0x0105
26 static const char *op_type_names[4] = {
36 extern uint32_t pistorm_dev_base;
37 extern uint32_t do_reset;
39 extern void adjust_ranges_amiga(struct emulator_config *cfg);
40 extern uint8_t rtg_enabled, rtg_on, pinet_enabled, piscsi_enabled, load_new_config, end_signal;
41 extern struct emulator_config *cfg;
43 char cfg_filename[256] = "default.cfg";
46 static uint8_t pi_byte[32];
47 static uint16_t pi_word[32];
48 static uint32_t pi_longword[32];
49 static uint32_t pi_string[32];
50 static uint32_t pi_ptr[32];
52 static uint32_t pi_dbg_val[32];
53 static uint32_t pi_dbg_string[32];
55 static uint32_t pi_cmd_result = 0, shutdown_confirm = 0xFFFFFFFF;
57 int32_t grab_amiga_string(uint32_t addr, uint8_t *dest, uint32_t str_max_len) {
58 int32_t r = get_mapped_item_by_address(cfg, addr);
62 DEBUG("[GRAB_AMIGA_STRING] No mapped range found for address $%.8X. Grabbing string data over the bus.\n", addr);
64 dest[index] = (unsigned char)m68k_read_memory_8(addr + index);
66 } while (dest[index - 1] != 0x00 && index < str_max_len);
69 uint8_t *src = cfg->map_data[r] + (addr - cfg->map_offset[r]);
71 dest[index] = src[index];
73 } while (dest[index - 1] != 0x00 && index < str_max_len);
75 if (index == str_max_len) {
76 memset(dest, 0x00, str_max_len + 1);
79 DEBUG("[GRAB_AMIGA_STRING] Grabbed string: %s\n", dest);
80 return (int32_t)strlen((const char*)dest);
83 int32_t amiga_transfer_file(uint32_t addr, char *filename) {
84 FILE *in = fopen(filename, "rb");
86 DEBUG("[AMIGA_TRANSFER_FILE] Failed to open file %s for reading.\n", filename);
89 fseek(in, 0, SEEK_END);
91 int32_t r = get_mapped_item_by_address(cfg, addr);
92 uint32_t filesize = ftell(in);
94 fseek(in, 0, SEEK_SET);
96 DEBUG("[GRAB_AMIGA_STRING] No mapped range found for address $%.8X. Transferring file data over the bus.\n", addr);
99 for (uint32_t i = 0; i < filesize; i++) {
100 tmp_read = (uint8_t)fgetc(in);
101 m68k_write_memory_8(addr + i, tmp_read);
104 uint8_t *dst = cfg->map_data[r] + (addr - cfg->map_offset[r]);
105 fread(dst, filesize, 1, in);
108 DEBUG("[AMIGA_TRANSFER_FILE] Copied %d bytes to address $%.8X.\n", filesize, addr);
113 char *get_pistorm_devcfg_filename() {
117 void set_pistorm_devcfg_filename(char *filename) {
118 strcpy(cfg_filename, filename);
121 void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
122 uint32_t addr = (addr_ & 0xFFFF);
126 // Output debug message based on value written and data in val/str registers.
128 case PI_DBG_VAL1: case PI_DBG_VAL2: case PI_DBG_VAL3: case PI_DBG_VAL4:
129 case PI_DBG_VAL5: case PI_DBG_VAL6: case PI_DBG_VAL7: case PI_DBG_VAL8:
130 DEBUG("[PISTORM-DEV] Set DEBUG VALUE %d to %d ($%.8X)\n", (addr - PI_DBG_VAL1) / 4, val, val);
131 pi_dbg_val[(addr - PI_DBG_VAL1) / 4] = val;
133 case PI_DBG_STR1: case PI_DBG_STR2: case PI_DBG_STR3: case PI_DBG_STR4:
134 DEBUG("[PISTORM-DEV] Set DEBUG STRING POINTER %d to $%.8X\n", (addr - PI_DBG_STR1) / 4, val);
135 pi_dbg_string[(addr - PI_DBG_STR1) / 4] = val;
138 case PI_BYTE1: case PI_BYTE2: case PI_BYTE3: case PI_BYTE4:
139 case PI_BYTE5: case PI_BYTE6: case PI_BYTE7: case PI_BYTE8:
140 DEBUG("[PISTORM-DEV] Set BYTE %d to %d ($%.2X)\n", addr - PI_BYTE1, (val & 0xFF), (val & 0xFF));
141 pi_byte[addr - PI_BYTE1] = (val & 0xFF);
143 case PI_WORD1: case PI_WORD2: case PI_WORD3: case PI_WORD4:
144 //DEBUG("[PISTORM-DEV] Set WORD %d to %d ($%.4X)\n", (addr - PI_WORD1) / 2, (val & 0xFFFF), (val & 0xFFFF));
145 pi_word[(addr - PI_WORD1) / 2] = (val & 0xFFFF);
147 case PI_WORD5: case PI_WORD6: case PI_WORD7: case PI_WORD8:
148 case PI_WORD9: case PI_WORD10: case PI_WORD11: case PI_WORD12:
149 //DEBUG("[PISTORM-DEV] Set WORD %d to %d ($%.4X)\n", (addr - PI_WORD5) / 2, (val & 0xFFFF), (val & 0xFFFF));
150 pi_word[(addr - PI_WORD5) / 2] = (val & 0xFFFF);
152 case PI_LONGWORD1: case PI_LONGWORD2: case PI_LONGWORD3: case PI_LONGWORD4:
153 //DEBUG("[PISTORM-DEV] Set LONGWORD %d to %d ($%.8X)\n", (addr - PI_LONGWORD1) / 4, val, val);
154 pi_longword[(addr - PI_LONGWORD1) / 4] = val;
156 case PI_STR1: case PI_STR2: case PI_STR3: case PI_STR4:
157 DEBUG("[PISTORM-DEV] Set STRING POINTER %d to $%.8X\n", (addr - PI_STR1) / 4, val);
158 pi_string[(addr - PI_STR1) / 4] = val;
160 case PI_PTR1: case PI_PTR2: case PI_PTR3: case PI_PTR4:
161 //DEBUG("[PISTORM-DEV] Set DATA POINTER %d to $%.8X\n", (addr - PI_PTR1) / 4, val);
162 pi_ptr[(addr - PI_PTR1) / 4] = val;
165 case PI_CMD_TRANSFERFILE:
166 DEBUG("[PISTORM-DEV] Write to TRANSFERFILE.\n");
167 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
168 printf("[PISTORM-DEV] No or invalid filename for TRANSFERFILE. Aborting.\n");
169 pi_cmd_result = PI_RES_INVALIDVALUE;
170 } else if (pi_ptr[0] == 0) {
171 printf("[PISTORM-DEV] Null pointer specified for TRANSFERFILE destination. Aborting.\n");
172 pi_cmd_result = PI_RES_INVALIDVALUE;
174 if (amiga_transfer_file(pi_ptr[0], tmp_string) == -1) {
175 pi_cmd_result = PI_RES_FAILED;
177 pi_cmd_result = PI_RES_OK;
184 //DEBUG("[PISTORM-DEV} Write to MEMCPY: %d (%.8X)\n", val, val);
185 if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
186 printf("[PISTORM-DEV] MEMCPY from/to null pointer not allowed. Aborting.\n");
187 pi_cmd_result = PI_RES_INVALIDVALUE;
188 } else if (val == 0) {
189 printf("[PISTORM-DEV] MEMCPY called with size 0. Aborting.\n");
190 pi_cmd_result = PI_RES_INVALIDVALUE;
192 int32_t src = get_mapped_item_by_address(cfg, pi_ptr[0]);
193 int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[1]);
194 if (dst != -1 && src != -1) {
195 //printf("doing super memcpy\n");
196 uint8_t *src_ptr = &cfg->map_data[src][(pi_ptr[0] - cfg->map_offset[src])];
197 uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[1] - cfg->map_offset[dst])];
198 memcpy(dst_ptr, src_ptr, val);
201 for (uint32_t i = 0; i < val; i++) {
202 if (src == -1) tmp = (unsigned char)m68k_read_memory_8(pi_ptr[0] + i);
203 else tmp = cfg->map_data[src][pi_ptr[0] - cfg->map_offset[src] + i];
205 if (dst == -1) m68k_write_memory_8(pi_ptr[1] + i, tmp);
206 else cfg->map_data[dst][pi_ptr[1] - cfg->map_offset[dst] + i] = tmp;
209 //DEBUG("[PISTORM-DEV] Copied %d bytes from $%.8X to $%.8X\n", val, pi_ptr[0], pi_ptr[1]);
213 //DEBUG("[PISTORM-DEV} Write to MEMSET: %d (%.8X)\n", val, val);
214 if (pi_ptr[0] == 0) {
215 printf("[PISTORM-DEV] MEMSET with null pointer not allowed. Aborting.\n");
216 pi_cmd_result = PI_RES_INVALIDVALUE;
217 } else if (val == 0) {
218 printf("[PISTORM-DEV] MEMSET called with size 0. Aborting.\n");
219 pi_cmd_result = PI_RES_INVALIDVALUE;
221 int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[0]);
223 uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[0] - cfg->map_offset[dst])];
224 memset(dst_ptr, pi_byte[0], val);
226 for (uint32_t i = 0; i < val; i++) {
227 m68k_write_memory_8(pi_ptr[0] + i, pi_byte[0]);
232 case PI_CMD_COPYRECT:
233 case PI_CMD_COPYRECT_EX:
234 if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
235 printf("[PISTORM-DEV] COPYRECT/EX from/to null pointer not allowed. Aborting.\n");
236 pi_cmd_result = PI_RES_INVALIDVALUE;
237 } else if (pi_word[2] == 0 || pi_word[3] == 0) {
238 printf("[PISTORM-DEV] COPYRECT/EX called with a width/height of 0. Aborting.\n");
239 pi_cmd_result = PI_RES_INVALIDVALUE;
241 int32_t src = get_mapped_item_by_address(cfg, pi_ptr[0]);
242 int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[1]);
244 if (dst != -1 && src != -1) {
245 uint8_t *src_ptr = &cfg->map_data[src][(pi_ptr[0] - cfg->map_offset[src])];
246 uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[1] - cfg->map_offset[dst])];
248 if (addr == PI_CMD_COPYRECT_EX) {
249 // Adjust pointers in the case of available src/dst coordinates.
250 src_ptr += pi_word[4] + (pi_word[5] * pi_word[0]);
251 dst_ptr += pi_word[6] + (pi_word[7] * pi_word[1]);
254 for (int i = 0; i < pi_word[3]; i++) {
255 memcpy(dst_ptr, src_ptr, pi_word[2]);
257 src_ptr += pi_word[0];
258 dst_ptr += pi_word[1];
261 printf("!!! doing manual copyrect\n");
263 if (addr != PI_CMD_COPYRECT_EX) {
264 // Clear out the src/dst coordinates in case something else set them previously.
265 pi_word[4] = pi_word[5] = pi_word[6] = pi_word[7] = 0;
268 uint32_t src_offset = 0, dst_offset = 0;
271 if (addr == PI_CMD_COPYRECT_EX) {
272 src_offset += pi_word[4] + (pi_word[5] * pi_word[0]);
273 dst_offset += pi_word[6] + (pi_word[7] * pi_word[1]);
276 for (uint32_t y = 0; y < pi_word[3]; y++) {
277 for (uint32_t x = 0; x < pi_word[2]; x++) {
278 if (src == -1) tmp = (unsigned char)m68k_read_memory_8(pi_ptr[0] + src_offset + x);
279 else tmp = cfg->map_data[src][(pi_ptr[0] + src_offset + x) - cfg->map_offset[src]];
281 if (dst == -1) m68k_write_memory_8(pi_ptr[1] + dst_offset + x, tmp);
282 else cfg->map_data[dst][(pi_ptr[1] + dst_offset + x) - cfg->map_offset[dst]] = tmp;
284 src_offset += pi_word[0];
285 dst_offset += pi_word[1];
291 case PI_CMD_SHOWFPS: rtg_show_fps((uint8_t)val); break;
292 case PI_CMD_PALETTEDEBUG: rtg_palette_debug((uint8_t)val); break;
293 case PI_CMD_RTGSTATUS:
294 DEBUG("[PISTORM-DEV] Write to RTGSTATUS: %d\n", val);
295 if (val == 1 && !rtg_enabled) {
298 pi_cmd_result = PI_RES_OK;
299 } else if (val == 0 && rtg_enabled) {
303 pi_cmd_result = PI_RES_OK;
305 // Refuse to disable RTG if it's currently in use.
306 pi_cmd_result = PI_RES_FAILED;
309 pi_cmd_result = PI_RES_NOCHANGE;
311 adjust_ranges_amiga(cfg);
313 case PI_CMD_NETSTATUS:
314 DEBUG("[PISTORM-DEV] Write to NETSTATUS: %d\n", val);
315 if (val == 1 && !pinet_enabled) {
318 pi_cmd_result = PI_RES_OK;
319 } else if (val == 0 && pinet_enabled) {
322 pi_cmd_result = PI_RES_OK;
324 pi_cmd_result = PI_RES_NOCHANGE;
326 adjust_ranges_amiga(cfg);
328 case PI_CMD_PISCSI_CTRL:
329 DEBUG("[PISTORM-DEV] Write to PISCSI_CTRL: ");
331 case PISCSI_CTRL_DISABLE:
333 if (piscsi_enabled) {
336 // Probably not OK... depends on if you booted from floppy, I guess.
337 pi_cmd_result = PI_RES_OK;
339 pi_cmd_result = PI_RES_NOCHANGE;
342 case PISCSI_CTRL_ENABLE:
344 if (!piscsi_enabled) {
347 piscsi_refresh_drives();
348 pi_cmd_result = PI_RES_OK;
350 pi_cmd_result = PI_RES_NOCHANGE;
353 case PISCSI_CTRL_MAP:
355 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
356 printf("[PISTORM-DEV] Failed to grab string for PISCSI drive filename. Aborting.\n");
357 pi_cmd_result = PI_RES_FAILED;
359 FILE *tmp = fopen(tmp_string, "rb");
361 printf("[PISTORM-DEV] Failed to open file %s for PISCSI drive mapping. Aborting.\n", tmp_string);
362 pi_cmd_result = PI_RES_FILENOTFOUND;
365 printf("[PISTORM-DEV] Attempting to map file %s as PISCSI drive %d...\n", tmp_string, pi_word[0]);
366 piscsi_unmap_drive(pi_word[0]);
367 piscsi_map_drive(tmp_string, pi_word[0]);
368 pi_cmd_result = PI_RES_OK;
373 case PISCSI_CTRL_UNMAP:
375 if (pi_word[0] > 7) {
376 printf("[PISTORM-DEV] Invalid drive ID %d for PISCSI unmap command.", pi_word[0]);
377 pi_cmd_result = PI_RES_INVALIDVALUE;
379 if (piscsi_get_dev(pi_word[0])->fd != -1) {
380 piscsi_unmap_drive(pi_word[0]);
381 pi_cmd_result = PI_RES_OK;
383 pi_cmd_result = PI_RES_NOCHANGE;
387 case PISCSI_CTRL_EJECT:
388 DEBUG("EJECT (NYI)\n");
389 pi_cmd_result = PI_RES_NOCHANGE;
391 case PISCSI_CTRL_INSERT:
392 DEBUG("INSERT (NYI)\n");
393 pi_cmd_result = PI_RES_NOCHANGE;
396 DEBUG("UNKNOWN/UNHANDLED. Aborting.\n");
397 pi_cmd_result = PI_RES_INVALIDVALUE;
400 adjust_ranges_amiga(cfg);
404 DEBUG("[PISTORM-DEV] Write to KICKROM.\n");
405 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
406 printf("[PISTORM-DEV] Failed to grab string KICKROM filename. Aborting.\n");
407 pi_cmd_result = PI_RES_FAILED;
409 FILE *tmp = fopen(tmp_string, "rb");
411 printf("[PISTORM-DEV] Failed to open file %s for KICKROM mapping. Aborting.\n", tmp_string);
412 pi_cmd_result = PI_RES_FILENOTFOUND;
415 if (get_named_mapped_item(cfg, "kickstart") != -1) {
416 uint32_t index = get_named_mapped_item(cfg, "kickstart");
417 free(cfg->map_data[index]);
418 free(cfg->map_id[index]);
419 cfg->map_type[index] = MAPTYPE_NONE;
420 // Dirty hack, I am sleepy and lazy.
421 add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "kickstart");
422 pi_cmd_result = PI_RES_OK;
425 printf ("[PISTORM-DEV] Could not find mapped range 'kickstart', cannot remap KICKROM.\n");
426 pi_cmd_result = PI_RES_FAILED;
430 adjust_ranges_amiga(cfg);
434 DEBUG("[PISTORM-DEV] Write to EXTROM.\n");
435 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
436 printf("[PISTORM-DEV] Failed to grab string EXTROM filename. Aborting.\n");
437 pi_cmd_result = PI_RES_FAILED;
439 FILE *tmp = fopen(tmp_string, "rb");
441 printf("[PISTORM-DEV] Failed to open file %s for EXTROM mapping. Aborting.\n", tmp_string);
442 pi_cmd_result = PI_RES_FILENOTFOUND;
445 if (get_named_mapped_item(cfg, "extended") != -1) {
446 uint32_t index = get_named_mapped_item(cfg, "extended");
447 free(cfg->map_data[index]);
448 free(cfg->map_id[index]);
449 cfg->map_type[index] = MAPTYPE_NONE;
450 // Dirty hack, I am tired and lazy.
451 add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "extended");
452 pi_cmd_result = PI_RES_OK;
455 printf ("[PISTORM-DEV] Could not find mapped range 'extrom', cannot remap EXTROM.\n");
456 pi_cmd_result = PI_RES_FAILED;
460 adjust_ranges_amiga(cfg);
465 DEBUG("[PISTORM-DEV] System reset called, code %d\n", (val & 0xFFFF));
468 case PI_CMD_SHUTDOWN:
469 DEBUG("[PISTORM-DEV] Shutdown requested. Confirm by replying with return value to CONFIRMSHUTDOWN.\n");
470 shutdown_confirm = rand() % 0xFFFF;
471 pi_cmd_result = shutdown_confirm;
473 case PI_CMD_CONFIRMSHUTDOWN:
474 if (val != shutdown_confirm) {
475 DEBUG("[PISTORM-DEV] Attempted shutdown with wrong shutdown confirm value. Not shutting down.\n");
476 shutdown_confirm = 0xFFFFFFFF;
477 pi_cmd_result = PI_RES_FAILED;
479 printf("[PISTORM-DEV] Shutting down the PiStorm. Good night, fight well, until we meet again.\n");
480 reboot(LINUX_REBOOT_CMD_POWER_OFF);
481 pi_cmd_result = PI_RES_OK;
485 case PI_CMD_SWITCHCONFIG:
486 DEBUG("[PISTORM-DEV] Config switch called, command: ");
490 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)cfg_filename, 255) == -1) {
491 printf("[PISTORM-DEV] Failed to grab string for CONFIG filename. Aborting.\n");
492 pi_cmd_result = PI_RES_FAILED;
494 FILE *tmp = fopen(cfg_filename, "rb");
496 printf("[PISTORM-DEV] Failed to open CONFIG file %s for reading. Aborting.\n", cfg_filename);
497 pi_cmd_result = PI_RES_FILENOTFOUND;
500 printf("[PISTORM-DEV] Attempting to load config file %s...\n", cfg_filename);
501 load_new_config = val + 1;
502 pi_cmd_result = PI_RES_OK;
509 printf("[PISTORM-DEV] Reloading current config file (%s)...\n", cfg_filename);
510 load_new_config = val + 1;
514 printf("[PISTORM-DEV] Loading default.cfg...\n");
515 load_new_config = val + 1;
518 DEBUG("UNKNOWN/UNHANDLED. Command ignored.\n");
519 pi_cmd_result = PI_RES_INVALIDVALUE;
524 DEBUG("[PISTORM-DEV] WARN: Unhandled %s register write to %.4X: %d\n", op_type_names[type], addr - pistorm_dev_base, val);
525 pi_cmd_result = PI_RES_INVALIDCMD;
530 uint32_t handle_pistorm_dev_read(uint32_t addr_, uint8_t type) {
531 uint32_t addr = (addr_ & 0xFFFF);
534 case PI_CMD_FILESIZE:
535 DEBUG("[PISTORM-DEV] %s read from FILESIZE.\n", op_type_names[type]);
536 if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
537 DEBUG("[PISTORM-DEV] Failed to grab string for FILESIZE command. Aborting.\n");
538 pi_cmd_result = PI_RES_FAILED;
542 FILE *tmp = fopen(tmp_string, "rb");
544 DEBUG("[PISTORM-DEV] Failed to open file %s for FILESIZE command. Aborting.\n", tmp_string);
546 pi_cmd_result = PI_RES_FILENOTFOUND;
548 fseek(tmp, 0, SEEK_END);
549 pi_longword[0] = ftell(tmp);
550 DEBUG("[PISTORM-DEV] Returning file size for file %s: %d bytes.\n", tmp_string, pi_longword[0]);
552 pi_cmd_result = PI_RES_OK;
556 return pi_longword[0];
560 // Probably replace this with some read from the CPLD to get a simple hardware revision.
561 DEBUG("[PISTORM-DEV] %s Read from HWREV\n", op_type_names[type]);
562 return 0x0101; // 1.1
565 DEBUG("[PISTORM-DEV] %s Read from SWREV\n", op_type_names[type]);
568 case PI_CMD_RTGSTATUS:
569 DEBUG("[PISTORM-DEV] %s Read from RTGSTATUS\n", op_type_names[type]);
570 return (rtg_on << 1) | rtg_enabled;
572 case PI_CMD_NETSTATUS:
573 DEBUG("[PISTORM-DEV] %s Read from NETSTATUS\n", op_type_names[type]);
574 return pinet_enabled;
576 case PI_CMD_PISCSI_CTRL:
577 DEBUG("[PISTORM-DEV] %s Read from PISCSI_CTRL\n", op_type_names[type]);
578 return piscsi_enabled;
581 //DEBUG("[PISTORM-DEV] %s read from GET_FB: %.8X\n", op_type_names[type], rtg_get_fb());
584 case PI_DBG_VAL1: case PI_DBG_VAL2: case PI_DBG_VAL3: case PI_DBG_VAL4:
585 case PI_DBG_VAL5: case PI_DBG_VAL6: case PI_DBG_VAL7: case PI_DBG_VAL8:
586 DEBUG("[PISTORM-DEV] Read DEBUG VALUE %d (%d / $%.8X)\n", (addr - PI_DBG_VAL1) / 4, pi_dbg_val[(addr - PI_DBG_VAL1) / 4], pi_dbg_val[(addr - PI_DBG_VAL1) / 4]);
587 return pi_dbg_val[(addr - PI_DBG_VAL1) / 4];
590 case PI_BYTE1: case PI_BYTE2: case PI_BYTE3: case PI_BYTE4:
591 case PI_BYTE5: case PI_BYTE6: case PI_BYTE7: case PI_BYTE8:
592 DEBUG("[PISTORM-DEV] Read BYTE %d (%d / $%.2X)\n", addr - PI_BYTE1, pi_byte[addr - PI_BYTE1], pi_byte[addr - PI_BYTE1]);
593 return pi_byte[addr - PI_BYTE1];
595 case PI_WORD1: case PI_WORD2: case PI_WORD3: case PI_WORD4:
596 DEBUG("[PISTORM-DEV] Read WORD %d (%d / $%.4X)\n", (addr - PI_WORD1) / 2, pi_word[(addr - PI_WORD1) / 2], pi_word[(addr - PI_WORD1) / 2]);
597 return pi_word[(addr - PI_WORD1) / 2];
599 case PI_WORD5: case PI_WORD6: case PI_WORD7: case PI_WORD8:
600 case PI_WORD9: case PI_WORD10: case PI_WORD11: case PI_WORD12:
601 DEBUG("[PISTORM-DEV] Read WORD %d (%d / $%.4X)\n", (addr - PI_WORD5) / 2, pi_word[(addr - PI_WORD5) / 2], pi_word[(addr - PI_WORD5) / 2]);
602 return pi_word[(addr - PI_WORD5) / 2];
604 case PI_LONGWORD1: case PI_LONGWORD2: case PI_LONGWORD3: case PI_LONGWORD4:
605 DEBUG("[PISTORM-DEV] Read LONGWORD %d (%d / $%.8X)\n", (addr - PI_LONGWORD1) / 4, pi_longword[(addr - PI_LONGWORD1) / 4], pi_longword[(addr - PI_LONGWORD1) / 4]);
606 return pi_longword[(addr - PI_LONGWORD1) / 4];
610 //DEBUG("[PISTORM-DEV] %s Read from CMDRESULT: %d\n", op_type_names[type], pi_cmd_result);
611 return pi_cmd_result;
615 DEBUG("[PISTORM-DEV] WARN: Unhandled %s register read from %.4X\n", op_type_names[type], addr - pistorm_dev_base);