mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-21 12: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
+15
-25
No files matched your search
@@ -1,3 +1,3 @@
|
||||
all:
|
||||
gcc main.c -o main
|
||||
./main
|
||||
all:
|
||||
gcc main.c -o main.exe
|
||||
./main.exe
|
||||
@@ -104,7 +104,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user