Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/amadvance/advancemame
Browse files Browse the repository at this point in the history
  • Loading branch information
trngaje committed Apr 20, 2024
2 parents f1cbe29 + ec65276 commit 53ec8fc
Show file tree
Hide file tree
Showing 46 changed files with 4,316 additions and 1,642 deletions.
4 changes: 2 additions & 2 deletions aclocal.m4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
# generated automatically by aclocal 1.15.1 -*- Autoconf -*-

# Copyright (C) 1996-2018 Free Software Foundation, Inc.
# Copyright (C) 1996-2017 Free Software Foundation, Inc.

# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
Expand Down
1,442 changes: 839 additions & 603 deletions advance/blit/blit.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions advance/blit/blit.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ struct __attribute__((aligned(8))) video_pipeline_struct {
struct video_stage_horz_struct stage_map[VIDEO_STAGE_MAX]; /**< Horizontal stages. */
struct video_stage_vert_struct stage_vert; /**< Vertical stage. */
unsigned stage_mac; /**< Number of horizontal stages. */
void* mark; /**< Marker for buffer allocation */
struct video_pipeline_target_struct target; /**< Target of the pipeline. */
};

Expand Down
179 changes: 140 additions & 39 deletions advance/blue/blue.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int opt_verbose; /** Verbose output */
/**
* Backlog
*/
#define BACKLOG_LINES 16
#define BACKLOG_LINES 256
#define BACKLOG_MAX 128

char backlog[BACKLOG_LINES][BACKLOG_MAX];
Expand All @@ -68,6 +68,10 @@ void backlog_print(void)
for (i = backlog_begin; i != backlog_end; i = (i + 1) % BACKLOG_LINES) {
printf(": %s\n", backlog[i]);
}

/* clear backlog */
backlog_begin = 0;
backlog_end = 0;
}

/**
Expand Down Expand Up @@ -175,10 +179,11 @@ void blue_send(int f, const char* command)
printf("# %s", command);

/* give some time to process the command */
usleep(500);
usleep(100000);
}

