From cbad8aabbc82efbe7a49572a2da74224ae9c9f85 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 1 Dec 2019 17:40:41 -0500 Subject: 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. --- sux.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'sux.c') 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(); -- cgit v1.2.3-13-gbd6f