#include <proto/dos.h>
#include <workbench/startup.h>
#include <clib/expansion_protos.h>
+#include <libraries/reqtools.h>
+#include <clib/reqtools_protos.h>
#include "pistorm_dev.h"
#include "../pistorm-dev-enums.h"
#include <stdio.h>
#include <string.h>
-
+#include <stdlib.h>
extern unsigned int pistorm_base_addr;
+struct ReqToolsBase *ReqToolsBase;
-#define VERSION "v0.1"
+#define VERSION "v0.2"
#define button1w 54
#define button1h 20
#define tbox1w 130
#define tbox1h 18
+#define statusbarw 507
+#define statusbarh 10
+
SHORT SharedBordersPairs0[] =
{
0, 0, 0, button1h - 1, 1, button1h - 2, 1, 0, button1w - 2, 0
-1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 0, tbox1w - 1, -1, tbox1w - 1, tbox1h - 1
};
+SHORT SharedBordersPairs8[] =
+{
+ 0, 0, statusbarw - 2, 0, statusbarw - 2, 0, 0, 0, 0, 0
+};
+
+SHORT SharedBordersPairs9[] =
+{
+ 0, 0, 0, tbox1h - 1, 1, tbox1h - 2, 1, 0, tbox1w - 2, 0
+};
+SHORT SharedBordersPairs10[] =
+{
+ 1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 1, tbox1w - 1, 0, 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 *) &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,
+ 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs8[0], NULL, // Statusbar
+ 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs9[0], &SharedBorders[10], // TBox inverted
+ 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs10[0], NULL,
};
struct Border SharedBordersInvert[] =
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,
+ 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs9[0], &SharedBordersInvert[7], // TBox inverted
+ 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs10[0], NULL,
+};
+
+UBYTE DestinationValue_buf[255];
+
+struct IntuiText Destination_text[] =
+{
+ 1, 0, JAM2, -98, 6, NULL, "Destination:", &Destination_text[1],
+ 1, 0, JAM2, 4, 4, NULL, DestinationValue_buf, NULL,
+};
+
+#define GADGETDESTINATION 11
+
+struct Gadget GetDestination =
+{
+ NULL, 108, 117, tbox1w, tbox1h,
+ GADGHIMAGE,
+ RELVERIFY,
+ BOOLGADGET,
+ (APTR) &SharedBorders[9], (APTR) &SharedBordersInvert[6],
+ Destination_text, 0, NULL, GADGETDESTINATION, NULL
+};
+
+struct IntuiText RebootButton_text =
+{
+ 1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Reboot", NULL
+};
+
+#define GADREBOOT 10
+
+struct Gadget RebootButton =
+{
+ &GetDestination, 4, 166, button1w, button1h,
+ GADGHIMAGE,
+ RELVERIFY,
+ BOOLGADGET,
+ (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
+ &RebootButton_text, 0, NULL, GADREBOOT, NULL
+};
+
+UBYTE StatusBar_buf[128] = "PiStorm...";
+
+struct IntuiText StatusBar_text =
+{
+ 1, 0, JAM2, 4, 2, NULL, (UBYTE *)StatusBar_buf, NULL
+};
+
+#define GADSTATUSBAR 9
+
+struct Gadget StatusBar =
+{
+ &RebootButton, 3, 188, 508, 10,
+ GADGHIMAGE,
+ 0,
+ BOOLGADGET,
+ (APTR) &SharedBorders[8], NULL,
+ &StatusBar_text, 0, NULL, GADSTATUSBAR, NULL
+};
+
+
+struct IntuiText RetrieveButton_text =
+{
+ 1, 0, JAM2, 10, 6, NULL, (UBYTE *)"Retrieve", NULL
+};
+
+#define GADRETRIEVEBUTTON 8
+
+struct Gadget RetrieveButton =
+{
+ &StatusBar, 244, 117, button2w, button2h,
+ GADGHIMAGE,
+ RELVERIFY,
+ BOOLGADGET,
+ (APTR) &SharedBorders[4], (APTR) &SharedBordersInvert[4],
+ &RetrieveButton_text, 0, NULL, GADRETRIEVEBUTTON, NULL
+};
+
+UBYTE GetFileValue_buf[255];
+
+struct StringInfo GetFileValue =
+{
+ GetFileValue_buf, NULL, 0, 255, 0, 0, 0, 0, 4, 4, NULL, 0, NULL
+};
+
+struct IntuiText GetFile_text[] =
+{
+ 1, 0, JAM2, -98, -15, NULL, "Get file", &GetFile_text[1],
+ 1, 0, JAM2, -98, 4, NULL, "Source:", NULL,
+};
+
+#define GADGETFILE 7
+
+struct Gadget GetFile =
+{
+ &RetrieveButton, 108, 93, tbox1w, tbox1h,
+ GADGHIMAGE,
+ 0,
+ STRGADGET,
+ (APTR) &SharedBorders[6], NULL,
+ GetFile_text, 0, (APTR)&GetFileValue, GADGETFILE, NULL
};
struct IntuiText ConfigDefault_text =
struct Gadget ConfigDefault =
{
- NULL, 304, 39, button3w, button3h,
+ &GetFile, 304, 39, button3w, button3h,
GADGHIMAGE,
RELVERIFY,
BOOLGADGET,
struct Gadget AboutButton =
{
- &RTGButton, 356, 170, button1w, button1h,
+ &RTGButton, 356, 166, button1w, button1h,
GADGHIMAGE,
RELVERIFY,
BOOLGADGET,
struct Gadget QuitButton =
{
- &AboutButton, 438, 170, button1w, button1h,
+ &AboutButton, 438, 166, button1w, button1h,
GADGHIMAGE,
RELVERIFY,
BOOLGADGET,
}
}
+static char *GetSavePath()
+{
+ struct rtFileRequester *filereq;
+ char filename[128];
+ char *fullpath = malloc(256 * sizeof(char));
+ UBYTE *buf = NULL;
+
+ if ((filereq = (struct rtFileRequester*)rtAllocRequestA (RT_FILEREQ, NULL)))
+ {
+ filename[0] = 0;
+
+ if (!rtFileRequest(filereq, filename, "Pick a destination directory",
+ RTFI_Flags, FREQF_NOFILES, TAG_END))
+ {
+ free(fullpath);
+ return NULL;
+ }
+
+ }
+ else
+ {
+ rtEZRequest("Out of memory!", "Oh no!", NULL, NULL);
+ }
+
+ strncpy(fullpath, (char*)filereq->Dir, 256);
+ return fullpath;
+}
+
+
int main()
{
struct Window *myWindow;
return RETURN_FAIL;
}
+ if (!(ReqToolsBase = (struct ReqToolsBase *)
+ OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION)))
+ {
+ static struct IntuiText pos;
+ struct IntuiText msg[] =
+ {
+ 1, 0, JAM2, 0, 0, NULL, "You need reqtools.library V38 or higher!.", &msg[1],
+ 1, 0, JAM2, 0, 10, NULL, "Please install it in your Libs: drirectory.", NULL,
+ };
+ AutoRequest(NULL, msg, NULL, &pos, 0, 0, 0, 0);
+ return RETURN_FAIL;
+ }
+
pistorm_base_addr = pi_find_pistorm();
myWindow = OpenWindow(&winlayout);
BOOL no_board = FALSE;
pos.IText = "OK";
AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
no_board = TRUE;
+ WriteGadgetText("PiStorm not found", StatusBar_buf, myWindow, &StatusBar);
}
if (!no_board)
{
if (ret == PI_RES_FILENOTFOUND)
{
static struct IntuiText msg, pos;
- msg.IText = "PiStorm says \"file not found\"";
+ msg.IText = "PiStorm says: \"file not found\"";
pos.IText = "OK";
AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
}
pi_handle_config(PICFG_DEFAULT, NULL);
break;
}
+ case GADRETRIEVEBUTTON:
+ {
+ unsigned int filesize = 0;
+ char outpath[128];
+ unsigned char *buf;
+
+ if (pi_get_filesize(GetFileValue_buf, &filesize) == 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;
+ }
+ buf = malloc(filesize);
+ if (buf == NULL)
+ {
+ static struct IntuiText msg, pos;
+ msg.IText = "Could not allocate enough memory to transfer file";
+ pos.IText = "OK";
+ AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
+ break;
+ }
+ WriteGadgetText("Retrieving file...", StatusBar_buf, myWindow, &StatusBar);
+ if (pi_transfer_file(GetFileValue_buf, buf) != PI_RES_OK)
+ {
+ static struct IntuiText msg, pos;
+ msg.IText = "PiStorm says: \"something went wrong with the file transfer\"";
+ pos.IText = "OK";
+ AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
+ WriteGadgetText("File transfer failed", StatusBar_buf, myWindow, &StatusBar);
+ free(buf);
+ break;
+ }
+ char *fname = strrchr(GetFileValue_buf, '/');
+ if (!fname)
+ {
+ fname = GetFileValue_buf;
+ }
+ char *destfile = malloc(256);
+ // Turns out WB doesn't like DF0:/filename.ext
+ if (DestinationValue_buf[(strlen(DestinationValue_buf) - 1)] == ':')
+ {
+ snprintf(destfile, 255, "%s%s", DestinationValue_buf, GetFileValue_buf);
+ }
+ else if (!strlen(DestinationValue_buf))
+ {
+ snprintf(destfile, 255, "%s", GetFileValue_buf);
+ }
+ else
+ {
+ snprintf(destfile, 255, "%s/%s", DestinationValue_buf, GetFileValue_buf);
+ }
+ BPTR fh = Open(destfile, MODE_NEWFILE);
+ if (!fh)
+ {
+ char errbuf[64];
+ snprintf(errbuf, 64, "Error code: %ld", IoErr());
+ struct IntuiText msg[] =
+ {
+ 1, 0, JAM2, 0, 0, NULL, "Could not open file for writing", &msg[1],
+ 1, 0, JAM2, 0, 10, NULL, destfile, &msg[2],
+ 1, 0, JAM2, 0, 20, NULL, (UBYTE*)errbuf, NULL,
+ };
+ static struct IntuiText pos;
+ pos.IText = "OK";
+ AutoRequest(myWindow, msg, NULL, &pos, 0, 0, 0, 0);
+ WriteGadgetText("File transfer failed", StatusBar_buf, myWindow, &StatusBar);
+ free(buf);
+ free(destfile);
+ break;
+ }
+ Write(fh, buf, filesize);
+ Close(fh);
+ free(destfile);
+ WriteGadgetText("File transfer complete", StatusBar_buf, myWindow, &StatusBar);
+ free(buf);
+ break;
+ }
+ case GADREBOOT:
+ {
+ WriteGadgetText("Rebooting PiStorm", StatusBar_buf, myWindow, &StatusBar);
+ pi_reset_amiga(0);
+ break;
+ }
+ case GADGETDESTINATION:
+ {
+ char *fileName = GetSavePath();
+ if (fileName)
+ {
+ WriteGadgetText(fileName, DestinationValue_buf, myWindow, &GetDestination);
+ free(fileName);
+ }
+ }
}
}
if (closewin)
}
};
if (myWindow) CloseWindow(myWindow);
+ CloseLibrary((struct Library*)ReqToolsBase);
return 0;
}