Bona Fide OS Development
http://forums.osdever.net/

Text output does not work
http://forums.osdever.net/viewtopic.php?f=6&t=346
Page 1 of 1

Author:  MTK358 [ Mon Apr 26, 2010 12:39 pm ]
Post subject:  Text output does not work

Somehow I can't get text output to work right.

I made functions that print a character set the color, set the position, but I just can't get printing strings and scrolling to work.

The OS is booted using GRUB, so it's in 32-bit Protected Mode.

Author:  smeezekitty [ Mon Apr 26, 2010 5:07 pm ]
Post subject:  Re: Text output does not work

Show code.
You are writing to B800:0000, right?

Author:  MTK358 [ Mon Apr 26, 2010 7:56 pm ]
Post subject:  Re: Text output does not work

The scroll() function simply does not work, and when I position it to near the end of the screen and print a few characters it prints the first few characters in two places on the screen and does not scroll.

kernel.c

Code:
#include "vga.h"

void kernel_main( void* mbd, unsigned int magic )
{
   if ( magic != 0x2BADB002 ) { // if the bootloader is not Multiboot-compatible
   }

   // char* boot_loader_name = (char*) ((long*) mbd)[16];
   set_color(COLOR_LTAQUA | (COLOR_AQUA << 4));
   set_cur(78, 24);
   put_character('H');
   put_character('e');
   put_character('l');
   put_character('l');
   put_character('o');
}


vga.c

Code:
#include "vga.h"

int curx=0, cury=0;
unsigned char curc = COLOR_GRAY | (COLOR_BLACK << 4);
unsigned short* videoram = (unsigned short*) 0xB8000;
#define videoram_get(x, y) videoram[x + (y * COLS)]

void scroll() {
   int x, y;
   for(y=1; y<LINES; y++) {
      for(x=0; x<COLS; x++) {
         videoram_get(x, y-1) = videoram_get(x, y);
      }
   }
}

void set_color(unsigned char color) {
   curc = color;
}

void set_cur(int x, int y) {
   curx = x;
   cury = y;
}

void put_character(char c) {
   if(c == '\n') {
      curx = 0;
      cury++;
   } else {
      videoram_get(curx, cury) = c | (curc << 8);
      if(++curx == COLS) {
         curx = 0;
         if(cury+1 == LINES) scroll(); else cury++;
      }
   }
}

void clear_screen() {
   int i;
   for(i=0; i<LINES*COLS; i++) {
      videoram[i] = ' ' | (curc << 8);
   }
}


The (improper) output is attached.

Attachments:
hello.jpg
hello.jpg [ 37.41 KiB | Viewed 32026 times ]

Author:  smeezekitty [ Mon Apr 26, 2010 9:45 pm ]
Post subject:  Re: Text output does not work

Code:

void put_character(char c) {
   if(c == '\n') {
      curx = 0;
      cury++;
      if(cury+1 == LINES || cury == LINES){scroll();}
   } else {
      videoram_get(curx, cury) = c | (curc << 8);
      if(++curx == COLS) {
         curx = 0;
         if(cury+1 == LINES || cury == LINES) scroll(); else cury++;
      }
   }
}

Try that.

Author:  MTK358 [ Tue Apr 27, 2010 5:26 am ]
Post subject:  Re: Text output does not work

smeezekitty wrote:
Code:

void put_character(char c) {
   if(c == '\n') {
      curx = 0;
      cury++;
      if(cury+1 == LINES || cury == LINES){scroll();}
   } else {
      videoram_get(curx, cury) = c | (curc << 8);
      if(++curx == COLS) {
         curx = 0;
         if(cury+1 == LINES || cury == LINES) scroll(); else cury++;
      }
   }
}

Try that.


What's the purpose of checking if cury AND cury+1 equals LINES? Why not >=, which will be simpler and more efficient?

Author:  Kieran [ Tue Apr 27, 2010 5:41 am ]
Post subject:  Re: Text output does not work

Id go with >= too :P

Author:  MTK358 [ Tue Apr 27, 2010 5:52 am ]
Post subject:  Re: Text output does not work

Code:
void scroll() {
   int x, y;
   for(y=1; y<LINES; y++) {
      for(x=0; x<COLS; x++) {
         videoram_get(x, y-1) = videoram_get(x, y);
      }
   }
   cury--;
}

void put_character(char c) {
   if (c == '\n') {
      curx = 0;
      if (++cury == LINES) scroll();
   } else {
      videoram_get(curx, cury) = c | (curc << 8);
      if (++curx == COLS) {
         curx = 0;
         if (++cury == LINES) scroll();
      }
   }
}


Newer version, but still the same result.

Author:  MTK358 [ Tue Apr 27, 2010 7:23 pm ]
Post subject:  Re: Text output does not work

Anyone?

I would like to search it, but I just don't know what. I tried things like "vga characher output" and stuff but 99.9% of the results are completely irrelavent.

Author:  Sharpner [ Thu Apr 29, 2010 3:38 am ]
Post subject:  Re: Text output does not work

Code:
int8u attrib = 0x0F;

void scroll(){
    int32u blank = ' ' | (attrib << 8);
    if(csr_y >= 25){
           int16u i;
           for (i = 0; i < 24*80; i++){
               vga_ptr[i] = vga_ptr[i+80];
           }
           for (i = 24*80; i < 25*80; i++){
               vga_ptr[i] = blank;
           }
           csr_y = 24;
       }
    move_csr();
}


I did it like that, maybe it helps you.
bye Sharpner

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/