How do I type where I am supposed to? [SOLVED]

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
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

How do I type where I am supposed to? [SOLVED]

Post by LordMage »

Okay, I have a simple ASCII keyboard driver working for the moment but I am typeing on the top of the screen and I want to type after my prompt. I can't find anything that is changing the position and I think that what is happening is multiple instances of my Video setup. I used the C++ kernel tutorial to help me create the temp video driver and I used a tutorial by Steve von Takach to help me code the keyboard driver. I have set my hardware pointer but it is jumping from the top of the screen to the bottom of the screen where I am writing my prompt. Has anyone else had this problem and if what I think is happening is; how do I make sure that only one instance of my Video class is running?

I can provide code if needed just like to try and not have my inital posts cluttered with my bad code :)
Last edited by LordMage on Wed Oct 31, 2007 3:56 pm, edited 1 time in total.
Getting back in the game.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Your problem description is a bit vague. Nevertheless I'll try to give some ideas:

The VGA maintains a cursor location. One copy is in memory, and the other is in the harware's registers. Normally it checks the one in memory as it is faster to access then updated the one in hardware with the new value if necessary.

Assuming that you are in protected mode, the bios calls can not do the printing for you. That means you have to manage the location of the cursor or where to type. Essentially, the two are completely different - moving the cursor requires a write to VGA registers, writing text requires a write to video memory. It is up to you to administer both.

In normal circumstances, you keep the x and y location of where you are typing, and as soon as that changes, you change the location of the hardware cursor. Note that writes to VGA are slow so once it works, you might want to consider not to update the cursor after each character.

I hope that helps in solving your problem.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

Sorry for being so vague. I guess I didn't realise I was THAT vauge.

I am in protected mode, I was just updating the video memory using a C++ class with xpos and ypos variables to track my current position in the video memory. I have a cout function that works perfectly. My cin function for some reason is printing all the typed characters at the top of the screen. I thought that it might be the hardware cursor so I added code to update the position of the hardware cursor to match the postion of the video location in memory. Now my hardware cursor is jumping from my prompt that I am creating with a cout statement to the top of the screen where my cin statement is still printing.

I think that my OStream class with the object name of cout and my IStream class with the object name of cin are using seperate instances of the Video class which is initiated once to my knowledge using an object named vid. Now when I update the color of my text using the function

Code: Select all


vid.setcolor(WHITE, BLACK);

it updates the colors being used by my cout object and my other Video class funcitons. So, I would think that since private variables inside the class are maintaining the changing values that a different instance of the class would cause my color changing not to be effective. I was assuming that if that worked then my cin would work the same way with the xpos and ypos variables that determine the output position of a printed character within the video class.

Inside my IStream class functions I am using cout to print the individual characters produced by the keyboard interrupt function. All my keyboard interrupt does is convert from scancode to ascii and it adds a counter to a buffer that indicates a character is waiting. then a getch function that is called by my cin object waits for the buffer to be a nonzero and processes any characters waiting in the keyboard buffer. That is where it prints all printable characters by issueing a

Code: Select all


cout << input;

command. For some reason this cout prints to the top of the screen instead of where the other cout being called by my main function is printing.

I hope that helps, again if you need actual functions i can post what I have.
Getting back in the game.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

LordMage wrote:Sorry for being so vague. I guess I didn't realise I was THAT vauge.

I am in protected mode, I was just updating the video memory using a C++ class with xpos and ypos variables to track my current position in the video memory. I have a cout function that works perfectly. My cin function for some reason is printing all the typed characters at the top of the screen. I thought that it might be the hardware cursor so I added code to update the position of the hardware cursor to match the postion of the video location in memory. Now my hardware cursor is jumping from my prompt that I am creating with a cout statement to the top of the screen where my cin statement is still printing.

I think that my OStream class with the object name of cout and my IStream class with the object name of cin are using seperate instances of the Video class which is initiated once to my knowledge using an object named vid. Now when I update the color of my text using the function

Code: Select all


vid.setcolor(WHITE, BLACK);

it updates the colors being used by my cout object and my other Video class funcitons. So, I would think that since private variables inside the class are maintaining the changing values that a different instance of the class would cause my color changing not to be effective. I was assuming that if that worked then my cin would work the same way with the xpos and ypos variables that determine the output position of a printed character within the video class.

Inside my IStream class functions I am using cout to print the individual characters produced by the keyboard interrupt function. All my keyboard interrupt does is convert from scancode to ascii and it adds a counter to a buffer that indicates a character is waiting. then a getch function that is called by my cin object waits for the buffer to be a nonzero and processes any characters waiting in the keyboard buffer. That is where it prints all printable characters by issueing a

Code: Select all


cout << input;

command. For some reason this cout prints to the top of the screen instead of where the other cout being called by my main function is printing.

I hope that helps, again if you need actual functions i can post what I have.
Did you declare your cout object static in the header file? Just a random guess?
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

Well, that got me thinking and I just looked at my headers. I hadn't switch from a list of headers to a centralized header in the IOStream files yet so I did that, It didn't work. I then for no real reason other than because I was there and figured I would try it, changed my cout statements in my cin funcitons into vid.put(char c) statements and now it works just fine. Thanks for the help, although it didn't solve the problem it led me to it. :)
Getting back in the game.
Post Reply