I can't fix a bug! :(

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.
Post Reply
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

I can't fix a bug! :(

Post 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).
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: I can't fix a bug! :(

Post by Da_Maestro »

What does the code for pset look like?
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: I can't fix a bug! :(

Post 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

ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: I can't fix a bug! :(

Post 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 ;)
Anything is possible if you put your mind to it.
ComputerPsi
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: I can't fix a bug! :(

Post 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...
Anything is possible if you put your mind to it.
ComputerPsi
slasher
Posts: 17
Joined: Sun Oct 24, 2004 11:00 pm
Contact:

Re: I can't fix a bug! :(

Post 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)
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: I can't fix a bug! :(

Post 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 ;)
Last edited by ComputerPsi on Mon Nov 22, 2004 12:00 am, edited 1 time in total.
Anything is possible if you put your mind to it.
ComputerPsi
[AlAdDiN]
Member
Member
Posts: 107
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: I can't fix a bug! :(

Post by [AlAdDiN] »

LOL
-----------------------
There are 10 types of people in this world... those that understand binary, and those that don't.
Post Reply