Built-in Functions
This page documents all built-in functions available in basm expressions.
Mathematical Functions
Trigonometric Functions
sin(x)- Sine of x (x in radians)cos(x)- Cosine of x (x in radians)asin(x)- Arc sine of x (returns radians)acos(x)- Arc cosine of x (returns radians)atan2(y, x)- Arc tangent of y/x (returns radians)
Exponential and Logarithmic Functions
exp(x)- Exponential function (e^x)ln(x)- Natural logarithm (base e)log10(x)- Logarithm base 10pow(base, exponent)- Power function (base^exponent)sqrt(x)- Square root
Rounding and Modulo Functions
floor(x)- Largest integer ≤ xceil(x)- Smallest integer ≥ xint(x)- Integer part (truncate towards zero)frac(x)- Fractional partabs(x)- Absolute valuefmod(x, y)- Floating point remainder of x/yremainder(x, y)- IEEE remainder function
Comparison and Utility Functions
min(a, b, ...)- Minimum value (variadic)max(a, b, ...)- Maximum value (variadic)clamp(value, min, max)- Clamp value between min and maxfmin(a, b)- Minimum of two floatsfmax(a, b)- Maximum of two floatsfdim(x, y)- Positive difference (max(x-y, 0))fstep(edge, x)- Step function (0 if x<edge, 1 if x≥edge)isgreater(x, y)- Test if x > y (returns 0 or 1)isless(x, y)- Test if x < y (returns 0 or 1)hypot(x, y)- Euclidean distance sqrt(x²+y²)ldexp(x, exp)- x * 2^exp
Bit Manipulation Functions
high(value)/hi(value)- High byte of 16-bit valuelow(value)/lo(value)- Low byte of 16-bit value
Memory Access Functions
peek(address)/memory(address)- Read byte from memory at address during assembly
String Functions
char(value)- Convert integer to single character stringstring_new(length, filler)- Create string of given length filled with fillerstring_push(string, char_or_string)- Append character or stringstring_concat(s1, s2, ...)- Concatenate strings (variadic)string_from_list(list)- Convert list of integers to stringstring_len(string)- Length of string (same aslist_len)
Pixels
mode0_byte_to_pen_at(byte, position)- Extract pen number at position (0 or 1) from mode 0 bytemode1_byte_to_pen_at(byte, position)- Extract pen number at position (0-3) from mode 1 bytemode2_byte_to_pen_at(byte, position)- Extract pen number at position (0-7) from mode 2 bytepen_at_mode0_byte(byte, position)- Get pen at position in mode 0 bytepen_at_mode1_byte(byte, position)- Get pen at position in mode 1 bytepen_at_mode2_byte(byte, position)- Get pen at position in mode 2 bytepens_to_mode0_byte(pen0, pen1)- Convert 2 pens to mode 0 bytepens_to_mode1_byte(pen0, pen1, pen2, pen3)- Convert 4 pens to mode 1 bytepens_to_mode2_byte(pen0, ..., pen7)- Convert 8 pens to mode 2 byte
List Functions
list_new(length, filler)- Create list of given length filled with filler valuelist_get(list, index)- Get element at indexlist_set(list, index, value)- Set element at index (returns new list)list_len(list)- Length of listlist_sublist(list, start, end)- Extract sublist (end is not included)list_sort(list)- Sort list in ascending order (returns new list)list_argsort(list)- Return indices that would sort the listlist_push(list, element)- Append element to list (returns new list)list_extend(list1, list2)- Concatenate two lists (returns new list)
Matrix Functions
To be called on a matrix object or a list of list object (WIP).
matrix_new(width, height, filler)- Create matrix filled with value, ormatrix_new(list_of_lists)to create from nested listsmatrix_set(matrix, x, y, value)- Set element at position (returns new matrix)matrix_get(matrix, x, y)- Get element at positionmatrix_col(matrix, x)- Get column as listmatrix_row(matrix, y)- Get row as listmatrix_set_col(matrix, x, list)- Set column from list (returns new matrix)matrix_set_row(matrix, y, list)- Set row from list (returns new matrix)matrix_width(matrix)- Get matrix widthmatrix_height(matrix)- Get matrix height
File Functions
load("filename")- Load file content as list of bytes
Code Assembly Function
assemble("z80_code")- Assemble Z80 code string and return bytes as list
Example:
Binary Transformation Function
binary_transform(data, "crunch_type")- Compress data using specified cruncher
Supported crunch types:
"LZEXO","LZ4","LZ48","LZ49""LZSHRINKLER","LZX7","LZX0","LZAPU""LZSA1","LZSA2","LZUPKR""BackwardZx0"(backward variant)
Example:
Section Functions
section_start("section_name")- Get start address of named sectionsection_stop("section_name")- Get stop address of named sectionsection_length("section_name")- Get length of named sectionsection_used("section_name")- Get number of bytes actually used in sectionsection_mmr("section_name")- Get memory mapper register value for section