Page 1 of 3

Printing newlines

Posted: Tue Dec 22, 2020 2:35 pm
by hausemaster
Okay I promised I'd never come back to annoy people in this forum, but I have no idea what
"in terminal_putchar check if c == '\n' and increment terminal_row and reset terminal_column." means, so can someone help me get my OS to support newlines (\n)?

Re: Printing newlines

Posted: Tue Dec 22, 2020 2:51 pm
by nexos
So think about is this way. Let's say I call terminal_writestring("hello, world\n"), '\n' equals some sort of ASCII char code. So, to print a new line, before we actually print the character on screen (i.e., into the buffer 0xB8000), then we check if the current char equals '\n', and then increment terminal_row, and zero terminal_column. If you have no clue what I just said, then check out http://www.brokenthorn.com/Resources/OSDev10.html, which explains text mode. Note that it is is ASM, however.

Re: Printing newlines

Posted: Tue Dec 22, 2020 2:55 pm
by alexfru
Given the cursor at some location (row,column) on the screen, you move it to (row+1,0).
I hope you're familiar with Two-dimensional space?
The only difference here is that typically row=0 at the top of the screen and increases downwards while y=0 at the bottom and increases upwards.

Re: Printing newlines

Posted: Tue Dec 22, 2020 3:36 pm
by bloodline
hausemaster wrote:Okay I promised I'd never come back to annoy people in this forum, but I have no idea what
"in terminal_putchar check if c == '\n' and increment terminal_row and reset terminal_column." means, so can someone help me get my OS to support newlines (\n)?
No offence intended, but this is elementary stuff... it only gets harder from here on!

Re: Printing newlines

Posted: Tue Dec 22, 2020 5:36 pm
by Schol-R-LEA
This is a question which comes up about once a month here, as it understandably is confusing to new OS devs until they've had a chance to sit down and think it out. A quick search on the topic in the forum search bar should find several explanations for how to solve the issue. This recent post covers it in detail.

Re: Printing newlines

Posted: Tue Dec 22, 2020 5:50 pm
by hausemaster
Thanks for not beating me up about basic stuff! I'm starting to get it now, but I'm sure you understand this can be hard for beginners.

Re: Printing newlines

Posted: Tue Dec 22, 2020 5:59 pm
by hausemaster
Okay, so I figured out how to print newlines, it makes so much sense, but I still get the weird block character? It does the newline, but it also prints out the character before it switches lines.

Re: Printing newlines

Posted: Tue Dec 22, 2020 6:05 pm
by bloodline
hausemaster wrote:Okay, so I figured out how to print newlines, it makes so much sense, but I still get the weird block character? It does the newline, but it also prints out the character before it switches lines.
Yeah... don’t write anything to the text buffer when you encounter the ‘\n’ character.

Re: Printing newlines

Posted: Tue Dec 22, 2020 6:06 pm
by hausemaster
Oh well yeah if I knew how to do that I would have already done it.

Re: Printing newlines

Posted: Tue Dec 22, 2020 6:17 pm
by bloodline
hausemaster wrote:Oh well yeah if I knew how to do that I would have already done it.
Well, if you look at the code you wrote which puts a character in the text buffer, don’t do that when the character is a newline.

Re: Printing newlines

Posted: Tue Dec 22, 2020 6:36 pm
by hausemaster
yeah osdeving is probably pretty hard, atleast for a kid.

Re: Printing newlines

Posted: Tue Dec 22, 2020 7:07 pm
by bloodline
hausemaster wrote:yeah osdeving is probably pretty hard, atleast for a kid.
Operating system development is probably second only to compiler writing in terms of difficulty. Not only do you need to know your target hardware extremely intimately, you must also have a clear understanding of the programming language you plan to use, and to really muddy the waters you also need to understand the different operating system paradigms well enough to know which fits your use case.

From the questions you are asking, it seems like you are new to C, if this is true, you would do well to spend some time working through some c exercise projects. Perhaps buy an Arduino and learn more about low level hardware concepts, like interrupts and bitwise operations. These things you will need to know.

-edit- Don’t be discouraged, the rudiments of my OSDev project can trace their design roots back to my first kernel sketches written when I was 14 (which is why they are heavily 68k oriented)!

Re: Printing newlines

Posted: Tue Dec 22, 2020 7:12 pm
by hausemaster
yeah, I'm pretty good with C++ and alot of the popular high-level languages, but I'm not the best with C or Assembly.

Re: Printing newlines

Posted: Tue Dec 22, 2020 7:12 pm
by alexfru
hausemaster wrote:yeah osdeving is probably pretty hard, atleast for a kid.
If we look at it as a hobby, there's rarely something for which you'd need a college degree (some fundamental school math is mostly what there is), but there's plenty of knowledge overall that's needed nonetheless. And a lot of patience. The less you know the more patience you need. And time, of course.

I'd seriously advise against doing osdev now if you have to ask the kind of question you did. But there's no harm in giving it a try. Just be aware that it may prove too heavy right now. There's nothing to be ashamed of if you fail now and get back to it later.

Re: Printing newlines

Posted: Tue Dec 22, 2020 8:32 pm
by austanss
You don't know how to conditionally not do something?

What????

I would give you some leeway in assembly land... but this is extremely beginner stuff, for basic programming.

I would suggest learning how to code before you write an OS.

Learn how to read before you write a book.