summaryrefslogtreecommitdiff
path: root/sux.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2019-12-01 17:40:41 -0500
committermrb0nk500 <b0nk@b0nk.xyz>2019-12-02 18:10:41 -0500
commitcbad8aabbc82efbe7a49572a2da74224ae9c9f85 (patch)
treee97b1ab35208bc3e4d633f235d875fd4c69d039f /sux.c
parentca89989d057a19b647514656d96d00ff23be9640 (diff)
Added the ability to disable the prefix byte.
Any instructions that either have a register size of 8 bits, use implied addressing, or branch can save a byte by disabling the prefix byte. It does this by checking if the first three bits are all set to 1. If true, then it will treat it as a prefix byte, otherwise, it will treat it as an opcode.
Diffstat (limited to 'sux.c')
-rw-r--r--sux.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/sux.c b/sux.c
index f42c0da..7bb8661 100644
--- a/sux.c
+++ b/sux.c
@@ -6,7 +6,8 @@
int run(struct sux *cpu, uint8_t prefix, uint8_t opcode, uint8_t thread) {
uint64_t address;
- uint8_t regsize = (1 << (prefix & 3));
+ uint8_t rs = (prefix & 0x30) >> 4;
+ uint8_t regsize = (1 << rs);
uint8_t tmp;
address = cpu->pc[thread];
#if !bench
@@ -17,7 +18,10 @@ int run(struct sux *cpu, uint8_t prefix, uint8_t opcode, uint8_t thread) {
fflush(stdout);
#endif
cpu->pc[thread]++;
- clk++;
+ if (ibcount > 8) {
+ clk++;
+ ibcount = 0;
+ }
switch(opcode) {
case CPS: /* Clear Processor Status. */
for (uint8_t i = 0; i < 8; i++) {
@@ -366,6 +370,7 @@ int main(int argc, char **argv) {
cpu.x[0] = 0;
cpu.y[0] = 0;
cpu.sp = 0xFFFF;
+ ibcount = 0;
addr = malloc(8*0x04000000);
int v = 0;
if (asmmon() == 2)
@@ -416,13 +421,21 @@ int main(int argc, char **argv) {
st = clock();
#endif
while (!end) {
- prefix = addr[cpu.pc[0]++];
+ prefix = addr[cpu.pc[0]];
+ if ((prefix & 0x07) == 0x07) {
+ cpu.pc[0]++;
+ ibcount++;
+ }
opcode = addr[cpu.pc[0]];
+ ibcount++;
#if !bench
printf("\033[%uH\033[2K", lines);
lines++;
#endif
- run(&cpu, prefix, opcode, 0);
+ if ((prefix & 0x07) == 0x07)
+ run(&cpu, prefix-7, opcode, 0);
+ else
+ run(&cpu, 0, opcode, 0);
#if !bench
if (lines > 24)
lines = 2;
@@ -431,9 +444,8 @@ int main(int argc, char **argv) {
t0 = ((double)clock() - (double)st)/(double)CLOCKS_PER_SEC;
#endif
inst++;
-
#if !bench
- printf("\033[HInstructions executed: %llu, Clock cycles: %llu\n", inst, clk);
+ printf("\033[HInstruction bytes: %x, Instructions executed: %llu, Clock cycles: %llu\n", ibcount, inst, clk);
fflush(stdout);
#endif
#if bench
@@ -441,6 +453,8 @@ int main(int argc, char **argv) {
end = 1;
}
#endif
+ if (ibcount >= 7)
+ ibcount = 0;
}
#if bench
en = (double)clock();