clear and set screen background question

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
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

clear and set screen background question

Post 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.
Talk is cheap, show me the code. - Linus Torvalds
invalid
Member
Member
Posts: 60
Joined: Thu Feb 23, 2012 8:39 am

Re: clear and set screen background question

Post by invalid »

Fill with double words, not bytes. Also, try MMX instructions, they are pretty fast.
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: clear and set screen background question

Post 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.
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: clear and set screen background question

Post 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?
Talk is cheap, show me the code. - Linus Torvalds
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: clear and set screen background question

Post 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
Post Reply