amiga/SniffEmu/SniffEmu/Source/SniffEmu.c

183 lines
5.8 KiB
C
Executable File

/*
* SniffEmu by BTHLabs
* Copyright (c) 2023-present BTHLabs <contact@bthlabs.pl> (https://bthlabs.pl)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <libraries/configregs.h>
#include <libraries/configvars.h>
#include <libraries/expansion.h>
#include <proto/dos.h>
#include <proto/expansion.h>
#include "SniffEmu.h"
struct ExpansionBase * ExpansionBase;
static STRPTR verstring = APP_VSTRING;
static char *MODE_NAME_EMU68 = "EMU68";
static char *MODE_NAME_UAE = "UAE";
static char *MODE_NAME_MUSASHI = "MUSASHI";
#define TEMPLATE "HELP/S,RTG/S,SND/S,MODE"
typedef enum {
OPT_HELP,
OPT_RTG,
OPT_SND,
OPT_MODE,
OPT_COUNT
} OPT_ARGS;
typedef enum {
MODE_UNKNOWN,
MODE_EMU68,
MODE_UAE,
MODE_MUSASHI
} MODE;
int help() {
printf(
"SniffEmu %s by BTHLabs\n"
"Developed by Tomek Wójcik\n"
"bthlabs.pl | MIT License\n",
VERSION
);
printf(
"\n"
"Usage: SniffEmu HELP/S RTG/S SND/S MODE\n"
"\n"
"HELP : Print this help\n"
"RTG : Sniff the RTG board\n"
"SND : Sniff the sound card\n"
"MODE : Specify the emulator to sniff\n"
" Valid values: EMU68, UAE, MUSASHI\n"
);
return RETURN_OK;
}
int find_board(int manufacturer, int product) {
int result = RETURN_OK;
if (ExpansionBase = (struct ExpansionBase *)OpenLibrary(EXPANSIONNAME, 0L)) {
struct ConfigDev* cd = NULL;
printf("SniffEmu: Looking for board: %d:%d... ", manufacturer, product);
while (cd = FindConfigDev(cd, manufacturer, product)) {
result = RETURN_WARN;
}
CloseLibrary(ExpansionBase);
if (result == RETURN_WARN) {
printf("FOUND\n");
} else {
printf("NOT FOUND\n");
}
} else {
printf("SniffEmu: Could not open expansion.library!\n");
result = RETURN_FAIL;
}
return result;
}
int main(int argc, char *argv[]) {
int result = RETURN_OK;
int opts[OPT_COUNT];
struct RDArgs *rdargs;
int manufacturer = -1;
int product = -1;
if (argc > 1) {
memset((char *)opts, 0, sizeof(opts));
if (rdargs = (struct RDArgs *)ReadArgs(TEMPLATE, opts, NULL)) {
if (opts[OPT_HELP]) {
result = help();
} else {
MODE mode = MODE_UNKNOWN;
if (strcmp((STRPTR)opts[OPT_MODE], MODE_NAME_EMU68) == 0) {
mode = MODE_EMU68;
} else if (strcmp((STRPTR)opts[OPT_MODE], MODE_NAME_UAE) == 0) {
mode = MODE_UAE;
} else if (strcmp((STRPTR)opts[OPT_MODE], MODE_NAME_MUSASHI) == 0) {
/* MUSASHI mode is untested. */
mode = MODE_MUSASHI;
} else {
printf("SniffEmu: Invalid MODE: `%s`\n", opts[OPT_MODE]);
result = help();
}
if (mode != MODE_UNKNOWN) {
if (mode == MODE_EMU68) {
manufacturer = EMU68_MANUFACTURER;
} else if (mode == MODE_UAE) {
manufacturer = UAE_MANUFACTURER;
} else if (mode == MODE_MUSASHI) {
manufacturer = MUSASHI_MANUFACTURER;
product = MUSASHI_INTERACTION;
}
if (opts[OPT_RTG]) {
if (mode == MODE_EMU68) {
product = EMU68_RTG;
} else if (mode == MODE_UAE) {
product = UAE_RTG;
} else if (mode == MODE_MUSASHI) {
printf("SniffEmu: Can't reliably sniff RTG on Musashi :(\n");
product = MUSASHI_RTG;
}
} else if (opts[OPT_SND]) {
if (mode == MODE_EMU68) {
printf("SniffEmu: Can't sniff SND on EMU68 :(\n");
product = EMU68_SND;
} else if (mode == MODE_UAE) {
manufacturer = UAE_SND_MANUFACTURER;
product = UAE_SND;
} else if (mode == MODE_MUSASHI) {
printf("SniffEmu: Can't sniff SND on Musashi :(\n");
product = MUSASHI_SND;
}
}
result = find_board(manufacturer, product);
}
}
FreeArgs(rdargs);
} else {
printf("SniffEmu: Invalid arguments.\n");
result = help();
}
} else {
result = help();
}
return result;
}