]> git.sesse.net Git - pistorm/commitdiff
Add PiStorm simple interaction example application
authorbeeanyew <beeanyew@gmail.com>
Fri, 23 Apr 2021 02:44:32 +0000 (04:44 +0200)
committerbeeanyew <beeanyew@gmail.com>
Fri, 23 Apr 2021 02:44:32 +0000 (04:44 +0200)
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/build.sh [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.h [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c [new file with mode: 0644]

diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple
new file mode 100644 (file)
index 0000000..3b8e9a5
Binary files /dev/null and b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple differ
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/build.sh b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/build.sh
new file mode 100644 (file)
index 0000000..f71c6ef
--- /dev/null
@@ -0,0 +1 @@
+m68k-amigaos-gcc pistorm_dev.c simple_interact.c -mregparm -m68020 -O2 -o PiSimple -Wno-unused-parameter -noixemul -DHAS_STDLIB
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c
new file mode 100644 (file)
index 0000000..96a3d4c
--- /dev/null
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: MIT
+
+#include "../pistorm-dev-enums.h"
+
+#include <exec/resident.h>
+#include <exec/errors.h>
+#include <exec/memory.h>
+#include <exec/lists.h>
+#include <exec/alerts.h>
+#include <exec/tasks.h>
+#include <exec/io.h>
+#include <exec/execbase.h>
+
+#include <libraries/expansion.h>
+
+#include <devices/trackdisk.h>
+#include <devices/timer.h>
+#include <devices/scsidisk.h>
+
+#include <dos/filehandler.h>
+
+#include <proto/exec.h>
+#include <proto/disk.h>
+#include <proto/expansion.h>
+
+#include <stdio.h>
+
+unsigned int pistorm_base_addr = 0xFFFFFFFF;
+
+#define WRITESHORT(cmd, val) *(unsigned short *)((unsigned int)(pistorm_base_addr+cmd)) = val;
+#define WRITELONG(cmd, val) *(unsigned int *)((unsigned int)(pistorm_base_addr+cmd)) = val;
+#define WRITEBYTE(cmd, val) *(unsigned char *)((unsigned int)(pistorm_base_addrT+cmd)) = val;
+
+#define READSHORT(cmd, var) var = *(volatile unsigned short *)(pistorm_base_addr + cmd);
+#define READLONG(cmd, var) var = *(volatile unsigned int *)(pistorm_base_addr + cmd);
+#define READBYTE(cmd, var) var = *(volatile unsigned short *)(pistorm_base_addr + cmd);
+
+unsigned int pi_find_pistorm() {
+    unsigned int board_addr = 0xFFFFFFFF;
+    struct ExpansionBase *expansionbase = (struct ExpansionBase *)OpenLibrary("expansion.library", 0L);
+       
+    if (expansionbase == NULL) {
+#ifdef HAS_STDLIB
+           printf("Failed to open expansion.library.\n");
+#endif
+       }
+       else {
+               struct ConfigDev* cd = NULL;
+               cd = (struct ConfigDev*)FindConfigDev(cd, 2011, 0x6B);
+               if (cd != NULL)
+                       board_addr = (unsigned int)cd->cd_BoardAddr;
+        CloseLibrary((struct Library *)expansionbase);
+       }
+    return board_addr;
+}
+
+void pi_reset_amiga(unsigned short reset_code) {
+    WRITESHORT(PI_CMD_RESET, reset_code);
+}
\ No newline at end of file
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.h b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.h
new file mode 100644 (file)
index 0000000..e906030
--- /dev/null
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: MIT
+
+unsigned long pi_find_pistorm();
+
+void pi_reset_amiga(unsigned short reset_code);
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c
new file mode 100644 (file)
index 0000000..271963b
--- /dev/null
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: MIT
+
+#include "../pistorm-dev-enums.h"
+#include "pistorm_dev.h"
+
+#include <exec/resident.h>
+#include <exec/errors.h>
+#include <exec/memory.h>
+#include <exec/lists.h>
+#include <exec/alerts.h>
+#include <exec/tasks.h>
+#include <exec/io.h>
+#include <exec/execbase.h>
+
+#include <libraries/expansion.h>
+
+#include <devices/trackdisk.h>
+#include <devices/timer.h>
+#include <devices/scsidisk.h>
+
+#include <dos/filehandler.h>
+
+#include <proto/exec.h>
+#include <proto/disk.h>
+#include <proto/expansion.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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);
+
+extern unsigned int pistorm_base_addr;
+
+int __stdargs main (int argc, char *argv[]) {
+    if (argc < 2) {
+        print_usage(argv[0]);
+        return 1;
+    }
+    
+    int command = get_command(argv[1]);
+    if (command == -1) {
+        printf("Unknown command %s.\n", argv[1]);
+        return 1;
+    }
+
+    pistorm_base_addr = pi_find_pistorm();
+
+    if (pistorm_base_addr == 0xFFFFFFFF) {
+        printf ("Unable to find PiStorm autoconf device.\n");
+        return 1;
+    }
+    else {
+        printf ("PiStorm autoconf device found at $%.X\n", pistorm_base_addr);
+    }
+
+    unsigned int tmpvalue = 0;
+    unsigned short tmpshort = 0;
+
+    if (tmpvalue) {};
+
+    switch (command) {
+        case PI_CMD_RESET:
+            if (argc >= 3)
+                tmpshort = (unsigned short)atoi(argv[2]);
+            pi_reset_amiga(tmpshort);
+            break;
+        default:
+            printf ("Unhandled command %s.\n", argv[1]);
+            return 1;
+            break;
+    }
+
+    return 0;
+}
+
+int get_command(char *cmd) {
+    if (strcmp(cmd, "--restart") == 0 || strcmp(cmd, "--reboot") || strcmp(cmd, "--reset") == 0) {
+        return PI_CMD_RESET;
+    }
+
+    return -1;
+}
+
+void print_usage(char *exe) {
+    printf ("Usage: %s --[command] (arguments)\n", exe);
+    printf ("Example: %s --restart, --reboot or --reset\n", exe);
+    printf ("         Restarts the Amiga.\n");
+    printf ("         %s --check or --find\n", exe);
+    printf ("         Finds the PiStorm device and prints some data.\n");
+
+    return;
+}