Page 1 of 1

Question about print function

Posted: Sat Jan 22, 2005 12:00 am
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

Re: Question about print function

Posted: Sat Jan 22, 2005 12:00 am
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 ;)

Re: Question about print function

Posted: Sun Jan 23, 2005 12:00 am
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

Re: Question about print function

Posted: Sun Jan 23, 2005 12:00 am
by [AlAdDiN]
I think you have to use mathias methode coz it's simpler, and most of OS' i know use that method

Re: Question about print function

Posted: Sun Jan 23, 2005 12:00 am
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."

Re: Question about print function

Posted: Mon Jan 24, 2005 12:00 am
by matthias
[offtopic]
Trouwens nooit geweten dat Nederlanders zulke enthousiaste os bouwers waren!
Ik ook niet :P

[/offtopic]