Enter new time:
```
The punctuation mark ":" separates the three TIME command fields of ``, ``, and ``. Fields after `` or `` may be omitted or considered to be 0. Each field can have the following values:
```
: 0 to 23
12A (represents midnight)
0A to 11A (represents midnight to 11 o'clock in the morning)
12P (represents noon)
1P to 11P (represents 1 o'clock to 11 o'clock in the evening)
: 0 to 59
: 0 to 59
```
examples:
```
A>TIME 12 ⟵ sets time to 12:00:00
A>TIME 1:16P ⟵ sets time to 13:16:00
```
#### TYPE
form: `TYPE `
The command TYPE displays the contents of a file specified by ``. Using wildcards in causes the first of the corresponding files to be displayed. This command is for ASCII files, and displaying binary files causes unreadable control characters to be sent to the screen.
#### VERIFY
form: `VERIFY [ON|OFF]`
VERIFY sets/resets the verify mode. When the verify mode is turned ON, after data is written to the disk, it is always read to ensure that it was written correctly. This is why disk access takes longer. "VERIFY OFF" is set by default.
### 2.3 Batch Command Usage
MSX-DOS has a batch feature that allows a series of commands listed in the order of operation to be executed automatically. The file containing this procedureis called a "batch file" and the series of operations defined by a batch file is called a "batch command".
A batch file uses the extension ".BAT". Typing only the file name (the extension ".bat" is not typed) at the command line prompt causes MSX-DOS to execute the commands in the file line by line.
For example, let us consider the following operation:
1. Copy all files on drive A with the extension ".COM" onto drive B.
2. List all "COM" files on drive B.
3. Delete all "COM" files on drive A.
This operation could be achieved by issuing the following commands to MSX-DOS:
```
A>COPY A:*.COM B:
A>DIR B:*.COM /W
A>DEL A:*.COM
```
If these three lines are combined into a batch file called "MV.BAT", the command line input "MV" will automatically execute the operation shown above. The following list illustrates this.
```
A>COPY CON MV.BAT -+
COPY A:*.COM B: | creates "MV.BAT"
DIR B:*.COM /W |
DEL A:*.COM -+
^Z Ctrl-Z + RETURN key input
A>TYPE MV.BAT -+
COPY A:*.COM B: | to confirm the contents of "MV.BAT"
DIR B:*.COM /W |
DEL A:*.COM -+
A>MV invokes the batch command "MV"
A>COPY A:*.COM B: reads the first line automatically and executes it
.
.
.
A>DIR B:*.COM /W reads the second line automatically and executes it
.
.
.
A>DEL A:*.COM reads the third line automatically and executes it
.
.
.
```
A batch operation may be interrupted by pressing Ctrl-C. When Ctrl-C is entered during batch operations, the request shown in [Figure 3.7](#figure-37--interrupt-of-the-batch-operation) is displayed on the screen.
##### _Figure 3.7 Interrupt of the batch operation_
```
-----------------------------------
| |
| Terminate batch file (Y/N)? |
| |
-----------------------------------
```
Selecting "Y" here terminates the batch command and returns to MSX-DOS. Selecting "N" reads the next line of the batch file and continues the execution of the batch command.
#### Batch variables
For more flexible use of the batch command, any string can be passed as parameters from the command line to the batch command. Parameters passed are referred to with the symbols "%n" where n is any number from 0 to 9. These "%n" symbols are called batch variables.
Batch variables %1, %2, ... correspond to parameters specified in the command line from left to right, and %0 is for the name of the batch command itself.
##### _Figure 3.8 Examples for batch variables usage_
```
-----------------------------------------------------------------
| |
| A>COPY CON TEST.BAT ......... creates a batch command |
| REM %0 %1 %2 %3 |
| ^Z |
| 1 file copied |
| A>TYPE TEST.BAT |
| REM %0 %1 %2 %3 ...... a batch command to display 3 arguments |
| |
| A>TEST ONE TWO THREE FOUR ...... executes the batch command, |
| A>REM TEST ONE TWO THREE giving arguments to it |
| A> |
| |
-----------------------------------------------------------------
```
#### AUTOEXEC.BAT
The batch file named "AUTOEXEC.BAT" is used as a special autostart program at MSX-DOS startup. When MSX-DOS is invoked, COMMAND.COM examines whether AUTOEXEC.BAT exists and, if so, executes it.
### 2.4 External Commands
External commands exist on the diskette as files with the extension ".COM", and typing the external command name (except for the extension) causes the command to be executed in the following manner.
1. loads an external command after 100H
2. calls 100H
#### Developing external commands
Assembly language routines created to work in memory at location 100H and saved under file names with the extension ".COM" are called external commands and can be executed from MSX-DOS.
For example, consider a program to produce a control code "0CH" by using one-character output routine (see system calls) and clear the screen. This is an 8-byte program as shown below.
##### List 3.1 Contents of CLS.COM
```
1E 0C LD E,0CH ; E := control-code of CLS
0F 02 LD C,02H ; C := function No. of CONSOLE OUTPUT
CD 05 00 CALL 0005H ; call BDOS
C9 RET
```
Writing these 8 bytes to a file named CLS.COM produces the external command "CLS" to clear the screen. The following sample program uses the sequential file access feature of BASIC to make this command. After this program is run, the CLS command is created on the diskette. Confirm that the command actually works after returning to MSX-DOS.
##### List 3.2 Creating CLS.COM
```
100 '***** This program makes "CLS.COM" *****
110 '
120 OPEN "CLS.COM" FOR OUTPUT AS #1
130 '
140 FOR I=1 TO 8
150 READ D$
160 PRINT #1,CHR$(VAL("&H"+D$));
170 NEXT
180 '
190 DATA 1E,0C,0E,02,CD,05,00,C9
```
#### Passing arguments to an external command
When creating an external command, there are two ways to pass arguments from the command line to the external command. First, when passing the file names to the command line as arguments, use 5CH and 6CH in the system scratch area. COMMAND.COM, which always considers the first and second parameters as file names when external commands are executed, expands them to a drive number (1 byte) + file name (8 bytes) + extension (3 bytes) and stores them in 5CH and 6CH. These are in the same format as the first 12 bytes of FCB, so setting these address as first addresses of FCB permits various operatuons.
However, since in this method only 16 bytes differ from the starting addresses of two FCBs, either 5CH or 6CH (only) can be used as a complete FCB. Next, when passing arguments other than file names (numbers, for instance) or creating an external command handling more than three file names, COMMAND.COM stores the whole command line, which invoked the external command, except for the command line itself in the form of number of bytes (1 byte) + command line body, so it can be used by interpreting it in the external command properly. See [List 3.3](#list-33--utility-routines) of section 4 for an example of passing arguments using this DMA area.
## 3. STRUCTURE OF DISK FILES
Information about the structure of data on the disk and how it is controlled is important when acessing the disk using system calls. This section begins with a description about "logical sectors" which are the basic units for exchanging data with the disk on MSX-DOS, and proceeds to the method of handling data with "files" which is more familiar to programmers.
### 3.1 Data units on the disk
#### Sectors
MSX-DOS can access most types of disk drives including th 3.5 inch 2DD and hard disks. For handling different media in the same way, the system call consider "logical sector" as the basic units of data on the disk. A logical sector is specified by numbers starting from 0.
#### Clusters
As long as system calls are used, a sector may be considered the basic unit of data as considered above. In fact, however, data on the disk is controlled in units of "clusters" which consists of multiple sectors. As described later in [the FAT section](#fat-file-allocation-table), a cluster is specified by a serial number from 2 and the top of the data area corresponds to the location of cluster #2. For getting information about how many sectors a cluster has, use the system call [function 1BH (acquiring disk information)](#disk-information-acquisition).
#### Conversion from clusters to sectors
In a part of the directory or FCB, described later, the data location on the disk is indicated by the cluster. To use system calls to access data indicated by cluster, the relation of the correspondence between the cluster and the sector needs to be calculated. Since cluster #2 and the top sector of the data area reside in the same location, this can be done as follows:
1. Assume the given cluster number is C.
2. Examine the top sector of the data area (by reading DPB) and assume it is S0.
3. Examine the number of sectors equivalent to one cluster (using [function 1BH](#disk-information-acquisition)) and assume it is n.
4. Use the formula `S = S0 + (C-2) * n` to calculate sector numbers.
In MSX-DOS, sectors in the disk are divided into four areas, as shown in [Table 3.9](#table-39--disk-contents). The file data body written to the disk is recorded in the "data area" portion. Information for handling data is written in three areas. [Figure 3.9](#figure-39--relation-of-locations-of-elements-in-the-disk) shows the relation of the locations of these areas. The boot sector is always in sector #0, but the top sectors (FAT, directory, and data area) differ by media, so DPB should be referred to.
##### _Table 3.9 Disk contents_
```
----------------------------------------------------------------------------
| boot sector | MSX-DOS startup program and information proper to the disk |
| FAT | physical control information of data on the disk |
| directory | control information of files on the disk |
| data area | actual file data |
----------------------------------------------------------------------------
```
##### _Figure 3.9 Relation of locations of elements in the disk_
```
+- ----------------------- ⟵ sector #0
| | boot sector |
| |---------------------| ⟵ sector #? -+
| | FAT | | Top sectors of these data
whole |---------------------| ⟵ sector #? | areas can be acquired by
of a | directory | | referring to DPB.
disk |---------------------| ⟵ sector #? -+
| | |
| | data area |
| | |
+- ----------------------- ⟵ last sector
```
#### DPB (drive parameter block) and boot sector
On MSX-DOS, the area "DPB" is allocated in the work area of memory for each connected drive, and information proper to each drive is recorded there. MSX-DOS can handle most types of disk drives, because the differences between media can be compensated for by the process corresponding to each drive.
Information written on DPB, which is originally on the boot sector (sector #0) of the disk, is read at MSX-DOS startup. Note that the differences between the contents of the boot sector and DPB, as shown in Figures [3.10](#figure-310--information-of-the-boot-sector) and [3.11](#figure-311--dpb-structure). Data is arranged differently in the boot sector and the DPB.
##### _Figure 3.10 Information of the boot sector_
```
| |
|---------------| -+
0B | | |-- 1 sector size (in bytes)
0C | | |
|---------------| -+
0D | | ---- 1 cluster size (in sectors)
|---------------| -+
0E | | |-- Number of unused sectors by MSX-DOS
0F | | |
|---------------| -+
10 | | ---- Number of FATs
|---------------| -+
11 | | |-- Number of directory entries (How many files can be created)
12 | | |
|---------------| -+
13 | | |-- Number of sectors per disk
14 | | |
|---------------| -+
15 | | ---- Media ID
|---------------| -+
16 | | |-- Size of FAT (in sectors)
17 | | |
|---------------| -+
18 | | |-- Number of tracks per sector
19 | | |
|---------------| -+
1A | | |-- Number of sides used (either one or two)
1B | | |
|---------------| -+
1C | | |-- Number of hidden sectors
1D | | |
|---------------| -+
| |
```
##### _Figure 3.11 DPB structure_
```
-----------------
BASE -> | | ---- drive number
|---------------|
+1 | | ---- media ID
|---------------| -+
+2 | | |-- sector size
+3 | | |
|---------------| -+
+4 | | ---- directory mask
|---------------|
+5 | | ---- directory shift
|---------------|
+6 | | ---- cluster mask
|---------------|
+7 | | ---- cluster shift
|---------------| -+
+8 | | |-- top sector of FAT
+9 | | |
|---------------| -+
+10 | | ---- number of FATs
|---------------|
+11 | | ---- number of directory entries
|---------------| -+
+12 | | |-- top sector of data area
+13 | | |
|---------------| -+
+14 | | |-- amount of cluster + 1
+15 | | |
|---------------| -+
+16 | | ---- number of sectors required for one FAT
|---------------| -+
+17 | | |-- top sector of directory area
+18 | | |
|---------------| -+
+19 | | |-- FAT address in memory
+20 | | |
----------------- -+
```
Use the system call [Function 1BH (disk information acquisition)](#disk-information-acquisition) to access the DPB. This system call returns the DPB address in memory and other information for each drive written on the boot sector (see [section 4 "System call usage"](#4--system-call-usage) for the detailed usage).
#### FAT (file allocation table)
In MSX-DOS, a "cluster" is the data unit for writing to the disk. Files larger than a cluster are written across multiple clusters. But in this case adjacent clusters are not always used. In particular, after creating and deleting files many times, clusters which are no longer used are scattered at random across the disk. When a large file is created for such cases, the file is broken down into several clusters and these clusters are stored where space is available. The linkage information is kept at the beginning so that the file can be recreated. This is the main function of the FAT.
When a bad cluster is found, FAT is also used to record that location, so access will not be made there any more. Linkage information of clusters and information concerning bad clusters is necessary for managing disk files. Without this information, the whole disk will be unusable. For this reason, more than one FAT is always prepared in case of accidental erasure.
Figure 3.2 shows an example of a FAT. The first byte is called the "FAT ID" which contains the value indicating the type of media (the same value as media ID in [Table 3.1](#table-31--media-supported-by-msx-dos)). The next two bytes contains meaningless dummy values. From the fourth byte (start address + 3), actual linkage information is recorded in an irregular format of 12 bits per cluster. Each 12-bit area containing linkage information is called a FAT entry. Note that the FAT entry begins with number 2. The number of the FAT entry is also the number of the cluster corresponding to it. Read the 12-bit linkage information recorded in the FAT entry in the way shown in [Figure 3.13](#figure-313--reading-fat).
##### _Figure 3.12 FAT example_

The linkage information is the value indicating the next cluster number. FFFH means that the file ends with that cluster. The example of [Figure 3.12](#figure-312--fat-example) shows a file of three clusters, (cluster #2 -> cluster #3 -> cluster #4), and a file of two clusters, (cluster #5 -> cluster #6). The linkage from the cluster with the smaller number is only for easy comprehension. In actual practice, numbers are not necessarily ordered.
##### _Figure 3.13 Reading FAT_

#### Directory
The FAT as described above, relates the physical location of data on the disk and does not include information about the contents of data written there. Thus, an information resource other than FAT is required to know what kind of data is in a file. This resource is called a "directory". A directory entry is composed of 32 bytes and records file names, file attributes, date created, time created, number of the top cluster of the file, and file size, as shown in [Figure 3.14](#figure-314--directory-construction).
"File attributes" in the directory are used for specifying the invisibility attribute in a file. Specifying "1" in the second bit from the lowest of this byte prevents files specified in the directory from being accessed by the system call (see [Figure 3.15](#figure-315--invisibility-attribute-of-the-file)). MS-DOS also has a file attribute byte which permits a write-prohibit attribute using another bit, but MSX-DOS does not support this feature.
The date and time are recorded so that two bytes of each are divided into three bitfields, as shown in [Figure 3.16](#figure-316--bitfield-representing-time) and [Figure 3.17](#figure-317--bitfield-representing-date). Since only 5 bits are prepared for the "time" bitfield, the minimum unit for time is two seconds. The year (1980 to 2079) is specified by using 0 to 99 in 7 bits.
##### _Figure 3.14 Directory construction_
```
Directory ----------------- -+
header --> | . | |
. |-- filename (8 characters)
. |
+7 | | |
|---------------| -+
+8 | | |
+9 | | |-- extension (3 characters)
+10 | | |
|---------------| -+
+11 | | ---- file attribute
|---------------| -+
. | . | |
. . |-- space for compatibility with MS-DOS
. . | (not used by MSX-DOS)
| | |
|---------------| -+
+22 | | |-- time created
+23 | | |
|---------------| -+
+24 | | |-- date created
+25 | | |
|---------------| -+
+26 | | |-- top cluster of the file
+27 | | |
|---------------| -+
+28 | | |
+29 | | |-- file size
+30 | | |
+31 | | |
----------------- -+
```
##### _Figure 3.15 Invisibility attribute of the file_
```
(11th byte of the directory)
---------------------------------
| . | . | . | . | . | . | X | . |
---------------------------------
|
| 0 : enables normal acess
+----->
1 : disables access
```
##### _Figure 3.16 Bitfield representing time_
```
(23rd byte of the directory) (22nd byte of the directory)
--------------------------------- ---------------------------------
| h4| h3| h2| h1| h0| m5| m4| m3| | m2| m1| m0| s4| s3| s2| s1| s0|
--------------------------------- ---------------------------------
| | | |
+-------------------+-----------------------------+-------------------+
hour (0 to 23) minute (0 to 59) second /2 (0 to 29)
|
"second" value when multiplied by 2 --+
```
##### _Figure 3.17 Bitfield representing date_
```
(25th byte of the directory) (24th byte of the directory)
--------------------------------- ---------------------------------
| y6| y5| y4| y3| y2| y1| y0| m3| | m2| m1| m0| d4| d3| d2| d1| d0|
--------------------------------- ---------------------------------
| | | |
+---------------------------+---------------------+-------------------+
year (0 to 99) month (1 to 12) day (1 to 31)
|
+-- corresponds to 1980 to 2079
```
The place where this directory information is actually recorded is the directory area on the disk (see [Figure 3.9](#figure-39--relation-of-locations-of-elements-in-the-disk)). The location (top sector) is recorded in the DPB. Directory entries (locations of directory storage) are arranged every 32 bytes in the driectory area, as shown in [Figure 3.18](#figure-318--organisation-of-directory-area). When a file is created, the directory is created at the lowest value of unused directory entries. Deleting a file causes E5H to be written to the first byte of the corresponding directory entry, which is empty. After all direcotry entries are exhausted, new files cannot be created even if there is a lot of unused space on the disk. The number of directory entries, that is, the number of files which can be created on one disk is also recorded in the DPB.
##### _Figure 3.18 Organisation of directory area_
```
|------ 32 bytes -------|
-------------------------
BASE -> | MSXDOS.SYS |
|-----------------------|
+32 | COMMAND.COM |
|-----------------------|
+64 | E5H | | ⟵ The directory entry whose first byte is E5H is currently unused
|-----------------------|
+96 | TEST |
|-----------------------|
| . |
. |
.
| |
|-----------------------|
+32 * n | 00H | | ⟵ The directory entry whose first byte is 00H has never been used
|-----------------------|
| |
```
### 3.2 File Access
#### FCB (file control block)
Using information recorded in the directory area allows data to be treated as a "file". The advantage of this method is that the data location is not represented by an absolute number such as sector number or cluster number; instead, the file can be specified with a "name". The programmer need only specify the file name and the system will do all the work concerned with accessing the requested file. In other words, the programmer need not understand the details of which sectors the file occupies. In this case, FCB plays an important role for directories.
FCB is the area for storing information needed to handle files using system calls. Handling one file requires 37 bytes of memory each, as shown in [Figure 3.19](#figure-319--organization-of-fcb). Although the FCB can be located anywhere in memory, the address 005CH is normally used to utilize MSX-DOS features.
##### _Figure 3.19 Organization of FCB_
```
FCB ------
bytes | 0 | drive number
from |----|
top | 1 | file name
| | | filename ..... 8 bytes
V | 11 | extension .... 3 bytes
|----|
| 12 | current block
| 13 | number of blocks from the top of the file to the current block
|----|
| 14 | record size
| 15 | 1 to 65535
|----|
| 16 | file size
| | 1 to 4294967296
| 19 |
+-- |----|
| | 20 | date
| | 21 | same form as directory
(1) |----|
| | 22 | time
| | 23 | same form as directory
+-- |----|
| | 24 | device ID
| |----|
| | 25 | directory location
| |----|
| | 26 | top cluster number of the file
(2) | 27 |
| |----|
| | 28 | last cluster number accessed
| | 29 |
| |----|
| | 30 | relative location from top cluster of the file
| | 31 | number of clusters from top of the file to the last cluster accessed
+-- |----|
| 32 | current record
|----|
| 33 | random record
| | record order from the top of the file
| 36 | usually stores the last record made random access
------
```
**Notes:** FCB usages differ, depending on whether they use CP/M compatible system calls or additional system calls. See the decription below for details.
(1) When using version 2 of MSX-DOS, here is stored the volume-id of the disk, and should not be modified by the program.
(2) When using version 2 of MSX-DOS, here is stored internal information relative to the physical location of the file on the disk. The format of this information is different from shown in figure 3.19, and should not be modified by the program.
* drive number (00H)
Indicates the disk drive containing the file.
(0 -> default drive, 1 -> A:, 2 -> B:...)
* filename (01H to 08H)
A filename can have up to 8 characters. When it has less than 8, the rest are filled in by spaces (20H).
* extension (09H to 0BH)
A extension can have up to 8 characters. When it has less than 3, the rest are filled in by spaces (20H).
* current block (0CH to 0DH)
Indicates the block number currently being referred to by sequential access (see function [14H](#sequential-readout), [15H](#sequential-writing-to-the-disk) in [section 4](#4--system-call-usage)).
* record size (0EH to 0FH)
Specifies the size of data unit (record) to be read or written at one access, in bytes (see function [14H](#sequential-readout), [15H](#sequential-writing-to-the-disk), [21H](#random-reading-from-the-disk), [27H](#random-readout---2-random-block-access), [28H](#random-writing---3)).
* file size (10H to 13H)
Indicates the size of the file in bytes.
* date (14H to 15H)
Indicates date when a file was last written. The format is the same as the one recorded in the directory.
* time (16H to 17H)
Indicates time when a file was last written. The format is the same as the one recorded in the directory.
* device ID (18H)
When a peripheral is opened as a file, the value shown in [Table 3.10](#table-310--device-id) is specified for this device ID field. For normal disk files, the value of this field is 40H + drive number. For example, the device ID for drive A is 40H (for future expansion, application programs should not use the ID byte).
##### _Table 3.10 Device ID_
```
----------------------------------
| Device name | Device ID |
|--------------------+-----------|
| CON (Console) | 0FFH |
| PRN (Printer) | 0FBH |
| LST (List=Printer) | 0FCH |
| AUX (Auxiliary) | 0FEH |
| NUL (Null) | 0FDH |
----------------------------------
```
* directory location (19H)
Indicates the order of the directory entries of a file in the directory area.
* top cluster (1AH to 1BH)
Indicates the top cluster of the file in the disk.
* last cluster accessed (1C to 1DH)
Indicates the last cluster accessed.
* relative location from top cluster of last cluster accessed (1EH to 1FH)
Indicates the relative location from the top cluster of the last cluster accessed.
* current record (20H)
Indicates the record currently being referred to by sequential access (see function [14H](#sequential-readout), [15H](#sequential-writing-to-the-disk)).
* random record (21H to 24H)
Specifies a record to be accessed by random access or random block access. Specifying a value from 1 to 63 for the record size field described above causes all four bytes from 21H to 24H to be used, where only three bytes from 21H to 23H have meaning when the record size is greater than 63 (see function [14H](#sequential-readout), [15H](#sequential-writing-to-the-disk), [21H](#random-reading-from-the-disk), [22h](#random-writing-to-the-disk), [27H](#random-readout---2-random-block-access), [28H](#random-writing---3)).
#### Opening a file
A special procedure is required to open a file when using FCB. "Opening a file" means, at the system call level, transforming the incomplete FCB whose file name field is only defined for the complete FCB, by using information written in the directory area. [Figure 3.20](#figure-320--beforeafter-opening-fcb) shows the differences between "unopened FCB" and "opened FCB".
##### _Figure 3.20 Before/after opening FCB_

#### Closing a file
When a file is opened and written to, the contents of each field of FCB, such as size, is also modified. Unless the updated FCB information is returned to the directory area, directory information and the actual contents of the file might be different at the next file access. This operation to return the updated FCB information to the directory corresponds to closing a file at the system call level.
#### Random block access (file management by records)
MSX-DOS has two system calls dealing with random access, "RANDOM BLOCK READ" and "RANDOM BLOCK WRITE". With these system calls, a file can be divided into data units of any size, which can be handled by numbers, such as 0, 1, 2, ..., from the top. This data unit is called a "record". Record size can be any value of more than one byte. So, treating a whole file as one record (extreme sequential access), treating data with one byte as one record (extreme random access), or treating 128 bytes as one record (the CP/M way) are all possible.
In this case, the FCB fields, "record size" and "random record" are used to specify the record. The value of the record size field is the number of bytes in one record. Random record fields can have any record number to be accessed (for more detailed usage, see descriptions of each system call).
##### _Figure 3.21 File and record_

#### Sequential access (file management by fixed-length record + current record + current block)
MSX-DOS can also access files the same way as CP/M for purposes of compatibility. One way is the sequential file which is managed by "current record" and "current block". This uses a 128-byte fixed-length record as the basic unit of data. File access is always done from the top sequentially and the number of records which was accessed is counted at the current record field of FCB. The value of the current record field is reset to 0 when it reaches 128, and the carry is counted in the current block field.
#### Random access (file management by fixed-length record + random record)
A second method included to keept compatibility with CP/M is a random access method using random record fields. It can access the record of any location but the record size is fixed at 128 bytes.
## 4. SYSTEM CALL USAGE
The system calls are a collection of general-purpose subroutines which handle the basic input/output operations of MSX-DOS. Having these system calls gathered into BIOS in a predefined manner permits the basic functions of the MSX disk system to be easily accessed.
There are two purposes of system calls; first, to reduce programming time by preprogramming basic functions; second, to increase portability by the fact that all programs share the same basic functions. Utilizing system calls shortens program development time and makes the developed program highly portable.
To execute a system call, enter the defined function number in the C register of the Z80 CPU and call one of the following addresses:
```
0005H ................. MSX-DOS
F37DH (&HF37D) ........ MSX DISK-BASIC
```
For example, when the function number is 01FH and the system call requires 00H to be set in the A register, the following assembler code can be used with MSX-DOS:
```
LD A,00H
LD C,01FH
CALL 0005H
.
.
.
```
The CALL statement is also used in operations that return values or restore registers from memory. System calls can also be used from DISK-BASIC by using the entry address of F37DH. For this case, store the machine codes in the area allocated by the CLEAR statement and call its start address using the USR function.
### System call format
This section introduces system call usages in the following notation:
* **Function**: function number
* **Setup**: value needed to be set in register or memory by programmer
* **Return value**: value set in register by system call
#### Function:
The function number is used to identify the system call. When using a system call, set the function number in the C register.
#### Setup:
In this section, "setup:" indicates the value to be set in the named register or memory location before executing system calls.
#### Return value:
The result obtained by a system call is normally set in a register or memory location. This is called output in this section and "return value:" indicates where and how this output is set.
Is important to note that when using system calls, the contents of registers other than those specified are sometimes destroyed. So, before using system calls, store the contents of registers whose value you do not want to change in an appropriate place (stack, for example) before executing system calls.
There are forty-two MSX system calls. These are listed in [Table 3.11](#table-311--list-of-system-calls), and are described in this section. There are four categories:
* Peripheral I/O
* Environment setting
* Absolute READ/WRITE (direct access to sector)
* File access using FCB
##### _Table 3.11 List of System Calls_
| Function no. | Function |
| --- | --- |
| 00H | system reset
| 01H | get one character from console (input wait, echo back, control code check)
| 02H | send one character to console
| 03H | get one character from auxiliary device
| 04H | send one character to auxiliary device
| 05H | send one character to printer
| 06H | get one character from console (no input wait, no echo back, no control code check) / one character output
| 07H | get one character from console (input wait, no echo back, no control code check)
| 08H | get one character from console (input wait, no echo back, control code check)
| 09H | send string
| 0AH | get string
| 0BH | check input from console
| 0CH | get version number
| 0DH | disk reset
| 0EH | select default drive
| 0FH | open file
| 10H | close file
| 11H | search the first file matched with wildcard
| 12H | search the second and after the second file matched wildcard
| 13H | delete file
| 14H | read sequential file
| 15H | write sequential file
| 16H | create file
| 17H | rename file
| 18H | get login vector
| 19H | get default drive name
| 1AH | set DMA address
| 1BH | get disk information
| 1CH-20H | no function
| 21H | write random file
| 22H | read random file
| 23H | get file size
| 24H | set random record field
| 25H | no function
| 26H | write random block
| 27H | read random block
| 28H | write random file (00H is set to unused portion)
| 29H | no function
| 2AH | get date
| 2BH | set date
| 2CH | get time
| 2DH | set time
| 2EH | set verify flag
| 2FH | read logical sector
| 30H | write logical sector
**Note**: System call function numbers are from 00H to 30H; the following seven numbers are blank: 1CH to 20H, 25H, 29H
Calling these blank function system calls do nothing except setting 00H in the A register. System calls after function 31H are undefined. Using them may cause unpredictable results (not advisable).
##### List 3.3 Utility routines
```
;**************************************************************
;
; List 3.3 utility.mac
;
; these routines are used in other programs
;
; GETARG, STOHEX, PUTHEX, PUTCHR, DUMP8B
;
;**************************************************************
;
PUBLIC GETARG Note: Five utility routines included in
PUBLIC STOHEX this program list will be used in
PUBLIC PUTHEX sample programs later.
PUBLIC PUTCHR
PUBLIC DUMP8B
BDOS: EQU 0005H
DMA: EQU 0080H
;----- DE := address of arg(A)'s copy -----
GETARG: PUSH AF Note: Nth parameter (N is specified by
PUSH BC A register) of the command line
PUSH HL stored in default DMA area
(0080H to ) is loaded in memory and
LD C,A its starting address is returned in
LD HL,DMA DE register.
LD B,(HL)
INC HL
INC B
SKPARG: DEC B
JR NZ,NOARG
SKP1: LD A,(HL)
INC HL
CALL TERMCHK
JR NZ,SKP1
SKP2: LD A,(HL)
INC HL
CALL TRMCHK
JR Z,SKP2
DEC HL
DEC C
JR NZ,SKPARG
CPYARG: LD DE,BUFMEM
CPY1: LD A,(HL)
LD (DE),A
INC HL
INC DE
CALL TRMCHK
JR NZ,CPY1
DEC DE
LD A,"$"
LD (DE),A
LD DE,BUFMEM
JR EXIT
NOARG: LD DE,BUFMEM
LD A,"$"
LD (DE),A
EXIT: POP HL
POP BC
POP AF
RET
TRMCHK: CP 09H
RET Z
CP 0DH
RET Z
CP " "
RET Z
CP ";"
RET
;----- HL := hexadecimal value of [DE] -----
SOTHEX: PUSH AF Note: Hexadecimal string indicated by
PUSH DE DE register is converted into
LD HL,0000H two-byte integer and stored in
CALL STOH1 HL register.
POP DE
POP AF
RET
STOH1: LD A,(DE)
INC DE
SUB "0"
RET C
CP 10
JR C,STOH2
SUB "A"-"0"
RET C
CP 6
RET NC
ADD A,10
STOH2: ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
OR L
LD L,A
JR STOH1
;----- print A-reg, in hexadecimal form (00-FF) -----
PUTHEX: PUSH AF Note: Contents of A register is displayed
RR A using two hexadecimal digits.
RR A
RR A
RR A
CALL PUTHX1
POP AF
PUTHX1: PUSH AF
AND 0FH
CP 10
JR C,PUTHX2
ADD A,"A"-10-"0"
PUTHX2: ADD A,"0"
CALL PUTCHR
POP AF
RET
;----- put character -----
PUTCHR: PUSH AF
PUSH BC
PUSH DE
PUSH HL
LD E,A
LD C,02H
CALL BDOS
POP HL
POP DE
POP BC
POP AF
RET
;----- dumps 8bytes of [HL] to [HL+7] in hexa & ASCII form -----
DUMP8B: PUSH HL Note: Contents of eight bytes after the
LD B,8 address indicated in HL register
DUMP1: LD A,(HL) are dumped in both hexadecimal
INC HL and character codes.
CALL PUTHEX
LD A," "
CALL PUTCHR
DJNZ DUMP1
POP HL
LD B,8
DUMP2: LD A,(HL)
INC HL
CP 20H
JR C,DUMP3
CP 7FH
JR NZ,DUMP4
DUMP3: LD A,"."
DUMP4: CALL PUTCHR
DJNZ DUMP2
LD A,0DH
CALL PUTCHR
LD A,0AH
CALL PUTCHR
RET
;----- work area -----
BUFMEM: DS 256
END
```
### 4.1 Peripheral I/O
The following system calls are intended for input/output operations. Some examples include console I/O (screen/keyboard), auxiliary I/O (external input/output), and printer I/O. Since subroutines such as getting information from the keyboard or controlling printers are necessary for most programs, you will find the system calls described in this section useful for general programming.
#### Console input
* **Function**: 01H
* **Setup**: none
* **Return value**: A register ⟵ one character from console
When there is no input (no key pressed and input buffer empty), an input is wait for. Input characters are echoed back to the console. The following control character input is allowed: Ctrl-C causes program execution to be halted and a return to the MSX-DOS command level; Ctrl-P causes any sucessive input to also echoed to the printer until Ctrl-N is accepted; Ctrl-S causes the display to stop until any key is pressed.
```
Ctrl-C ........ system reset
Ctrl-P ........ printer echo
Ctrl-N ........ halt printer echo
Ctrl-S ........ pause display
```
#### Console output
* **Function**: 02H
* **Setup**: E register ⟵ character code to be sent out
* **Return value**: none
This system call displays the character specified by the E register on the screen. It also checks the four control characters, listed above.
#### External input
* **Function**: 03H
* **Setup**: none
* **Return value**: A register ⟵ one character from AUX device
This system call checks four control characters.
#### External output
* **Function**: 04H
* **Setup**: E register ⟵ character code to send to AUX device
* **Return value**: none
This system call checks four control characters.
#### Printer output
* **Function**: 05H
* **Setup**: A register ⟵ one character from console
* **Return value**: ```
This system call does not echo back. It treats control characters in the same way as [function 01H](#console-input).
#### Direct console input/output
* **Function**: 06H
* **Setup**: E register ⟵ character code to be send to the console. When 0FFH is specified, the character will be input from the console.
* **Return value**: When the E register is set to 0FFH (input), the result of input is in the A register. The value set in the A register is the character code of the key, if it was pressed; otherwise, the value is 00H. When the E register is set to a value other than 0FFH (output), there is no return value.
This system call does not support control characters and does not echo back input. This system call checks four control characters.
#### Direct console input - 1
* **Function**: 07H
* **Setup**: none
* **Return value**: A register ⟵ one character from console
This system call does not support control characters, nor echo back.
#### Direct console input - 2
* **Function**: 08H
* **Setup**: none
* **Return value**: A register ⟵ one character from console
This system call does not echo back. It treats control characters in the same way as [function 01H](#console-input).
#### String output
* **Function**: 09H
* **Setup**: DE register ⟵ starting address of string, prepared on memory, to be sent to the console.
* **Return value**: none
24H ("$") is appended to the end of the string as the end symbol. This system call checks and performs four control character functions, as listed previously.
#### String input
* **Function**: 0AH
* **Setup**: The address of memory where the maximum number of input characters (1 to 0FFH) is set should be set in the DE register.
* **Return value**: Number of characters actually sent from console is set in the address, one added to the address indicated by the DE register; string sent from console is set in the area from the address, two added to the address indicated by the DE register.
Return key input is considered as the end of console input. However, when the number of input characters exceeds the specified number of characters (contents indicated by DE register, 1 to 255), characters within the specified number of characters will be treated as an input string and set in memory, and the operation ends. The rest of characters including the return key are ignored. Editing with the template is available to string input using this system call. This system call checks and performs four control character function, as listed previously.
#### Console status check
* **Function**: 0BH
* **Setup**: none
* **Return value**: 0FFH is set in the A register when the keyboard is being pressed; otherwise, 00H is set.
This system call checks and performs four control character function, as listed previously.
### 4.2 Environment Setting and Readout
The following system calls set the MSX system environment; for example, changing the default drive, or setting various default values of the system.
#### System reset
* **Function**: 00H
* **Setup**: none
* **Return value**: none
When this is called in MSX-DOS, the system is reset by jumping to 0000H. When MSX DISK-BASIC call this, it is "warm started". That is, it returns to BASIC command level without destroying programs currently loaded.
#### Version number acquisition
* **Function**: 0CH
* **Setup**: none
* **Return value**: HL register ⟵ 0022H
This system call is for acquiring various CP/M version numbers, on MSX-DOS, however, 0022H is always returned.
#### Disk reset
* **Function**: 0DH
* **Setup**: none
* **Return value**: none
If there is a sector which has been changed but not written to the disk, this system call writes it to the disk, then it sets the default drive to drive A and sets DMA to 0080H.
#### Default drive setting
* **Function**: 0EH
* **Setup**: E register ⟵ default drive number (A = 00H, B = 01H, ...)
* **Return value**: none
Disk access by the system calls are made to the drive indicated by the default drive number, unless otherwise specified. Note that, when the drive number, which is set in the FCB specified upon calling the system call, is other than 00H, the default drive setting made by this system call is ignored.
#### Login vector acquisition
* **Function**: 18H
* **Setup**: none
* **Return value**: HL register ⟵ online drive information
The online drive is the drive connected to MSX normally when the disk system is booted up. Executing this system call causes each drive to be examined whether it is online, and the result is returned in the HL register as shown in [Figure 3.22](#figure-322--login-vector). When the bit is "1", the corresponding drive is online; otherwise it is not.
##### _Figure 3.22 Login vector_
```
------------------------------------------------------------------------
| register name | H | L |
|----------------+--------------------------+--------------------------|
| bit number | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |
|----------------+--------------------------+--------------------------|
| drive name | meaningless on MSX-DOS | H: G: F: E: D: C: B: A: |
|----------------+-----------------------------------------------------|
| online/offline | 1 is set for online and 0 for offline in each bit |
------------------------------------------------------------------------
```
#### Default drive acquisition
* **Function**: 19H
* **Setup**: none
* **Return value**: A register ⟵ defaut drive number (A = 00H, B = 01H, ...)
#### Setting of address to be transferred to
* **Function**: 1AH
* **Setup**: DE register ⟵ address setting to be transferred to (DMA address)
* **Return value**: none
Though DMA address is initialized to 0080H at system reset, it can be reset to any address by using this system call.
#### Disk information acquisition
* **Function**: 1BH
* **Setup**: E register ⟵ number of the objective drive (default drive = 00H, A = 01H, B = 02H, ...)
* **Return value**:
* A register ⟵ number of logical sectors per one cluster (FFH if E register is set inappropriate)
* BC register ⟵ logical sector size
* DE register ⟵ amount of clusters
* IX register ⟵ DPB starting address
* IY register ⟵ FAT starting address on memory
This system call gets the information about the disk in the specified drive. Specifying 00H for the drive number specifies the default drive. For other than that, specify 01H for drive A, 02H for drive B, and so on.
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Date acquisition
* **Function**: 2AH
* **Setup**: none
* **Return value**:
* HL register ⟵ year
* D register ⟵ month
* E register ⟵ day of month
* A register ⟵ day of week
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Date setting
* **Function**: 2BH
* **Setup**:
* HL register ⟵ year
* D register ⟵ month
* E register ⟵ day of month
* **Return value**: A indicates whether the system call has done succesfully. If successful, the A register is set to 00H; otherwise, 0FFH.
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Time acquisition
* **Function**: 2CH
* **Setup**: none
* **Return value**:
* H register ⟵ hour
* L register ⟵ minute
* D register ⟵ second
* E register ⟵ 1/100 second
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Time setting
* **Function**: 2DH
* **Setup**:
* H register ⟵ hour
* L register ⟵ minute
* D register ⟵ second
* E register ⟵ 1/100 second
* **Return value**: If successful, the A register is set to 00H; otherwise, 0FFH
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Verify flag setting
* **Function**: 2EH
* **Setup**:
* E register ⟵ 00H, when resetting verify flag
* E register ⟵ value other than 00H, when setting the verify flag
* **Return value**: none
Setting the verify flag causes successive writing to the disk to be done in mode "verify on". That is, by reading the contents written on the disk, the check is made to compare them with the contents to be written.
This system call has been created for MSX-DOS and is not compatible with CP/M.
### 4.3 Absolute READ/WRITE (direct access to sectors)
MSX manages the disk with the "logical sector" as a minimum unit. The logical sector is defined independent of the physical secotrs of the disk, and is numbered from 0 to the maximum logical sector (maximum number depends on the kind of the disks).
Logical sectors enable users of MSX-DOS or MSX DISK-BASIC to access the disk without being concerned about the number of physical sectors per track, where that number depends on the media type of the disk. In fact, by utilizing system calls which use FCB (file control block), the file can be easily handled in detail even without considering logical sectors, so the user does not even need to use logical sectors. But for some purposes, access using logical sectors is desirable, so MSX-DOS ans MSX DISK-BASIC offer system calls which can access logical sectors.
This section describes the system calls which access the disk by use of logical sectors.
#### Reading from the disk using logical sectors
* **Function**: 2FH
* **Setup**: The logical sector number to be read from (for more than one logical sector, the starting logical sector number) should be set in the DE register. The number of logical sectors to be read should be set in the H register, and the drive number (00H for drive A, 01H for drive B, and so on. The same follows for function 30H below) to be used to read should be set in the L register.
* **Return value**: The contents read are set in the DMA buffer.
This system call reads out a specified number of continuous logical sectors from the specified logical sector of the specified drive and stores the contents in memory after DMA. It then stores the contents of what it has read in memory after DMA. [Function 1AH](#setting-of-address-to-be-transferred-to) (which specifies the address it is to be transferred to) assures that there is enough available space in memory.
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Writing to the disk using logocal sectors
* **Function**: 30H
* **Setup**: Contents to be written should be set in memory area after the address indicated by DMA. The logical sector number from where the writing begins should be set in the DE register. The number of logical sectors to be written should be set in the H register. The drive number to be written to should be set in the L register.
* **Return value**: none
This system call has been created for MSX-DOS and is not compatible with CP/M.
##### _List 3.4 Cluster dump_
```
;*********************************************************
;
; List 3.4 cluster dump
;
; this program must link List 3.3
;
;*********************************************************
;
EXTRN GETARG Note: The first 128 bytes of an arbitrary
EXTRN STOHEX cluster specified in the command
EXTRN PUTHEX line are dumped.
EXTRN PUTCHR
EXTRN DUMP8B
BDOS EQU 0005H
;----- program start -----
LD A,1
CALL GETARG ;[DE] := 1st argument of command line
CALL STOHEX ;HL := evaluate [DE] as hexadecimal
; this is the target cluster No.
PUSH HL
LD E,00H ;requests the default drive
LD C,1BH ;get disk information
CALL BDOS
POP HL
CP 0FFH ;fail ?
JR NZ,L2 ;if not fail, A := sector/cluster and goto L2
LD DE,ERMSG1 ;[DE] := 'Cannot get Disk information'
LD C,09H ;string putput function
CALL BDOS
RET ;error return
L2: LD E,(IX+12) ;DE := 1st sector of data area
LD D,(IX+13)
DEC HL
DEC HL ;HL := Cluster No. - 2
LD B,H
LD C,L ;BC := Cluster No. - 2
LOOP: DEC A ;Count N times
JR Z,RESULT
ADD HL,BC
JR LOOP
RESULT: ADD HL,DE ;HL := sector of target cluster
PUSH HL ;save target sector
LD DE,NEWDMA ;we reserved 1024 bytes area for DMA
LD C,1AH ;Set DMA address function
CALL BDOS
LD C,19H
CALL BDOS ;default drive ?
LD L,A
POP DE ;DE := target sector
LD H,1 ;H := 1 (read 1 sector only)
LD C,2FH ;absolute read function
CALL BDOS ;data will be set into DMA
DUMP: LD HL,NEWDMA ;HL := DMA address
LD DE,0000H ;DE := relative address from cluster top
LD B,16 ;dump 16 lines
DLOOP: PUSH BC
LD A,D
CALL PUTHEX
LD A,E
CALL PUTHEX
LD A," "
CALL PUTCHR
PUSH HL
LD HL,8
ADD HL,DE
EX DE,HL ;DE := DE+8
POP HL
CALL DUMP8B ;8 bytes dump subroutine (in another file)
POP BC
DJNZ DLOOP
RET ;all work have done.
;----- work area -----
NEWDMA: DS 1024 ;Private DMA area
ADRS: DS 2
ERMSG1: DB "Cannot get Disk information.$"
ERMSG2: DB "Cannot read that cluster.$"
END
```
### 4.4 File Access Using FCB
Since accessing a file is difficult when using the system calls described in the previous section (which read and write logical sectors directly), system calls using FCB are needed to easier access the disk by specifying files.
There are three categories of system calls using FCB. First is sequential file access and second is random file access, both are offered to maintain CP/M compatibility. The third is what gives MSX-DOS its power: random block access. This method is not available in CP/M. Random block access has the following features:
* Any record size can be specified
* Random access can be made to multiple records
* File size can be controlled in bytes
This section describes system calls for file access using FCB, including random block access. Note that the following three functions do not work correctly when FCB is in the address range 4000H to 7FFFH:
1. [Function call 11H](#file-search---1)
2. [Function call 12H](#file-search---2)
3. Input/output for devices (CON, PRN, NUL, AUX)
#### Opening files
* **Function**: 0FH
* **Setup**: DE register ⟵ starting address of FCB which is not opened
* **Return value**: 00H is set in the A register when a file is opened succeessfully; otherwise 0FFH is set. When a file is opened successfully, each field of the FCB is set.
When 00H is specified for a drive number, the default drive set by [function 0EH (default drive setting)](#default-drive-setting) is used. To open a file on another drive, specify 01H for drive A, 02H for drive B and so on.
When a file is opened by this system call, all FCB fields except record size, current block, current record, and random record are set using information from the directory area on the disk. Fields which are not set should be set by the user after executing this system call, if needed. The state that each field of FCB is set is "the state that file is opened" when using system calls using FCB, and, in this case, system calls which access the file using FCB, described below, can be used.
#### Closing files
* **Function**: 10H
* **Setup**: DE register ⟵ starting address of opened FCB
* **Return value**: 00H is set in the A register when file is closed scuccessfully; otherwise, 0FFH is set.
By writing the current contents of FCB in memory to the corresponding directory area on the disk, file information can be kept current. When the file is only read, it does not need to be closed by using this system call.
#### File search - 1
* **Function**: 11H
* **Setup**: DE register ⟵ starting address of FCB which is not opened
* **Return value**: 00H is set in the A register when the file is found; otherwise 0FFH is set. When the file is found, the directory entry (32 bytes) of the file on the disk is set in the area indicated by DMA, and FCB drive number is set (thus, 33 bytes are used).
Wildcard characters can be used in the name of the file. For example, a specification "????????.c" causes any file name with an extension of "c" to be searched for, and the directory information of the file first found is written in after DMA. To find all matching files or to see whether there is only one matching file, use [function 12H](#file-search---2) described below.
#### File search - 2
* **Function**: 12H
* **Setup**: none
* **Return value**: 00H is set in the A register when the file is found; otherwise 0FFH is set. When the file is found, the directory entry (32 bytes) of the file on the disk is set in the area indicated by DMA, and the FCB drive number is set (thus, 33 bytes are used).
This system call should be used to search for multiple files meeting the file name specification by wildcard characters in [function 11H](#file-search---1). So this function should not be used by itself.
This system call allows the directory information of files meeting the specifications in [function 11H](#file-search---1) to be listed in order, one by one.
#### Deleting files
* **Function**: 13H
* **Setup**: DE register ⟵ starting address of FCB which is not opened
* **Return value**: 00H is set in the A register when file is successfully deleted., otherwise 0FFH is set.
Using wildcard characters for the file name may cause more than one file to be deleted. Exercise caution when using wildcards to delete files.
#### Sequential readout
* **Function**: 14H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* FCB current block ⟵ starting block for readout
* FCB current record ⟵ starting record for readout
* **Return value**: 00H is set in the A register when readout is successful; otherwise 01H is set. When successful, one record which has been read is set in the area indicated by DMA.
The FCB current block and record will be updated automatically after the readout. That is, in successive readouts, the current block and record do not need to be set. The record size for readout is fixed at 128 bytes.
#### Sequential writing to the disk
* **Function**: 15H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* FCB current block ⟵ starting block for writing
* FCB current record ⟵ starting record for writing
* 128 bytes starting from DMA ⟵ data to be written
* **Return value**: 00H is set in the A register when writing is successful; otherwise 01H is set.
The FCB current block and record will be updated automatically after the readout.
#### Creating files
* **Function**: 16H
* **Setup**: DE register ⟵ starting address of FCB which is not opened
* **Return value**: 00H is set in the A register when the file is created successfully; otherwise 0FFH is set.
The record size, current block and record, and the random record of the FCB should be set after executing this system call.
#### Renaming files
* **Function**: 17H
* **Setup**: New file name should be set within 11 bytes after the 18th byte of the FCB (2nd byte of file size field of FCB = 16 bytes after old file name) corresponding to old file name (that is, it should be set in 18th to 28th byte), the FCB address should be set in the DE register.
* **Return value**: 00H is set in the A register when the file name is renamed successfully; otherwise 0FFH is set.
Wildcard characters can be used for both the new and old file names. For example, specifying "????????.o" for the old file name and "????????.obj" for the new file name causes the extension of all files having ".o" to be changed to ".obj".
#### Random reading from the disk
* **Function**: 21H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* random record in FCB ⟵ record for readout
* **Return value**: 00H is set in the A register when readout is successful; otherwise 01H is set. When successful, the contents of one record which has been read are set in the area indicated by DMA.
The lenght of the record is fixed to 128 bytes.
#### Random writing to the disk
* **Function**: 22H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* random record in FCB ⟵ record to be written to
* 128 bytes starting from DMA ⟵ data to be written
* **Return value**: 00H is set in the A register when writing is successful; otherwise 01H is set.
The lenght of the record is fixed to 128 bytes.
#### File size acquisition
* **Function**: 23H
* **Setup**: DE register ⟵ starting address of FCB which is not opened
* **Return value**: 00H is set in the A register when the function is successful; otherwise 00H is set. When successful, the size of the specified file is set in increments of 128 bytes, in the first three bytes of the random record field.
The file size is calculated in increments of 128 bytes. That is, 2 would be set for files ranging in size from 129 bytes to 256 bytes. Thus a file with 257 bytes would return a value of 3.
#### Random record field setting
* **Function**: 24H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* FCB current block ⟵ objective block
* FCB current record ⟵ objective record
* **Return value**: Current record position, calculated from the current block and record fields of specified FCB, is set in the random record field.
#### Random writing to the disk - 2 (random block access)
* **Function**: 26H
* **Setup**:
* DE register ⟵ the starting address from the FCB
* FCB record size ⟵ size of record to be written
* FCB random record ⟵ the record ID number
* HL register ⟵ the number of records to be written
* DMA memory buffer ⟵ the data to be written
* **Return value**: 00H is set in the A register when writing is successful; otherwise 01H is set.
After writing to the disk, the value of the random record field is automatically updated and points to the next record. The size of one record can be set to any value from 1 byte to 65535 bytes by setting the desired value in the FCB record size field. When 0 records are to be written, the file lenght is calculated at the record size multiplied by the record number. The rest is discarded.
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Random readout - 2 (random block access)
* **Function**: 27H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* FCB record size ⟵ record size to be read
* FCB random record ⟵ record to start reading
* HL register ⟵ number of records to be read
* **Return value**: 00H is set in the A register when data is read successfully; otherwise 01H is read. The number of records actually read is set back in the HL register. When this number is almost one, the data which has been read is set in the area indicated by DMA.
After readout, the random record field is automatically updated. After executing this system call, the total number of records actually read is set in the HL register. That is, if the end of file is reached before the specified number of records have been read, the actual number of records read will be returned in the HL register.
This system call has been created for MSX-DOS and is not compatible with CP/M.
#### Random writing - 3
* **Function**: 28H
* **Setup**:
* DE register ⟵ starting address of opened FCB
* FCB random record ⟵ record to be written
* 128 bytes in DMA buffer ⟵ data to be written
* **Return value**: 00H is set in the A register when writing is successful; otherwise, 01H is set.
The lenght of records is fixed at 128 bytes.
This system call is the same as 22H except for one point. When the file becomes large, 00H is written to the added records coming before the specified record.
##### _List 3.5 File dump_
```
;********************************************************
;
; List 3.5 file dump
;
; this program must link List 3.3
;
;********************************************************
;
EXTRN GETARG Note: gets the dump list of the file
EXTRN STOHEX specified at the command line
EXTRN PUTCHR
EXTRN PUTHEX
EXTRN DUMP8B
BDOS: EQU 0005H Note: The file name specified as the first
FCB: EQU 005CH parameter of the command line is
stored in the default FCB area
from (005CH)
;----- program start -----
LD DE,FCB ;DE := default FCB address
LD C,0FH ;open file function
CALL BDOS
OR A ;success ?
JR Z,READ ;if so, goto READ
LD DE,ERMSG1 ;[DE] := 'Cannot open that file'
LD C,09H ;string output function
CALL BDOS
RET ;error return
READ: LD A,2
CALL GETARG ;get 2nd argument of command line
CALL STOHEX ;HL := value of the argument
LD (ADRS),HL ;set address counter
LD DE,NEWDMA
LD C,1AH ;set DMA address function
CALL BDOS
LD HL,8
LD (FCB+14),HL ;record size := 8
LD HL,0
LD (FCB+33),HL
LD (FCB+35),HL ;random record := 0
RD1: LD HL,NEWDMA ;clear DMA area
LD B,8
RD2: LD (HL)," "
INC HL
DJNZ RD2
LD HL,1 ;read 1 record
LD DE,FCB
LD C,27H ;random block read function
CALL BDOS
OR A ;success ?
JR Z,DUMP ;if so, goto DUMP
LD DE,ERMSG2 ;[DE] := 'Ok.'
LD C,09H ;string output function
CALL BDOS
RET
DUMP: LD HL,(ADRS)
LD A,H
CALL PUTHEX
LD A,L
CALL PUTHEX
LD A," "
CALL PUTCHR
LD DE,8
ADD HL,DE
LD (ADRS),HL
LD HL,NEWDMA
CALL DUMP8B ;dump 8 bytes
JR RD1
;----- work area -----
ADRS: DS 2
NEWDMA: DS 8
;----- error message -----
ERMSG1: DB "Cannot open that file.$"
ERMSG2: DB "Ok.$"
END
```
## Changes from the original
- Remarks (1) and (2) about [the FCB format](#figure-319--organization-of-fcb) in version 2 of MSX-DOS have been added.
- Description of [function call 06H](#direct-console-inputoutput) is modified. The name of this function in the original text is "String output", and the setup description is "E register ⟵ starting address of string to send to the console. When 0FF is specified, the character will be sent to the console as character code."
- In description of function calls [13H (Deleting files)](#deleting-files) and [23H (File size acquisition)](#file-size-acquisition), the original text has "DE register ⟵ starting address of opened FCB" in setup field. Instead of this, the correct setup explanation is set.
- In description of function [26H (Random writing to the disk 2)](#random-writing-to-the-disk---2-random-block-access), the correct term "FCB" is set instead of "DMA" in DE register setup explanation.
- In description of function [27H (Random readout 2)](#random-readout---2-random-block-access), the phrase "When this number is almost one, the data which has been read is set in the area indicated by DMA" has been added.
- In [1.2 MSX-DOS Environment](#12-msx-dos-environment), "see Chapter 3" has been corrected to "see Section 3".