Page 1 of 1

clear and set screen background question

Posted: Fri Mar 30, 2012 5:00 am
by assembler01
In screen mode 13h, is there a faster way to clear the screen and set the background color than this?

Code: Select all

; in: bl = background color
draw_back:
pusha
mov ax,0xa000 ; set es to segment to write directly to the screen
mov es,ax
mov di,64000 ; 64000 = 320 * 200 = num of pixels in mode 13h
.do:
mov byte[es:di],bl ; write pixel
dec di
jnz .do
popa
ret
PS: This code is VERY slow for my needs.

Re: clear and set screen background question

Posted: Fri Mar 30, 2012 5:52 am
by invalid
Fill with double words, not bytes. Also, try MMX instructions, they are pretty fast.

Re: clear and set screen background question

Posted: Fri Mar 30, 2012 6:02 am
by turdus

Code: Select all

mov ax, 0A000h
mov es, ax
mov ah, bl
mov al, bl
shl eax, 16
mov ah, bl
mov al, bl
xor di, di
mov cx, 320*200/4
cld
repnz stosd
If it's still not fast enough, consider double buffering.

Re: clear and set screen background question

Posted: Fri Mar 30, 2012 8:40 am
by assembler01
Tried it, very fast, but is there any way one can set the palette in mode 13h because I tried the ah=0x0b bh=0x01 bl=color int 0x10 and it didn't work?

Re: clear and set screen background question

Posted: Fri Mar 30, 2012 11:11 am
by turdus
assembler01 wrote:Tried it, very fast, but is there any way one can set the palette in mode 13h because I tried the ah=0x0b bh=0x01 bl=color int 0x10 and it didn't work?

Code: Select all

		;set palette
		mov			dx, word 3c8h
		mov			al, n				;index 
		out			dx, al
		inc			dx
		mov			al, r
		out			dx, al			;red
		mov			al, g
		out			dx, al			;green
		mov			al, b
		out			dx, al			;blue