Merge pull request #5061 from QuarkTheAwesome/master

Tweaks to let DOSBox core work on Wii U
This commit is contained in:
Twinaphex 2017-06-15 07:43:22 +02:00 committed by GitHub
commit d25a749702
5 changed files with 92 additions and 25 deletions

5
.gitignore vendored
View File

@ -63,6 +63,11 @@ menu/driverspzarch.c
/media/shaders_glsl/
/obj-w32/
# Wii U
*.depend
*.rpx
wiiu/wut/elf2rpl/elf2rpl
# Ctags
/tags

View File

@ -11,6 +11,7 @@ PC_DEVELOPMENT_TCP_PORT ?=
OBJ :=
OBJ += wiiu/system/memory.o
OBJ += wiiu/system/exception_handler.o
OBJ += wiiu/system/missing_libc_functions.o
OBJ += wiiu/fs/sd_fat_devoptab.o
OBJ += wiiu/fs/fs_utils.o
OBJ += wiiu/controller_patcher/ControllerPatcher.o

View File

@ -310,14 +310,14 @@ frontend_ctx_driver_t frontend_ctx_wiiu =
"wiiu",
};
static int log_socket = -1;
static volatile int log_lock = 0;
static int wiiu_log_socket = -1;
static volatile int wiiu_log_lock = 0;
void log_init(const char *ipString, int port)
void wiiu_log_init(const char *ipString, int port)
{
log_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
wiiu_log_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (log_socket < 0)
if (wiiu_log_socket < 0)
return;
struct sockaddr_in connect_addr;
@ -326,37 +326,37 @@ void log_init(const char *ipString, int port)
connect_addr.sin_port = port;
inet_aton(ipString, &connect_addr.sin_addr);
if (connect(log_socket, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) < 0)
if (connect(wiiu_log_socket, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) < 0)
{
socketclose(log_socket);
log_socket = -1;
socketclose(wiiu_log_socket);
wiiu_log_socket = -1;
}
}
void log_deinit(void)
void wiiu_log_deinit(void)
{
if (log_socket >= 0)
if (wiiu_log_socket >= 0)
{
socketclose(log_socket);
log_socket = -1;
socketclose(wiiu_log_socket);
wiiu_log_socket = -1;
}
}
static ssize_t log_write(struct _reent *r, void *fd, const char *ptr, size_t len)
static ssize_t wiiu_log_write(struct _reent *r, void *fd, const char *ptr, size_t len)
{
if (log_socket < 0)
if (wiiu_log_socket < 0)
return len;
while (log_lock)
while (wiiu_log_lock)
OSSleepTicks(((248625000 / 4)) / 1000);
log_lock = 1;
wiiu_log_lock = 1;
int ret;
while (len > 0)
{
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
ret = send(log_socket, ptr, block, 0);
ret = send(wiiu_log_socket, ptr, block, 0);
if (ret < 0)
break;
@ -365,18 +365,18 @@ static ssize_t log_write(struct _reent *r, void *fd, const char *ptr, size_t len
ptr += ret;
}
log_lock = 0;
wiiu_log_lock = 0;
return len;
}
void net_print(const char *str)
{
log_write(NULL, 0, str, strlen(str));
wiiu_log_write(NULL, 0, str, strlen(str));
}
void net_print_exp(const char *str)
{
send(log_socket, str, strlen(str), 0);
send(wiiu_log_socket, str, strlen(str), 0);
}
static devoptab_t dotab_stdout =
@ -385,7 +385,7 @@ static devoptab_t dotab_stdout =
0, // size of file structure
NULL, // device open
NULL, // device close
log_write, // device write
wiiu_log_write, // device write
NULL,
/* ... */
};
@ -420,7 +420,7 @@ int main(int argc, char **argv)
network_init();
#endif
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
wiiu_log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
devoptab_list[STD_OUT] = &dotab_stdout;
devoptab_list[STD_ERR] = &dotab_stdout;
#endif
@ -504,7 +504,7 @@ int main(int argc, char **argv)
ProcUIShutdown();
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
log_deinit();
wiiu_log_deinit();
#endif
/* returning non 0 here can prevent loading a different rpx/elf in the HBL environment */

View File

@ -81,7 +81,7 @@ static const char exception_print_formats[18][45] =
"%p: %08X %08X %08X %08X\n", // 17
};
void net_print_exp(const char* str);
void log_deinit(void);
void wiiu_log_deinit(void);
static unsigned char exception_cb(void* c, unsigned char exception_type)
{
@ -182,7 +182,7 @@ static unsigned char exception_cb(void* c, unsigned char exception_type)
//}
net_print_exp(gdb_buf);
// net_print_exp(buf);
log_deinit();
wiiu_log_deinit();
OSFatal(buf);
return 1;
}

View File

@ -0,0 +1,61 @@
/* devkitPPC is missing a few functions that are kinda needed for some cores.
* This should add them back in.
*/
#include <unistd.h>
#include <stdio.h>
#include <wiiu/os.h>
#include <pwd.h>
#include <features/features_cpu.h>
//This is usually in libogc; we can't use that on wiiu
int usleep(useconds_t microseconds) {
OSSleepTicks(us_to_ticks(microseconds));
return 0;
}
//Can't find this one anywhere for some reason :/
//This could probably be done a lot better with some love
int access(const char* path, int mode) {
return 0; //TODO temp hack, real code below
FILE* fd = fopen(path, "rb");
if (fd < 0) {
fclose(fd);
//We're supposed to set errono here
return -1;
} else {
fclose(fd);
return 0;
}
}
//Just hardcode the Linux User ID, we're not on linux anyway
//Feasible cool addition: nn::act for this?
uid_t getuid() {
return 1000;
}
//Fake user info
//Not thread safe, but avoids returning local variable, so...
struct passwd out;
struct passwd* getpwuid(uid_t uid) {
out.pw_name = "retroarch";
out.pw_passwd = "Wait, what?";
out.pw_uid = uid;
out.pw_gid = 1000;
out.pw_gecos = "retroarch";
out.pw_dir = "sd:/";
out.pw_shell = "/vol/system_slc/fw.img";
return &out;
}
//Try to vaugely spoof the POISX clock. Epoch is off by about 30
//years, so this could be better...
//Only has second accuracy since I'm lazy.
int clock_gettime(clockid_t clk_id, struct timespec* tp) {
int64_t time_usec = cpu_features_get_time_usec();
tp->tv_sec = time_usec / 1000000;
return 0;
}