Pico controller manual




















In Lua, tables are a collection of key-value pairs where the key and value types can both be mixed. They can be used as arrays by indexing them with integers. Tables with 1-based integer indexes are special though. Shorthand assignment operators can also be used if the whole statement is on one line. PRINT 1! When a PICO-8 programs runs, all of the code from tabs is concatenated from left to right and executed. It is possible to provide your own main loop manually, but typically PICO-8 programs use 3 special functions that, if defined by the author, are called during program execution:.

Note that not all host machines are capable of running at 60fps. When the cartridge is run, the contents of each included file is treated as if it had been pasted into the editor in place of that line. When a cartridge is saved as. PNG, or exported to a binary, any included files are flattened and saved with the cartridge so that there are no external dependencies. Built-in operations like drawing sprites also have a CPU cost.

Instead, a small api is offered in keeping with PICO-8's minimal design and limited screen space. Note that PICO-8 does not have upper or lower case characters -- if you are editing a.

System functions called from commandline can omit the usual brackets and string quotes. P8" , it is possible to write:. Filenames that start with ' ' are taken to be a BBS cart id, that is immediately downloaded and run:. If the id is the cart's parent post, or a revision number is not specified, then the latest version is fetched.

List files in the current directory. When called from a running program, returns a list of all. Use a single ". This enters frame-by-frame mode, that can be read with stat While frame-by-frame mode is active, entering an empty command by pressing enter advances one frames.

Reset the values in RAM from 0x5f This includes the palette, camera position, clipping and fill pattern. If you get lost at the command prompt because the draw state makes viewing text impossible, try typing RESET!

It can also be called from a running program. Flip the back buffer to screen and wait for next frame. But when using a custom main loop, a call to FLIP is normally needed:.

If filename is set, append the string to a file on the host operating system in the current directory by default -- use FOLDER to view. Use stat 4 to read the clipboard, but the contents of the clipboard are only available after pressing CTRL-V during runtime for security. Audio values Due to the nature of the gif format, all gifs are recorded at To record exactly one frame each time FLIP is called, regardless of the runtime framerate or how long it took to generate the frame, use:.

PICO-8 has a fixed capacity of 8x8 sprites, plus another that overlap with the bottom half of the map data "shared data". These sprites are collectively called the sprite sheet, and can be thought of as a x pixel image. All of PICO-8's drawing operations are subject to the current draw state.

The draw state includes a camera position for adding an offset to all coordinates , palette mapping for recolouring sprites , clipping rectangle, a drawing colour, and a fill pattern. The initial state of flags It is also possible to draw only a subset of map tiles by providing a mask in MAP. When X, Y are not specified, a newline is automatically appended. This can be omitted by ending the string with an explicit termination control character:.

Additionally, when X, Y are not specified, printing text below causes the console to scroll. This can be disabled during runtime with POKE 0x5f36,0x PRINT returns the right-most x position that occurred while printing. This can be used to find out the width of some text by printing it off-screen:. The draw palette re-maps colours when they are drawn. For example, an orange flower sprite can be drawn as a red flower by setting the 9th palette value to PAL 9,8 -- draw subsequent orange colour 9 pixels as red colour 8 SPR 1,70,60 -- any orange pixels in the sprite will be drawn with red instead.

The display palette re-maps the whole screen when it is displayed at the end of a frame. For example, if you boot PICO-8 and then type PAL 6,14,1 , you can see all of the gray colour 6 text immediate change to pink colour 14 even though it has already been drawn. This provides a mapping from a single 4-bit colour index to two 4-bit colour indexes.

When the first parameter of pal is a table, colours are assigned for each entry. For example, to re-map colour 12 and 14 to red:. When C is the only parameter, it is treated as a bitfield used to set all 16 values. For example: to set colours 0 and 1 as transparent:. Stretch an rectangle of the sprite sheet sx, sy, sw, sh to a destination rectangle on the screen sx, sy, dw, dh. In both cases, the x and y values are coordinates in pixels of the rectangle's top left corner, with a width of w, h.

P is a bitfield in reading order starting from the highest bit. To calculate the value of P for a desired pattern, add the bit values together:.

When set, the fill pattern is applied to sprites spr, sspr, map, tline , using a colour mapping provided by the secondary palette. Each pixel value in the sprite after applying the draw palette as usual is taken to be an index into the secondary palette.

