From 182d9143ad2b12bc087ad82465acc687e221137a Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 1 Sep 2020 19:20:17 -0400 Subject: [PATCH] Feature additions requested by @reid_dc. --- README.md | 15 +++++++++++++-- __tests__/buttons.spec.js | 2 +- package.json | 8 ++++---- src/components/Nav.svelte | 4 ++-- src/node_modules/buttons.js | 4 ++-- src/routes/manual.svelte | 16 ++++++++-------- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 95677b0..127faa0 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ to be a billion dollar project. # The Machine Buttons is a simple stack machine with arbitrary registers and a limited amount of power known as -"ticks" of which you have 128. What does that mean in practice? +"clicks" of which you have 128. What does that mean in practice? 1. You do most of your calculations by working a stack with PUSH and POP. 2. You can store things in a register and name that register anything you want. 3. Every operation takes 1 tick to process. -4. You have only 128 ticks to complete your calculation. +4. You have only 128 clicks to complete your calculation. 5. You can do all of this with only a single mouse with two buttons. 6. The data type for the stack is whatever JavaScript does with numbers. @@ -100,3 +100,14 @@ This software is fully Copyright (C) Zed A. Shaw 2020. It's like a painting at look at it and admire its beauty, but you don't own it and can't take it home with you. +# Feature Requests + +Currently have the following feature requests: + +1. SWAP operation would simplify a lot of calculations. +2. A share this code link to share the code with others. +3. PEEK and POKE for writing to a RAM spot. +4. IN and OUT for reading and writing numbers. +5. Edit it as CODE instead of clicking if you want. +6. Better line number display. + diff --git a/__tests__/buttons.spec.js b/__tests__/buttons.spec.js index 715caf0..1d799c9 100644 --- a/__tests__/buttons.spec.js +++ b/__tests__/buttons.spec.js @@ -50,7 +50,7 @@ it('Can do modulus', () => { ]) }) -it('Can loop until the end of ticks', () => { +it('Can loop until the end of clicks', () => { run_code(43, [ ['PUSH', 1], ['PUSH', 1], diff --git a/package.json b/package.json index ef351d9..4d92839 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,6 @@ "svelte-preprocess": "^4.1.2" }, "devDependencies": { - "npm-run-all": "^4.1.5", - "sapper": "^0.28.0", - "svelte": "^3.17.3", "@babel/core": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-transform-runtime": "^7.0.0", @@ -38,8 +35,11 @@ "@rollup/plugin-commonjs": "^14.0.0", "@rollup/plugin-node-resolve": "^8.0.0", "@rollup/plugin-replace": "^2.2.0", + "npm-run-all": "^4.1.5", "rollup": "^2.3.4", "rollup-plugin-svelte": "^6.0.0", - "rollup-plugin-terser": "^7.0.0" + "rollup-plugin-terser": "^7.0.0", + "sapper": "^0.28.0", + "svelte": "^3.17.3" } } diff --git a/src/components/Nav.svelte b/src/components/Nav.svelte index c85e347..c17352f 100644 --- a/src/components/Nav.svelte +++ b/src/components/Nav.svelte @@ -36,8 +36,8 @@ - - + + diff --git a/src/node_modules/buttons.js b/src/node_modules/buttons.js index 7565883..64cbc39 100644 --- a/src/node_modules/buttons.js +++ b/src/node_modules/buttons.js @@ -6,7 +6,7 @@ class ButtonMachine { this.stack = []; this.ip = 0; this.code = code; - this.max_ticks = 128; + this.max_clicks = 128; this.tick = 0; this.registers = {}; this.error = ''; @@ -161,7 +161,7 @@ class ButtonMachine { } get running() { - return this.halted === false && this.tick < this.max_ticks && this.ip < this.code.length && this.cur_op !== undefined; + return this.halted === false && this.tick < this.max_clicks && this.ip < this.code.length && this.cur_op !== undefined; } next() { diff --git a/src/routes/manual.svelte b/src/routes/manual.svelte index c557971..a8d9154 100644 --- a/src/routes/manual.svelte +++ b/src/routes/manual.svelte @@ -39,7 +39,7 @@
-

The Manual

+

Pushing BUTTONS

BUTTONS is a tiny computer that you can program entirely with a 2 button mouse by clicking on buttons. @@ -57,7 +57,7 @@ plates done plates.

You would probably take the first plate off the top of the stack of - plates, write the number 1 on it, and then set it to the + new plates, write the number 1 on it, and then set it to the side in the done plates stack. You can't put it back on the new plates stack of plates because then you wouldn't make your way through the plates. You take one off the top of @@ -67,7 +67,7 @@ going through all 10 plates.

You then look over at your stack of numbered done plates - and you're happy, but the plate on top is numbered 20. + and you're happy, but the plate on top is numbered 10. You've stacked them in reverse, and you probably need to re-stack them in order. How would you do that? Well, you simply take one off the top of the done stack and put it onto another stack (let's call @@ -159,13 +159,13 @@ When you see the 0: at the front of the line that's the line number. It's not code, just me being lazy and not wanting to implement line numbers in fancy CSS. -

TICKS

+

CLICKS

Before we get into loops I have to warn you that BUTTONS is not a very powerful computer. It can only perform 128 - operations before it runs out of energy called TICKS. If - your computer runs this many ticks then BUTTONS will stop - running and give up.

+ operations before it runs out of energy called CLICKS. If + your program runs for 128 many clicks then BUTTONS will stop + running and give up because it is tired.

Looping with JUMP

@@ -216,7 +216,7 @@

You run it, thinking it will stop at zero, and instead BUTTONS does exactly what you told it to do and keeps going - until it runs out of TICKS, leaving .... -32 on + until it runs out of CLICKS, leaving .... -32 on the top? What?!

The reason is you have no way to tell BUTTONS when to stop. You can tell it to do the math and where to JUMP but you have no way to tell buttons "when you reach 0 on the STACK you should stop." You do this with the JZ operation which means "JUMP if Zero". It simply looks at the top of the STACK and if that's 0 then it does a JUMP to where you want. This is doing a test of the top of stack, and a jump. Now we can rewrite our program like this: