VGA Problem

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.
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

VGA Problem

Post by matias_beretta »

Hello

Code: Select all

int_33:
   push 0xb800
   pop es
   mov di, [XY]
   mov [es:di], ax
   add ax, 2
   mov [XY], di
   ret

XY:             ;-> OFFSET
   dw 0
How can I put a carriage return?
Matías Beretta
raevin
Member
Member
Posts: 33
Joined: Tue Dec 28, 2004 12:00 am

Re: VGA Problem

Post by raevin »

matias_beretta wrote:Hello

Code: Select all

int_33:
   push 0xb800
   pop es
   mov di, [XY]
   mov [es:di], ax
   add ax, 2
   mov [XY], di
   ret

XY:             ;-> OFFSET
   dw 0
How can I put a carriage return?
Well, wouldn't it be better if you break it off into two components...one X, another Y, and just increment Y for the carriage return?
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post by matias_beretta »

Is there any way of doing it without X and Y variables??????
Matías Beretta
raevin
Member
Member
Posts: 33
Joined: Tue Dec 28, 2004 12:00 am

Re: Reply

Post by raevin »

matias_beretta wrote:Is there any way of doing it without X and Y variables??????
Not exactly sure...don't think so, but I could be wrong.

Why do you want to make this harder than it actually is?
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post by matias_beretta »

i just wanted to know... thanks
Matías Beretta
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

You CAN do it with just one variable, but you would have to calculate the modulus of XY and 160, and then subtract from XY. Modulus is a VERY slow calculation, and I would not recommend it.
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post by matias_beretta »

I don't understand this of the module.. Can you explain me??
Matías Beretta
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Post by matias_beretta »

please answer!!!!!
Matías Beretta
raevin
Member
Member
Posts: 33
Joined: Tue Dec 28, 2004 12:00 am

Post by raevin »

matias_beretta wrote:please answer!!!!!
1) Chill...not everyone is on the boards 24/7...sheesh.
2) It's MODULUS, not MODULE...there's a difference...BIG difference in this case.
3) Modulus is dividing a number, and having the return value being the remainder.
4) Example: 5/4 = 1.25, so the modulus (returned value) will be 25.
5) You're welcome.
Fear
Member
Member
Posts: 39
Joined: Wed May 24, 2006 11:00 pm

Post by Fear »

Wouldn't 5 mod 4 be 1, not 25...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

raevin wrote:4) Example: 5/4 = 1.25, so the modulus (returned value) will be 25.
Wrong. That's the mantissa.

I have a 5 pizzas, with 4 people. How many pizzas do I have left over if everyone gets 1? That's what the remainder is. Remainder == modulus.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Yes, when you are operating in the 0xb8000 vga text memory, each line is 160 bytes long. Your variable XY seems to be the offset from 0xb8000. If you want to know how many lines down you are on the screen, you would do XY / 160, and store the number in a register. In C, the modulus operator is shown as %. It gives the "remainder" after a division operation. So, if the value of XY is 180, then XY / 160 = 1, and XY % 160 = 20. You would be on line #1 (if the top line is called line #0), and you would be at a horizontal offset of 20 on that line. If you wanted to move back to the beginning of the line, you could do: XY - (XY % 160).

On intel clone machines (which you are obviously on), the DIV opcode gives you both the dividend and the remainder (modulus).

Code: Select all

xor edx, edx     ; need edx = 0
mov eax, [XY]  ; number to divide
mov ebx, 160   ; divide by this
div ebx           ; divides the qword edx:eax by ebx
sub [XY], edx   ; modulus (remainder) gets stored in edx
but as I said -- the DIV opcode is VERY SLOW. Usually 20 times slower than any other opcode on the machine. You do not want to use it often if you can help it at all.

This code would move your "pointer" back to the beginning of the current line of text. Then if you want to move down a line, add 160.
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

thanks

Post by matias_beretta »

thanks , this helped me a lot, but remember, my os is just a real mode hobby os... so speed doesn't mind for me
Matías Beretta
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

but as I said -- the DIV opcode is VERY SLOW. Usually 20 times slower than any other opcode on the machine. You do not want to use it often if you can help it at all.
only if you have a very old CPU...
on current CPUs all ALU instructions can execute in a single cycle (iirc prescott can execute 8 DIV instructions in a single cycle...)
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

AFAIK div instructions are pipelined -- that is, you get the result 8 (for example) clock cycles after you begin processing the opcode -- it's just that the CPU can perform 8 of them at the same time, each at a different point in the pipeline process.

Mathematically, division is a "guessing game". It is not as nicely (straightforwardly) deterministic as the other binary operators.
Post Reply