the tab character (\t) is not printed correctly
the tab character (\t) is not printed correctly
I am writing the ram disk for my simple OS... when I print the tab character \t, it looks like a dot, (pls see the attachment jpg file)... what is wrong, I thought the rendering is supposed to be a vertical jump (blank) on the screen... what is wrong here?
-
- Member
- Posts: 5885
- Joined: Mon Mar 25, 2013 7:01 pm
Re: the tab character (\t) is not printed correctly
How do you print a newline character?
Why is printing a newline character different from printing letters and numbers and such?
Why is printing a newline character different from printing letters and numbers and such?
Re: the tab character (\t) is not printed correctly
the code for print a single char is below. it just shift the cursor to the next line....
Code: Select all
void print_char(char character, int col, int row, char attribute_byte){
char* video_memory = (char *) VIDEO_ADDRESS;
int offset;
if (attribute_byte <0)
attribute_byte = WHITE_ON_BLUE;
if (col<0 || row<0){
offset = get_cursor();
}else{
offset = get_screen_offset(col, row);
}
if (character =='\n'){
int rows = (offset>>1) /(MAX_COLS) ;
offset = get_screen_offset (79, rows);
}else{
video_memory[offset] = character;
video_memory[offset+1] = attribute_byte;
}
offset +=2;
offset = handle_scrolling(offset);
set_cursor(offset);
}
-
- Member
- Posts: 5885
- Joined: Mon Mar 25, 2013 7:01 pm
Re: the tab character (\t) is not printed correctly
So... why do you need to shift the cursor to the next line? Other characters display fine when you write them directly to video memory. What makes '\n' so special?
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: the tab character (\t) is not printed correctly
To put it another way, what do tab and newline have in common? What class or category of characters do they both belong to?
As a bonus question, what other ASCII characters - or even categories of characters - have to be handled specially? Are there any which shouldn't be printed at all? Why are these characters part of the ASCII set in the first place, and do they still have a role today?
Also, why do different OSes which use ASCII nonetheless have different newline characters (or pairs of characters, for Windows)? Why was the original standard for newlines a Carriage Return followed by Line Feed, and why did Unix drop one of them?
This may sound like an overly pedantic history lesson, but it is directly relevant to why tab and newline differ from other ASCII characters in this regard, and understanding that history may make a bunch of things about why you do certain things certain ways clearer.
Finally, just for fun, what about if you decide to support a different character encoding scheme, such as Latin-1 (which is mostly ASCII but adds a list of extended characters), UTF-8 (which shares a lot of character code points with ASCII, but is decidedly different in many ways), UTF-16 (which is very definitely not the same as either ASCII or UTF-8) or even EBCDIC (which you'll probably never need anyway, but just for argument's sake, as it bears almost no resemblance to ASCII)?
As a bonus question, what other ASCII characters - or even categories of characters - have to be handled specially? Are there any which shouldn't be printed at all? Why are these characters part of the ASCII set in the first place, and do they still have a role today?
Also, why do different OSes which use ASCII nonetheless have different newline characters (or pairs of characters, for Windows)? Why was the original standard for newlines a Carriage Return followed by Line Feed, and why did Unix drop one of them?
This may sound like an overly pedantic history lesson, but it is directly relevant to why tab and newline differ from other ASCII characters in this regard, and understanding that history may make a bunch of things about why you do certain things certain ways clearer.
Finally, just for fun, what about if you decide to support a different character encoding scheme, such as Latin-1 (which is mostly ASCII but adds a list of extended characters), UTF-8 (which shares a lot of character code points with ASCII, but is decidedly different in many ways), UTF-16 (which is very definitely not the same as either ASCII or UTF-8) or even EBCDIC (which you'll probably never need anyway, but just for argument's sake, as it bears almost no resemblance to ASCII)?
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
-
- Member
- Posts: 451
- Joined: Tue Apr 03, 2018 2:44 am
Re: the tab character (\t) is not printed correctly
Tab is a horizontal jump, not vertical.ITchimp wrote:I am writing the ram disk for my simple OS... when I print the tab character \t, it looks like a dot, (pls see the attachment jpg file)... what is wrong, I thought the rendering is supposed to be a vertical jump (blank) on the screen... what is wrong here?
If you have tabstop set to 8, say, then printing a tab should jump the cursor to the next modulo-8 column (assuming 0 based column counting.)
So, if you're in the first column (column 0) and print a tab, you want to jump to column 8. Similarly, if you're in any of columns 1..7, a tab will jump you to column 8.
If you want the tab to erase the intervening characters, you need to print a space in each of the columns you're jumping over until you reach your desired column.
As it is at the moment, you're just putting the character 9 in the character buffer, and the display is just rendering whatever the font defines for glyph 9 to the screen. The character buffer is dumb, and won't interpret control characters, which is what tab is.