I have to create a function that draws a rectangle using the parameters passed to the function, in inline assembler, by writing to video memory instead of using interrupts.
function prototype:
void DrawRectangle(left, top, bottom, right, character, attributes);
I have an attempt at writing this but it always writes 1 column too short.
DrawRectangle(0, 0, 79, 24, 219, BLACK); would effectively draw a black rectangle filling the console, but it is 1 column too short. The source is currently on my laptop, although I think it might be easier for myself to rewrite the function from scratch.
Thanks for any help.
Edit: Source http://slexy.org/view/s21lgdLzi5
Drawing Rectangles in Video Memory
Drawing Rectangles in Video Memory
Last edited by TomB on Fri Dec 07, 2007 10:48 am, edited 1 time in total.
Re: Drawing Rectangles in Video Memory
Hi,
I was bored. I looked at your code. I wrote this:
Normally I'd complain if someone posted code like this without comments, but I'm guessing you're a student and you'd learn more by adding the comments than you would by doing "cut & paste"...
Cheers,
Brendan
I was bored. I looked at your code. I wrote this:
Code: Select all
mov ax, VIDEO_MEMORY
mov es, ax
mov di, [bLeft]
mov si, SCREEN_WIDTH * 2
mov ax, [bTop]
add di, di
mul si
mov dx, [bRight]
add di, ax
mov bx, [bBottom]
sub dx, [bLeft]
mov ah, [bAttribute]
inc dx
sub bx, [bTop]
sub si, dx
mov al, [bCharacter]
sub si, dx
cld
.nextLine:
mov cx, dx
rep stosw
add di, si
sub bx, 1
jbe .nextLine
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Hi,
I have tested it now though and (after fixing the last line) it works fine, as long as you give it correct input (for e.g. you can expect problems if "bRight" is 10 and "bLeft" is 20). I have no idea how you would've got a 'C' on the next row...
Cheers,
Brendan
I didn't test it before I posted it and made a silly mistake - the last line should be "jae .nextLine".TomB wrote:Thanks for writing an example, unfortunately when I try to use it, it doesn't draw the rectangle properly.
Edit: It's drawing the top row, and then just a 'C' on the next row.
I have tested it now though and (after fixing the last line) it works fine, as long as you give it correct input (for e.g. you can expect problems if "bRight" is 10 and "bLeft" is 20). I have no idea how you would've got a 'C' on the next row...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.