Ml functions: Difference between revisions
No edit summary |
No edit summary |
||
| Line 222: | Line 222: | ||
|- | |- | ||
| @29 | | @29 | ||
| <strong>Read | | <strong>Read a Fixed-Length String from a File</strong><br> | ||
<strong> | Format: <strong><nowiki>@29(<count>[,<skip>])</nowiki></strong> | ||
Reads and returns a string containing a fixed number of bytes from the logical file specified by !14. | |||
* <nowiki><count></nowiki> is the length of the returned string and must be from 1 to 255. | |||
* <nowiki><skip></nowiki> is optional. When specified, that number of bytes is read and discarded before the returned data is collected. | |||
* The returned string is always exactly <count> bytes long. | |||
* !40 is not changed by this function. | |||
* The file remains open after the function. | |||
* The current file status remains available through ST. | |||
The function does not use !04, !08, or !15, and does not stop at carriage returns or other delimiter characters. | |||
If the file ends or another file-status condition occurs before the requested number of bytes is available, the remainder of the returned string is filled with CHR$(0). Check ST when it is necessary to determine whether all bytes came from the file. | |||
Do not use a count of zero. | |||
Examples: | |||
* <strong>A$=@29(6)</strong> Returns the next six bytes from the file. | |||
* <strong>A$=@29(2,2)</strong> Discards two bytes and returns the following two bytes. | |||
|- | |- | ||
| @30 | | @30 | ||
| Line 239: | Line 255: | ||
|- | |- | ||
| @32 | | @32 | ||
| <strong> | | <strong>Read File Bytes and Convert Them to a Numeric Value</strong><br> | ||
<strong> | Format: <strong>@32(<nowiki><count>[,<skip>])</nowiki></strong> | ||
Performs the same fixed-length file read as @29, then converts the returned byte string to a numeric value using the same internal conversion performed by @6. | |||
* It is functionally equivalent to <strong>@6(@29(<nowiki><count>[,<skip>]))</nowiki></strong> but performs the read and conversion as one function. | |||
* <nowiki><count></nowiki> is the number of bytes to read and must be from 1 to 255. | |||
* <nowiki><skip></nowiki> is optional. When specified, that number of bytes is discarded before the bytes used for the numeric result are read. | |||
* The logical file is selected by !14. | |||
* !40 is not changed. | |||
* The file remains open after the function. | |||
* The current file status remains available through ST. | |||
* Missing bytes following an end-of-file or other file-status condition are treated as zero bytes. | |||
Do not use a count of zero. | |||
Example: <strong>A=@32(2,2)</strong> | |||
This discards the first two bytes of a disk-directory record, reads the following two bytes, and returns their numeric value. This is commonly used to obtain the block count from a Commodore disk-directory entry. The same operation could be written as: <strong>A=@6(@29(2,2))</strong> | |||
|- | |- | ||
| @33 | | @33 | ||
Revision as of 18:06, 28 July 2026
Programming Features - ML Functions
The ML functions provide operations that are more flexible than ML commands or ML variables. In practice, they behave like built-in BASIC functions: some execute an ML routine and then return a computed value. Functions can return either numeric or string results (including string values that cannot be returned through ML variables).
All ML functions begin with an "@" followed by one or two digits (the function number). Functions are either STRING or NUMERIC, as indicated in the table. Some functions accept required and/or optional parameters, which are placed in parentheses after the function number.
Example:
1000 a$=@5:sr=st:a=val(a$):ifa<>0thenprint@1(a) 1010 ifsr=.then1000
In this example:
- @5 reads a line from disk (like .01) and returns it as a string.
- VAL() is used to test whether the returned line is numeric; if so, @1 prints the number without the leading space added by STR$ for positive values.
- The loop continues until end-of-file (as indicated by ST).
All ML functions (@##) invoke address $4E21 for ML processing.
The table below lists the ML Functions and descriptions.
| Function | Format and Description |
|---|---|
| @0 | Input Buffer Slice (TX$/!40) Format: @0 : STRING |
| @1 | STR$ Without Leading Space Format: @1( <number> ) : STRING |
| @2 | Find Substring (Forward) Format: @2( <string1> , <string2> [ , <number> ] ) : NUMERIC
Examples:
The !52 variable stores the most recent find position (0 if the count form was used). |
| @3 | Repeat First Character Format: @3( <string> , <number> ) : STRING |
| @4 | Modem GET Character Format: @4 : STRING |
| @5 | Read Disk Line (Returns String) Format: @5 : STRING |
| @6 | Extended ASC / 16-bit Extract Format: @6( <string1> [ , <string2> ] ) : NUMERIC
Example: GET#8,A$:I=@6(A$)
Example: IF LEN(I$)=2 THEN L=@6(I$)
Example: GET#8,A$,B$:L=@6(A$,B$) |
| @7 | Extended CHR$ (16-bit to 2 Bytes) Format: @7( <number> ) : STRING |
| @8 | Read Keyed Line (Returns String) Format: @8 : STRING |
| @9 | Enhanced FRE() Format: @9 : NUMERIC |
| @10 | Strip Control/Graphics Codes Format: @10( <string> [ , <number> ] ) : STRING |
| @11 | Get Time String Format: @11 : STRING |
| @12 | Overlay String / Replace at Position Format: @12( <string1> , <string2> , <number> ) : STRING
Special replace mode: if <number>=0, uses the most recent find position from @2 or @25. If that value is 0 (or if @2/@25 was used in count mode), an ILLEGAL QUANTITY error will occur. |
| @13 | Capture Crash Error Format: @13 : STRING |
| @14 | Capture Crash Line Number Format: @14 : STRING |
| @15 | Convert Date to ADN Format: @15( <year> , <month> , <day> ) : NUMERIC |
| @16 | Convert ADN to Year (Sets Month/Day) Format: @16( <number> ) : NUMERIC |
| @17 | Convert ADN to Day of Week Format: @17( <number> ) : NUMERIC |
| @18 | Convert ADN to Date String Format: @18( <number> ) : STRING |
| @19 | Convert Date String to ADN Format: @19( <string> ) : NUMERIC |
| @20 | Current Overlay Filename Format: @20 : STRING |
| @21 | Alpha-Only, Lowercase Filter Format: @21( <string> ) : STRING |
| @22 | Compress Number for Disk Format: @22( <number> ) : STRING |
| @23 | Uncompress Number from Disk Format: @23( <string> ) : NUMERIC |
| @24 | Pad/Terminate Relative Record Format: @24( <string> , <number> ) : STRING
Null strings or <number><2 may yield undefined results. |
| @25 | Find Substring (Reverse) Format: @25( <string1> , <string2> [ , <number> ] ) : NUMERIC |
| @26 | Get Delimited Field Format: @26( <string1> , <string2> , <number> ) : STRING |
| @27 | Calendar Age from ADNs Format: @27( <number1> , <number2> ) : NUMERIC |
| @28 | Find String in Array Format: @28( <string> , <array> ) : NUMERIC |
| @29 | Read a Fixed-Length String from a File Format: @29(<count>[,<skip>]) Reads and returns a string containing a fixed number of bytes from the logical file specified by !14.
The function does not use !04, !08, or !15, and does not stop at carriage returns or other delimiter characters. If the file ends or another file-status condition occurs before the requested number of bytes is available, the remainder of the returned string is filled with CHR$(0). Check ST when it is necessary to determine whether all bytes came from the file. Do not use a count of zero. Examples:
|
| @30 | Boot Drive Init Command Format: @30( <number> ) : STRING |
| @31 | Sequential Read (Enhanced) Format: @31 : (Undocumented) |
| @32 | Read File Bytes and Convert Them to a Numeric Value Format: @32(<count>[,<skip>]) Performs the same fixed-length file read as @29, then converts the returned byte string to a numeric value using the same internal conversion performed by @6.
Do not use a count of zero. Example: A=@32(2,2) This discards the first two bytes of a disk-directory record, reads the following two bytes, and returns their numeric value. This is commonly used to obtain the block count from a Commodore disk-directory entry. The same operation could be written as: A=@6(@29(2,2))
|
| @33 | Return 1-Byte Null String Format: @33 : (Undocumented) |
Next section: Basic Variables Table