diff options
Diffstat (limited to 'instructions')
39 files changed, 0 insertions, 406 deletions
diff --git a/instructions/add.ts b/instructions/add.ts deleted file mode 100644 index 93a5018..0000000 --- a/instructions/add.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] + this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/and.ts b/instructions/and.ts deleted file mode 100644 index 77a28e0..0000000 --- a/instructions/and.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] & this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/clr.ts b/instructions/clr.ts deleted file mode 100644 index bbbe422..0000000 --- a/instructions/clr.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.returnStack.pop(); - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/cmp.ts b/instructions/cmp.ts deleted file mode 100644 index 1b2db94..0000000 --- a/instructions/cmp.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, val]: number[]) { - const r = this.lib.parseReg(reg) - this.returnFlag = +(this.registers[r] == +val) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/cmr.ts b/instructions/cmr.ts deleted file mode 100644 index c92d939..0000000 --- a/instructions/cmr.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.lib.parseReg(reg2) - this.returnFlag = +(this.registers[r1] == this.registers[r2]) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/crp.ts b/instructions/crp.ts deleted file mode 100644 index c334ed5..0000000 --- a/instructions/crp.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2, val]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.lib.parseReg(reg2) - this.registers[r1] = +(this.registers[r2] == val) - }, - args: 3 -} \ No newline at end of file diff --git a/instructions/crr.ts b/instructions/crr.ts deleted file mode 100644 index cea6995..0000000 --- a/instructions/crr.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2, reg3]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.lib.parseReg(reg2) - const r3 = this.lib.parseReg(reg3) - this.registers[r1] = +(this.registers[r2] == this.registers[r3]) - }, - args: 3 -} \ No newline at end of file diff --git a/instructions/dbg.ts b/instructions/dbg.ts deleted file mode 100644 index 6781fbf..0000000 --- a/instructions/dbg.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [msg]: string[]) { - console.log(msg, this.mem, this.registers, this.returnFlag, this.returnStack); - const b = new Uint8Array(1); - Deno.stdin.readSync(b) - if (b[0] == 'c'.charCodeAt(0)) { - this.programPointer = 0xFFFF - 1 - } - }, - args: 1 -} \ No newline at end of file diff --git a/instructions/dec.ts b/instructions/dec.ts deleted file mode 100644 index df46769..0000000 --- a/instructions/dec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, by]: number[]) { - const r = this.lib.parseReg(reg); - this.registers[r] -= by - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/decr.ts b/instructions/decr.ts deleted file mode 100644 index 12e7fd9..0000000 --- a/instructions/decr.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1); - const r2 = this.lib.parseReg(reg2); - this.registers[r1] -= this.registers[r2] - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/div.ts b/instructions/div.ts deleted file mode 100644 index dbad7e1..0000000 --- a/instructions/div.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = Math.floor(this.registers[0] / this.registers[1]) - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/halt.ts b/instructions/halt.ts deleted file mode 100644 index 4685f2b..0000000 --- a/instructions/halt.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - // this.programPointer = 0xFFFF - 1 - this.halted = true - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/inc.ts b/instructions/inc.ts deleted file mode 100644 index 180546e..0000000 --- a/instructions/inc.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, by]: number[]) { - const r = this.lib.parseReg(reg); - this.registers[r] += by - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/incr.ts b/instructions/incr.ts deleted file mode 100644 index 5f1d529..0000000 --- a/instructions/incr.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1); - const r2 = this.lib.parseReg(reg2); - this.registers[r1] += this.registers[r2] - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/jmp.ts b/instructions/jmp.ts deleted file mode 100644 index 00db338..0000000 --- a/instructions/jmp.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [addr]: string[]) { - this.programPointer = Number(addr) - 1 - }, - args: 1 -} \ No newline at end of file diff --git a/instructions/jmr.ts b/instructions/jmr.ts deleted file mode 100644 index 25f5334..0000000 --- a/instructions/jmr.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [addr]: string[]) { - this.returnStack.push(this.programPointer) - this.programPointer = Number(addr) - 1 - }, - args: 1 -} \ No newline at end of file diff --git a/instructions/jnz.ts b/instructions/jnz.ts deleted file mode 100644 index e5b539f..0000000 --- a/instructions/jnz.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [addr]: string[]) { - if (this.returnFlag == 0) return; - this.programPointer = +addr - 1 - }, - args: 1 -} \ No newline at end of file diff --git a/instructions/jnzr.ts b/instructions/jnzr.ts deleted file mode 100644 index 00f1569..0000000 --- a/instructions/jnzr.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.lib.parseReg(reg2) - if (this.registers[r1] == 0) return; - this.programPointer = this.registers[r2] - 1 - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/jz.ts b/instructions/jz.ts deleted file mode 100644 index 0e105b3..0000000 --- a/instructions/jz.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [addr]: string[]) { - if (this.returnFlag != 0) return; - this.programPointer = +addr - 1 - }, - args: 1 -} \ No newline at end of file diff --git a/instructions/ld.ts b/instructions/ld.ts deleted file mode 100644 index 977f343..0000000 --- a/instructions/ld.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, addr]: number[]) { - const r = this.lib.parseReg(reg) - this.registers[r] = this.getMem(Number(addr)) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/ldm.ts b/instructions/ldm.ts deleted file mode 100644 index c82425a..0000000 --- a/instructions/ldm.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, addr]: number[]) { - this.registers[this.lib.parseReg(reg)] = this.getMem(this.getMem(Number(addr))) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/ldr.ts b/instructions/ldr.ts deleted file mode 100644 index 724b94c..0000000 --- a/instructions/ldr.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - this.registers[this.lib.parseReg(reg1)] = this.getMem(this.registers[this.lib.parseReg(reg2)]) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/mod.ts b/instructions/mod.ts deleted file mode 100644 index 24b96d5..0000000 --- a/instructions/mod.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] % this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/mul.ts b/instructions/mul.ts deleted file mode 100644 index b625a07..0000000 --- a/instructions/mul.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] * this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/not.ts b/instructions/not.ts deleted file mode 100644 index 6416a5c..0000000 --- a/instructions/not.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = ~this.registers[0] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/or.ts b/instructions/or.ts deleted file mode 100644 index 5a8b593..0000000 --- a/instructions/or.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] | this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/put.ts b/instructions/put.ts deleted file mode 100644 index a35806e..0000000 --- a/instructions/put.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, data]: number[]) { - const r = this.lib.parseReg(reg) - this.registers[r] = Number(data) ?? 0 - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/ret.ts b/instructions/ret.ts deleted file mode 100644 index 6a42313..0000000 --- a/instructions/ret.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - const ret = this.returnStack.pop(); - if (ret == undefined) throw 'whar' - this.programPointer = ret - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/sbc.ts b/instructions/sbc.ts deleted file mode 100644 index 928aa61..0000000 --- a/instructions/sbc.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1); - const r2 = this.lib.parseReg(reg2); - this.registers[r1] -= this.registers[r2] - this.returnFlag - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/shl.ts b/instructions/shl.ts deleted file mode 100644 index 68345bb..0000000 --- a/instructions/shl.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, by]: number[]) { - const r = this.lib.parseReg(reg); - this.registers[r] = this.registers[r] << by - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/shr.ts b/instructions/shr.ts deleted file mode 100644 index 15e9345..0000000 --- a/instructions/shr.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, by]: number[]) { - const r = this.lib.parseReg(reg); - this.registers[r] = this.registers[r] >> by - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/srm.ts b/instructions/srm.ts deleted file mode 100644 index b3c71fa..0000000 --- a/instructions/srm.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, addr]: number[]) { - this.setMem(this.getMem(Number(addr)), this.registers[this.lib.parseReg(reg)]) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/srr.ts b/instructions/srr.ts deleted file mode 100644 index 0a7e5c6..0000000 --- a/instructions/srr.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.registers[this.lib.parseReg(reg2)] - this.setMem(Number(r2), this.registers[r1] & 0xFFFF) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/str.ts b/instructions/str.ts deleted file mode 100644 index bdcae63..0000000 --- a/instructions/str.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg, addr]: number[]) { - const r = this.lib.parseReg(reg) - this.setMem(Number(addr), this.registers[r] & 0xFFFF) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/sub.ts b/instructions/sub.ts deleted file mode 100644 index 8e4d894..0000000 --- a/instructions/sub.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] - this.registers[1] - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/swp.ts b/instructions/swp.ts deleted file mode 100644 index 48ee9b6..0000000 --- a/instructions/swp.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const r1 = this.lib.parseReg(reg1) - const r2 = this.lib.parseReg(reg2) - const data1 = Number(this.registers[r1]) - const data2 = Number(this.registers[r2]) - this.registers[r1] = data2 - this.registers[r2] = data1 - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/swpm.ts b/instructions/swpm.ts deleted file mode 100644 index f4856a2..0000000 --- a/instructions/swpm.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC, [reg1, reg2]: number[]) { - const addr1 = this.registers[this.lib.parseReg(reg1)] - const addr2 = this.registers[this.lib.parseReg(reg2)] - const data1 = 0 + this.getMem(+addr1) - const data2 = 0 + this.getMem(+addr2) - this.setMem(+addr1, data2) - this.setMem(+addr2, data1) - }, - args: 2 -} \ No newline at end of file diff --git a/instructions/sys.ts b/instructions/sys.ts deleted file mode 100644 index 5131bf2..0000000 --- a/instructions/sys.ts +++ /dev/null @@ -1,55 +0,0 @@ -// deno-lint-ignore-file no-case-declarations no-process-globals -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - switch (this.registers[0]) { - case 0: - switch (this.registers[1]) { - case 0: - const data = new Uint8Array(1024) - const len = Deno.stdin.readSync(data) ?? 0 - let i = 0; - while (i < len) { - this.mem[this.registers[2] + i] = data[i] - i++ - } - this.registers[0] = len - this.mem[this.registers[2] + i] = 0 - break; - - default: - throw 'unknown fd' - } - break; - case 1: - const writeBuff = []; - let i = this.registers[2]; - while (this.mem[i] != 0 && i <= this.mem.length) { - writeBuff.push(this.mem[i]); - i++ - } - switch (this.registers[1]) { - case 1: - process.stdout.write(writeBuff.map(a => String.fromCharCode(a)).join('')) - break; - - case 2: - process.stderr.write(writeBuff.map(a => String.fromCharCode(a)).join('')) - break; - - default: - throw 'unknown fd' - } - break; - - case 2: - Deno.stdin.setRaw(this.registers[1] ? true : false); - break; - - default: - throw 'unknown syscall id ' + this.registers[0] - } - }, - args: 0 -} \ No newline at end of file diff --git a/instructions/xor.ts b/instructions/xor.ts deleted file mode 100644 index 4cccecd..0000000 --- a/instructions/xor.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PC } from "../pc.ts"; - -export default { - function(this: PC) { - this.registers[2] = this.registers[0] ^ this.registers[1] - }, - args: 0 -} \ No newline at end of file |