for reading text files on the disk and displying them in the screen
should i directly read it from the floppy disk (i.e locate its cluster in the FAT table and put a di pointer to the text file's clusters and read the text file and disply it on the screen)
or do you guys sugggest something else??
reading text files
That won't work. When you put data in the textmode VGA screen buffer at memory address 0xB8000, every other byte needs to be something called an "attribute" byte.
If you just read a text file into that memory area, it will only display every other byte as a character. The other bytes will be interpreted as screen colors.
If you want to read a text file and display it, you need to read it into a buffer that you allocate. Then you can copy that buffer, one character at a time, to 0xb8000 -- adding the extra attribute byte for every character that you copy.
If you just read a text file into that memory area, it will only display every other byte as a character. The other bytes will be interpreted as screen colors.
If you want to read a text file and display it, you need to read it into a buffer that you allocate. Then you can copy that buffer, one character at a time, to 0xb8000 -- adding the extra attribute byte for every character that you copy.
Hi,
Lately I've been using pre-scanning for this, to improve performance. The idea is you check the text in the buffer and find out how many lines you need to scroll, then scroll once, then draw the text last. For example (with 80 * 25 text mode), this means if there's 20 lines of text in the buffer you scroll once (instead of 20 times), and if there's 200 lines of text in the buffer you skip 175 lines of text completely, clear the buffer, and then draw 25 lines of text (with no scrolling at all).
Something about the way you wrote the question makes me think you're writing a bootable application instead of an OS....
Cheers,
Brendan
There's also control characters (tab, newline, etc) and scrolling to worry about - a simple "lodsb; stosw" loop won't work.bewing wrote:If you want to read a text file and display it, you need to read it into a buffer that you allocate. Then you can copy that buffer, one character at a time, to 0xb8000 -- adding the extra attribute byte for every character that you copy.
Lately I've been using pre-scanning for this, to improve performance. The idea is you check the text in the buffer and find out how many lines you need to scroll, then scroll once, then draw the text last. For example (with 80 * 25 text mode), this means if there's 20 lines of text in the buffer you scroll once (instead of 20 times), and if there's 200 lines of text in the buffer you skip 175 lines of text completely, clear the buffer, and then draw 25 lines of text (with no scrolling at all).
Definately not. Your code should be split into at least 4 logical pieces - a disk driver, the file system code, the code to copy data from a file to the virtual screen, and a video driver.vishal wrote:for reading text files on the disk and displying them in the screen
should i directly read it from the floppy disk (i.e locate its cluster in the FAT table and put a di pointer to the text file's clusters and read the text file and disply it on the screen)
or do you guys sugggest something else??
Something about the way you wrote the question makes me think you're writing a bootable application instead of an OS....
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
thanks for the replies
for running executables file i just copy them into memory and pass the control there and later return the control to the kernel
so for allocating buffer for text file can i copy it into memory(RAM) and then read the file from there
for real mode :
use ah=0eh/int10h for every character in the memory
for protected mode:
copy each character in the screen memory and setting the attribute character along with every character to normal while displaying the last set of lines of file that will be displayed on the screen (after scrolling)
right i am coding this in assembly language
@ brendan
you can really say that because i am right now at the very basic level operating system development.....
for running executables file i just copy them into memory and pass the control there and later return the control to the kernel
so for allocating buffer for text file can i copy it into memory(RAM) and then read the file from there
for real mode :
use ah=0eh/int10h for every character in the memory
for protected mode:
copy each character in the screen memory and setting the attribute character along with every character to normal while displaying the last set of lines of file that will be displayed on the screen (after scrolling)
right i am coding this in assembly language
@ brendan
you can really say that because i am right now at the very basic level operating system development.....
If you are still needing to worry about the memory addressing of video addressing, I recommend to not worry about displaying a text file on screen right now. The basic idea is abstracting the memory layout behind an interface. (i.e., device drivers.) This is just my opinion, though.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
there is no confusion from my side about the video addressing ...i have been reading stuff about it...all i want to know to that if i directly read from the file on the disk character by character and store it in al and display it by int 10h or write to video memory is enough??
is this the best way to do it or anything else is required???
is this the best way to do it or anything else is required???
When you take a byte from memory, if your in real mode you can test for 0 and if not 0, you can pass it to int 10h function 0eh, you should also test for tabs (09h), as this function does not deal with them.
Then that will work fine.
But if your do this from Pmode, you will need to write your own function, which will need to test for command char eg:back space (08h), bell (07h), carriage return (0dh) and line feed(0ah) etc. also you need to test for extended ASCII char's eg: 80h-ffh.
On top of this you need to add attribute byte, plus scroll the screen.
But if you have more line in the file than your screen res, you need to wait for a keypress to scroll it, or people will not be able to read it, before it scrolls up the screen.
If you need example code here it is
Then that will work fine.
But if your do this from Pmode, you will need to write your own function, which will need to test for command char eg:back space (08h), bell (07h), carriage return (0dh) and line feed(0ah) etc. also you need to test for extended ASCII char's eg: 80h-ffh.
On top of this you need to add attribute byte, plus scroll the screen.
But if you have more line in the file than your screen res, you need to wait for a keypress to scroll it, or people will not be able to read it, before it scrolls up the screen.
If you need example code here it is
- Attachments
-
- text.asm
- (3.18 KiB) Downloaded 73 times