Misc Functionstic80On this pagetic80 MapRemapCallback Type: Type Definition. Description: Remap callback function type for map() function. Signature: local type MapRemapCallback = function(tile: number, x: number, y: number): number, number | nil, number | nil Parameters: ParameterTypeDescriptiontilenumberThe tile ID at position (x, y)xnumberThe X coordinate of the tileynumberThe Y coordinate of the tile Returns: Return TypeDescriptionnumber, number | nil, number | nilA tuple containing [tile, flip, rotate] btn Type: Function. Description: Checks if a button is currently pressed. Signature: global btn: function(id?: number): boolean Parameters: ParameterTypeDescriptionidnumber[optional] Button ID (0-31). If omitted, checks if any button is pressed.Button IDs for all players:Player 1: Up 0, Down 1, Left 2, Right 3, A 4, B 5, X 6, Y 7Player 2: Up 8, Down 9, Left 10, Right 11, A 12, B 13, X 14, Y 15Player 3: Up 16, Down 17, Left 18, Right 19, A 20, B 21, X 22, Y 23Player 4: Up 24, Down 25, Left 26, Right 27, A 28, B 29, X 30, Y 31 Returns: Return TypeDescriptionbooleanTrue if the button is pressed, false otherwise. btnp Type: Function. Description: Checks if a button was just pressed (on this frame). Signature: global btnp: function(id?: number, hold?: number, period?: number): boolean Parameters: ParameterTypeDescriptionidnumber[optional] Button ID (0-31). If omitted, checks all buttons.holdnumber[optional] Hold time in frames.periodnumber[optional] Repeat period in frames. Returns: Return TypeDescriptionbooleanTrue if the button was just pressed, false otherwise. key Type: Function. Description: Checks if a keyboard key is currently pressed. Signature: global key: function(code?: number): boolean Parameters: ParameterTypeDescriptioncodenumber[optional] Key code. If omitted, checks all keys.Letters A-Z: 0-25Numbers 0-9: 27-36Special keys: 37-65Minus = 37Equals = 38LeftBracket = 39RightBracket = 40Backslash = 41Semicolon = 42Apostrophe = 43Grave = 44Comma = 45Period = 46Slash = 47Space = 48Tab = 49Return = 50Backspace = 51Delete = 52Insert = 53PageUp = 54PageDown = 55Home = 56End = 57Up = 58Down = 59Left = 60Right = 61CapsLock = 62Ctrl = 63Shift = 64Alt = 65 Returns: Return TypeDescriptionbooleanTrue if the key is pressed, false otherwise. keyp Type: Function. Description: Checks if a keyboard key was just pressed (on this frame). Signature: global keyp: function(code?: number, hold?: number, period?: number): boolean Parameters: ParameterTypeDescriptioncodenumber[optional] Key code. If omitted, checks all keys.holdnumber[optional] Hold time in frames.periodnumber[optional] Repeat period in frames. Returns: Return TypeDescriptionbooleanTrue if the key was just pressed, false otherwise. mouse Type: Function. Description: Gets the current mouse state. Signature: global mouse: function(): number, number, number, number, number, number, number Returns: Return TypeDescriptionnumber, number, number, number, number, number, numberMultiple return values containing [x, y, left, middle, right, scrollx, scrolly] clip Type: Function. Description: Sets the drawing clip region. Signature: global clip: function(x: number, y: number, w: number, h: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the clip region.ynumberThe Y coordinate of the clip region.wnumberThe width of the clip region.hnumberThe height of the clip region. cls Type: Function. Description: Clears the screen with a color. Signature: global cls: function(color?: number) Parameters: ParameterTypeDescriptioncolornumber[optional] Color index (default: 0). circ Type: Function. Description: Draws a filled circle. Signature: global circ: function(x: number, y: number, radius: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the center.ynumberThe Y coordinate of the center.radiusnumberThe radius of the circle.colornumberThe color index. circb Type: Function. Description: Draws a circle outline. Signature: global circb: function(x: number, y: number, radius: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the center.ynumberThe Y coordinate of the center.radiusnumberThe radius of the circle.colornumberThe color index. elli Type: Function. Description: Draws a filled ellipse. Signature: global elli: function(x: number, y: number, a: number, b: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the center.ynumberThe Y coordinate of the center.anumberThe horizontal radius.bnumberThe vertical radius.colornumberThe color index. ellib Type: Function. Description: Draws an ellipse outline. Signature: global ellib: function(x: number, y: number, a: number, b: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the center.ynumberThe Y coordinate of the center.anumberThe horizontal radius.bnumberThe vertical radius.colornumberThe color index. line Type: Function. Description: Draws a line. Signature: global line: function(x0: number, y0: number, x1: number, y1: number, color: number) Parameters: ParameterTypeDescriptionx0numberThe X coordinate of the start point.y0numberThe Y coordinate of the start point.x1numberThe X coordinate of the end point.y1numberThe Y coordinate of the end point.colornumberThe color index. pix Type: Function. Description: Gets or sets a pixel color. Signature: global pix: function(x: number, y: number, color?: number): number Parameters: ParameterTypeDescriptionxnumberThe X coordinate.ynumberThe Y coordinate.colornumber?Optional color index. If provided, sets the pixel color. Returns: Return TypeDescriptionnumberThe color index at the specified position. print Type: Function. Description: Prints text on the screen. Signature: global print: function(text: string, x?: number, y?: number, color?: number, fixed?: boolean, scale?: number, smallfont?: boolean): number Parameters: ParameterTypeDescriptiontextstringThe text to print.xnumber[optional] X coordinate (default: 0).ynumber[optional] Y coordinate (default: 0).colornumber[optional] Color index (default: 12).fixedboolean[optional] Fixed-width font flag (default: false).scalenumber[optional] Scale factor (default: 1).smallfontboolean[optional] Small font flag (default: false). Returns: Return TypeDescriptionnumberThe width of the printed text. rect Type: Function. Description: Draws a filled rectangle. Signature: global rect: function(x: number, y: number, w: number, h: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the top-left corner.ynumberThe Y coordinate of the top-left corner.wnumberThe width of the rectangle.hnumberThe height of the rectangle.colornumberThe color index. rectb Type: Function. Description: Draws a rectangle outline. Signature: global rectb: function(x: number, y: number, w: number, h: number, color: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate of the top-left corner.ynumberThe Y coordinate of the top-left corner.wnumberThe width of the rectangle.hnumberThe height of the rectangle.colornumberThe color index. spr Type: Function. Description: Draws a sprite. Signature: global spr: function(id: number, x: number, y: number, transparent?: number, scale?: number, flip?: number, rotate?: number, w?: number, h?: number) Parameters: ParameterTypeDescriptionidnumberThe sprite ID.xnumberThe X coordinate.ynumberThe Y coordinate.transparentnumber[optional] Transparent color index (default: -1, no transparency).scalenumber[optional] Scale factor (default: 1).flipnumber[optional] Flip flag: 1=horizontal, 2=vertical, 3=both (default: 0).rotatenumber[optional] Rotation: 1=90°, 2=180°, 3=270° clockwise (default: 0).wnumber[optional] Sprite width in tiles (default: 1).hnumber[optional] Sprite height in tiles (default: 1). tri Type: Function. Description: Draws a filled triangle. Signature: global tri: function(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: number) Parameters: ParameterTypeDescriptionx1numberThe X coordinate of the first vertex.y1numberThe Y coordinate of the first vertex.x2numberThe X coordinate of the second vertex.y2numberThe Y coordinate of the second vertex.x3numberThe X coordinate of the third vertex.y3numberThe Y coordinate of the third vertex.colornumberThe color index. trib Type: Function. Description: Draws a triangle outline. Signature: global trib: function(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: number) Parameters: ParameterTypeDescriptionx1numberThe X coordinate of the first vertex.y1numberThe Y coordinate of the first vertex.x2numberThe X coordinate of the second vertex.y2numberThe Y coordinate of the second vertex.x3numberThe X coordinate of the third vertex.y3numberThe Y coordinate of the third vertex.colornumberThe color index. ttri Type: Function. Description: Draws a textured triangle. Signature: global ttri: function(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u1: number, v1: number, u2: number, v2: number, u3: number, v3: number, texsrc?: number, chromakey?: number, z1?: number, z2?: number, z3?: number) Parameters: ParameterTypeDescriptionx1numberThe X coordinate of the first vertex.y1numberThe Y coordinate of the first vertex.x2numberThe X coordinate of the second vertex.y2numberThe Y coordinate of the second vertex.x3numberThe X coordinate of the third vertex.y3numberThe Y coordinate of the third vertex.u1numberThe U texture coordinate of the first vertex.v1numberThe V texture coordinate of the first vertex.u2numberThe U texture coordinate of the second vertex.v2numberThe V texture coordinate of the second vertex.u3numberThe U texture coordinate of the third vertex.v3numberThe V texture coordinate of the third vertex.texsrcnumber[optional] Texture source (default: 0).chromakeynumber[optional] Chroma key color index (default: -1).z1number[optional] Z coordinate of the first vertex (default: 0).z2number[optional] Z coordinate of the second vertex (default: 0).z3number[optional] Z coordinate of the third vertex (default: 0). font Type: Function. Description: Draws text using a custom font. Signature: global font: function(text: string, x: number, y: number, transparent?: number, charWidth?: number, charHeight?: number, fixed?: boolean, scale?: number): number Parameters: ParameterTypeDescriptiontextstringThe text to draw.xnumberThe X coordinate.ynumberThe Y coordinate.transparentnumber[optional] Transparent color index.charWidthnumber[optional] Character width.charHeightnumber[optional] Character height.fixedboolean[optional] Fixed-width font flag (default: false).scalenumber[optional] Scale factor (default: 1). Returns: Return TypeDescriptionnumberThe width of the drawn text. map Type: Function. Description: Draws a map tile layer. Signature: global map: function(x?: number, y?: number, w?: number, h?: number, sx?: number, sy?: number, colorkey?: number, scale?: number, remap?: MapRemapCallback) Parameters: ParameterTypeDescriptionxnumber[optional] Map X coordinate (default: 0).ynumber[optional] Map Y coordinate (default: 0).wnumber[optional] Width in tiles (default: 30).hnumber[optional] Height in tiles (default: 17).sxnumber[optional] Sprite X offset (default: 0).synumber[optional] Sprite Y offset (default: 0).colorkeynumber[optional] Color key for transparency (default: -1).scalenumber[optional] Scale factor (default: 1).remapMapRemapCallback[optional] Remap callback function. mget Type: Function. Description: Gets the tile ID at a map position. Signature: global mget: function(x: number, y: number): number Parameters: ParameterTypeDescriptionxnumberThe X coordinate in tiles.ynumberThe Y coordinate in tiles. Returns: Return TypeDescriptionnumberThe tile ID. mset Type: Function. Description: Sets the tile ID at a map position. Signature: global mset: function(x: number, y: number, id: number) Parameters: ParameterTypeDescriptionxnumberThe X coordinate in tiles.ynumberThe Y coordinate in tiles.idnumberThe tile ID to set. fget Type: Function. Description: Gets a sprite flag. Signature: global fget: function(sprite_id: number, flag: number): boolean Parameters: ParameterTypeDescriptionsprite_idnumberThe sprite ID.flagnumberThe flag index (0-7). Returns: Return TypeDescriptionbooleanTrue if the flag is set, false otherwise. fset Type: Function. Description: Sets a sprite flag. Signature: global fset: function(sprite_id: number, flag: number, bool: boolean) Parameters: ParameterTypeDescriptionsprite_idnumberThe sprite ID.flagnumberThe flag index (0-7).boolbooleanThe flag value to set. sfx Type: Function. Description: Plays a sound effect. Signature: global sfx: function(id: number, note?: number, duration?: number, channel?: number, volume?: number, speed?: number) Parameters: ParameterTypeDescriptionidnumberThe sound effect ID.notenumber[optional] Note number (0-95, default: uses SFX note).durationnumber[optional] Duration in frames (default: -1, full duration).channelnumber[optional] Channel number (0-3, default: 0).volumenumber[optional] Volume (0-15, default: 15).speednumber[optional] Speed (0-15, default: 0). music Type: Function. Description: Plays music. Signature: global music: function(track?: number, frame?: number, row?: number, loop?: boolean) Parameters: ParameterTypeDescriptiontracknumber[optional] Track number (default: -1, stops music).framenumber[optional] Frame number (default: -1).rownumber[optional] Row number (default: -1).loopboolean[optional] Loop flag (default: true). peek Type: Function. Description: Reads a value from memory. Signature: global peek: function(addr: number, bits?: number): number Parameters: ParameterTypeDescriptionaddrnumberThe memory address.bitsnumber[optional] Bit width: 8, 16, or 32 (default: 8). Returns: Return TypeDescriptionnumberThe value read from memory. peek1 Type: Function. Description: Reads a single bit from memory. Signature: global peek1: function(bitaddr: number): number Parameters: ParameterTypeDescriptionbitaddrnumberThe bit address. Returns: Return TypeDescriptionnumberThe bit value (0 or 1). peek2 Type: Function. Description: Reads a 2-byte value from memory. Signature: global peek2: function(addr2: number): number Parameters: ParameterTypeDescriptionaddr2numberThe memory address (must be 2-byte aligned). Returns: Return TypeDescriptionnumberThe 16-bit value read from memory. peek4 Type: Function. Description: Reads a 4-byte value from memory. Signature: global peek4: function(addr4: number): number Parameters: ParameterTypeDescriptionaddr4numberThe memory address (must be 4-byte aligned). Returns: Return TypeDescriptionnumberThe 32-bit value read from memory. poke Type: Function. Description: Writes a value to memory. Signature: global poke: function(addr: number, val: number) Parameters: ParameterTypeDescriptionaddrnumberThe memory address.valnumberThe value to write. poke1 Type: Function. Description: Writes a single bit to memory. Signature: global poke1: function(bitaddr: number, bitval: number) Parameters: ParameterTypeDescriptionbitaddrnumberThe bit address.bitvalnumberThe bit value (0 or 1). poke2 Type: Function. Description: Writes a 2-byte value to memory. Signature: global poke2: function(addr2: number, val2: number) Parameters: ParameterTypeDescriptionaddr2numberThe memory address (must be 2-byte aligned).val2numberThe 16-bit value to write. poke4 Type: Function. Description: Writes a 4-byte value to memory. Signature: global poke4: function(addr4: number, val4: number) Parameters: ParameterTypeDescriptionaddr4numberThe memory address (must be 4-byte aligned).val4numberThe 32-bit value to write. pmem Type: Function. Description: Gets or sets a persistent memory value. Signature: global pmem: function(index: number, val?: number): number Parameters: ParameterTypeDescriptionindexnumberThe persistent memory index (0-255).valnumber[optional] Value to set. If omitted, returns the current value. Returns: Return TypeDescriptionnumberThe persistent memory value. memcpy Type: Function. Description: Copies memory from one location to another. Signature: global memcpy: function(toaddr: number, fromaddr: number, len: number) Parameters: ParameterTypeDescriptiontoaddrnumberThe destination address.fromaddrnumberThe source address.lennumberThe number of bytes to copy. memset Type: Function. Description: Sets a block of memory to a value. Signature: global memset: function(addr: number, val: number, len: number) Parameters: ParameterTypeDescriptionaddrnumberThe starting address.valnumberThe value to set.lennumberThe number of bytes to set. BDR Type: Function. Description: The BDR (Between Display Rows) callback allows you to execute code between the rendering of each scan line. The primary reason to do this is to manipulate the palette. Doing so makes it possible to use a different palette for each scan line, and therefore more than 16 colors at a time. Signature: global BDR: function(scanline: number) Parameters: ParameterTypeDescriptionscanlinenumberThe scan line about to be drawn (0-143).0-3: TOP BORDER4-139: ROW 0-135 (equiv SCN(0-135))140-143: BOTTOM BORDER TIC Type: Function. Description: The TIC function is the main update/draw callback and must be present in every program. It takes no parameters and is called sixty times per second (60fps). Put your update and draw code here. Signature: global TIC: function() BOOT Type: Function. Description: The BOOT function is called a single time when your cartridge is booted. It should be used for startup/initialization code. For scripting languages that allow code in the global scope (Lua, etc.) using BOOT is preferred rather than including source code in the global scope. Signature: global BOOT: function() exit Type: Function. Description: Exits the game. Signature: global exit: function() reset Type: Function. Description: Resets the game. Signature: global reset: function() sync Type: Function. Description: Synchronizes cart data. Signature: global sync: function(mask?: number, bank?: number, tocart?: boolean) Parameters: ParameterTypeDescriptionmasknumber[optional] Sync mask (default: 0, syncs all).Tiles = 1 << 0Sprites = 1 << 1Map = 1 << 2Sfx = 1 << 3Music = 1 << 4Palette = 1 << 5Flags = 1 << 6Screen = 1 << 7banknumber[optional] Bank number (default: 0).tocartboolean[optional] Flag to save to cart (default: false). time Type: Function. Description: Gets the current time in milliseconds. Signature: global time: function(): number Returns: Return TypeDescriptionnumberThe current time in milliseconds. tstamp Type: Function. Description: Gets a timestamp. Signature: global tstamp: function(): number Returns: Return TypeDescriptionnumberA timestamp value. trace Type: Function. Description: Outputs a trace message. Signature: global trace: function(msg: string, color?: number) Parameters: ParameterTypeDescriptionmsgstringThe message to output.colornumber[optional] Color index. vbank Type: Function. Description: Switches the video bank. Signature: global vbank: function(bank: number) Parameters: ParameterTypeDescriptionbanknumberThe bank number (0 or 1).