mirror of https://github.com/bsnes-emu/bsnes.git
Update to v086r05 release.
byuu says: USART implements reading and writing, but I don't yet have code to test SNES reading yet. So ... obviously I need to do that next. Went ahead and required nall::function, so the modules will have to be C++11. I don't see anyone else making these, and it avoids the annoyance of deducing the correct controller port based on dynamic casting the active thread. Apparently a library can have a main() function to no ill effect, so there's no need for USART_HARDWARE. Same exact code with different flags will make the binary and the library.
This commit is contained in:
parent
6cbc312f11
commit
338f13e57b
|
@ -1,7 +1,7 @@
|
||||||
#ifndef BASE_HPP
|
#ifndef BASE_HPP
|
||||||
#define BASE_HPP
|
#define BASE_HPP
|
||||||
|
|
||||||
const char Version[] = "086.04";
|
const char Version[] = "086.05";
|
||||||
|
|
||||||
#include <nall/platform.hpp>
|
#include <nall/platform.hpp>
|
||||||
#include <nall/algorithm.hpp>
|
#include <nall/algorithm.hpp>
|
||||||
|
|
|
@ -16,14 +16,35 @@
|
||||||
// IOBit ---
|
// IOBit ---
|
||||||
// GND GND
|
// GND GND
|
||||||
|
|
||||||
static uint8 usart_read();
|
void USART::enter() {
|
||||||
static void usart_write(uint8 data);
|
main({ &USART::usleep, this }, { &USART::read, this }, { &USART::write, this });
|
||||||
|
while(true) step(1000000); //fallback; main should never return
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART::usleep(unsigned milliseconds) {
|
||||||
|
step(milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
//SNES -> USART
|
||||||
|
uint8 USART::read() {
|
||||||
|
while(txbuffer.size() == 0) step(1);
|
||||||
|
uint8 data = txbuffer[0];
|
||||||
|
txbuffer.remove(0);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
//USART -> SNES
|
||||||
|
void USART::write(uint8 data) {
|
||||||
|
rxbuffer.append(data);
|
||||||
|
}
|
||||||
|
|
||||||
//USART -> SNES
|
//USART -> SNES
|
||||||
uint2 USART::data() {
|
uint2 USART::data() {
|
||||||
if(rxlength == 0) {
|
if(rxlength == 0 && rxbuffer.size()) {
|
||||||
data1 = 0;
|
data1 = 0;
|
||||||
rxdata = usart_read();
|
rxdata = rxbuffer[0];
|
||||||
|
rxbuffer.remove(0);
|
||||||
|
rxlength++;
|
||||||
} else if(rxlength <= 8) {
|
} else if(rxlength <= 8) {
|
||||||
data1 = rxdata & 1;
|
data1 = rxdata & 1;
|
||||||
rxdata >>= 1;
|
rxdata >>= 1;
|
||||||
|
@ -43,7 +64,7 @@ void USART::latch(bool data) {
|
||||||
txdata = (data << 7) | (txdata >> 1);
|
txdata = (data << 7) | (txdata >> 1);
|
||||||
txlength++;
|
txlength++;
|
||||||
} else {
|
} else {
|
||||||
if(data == 1) usart_write(txdata);
|
if(data == 1) txbuffer.append(txdata);
|
||||||
txlength = 0;
|
txlength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,16 +81,16 @@ USART::USART(bool port) : Controller(port) {
|
||||||
|
|
||||||
txlength = 0;
|
txlength = 0;
|
||||||
txdata = 0;
|
txdata = 0;
|
||||||
|
|
||||||
|
string filename = interface->path(Cartridge::Slot::Base, "usart.so");
|
||||||
|
if(open_absolute(filename)) {
|
||||||
|
main = sym("usart_main");
|
||||||
|
if(main) create(Controller::Enter, 1000000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
USART::~USART() {
|
USART::~USART() {
|
||||||
}
|
if(opened()) close();
|
||||||
|
|
||||||
static uint8 usart_read() {
|
|
||||||
return 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usart_write(uint8 data) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
struct USART : Controller, public library {
|
struct USART : Controller, public library {
|
||||||
|
void enter();
|
||||||
|
void usleep(unsigned milliseconds);
|
||||||
|
uint8 read();
|
||||||
|
void write(uint8 data);
|
||||||
|
|
||||||
uint2 data();
|
uint2 data();
|
||||||
void latch(bool data);
|
void latch(bool data);
|
||||||
|
|
||||||
USART(bool port);
|
USART(bool port);
|
||||||
~USART();
|
~USART();
|
||||||
|
|
||||||
|
@ -11,7 +17,11 @@ private:
|
||||||
|
|
||||||
uint8 rxlength;
|
uint8 rxlength;
|
||||||
uint8 rxdata;
|
uint8 rxdata;
|
||||||
|
vector<uint8> rxbuffer;
|
||||||
|
|
||||||
uint8 txlength;
|
uint8 txlength;
|
||||||
uint8 txdata;
|
uint8 txdata;
|
||||||
|
vector<uint8> txbuffer;
|
||||||
|
|
||||||
|
function<void (function<void (unsigned)>, function<uint8 ()>, function<void (uint8)>)> main;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue