Question about print function

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
Peter
Posts: 13
Joined: Wed Jan 05, 2005 12:00 am

Question about print function

Post by Peter »

Hey people,

I've a little question about some code I saw,

Code: Select all


   out(0x3D4, 14);
   offset = in(0x3D5) << 8;
   out(0x3D4, 15);
   offset |= in(0x3D5);

   vidmem += offset*2;

when the screen was cleared this was in the print function,

the bitshift-8, is that because the two registers holding the cursor but starts at bit 8 so it have to shiftback to 0?

Why does offset ored by in(0x3D5)?
and why does offset multiplied with 2 and added by the video-pointer.

I've seen some tutorials, but I'm dutch and it's hard to understand :-P

Thanks :-D,

Peter
Last edited by Peter on Sat Jan 22, 2005 12:00 am, edited 1 time in total.
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: Question about print function

Post by matthias »

Why do you use the register: 0x3D5 to calcuate your offset?
I have build a print function as well but I don't use 0x3D5 to get my offset, I just store an x and an y globally, and then I calculate the offset with this.

I assume you work in (80 * 25) so then to calculate the offset I use:

Code: Select all

offset = ((x_pos + y_pos * 80) * 2);
and then I use this offset to write a character.

So:

Code: Select all


char* video = (char*)0xb8000;


*(video + (xpos + ypos * 80) * 2) = char_to_write;
*(video + (xpos + ypos * 80) * 2 + 1) = attribute;

And you should have look at this as well:
http://www.osdev.org/index.html?module ... opic&t=51

Je bent niet de enigste nederlander hier ;)
Last edited by matthias on Sat Jan 22, 2005 12:00 am, edited 1 time in total.
The source of my problems is in the source.
Peter
Posts: 13
Joined: Wed Jan 05, 2005 12:00 am

Re: Question about print function

Post by Peter »

0x3D5 is for input too the screen,
I think I'm already know, 0x3D4 = 14 & 15 contains the cursor position but the register is 8 - 15 bits or something. I think, I need to shiftback too get on the right position.

But what I don't get is that the second IN contruction is ORed and that the Video-Memory contains offset multiplied by 2.


[offtopic]

Jeej!, eindelijk meer Nederlanders die zich bezighouden met OS development
btw, mijn msn is [email protected]
[/offtopic]

Thanks :-D,

Peter
[AlAdDiN]
Member
Member
Posts: 107
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: Question about print function

Post by [AlAdDiN] »

I think you have to use mathias methode coz it's simpler, and most of OS' i know use that method
-----------------------
There are 10 types of people in this world... those that understand binary, and those that don't.
grinny
Posts: 6
Joined: Sun Jan 23, 2005 12:00 am

Re: Question about print function

Post by grinny »

the bitshift-8, is that because the two registers holding the cursor but starts at bit 8 so it have to shiftback to 0?

Why does offset ored by in(0x3D5)?
The bitshift and the OR are the result of reading a word (2 byte) value one byte at a time in little endian format.
and why does offset multiplied with 2 and added by the video-pointer.
The video pointer points to the start of the video mem. Adding the calculated offset to it will make the result point to the cursor (somewhere half-way video memory). It has to be multiplied with 2, beceause each letter in the console is represented by 2 bytes, one for the letter and one for the color.

Trouwens nooit geweten dat Nederlanders zulke enthousiaste os bouwers waren!

- Grinny -

"Beware of programmers carrying screwdrivers."
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: Question about print function

Post by matthias »

[offtopic]
Trouwens nooit geweten dat Nederlanders zulke enthousiaste os bouwers waren!
Ik ook niet :P

[/offtopic]
The source of my problems is in the source.
Post Reply