Feature additions requested by @reid_dc.

master v1
Zed A. Shaw 4 years ago
parent 1cd84af248
commit 182d9143ad
  1. 15
      README.md
  2. 2
      __tests__/buttons.spec.js
  3. 8
      package.json
  4. 4
      src/components/Nav.svelte
  5. 4
      src/node_modules/buttons.js
  6. 16
      src/routes/manual.svelte

@ -14,12 +14,12 @@ to be a billion dollar project.
# The Machine # The Machine
Buttons is a simple stack machine with arbitrary registers and a limited amount of power known as 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. 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. 2. You can store things in a register and name that register anything you want.
3. Every operation takes 1 tick to process. 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. 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. 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. 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.

@ -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, [ run_code(43, [
['PUSH', 1], ['PUSH', 1],
['PUSH', 1], ['PUSH', 1],

@ -26,9 +26,6 @@
"svelte-preprocess": "^4.1.2" "svelte-preprocess": "^4.1.2"
}, },
"devDependencies": { "devDependencies": {
"npm-run-all": "^4.1.5",
"sapper": "^0.28.0",
"svelte": "^3.17.3",
"@babel/core": "^7.0.0", "@babel/core": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0", "@babel/plugin-transform-runtime": "^7.0.0",
@ -38,8 +35,11 @@
"@rollup/plugin-commonjs": "^14.0.0", "@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.0", "@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-replace": "^2.2.0", "@rollup/plugin-replace": "^2.2.0",
"npm-run-all": "^4.1.5",
"rollup": "^2.3.4", "rollup": "^2.3.4",
"rollup-plugin-svelte": "^6.0.0", "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"
} }
} }

@ -36,8 +36,8 @@
<a data-testid='nav-home-icon' rel="prefetch" class:btn-link="{ segment != undefined }" class="btn" href="/" alt="Home" aria-label="Home"> <a data-testid='nav-home-icon' rel="prefetch" class:btn-link="{ segment != undefined }" class="btn" href="/" alt="Home" aria-label="Home">
<Icon name="home" size="32" tooltip="Home" tooltip_bottom={true} light={true}/> <Icon name="home" size="32" tooltip="Home" tooltip_bottom={true} light={true}/>
</a> </a>
<a data-testid='nav-manual-icon' class:btn-link="{ segment != 'manual' }" class="btn" href="manual" alt="Read the manual" aria-label="Read the blog"> <a data-testid='nav-manual-icon' class:btn-link="{ segment != 'manual' }" class="btn" href="manual" alt="Read the manual" aria-label="Read the manual">
<Icon name="book-open" size="32" tooltip="Blog" tooltip_bottom={true} light={true} /> <Icon name="book-open" size="32" tooltip="Manual" tooltip_bottom={true} light={true} />
</a> </a>
</section> </section>
</header> </header>

4
src/node_modules/buttons.js generated vendored

@ -6,7 +6,7 @@ class ButtonMachine {
this.stack = []; this.stack = [];
this.ip = 0; this.ip = 0;
this.code = code; this.code = code;
this.max_ticks = 128; this.max_clicks = 128;
this.tick = 0; this.tick = 0;
this.registers = {}; this.registers = {};
this.error = ''; this.error = '';
@ -161,7 +161,7 @@ class ButtonMachine {
} }
get running() { 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() { next() {

@ -39,7 +39,7 @@
<div class="columns"> <div class="columns">
<div class="column col-12"> <div class="column col-12">
<h1>The Manual</h1> <h1>Pushing BUTTONS</h1>
<p> <p>
<code>BUTTONS</code> is a tiny computer that you can program entirely with a 2 button mouse by clicking on buttons. <code>BUTTONS</code> is a tiny computer that you can program entirely with a 2 button mouse by clicking on buttons.
@ -57,7 +57,7 @@
plates <code>done plates</code>.</p> plates <code>done plates</code>.</p>
<p>You would probably take the first plate off the top of the stack of <p>You would probably take the first plate off the top of the stack of
plates, write the number <code>1</code> on it, and then set it to the <code>new plates</code>, write the number <code>1</code> on it, and then set it to the
side in the <code>done plates</code> stack. You can't put it back on the side in the <code>done plates</code> stack. You can't put it back on the
<code>new plates</code> stack of plates because then you wouldn't make <code>new plates</code> stack of plates because then you wouldn't make
your way through the plates. You take one off the <code>top</code> of your way through the plates. You take one off the <code>top</code> of
@ -67,7 +67,7 @@
going through all 10 plates.</p> going through all 10 plates.</p>
<p>You then look over at your stack of numbered <code>done plates</code> <p>You then look over at your stack of numbered <code>done plates</code>
and you're happy, but the plate on <code>top</code> is numbered 20. and you're happy, but the plate on <code>top</code> is numbered 10.
You've stacked them in reverse, and you probably need to re-stack them in 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 order. How would you do that? Well, you simply take one off the top of
the <code>done stack</code> and put it onto another stack (let's call the <code>done stack</code> and put it onto another stack (let's call
@ -159,13 +159,13 @@
When you see the <code>0:</code> 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. When you see the <code>0:</code> 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.
</blockquote> </blockquote>
<h2>TICKS</h2> <h2>CLICKS</h2>
<p>Before we get into loops I have to warn you that <code>BUTTONS</code> <p>Before we get into loops I have to warn you that <code>BUTTONS</code>
is not a very powerful computer. It can only perform <code>128</code> is not a very powerful computer. It can only perform <code>128</code>
operations before it runs out of energy called <code>TICKS</code>. If operations before it runs out of energy called <code>CLICKS</code>. If
your computer runs this many ticks then <code>BUTTONS</code> will stop your program runs for 128 many clicks then <code>BUTTONS</code> will stop
running and give up.</p> running and give up because it is tired.</p>
<h2>Looping with JUMP</h2> <h2>Looping with JUMP</h2>
@ -216,7 +216,7 @@
<p>You run it, thinking it will stop at zero, and instead <p>You run it, thinking it will stop at zero, and instead
<code>BUTTONS</code> does exactly what you told it to do and keeps going <code>BUTTONS</code> does exactly what you told it to do and keeps going
until it runs out of <code>TICKS</code>, leaving .... <code>-32</code> on until it runs out of <code>CLICKS</code>, leaving .... <code>-32</code> on
the top? What?!</p> the top? What?!</p>
<p>The reason is you have no way to tell <code>BUTTONS</code> when to stop. You can tell it to do the math and where to <code>JUMP</code> but you have no way to tell buttons "when you reach 0 on the <code>STACK</code> you should stop." You do this with the <code>JZ</code> operation which means "<code>JUMP if Zero</code>". It simply looks at the top of the <code>STACK</code> and if that's 0 then it does a <code>JUMP</code> 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:</p> <p>The reason is you have no way to tell <code>BUTTONS</code> when to stop. You can tell it to do the math and where to <code>JUMP</code> but you have no way to tell buttons "when you reach 0 on the <code>STACK</code> you should stop." You do this with the <code>JZ</code> operation which means "<code>JUMP if Zero</code>". It simply looks at the top of the <code>STACK</code> and if that's 0 then it does a <code>JUMP</code> 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:</p>

Loading…
Cancel
Save