Skip to content

Instantly share code, notes, and snippets.

@acmiyaguchi
Last active June 18, 2023 06:27
Show Gist options
  • Save acmiyaguchi/d897fcbb754a05f29faaa5d3fa414e7d to your computer and use it in GitHub Desktop.
Save acmiyaguchi/d897fcbb754a05f29faaa5d3fa414e7d to your computer and use it in GitHub Desktop.

Revisions

  1. acmiyaguchi revised this gist Jun 15, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions 50-timing,basic
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    10 let t0=0
    20 let n=100
    30 start=millis
    30 t0=millis
    40 for i=1 to n
    50 print i
    60 next i
    70 let diff = millis - t0
    80 diff = diff / n
    90 print end
    70 let d = millis - t0
    80 d = d / n
    90 print d
  2. acmiyaguchi revised this gist Jun 15, 2023. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions 50-timing,basic
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    10 let t0=0
    11 let n=100
    20 start=millis
    30 for i=1 to n
    40 print i
    50 next i
    60 let diff = millis - t0
    70 diff = diff / n
    80 print end
    20 let n=100
    30 start=millis
    40 for i=1 to n
    50 print i
    60 next i
    70 let diff = millis - t0
    80 diff = diff / n
    90 print end
  3. acmiyaguchi revised this gist Jun 15, 2023. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions 50-timing,basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    10 let t0=0
    11 let n=100
    20 start=millis
    30 for i=1 to n
    40 print i
    50 next i
    60 let diff = millis - t0
    70 diff = diff / n
    80 print end
  4. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions 41-cosine-draw.basic
    Original file line number Diff line number Diff line change
    @@ -27,12 +27,17 @@
    280 RETURN

    # shift by 1, divide by 2, multiply by num of rows, integerize, and print
    300 for i=0 to k-1
    300 for j = 0 to 6
    305 for i=0 to k-1
    310 let v=res(i+1)
    320 v=(v+1)/2
    321 if v > 1 then v = 1
    322 if v < 0 then v = 0
    330 v=int(v*7)
    335 if v <> j then goto 360
    340 position i,v
    # we clear lines in the middle rows, probably because of screen behavior
    350 print "X"
    351 pause 200
    360 next i
    # 351 pause 200
    360 next i
    370 next j
  5. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion 41-cosine-draw.basic
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    2 CLS
    5 LET pi=3.14159
    9 k=30
    9 k=32
    10 dim res(k)
    20 let s0=0
    30 let s1=1080
    # step is a keyword presumably
    40 let ds = (s1-s0)/(k-1)
    50 for i = 0 to k-1
    60 let x = s0 + i*ds
    # now we have to fix this because the approximation is only good close to 0
    61 x = x mod 360
    62 x = (x - 180)/180*pi
    70 gosub 200
    @@ -31,5 +32,7 @@
    320 v=(v+1)/2
    330 v=int(v*7)
    340 position i,v
    # we clear lines in the middle rows, probably because of screen behavior
    350 print "X"
    351 pause 200
    360 next i
  6. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 35 additions and 0 deletions.
    35 changes: 35 additions & 0 deletions 41-cosine-draw.basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    2 CLS
    5 LET pi=3.14159
    9 k=30
    10 dim res(k)
    20 let s0=0
    30 let s1=1080
    # step is a keyword presumably
    40 let ds = (s1-s0)/(k-1)
    50 for i = 0 to k-1
    60 let x = s0 + i*ds
    61 x = x mod 360
    62 x = (x - 180)/180*pi
    70 gosub 200
    80 res(i+1) = cosx
    90 next i
    100 GOTO 300

    200 REM cosine
    210 LET x2 = x * x
    220 LET x4 = x2 * x2
    230 LET x6 = x4 * x2
    240 LET f2 = 2
    250 LET f4 = f2 * 3 * 4
    260 LET f6 = f4 * 5 * 6
    270 LET cosx = 1 - x2/f2 + x4/f4 - x6/f6
    280 RETURN

    # shift by 1, divide by 2, multiply by num of rows, integerize, and print
    300 for i=0 to k-1
    310 let v=res(i+1)
    320 v=(v+1)/2
    330 v=int(v*7)
    340 position i,v
    350 print "X"
    360 next i
  7. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions 40-cosine.basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    5 LET pi=3.14159
    9 print "enter angle"
    10 INPUT x$
    20 LET x=val(x$)
    21 x=x*pi/180
    30 GOSUB 200
    40 print x; ", "; cosx
    50 GOTO 1000

    200 REM cosine
    210 LET x2 = x * x
    220 LET x4 = x2 * x2
    230 LET x6 = x4 * x2
    240 LET f2 = 2
    250 LET f4 = f2 * 3 * 4
    260 LET f6 = f4 * 5 * 6
    270 LET cosx = 1 - x2/f2 + x4/f4 - x6/f6
    280 RETURN
  8. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 00-README.md
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,7 @@ There are observations or minor improvements that I would make on the implementa
    - `meta+shift+v` makes for a very unintuitive underscore. This should probably be under `-`. Actually `shift+space` is probably supposed to be the combo.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.
    - The `POSITION` function takes column, then row. Which in retrospect make sense, given that origin is the top left and the arguments are` x, y`
    - There aren't any trigonomic functions to play with e.g. `sin`, `cos`, or `tan`, nor functions like `sqrt`. Implementing these from scratch seem little tedious when they can be wrapped from the c standard library. But I suppose implementing [cosine from scratch](https://austinhenley.com/blog/cosine.html) might not be the worst thing to do.

    ## links

  9. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 00-README.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ In particular, `IF` expressions are limited to a single expression.
    If you want to run multiple lines in a branch of code, you must jump to a line to continue execution in that code block.
    The result of this is that line numbering becomes something that you need to mindful of during development.

    There are a couple of minor improvements that I would make on the implementation of BASIC on this device.
    There are observations or minor improvements that I would make on the implementation of BASIC on this device.

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error. I think this is related to setting the position to the 7th row; if I do this and print a value, then we'll automatically scroll the buffer forward.
    @@ -32,7 +32,7 @@ There are a couple of minor improvements that I would make on the implementation
    - Hitting any of the buttons for math (=,+,-,x,/) is awkward. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
    - `meta+shift+v` makes for a very unintuitive underscore. This should probably be under `-`. Actually `shift+space` is probably supposed to be the combo.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.
    - The `POSITION` function doesn't work correctly.
    - The `POSITION` function takes column, then row. Which in retrospect make sense, given that origin is the top left and the arguments are` x, y`

    ## links

  10. acmiyaguchi revised this gist Jun 10, 2023. 2 changed files with 15 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions 00-README.md
    Original file line number Diff line number Diff line change
    @@ -25,13 +25,14 @@ The result of this is that line numbering becomes something that you need to min
    There are a couple of minor improvements that I would make on the implementation of BASIC on this device.

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error. I think this is related to setting the position to the 7th row; if I do this and print a value, then we'll automatically scroll the buffer forward.
    - Hitting `q` when listing code should put me back into the the main interpreter. It would also be nice to see a pager of some kind at the bottom of the screen (like less), but it's by no mean necessary.
    - I would like a way to edit the current line using direction keys, without having to delete everything that I just wrote.
    - I would also like a buffer for history. Pressing `up` should bring up the previous statement, like sh/bash.
    - Hitting any of the buttons for math (=,+,-,x,/) is awkward. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
    - I don't see a way to type an underscore.
    - `meta+shift+v` makes for a very unintuitive underscore. This should probably be under `-`. Actually `shift+space` is probably supposed to be the combo.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.
    - The `POSITION` function doesn't work correctly.

    ## links

    12 changes: 12 additions & 0 deletions 30-debug-screen.basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    1 REM debug screen
    2 CLS
    5 LET x=4
    6 LET y=30
    10 FOR i=0 TO x-1
    20 FOR j=0 TO y-1
    30 POSITION j,i
    40 PRINT "X"
    50 POSITION 0,6
    60 PRINT i; ", "; j
    100 NEXT j
    110 NEXT i
  11. acmiyaguchi revised this gist Jun 10, 2023. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  12. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 10-stats.basic
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    150 NEXT i

    200 LET mean = sum/k
    210 LET var = (sum_sq - (sum*sum)/k)/(k-1)
    210 LET var = (sumsq - (sum*sum)/k)/(k-1)

    300 PRINT "count: "; k
    310 PRINT "mean: "; mean
  13. acmiyaguchi revised this gist Jun 10, 2023. 2 changed files with 6 additions and 1 deletion.
    5 changes: 5 additions & 0 deletions 00-guessing-game.basic
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,21 @@
    1 REM guess a number game

    5 LET actual=INT(RND*100)
    6 LET tries=0

    10 PRINT "guess a number"
    20 INPUT num$
    30 LET num=VAL(num)
    31 LET tries=tries+1
    40 IF num<actual THEN GOTO 100
    50 IF num>actual THEN GOTO 200
    60 GOTO 300

    100 PRINT "too low"
    110 GOTO 10

    200 PRINT "too high"
    210 GOTO 10

    300 PRINT "correct"
    310 PRINT "took "; tries; " tries"
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ There are a couple of minor improvements that I would make on the implementation

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error.
    - - Hitting `q` when listing code should put me back into the the main interpreter. It would also be nice to see a pager of some kind at the bottom of the screen (like less), but it's by no mean necessary.
    - Hitting `q` when listing code should put me back into the the main interpreter. It would also be nice to see a pager of some kind at the bottom of the screen (like less), but it's by no mean necessary.
    - I would like a way to edit the current line using direction keys, without having to delete everything that I just wrote.
    - I would also like a buffer for history. Pressing `up` should bring up the previous statement, like sh/bash.
    - Hitting any of the buttons for math (=,+,-,x,/) is awkward. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
  14. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -26,9 +26,10 @@ There are a couple of minor improvements that I would make on the implementation

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error.
    - - Hitting `q` when listing code should put me back into the the main interpreter. It would also be nice to see a pager of some kind at the bottom of the screen (like less), but it's by no mean necessary.
    - I would like a way to edit the current line using direction keys, without having to delete everything that I just wrote.
    - I would also like a buffer for history. Pressing `up` should bring up the previous statement, like sh/bash.
    - Hitting any of the buttons for math (=,+,-,x,/) is awkard. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
    - Hitting any of the buttons for math (=,+,-,x,/) is awkward. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
    - I don't see a way to type an underscore.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.

  15. acmiyaguchi revised this gist Jun 10, 2023. 2 changed files with 32 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions 10-stats.basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
    1 REM running stats

    10 LET upper=100
    20 LET n=100
    30 LET k=0
    40 LET sum=0
    50 LET sumsq=0

    60 PRINT "upper?"
    61 INPUT upper$
    62 upper=VAL(upper$)
    70 PRINT "n samples?"
    71 INPUT n$
    72 n=VAL(n$)

    100 FOR i=1 TO n
    110 LET v=RND*upper
    120 k=k+1
    130 sum=sum+v
    140 sumsq=sumsq+(v*v)
    150 NEXT i

    200 LET mean = sum/k
    210 LET var = (sum_sq - (sum*sum)/k)/(k-1)

    300 PRINT "count: "; k
    310 PRINT "mean: "; mean
    320 PRINT "var: ; var
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,11 @@ The result of this is that line numbering becomes something that you need to min
    There are a couple of minor improvements that I would make on the implementation of BASIC on this device.

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - When running `LIST`, hitting enter or down skips the last line in the entry, which means I can't see all the code I've written. This is a small off-by-one error.
    - I would like a way to edit the current line using direction keys, without having to delete everything that I just wrote.
    - I would also like a buffer for history. Pressing `up` should bring up the previous statement, like sh/bash.
    - Hitting any of the buttons for math (=,+,-,x,/) is awkard. I need to have both fingers on the left-hand side of the keyboard. The bottom two keys of the display would be useful as extra modifier keys, since they're currently not doing anything.
    - I don't see a way to type an underscore.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.

    ## links
  16. acmiyaguchi revised this gist Jun 10, 2023. 2 changed files with 39 additions and 1 deletion.
    File renamed without changes.
    40 changes: 39 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,42 @@
    # SMART Response XE

    I recently got my hands on a SMART Response XE, which is a defunct education device based on a ATMega128RFA1.
    It's basically a beefy arduino with a keyboard and screen.


    ## Learning BASIC

    The device that I bought came preloaded with a fork of Arduino BASIC.
    It took me an hour or two to get the basic control flow down, but its simpler than I expected.

    The REPL flow is quite nice.
    You can swap between 9 banks of memory using `mload {slot}` and `msave {slot}` where `slot` is between 0 and 9.
    You can immediately execute an expression by typing it and hitting enter.
    You add code to your program by prefixing an expression with a line number.
    To delete a line, type the line number without any extra characters.
    Use `list` to see your source and `run` to run your program.
    These take a line number as an argument so you can skip around.

    In a modern language like Python, you're given more control over execution flow of the program.
    In particular, `IF` expressions are limited to a single expression.
    If you want to run multiple lines in a branch of code, you must jump to a line to continue execution in that code block.
    The result of this is that line numbering becomes something that you need to mindful of during development.

    There are a couple of minor improvements that I would make on the implementation of BASIC on this device.

    - I would set `enter` to be the down or right key. I keep wanting to use the `backspace` key for it's intended purpose, and it's a little annoying to have to change it. A dynamic setting could be cool, built into the environment as a function.
    - I would like a way to edit the current line using direction keys, without having to delete everything that I just wrote.
    - I would also like a buffer for history. Pressing `up` should bring up the previous statement, like sh/bash.
    - A `HELP` function might to start programming without having to dive into various docs. Alternatively, having a canonical reference with some examples would be cool. I'll try to include some useful examples in this doc, but it would be nice to have it built into the system.

    ## links

    - https://www.tindie.com/products/subsystems/smart-response-xe-with-arduino-basic/
    - https://www.tindie.com/products/bradanlane/smart-response-xe-developer-kit/
    - https://hackaday.com/tag/smart-response-xe/
    - https://github.com/robinhedwards/ArduinoBASIC
    - https://github.com/Subsystems-us/SMART-Response-XE-Tiny-Basic-Port
    - https://github.com/Subsystems-us/SMART-Response-XE-Tiny-Basic-Port
    - https://gitlab.com/bradanlane/srxecore
    - https://simba-os.readthedocs.io/en/latest/
    - http://www.ulisp.com/
    - https://www.bigmessowires.com/2016/05/06/fc8-faster-68k-decompression/
  17. acmiyaguchi revised this gist Jun 10, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion guessing-game.basic
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    1 REM guess a number game
    5 LET actual=INT(RND*100)
    6 LET tries=0
    10 INPUT "guess a number"
    10 PRINT "guess a number"
    20 INPUT num$
    30 LET num=VAL(num)
    31 LET tries=tries+1
  18. acmiyaguchi created this gist Jun 10, 2023.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ## links

    - https://github.com/robinhedwards/ArduinoBASIC
    - https://github.com/Subsystems-us/SMART-Response-XE-Tiny-Basic-Port
    16 changes: 16 additions & 0 deletions guessing-game.basic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    1 REM guess a number game
    5 LET actual=INT(RND*100)
    6 LET tries=0
    10 INPUT "guess a number"
    20 INPUT num$
    30 LET num=VAL(num)
    31 LET tries=tries+1
    40 IF num<actual THEN GOTO 100
    50 IF num>actual THEN GOTO 200
    60 GOTO 300
    100 PRINT "too low"
    110 GOTO 10
    200 PRINT "too high"
    210 GOTO 10
    300 PRINT "correct"
    310 PRINT "took "; tries; " tries"