nesbox / TIC-80

TIC-80 is a fantasy computer for making, playing and sharing tiny games.
https://tic80.com
MIT License
5.01k stars 486 forks source link

help (api function) command #154

Closed darkhog closed 3 years ago

darkhog commented 7 years ago

I'd like this to be implemented so you won't have to alt-tab to find info. It would after usage type out short description of an api function along of what parameters it takes. So, e.g. after writing help btnp something like this will show:

btnp [id: 0..5 8..13 [hold period] ] -> pressed (but wasn't pressed in previous frame)
This function allow to read the status of one of the buttons attached to TIC. The 
function return true value only in the moment the key is pressed.
id : the id of the key we need to interrogate, see the key map for reference
hold : the time (in ticks) the key must be pressed to consider it as "being pressed"
period : the time (in ticks) after that the function will return true again
hseiken commented 7 years ago

I suggest doing the lofi fix for this: Make your default cart and put in the API reference as a comment and put your code above it. CTRL-END to jump to your help. This is what I did, and also included some LUA tricks and routines. I always load this cart when starting off a project and it's served me well and doesn't require the dev(s) to do anything.

darkhog commented 7 years ago

Yeah, but eventually you get to the memory limits and then usually comments tend to get axed first.

nesbox commented 7 years ago

198 is duplicate

ElfEars commented 6 years ago

This is cool but I think that help should be about general system specs and limitations and limitations wheras there should be a dedicated command for a function reference (maybe FUNCI or INFO?)

darkhog commented 5 years ago

@ElfEars Good idea. Another thought: Turn help command into Turbo Pascal 7.0-style text-based help system.

nesbox commented 3 years ago

Added detailed help info for the console commands and all the api functions here 8b74519

help

ram vram version commands moved to help [ram|vram|version]

joshgoebel commented 3 years ago

@nesbox dude that's awesome!

nesbox commented 3 years ago

added help command categories here 3a275d3

usage: help [<text>|version|welcome|spec|ram|vram|commands|api|terms|license]
nesbox commented 3 years ago

Added export help <file> command which generates <file>.md and it looks like:

TIC-80 tiny computer

0.90.1605-dev (511752a) https://tic80.com (C) 2017-2021

Welcome

TIC-80 is a fantasy computer for making, playing and sharing tiny games.

There are built-in tools for development: code, sprites, maps, sound editors and the command line, which is enough to create a mini retro game. At the exit you will get a cartridge file, which can be stored and played on the website.

Also, the game can be packed into a player that works on all popular platforms and distribute as you wish. To make a retro styled game the whole process of creation takes place under some technical limitations: 240x136 pixels display, 16 color palette, 256 8x8 color sprites, 4 channel sound and etc.

Specification

DISPLAY: 240x136 pixels, 16 colors palette. INPUT: 4 gamepads with 8 buttons / mouse / keyboard. SPRITES: 256 8x8 tiles and 256 8x8 sprites. MAP: 240x136 cells, 1920x1088 pixels. SOUND: 4 channels with configareble waveforms. CODE: 64KB of Lua, Moonscript, JS, Wren, Fennel or Squirrel.

+-----------------------------------+
|           96KB RAM LAYOUT         |
+-------+-------------------+-------+
| ADDR  | INFO              | BYTES |
+-------+-------------------+-------+
| 00000 | <VRAM>            | 16384 |
| 04000 | TILES             | 8192  |
| 06000 | SPRITES           | 8192  |
| 08000 | MAP               | 32640 |
| 0FF80 | GAMEPADS          | 4     |
| 0FF84 | MOUSE             | 4     |
| 0FF88 | KEYBOARD          | 4     |
| 0FF8C | SFX STATE         | 16    |
| 0FF9C | SOUND REGISTERS   | 72    |
| 0FFE4 | WAVEFORMS         | 256   |
| 100E4 | SFX               | 4224  |
| 11164 | MUSIC PATTERNS    | 11520 |
| 13E64 | MUSIC TRACKS      | 408   |
| 13FFC | MUSIC STATE       | 4     |
| 14000 | STEREO VOLUME     | 4     |
| 14004 | PERSISTENT MEMORY | 1024  |
| 14404 | SPRITE FLAGS      | 512   |
| 14604 | SYSTEM FONT       | 2048  |
| 14E04 | MUSIC PARAMETERS  | 2     |
| 14E06 | ... (free)        | 12794 |
+-------+-------------------+-------+
+-----------------------------------+
|          16KB VRAM LAYOUT         |
+-------+-------------------+-------+
| ADDR  | INFO              | BYTES |
+-------+-------------------+-------+
| 00000 | SCREEN            | 16320 |
| 03FC0 | PALETTE           | 48    |
| 03FF0 | PALETTE MAP       | 8     |
| 03FF8 | BORDER COLOR      | 1     |
| 03FF9 | SCREEN OFFSET     | 2     |
| 03FFB | MOUSE CURSOR      | 1     |
| 03FFC | BLIT SEGMENT      | 1     |
| 03FFD | ... (reserved)    | 3     |
+-------+-------------------+-------+

Console commands

cd

change directory. usage: cd <path> cd / cd ..

cls

clear console screen. usage: cls

config

edit system configuration cartridge, use reset param to reset current configuration, use default to edit default cart template. usage: config [reset|default]

del

delete from the filesystem. usage: del <file|folder>

demo

install demo carts to the current directory. usage: demo

dir

show list of local files. usage: dir

eval

run code provided code. usage: eval

exit

exit the application. usage: exit

export

export cart to HTML, native build (win linux rpi mac), export sprites/map/... as a .png image or export sfx and music to .wav files. usage: export [win|linux|rpi|mac|html|tiles|sprites|map|sfx|music|screen|help|...] <file>

folder

open working directory in OS. usage: folder

help

show help info about commands/api/... usage: help [<text>|version|welcome|spec|ram|vram|commands|api|terms|license]

import

import code/sprites/map/... from an external file. usage: import [tiles|sprites|map|code|screen|...] <file>

load

load cartridge from the local filesystem (there's no need to type the .tic extension). you can also load just the section (sprites, map etc) from another cart. usage: load <cart> [code|tiles|sprites|map|sfx|music|palette|flags|screen]

menu

show game menu where you can setup keyboard/gamepad buttons mapping. usage: menu

mkdir

make a directory. usage: mkdir <name>

new

creates a new Hello World cartridge. usage: new [lua|moon|js|wren|fennel|squirrel]

resume

resume last run cart / project. usage: resume

run

run current cart / project. usage: run

save

save cartridge to the local filesystem, use .lua .moon .fnl .js .wren .nut cart extension to save it in text format. usage: save <cart>

surf

open carts browser. usage: surf

API functions

OVR

OVR() Called after each frame;draw calls from this function ignore palette swap and screen offset.

SCN

SCN(row) Allows you to execute code between the drawing of each scanline, for example, to manipulate the palette.

TIC

TIC() Main function. It's called at 60 fps (60 times every second).

btn

btn(id) -> pressed This function allows you to read the status of one of the buttons attached to TIC. The function returns true if the key with the supplied id is currently in the pressed state. It remains true for as long as the key is held down. If you want to test if a key was just pressed, use btnp() instead.

btnp

btnp(id hold=-1 period=-1) -> pressed This function allows you to read the status of one of TIC's buttons. It returns true only if the key has been pressed since the last frame. You can also use the optional hold and period parameters which allow you to check if a button is being held down. After the time specified by hold has elapsed, btnp will return true each time period is passed if the key is still down. For example, to re-examine the state of button 0 after 2 seconds and continue to check its state every 1/10th of a second, you would use btnp(0, 120, 6). Since time is expressed in ticks and TIC runs at 60 frames per second, we use the value of 120 to wait 2 seconds and 6 ticks (ie 60/10) as the interval for re-checking.

circ

circ(x y radius color) This function draws a filled circle of the desired radius and color with its center at x, y. It uses the Bresenham algorithm.

circb

circb(x y radius color) Draws the circumference of a circle with its center at x, y using the radius and color requested. It uses the Bresenham algorithm.

clip

clip(x y width height) clip() This function limits drawing to a clipping region or viewport defined by x,y,w,h. Things drawn outside of this area will not be visible. Calling clip() with no parameters will reset the drawing area to the entire screen.

cls

cls(color=0) Clear the screen. When called this function clear all the screen using the color passed as argument. If no parameter is passed first color (0) is used.

Tips: Use a color over 15 to see some special fill pattern.

exit

exit() Interrupts program execution and returns to the console when the TIC function ends.

fget

fget(sprite_id flag) -> bool Returns true if the specified flag of the sprite is set. See fset() for more details.

font

font(text x y chromakey char_width char_height fixed=false scale=1) -> width Print string with font defined in foreground sprites. To simply print to the screen, check out print(). To print to the console, check out trace().

fset

fset(sprite_id flag bool) Each sprite has eight flags which can be used to store information or signal different conditions. For example, flag 0 might be used to indicate that the sprite is invisible, flag 6 might indicate that the flag should be draw scaled etc. See algo fget().

key

key(code=-1) -> pressed The function returns true if the key denoted by keycode is pressed.

keyp

keyp(code=-1 hold=-1 period=-1) -> pressed This function returns true if the given key is pressed but wasn't pressed in the previous frame. Refer to btnp() for an explanation of the optional hold and period parameters.

line

line(x0 y0 x1 y1 color) Draws a straight line from point (x0,y0) to point (x1,y1) in the specified color.

map

map(x=0 y=0 w=30 h=17 sx=0 sy=0 colorkey=-1 scale=1 remap=nil) The map consists of cells of 8x8 pixels, each of which can be filled with a sprite using the map editor. The map can be up to 240 cells wide by 136 deep. This function will draw the desired area of the map to a specified screen position. For example, map(5,5,12,10,0,0) will draw a 12x10 section of the map, starting from map co-ordinates (5,5) to screen position (0,0). The map function’s last parameter is a powerful callback function​ for changing how map cells (sprites) are drawn when map is called. It can be used to rotate, flip and replace sprites while the game is running. Unlike mset, which saves changes to the map, this special function can be used to create animated tiles or replace them completely. Some examples include changing sprites to open doorways, hiding sprites used to spawn objects in your game and even to emit the objects themselves. The tilemap is laid out sequentially in RAM - writing 1 to 0x08000 will cause tile(sprite) #1 to appear at top left when map() is called. To set the tile immediately below this we need to write to 0x08000 + 240, ie 0x080F0.

memcpy

memcpy(dest source size) This function allows you to copy a continuous block of TIC's 96K RAM from one address to another. Addresses are specified are in hexadecimal format, values are decimal.

memset

memset(dest value size) This function allows you to set a continuous block of any part of TIC's RAM to the same value. The address is specified in hexadecimal format, the value in decimal.

mget

mget(x y) -> tile_id Gets the sprite id at the given x and y map coordinate.

mouse

mouse() -> x y left middle right scrollx scrolly This function returns the mouse coordinates and a boolean value for the state of each mouse button,with true indicating that a button is pressed.

mset

mset(x y tile_id) This function will change the tile at the specified map coordinates. By default, changes made are only kept while the current game is running. To make permanent changes to the map, see sync(). Related: map() mget() sync().

music

music(track=-1 frame=-1 row=-1 loop=true sustain=false) This function starts playing a track created in the Music Editor. Call without arguments to stop the music.

peek

peek(addr) -> value This function allows to read the memory from TIC. It's useful to access resources created with the integrated tools like sprite, maps, sounds, cartridges data? Never dream to sound a sprite? Address are in hexadecimal format but values are decimal. To write to a memory address, use poke().

peek4

peek4(addr) -> value This function enables you to read 4bit values from TIC's RAM. The address should be specified in hexadecimal format.

pix

pix(x y color) pix(x y) -> color This function can read or write pixel color values. When called with a color parameter, the pixel at the specified coordinates is set to that color. Calling the function without a color parameter returns the color of the pixel at the specified position.

pmem

pmem(index value) pmem(index) -> value This function allows you to save and retrieve data in one of the 256 individual 32-bit slots available in the cartridge's persistent memory. This is useful for saving high-scores, level advancement or achievements. The data is stored as unsigned 32-bit integers (from 0 to 4294967295).

Tips:

poke

poke(addr value) This function allows you to write a single byte to any address in TIC's RAM. The address should be specified in hexadecimal format, the value in decimal.

poke4

poke4(addr value) This function allows you to write to the virtual RAM of TIC. It differs from poke() in that it divides memory in groups of 4 bits. Therefore, to address the high nibble of position 0x4000 you should pass 0x8000 as addr4, and to access the low nibble (rightmost 4 bits) you would pass 0x8001. The address should be specified in hexadecimal format, and values should be given in decimal.

print

print(text x=0 y=0 color=15 fixed=false scale=1 smallfont=false) -> width This will simply print text to the screen using the font defined in config. When set to true, the fixed width option ensures that each character will be printed in a box of the same size, so the character i will occupy the same width as the character w for example. When fixed width is false, there will be a single space between each character.

Tips:

rect

rect(x y w h color) This function draws a filled rectangle of the desired size and color at the specified position. If you only need to draw the the border or outline of a rectangle (ie not filled) see rectb().

rectb

rectb(x y w h color) This function draws a one pixel thick rectangle border at the position requested. If you need to fill the rectangle with a color, see rect() instead.

reset

reset() Resets the cartridge. To return to the console, see the exit().

sfx

sfx(id note=-1 duration=-1 channel=0 volume=15 speed=0) This function will play the sound with id created in the sfx editor. Calling the function with id set to -1 will stop playing the channel. The note can be supplied as an integer between 0 and 95 (representing 8 octaves of 12 notes each) or as a string giving the note name and octave. For example, a note value of 14 will play the note D in the second octave. The same note could be specified by the string D-2. Note names consist of two characters, the note itself (in upper case) followed by - to represent the natural note or # to represent a sharp. There is no option to indicate flat values. The available note names are therefore: C-, C#, D-, D#, E-, F-, F#, G-, G#, A-, A#, B-. The octave is specified using a single digit in the range 0 to 8. The duration specifies how many ticks to play the sound for since TIC-80 runs at 60 frames per second, a value of 30 represents half a second. A value of -1 will play the sound continuously. The channel parameter indicates which of the four channels to use. Allowed values are 0 to 3. The volume can be between 0 and 15. The speed in the range -4 to 3 can be specified and means how many ticks+1 to play each step, so speed==0 means 1 tick per step.

spr

spr(id x y colorkey=-1 scale=1 flip=0 rotate=0 w=1 h=1) Draws the sprite number index at the x and y coordinate. You can specify a colorkey in the palette which will be used as the transparent color or use a value of -1 for an opaque sprite. The sprite can be scaled up by a desired factor. For example, a scale factor of 2 means an 8x8 pixel sprite is drawn to a 16x16 area of the screen. You can flip the sprite where:

sync

sync(mask=0 bank=0 tocart=false) The pro version of TIC-80 contains 8 memory banks. To switch between these banks, sync can be used to either load contents from a memory bank to runtime, or save contents from the active runtime to a bank. The function can only be called once per frame.If you have manipulated the runtime memory (e.g. by using mset), you can reset the active state by calling sync(0,0,false). This resets the whole runtime memory to the contents of bank 0.Note that sync is not used to load code from banks; this is done automatically.

textri

textri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 use_map=false chromakey=-1) It renders a triangle filled with texture from image ram or map ram. Use in 3D graphics. This function does not perform perspective correction, so it is not generally suitable for 3D graphics (except in some constrained scenarios). In particular, if the vertices in the triangle have different 3D depth, you may see some distortion. These can be thought of as the window inside image ram (sprite sheet), or map ram. Note that the sprite sheet or map in this case is treated as a single large image, with U and V addressing its pixels directly, rather than by sprite ID. So for example the top left corner of sprite #2 would be located at u=16, v=0.

time

time() -> ticks This function returns the number of milliseconds elapsed since the cartridge began execution. Useful for keeping track of time, animating items and triggering events.

trace

trace(message color=15) This is a service function, useful for debugging your code. It prints the message parameter to the console in the (optional) color specified.

Tips:

tri

tri(x1 y1 x2 y2 x3 y3 color) This function draws a triangle filled with color, using the supplied vertices.

tstamp

tstamp() -> timestamp This function returns the number of seconds elapsed since January 1st, 1970. Useful for creating persistent games which evolve over time between plays.

Terms of Use

Privacy Policy

We store only the user's email and password in encrypted form and will not transfer any personalinformation to third parties without explicit permission.

MIT License

Copyright (c) 2017-2021 Vadim Grigoruk @nesbox // grigoruk@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.