Page 1 of 1
I can't fix a bug! :(
Posted: Sat Nov 20, 2004 12:00 am
by ComputerPsi
Here is code that clears the screen:
Code: Select all
cls1:
push ebx
push edx
xor ebx,ebx
@againx:
xor edx,edx
@againy:
call pset
inc edx
cmp edx,200
jnz @againy
inc ebx
cmp ebx,320
jnz @againx
pop edx
pop ebx
ret
For some reason, when I ran it on my computer, the keyboard stoped working. I tried running it on Bochs, and got "internal keyboard buffer full, ignoring scancode."
After some testing, I figured out that if I comment out the line "jnz @againx", the keyboard starts working again.. but then the cls function doesn't work correctly. Does anybody know how to fix this?
The code is in NASM, in 32-bit protected mode. (Yes, Interrupts are enabled, and I don't get any Interrupt error).
Re: I can't fix a bug! :(
Posted: Sat Nov 20, 2004 12:00 am
by Da_Maestro
What does the code for pset look like?
Re: I can't fix a bug! :(
Posted: Sat Nov 20, 2004 12:00 am
by Da_Maestro
btw if you are trying to clear a VGA screen here is some better code:
Code: Select all
cls:
mov eax, screen ; Pointer to screen buffer
mov edi, eax
mov ecx, 320*50 ; Clearing 320*50 dwords
xor eax, eax ; Colour zero
cld ; forwards through memory
rep stosd ; DO IT!!
ret
Re: I can't fix a bug! :(
Posted: Sun Nov 21, 2004 12:00 am
by ComputerPsi
Da_Maestro wrote:What does the code for pset look like?
Code: Select all
pset: ;ebx = x, edx = y, cl=color
push eax
push edx
push es
mov eax,8
mov es,eax
mov eax,320 ;addr=320*y+x
mul edx
add eax,ebx
add eax,[videomemory]
mov [es:eax],cl
pop es
pop edx
pop eax
ret
btw if you are trying to clear a VGA screen here is some better code:
Thanks for the code

Re: I can't fix a bug! :(
Posted: Sun Nov 21, 2004 12:00 am
by ComputerPsi
Well... I tried out the code, and it worked on Bochs.. but on my test computer, it didn't work. The keyboard still didn't respond. I found that if you comment out "rep stosd", it starts working again.. but I have no idea why...
Re: I can't fix a bug! :(
Posted: Sun Nov 21, 2004 12:00 am
by slasher
rep stosd is writing 4bytes at a time, so in 320*200*256 mode, the value in Ecx should be divided by 4 before calling rep stosd.( as it is now, you are overwriting something in memory)
Re: I can't fix a bug! :(
Posted: Mon Nov 22, 2004 12:00 am
by ComputerPsi
I finally found what was wrong (I feel like an idiot now, as usual when I find what's wrong). Apparently, I had these problems because I called the cls function before I unmasked, and enable the interrupts. When I called cls after the enabling of interrupts, it worked.
slasher:
Ya.. I saw that, which is why I changed the instruction to rep stosb

Re: I can't fix a bug! :(
Posted: Tue Nov 23, 2004 12:00 am
by [AlAdDiN]
LOL