OSDev.org
https://forum.osdev.org/

Loading and reading from a text file
https://forum.osdev.org/viewtopic.php?f=1&t=17081
Page 1 of 1

Author:  Loknar [ Tue May 27, 2008 2:36 pm ]
Post subject:  Loading and reading from a text file

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:

Code:
4
         2


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?

Author:  svdmeer [ Tue May 27, 2008 3:07 pm ]
Post subject:  Re: Loading and reading from a text file

Quote:
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".

Author:  jinksys [ Tue May 27, 2008 3:22 pm ]
Post subject:  Re: Loading and reading from a text file

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.

Author:  Loknar [ Tue May 27, 2008 6:11 pm ]
Post subject: 

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.

Author:  tadada [ Tue May 27, 2008 8:17 pm ]
Post subject: 

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.

Author:  neon [ Tue May 27, 2008 8:55 pm ]
Post subject: 

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...

Author:  svdmeer [ Wed May 28, 2008 1:02 am ]
Post subject: 

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.

Author:  Loknar [ Wed May 28, 2008 6:27 am ]
Post subject: 

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?

Author:  AJ [ Wed May 28, 2008 6:33 am ]
Post subject: 

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/