Low Level Filesystem Access: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
(Carl Oppedahl) | (Carl Oppedahl) | ||
==== Published RAM File-Handling Routines ==== | |||
User files reside in RAM starting at the lowest installed RAM address, with BA files at the bottom, followed by DO files and CO files. The directory is located in high memory from F962 to FA74. There is room to store sixteen filenames with eleven bytes of information each. The format of the filename information is given in table 18.1. | User files reside in RAM starting at the lowest installed RAM address, with BA files at the bottom, followed by DO files and CO files. The directory is located in high memory from F962 to FA74. There is room to store sixteen filenames with eleven bytes of information each. The format of the filename information is given in table 18.1. | ||
Line 20: | Line 22: | ||
| Eight-byte file name | | Eight-byte file name | ||
|} | |} | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
Line 48: | Line 51: | ||
| Internal use only | | Internal use only | ||
|} | |} | ||
Notice that no entry exists for filesize. To determine filesize, either of two techniques may be used. By comparing the various start addresses, one can determine the next file's starting address. The two start addresses may simply be subtracted. | |||
However, the filenames in the directory are not in order by start address, so one must search the entire directory to find the next file up. The ending address of the top file is stored at FBB2+. | |||
Another way to determine file size is by examining the files themselves, since the file itself always contains enough information to determine its size. With BA and DO files, you must scan the file, beginning at the start address, to locate the end-of-file marker. For DO files, the EOF characters is 26H. For BA files, it is a three character sequence, 00H,00H,00H. | |||
For CO files, there is no end-of-file character as such, but the length of the file is determined by adding the value of the third byte to the product of 256 times the fourth byte, plus six. | |||
=== Suzuki and Hayash === | |||
Sooner or later you will stumble across the names Suzuki and Hayashi in the directory. Hayashi is the PASTE buffer. Suzuki is the location of the BASIC program, if any, that has not yet been SAVEd and therefore does not have a name. (It is the file you sometimes see listed as BASIC*.) Sometimes you select BASIC from the main menu and find that some lines are still present from the last time you were in BASIC; these lines were hiding in Suzuki. | |||
Suzuki and Hayashi take up memory, of course, like any other files. It can be emptied by entering BASIC and typing NEW. | |||
=== DO Files === | |||
A DO file's first character is that which would be returned if you accessed it with TEXT or with BASIC's OPEN and INPUT statements. The file ends with the 26H described above. | |||
=== BA File Format === | |||
A BA file in RAM is set up as a sequence of lines, each with the following form: | |||
{| class="wikitable" border="1" | |||
|- | |||
| 2 bytes | |||
| Address of the line number to follow (little endian) | |||
|- | |||
| 2 bytes | |||
| Current line number (little endian) | |||
|- | |||
| Numerous bytes | |||
| Program line in tokenized form | |||
|- | |||
| 1 byte | |||
| Null (00H) | |||
|} | |||
== How RAM File Creation Works == | == How RAM File Creation Works == |
Revision as of 16:26, 24 February 2008
Excerpt from Inside the TRS-80 Model 100
(Carl Oppedahl)
Published RAM File-Handling Routines
User files reside in RAM starting at the lowest installed RAM address, with BA files at the bottom, followed by DO files and CO files. The directory is located in high memory from F962 to FA74. There is room to store sixteen filenames with eleven bytes of information each. The format of the filename information is given in table 18.1.
Byte | Description |
---|---|
0 | Directory flag (see table 18.2) |
1-2 | File start address |
3-10 | Eight-byte file name |
Bit | Description |
---|---|
7 | 0 if a killed file |
6 | 1 if a DO file |
5 | 1 if a CO file |
4 | 1 if located in ROM |
3 | 1 for inivisible file |
2-1 | Reserved |
0 | Internal use only |
Notice that no entry exists for filesize. To determine filesize, either of two techniques may be used. By comparing the various start addresses, one can determine the next file's starting address. The two start addresses may simply be subtracted.
However, the filenames in the directory are not in order by start address, so one must search the entire directory to find the next file up. The ending address of the top file is stored at FBB2+.
Another way to determine file size is by examining the files themselves, since the file itself always contains enough information to determine its size. With BA and DO files, you must scan the file, beginning at the start address, to locate the end-of-file marker. For DO files, the EOF characters is 26H. For BA files, it is a three character sequence, 00H,00H,00H.
For CO files, there is no end-of-file character as such, but the length of the file is determined by adding the value of the third byte to the product of 256 times the fourth byte, plus six.
Suzuki and Hayash
Sooner or later you will stumble across the names Suzuki and Hayashi in the directory. Hayashi is the PASTE buffer. Suzuki is the location of the BASIC program, if any, that has not yet been SAVEd and therefore does not have a name. (It is the file you sometimes see listed as BASIC*.) Sometimes you select BASIC from the main menu and find that some lines are still present from the last time you were in BASIC; these lines were hiding in Suzuki.
Suzuki and Hayashi take up memory, of course, like any other files. It can be emptied by entering BASIC and typing NEW.
DO Files
A DO file's first character is that which would be returned if you accessed it with TEXT or with BASIC's OPEN and INPUT statements. The file ends with the 26H described above.
BA File Format
A BA file in RAM is set up as a sequence of lines, each with the following form:
2 bytes | Address of the line number to follow (little endian) |
2 bytes | Current line number (little endian) |
Numerous bytes | Program line in tokenized form |
1 byte | Null (00H) |
How RAM File Creation Works
(Steve Adolph)
There are a number of pointers in himem that are used to demarcate the area used for basic files text files the three scratchpads machine language files
These pointers need to be modified according to what you need to insert or delete. For example, if you add a .CO file, then you don't need to modify the pointers that deal with the lower file space. But, adding a .BA moves all the pointers.
To create a file you need to
- wedge open the file space at a precise location, depending on the file type and the pointer values...placement is critical because of a fundamental assumption in the directory management
- load all the appropriate data into that memory hole, representing the actual file data
- create a directory entry with the right stuff in the entry to connect with that file
- run the magic LNKFIL routine that re-assigns all the directory links and connects them to the right files again
Deleting a file is kinda similar.
The fundamental assumption is that the order of the files must be maintained within each file type. That way the linker can deduce which file directory entry is associated with a specific file.
IE the next .BA directory entry must be associated with the next found file in the .BA area. and so on.