Terminal Skipping Over Line

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.
Post Reply
djalex234
Posts: 2
Joined: Sun Jan 26, 2020 3:45 pm
Libera.chat IRC: djalex234

Terminal Skipping Over Line

Post by djalex234 »

Basically, I have developed to the point where you can print characters to the screen. But I ran into a issue, the text screen has been scrolled down by one. Working in QEMU, but not real hardware. Here is the code I use for printing:

Code: Select all

#include <stdint.h>
#include <stddef.h>
#include "terminal.h"
#include "asm-io.h"
void disable_cursor()
{
	outb(0x3D4, 0x0A);
	outb(0x3D5, 0x20);
}
uint16_t* video_mem;
int row, column;
static const int width = 80;
static const int height = 25;
uint16_t char_entry(unsigned char c, uint8_t color)
{
  return (uint16_t) c | (uint16_t) color << 8;
}
uint8_t char_color(enum color_list fg, enum color_list bg)
{
  return fg | bg << 4;
}
void printc(char c, int color, int x, int y)
{
  video_mem[y * width + x] = char_entry(c, color);
}
void terminal_init(void)
{
  disable_cursor();
  row = 0;
  column = 0;
  video_mem = (uint16_t*)0xB8000;
  for (int y = 0; y < height; y++){
    for (int x = 0; x < width; x++){
      int spot = y * width + x;
      video_mem[spot] = char_entry(' ', char_color(7, 0));
    }
  }
  row = 0;
  column = 0;
  //long string of characters to print, hopefully filling up the screen
  printc('1', char_color(7, 0), column, row++);
  printc('2', char_color(7, 0), column, row++);
  printc('3', char_color(7, 0), column, row++);
  printc('4', char_color(7, 0), column, row++);
  printc('5', char_color(7, 0), column, row++);
  printc('6', char_color(7, 0), column, row++);
  printc('7', char_color(7, 0), column, row++);
  printc('8', char_color(7, 0), column, row++);
  printc('9', char_color(7, 0), column, row++);
  printc('0', char_color(7, 0), column, row++);
  printc('1', char_color(7, 0), column, row++);
  printc('2', char_color(7, 0), column, row++);
  printc('3', char_color(7, 0), column, row++);
  printc('4', char_color(7, 0), column, row++);
  printc('5', char_color(7, 0), column, row++);
  printc('6', char_color(7, 0), column, row++);
  printc('7', char_color(7, 0), column, row++);
  printc('8', char_color(7, 0), column, row++);
  printc('9', char_color(7, 0), column, row++);
  printc('0', char_color(7, 0), column, row++);
  printc('1', char_color(7, 0), column, row++);
  printc('2', char_color(7, 0), column, row++);
  printc('3', char_color(7, 0), column, row++);
  printc('4', char_color(7, 0), column, row++);
  printc('5', char_color(7, 0), column, row++);
}
Is there any obvious flaw I've made?
Octocontrabass
Member
Member
Posts: 5578
Joined: Mon Mar 25, 2013 7:01 pm

Re: Terminal Skipping Over Line

Post by Octocontrabass »

djalex234 wrote:But I ran into a issue, the text screen has been scrolled down by one.
I'm not sure I understand what this means. Are you saying there's an empty space at the top of the screen, and the line of text that should be at the bottom of the screen has been cut off? If so, your monitor may not be calibrated correctly. It's very common for LCD monitors to fail automatic calibration when the screen is mostly black.
djalex234
Posts: 2
Joined: Sun Jan 26, 2020 3:45 pm
Libera.chat IRC: djalex234

Re: Terminal Skipping Over Line

Post by djalex234 »

I forgot that this monitor wasn't top quality, the calibration worked. Didn't seem like that was the issue with stuff like Ubuntu working on it perfectly. Thanks for the idea.
Post Reply