summaryrefslogtreecommitdiff
path: root/sux.h
diff options
context:
space:
mode:
Diffstat (limited to 'sux.h')
-rw-r--r--sux.h88
1 files changed, 47 insertions, 41 deletions
diff --git a/sux.h b/sux.h
index 8dbc064..509a6bc 100644
--- a/sux.h
+++ b/sux.h
@@ -77,56 +77,62 @@ static void *memcopy(void *restrict dst, const void *restrict src, unsigned int
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 (IO || debug) && !branch
- #if keypoll
- pthread_mutex_lock(&mutex);
- #endif
- if (check_io) {
- io(address, 1);
- }
- #if keypoll
- pthread_mutex_unlock(&mutex);
- #endif
- #endif
#if getclk
cpu->clk += inc_clk;
#endif
size = (size > 7) ? 7 : size;
- #if 1
- if (size < 7) {
- uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8));
- return (reg & ~mask) | (*(uint64_t *)(addr+address) & mask);
+ uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8));
+ if (address < mem_size) {
+ #if (IO || debug) && !branch
+ #if keypoll
+ pthread_mutex_lock(&mutex);
+ #endif
+ if (check_io) {
+ io(address, 1);
+ }
+ #if keypoll
+ pthread_mutex_unlock(&mutex);
+ #endif
+ #endif
+ #if 1
+ if (size < 7) {
+ return (reg & ~mask) | (*(uint64_t *)(addr+address) & mask);
+ } else {
+ return *(uint64_t *)(addr+address);
+ }
+ #else
+ return *(uint64_t *)memcopy(&reg, addr+address, size+1);
+ #endif
} else {
- return *(uint64_t *)(addr+address);
+ return (size < 7) ? (reg & ~mask) | (mask) : mask;
}
- #else
- return *(uint64_t *)memcopy(&reg, addr+address, size+1);
- #endif
}
static inline void write_value(struct sux *cpu, uint64_t value, uint64_t address, uint8_t size, uint8_t inc_clk, uint8_t check_io) {
- size = (size > 7) ? 7 : size;
- #if 1
- if (size < 7) {
- uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8));
- *(uint64_t *)(addr+address) = (*(uint64_t *)(addr+address) & ~mask) | (value & mask);
- } else {
- *(uint64_t *)(addr+address) = value;
+ if (address < mem_size) {
+ size = (size > 7) ? 7 : size;
+ #if 1
+ if (size < 7) {
+ uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8));
+ *(uint64_t *)(addr+address) = (*(uint64_t *)(addr+address) & ~mask) | (value & mask);
+ } else {
+ *(uint64_t *)(addr+address) = value;
+ }
+ #else
+ memcopy(addr+address, &value, size+1);
+ #endif
+ #if (IO || debug) && !branch
+ #if keypoll
+ pthread_mutex_lock(&mutex);
+ #endif
+ if (check_io) {
+ io(address, 0);
+ }
+ #if keypoll
+ pthread_mutex_unlock(&mutex);
+ #endif
+ #endif
}
- #else
- memcopy(addr+address, &value, size+1);
- #endif
- #if (IO || debug) && !branch
- #if keypoll
- pthread_mutex_lock(&mutex);
- #endif
- if (check_io) {
- io(address, 0);
- }
- #if keypoll
- pthread_mutex_unlock(&mutex);
- #endif
- #endif
#if getclk
cpu->clk += inc_clk;
#endif
@@ -276,7 +282,7 @@ static inline uint64_t sbc(struct sux *cpu, uint64_t reg, uint64_t value, uint8_
setflag(sum == 0, Z);
setflag(sum >> 63, N);
setflag(((reg^value) >> 63) && ((reg^sum) >> 63), V);
- setflag((sum > value), C);
+ setflag((sum < value), C);
return sum;
}