1
0
mirror of https://github.com/jscrane/r65emu.git synced 2026-04-21 20:17:19 +00:00

Pollable interface (#87)

This commit is contained in:
Stephen Crane
2026-02-15 12:27:11 +00:00
committed by GitHub
parent c289aea486
commit 6ce662509e
8 changed files with 38 additions and 12 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ uint8_t ACIA::read_status() {
return s;
}
void ACIA::poll_for_interrupt() {
void ACIA::poll() {
if (irq_handler) {
uint8_t s = read_status();
+2 -2
View File
@@ -4,7 +4,7 @@
#include <functional>
class ACIA {
class ACIA: public Pollable {
public:
void write(Memory::address, uint8_t);
uint8_t read(Memory::address);
@@ -37,7 +37,7 @@ public:
irq_handler = fn;
}
void poll_for_interrupt();
void poll();
// status bits
//
+19 -6
View File
@@ -129,19 +129,32 @@ void Arduino::begin() {
#endif
}
#define MAX_POLLABLE 5
static Pollable *devices[MAX_POLLABLE];
static uint8_t num_pollable = 0;
void Arduino::register_pollable(Pollable &p) {
devices[num_pollable++] = &p;
}
void Arduino::run(unsigned instructions) {
timers.run();
for (uint8_t i = 0; i < num_pollable; i++)
devices[i]->poll();
if (instructions > 0) {
#if DEBUGGING & DEBUG_CPU
if (_debug_handler()) {
char buf[256];
DBG_CPU(_cpu.status(buf, sizeof(buf)));
}
_cpu.run(1);
if (_debug_handler()) {
char buf[256];
DBG_CPU(_cpu.status(buf, sizeof(buf)));
}
_cpu.run(1);
#else
_cpu.run(instructions);
_cpu.run(instructions);
#endif
}
if (_cpu.halted())
_halted_handler();
+2
View File
@@ -41,6 +41,8 @@ public:
_halted_handler = handler;
}
void register_pollable(Pollable &);
void run(unsigned instructions = CPU_INSTRUCTIONS);
int interval_timer(uint32_t micros, std::function<void(void)> cb);
+3
View File
@@ -35,8 +35,11 @@
#if !defined(USE_OWN_KBD)
#define USE_PS2_KBD
#endif
#if defined(USE_PS2_KBD)
#define PS2_KBD_DATA 32
#define PS2_KBD_IRQ 33
#endif
// 64kB RAM
#define RAM_SIZE 0x10000u
+9 -2
View File
@@ -2,6 +2,11 @@
#include <functional>
class Pollable {
public:
virtual void poll() =0;
};
class Checkpoint {
public:
virtual size_t read(uint8_t *, int) =0;
@@ -13,8 +18,8 @@ public:
class Checkpointable {
public:
virtual void checkpoint(Checkpoint &) = 0;
virtual void restore(Checkpoint &) = 0;
virtual void checkpoint(Checkpoint &) =0;
virtual void restore(Checkpoint &) =0;
};
class CPU;
@@ -31,6 +36,8 @@ public:
_debug_handler = handler;
}
void register_pollable(Pollable &);
virtual int interval_timer(uint32_t micros, std::function<void(void)> cb) =0;
virtual int oneshot_timer(uint32_t micros, std::function<void(void)> cb) =0;
virtual void cancel_timer(int timer) =0;
+1
View File
@@ -4,6 +4,7 @@
#if defined(USE_PS2_KBD)
#include <PS2KeyRaw.h>
#include "machine.h"
#include "ps2_raw_kbd.h"
static PS2KeyRaw keyboard;
+1 -1
View File
@@ -13,7 +13,7 @@ inline bool is_ps2_shift(uint16_t scan) { return scan == 0x12 || scan == 0x59; }
inline bool is_ps2_ctrl(uint16_t scan) { return scan == 0x14; }
class ps2_raw_kbd {
class ps2_raw_kbd: public Pollable {
public:
ps2_raw_kbd(matrix_keyboard &m): _m(m) {}