mirror of
https://github.com/captain-amygdala/pistorm.git
synced 2026-02-19 13:55:17 +00:00
Add PiStorm simple interaction example application
This commit is contained in:
BIN
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple
Normal file
BIN
platforms/amiga/pistorm-dev/pistorm_dev_amiga/PiSimple
Normal file
Binary file not shown.
1
platforms/amiga/pistorm-dev/pistorm_dev_amiga/build.sh
Normal file
1
platforms/amiga/pistorm-dev/pistorm_dev_amiga/build.sh
Normal file
@@ -0,0 +1 @@
|
||||
m68k-amigaos-gcc pistorm_dev.c simple_interact.c -mregparm -m68020 -O2 -o PiSimple -Wno-unused-parameter -noixemul -DHAS_STDLIB
|
||||
59
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c
Normal file
59
platforms/amiga/pistorm-dev/pistorm_dev_amiga/pistorm_dev.c
Normal file
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
unsigned long pi_find_pistorm();
|
||||
|
||||
void pi_reset_amiga(unsigned short reset_code);
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user