Skip to content

Commit

Permalink
a26: riot timer improvements
Browse files Browse the repository at this point in the history
Fixes "bang!" demoscene demo running too fast

Most effects in that demo are still broken, however.
  • Loading branch information
LukeUsher committed Nov 14, 2023
1 parent dc385db commit 4a48753
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
17 changes: 13 additions & 4 deletions ares/a26/riot/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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; }
}

Expand Down
1 change: 1 addition & 0 deletions ares/a26/riot/riot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ares/a26/riot/riot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct RIOT : Thread {
u8 counter;
n16 interval;
n16 reload;
n1 interruptEnable;
n1 interruptFlag;
} timer;

struct Port {
Expand Down
2 changes: 2 additions & 0 deletions ares/a26/riot/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ares/a26/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 4a48753

Please sign in to comment.