Thread: Printing to the screen without a library.

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    21

    Printing to the screen without a library.

    I need to write to the screen for my OS, and I can't find a good way to do it. I have seen several assembly codes, but I can't find one that will do the job. One in C++ would be even better! I'm running Red Hat 9, if that helps.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Are you writing an OS from scratch and you want to access the screen, and RH9 is your development platform?

    Or are you just using RH9 and want to access the screen from within RH9
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    I am using Red Hat 9, and I'm writing the OS from scratch.

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Compuboy over at flashdaddee has a tutorial about making an OS, and his bootloader development tutorial has what you need. Basically...
    Code:
    mov ah, 0x0E ;set teletype mode
    mov al, 'A' ;the char we want to print
    mov bh, 0x00 ;set the page number
    
    int 0x10 ;call the video function.
    Get it from http://electrichamster.net/lucie/
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    Thanks, it's a great tuturial. Only one problem. I'm using the GRUB bootloader, and I have my multiboot header. I must compile this with as, and the code in the tuturial must be compiled with NASM. Is it possible to link these together, or do I need one in AT&T Syntax?

  6. #6
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    The syntax you use or the assembler doesn't really matter, the binary will be the same. You don't need a boot loader, just put the floppy you're using before in the boot order and GRUB won't have to worry about it.
    Translating the asm syntax should prove too hard. Good luck!
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    You can access text-mode video memory directly at 0xb8000. Each character is composed of two bytes. The first byte is the character and the second byte is the foreground-background color. The screen is 80 characters wide, 25 characters high, and I believe up to 7 "virtual screens" which are basically extra storage space you can scroll.

    With this you can make a putch function, some color functions, and you're on your way to making the printf function.
    Code:
    char *videoText = (char *)0xb8000;
    Just search google for more information about the colors. I believe the first 8 values were full colors and the next 8 were light shaded versions. That would make 16 possibilities. You do this for the color byte twice using upper and lower nibbles for the foreground and background color.

    EDIT: Color chart found here: http://my.execpc.com/~geezer/osd/cons/

  8. #8
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Speedy5 you can't access memory like that in linux

  9. #9
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    >>Speedy5 you can't access memory like that in linux
    He's not trying to access it in Linux, he's using bios functions.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    No those are not BIOS functions. Those are memory that maps to the screen when you initialy boot up. Use them until you switch to graphics resolutions. Works in real or protected mode after you boot the kernel.

  11. #11
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    >>No those are not BIOS functions
    True, I was thinking of something else.
    Anyhow, what's the limit for that video memory and how standard is that memory location?
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    That memory location is pretty standard and is supported by all VGA adapters. Its been around since a long, long time. It possibly dates back to 1970's or 1980's. Its 80 characters wide, 25 characters high (per screen), 2 bytes per character, and 8 virtual screens (memory lower than the first screen). It ranges 32767 bytes (note some aren't used) from 0xB8000 to 0xBFFFF.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing \n on the screen in C
    By swgh in forum C Programming
    Replies: 4
    Last Post: 05-18-2007, 03:52 PM
  2. Printing arrays to curses screen
    By trev456 in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 12:46 AM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. question about printing on screen and not overwriting text...
    By revelation437 in forum C Programming
    Replies: 2
    Last Post: 12-14-2002, 02:48 PM
  5. Printing out contents of a file to the screen
    By Simon in forum C Programming
    Replies: 18
    Last Post: 10-21-2002, 08:05 AM