Each entry in the secondary palette contains the two colours used to render the fill pattern. For example, to draw a white and red 7 and 8 checkerboard pattern for only blue pixels colour 12 in a sprite:. When set, the secondary palette mapping is also applied by all draw functions that respect fill patterns circfill, line etc. This can be useful when used in conjunction with sprite drawing functions, so that the colour index of each sprite pixel means the same thing as the colour index supplied to the drawing functions.

FILLP 0b The secondary palette mapping is applied after the regular draw palette mapping. So the following would also draw a red and white checkered circle:.

FFFF are interpreted as the fill pattern. The remaining entries are shifted left one index to avoid holes. Note that VAL is the value of the item to be deleted, not the index into the table. To remove an item at a particular index, use DELI instead. DEL returns the deleted item, or returns no value when nothing was deleted.

Used in FOR loops to iterate over all items in a table that have a 1-based integer index , in the order they were added. Order is not guaranteed. V END. Instead of using a number for B, it is also possible to use a button glyph. It also repeats after 15 frames, returning true every 4 frames after that at 30fps -- double that at 60fps.

This can be used for things like menu navigation or grid-wise player movement. Custom delays in frames 30fps can be set by poking the following memory addresses:. Play music starting from pattern N So to fade pattern 0 in over 1 second:. For example, to play only on channels Reserved channels can still be used to play sound effects on, but only when that channel index is explicitly requested by SFX.

The PICO-8 map is a x32 grid of 8-bit cells, or x64 when using the shared memory. When using the map editor, the meaning of each cell is taken to be an index into the sprite sheet However, it can instead be used as a general block of data.

To draw the whole map, including the bottom half shared with the sprite sheet, use:. To draw the map so that a player object at PL. X in PL. Y in pixels is centered:. When given, only sprites with matching sprite flags are drawn. Sprite 0 is taken to mean "empty" and is not drawn. Draw a textured line from X0,Y0 to X1,Y1 , sampling colour values from the map.

MX, MY are map coordinates to sample from, given in tiles. Colour values are sampled from the 8x8 sprite present at each map tile. For example:. The map coordinates MX, MY are masked by values calculated by subtracting 0x0.

In simpler terms, this means you can loop a section of the map by poking the width and height you want to loop within, as long as they are powers of 2 2,4,8, The default values 0,0 gives a masks of 0xff.

Sprite 0 is taken to mean "empty" and not drawn. Base RAM 64k : see layout below. Cart ROM 32k : same layout as base ram until 0x 3. Technical note: While using the editor, the data being modified is in cart rom, but api functions such as SPR and SFX only operate on base ram. PICO-8 automatically copies cart rom to base ram i. When a cartridge is loaded 2. When a cartridge is run 3. Persistent cart data is mapped to 0x5e Map format is one byte per cel, where each byte normally encodes a sprite index.

Read a byte from an address in base ram. For example, to read the first 2 bytes of video memory:. Write one or more bytes to an address in base ram. If more than one parameter is provided, they are written sequentially max: Read and write one number VAL in little-endian format:. Alternatively, the following operators can be used to peek but not poke , and are slightly faster:. If filename specified, load data from a separate cartridge. In this case, the cartridge must be local BBS carts can not be read in this way.

Up to 64 cartridges can be written in one session. See Cartridge Data for more information. Returns the cosine or sine of x, where 1. For example, to animate a dial that turns once every second:. To get conventional radian-based trig functions without the y inversion, paste the following snippet near the start of your program:. If you want an integer, use flr rnd x. If x is an array-style table, return a random element between table[1] and table[ table].

Operators are slightly faster than their corresponding functions. They behave exactly the same, except that if any operands are not numbers the result is a runtime error the function versions instead default to a value of 0. Index should be If the callback returns true, the pause menu remains open. The callback takes a single parameter that is a bitfield of L,R,X button presses. TONUM " Grab a substring from string str, from pos0 up to and including pos1.

When POS1 is not specified, the remainder of the string is returned. Split a string into a table of elements delimited by the given separator defaults to ",". When separator is a number n, the string is split into n-character groups. Empty elements are stored as empty strings. This can be used as a lightweight way to store things like high scores or to save player progress.

The disadvantage is that the data is tied to that particular version of the cartridge. Also, some space in the data sections of the cartridge need to be left available to use as storage. Browse Tech Doc Center. Search Literature Library. Get Answers. Chevron Up Chevron Up. Product Compatibility and Migration Solutions Demanding market conditions pose significant challenges.

Select a language English. Technical Documentation Center Details Details. Technical Documentation Center. Literature Library.



0コメント

  • 1000 / 1000