From a7d059f87798075986f02dbdc15d3318b4438e3f Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 9 Nov 2023 20:45:33 -0800 Subject: [PATCH] Changing jump opcodes to signed bcb --- src/gyoemu.c | 118 +++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/src/gyoemu.c b/src/gyoemu.c index f3341b2..6ca69c9 100644 --- a/src/gyoemu.c +++ b/src/gyoemu.c @@ -26,62 +26,78 @@ char *opcodes[] = { /* clang-format on */ void -disinstr(uc15 inst) +dislit(uc15 inst) +{ + putchar('#'), phep(inst >> 2, 5); +} + +void +disjmp(uc15 inst) { - if((inst & 0x3) == BCP) { - putchar('#'), phep(inst >> 2, 5); + switch((inst >> 2) & 0x3) { + case 0: /* JCN */ + putchar('?'), phep(inst >> 4, 5); return; - } else if((inst & 0x3) == BCZ) { - if(((inst >> 2) & 0x3) == 1) { - putchar('?'), phep(inst >> 4, 5); - return; - } else if(((inst >> 2) & 0x3) == 0) { - putchar('>'), phep(inst >> 4, 5); - return; - } - printf("call:"), phep(inst >> 4, 5); + case 1: /* JMP */ + putchar('>'), phep(inst >> 4, 5); return; - } else if((inst & 0x3) == BCN) { - /* (RST->PC,NOP,T->N) */ - switch((inst >> 2) & 0x3) { - case 0: putchar(';'); break; - case 2: putchar('%'); break; - } - /* (N,T,INS)->ACC */ - switch((inst >> 4) & 0x3) { - case 0: putchar('n'); break; - case 2: putchar('i'); break; - } - /* ALU */ - switch((inst >> 6) & 0xf) { - case 1: printf("CM"); break; - case 2: printf("UN"); break; - case 4: printf("BI"); break; - case 5: printf("AD"); break; - case 6: printf("LS"); break; - case 8: printf("RS"); break; - case 9: printf("ST"); break; - case 10: printf("ME"); break; - } - /* RST */ - if(((inst >> 14) & 0x3) == 0) printf("[r"); - switch((inst >> 12) & 0x3) { - case 0: printf("-"); break; - case 2: printf("+"); break; - } - /* DST */ - if(((inst >> 14) & 0x3) == 2) printf("[d"); - switch((inst >> 10) & 0x3) { - case 0: printf("-"); break; - case 2: printf("+"); break; - } - /* OUT */ - switch((inst >> 16) & 0x3) { - case 0: printf("/"); break; - case 2: printf("!"); break; - } + case 2: /* JSR */ + printf("call:"), phep(inst >> 4, 5); return; } +} + +void +disopc(uc15 inst) +{ + /* (RST->PC,NOP,T->N) */ + switch((inst >> 2) & 0x3) { + case 0: putchar(';'); break; + case 2: putchar('%'); break; + } + /* (N,T,INS)->ACC */ + switch((inst >> 4) & 0x3) { + case 0: putchar('n'); break; + case 2: putchar('i'); break; + } + /* ALU */ + switch((inst >> 6) & 0xf) { + case 1: printf("CM"); break; + case 2: printf("UN"); break; + case 4: printf("BI"); break; + case 5: printf("AD"); break; + case 6: printf("LS"); break; + case 8: printf("RS"); break; + case 9: printf("ST"); break; + case 10: printf("ME"); break; + } + /* RST */ + if(((inst >> 14) & 0x3) == 0) printf("[r"); + switch((inst >> 12) & 0x3) { + case 0: printf("-"); break; + case 2: printf("+"); break; + } + /* DST */ + if(((inst >> 14) & 0x3) == 2) printf("[d"); + switch((inst >> 10) & 0x3) { + case 0: printf("-"); break; + case 2: printf("+"); break; + } + /* OUT */ + switch((inst >> 16) & 0x3) { + case 0: printf("/"); break; + case 2: printf("!"); break; + } +} + +void +disinstr(uc15 inst) +{ + switch(inst & 0x3) { + case BCP: dislit(inst); return; + case BCZ: disjmp(inst); return; + case BCN: disopc(inst); return; + } printf("Unknown instruciton\n"); } -- 2.45.2