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.
110 lines
2.8 KiB
C++
110 lines
2.8 KiB
C++
#ifndef NALL_SERIAL_HPP
|
|
#define NALL_SERIAL_HPP
|
|
|
|
#include <sys/ioctl.h>
|
|
#include <fcntl.h>
|
|
#include <termios.h>
|
|
#include <unistd.h>
|
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
namespace nall {
|
|
struct serial {
|
|
bool readable() {
|
|
if(port_open == false) return false;
|
|
fd_set fdset;
|
|
FD_ZERO(&fdset);
|
|
FD_SET(port, &fdset);
|
|
timeval timeout;
|
|
timeout.tv_sec = 0;
|
|
timeout.tv_usec = 0;
|
|
int result = select(FD_SETSIZE, &fdset, nullptr, nullptr, &timeout);
|
|
if(result < 1) return false;
|
|
return FD_ISSET(port, &fdset);
|
|
}
|
|
|
|
//-1 on error, otherwise return bytes read
|
|
int read(uint8_t *data, unsigned length) {
|
|
if(port_open == false) return -1;
|
|
return ::read(port, (void*)data, length);
|
|
}
|
|
|
|
bool writable() {
|
|
if(port_open == false) return false;
|
|
fd_set fdset;
|
|
FD_ZERO(&fdset);
|
|
FD_SET(port, &fdset);
|
|
timeval timeout;
|
|
timeout.tv_sec = 0;
|
|
timeout.tv_usec = 0;
|
|
int result = select(FD_SETSIZE, nullptr, &fdset, nullptr, &timeout);
|
|
if(result < 1) return false;
|
|
return FD_ISSET(port, &fdset);
|
|
}
|
|
|
|
//-1 on error, otherwise return bytes written
|
|
int write(const uint8_t *data, unsigned length) {
|
|
if(port_open == false) return -1;
|
|
return ::write(port, (void*)data, length);
|
|
}
|
|
|
|
bool open(const char *portname, unsigned rate, bool flowcontrol) {
|
|
close();
|
|
|
|
port = ::open(portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
|
if(port == -1) return false;
|
|
|
|
if(ioctl(port, TIOCEXCL) == -1) { close(); return false; }
|
|
if(fcntl(port, F_SETFL, 0) == -1) { close(); return false; }
|
|
if(tcgetattr(port, &original_attr) == -1) { close(); return false; }
|
|
|
|
termios attr = original_attr;
|
|
cfmakeraw(&attr);
|
|
cfsetspeed(&attr, rate);
|
|
|
|
attr.c_lflag &=~ (ECHO | ECHONL | ISIG | ICANON | IEXTEN);
|
|
attr.c_iflag &=~ (BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY);
|
|
attr.c_iflag |= (IGNBRK | IGNPAR);
|
|
attr.c_oflag &=~ (OPOST);
|
|
attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB | CLOCAL);
|
|
attr.c_cflag |= (CS8 | CREAD);
|
|
if(flowcontrol == false) {
|
|
attr.c_cflag &= ~CRTSCTS;
|
|
} else {
|
|
attr.c_cflag |= CRTSCTS;
|
|
}
|
|
attr.c_cc[VTIME] = attr.c_cc[VMIN] = 0;
|
|
|
|
if(tcsetattr(port, TCSANOW, &attr) == -1) { close(); return false; }
|
|
return port_open = true;
|
|
}
|
|
|
|
void close() {
|
|
if(port != -1) {
|
|
tcdrain(port);
|
|
if(port_open == true) {
|
|
tcsetattr(port, TCSANOW, &original_attr);
|
|
port_open = false;
|
|
}
|
|
::close(port);
|
|
port = -1;
|
|
}
|
|
}
|
|
|
|
serial() {
|
|
port = -1;
|
|
port_open = false;
|
|
}
|
|
|
|
~serial() {
|
|
close();
|
|
}
|
|
|
|
private:
|
|
int port;
|
|
bool port_open;
|
|
termios original_attr;
|
|
};
|
|
}
|
|
|
|
#endif
|