struct blue_device {
unsigned cookie;
char* id;
char name[128];
int is_game;
Expand All @@ -190,34 +195,57 @@ struct blue_device {
struct blue_device* next;
};

struct blue_device* devs;
struct blue_device* DEVS;

struct blue_device* dev_find(const char* id)
struct blue_device* dev_insert(const char* id, unsigned cookie)
{
struct blue_device* i = devs;
struct blue_device* i = DEVS;

while (i != 0) {
if (strcmp(id, i->id) == 0)
if (strcmp(id, i->id) == 0) {
i->cookie = cookie;
return i;
}
i = i->next;
}

/* if not found, allocate */
i = calloc(1, sizeof(struct blue_device));

i->id = strdup(id);
i->next = devs;
devs = i;
i->cookie = cookie;
i->next = DEVS;
DEVS = i;

return i;
}

void dev_flush(unsigned cookie)
{

struct blue_device* i = DEVS;

DEVS = 0;
while (i != 0) {
struct blue_device* i_next = i->next;

if (i->cookie == cookie) {
i->next = DEVS;
DEVS = i;
} else {
free(i);
}

i = i_next;
}
}

/**
* Process a device line
*
* Like: 'Device E4:17:D8:B8:0B:7E 8Bitdo SFC30 GamePad'
*/
void process_device_line(char* line)
void process_device_line(char* line, unsigned cookie)
{
char* id;
int i;
Expand All @@ -240,23 +268,29 @@ void process_device_line(char* line)
*line = 0;

/* allocate if missing */
dev_find(id);
dev_insert(id, cookie);
}

unsigned COOKIE = 0;

/**
* List all devices
*/
void process_list(int in_f, int out_f)
void process_devices(int in_f, int out_f)
{
char* line;

blue_send(in_f, "devices\n");

++COOKIE;

line = blue_line(out_f);
while (line) {
process_device_line(line);
process_device_line(line, COOKIE);
line = blue_line(out_f);
}

dev_flush(COOKIE);
}

/**
Expand Down Expand Up @@ -322,7 +356,7 @@ void process_info_line(struct blue_device* dev, const char* line)
*/
void process_info(int in_f, int out_f)
{
struct blue_device* i = devs;
struct blue_device* i = DEVS;

while (i != 0) {
char cmd[128];
Expand All @@ -347,29 +381,44 @@ void process_info(int in_f, int out_f)
*/
void process_connect(int in_f, int out_f)
{
struct blue_device* i = devs;
struct blue_device* i;
char processing[4096];
char connected[4096];
char msg[4096];
char ignored[128];
char paired[128];
unsigned count_processing;
unsigned count_connected;
unsigned count_ignored;
unsigned count_paired;
int ret;
time_t now;

now = time(0);
count_processing = 0;
count_connected = 0;
count_ignored = 0;
count_paired = 0;
processing[0] = 0;
connected[0] = 0;
ignored[0] = 0;
paired[0] = 0;

for (i = devs; i != 0; i = i->next) {
for (i = DEVS; i != 0; i = i->next) {
char cmd[128];
const char* name = i->name[0] ? i->name : i->id;

if (!i->is_game)
if (!i->is_game) {
snprintf(ignored, sizeof(ignored), "%s", name);
++count_ignored;
continue;
}

if (!i->is_trusted) {
snprintf(cmd, sizeof(cmd), "trust %s\n", i->id);
blue_send(in_f, cmd);
blue_discard(out_f);
snprintfcat(processing, sizeof(processing) - 1, "Trusting %s...\n", name);
snprintfcat(processing, sizeof(processing), "Trusting %s...\n", name);
++count_processing;
continue;
}
Expand All @@ -385,9 +434,12 @@ void process_connect(int in_f, int out_f)
snprintf(cmd, sizeof(cmd), "pair %s\n", i->id);
blue_send(in_f, cmd);
blue_discard(out_f);
snprintfcat(processing, sizeof(processing) - 1, "Pairing %s...\n", name);
snprintfcat(processing, sizeof(processing), "Pairing %s...\n", name);
++count_processing;
continue;
} else {
snprintf(paired, sizeof(paired), "%s", name);
++count_paired;
}

if (!i->is_connected && i->need_connect) {
Expand All @@ -400,47 +452,95 @@ void process_connect(int in_f, int out_f)
}

if (i->is_connected) {
snprintfcat(connected, sizeof(connected), "Connected %s", name);
snprintf(connected, sizeof(connected), "%s", name);
++count_connected;
}
}

/* ensure to have the final terminator */
processing[sizeof(processing) - 1] = 0;
connected[sizeof(connected) - 1] = 0;
ignored[sizeof(ignored) - 1] = 0;
paired[sizeof(paired) - 1] = 0;

if (count_processing != 0) {
if (count_connected == 1)
snprintfcat(processing, sizeof(processing), "%s", connected);
else if (count_connected > 1)
snprintfcat(processing, sizeof(processing), "Connected %u devices", count_connected);
if (count_connected == 0) {
if (count_processing != 0) {
/* processing is already set */
} else {
if (count_paired != 0) {
snprintf(processing, sizeof(processing), "Turn on %s or pair another gamepad", paired);
} else if (count_ignored == 0) {
strcpy(processing, "Insert or pair a gamepad");
} else {
snprintf(processing, sizeof(processing), "Insert or pair a gamepad (%u not gamepads)", count_ignored);
}
}
} else {
if (count_connected == 0)
strcpy(processing, "Press START for one second to power on");
else if (count_connected > 1)
snprintf(processing, sizeof(processing), "Connected %u devices", count_connected);
if (count_connected == 1) {
snprintf(processing, sizeof(processing), "Connected %s", connected);
} else {
snprintf(processing, sizeof(processing), "Connected %u gamepads", count_connected);
}
}

if (count_connected == 0 && count_processing == 0) {
if (count_paired != 0)
snprintf(msg, sizeof(msg), "WAITING\n");
else
strcpy(processing, connected);
snprintf(msg, sizeof(msg), "EMPTY\n");
} else {
snprintf(msg, sizeof(msg), "WORKING\n");
}

snprintfcat(msg, sizeof(msg), processing);
msg[sizeof(msg) - 1] = 0;

if (opt_msg) {
int f = open("/tmp/blue.msg", O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (f >= 0) {
write(f, processing, strlen(processing));
write(f, msg, strlen(msg));
close(f);
}
if (opt_verbose)
printf("<%s>\n", processing);
}
}

void print_list(void)
void kill_devices(int in_f, int out_f)
{
struct blue_device* i = DEVS;

i = DEVS;
while (i != 0) {
char cmd[128];
struct blue_device* i_next = i->next;

if (!i->is_game) {
free(i);
i = i_next;
continue;
}

snprintf(cmd, sizeof(cmd), "remove %s\n", i->id);

blue_send(in_f, cmd);
blue_discard(out_f);
usleep(1000000);

free(i);
i = i_next;
}

DEVS = 0;
}

void print_devices(void)
{
struct blue_device* i = devs;
struct blue_device* i = DEVS;

printf("\nDevices:\n");

for (i = devs; i != 0; i = i->next) {
for (i = DEVS; i != 0; i = i->next) {
printf("\t\"%s\" %s %s %s %s %s %s\n", i->name, i->id,
i->is_game ? "game" : "",
i->is_trusted ? "trusted" : "",
Expand All @@ -467,22 +567,23 @@ void process(int in_f, int out_f)

blue_discard(out_f);

blue_send(in_f, "scan on\n");
while (1) {
usleep(500000);

blue_discard(out_f);
/* sometimes at startup the scan is lost, better to repeat it every time */
blue_send(in_f, "scan on\n");

while (1) {
sleep(1);
blue_discard(out_f);

process_list(in_f, out_f);
process_devices(in_f, out_f);

process_info(in_f, out_f);

process_connect(in_f, out_f);

if (opt_stat) {
backlog_print();
print_list();
print_devices();
}
}
}
Expand Down
Loading

0 comments on commit 53ec8fc

Please sign in to comment.