diff --git a/bsnes/base/base.hpp b/bsnes/base/base.hpp index 4a7bb5aa..c160d6a8 100755 --- a/bsnes/base/base.hpp +++ b/bsnes/base/base.hpp @@ -1,7 +1,7 @@ #ifndef BASE_HPP #define BASE_HPP -const char Version[] = "086.06"; +const char Version[] = "086.07"; #include #include diff --git a/bsnes/snes/controller/usart/usart.cpp b/bsnes/snes/controller/usart/usart.cpp index a40fa027..88a07088 100755 --- a/bsnes/snes/controller/usart/usart.cpp +++ b/bsnes/snes/controller/usart/usart.cpp @@ -17,7 +17,8 @@ // GND GND void USART::enter() { - main({ &USART::usleep, this }, { &USART::read, this }, { &USART::write, this }); + init({ &USART::usleep, this }, { &USART::read, this }, { &USART::write, this }); + main(); while(true) step(1000000); //fallback; main should never return } @@ -38,8 +39,20 @@ void USART::write(uint8 data) { rxbuffer.append(data ^ 0xff); } -//USART -> SNES +//clock uint2 USART::data() { + //SNES -> USART + if(txlength == 0 && latched == 0) { + txlength++; + } else if(txlength <= 8) { + txdata = (latched << 7) | (txdata >> 1); + txlength++; + } else { + if(latched == 1) txbuffer.append(txdata); + txlength = 0; + } + + //USART -> SNES if(rxlength == 0 && rxbuffer.size()) { data1 = 1; rxdata = rxbuffer[0]; @@ -57,18 +70,8 @@ uint2 USART::data() { return (data2 << 1) | (data1 << 0); } -//SNES -> USART +//latch void USART::latch(bool data) { - if(txlength == 0 && latched == 1 && data == 0) { - txlength++; - } else if(txlength <= 8) { - txdata = (data << 7) | (txdata >> 1); - txlength++; - } else { - if(data == 1) txbuffer.append(txdata); - txlength = 0; - } - latched = data; } @@ -85,8 +88,9 @@ USART::USART(bool port) : Controller(port) { string filename = interface->path(Cartridge::Slot::Base, "usart.so"); if(open_absolute(filename)) { + init = sym("usart_init"); main = sym("usart_main"); - if(main) create(Controller::Enter, 1000000); + if(init && main) create(Controller::Enter, 1000000); } } diff --git a/bsnes/snes/controller/usart/usart.hpp b/bsnes/snes/controller/usart/usart.hpp index 17de61a5..dcf39077 100755 --- a/bsnes/snes/controller/usart/usart.hpp +++ b/bsnes/snes/controller/usart/usart.hpp @@ -23,5 +23,6 @@ private: uint8 txdata; vector txbuffer; - function, function, function)> main; + function, function, function)> init; + function main; };