Assembler - External Functions
External functions can be used in expressions to allow more sophisticated builds. Functions are kept in namespaces to avoid name clashes.
These functions are currently supported:
IO.FILESIZE
file size = io.filesize( filename )
io.filesize expects a file name and returns the file size in bytes. If the file name contains a relative path its base is the assembly path.
BYTES_TO_COPY = io.filesize( "file.prg" )
MATH.MIN
result = math.min( 1, 5 )
math.min compares both numeric parameters and returns the smaller one.
PAD_BYTES = math.min( 4, FIELD_LENGTH % 4 )
MATH.MAX
result = math.max( 1, 5 )
math.max compares both numeric parameters and returns the higher one.
PAD_BYTES = math.max( 128, FIELD_LENGTH )
MATH.SIN
result = math.sin( 90 )
math.sin calculates the sinus of the provided expression. The expression is treated as degrees. The result is a real number. Note that a real number will be cast to byte.
!fill 256, [127 + 128 * math.sin( i * 360 / 256 )]
MATH.COS
result = math.cos( 90 )
math.sin calculates the cosinus of the provided expression. The expression is treated as degrees. The result is a real number. Note that a real number will be cast to byte.
!fill 256, [127 + 128 * math.cos( i * 360 / 256 )]
MATH.TAN
result = math.tan( 90 )
math.sin calculates the tangens of the provided expression. The expression is treated as degrees. The result is a real number. Note that a real number will be cast to byte.
!fill 256, [127 + 128 * math.tan( i * 360 / 256 )]
MATH.SQRT
result = math.sqrt( 144 )
math.sqrt calculates the sqaure root of the provided expression. The result is a real number. Note that a real number will be cast to byte.
ROOT = math.sqrt( 144 )
MATH.FLOOR
result = math.floor( 4.7 )
math.floor calculates the lower next closest integer of the provided value. The result is an integer.
!fill 256, math.floor( i * 2.5 / 128 )
MATH.CEILING
result = math.ceiling( 4.7 )
math.ceiling calculates the higher closest integer of the provided value. The result is an integer.
!fill 256, math.ceiling( i * 2.5 / 128 )
MATH.TODEGREES
result = math.todegrees( 3.1415926 )
math.todegrees calculates the matching angle in degrees from the provided value interpreted as radians. The result is a real number. Note that a real number will be cast to byte.
DEGREE = math.todegrees( 3.1415926f )
MATH.TORADIANS
result = math.toradians( 180.0 )
math.toradians calculates the matching angle in radians from the provided value interpreted as degrees. The result is a real number. Note that a real number will be cast to byte.
ANGLE_RADIANS = math.toradians( 180.0 )
MATH.RANDOM
result = math.random( MaxValue )
math.random returns a pseudo random number from 0 to MaxValue - 1.
result = math.random( MinValue, MaxValue )
math.random returns a pseudo random number from MinValue to MaxValue - 1.
The random generator is automatically seeded with a varying value on assembling start. To seed the RNG yourself for a predictable series of pseudo random numbers use math.randomseed.
!fill math.random(20)
!fill math.random(5,16)
MATH.RANDOMSEED
result = math.randomseed( SeedValue )
math.randomseed initialises the pseudo random generator with the provided seed value. Useful for predictable pseudo random numbers.
If the SeedValue -1 is used, the random generator is initialised with a time specific seed.
math.randomseed( 7 )