diff --git a/ares/a26/riot/io.cpp b/ares/a26/riot/io.cpp index 42c9652531..638c0bf955 100644 --- a/ares/a26/riot/io.cpp +++ b/ares/a26/riot/io.cpp @@ -7,12 +7,18 @@ auto RIOT::writeRam(n8 address, n8 data) -> void { } auto RIOT::readIo(n8 address) -> n8 { - switch(address) { + switch(address.bit(0, 2)) { case 0x00: return readPortA(); case 0x01: return port[0].direction; case 0x02: return readPortB(); case 0x03: return port[1].direction; - case 0x04: return timer.counter; + case 0x04: timer.interruptFlag = address.bit(3); return timer.counter; + case 0x05: case 0x07: { + n8 output = 0; + output.bit(6) = 0; //TODO: PA7 IRQ Flag + output.bit(7) = timer.interruptFlag; + return output; + } } debug(unimplemented, "[RIOT] IO read ", hex(address)); @@ -25,11 +31,14 @@ auto RIOT::writeIo(n8 address, n8 data) -> void { case 0x01: port[0].direction = data; return; case 0x02: writePortB(data); return; case 0x03: port[1].direction = data; return; - case 0x14: case 0x15: case 0x16: case 0x17: { + case 0x14: case 0x15: case 0x16: case 0x17: + case 0x1c: case 0x1d: case 0x1e: case 0x1f: { const n16 intervals[] = {1, 8, 64, 1024}; timer.counter = data; - timer.interval = intervals[address - 0x14]; + timer.interval = intervals[address.bit(0, 1)]; timer.reload = timer.interval; + timer.interruptFlag = 0; + timer.interruptEnable = address.bit(3); return; } } diff --git a/ares/a26/riot/riot.cpp b/ares/a26/riot/riot.cpp index 815472c26e..c23bdca0cb 100644 --- a/ares/a26/riot/riot.cpp +++ b/ares/a26/riot/riot.cpp @@ -21,6 +21,7 @@ auto RIOT::unload() -> void { auto RIOT::main() -> void { if(--timer.counter == 0xff) { timer.interval = 1; + timer.interruptFlag = 1; } step(timer.interval); diff --git a/ares/a26/riot/riot.hpp b/ares/a26/riot/riot.hpp index fffff15f27..b8cbbcfee5 100644 --- a/ares/a26/riot/riot.hpp +++ b/ares/a26/riot/riot.hpp @@ -30,6 +30,8 @@ struct RIOT : Thread { u8 counter; n16 interval; n16 reload; + n1 interruptEnable; + n1 interruptFlag; } timer; struct Port { diff --git a/ares/a26/riot/serialization.cpp b/ares/a26/riot/serialization.cpp index 4a4c93f80c..546ae34b8c 100644 --- a/ares/a26/riot/serialization.cpp +++ b/ares/a26/riot/serialization.cpp @@ -6,6 +6,8 @@ auto RIOT::serialize(serializer& s) -> void { s(timer.counter); s(timer.interval); s(timer.reload); + s(timer.interruptEnable); + s(timer.interruptFlag); for(auto n : range(2)) { s(port[n].data); diff --git a/ares/a26/system/serialization.cpp b/ares/a26/system/serialization.cpp index c08d0f93bd..b16a0a4dea 100644 --- a/ares/a26/system/serialization.cpp +++ b/ares/a26/system/serialization.cpp @@ -1,4 +1,4 @@ -static const string SerializerVersion = "v131"; +static const string SerializerVersion = "v132"; auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);