?"\*0abc" -- expected: bc -- actual: abc |
Perhaps this isn't a bug, but it could make a padding function a lot simpler.
function pad(str, char, len) return str.."\*"..(len-#str)..char end ?pad("hello","h",6) -- helloh ?pad("hello","h",5) -- helloh -- second one should just be hello |
Basically the title.
info([cart])--returns tokens,chars,compressed_size of [cart] or the current cart if given none |
This could be useful for people who are creating carts using printh() and such, to detect if the cart is able to be run before load()ing it:
tokens,chars,compressed=info("cart.p8") if(tokens<8192 and chars<65536)load("cart.p8") |
What do you all think?
Welp, this took way to long to finish. But now it's here!
about
picoforth is a programming language based on Forth, a family of stack-based programming languages. If you're unfamiliar with stack-based programming languages or Forth, I recommend you check out this site.
wordlist
Here is a list of every word in picoforth. (A "word" in a stack-based language is roughly equivalent to a "function" or a "subroutine" in a normal programming language.)
--typical forth stack-manipulating words pop 2pop dup 2dup over swap rotl rotr --mathematical operators + - * / // --integer division ^ --comparing operators = ~= > < --bitwise operators & --bitwise and, or, shr, shl, xor, and not, respectively | >> << ^^ ~ --storing and recalling ! --peek and poke, respectively @ --printing . --prints the popped item (works with strings and numbers) .stack --prints the entire stack (doesn't affect anything) --key operations chr ord key --halts the program until a key is pressed; pushes the pressed key input --repeats key until enter is pressed; pushes the finished string --branching branch --relative branch: I(nstruction)P(ointer) becomes the sum of itself and popped item goto --absolute branch: sets the IP to popped item --screen drawing cls flip spr pset --strings " -- opens a string, then closes it the next time it's used (i.e. " asdf " . will print asdf) "" --pushes an empty string join --concatenates the two top popped items sub # --length of string --miscellaneous exec --runs the popped item as if it were forth code time --pushes t()\1 rnd --pushes rnd(poppeditem\1) sin --pushes sin(poppeditem) cos --pushes cos(poppeditem) def --pushes the definition of popped item interpret --repeats input + exec forever --creating new words : -- : name-of-new-word [definition] ; ; |
Here's an example program, the one that generated the label image:
0 1 + dup dup 0x6000 + dup rotl ! 0x7fff < 2 * goto |
Post any spinoffs of this cart/programs in picoforth that you made in the comments. I'd love to see them!
For the previous picoforth, which was a work-in-progress, see this cart.
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:
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.
context
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.
conclusion
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 ?"\^c"..split("0123456789abcdef","")[a+1] end |
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.
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.
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() collr1=pget(px+8,py) collr2=pget(px+8,py+7) colll1=pget(px-1,py) colll2=pget(px-1,py+7) collu1=pget(px,py-1) collu2=pget(px+7,py-1) colld1=pget(px,py+8) colld2=pget(px+7,py+8) end function _update() cls() map(0,0,0,0,16,16) collision() spr(1,px,py) 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 end
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!