Page 1 of 1
Loading and reading from a text file
Posted: Tue May 27, 2008 2:36 pm
by Loknar
I am using Neon's tutorials at brokenthorn, and I have just finished the Bootloader tutorial. I have a FAT system setup. I was going to pause from doing the tutorials and do a little work myself. I am just trying to load a text file and add two numbers from seperate lines inside and add them together. An example text file would be:
I need to know how to load the file and read each line seperately using only BIOS commands. Any tips on how to do this?
Re: Loading and reading from a text file
Posted: Tue May 27, 2008 3:07 pm
by svdmeer
I need to know how to load the file and read each line seperately using only BIOS commands. Any tips on how to do this?
Search for documentation about "filesystems".
Re: Loading and reading from a text file
Posted: Tue May 27, 2008 3:22 pm
by jinksys
Loknar wrote:I have a FAT system setup.
What do you mean when you say setup? Are you implying that you have a FAT file system on disk?
http://www.osdever.net/documents.php?cat=13&sort=1
There are some documents on FAT on osdever.
Posted: Tue May 27, 2008 6:11 pm
by Loknar
By setup, I mean that I can search for and run a second stage in the form of a .sys file. I just do not know how to open a file and read from its contents.
Posted: Tue May 27, 2008 8:17 pm
by tadada
Read the tutorials at
http://www.Brokenthorn.com. There they go over the basics. The load a stage 1 bootloader which loads a stage 2 (which is saved as a .sys) and even load and run a C kernel (might be a c++ kernel) Not to mention they go over other basics like pmode, 32-bit, and other stuff that one might want.
Posted: Tue May 27, 2008 8:55 pm
by neon
The FAT12 code can be used to load a file of any type. Text files have no real specific format (Besides the EOF character, and parsing special characters like new lines)
I personally recommend waiting until the Stage 2 bootloader, as the first stage is limited to 512 bytes.
Once the image is in memory, then parse it line by line and go from there...
Posted: Wed May 28, 2008 1:02 am
by svdmeer
neon wrote:The FAT12 code can be used to load a file of any type. Text files have no real specific format (Besides the EOF character, and parsing special characters like new lines)
I personally recommend waiting until the Stage 2 bootloader, as the first stage is limited to 512 bytes.
Once the image is in memory, then parse it line by line and go from there...
My loader loads a file from a FAT12-volume without the need for non-fragmented systemfiles, support for both int 13h extensions and legacy int 13h functions, and no precalculated-sectors. It's a hard job to put that in 512 bytes, but it's possible. But before you even begin with an OS, learn the basics.
But it can only load the most necessary binary file for further loading the OS. Reading and parsing textfiles cannot be done from a small bootsector, waith until "stage 2" or whatever you call it.
Posted: Wed May 28, 2008 6:27 am
by Loknar
OK, I think I can put it in Stage two, I just need to get the FAT12 search code copied over. Will the FAT tables stay in memory after being loaded to run the second stage?
Posted: Wed May 28, 2008 6:33 am
by AJ
Yes - as long as you are certain that no other code / data has overwritten them (in other words, be careful that no other buffers overlap these areas).
Cheers,
Adam