Loading and reading from a text file

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Loknar
Posts: 3
Joined: Tue May 27, 2008 10:34 am
Contact:

Loading and reading from a text file

Post 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:

Code: Select all

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?
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Re: Loading and reading from a text file

Post 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".
User avatar
jinksys
Posts: 20
Joined: Tue May 20, 2008 4:52 pm
Location: St Louis, Missouri, USA

Re: Loading and reading from a text file

Post 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.
Loknar
Posts: 3
Joined: Tue May 27, 2008 10:34 am
Contact:

Post 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.
tadada
Member
Member
Posts: 42
Joined: Sun Apr 20, 2008 5:32 pm
Location: Index 0 of the nearest Array

Post 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.
My OS: SOS (Simple Operating System).
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post 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...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Post 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.
Loknar
Posts: 3
Joined: Tue May 27, 2008 10:34 am
Contact:

Post 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?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
Post Reply