1 // SPDX-License-Identifier: MIT
3 #include <proto/intuition.h>
5 #include <intuition/intuition.h>
6 #include <proto/exec.h>
8 #include <workbench/startup.h>
9 #include <clib/expansion_protos.h>
11 #include "pistorm_dev.h"
12 #include "../pistorm-dev-enums.h"
17 extern unsigned int pistorm_base_addr;
19 #define VERSION "v0.1"
33 SHORT SharedBordersPairs0[] =
35 0, 0, 0, button1h - 1, 1, button1h - 2, 1, 0, button1w - 2, 0
37 SHORT SharedBordersPairs1[] =
39 1, button1h - 1, button1w - 2, button1h - 1, button1w - 2, 1, button1w - 1, 0, button1w - 1, button1h - 1
42 SHORT SharedBordersPairs2[] =
44 0, 0, 0, button3h - 1, 1, button3h - 2, 1, 0, button3w - 2, 0
46 SHORT SharedBordersPairs3[] =
48 1, button3h - 1, button3w - 2, button3h - 1, button3w - 2, 1, button3w - 1, 0, button3w - 1, button3h - 1
51 SHORT SharedBordersPairs4[] =
53 0, 0, 0, button2h - 1, 1, button2h - 2, 1, 0, button2w - 2, 0
55 SHORT SharedBordersPairs5[] =
57 1, button2h - 1, button2w - 2, button2h - 1, button2w - 2, 1, button2w - 1, 0, button2w - 1, button2h - 1
60 SHORT SharedBordersPairs6[] =
62 -2, -1, -2, tbox1h - 1, -1, tbox1h - 2, -1, -1, tbox1w - 2, -1
65 SHORT SharedBordersPairs7[] =
67 -1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 0, tbox1w - 1, -1, tbox1w - 1, tbox1h - 1
70 struct Border SharedBorders[] =
72 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBorders[1], // Button 1
73 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
74 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBorders[3], // Button 3
75 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
76 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBorders[5], // Button 2
77 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
78 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs6[0], &SharedBorders[7], // TBox
79 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs7[0], NULL,
82 struct Border SharedBordersInvert[] =
84 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBordersInvert[1], // Button 1
85 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
86 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBordersInvert[3], // Button 3
87 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
88 0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBordersInvert[5], // Button 2
89 0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
92 struct IntuiText ConfigDefault_text =
94 1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Load Default", NULL
97 #define GADCONFIGDEFAULT 6
99 struct Gadget ConfigDefault =
101 NULL, 304, 39, button3w, button3h,
105 (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
106 &ConfigDefault_text, 0, NULL, GADCONFIGDEFAULT, NULL
109 struct IntuiText ConfigCommit_text =
111 1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Commit", NULL
114 #define GADCONFIGCOMMIT 5
116 struct Gadget ConfigCommit =
118 &ConfigDefault, 244, 39, button1w, button1h,
122 (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
123 &ConfigCommit_text, 0, NULL, GADCONFIGCOMMIT, NULL
127 UBYTE ConfigFileValue_buf[255];
129 struct StringInfo ConfigFileValue =
131 ConfigFileValue_buf, NULL, 0, 255, 0, 0, 0, 0, 4, 4, NULL, 0, NULL
134 struct IntuiText ConfigFile_text =
136 1, 0, JAM2, -98, 4, NULL, "Config file:", NULL
139 #define GADCONFIGFILE 4
141 struct Gadget ConfigFile =
143 &ConfigCommit, 108, 41, tbox1w, tbox1h,
147 (APTR) &SharedBorders[6], NULL,
148 &ConfigFile_text, 0, (APTR)&ConfigFileValue, GADCONFIGFILE, NULL
151 UBYTE RTGStatus_buf[64] = "RTG status";
153 struct IntuiText RTGStatus_text =
155 1, 0, JAM2, 4, 4, NULL, (UBYTE *)RTGStatus_buf, NULL
158 #define GADRTGSTATUS 3
160 struct Gadget RTGStatus =
162 &ConfigFile, 14, 15, tbox1w, tbox1h,
166 (APTR) &SharedBorders[6], NULL,
167 &RTGStatus_text, 0, NULL, GADRTGSTATUS, NULL
170 UBYTE RTG_buf[64] = "RTG Enable";
172 struct IntuiText RTG_text =
174 1, 0, JAM2, 8, 6, NULL, (UBYTE *)RTG_buf, NULL
177 #define GADRTGBUTTON 2
179 struct Gadget RTGButton =
181 &RTGStatus, 150, 13, button3w, button3h,
185 (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
186 &RTG_text, 0, NULL, GADRTGBUTTON, NULL
189 struct IntuiText AboutButton_text =
191 1, 0, JAM2, 8, 6, NULL, (UBYTE *)"About", NULL
196 struct Gadget AboutButton =
198 &RTGButton, 356, 170, button1w, button1h,
202 (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
203 &AboutButton_text, 0, NULL, GADABOUT, NULL
207 struct IntuiText QuitButton_text =
209 1, 0, JAM2, 12, 6, NULL, (UBYTE *)"Quit", NULL
214 struct Gadget QuitButton =
216 &AboutButton, 438, 170, button1w, button1h,
220 (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
221 &QuitButton_text, 0, NULL, GADQUIT, NULL
225 struct NewWindow winlayout =
230 CLOSEWINDOW | GADGETUP | GADGETDOWN,
231 ACTIVATE | WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH,
233 (STRPTR)"PiStorm Interaction Tool",
240 // Pads what we are writing to screen with spaces, otherwise we get bits of
241 // old text still showing
242 static void WriteGadgetText(const char *text, UBYTE *buffer, struct Window *window, struct Gadget *gadget)
244 ULONG newlen = strlen(text);
245 ULONG oldlen = strlen((char *)buffer);
249 snprintf((char *)buffer, 64, "%s%*.*s", text, (int)(oldlen - newlen),
250 (int)(oldlen - newlen), " ");
254 strncpy((char *)buffer, text, 64);
257 RefreshGadgets(gadget, window, NULL);
259 static void updateRTG(struct Window *window)
261 unsigned short rtg = pi_get_rtg_status();
264 WriteGadgetText("Disable RTG", RTG_buf, window, &RTGButton);
267 WriteGadgetText("RTG in use", RTGStatus_buf, window, &RTGStatus);
271 WriteGadgetText("RTG not in use", RTGStatus_buf, window, &RTGStatus);
276 WriteGadgetText("Enable RTG", RTG_buf, window, &RTGButton);
277 WriteGadgetText("RTG disabled", RTGStatus_buf, window, &RTGStatus);
283 struct Window *myWindow;
285 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
286 if (IntuitionBase == NULL)
291 pistorm_base_addr = pi_find_pistorm();
292 myWindow = OpenWindow(&winlayout);
293 BOOL no_board = FALSE;
295 if (pistorm_base_addr == 0xFFFFFFFF)
297 static struct IntuiText msg, pos;
298 msg.IText = "Unable to find PiStorm autoconf device.";
300 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
310 BOOL closewin = FALSE;
311 struct IntuiMessage *message;
312 Wait(1 << myWindow->UserPort->mp_SigBit);
314 while ((message = (struct IntuiMessage*)GetMsg(myWindow->UserPort)))
316 ULONG class = message->Class;
317 struct Gadget *address = (struct Gadget*)message->IAddress;
318 ReplyMsg((struct Message*)message);
320 if (class == CLOSEWINDOW)
324 else if (class == GADGETUP)
326 if (no_board && (address->GadgetID != GADQUIT) && (address->GadgetID != GADABOUT))
330 switch (address->GadgetID)
337 static struct IntuiText pos;
338 UBYTE buf[64], buf2[64], buf3[64];
341 unsigned short hw_rev = pi_get_hw_rev();
342 unsigned short sw_rev = pi_get_sw_rev();
343 snprintf((char*)buf2, 64, "PiStorm hardware: %d.%d", (hw_rev >> 8), (hw_rev & 0xFF));
344 snprintf((char*)buf3, 64, "PiStorm software: %d.%d", (sw_rev >> 8), (sw_rev & 0xFF));
348 snprintf((char*)buf2, 64, "PiStorm hardware not found!");
350 struct IntuiText msg[] =
352 1, 0, JAM2, 0, 0, NULL, (UBYTE *)buf, &msg[1],
353 1, 0, JAM2, 0, 10, NULL, "Tool written by beeanyew and LinuxJedi", &msg[2],
354 1, 0, JAM2, 0, 20, NULL, (UBYTE*)buf2, &msg[3],
355 1, 0, JAM2, 0, 30, NULL, (UBYTE*)buf3, &msg[4],
356 1, 0, JAM2, 0, 50, NULL, "Now with 53% more Nibbles!", NULL,
358 snprintf(buf, 64, "PiStorm Interaction Tool %s", VERSION);
360 AutoRequest(myWindow, msg, NULL, &pos, 0, 0, 0, 0);
365 unsigned short rtgStatus = pi_get_rtg_status() & 0x01;
366 pi_enable_rtg(!rtgStatus);
370 case GADCONFIGCOMMIT:
372 unsigned short ret = pi_handle_config(PICFG_LOAD, ConfigFileValue_buf);
373 if (ret == PI_RES_FILENOTFOUND)
375 static struct IntuiText msg, pos;
376 msg.IText = "PiStorm says \"file not found\"";
378 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
382 case GADCONFIGDEFAULT:
384 pi_handle_config(PICFG_DEFAULT, NULL);
399 if (myWindow) CloseWindow(myWindow);