Hello,
im trying to make a function that can paint a box of any size (and colour, using any ascii char) to the screen in order to make a game in asm.
My problem is, when i try to make it print just one full line, it dosnt seem to be able to handle it =( in my main it can print a nice box with a shadow and a line down one side of the screen - but when it comes to printing one full line accross it cant handle it!!
Can anyone help? thanks in advance
void ClearWindow(BYTE Left, BYTE Top, BYTE Right, BYTE Bottom, BYTE Char,BYTE Colour)
{
asm {
xor ax, ax //clear ax
xor bx, bx //clear bx
mov ax, SCREEN_SEG //move into ax memory location of the start of the screen memory location
mov es, ax // move ax into the extra segment reg
xor ax, ax //clear ax again
mov al, Top // move in to al (bottom of ax) the Top var
mov bl, SCREEN_WIDTH*2 //make bl the screen width (needs to be doubled for the two mem locations)
mul bl //multiply bl by itself, the answer goes to bx
xor bl, bl //clear bl
mov bl, Left //move into bl the Left var
shl bl, 1 //shift the bl reg left
add ax, bx //add ax and bx reg
mov di, ax //move ax into destination index
xor ax, ax //clear ax
mov al, Bottom //move the Bottom var into al
sub al, Top // subtract top from al (which is in the al reg)
push ax // push ax onto the stack
xor ax, ax //clear the ax register
xor bx, bx //clear the bx register
xor dx, dx //clear the dx register
mov al, Right //move the Right var into al
sub al, Left //subtract Left from the al register
mov bx, ax //move ax into bx
mov bh, 1
}
//This is the start of the clearscreen printing
SClear:
asm {
xor ax, ax //clear ax register
mov al, SCREEN_WIDTH*2 //make al the screen width (needs to be doubled for the two mem locations)
sub al, bl //subtract bl from al
mov cx, ax //move ax into cx
sub cx, 1 //minus 1 from cx
mov bh, 1 //move 1 into bh
xor ax, ax //clear ax register
mov al, Char //move the print char var into the first part of ax
mov ah, Colour //move into the second half of ah the colour var
}
PrintClr:
asm {
mov es:[di], ax
add di, 2 //add 2 to the di reg
cmp bh, bl //compare bh to bl
je IncDI //jump to IncDI if they are equal
inc bh //incrament bh reg
loop PrintClr //loop back to start of PrintClr
}
IncDI:
asm {
inc di //incrament di reg
loop IncDI //go back to IncDI
}
asm {
cmp dh, 1 //check if dh is 1
jl EndClr //jump to the EndClr
cmp dh, dl //compare dh to dl
je ExitClr //jump if equal to ExitClr
inc dh //incrament to dh register
jmp SClear //jump to SClear
}
EndClr:
asm {
pop dx //put dx on to the stack
mov dh, 1 //move 1 into dh
jmp SClear //jump tp SClear
}
ExitClr: //
}
void main()
{
ClearWindow(0,0,80,0,219, BLUE);
ClearWindow(0,0,1,24,219, GREEN);
ClearWindow(5,5,77,20,219,RED);
ClearWindow(4,4,76,19,219,WHITE);
}