summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-02-02 14:53:54 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2022-02-02 14:53:54 -0400
commit5aa885bb00a76a6be066a164187c8c2a065d6fab (patch)
tree106df8fdbeae95915bfb840b8f1979d94a2ce31b
parent83b312141ce29132f99a750a3f6149d152c4990f (diff)
sux.h: Added a `tick()` function.
This function will increment the cycle count by one everytime it's called. Later on, this'll help simplify I/O emulation, as I've considered implementing read, write, and tick callbacks for I/O.
-rw-r--r--sux.h24
1 files changed, 19 insertions, 5 deletions
diff --git a/sux.h b/sux.h
index efda8f0..18087a0 100644
--- a/sux.h
+++ b/sux.h
@@ -357,11 +357,25 @@ static void *memcopy(void *restrict dst, const void *restrict src, unsigned int
return dst;
}
-
-static /*inline*/ uint64_t read_value(struct sux *cpu, uint64_t reg, uint64_t address, uint8_t size, uint8_t inc_clk, uint8_t check_io) {
+static void tick(struct sux *cpu, uint8_t inc_clk) {
#if getclk
cpu->clk += inc_clk;
#endif
+ #if (IO || debug) && !branch
+ #if keypoll
+ pthread_mutex_lock(&mutex);
+ #endif
+ get_key(scr, 0, cpu->clk);
+ #if keypoll
+ pthread_mutex_unlock(&mutex);
+ #endif
+ #endif
+}
+
+static /*inline*/ uint64_t read_value(struct sux *cpu, uint64_t reg, uint64_t address, uint8_t size, uint8_t inc_clk, uint8_t check_io) {
+ if (inc_clk) {
+ tick(cpu, inc_clk);
+ }
size = (size > 7) ? 7 : size;
uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8));
if (address < mem_size) {
@@ -415,9 +429,9 @@ static /*inline*/ void write_value(struct sux *cpu, uint64_t value, uint64_t add
#endif
#endif
}
- #if getclk
- cpu->clk += inc_clk;
- #endif
+ if (inc_clk) {
+ tick(cpu, inc_clk);
+ }
}
static /*inline*/ uint64_t offset_addr(struct sux *cpu, uint64_t offset, uint8_t size, uint8_t inc_clk, uint8_t prefix) {