PI_CMD_HWREV = 0x10, // [R] Check the PiStorm hardware version/revision
PI_CMD_SWREV = 0x12, // [R] Check the PiStorm software version/revision
+ PI_CMD_FILESIZE = 0x0100, // [R] Get the file size for file on the Pi side using the path
+ // at PI_STR1, if it exists.
+ PI_CMD_TRANSFERFILE = 0x0104, // [W] Transfer over a file from the Pi to Amiga RAM.
+
PI_CMD_QBASIC = 0x0FFC, // QBasic
PI_CMD_NIBBLES = 0x0FFE, // Nibbles
PI_DBG_VAL6 = 0x1024, // [RW]
PI_DBG_VAL7 = 0x1028, // [RW]
PI_DBG_VAL8 = 0x102C, // [RW]
- PI_DBG_STR1 = 0x1030, // [W] Pointers to debug strings (typically in "Amiga RAM")
+ PI_DBG_STR1 = 0x1030, // [W] Pointers to debug strings (typically in Amiga RAM)
PI_DBG_STR2 = 0x1034, // [W]
PI_DBG_STR3 = 0x1038, // [W]
PI_DBG_STR4 = 0x103C, // [W]
PI_LONGWORD2 = 0x2014, // [RW]
PI_LONGWORD3 = 0x2018, // [RW]
PI_LONGWORD4 = 0x201C, // [RW]
- PI_STR1 = 0x2020, // [W] Pointers to strings (typically in "Amiga RAM")
+ PI_STR1 = 0x2020, // [W] Pointers to strings (typically in Amiga RAM)
PI_STR2 = 0x2024, // [W]
PI_STR3 = 0x2028, // [W]
PI_STR4 = 0x202C, // [W]
+ PI_PTR1 = 0x2030, // [W] Pointers to allocated memory in Amiga RAM.
+ PI_PTR2 = 0x2034, // [W] For instance for loading large files to Amiga RAM or
+ PI_PTR3 = 0x2038, // [W] transferring over files from the Pi side of things.
+ PI_PTR4 = 0x203C, // [W]
PI_CMDRESULT = 0x2100, // [R] Check the result of any command that provides a "return value".
};
static uint16_t pi_word[4];
static uint32_t pi_longword[4];
static uint32_t pi_string[4];
+static uint32_t pi_ptr[4];
static uint32_t pi_dbg_val[4];
static uint32_t pi_dbg_string[4];
return (int32_t)strlen((const char*)dest);
}
+int32_t amiga_transfer_file(uint32_t addr, char *filename) {
+ FILE *in = fopen(filename, "rb");
+ if (in == NULL) {
+ DEBUG("[AMIGA_TRANSFER_FILE] Failed to open file %s for reading.\n", filename);
+ return -1;
+ }
+ fseek(in, 0, SEEK_END);
+
+ int32_t r = get_mapped_item_by_address(cfg, addr);
+ uint32_t filesize = ftell(in);
+
+ fseek(in, 0, SEEK_SET);
+ if (r == -1) {
+ DEBUG("[GRAB_AMIGA_STRING] No mapped range found for address $%.8X. Transferring file data over the bus.\n", addr);
+ uint8_t tmp_read = 0;
+
+ for (uint32_t i = 0; i < filesize; i++) {
+ tmp_read = (uint8_t)fgetc(in);
+ write8(addr + i, tmp_read);
+ }
+ } else {
+ uint8_t *dst = cfg->map_data[r] + (addr - cfg->map_offset[r]);
+ fread(dst, filesize, 1, in);
+ }
+ fclose(in);
+ DEBUG("[AMIGA_TRANSFER_FILE] Copied %d bytes to address $%.8X.\n", filesize, addr);
+
+ return 0;
+}
+
char *get_pistorm_devcfg_filename() {
return cfg_filename;
}
DEBUG("[PISTORM-DEV] Set STRING POINTER %d to $%.8X\n", (addr - PI_STR1) / 4, val);
pi_string[(addr - PI_STR1) / 4] = val;
break;
+ case PI_PTR1: case PI_PTR2: case PI_PTR3: case PI_PTR4:
+ DEBUG("[PISTORM-DEV] Set DATA POINTER %d to $%.8X\n", (addr - PI_PTR1) / 4, val);
+ pi_ptr[(addr - PI_PTR1) / 4] = val;
+ break;
+
+ case PI_CMD_TRANSFERFILE:
+ DEBUG("[PISTORM-DEV] Write to TRANSFERFILE.\n");
+ if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
+ printf("[PISTORM-DEV] No or invalid filename for TRANSFERFILE. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else if (pi_ptr[0] == 0) {
+ printf("[PISTORM-DEV] Null pointer specified for TRANSFERFILE destination. Aborting.\n");
+ pi_cmd_result = PI_RES_INVALIDVALUE;
+ } else {
+ if (amiga_transfer_file(pi_ptr[0], tmp_string) == -1) {
+ pi_cmd_result = PI_RES_FAILED;
+ } else {
+ pi_cmd_result = PI_RES_OK;
+ }
+ }
+ pi_string[0] = 0;
+ pi_ptr[0] = 0;
+ break;
case PI_CMD_RTGSTATUS:
DEBUG("[PISTORM-DEV] Write to RTGSTATUS: %d\n", val);
} else {
FILE *tmp = fopen(tmp_string, "rb");
if (tmp == NULL) {
- printf("[PISTORM-DEV] Failed to open file %s for PISCSI drive mapping. Aborting.\n", cfg_filename);
+ printf("[PISTORM-DEV] Failed to open file %s for PISCSI drive mapping. Aborting.\n", tmp_string);
pi_cmd_result = PI_RES_FILENOTFOUND;
} else {
fclose(tmp);
- printf("[PISTORM-DEV] Attempting to map file %s as PISCSI drive %d...\n", cfg_filename, pi_word[0]);
+ printf("[PISTORM-DEV] Attempting to map file %s as PISCSI drive %d...\n", tmp_string, pi_word[0]);
piscsi_unmap_drive(pi_word[0]);
piscsi_map_drive(tmp_string, pi_word[0]);
pi_cmd_result = PI_RES_OK;
} else {
FILE *tmp = fopen(tmp_string, "rb");
if (tmp == NULL) {
- printf("[PISTORM-DEV] Failed to open file %s for KICKROM mapping. Aborting.\n", cfg_filename);
+ printf("[PISTORM-DEV] Failed to open file %s for KICKROM mapping. Aborting.\n", tmp_string);
pi_cmd_result = PI_RES_FILENOTFOUND;
} else {
fclose(tmp);
} else {
FILE *tmp = fopen(tmp_string, "rb");
if (tmp == NULL) {
- printf("[PISTORM-DEV] Failed to open file %s for EXTROM mapping. Aborting.\n", cfg_filename);
+ printf("[PISTORM-DEV] Failed to open file %s for EXTROM mapping. Aborting.\n", tmp_string);
pi_cmd_result = PI_RES_FILENOTFOUND;
} else {
fclose(tmp);
uint32_t addr = (addr_ & 0xFFFF);
switch((addr)) {
+ case PI_CMD_FILESIZE:
+ DEBUG("[PISTORM-DEV] %s read from FILESIZE.\n", op_type_names[type]);
+ if (pi_string[0] == 0 || grab_amiga_string(pi_string[0], (uint8_t *)tmp_string, 255) == -1) {
+ DEBUG("[PISTORM-DEV] Failed to grab string for FILESIZE command. Aborting.\n");
+ pi_cmd_result = PI_RES_FAILED;
+ pi_longword[0] = 0;
+ return 0;
+ } else {
+ FILE *tmp = fopen(tmp_string, "rb");
+ if (tmp == NULL) {
+ DEBUG("[PISTORM-DEV] Failed to open file %s for FILESIZE command. Aborting.\n", tmp_string);
+ pi_longword[0] = 0;
+ pi_cmd_result = PI_RES_FILENOTFOUND;
+ } else {
+ fseek(tmp, 0, SEEK_END);
+ pi_longword[0] = ftell(tmp);
+ DEBUG("[PISTORM-DEV] Returning file size for file %s: %d bytes.\n", tmp_string, pi_longword[0]);
+ fclose(tmp);
+ pi_cmd_result = PI_RES_OK;
+ }
+ }
+ pi_string[0] = 0;
+ return pi_longword[0];
+ break;
+
case PI_CMD_HWREV:
// Probably replace this with some read from the CPLD to get a simple hardware revision.
DEBUG("[PISTORM-DEV] %s Read from HWREV\n", op_type_names[type]);
break;
case PI_CMDRESULT:
- DEBUG("[PISTORM-DEV] %s Read from CMDRESULT\n", op_type_names[type]);
+ DEBUG("[PISTORM-DEV] %s Read from CMDRESULT: %d\n", op_type_names[type], pi_cmd_result);
return pi_cmd_result;
break;
#include "../pistorm-dev-enums.h"
#include "pistorm_dev.h"
+//#define SHUTUP_VSCODE
+
+#ifdef SHUTUP_VSCODE
+#define __stdargs
+#else
#include <exec/resident.h>
#include <exec/errors.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/disk.h>
#include <proto/expansion.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \
printf("Failed to load %s.\n", b); \
return 1; \
- } \
+ }
void print_usage(char *exe);
int get_command(char *cmd);
}
pi_handle_config(cmd_arg, argv[2]);
break;
+ case PI_CMD_TRANSFERFILE:
+ if (argc < 4) {
+ printf ("Please specify a source and destination filename in addition to the command.\n");
+ printf ("Example: %s --transfer platforms/platform.h snakes.h\n", argv[0]);
+ }
+ if (pi_get_filesize(argv[2], &tmpvalue) == PI_RES_FILENOTFOUND) {
+ printf ("File %s not found on the Pi side.\n", argv[2]);
+ } else {
+ unsigned int filesize = tmpvalue;
+ unsigned char *dest = malloc(filesize);
+
+ if (dest == NULL) {
+ printf ("Failed to allocate memory buffer for file. Aborting file transfer.\n");
+ } else {
+ printf ("Found a %d byte file on the Pi side. Eating it.\n", filesize);
+ if (pi_transfer_file(argv[2], dest) != PI_RES_OK) {
+ printf ("Something went horribly wrong during the file transfer.\n");
+ } else {
+ FILE *out = fopen(argv[3], "wb+");
+ if (out == NULL) {
+ printf ("Failed to open output file %s for writing.\n", argv[3]);
+ } else {
+ fwrite(dest, filesize, 1, out);
+ fclose(out);
+ printf ("%d bytes transferred to file %s.\n", filesize, argv[3]);
+ }
+ }
+ free(dest);
+ }
+ }
+ break;
default:
printf ("Unhandled command %s.\n", argv[1]);
return 1;
cmd_arg = PICFG_DEFAULT;
return PI_CMD_SWITCHCONFIG;
}
+ if (strcmp(cmd, "--transfer-file") == 0 || strcmp(cmd, "--transfer") == 0 || strcmp(cmd, "--getfile") == 0) {
+ return PI_CMD_TRANSFERFILE;
+ }
return -1;
}