Log In  

Cart #picoforth-0 | 2021-05-14 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

picoforth - a stack-based programming language

picoforth is a project I started working on a while ago, and then gave up on, then returned to yesterday. It is unfinished (there are a few minor bugs, there is essentially no support for strings yet, and the method of inputting text is pretty bad), but still can do quite a lot.

If you are unfamiliar with stack-based languages, I recommend you check out easyforth, a stack-based language resembling a typical Forth. It can teach you the basics of stack-based languages, and to a lesser extent, Forth.

Here's the list of the words (for those unfamiliar, a "word" in forth is roughly comparable to a function in most other languages) currently in picoforth:

(if a word doesn't have a comment, that means it works exactly like it would in a normal Forth)
rotl   -- rotates the top three stack items left (n1 n2 n3 -> n3 n1 n2)
rotr   -- same, but to the right (n1 n2 n3 -> n2 n3 n1)
//     -- integer division 
~=     -- not equals
&      -- bitwise and
|      -- or
^^     -- xor
~      -- not
>>     -- shr
<<     -- shl
not    -- 1 -> 0, 0 -> 1
!      -- @ and ! are peek and poke, respectively
.stack -- prints the current stack, mostly useful for debugging
key    -- halts the program until a key is pressed; puts the ord() of that key on the stack
branch -- relative branch: adds the instruction pointer with the value at the top of the stack (can be negative)
absbranch -- absolute branch: sets the instruction pointer to the value of the item at the top of the stack

Here's an example program, the one that generated the label image:

0 1 + dup dup 0x6000 + dup rotl ! 0x7fff < 2 * absbranch

My eventual goal with this is to make tiny games/demos that you can copy and paste into this cart, similar to a tweetcart. If you want to, make spinoffs of this cart! I'd love to see them.

P#91954 2021-05-14 23:28 ( Edited 2021-05-15 02:44)


Earlier today, I learned that pressing ctrl+p while running a cart brings up a performance monitor (and something else I learned on accident: pressing ctrl+p in the commandline/text editor lets you use the tiny characters; this isn't documented in the pico-8 fandom wiki but is on pico-8's changelog in the manual.)

I booted up one of my carts and opened the performance monitor. (It runs at a smooth 60fps, it's not very complicated at all). For fun, I changed the cls(1) to print("\^c1"). To my great surprise, the performance monitor indicated that it did this ever so slightly quicker than cls(1). So I made a new cartridge (function _update60()for _=1,1000do print("\^c1") end) and it ran smoothly, never going over the virtual processor limit. I switched the print() to the respective cls() and it was almost 2 times more resource intensive, constantly over the virtual limit, and running at an extremely choppy ~1fps.


I'm not sure how this would be useful unless you're calling cls() an awful lot of times, as it takes quite a few extra characters. Even with the minor improvement of using ? rather than print() is small, as you still need a newline on either side. If you really wanted to, you could just redefine cls() to simply be something like this:

function cls(a)a=a or 0
P#89318 2021-03-21 21:02 ( Edited 2021-03-22 17:22)

Cart #lotsocolors-2 | 2020-12-15 | Code ▽ | Embed ▽ | No License

This is a simple pico-8 program that I thought I would share. The concept is simple; it's drawing circles where the center is a point on an (hidden) circle, incrementing the color each time. You can adjust the radius of the hidden circle by using left/right and the amount of circles being drawn with up/down. Since it never clears the screen, it gives really nice visuals with the trails left behind by the circles.

edit: there is now a version 1.1, which allows you to press x/o to swap whether or not screen clearing is on or not. While this looks much more boring, it allows to see how it works much better.

Cart #lotsocolors-3 | 2020-12-17 | Code ▽ | Embed ▽ | No License

P#85434 2020-12-15 17:19 ( Edited 2020-12-17 20:11)

Cart #juliasetrender-0 | 2020-11-04 | Code ▽ | Embed ▽ | No License

This is a Julia set renderer. Not much else to say. The code was based off of the Wikipedia Pseudocode for the Julia Set.
The controls are (X) to zoom out, (Z)/(C) to zoom in, and the arrow keys to adjust the fractal parameters.
Hopefully you can enjoy it!
PS There are probably ways to increase the speed of this program. (This is my third published cartridge and so I'm not too great at pico-8 yet.) Once you zoom to fit the screen it takes ~2 seconds to respond. Feel free to point out changes that can be made.

P#83705 2020-11-04 18:33

Cart #wezemogowo-0 | 2020-10-11 | Code ▽ | Embed ▽ | No License

This is my second published Pico-8 cartridge. It shows a near-perfect (in collision detection, not in the way it works) tiny collision detection function for a square. It can be expanded to any arbitrarily-sized rectangle. A square was chosen for simplicity.

There is no doubt in my mind that this can be improved upon. You know what, there's probably a way better, super obvious way that I glanced over.

I don't recommend using this for any of your games, as it has a blazingly obvious issue: You can't go into anything that isn't a black pixel. Also, due to the way it detects the pixels, it cannot detect sprites/map tiles that are smaller then a square.

The only reason I made this was to see if I could make a collision detection system that didn't use:

  • Rocket science
  • Quantum physics
  • Carts that use coding like this video
  • just kidding about most of those
    I included the code so you can see how short it is (yes this is the entire cartridge's code)
    px=64 py=64
    function collision()
    function _update()
    if btn(0) and colll1==0 and colll2==0 then px-=1 end
    if btn(1) and collr1==0 and collr2==0 then px+=1 end
    if btn(2) and collu1==0 and collu2==0 then py-=1 end
    if btn(3) and colld1==0 and colld2==0 then py+=1 end    
P#82804 2020-10-11 20:17 ( Edited 2020-10-12 22:36)

Cart #sss-0 | 2020-10-04 | Code ▽ | Embed ▽ | No License

This is a simple program that picks a random sprite, displays it, moves, and then repeats. This is my first Pico-8 program and doesn't do much but is a decent screensaver in a pinch. If you're wondering where those sprites came from, it was my interpretation of sitelen pona, one of the writing systems of Toki Pona. Hopefully I didn't mess anything up!

P#82564 2020-10-04 19:21 ( Edited 2020-10-04 19:23)

Follow Lexaloffle:        
Generated 2021-05-16 11:25:59 | 0.082s | Q:28