Printing newlines

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.
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Printing newlines

Post 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)?
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Printing newlines

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Printing newlines

Post 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.
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Printing newlines

Post 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!
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Printing newlines

Post 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.
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.
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Re: Printing newlines

Post 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.
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Re: Printing newlines

Post 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.
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Printing newlines

Post 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.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Re: Printing newlines

Post by hausemaster »

Oh well yeah if I knew how to do that I would have already done it.
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Printing newlines

Post 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.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Re: Printing newlines

Post by hausemaster »

yeah osdeving is probably pretty hard, atleast for a kid.
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Printing newlines

Post 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)!
Last edited by bloodline on Tue Dec 22, 2020 7:12 pm, edited 1 time in total.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
hausemaster
Member
Member
Posts: 30
Joined: Sat Dec 12, 2020 8:30 am

Re: Printing newlines

Post 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.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Printing newlines

Post 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.
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: Printing newlines

Post 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.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Post Reply