0 Replies - 1407 Views - Last Post: 28 May 2010 - 08:55 AM

#1 nathanpc   User is offline

  • SCIENCE!
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

VBE And Mouse Use

Posted 28 May 2010 - 08:55 AM

Description: On this example, you're going to see the use of VBE(to make better view on bigger screens), used 320x200 256 color graphics (MCGA, VGA), use mouse and the keyboard, very simply. To compile this source code, just type this on the console: fasm source.asmSimple use of VBE(for a higher resolution, used 320x200 256 color graphics - MCGA, VGA), keyboard and mouse using Assembly. (Fasm Syntax)
org  100h

main:
		call	set_video_mode
		
	.main_loop:
		call	get_mouse_input
		call	draw_top_bar
		call	get_keyboard_input
		
		jz		.main_loop
		
		jmp	exit



set_video_mode:
	    mov	ah, 0h
	    mov	al, 13h  ; 320x200 256 color graphics (MCGA,VGA)
	    int	10h
	
	    mov	ax, 1h  ; show mouse cursor
		int	33h
	ret


get_mouse_input:
		mov	ax, 3h	; Get Mouse Position and Button Status
		int	33h	 ; CX = X, DX = Y, BX = status
		mov	[mouseX], cx
		mov	[mouseY], dx
	ret


draw_top_bar:
		mov	cx, [screenW]  ; column (X)
		mov	dx, 5  ; row    (Y)
		mov	al, 0Fh  ; white color
	@@:
		mov	ah, 0Ch  ; put pixel 
		int	10h
		dec	cx  ; ZF = (cx == 0)? 1 : 0
		jnz	@b
		
		mov		cx, [screenW]
		dec	dx  ; go to the next line
		jnz		@b
	ret


get_keyboard_input:
		mov	ah, 1h;                         ; 0h = wait for keypress; 1h = Get Keyboard Status
		int	16h  ; AL = ASCII (F# = 0), AH = keyboard scancode
	ret


set_text_mode:	; return to text mode:
		mov	ah, 0h
		mov	al, 3h  ;text mode 3 
		int	10h
	ret


exit:
		mov	ah, 4Ch  ; default output of the .com format
		int	21h

	
	screenW dw 319  ; (só appear 1 until 319) = 320
	screenH dw 199	; (só appear 1 until 199) = 200
	
	mouseX dw 0
	mouseY dw 0


Is This A Good Question/Topic? 0
  • +

Page 1 of 1