]> git.sesse.net Git - pistorm/blob - platforms/amiga/pistorm-dev/pistorm_dev_amiga/simple_interact.c
Add not-so-simple config switching from Amiga side
[pistorm] / platforms / amiga / pistorm-dev / pistorm_dev_amiga / simple_interact.c
1 // SPDX-License-Identifier: MIT
2
3 #include "../pistorm-dev-enums.h"
4 #include "pistorm_dev.h"
5
6 #include <exec/resident.h>
7 #include <exec/errors.h>
8 #include <exec/memory.h>
9 #include <exec/lists.h>
10 #include <exec/alerts.h>
11 #include <exec/tasks.h>
12 #include <exec/io.h>
13 #include <exec/execbase.h>
14
15 #include <libraries/expansion.h>
16
17 #include <devices/trackdisk.h>
18 #include <devices/timer.h>
19 #include <devices/scsidisk.h>
20
21 #include <dos/filehandler.h>
22
23 #include <proto/exec.h>
24 #include <proto/disk.h>
25 #include <proto/expansion.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \
32     printf("Failed to load %s.\n", b); \
33     return 1; \
34   } \
35
36 void print_usage(char *exe);
37 int get_command(char *cmd);
38
39 extern unsigned int pistorm_base_addr;
40
41 unsigned short cmd_arg = 0;
42
43 int __stdargs main (int argc, char *argv[]) {
44     if (argc < 2) {
45         print_usage(argv[0]);
46         return 1;
47     }
48     
49     int command = get_command(argv[1]);
50     if (command == -1) {
51         printf("Unknown command %s.\n", argv[1]);
52         return 1;
53     }
54
55     pistorm_base_addr = pi_find_pistorm();
56
57     if (pistorm_base_addr == 0xFFFFFFFF) {
58         printf ("Unable to find PiStorm autoconf device.\n");
59         return 1;
60     }
61     else {
62         printf ("PiStorm autoconf device found at $%.X\n", pistorm_base_addr);
63     }
64
65     unsigned int tmpvalue = 0;
66     unsigned short tmpshort = 0;
67
68     if (tmpvalue) {};
69
70     switch (command) {
71         case PI_CMD_RESET:
72             if (argc >= 3)
73                 tmpshort = (unsigned short)atoi(argv[2]);
74             pi_reset_amiga(tmpshort);
75             break;
76         case PI_CMD_SWREV:
77             printf ("PiStorm ----------------------------\n");
78             printf ("Hardware revision: %d.%d\n", (pi_get_hw_rev() >> 8), (pi_get_hw_rev() & 0xFF));
79             printf ("Software revision: %d.%d\n", (pi_get_sw_rev() >> 8), (pi_get_sw_rev() & 0xFF));
80             printf ("RTG: %s - %s\n", (pi_get_rtg_status() & 0x01) ? "Enabled" : "Disabled", (pi_get_rtg_status() & 0x02) ? "In use" : "Not in use");
81             printf ("NET: %s\n", pi_get_net_status() ? "Enabled" : "Disabled");
82             break;
83         case PI_CMD_SWITCHCONFIG:
84             if (cmd_arg == PICFG_LOAD) {
85                 if (argc < 3) {
86                     printf ("User asked to load config, but no config filename specified.\n");
87                 }
88             }
89             pi_handle_config(cmd_arg, argv[2]);
90             break;
91         default:
92             printf ("Unhandled command %s.\n", argv[1]);
93             return 1;
94             break;
95     }
96
97     return 0;
98 }
99
100 int get_command(char *cmd) {
101     if (strcmp(cmd, "--restart") == 0 || strcmp(cmd, "--reboot") == 0 || strcmp(cmd, "--reset") == 0) {
102         return PI_CMD_RESET;
103     }
104     if (strcmp(cmd, "--check") == 0 || strcmp(cmd, "--find") == 0 || strcmp(cmd, "--info") == 0) {
105         return PI_CMD_SWREV;
106     }
107     if (strcmp(cmd, "--config") == 0 || strcmp(cmd, "--config-file") == 0 || strcmp(cmd, "--cfg") == 0) {
108         cmd_arg = PICFG_LOAD;
109         return PI_CMD_SWITCHCONFIG;
110     }
111
112     return -1;
113 }
114
115 void print_usage(char *exe) {
116     printf ("Usage: %s --[command] (arguments)\n", exe);
117     printf ("Example: %s --restart, --reboot or --reset\n", exe);
118     printf ("         Restarts the Amiga.\n");
119     printf ("         %s --check, --find or --info\n", exe);
120     printf ("         Finds the PiStorm device and prints some data.\n");
121
122     return;
123 }