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:
Tim Allen 2012-02-25 19:52:42 +11:00
parent 6cbc312f11
commit 338f13e57b
3 changed files with 44 additions and 13 deletions

View File

@ -1,7 +1,7 @@
#ifndef BASE_HPP
#define BASE_HPP
const char Version[] = "086.04";
const char Version[] = "086.05";
#include <nall/platform.hpp>
#include <nall/algorithm.hpp>

View File

@ -16,14 +16,35 @@
// IOBit ---
// GND GND
static uint8 usart_read();
static void usart_write(uint8 data);
void USART::enter() {
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
uint2 USART::data() {
if(rxlength == 0) {
if(rxlength == 0 && rxbuffer.size()) {
data1 = 0;
rxdata = usart_read();
rxdata = rxbuffer[0];
rxbuffer.remove(0);
rxlength++;
} else if(rxlength <= 8) {
data1 = rxdata & 1;
rxdata >>= 1;
@ -43,7 +64,7 @@ void USART::latch(bool data) {
txdata = (data << 7) | (txdata >> 1);
txlength++;
} else {
if(data == 1) usart_write(txdata);
if(data == 1) txbuffer.append(txdata);
txlength = 0;
}
@ -60,16 +81,16 @@ USART::USART(bool port) : Controller(port) {
txlength = 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() {
}
static uint8 usart_read() {
return 0xff;
}
static void usart_write(uint8 data) {
if(opened()) close();
}
#endif

View File

@ -1,6 +1,12 @@
struct USART : Controller, public library {
void enter();
void usleep(unsigned milliseconds);
uint8 read();
void write(uint8 data);
uint2 data();
void latch(bool data);
USART(bool port);
~USART();
@ -11,7 +17,11 @@ private:
uint8 rxlength;
uint8 rxdata;
vector<uint8> rxbuffer;
uint8 txlength;
uint8 txdata;
vector<uint8> txbuffer;
function<void (function<void (unsigned)>, function<uint8 ()>, function<void (uint8)>)> main;
};