mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
byuu says: Most notably, this release adds Nintendo DS emulation. The Nintendo DS module was written entirely by Cydrak, so please give him all of the credit for it. I for one am extremely grateful to be allowed to use his module in bsnes. The Nintendo DS emulator's standalone name is dasShiny. You will need the Nintendo DS firmware, which I cannot provide, in order to use it. It also cannot (currently?) detect the save type used by NDS games. As such, manifest.xml files must be created manually for this purpose. The long-term plan is to create a database of save types for each game. Also, you will need an analog input device for the touch screen for now (joypad axes work well.) There have also been a lot of changes from my end: a unified manifest.xml format across all systems, major improvements to SPC7110 emulation, enhancements to RTC emulation, MSU1 enhancements, icons in the file browser list, improvements to SNES coprocessor memory mapping, cleanups and improvements in the libraries used to build bsnes, etc. I've also included kaijuu (which allows launching game folders directly with bsnes) and purify (which allows opening images that are compressed, have copier headers, and have wrong extensions); both of which are fully GUI-based. This release only loads game folders, not files. Use purify to load ROM files in bsnes. Note that this will likely be the last release for a long time, and that I will probably rename the emulator for the next release, due to how many additional systems it now supports.
176 lines
4.3 KiB
C++
176 lines
4.3 KiB
C++
#ifndef NALL_HTTP_HPP
|
|
#define NALL_HTTP_HPP
|
|
|
|
#if !defined(_WIN32)
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <netdb.h>
|
|
#else
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
#include <nall/platform.hpp>
|
|
#include <nall/string.hpp>
|
|
|
|
namespace nall {
|
|
|
|
struct http {
|
|
string hostname;
|
|
addrinfo *serverinfo;
|
|
int serversocket;
|
|
string header;
|
|
|
|
inline void download(const string &path, uint8_t *&data, unsigned &size) {
|
|
data = 0;
|
|
size = 0;
|
|
|
|
send({
|
|
"GET ", path, " HTTP/1.1\r\n"
|
|
"Host: ", hostname, "\r\n"
|
|
"Connection: close\r\n"
|
|
"\r\n"
|
|
});
|
|
|
|
header = downloadHeader();
|
|
downloadContent(data, size);
|
|
}
|
|
|
|
inline bool connect(string host, unsigned port) {
|
|
hostname = host;
|
|
|
|
addrinfo hints;
|
|
memset(&hints, 0, sizeof(addrinfo));
|
|
hints.ai_family = AF_UNSPEC;
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
int status = getaddrinfo(hostname, string(port), &hints, &serverinfo);
|
|
if(status != 0) return false;
|
|
|
|
serversocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol);
|
|
if(serversocket == -1) return false;
|
|
|
|
int result = ::connect(serversocket, serverinfo->ai_addr, serverinfo->ai_addrlen);
|
|
if(result == -1) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
inline bool send(const string &data) {
|
|
return send((const uint8_t*)(const char*)data, data.length());
|
|
}
|
|
|
|
inline bool send(const uint8_t *data, unsigned size) {
|
|
while(size) {
|
|
int length = ::send(serversocket, (const char*)data, size, 0);
|
|
if(length == -1) return false;
|
|
data += length;
|
|
size -= length;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
inline string downloadHeader() {
|
|
string output;
|
|
do {
|
|
char buffer[2];
|
|
int length = recv(serversocket, buffer, 1, 0);
|
|
if(length <= 0) return output;
|
|
buffer[1] = 0;
|
|
output.append(buffer);
|
|
} while(output.endswith("\r\n\r\n") == false);
|
|
return output;
|
|
}
|
|
|
|
inline string downloadChunkLength() {
|
|
string output;
|
|
do {
|
|
char buffer[2];
|
|
int length = recv(serversocket, buffer, 1, 0);
|
|
if(length <= 0) return output;
|
|
buffer[1] = 0;
|
|
output.append(buffer);
|
|
} while(output.endswith("\r\n") == false);
|
|
return output;
|
|
}
|
|
|
|
inline void downloadContent(uint8_t *&data, unsigned &size) {
|
|
unsigned capacity = 0;
|
|
|
|
if(header.iposition("\r\nTransfer-Encoding: chunked\r\n")) {
|
|
while(true) {
|
|
unsigned length = hex(downloadChunkLength());
|
|
if(length == 0) break;
|
|
capacity += length;
|
|
data = (uint8_t*)realloc(data, capacity);
|
|
|
|
char buffer[length];
|
|
while(length) {
|
|
int packetlength = recv(serversocket, buffer, length, 0);
|
|
if(packetlength <= 0) break;
|
|
memcpy(data + size, buffer, packetlength);
|
|
size += packetlength;
|
|
length -= packetlength;
|
|
}
|
|
}
|
|
} else if(auto position = header.iposition("\r\nContent-Length: ")) {
|
|
unsigned length = decimal((const char*)header + position() + 18);
|
|
while(length) {
|
|
char buffer[256];
|
|
int packetlength = recv(serversocket, buffer, min(256, length), 0);
|
|
if(packetlength <= 0) break;
|
|
capacity += packetlength;
|
|
data = (uint8_t*)realloc(data, capacity);
|
|
memcpy(data + size, buffer, packetlength);
|
|
size += packetlength;
|
|
length -= packetlength;
|
|
}
|
|
} else {
|
|
while(true) {
|
|
char buffer[256];
|
|
int packetlength = recv(serversocket, buffer, 256, 0);
|
|
if(packetlength <= 0) break;
|
|
capacity += packetlength;
|
|
data = (uint8_t*)realloc(data, capacity);
|
|
memcpy(data + size, buffer, packetlength);
|
|
size += packetlength;
|
|
}
|
|
}
|
|
|
|
data = (uint8_t*)realloc(data, capacity + 1);
|
|
data[capacity] = 0;
|
|
}
|
|
|
|
inline void disconnect() {
|
|
close(serversocket);
|
|
freeaddrinfo(serverinfo);
|
|
serverinfo = 0;
|
|
serversocket = -1;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
inline int close(int sock) {
|
|
return closesocket(sock);
|
|
}
|
|
|
|
inline http() {
|
|
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) {
|
|
WSADATA wsaData;
|
|
if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
|
WSACleanup();
|
|
return;
|
|
}
|
|
} else {
|
|
close(sock);
|
|
}
|
|
}
|
|
#endif
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|