From 4bc84ed51ed807e8d7f0a3d7ca96150050dd2d3b Mon Sep 17 00:00:00 2001 From: mrbobbyguy <84521318+somerandomviolinkid@users.noreply.github.com> Date: Sun, 6 Sep 2026 11:50:07 -0500 Subject: [PATCH] change everything to int16 and also hopefully fix makefile --- Makefile | 6 +++--- main.c | 34 ++++++++++++---------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index de755d9..55175f3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -all: - gcc main.c -o main - ./main +all: + gcc main.c -o main.exe + ./main.exe \ No newline at end of file diff --git a/main.c b/main.c index f75272c..92812fb 100644 --- a/main.c +++ b/main.c @@ -104,7 +104,7 @@ #include #include -typedef uint16_t reg_t; +typedef int16_t reg_t; typedef enum INSTRUCTION_E { NOP, @@ -151,7 +151,7 @@ struct cpu_t { } cpu; struct ram_t { - uint16_t memory[0x10000]; + int16_t memory[0x10000]; reg_t mar; reg_t mdr; } ram; @@ -161,20 +161,10 @@ int sext(uint16_t val, uint16_t length) { return (val << n) >> n; } -void updateCC(uint16_t val) { - if (val < 0) { - cpu.cc[N] = true; - cpu.cc[Z] = false; - cpu.cc[P] = false; - } else if (val == 0) { - cpu.cc[N] = false; - cpu.cc[Z] = true; - cpu.cc[P] = false; - } else { - cpu.cc[N] = false; - cpu.cc[Z] = false; - cpu.cc[P] = true; - } +void updateCC(int16_t val) { + cpu.cc[N] = val < 0; + cpu.cc[Z] = val == 0; + cpu.cc[P] = val > 0; } void fetch() { @@ -246,7 +236,7 @@ void execute() { cpu.alu.accumulator = cpu.regFile[(cpu.ir >> 4) & 0x7] & cpu.regFile[(cpu.ir >> 1) & 0x7]; break; case 1: - cpu.alu.accumulator = cpu.regFile[(cpu.ir >> 4) & 0x7] & sext(cpu.ir & 0xF, 4); + cpu.alu.accumulator = cpu.regFile[(cpu.ir >> 4) & 0x7] & sext(cpu.ir & 0x1, 4); break; case 2: if (cpu.ir & 0x1F) { @@ -788,11 +778,11 @@ int assemble() { int conditionCodes = 0; for (int i = 0; i < l; i++) { - if (tokens[1][i] == 'n') { + if (tokens[2][i] == 'n') { conditionCodes |= 0b100; - } else if (tokens[1][i] == 'z') { + } else if (tokens[2][i] == 'z') { conditionCodes |= 0b010; - } else if (tokens[1][i] == 'p') { + } else if (tokens[2][i] == 'p') { conditionCodes |= 0b001; } } @@ -854,7 +844,7 @@ int assemble() { return -4; } - int r0 = parseReg(tokens[1]); + int r0 = parseReg(tokens[2]); if (r0 == -1) { printf("Wrong tokens on line %d!\n", lineCount); return -3; @@ -942,4 +932,4 @@ int main(int argc, char** argv) { } return 0; -} +} \ No newline at end of file