]> git.sesse.net Git - pistorm/commitdiff
Initial alpha of the PiStorm GUI tool
authorAndrew Hutchings <andrew@linuxjedi.co.uk>
Sun, 25 Apr 2021 07:05:31 +0000 (08:05 +0100)
committerAndrew Hutchings <andrew@linuxjedi.co.uk>
Sun, 25 Apr 2021 07:10:57 +0000 (08:10 +0100)
It can only change the config file and enable/disable RTG right now, but
it a framework for adding more things in the future.

Some of the CLI tool code was slightly modified for VBCC compatibility,
most importantly, some macros that didn't work were expanded and some
includes were changed.

platforms/amiga/pistorm-dev/pistorm_dev_amiga/Makefile [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple [changed mode: 0644->0755]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm [new file with mode: 0755]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm.info [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/README.md [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/gui_interact.c [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.h
platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c

diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/Makefile b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/Makefile
new file mode 100644 (file)
index 0000000..ae0465a
--- /dev/null
@@ -0,0 +1,12 @@
+CC=vc +kick13
+CFLAGS=-c99 -DNDEBUG -lamiga -lauto
+
+all: PiSimple PiStorm
+
+PiSimple: simple_interact.c pistorm_dev.c
+       $(CC) $(CFLAGS) $^ -o PiSimple
+
+PiStorm: gui_interact.c pistorm_dev.c
+       $(CC) $(CFLAGS) $^ -o PiStorm
+
+
old mode 100644 (file)
new mode 100755 (executable)
index 9cc89dc..3bb3155
Binary files a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple and b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple differ
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm
new file mode 100755 (executable)
index 0000000..a2de33b
Binary files /dev/null and b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm differ
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm.info b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm.info
new file mode 100644 (file)
index 0000000..9c216f2
Binary files /dev/null and b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiStorm.info differ
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/README.md b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/README.md
new file mode 100644 (file)
index 0000000..c602ecc
--- /dev/null
@@ -0,0 +1,25 @@
+# PiStorm Interaction Tool
+
+## Cross-Compiling
+
+Compiling the tool requires VBCC setup with the kickstart 1.3 libraries. For information on how to set this up in Linux please see https://linuxjedi.co.uk/2021/02/27/using-vbcc-as-an-amiga-cross-compiler-in-linux/
+
+Once you have the tooling setup, just run `make`.
+
+## Tools
+
+### PiSimple
+
+PiSimple is a command line tool to interact with PiStorm. Running it without any parameters will give you detailed usage information for the tool.
+
+### PiStorm
+
+The PiStorm tool is a GUI tool that implements the same interaction API as the command line tool. It is compatible with Workbench 1.3 onwards.
+
+#### RTG
+
+You can enable / disable RTG on-the-fly with the "Enable/Disable RTG" button. This will have a status next to it which indicates the current state of the RTG.
+
+### Config file
+
+It is possible to switch the configuration file PiStorm is using. You can either type a name for the config file relative to the PiStorm's execution directory and hit "Commit" or hit "Load Default". If the config file is valid the PiStorm will load it in and the Amiga will immediately reboot.
diff --git a/platforms/amiga/pistorm-dev/pistorm_dev_amiga/gui_interact.c b/platforms/amiga/pistorm-dev/pistorm_dev_amiga/gui_interact.c
new file mode 100644 (file)
index 0000000..f698c90
--- /dev/null
@@ -0,0 +1,401 @@
+// SPDX-License-Identifier: MIT
+
+#include <proto/intuition.h>
+#include <proto/dos.h>
+#include <intuition/intuition.h>
+#include <proto/exec.h>
+#include <proto/dos.h>
+#include <workbench/startup.h>
+#include <clib/expansion_protos.h>
+
+#include "pistorm_dev.h"
+#include "../pistorm-dev-enums.h"
+
+#include <stdio.h>
+#include <string.h>
+
+extern unsigned int pistorm_base_addr;
+
+#define VERSION "v0.1"
+
+#define button1w 54
+#define button1h 20
+
+#define button2w 87
+#define button2h 20
+
+#define button3w 100
+#define button3h 20
+
+#define tbox1w 130
+#define tbox1h 18
+
+SHORT SharedBordersPairs0[] =
+{
+    0, 0, 0, button1h - 1, 1, button1h - 2, 1, 0, button1w - 2, 0
+};
+SHORT SharedBordersPairs1[] =
+{
+    1, button1h - 1, button1w - 2, button1h - 1, button1w - 2, 1, button1w - 1, 0, button1w - 1, button1h - 1
+};
+
+SHORT SharedBordersPairs2[] =
+{
+    0, 0, 0, button3h - 1, 1, button3h - 2, 1, 0, button3w - 2, 0
+};
+SHORT SharedBordersPairs3[] =
+{
+    1, button3h - 1, button3w - 2, button3h - 1, button3w - 2, 1, button3w - 1, 0, button3w - 1, button3h - 1
+};
+
+SHORT SharedBordersPairs4[] =
+{
+    0, 0, 0, button2h - 1, 1, button2h - 2, 1, 0, button2w - 2, 0
+};
+SHORT SharedBordersPairs5[] =
+{
+    1, button2h - 1, button2w - 2, button2h - 1, button2w - 2, 1, button2w - 1, 0, button2w - 1, button2h - 1
+};
+
+SHORT SharedBordersPairs6[] =
+{
+    -2, -1, -2, tbox1h - 1, -1, tbox1h - 2, -1, -1, tbox1w - 2, -1
+};
+
+SHORT SharedBordersPairs7[] =
+{
+    -1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 0, tbox1w - 1, -1, tbox1w - 1, tbox1h - 1
+};
+
+struct Border SharedBorders[] =
+{
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBorders[1], // Button 1
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBorders[3], // Button 3
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBorders[5], // Button 2
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs6[0], &SharedBorders[7], // TBox
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs7[0], NULL,
+};
+
+struct Border SharedBordersInvert[] =
+{
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBordersInvert[1], // Button 1
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBordersInvert[3], // Button 3
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
+    0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBordersInvert[5], // Button 2
+    0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
+};
+
+struct IntuiText ConfigDefault_text =
+{
+    1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Load Default", NULL
+};
+
+#define GADCONFIGDEFAULT 6
+
+struct Gadget ConfigDefault =
+{
+    NULL, 304, 39, button3w, button3h,
+    GADGHIMAGE,
+    RELVERIFY,
+    BOOLGADGET,
+    (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
+    &ConfigDefault_text, 0, NULL, GADCONFIGDEFAULT, NULL
+};
+
+struct IntuiText ConfigCommit_text =
+{
+    1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Commit", NULL
+};
+
+#define GADCONFIGCOMMIT 5
+
+struct Gadget ConfigCommit =
+{
+    &ConfigDefault, 244, 39, button1w, button1h,
+    GADGHIMAGE,
+    RELVERIFY,
+    BOOLGADGET,
+    (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
+    &ConfigCommit_text, 0, NULL, GADCONFIGCOMMIT, NULL
+};
+
+
+UBYTE ConfigFileValue_buf[255];
+
+struct StringInfo ConfigFileValue =
+{
+    ConfigFileValue_buf, NULL, 0, 255, 0, 0, 0, 0, 4, 4, NULL, 0, NULL
+};
+
+struct IntuiText ConfigFile_text =
+{
+    1, 0, JAM2, -98, 4, NULL, "Config file:", NULL
+};
+
+#define GADCONFIGFILE 4
+
+struct Gadget ConfigFile =
+{
+    &ConfigCommit, 108, 41, tbox1w, tbox1h,
+    GADGHIMAGE,
+    0,
+    STRGADGET,
+    (APTR) &SharedBorders[6], NULL,
+    &ConfigFile_text, 0, (APTR)&ConfigFileValue, GADCONFIGFILE, NULL
+};
+
+UBYTE RTGStatus_buf[64] = "RTG status";
+
+struct IntuiText RTGStatus_text =
+{
+    1, 0, JAM2, 4, 4, NULL, (UBYTE *)RTGStatus_buf, NULL
+};
+
+#define GADRTGSTATUS 3
+
+struct Gadget RTGStatus =
+{
+    &ConfigFile, 14, 15, tbox1w, tbox1h,
+    GADGHIMAGE,
+    0,
+    BOOLGADGET,
+    (APTR) &SharedBorders[6], NULL,
+    &RTGStatus_text, 0, NULL, GADRTGSTATUS, NULL
+};
+
+UBYTE RTG_buf[64] = "RTG Enable";
+
+struct IntuiText RTG_text =
+{
+    1, 0, JAM2, 8, 6, NULL, (UBYTE *)RTG_buf, NULL
+};
+
+#define GADRTGBUTTON 2
+
+struct Gadget RTGButton =
+{
+    &RTGStatus, 150, 13, button3w, button3h,
+    GADGHIMAGE,
+    RELVERIFY,
+    BOOLGADGET,
+    (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
+    &RTG_text, 0, NULL, GADRTGBUTTON, NULL
+};
+
+struct IntuiText AboutButton_text =
+{
+    1, 0, JAM2, 8, 6, NULL, (UBYTE *)"About", NULL
+};
+
+#define GADABOUT 1
+
+struct Gadget AboutButton =
+{
+    &RTGButton, 356, 170, button1w, button1h,
+    GADGHIMAGE,
+    RELVERIFY,
+    BOOLGADGET,
+    (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
+    &AboutButton_text, 0, NULL, GADABOUT, NULL
+};
+
+
+struct IntuiText QuitButton_text =
+{
+    1, 0, JAM2, 12, 6, NULL, (UBYTE *)"Quit", NULL
+};
+
+#define GADQUIT 0
+
+struct Gadget QuitButton =
+{
+    &AboutButton, 438, 170, button1w, button1h,
+    GADGHIMAGE,
+    RELVERIFY,
+    BOOLGADGET,
+    (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
+    &QuitButton_text, 0, NULL, GADQUIT, NULL
+};
+
+
+struct NewWindow winlayout =
+{
+    20, 20,
+    512, 200,
+    -1, -1,
+    CLOSEWINDOW | GADGETUP | GADGETDOWN,
+    ACTIVATE | WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH,
+    &QuitButton, NULL,
+    (STRPTR)"PiStorm Interaction Tool",
+    NULL, NULL,
+    0, 0,
+    600, 400,
+    WBENCHSCREEN
+};
+
+// Pads what we are writing to screen with spaces, otherwise we get bits of
+// old text still showing
+static void WriteGadgetText(const char *text, UBYTE *buffer, struct Window *window, struct Gadget *gadget)
+{
+    ULONG newlen = strlen(text);
+    ULONG oldlen = strlen((char *)buffer);
+
+    if (newlen < oldlen)
+    {
+        snprintf((char *)buffer, 64, "%s%*.*s", text, (int)(oldlen - newlen),
+                 (int)(oldlen - newlen), " ");
+    }
+    else
+    {
+        strncpy((char *)buffer, text, 64);
+    }
+
+    RefreshGadgets(gadget, window, NULL);
+}
+static void updateRTG(struct Window *window)
+{
+    unsigned short rtg = pi_get_rtg_status();
+    if (rtg & 0x01)
+    {
+        WriteGadgetText("Disable RTG", RTG_buf, window, &RTGButton);
+        if (rtg & 0x02)
+        {
+            WriteGadgetText("RTG in use", RTGStatus_buf, window, &RTGStatus);
+        }
+        else
+        {
+            WriteGadgetText("RTG not in use", RTGStatus_buf, window, &RTGStatus);
+        }
+    }
+    else
+    {
+        WriteGadgetText("Enable RTG", RTG_buf, window, &RTGButton);
+        WriteGadgetText("RTG disabled", RTGStatus_buf, window, &RTGStatus);
+    }
+}
+
+int main()
+{
+    struct Window *myWindow;
+
+    IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
+    if (IntuitionBase == NULL)
+    {
+        return RETURN_FAIL;
+    }
+
+    pistorm_base_addr = pi_find_pistorm();
+    myWindow = OpenWindow(&winlayout);
+    BOOL no_board = FALSE;
+
+    if (pistorm_base_addr == 0xFFFFFFFF)
+    {
+        static struct IntuiText msg, pos;
+        msg.IText = "Unable to find PiStorm autoconf device.";
+        pos.IText = "OK";
+        AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
+        no_board = TRUE;
+    }
+    if (!no_board)
+    {
+        updateRTG(myWindow);
+    }
+
+    FOREVER
+    {
+        BOOL closewin = FALSE;
+        struct IntuiMessage *message;
+        Wait(1 << myWindow->UserPort->mp_SigBit);
+
+        while ((message = (struct IntuiMessage*)GetMsg(myWindow->UserPort)))
+        {
+            ULONG class = message->Class;
+            struct Gadget *address = (struct Gadget*)message->IAddress;
+            ReplyMsg((struct Message*)message);
+
+            if (class == CLOSEWINDOW)
+            {
+                closewin = TRUE;
+            }
+            else if (class == GADGETUP)
+            {
+                if (no_board && (address->GadgetID != GADQUIT) && (address->GadgetID != GADABOUT))
+                {
+                    continue;
+                }
+                switch (address->GadgetID)
+                {
+                    case GADQUIT:
+                        closewin = TRUE;
+                        break;
+                    case GADABOUT:
+                        {
+                            static struct IntuiText pos;
+                            UBYTE buf[64], buf2[64], buf3[64];
+                            if (!no_board)
+                            {
+                                unsigned short hw_rev = pi_get_hw_rev();
+                                unsigned short sw_rev = pi_get_sw_rev();
+                                snprintf((char*)buf2, 64, "PiStorm hardware: %d.%d", (hw_rev >> 8), (hw_rev & 0xFF));
+                                snprintf((char*)buf3, 64, "PiStorm software: %d.%d", (sw_rev >> 8), (sw_rev & 0xFF));
+                            }
+                            else
+                            {
+                                snprintf((char*)buf2, 64, "PiStorm hardware not found!");
+                            }
+                            struct IntuiText msg[] =
+                            {
+                                1, 0, JAM2, 0, 0, NULL, (UBYTE *)buf, &msg[1],
+                                1, 0, JAM2, 0, 10, NULL, "Tool written by beeanyew and LinuxJedi", &msg[2],
+                                1, 0, JAM2, 0, 20, NULL, (UBYTE*)buf2, &msg[3],
+                                1, 0, JAM2, 0, 30, NULL, (UBYTE*)buf3, &msg[4],
+                                1, 0, JAM2, 0, 50, NULL, "Now with 53% more Nibbles!", NULL,
+                            };
+                            snprintf(buf, 64, "PiStorm Interaction Tool %s", VERSION);
+                            pos.IText = "OK";
+                            AutoRequest(myWindow, msg, NULL, &pos, 0, 0, 0, 0);
+                            break;
+                        }
+                    case GADRTGBUTTON:
+                        {
+                            unsigned short rtgStatus = pi_get_rtg_status() & 0x01;
+                            pi_enable_rtg(!rtgStatus);
+                            updateRTG(myWindow);
+                            break;
+                        }
+                    case GADCONFIGCOMMIT:
+                        {
+                            unsigned short ret = pi_handle_config(PICFG_LOAD, ConfigFileValue_buf);
+                            if (ret == PI_RES_FILENOTFOUND)
+                            {
+                                static struct IntuiText msg, pos;
+                                msg.IText = "PiStorm says \"file not found\"";
+                                pos.IText = "OK";
+                                AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
+                            }
+                            break;
+                        }
+                    case GADCONFIGDEFAULT:
+                        {
+                            pi_handle_config(PICFG_DEFAULT, NULL);
+                            break;
+                        }
+                }
+            }
+            if (closewin)
+            {
+                break;
+            }
+        }
+        if (closewin)
+        {
+            break;
+        }
+    };
+    if (myWindow) CloseWindow(myWindow);
+    return 0;
+}
index 8bf004e1c0c073097a61e044642f1d023ece8909..58cf5bdac52c5756398a4338dbdf0b906a088b38 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "../pistorm-dev-enums.h"
 
+#include <exec/types.h>
 #include <exec/resident.h>
 #include <exec/errors.h>
 #include <exec/memory.h>
 #include <devices/timer.h>
 #include <devices/scsidisk.h>
 
-#include <dos/filehandler.h>
+#include <libraries/filehandler.h>
 
 #include <proto/exec.h>
 #include <proto/disk.h>
-#include <proto/expansion.h>
+#include <clib/expansion_protos.h>
 
 #ifdef HAS_STDLIB
 #include <stdio.h>
@@ -165,14 +166,19 @@ unsigned short pi_handle_config(unsigned char cmd, char *str) {
        RETURN_CMDRES;
 }
 
-// Generic stuff
-#define SIMPLEWRITE_SHORT(a, b) \
-    void a(unsigned short val) { WRITESHORT(b, val); }
-
 // Simple feature status write functions
-SIMPLEWRITE_SHORT(pi_enable_rtg, PI_CMD_RTGSTATUS);
-SIMPLEWRITE_SHORT(pi_enable_net, PI_CMD_NETSTATUS);
-SIMPLEWRITE_SHORT(pi_enable_piscsi, PI_CMD_RTGSTATUS);
+void pi_enable_rtg(unsigned short val)
+{
+    WRITESHORT(PI_CMD_RTGSTATUS, val);
+}
+void pi_enable_net(unsigned short val)
+{
+    WRITESHORT(PI_CMD_NETSTATUS, val);
+}
+void pi_enable_piscsi(unsigned short val)
+{
+    WRITESHORT(PI_CMD_PISCSI_CTRL, val);
+}
 
 // Generic feature status setting function.
 // Example: pi_set_feature_status(PI_CMD_RTGSTATUS, 1) to enable RTG
@@ -185,9 +191,33 @@ void pi_set_feature_status(unsigned short cmd, unsigned char value) {
     unsigned short a() { READSHORT(b, short_val); return short_val; }
 
 // Simple feature status read functions
-SIMPLEREAD_SHORT(pi_get_hw_rev, PI_CMD_HWREV);
-SIMPLEREAD_SHORT(pi_get_sw_rev, PI_CMD_SWREV);
-SIMPLEREAD_SHORT(pi_get_rtg_status, PI_CMD_RTGSTATUS);
-SIMPLEREAD_SHORT(pi_get_net_status, PI_CMD_NETSTATUS);
-SIMPLEREAD_SHORT(pi_get_piscsi_status, PI_CMD_PISCSI_CTRL);
-SIMPLEREAD_SHORT(pi_get_cmd_result, PI_CMDRESULT);
+unsigned short pi_get_hw_rev()
+{
+    READSHORT(PI_CMD_HWREV, short_val);
+    return short_val;
+}
+unsigned short pi_get_sw_rev()
+{
+    READSHORT(PI_CMD_SWREV, short_val);
+    return short_val;
+}
+unsigned short pi_get_rtg_status()
+{
+    READSHORT(PI_CMD_RTGSTATUS, short_val);
+    return short_val;
+}
+unsigned short pi_get_net_status()
+{
+    READSHORT(PI_CMD_NETSTATUS, short_val);
+    return short_val;
+}
+unsigned short pi_get_piscsi_status()
+{
+    READSHORT(PI_CMD_PISCSI_CTRL, short_val);
+    return short_val;
+}
+unsigned short pi_get_cmd_result()
+{
+    READSHORT(PI_CMDRESULT, short_val);
+    return short_val;
+}
index 6de33b0b0ba673f6e558028cd201c96e1935121b..a8f49938fc53f3b3f4e340a670a340af9e4fe1c8 100644 (file)
@@ -8,9 +8,9 @@ unsigned short pi_get_net_status();
 unsigned short pi_get_rtg_status();
 unsigned short pi_get_piscsi_status();
 
-void enable_rtg(unsigned short val);
-void enable_net(unsigned short val);
-void enable_piscsi(unsigned short val);
+void pi_enable_rtg(unsigned short val);
+void pi_enable_net(unsigned short val);
+void pi_enable_piscsi(unsigned short val);
 
 void pi_reset_amiga(unsigned short reset_code);
 unsigned short pi_handle_config(unsigned char cmd, char *str);
index b9ea1a919180dade02f67285b53f3cc24f9e65da..969cebf11598913f1b83bb78119997ddb4915622 100644 (file)
@@ -8,6 +8,7 @@
 #ifdef SHUTUP_VSCODE
 #define __stdargs
 #else
+#include <exec/types.h>
 #include <exec/resident.h>
 #include <exec/errors.h>
 #include <exec/memory.h>
@@ -23,7 +24,7 @@
 #include <devices/timer.h>
 #include <devices/scsidisk.h>
 
-#include <dos/filehandler.h>
+#include <libraries/filehandler.h>
 
 #include <proto/exec.h>
 #include <proto/disk.h>