mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-26 05:52:59 +01:00
change everything to int16 and also hopefully fix makefile
This commit is contained in:
1 parent
d87e7acb1f
commit
4bc84ed51e
2 files changed
+13
-23
No files matched your search
@@ -1,3 +1,3 @@
|
|||||||
all:
|
all:
|
||||||
gcc main.c -o main
|
gcc main.c -o main.exe
|
||||||
./main
|
./main.exe
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef uint16_t reg_t;
|
typedef int16_t reg_t;
|
||||||
|
|
||||||
typedef enum INSTRUCTION_E {
|
typedef enum INSTRUCTION_E {
|
||||||
NOP,
|
NOP,
|
||||||
@@ -151,7 +151,7 @@ struct cpu_t {
|
|||||||
} cpu;
|
} cpu;
|
||||||
|
|
||||||
struct ram_t {
|
struct ram_t {
|
||||||
uint16_t memory[0x10000];
|
int16_t memory[0x10000];
|
||||||
reg_t mar;
|
reg_t mar;
|
||||||
reg_t mdr;
|
reg_t mdr;
|
||||||
} ram;
|
} ram;
|
||||||
@@ -161,20 +161,10 @@ int sext(uint16_t val, uint16_t length) {
|
|||||||
return (val << n) >> n;
|
return (val << n) >> n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCC(uint16_t val) {
|
void updateCC(int16_t val) {
|
||||||
if (val < 0) {
|
cpu.cc[N] = val < 0;
|
||||||
cpu.cc[N] = true;
|
cpu.cc[Z] = val == 0;
|
||||||
cpu.cc[Z] = false;
|
cpu.cc[P] = val > 0;
|
||||||
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 fetch() {
|
void fetch() {
|
||||||
@@ -246,7 +236,7 @@ void execute() {
|
|||||||
cpu.alu.accumulator = cpu.regFile[(cpu.ir >> 4) & 0x7] & cpu.regFile[(cpu.ir >> 1) & 0x7];
|
cpu.alu.accumulator = cpu.regFile[(cpu.ir >> 4) & 0x7] & cpu.regFile[(cpu.ir >> 1) & 0x7];
|
||||||
break;
|
break;
|
||||||
case 1:
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (cpu.ir & 0x1F) {
|
if (cpu.ir & 0x1F) {
|
||||||
@@ -788,11 +778,11 @@ int assemble() {
|
|||||||
|
|
||||||
int conditionCodes = 0;
|
int conditionCodes = 0;
|
||||||
for (int i = 0; i < l; i++) {
|
for (int i = 0; i < l; i++) {
|
||||||
if (tokens[1][i] == 'n') {
|
if (tokens[2][i] == 'n') {
|
||||||
conditionCodes |= 0b100;
|
conditionCodes |= 0b100;
|
||||||
} else if (tokens[1][i] == 'z') {
|
} else if (tokens[2][i] == 'z') {
|
||||||
conditionCodes |= 0b010;
|
conditionCodes |= 0b010;
|
||||||
} else if (tokens[1][i] == 'p') {
|
} else if (tokens[2][i] == 'p') {
|
||||||
conditionCodes |= 0b001;
|
conditionCodes |= 0b001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -854,7 +844,7 @@ int assemble() {
|
|||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r0 = parseReg(tokens[1]);
|
int r0 = parseReg(tokens[2]);
|
||||||
if (r0 == -1) {
|
if (r0 == -1) {
|
||||||
printf("Wrong tokens on line %d!\n", lineCount);
|
printf("Wrong tokens on line %d!\n", lineCount);
|
||||||
return -3;
|
return -3;
|
||||||
|
|||||||
Reference in new issue
Block a user