Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 9:59 am



Post new topic Reply to topic  [ 9 posts ] 
 Text output does not work 
Author Message

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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.


Mon Apr 26, 2010 12:39 pm
Profile

Joined: Tue Apr 20, 2010 1:39 pm
Posts: 17
Post Re: Text output does not work
Show code.
You are writing to B800:0000, right?


Mon Apr 26, 2010 5:07 pm
Profile

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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 32014 times ]
Mon Apr 26, 2010 7:56 pm
Profile

Joined: Tue Apr 20, 2010 1:39 pm
Posts: 17
Post 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.


Mon Apr 26, 2010 9:45 pm
Profile

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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?


Tue Apr 27, 2010 5:26 am
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: Text output does not work
Id go with >= too :P

_________________
Thank you for reading,

Kieran C G Foot


Tue Apr 27, 2010 5:41 am
Profile WWW

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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.


Tue Apr 27, 2010 5:52 am
Profile

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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.


Tue Apr 27, 2010 7:23 pm
Profile

Joined: Wed Feb 10, 2010 6:32 am
Posts: 26
Post 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


Thu Apr 29, 2010 3:38 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.