I'm doing it completely in 32 bit assembler (cause I really like it ). But I can't manage to clear the entire screen.
This is the code, and the result:
This is how it's done in C (I didn't copy the entire function)
Code: Select all
/* Sets the entire screen to spaces in our current
* color */
for(i = 0; i < 25; i++)
memsetw (textmemptr + i * 80, blank, 80);
Code: Select all
global cls ;clear screen
cls:
xor eax,eax
mov ah, [text_attributes]
mov al,'A' ;0x20 | I replaced the BLANK char, to verify where it's writing on the screen
;now we have to go from row 0 to 24 in memory to blank the screen
;Index = [(y * width) + x]
;ecx will be Y and X will be vga_memory (0xB8000). width is 80
mov ecx,24
push eax ;remember that eax has the 'A' char with the attributes (foreground color... etc)
.fill_memory:
mov eax,ecx ;move to the next row
mov ebx,80
mul ebx
add eax,[video_memory] ;now eax = [(ecx * 80) + video_memmory]
mov edi, eax ;this is the memory location were it should write
pop eax ;this has the blank character!
push ecx ;keep it safe!!! you don't want to mess with the loop
mov ecx, 80 ;this is the length of each row
rep stosw ;write 80 'A' in memory, then
pop ecx ;restore ecx
push eax; ;save the 'A' character
loop .fill_memory ; decrease ecx and continue with the next row
pop eax ;clean the stack ;)
ret
The result? Bochs says:
, BSS=0x3000Sarting up... AAAAAAAAAAAAAAAAAA... and writes 13 rows of 'A' instead of 25
Any suggestions?
Thanks for reading this far!