OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 1:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Mouse driver ps2 (help) (solved)
PostPosted: Sun Feb 25, 2007 5:25 pm 
Offline

Joined: Sun Feb 25, 2007 5:16 pm
Posts: 6
...


Last edited by grunge_asm on Sat Mar 10, 2007 3:12 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: ...
PostPosted: Sun Mar 04, 2007 8:42 pm 
Offline

Joined: Sun Feb 25, 2007 5:16 pm
Posts: 6
Hi All

I have changed the code for load mouse out DOS... but not success... this is source with run in DOS:

Code:
ORG 100h

   Jmp   InstallMouse  ; Load the mouse

MainCode:              ; Use the mouse loaded
   Mov   AX,12h
   Int   10h

MainLoop:              ; My Main Loop, show pixel with mouse coordinates
   Call  get_pos
   Mov   AH,0Ch
   Mov   CX,CX
   Mov   DX,DX
   Mov   AL,15
   Int   10h

   Xor   AX,AX
   Mov   AH,11h
   Int   16h
   Jnz   Exit
   Jmp   MainLoop

Exit:                 ; Exit code
   Mov   AX,3h
   Int   10h
   Mov   AX,0x4C00
   Int   21h

InstallMouse:         ; Load mouse in DOS, create one int
   mov   bl,0adh
   call  keyboard_cmd
   call  keyboard_read ; Pac 1
   call  keyboard_read ; Pac 2
   call  keyboard_read ; Pac 3
   mov   bl,0aeh
   call  keyboard_cmd
   mov   al,20h
   out   0a0h,al
   out   20h,al
   mov   ax,0x2574
   mov   dx,mouse_code
   int   21h
   cli
   mov   bl,0a8h
   call  keyboard_cmd
   mov   bl,20h
   call  keyboard_cmd
   call  keyboard_read
   or    al,2
   mov   bl,60h
   push  ax
   call  keyboard_cmd
   pop   ax
   call  keyboard_write
   mov   bl,0d4h
   call  keyboard_cmd
   mov   al,0f4h
   call  keyboard_write

   Jmp   MainCode        ; Return to MainCode (mouse loaded, then: use mouse ;) )


mouse_code:            ; Mouse codes
   push  ax
   push  bx
   push  cx
   push  dx
   push  di
   push  si
   push  es
   push  ds
   push  cs
   pop   ds
   mov   bl,0adh
   call  keyboard_cmd
   call  keyboard_read ; for first byte
   call  keyboard_read
   cbw
   add   word [pos_x],ax
   mov   ax,word [x_min]
   cmp   word [pos_x],ax
   jg    .goodhor1
   mov   word [pos_x],ax

.goodhor1:
   mov   ax,word [x_max]
   cmp   word [pos_x],ax
   jle   .goodhor2
   mov   word [pos_x],ax

.goodhor2:
   call  keyboard_read
   neg   al
   cbw
   add   word [pos_y],ax
   mov   ax,[y_min]
   cmp   word [pos_y],ax
   jg    .goodver1
   mov   word [pos_y],ax

.goodver1:
   mov   ax,word [y_max]
   cmp   word [pos_y],ax
   jle   no_show
   mov   word [pos_y],ax

no_show:
   mov   bl,0aeh
   call  keyboard_cmd
   mov   al,20h
   out   0a0h,al
   out   20h,al
   pop   ds
   pop   es
   pop   si
   pop   di
   pop   dx
   pop   cx
   pop   bx
   pop   ax
   iret

get_pos:
   mov   cx,word [pos_x]
   mov   dx,word [pos_y]
   ret

;------------------------------------------------------------------------

pos_x           dw 0
pos_y           dw 0
x_max           dw 639
x_min           dw 0
y_max           dw 479
y_min           dw 0

keyboard_read:
   push  cx
   push  dx
   xor   cx,cx

key_read_loop:
   in    al,64h
   test  al,1
   jnz   key_read_ready
   loop  key_read_loop
   mov   ah,1
   jmp   key_read_exit

key_read_ready:
   push  cx
   mov   cx,32

key_read_delay:
   loop  key_read_delay
   pop   cx
   in    al,60h
   xor   ah,ah

key_read_exit:
   pop   dx
   pop   cx
   ret

keyboard_write:
   push  cx
   push  dx
   mov   dl,al
   xor   cx,cx

kbd_wrt_loop1:
   in    al,64h
   test  al,20h
   jz    kbd_wrt_ok1
   loop  kbd_wrt_loop1
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok1:
   in    al,60h
   xor   cx,cx

kbd_wrt_loop:
   in    al,64h
   test  al,2
   jz    kbd_wrt_ok
   loop  kbd_wrt_loop
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok:
   mov   al,dl
   out   60h,al
   xor   cx,cx

kbd_wrt_loop3:
   in    al,64h
   test  al,2
   jz    kbd_wrt_ok3
   loop  kbd_wrt_loop3
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok3:
   mov   ah,8

kbd_wrt_loop4:
   xor   cx,cx

kbd_wrt_loop5:
   in    al,64h
   test  al,1
   jnz   kbd_wrt_ok4
   loop  kbd_wrt_loop5
   dec   ah
   jnz   kbd_wrt_loop4

kbd_wrt_ok4:
   xor   ah,ah

kbd_wrt_exit:
   pop   dx
   pop   cx
   ret

keyboard_cmd:
   xor   cx,cx

cmd_wait:
   in    al,64h
   test  al,2
   jz    cmd_send
   loop  cmd_wait
   jmp   cmd_error

cmd_send:
   mov   al,bl
   out   64h,al
   xor   cx,cx

cmd_accept:
   in    al,64h
   test  al,2
   jz    cmd_ok
   loop  cmd_accept

cmd_error:
   mov     ah,1
   jmp      cmd_exit

cmd_ok:
   xor     ah,ah

cmd_exit:
   ret


And this is my code changed for run out DOS (when I run it... not run correct)

Code:
ORG 100h

   Jmp   InstallMouse  ; Load the mouse

MainCode:              ; Use the mouse loaded
   Mov   AX,12h
   Int   10h

MainLoop:              ; My Main Loop, show pixel with mouse coordinates
   Call  mouse_code
   Call  get_pos
   Mov   AH,0Ch
   Mov   CX,CX
   Mov   DX,DX
   Mov   AL,15
   Int   10h

   Xor   AX,AX
   Mov   AH,11h
   Int   16h
   Jnz   Exit
   Jmp   MainLoop

Exit:                 ; Exit code
   Mov   AX,3h
   Int   10h
   Jmp   $

InstallMouse:         ; Load mouse in DOS, create one int
   mov   bl,0adh
   call  keyboard_cmd
   call  keyboard_read ; Pac 1
   call  keyboard_read ; Pac 2
   call  keyboard_read ; Pac 3
   mov   bl,0aeh
   call  keyboard_cmd
   mov   al,20h
   out   0a0h,al
   out   20h,al
;   mov   ax,0x2574
;   mov   dx,mouse_code
;   int   21h
   cli
   mov   bl,0a8h
   call  keyboard_cmd
   mov   bl,20h
   call  keyboard_cmd
   call  keyboard_read
   or    al,2
   mov   bl,60h
   push  ax
   call  keyboard_cmd
   pop   ax
   call  keyboard_write
   mov   bl,0d4h
   call  keyboard_cmd
   mov   al,0f4h
   call  keyboard_write

   Jmp   MainCode        ; Return to MainCode (mouse loaded, then: use mouse ;) )


mouse_code:            ; Mouse codes
   push  ax
   push  bx
   push  cx
   push  dx
   push  di
   push  si
   push  es
   push  ds
   push  cs
   pop   ds
   mov   bl,0adh
   call  keyboard_cmd
   call  keyboard_read ; for first byte
   call  keyboard_read
   cbw
   add   word [pos_x],ax
   mov   ax,word [x_min]
   cmp   word [pos_x],ax
   jg    .goodhor1
   mov   word [pos_x],ax

.goodhor1:
   mov   ax,word [x_max]
   cmp   word [pos_x],ax
   jle   .goodhor2
   mov   word [pos_x],ax

.goodhor2:
   call  keyboard_read
   neg   al
   cbw
   add   word [pos_y],ax
   mov   ax,[y_min]
   cmp   word [pos_y],ax
   jg    .goodver1
   mov   word [pos_y],ax

.goodver1:
   mov   ax,word [y_max]
   cmp   word [pos_y],ax
   jle   no_show
   mov   word [pos_y],ax

no_show:
   mov   bl,0aeh
   call  keyboard_cmd
   mov   al,20h
   out   0a0h,al
   out   20h,al
   pop   ds
   pop   es
   pop   si
   pop   di
   pop   dx
   pop   cx
   pop   bx
   pop   ax
;   iret
   ret

get_pos:
   mov   cx,word [pos_x]
   mov   dx,word [pos_y]
   ret

;------------------------------------------------------------------------

pos_x           dw 0
pos_y           dw 0
x_max           dw 639
x_min           dw 0
y_max           dw 479
y_min           dw 0

keyboard_read:
   push  cx
   push  dx
   xor   cx,cx

key_read_loop:
   in    al,64h
   test  al,1
   jnz   key_read_ready
   loop  key_read_loop
   mov   ah,1
   jmp   key_read_exit

key_read_ready:
   push  cx
   mov   cx,32

key_read_delay:
   loop  key_read_delay
   pop   cx
   in    al,60h
   xor   ah,ah

key_read_exit:
   pop   dx
   pop   cx
   ret

keyboard_write:
   push  cx
   push  dx
   mov   dl,al
   xor   cx,cx

kbd_wrt_loop1:
   in    al,64h
   test  al,20h
   jz    kbd_wrt_ok1
   loop  kbd_wrt_loop1
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok1:
   in    al,60h
   xor   cx,cx

kbd_wrt_loop:
   in    al,64h
   test  al,2
   jz    kbd_wrt_ok
   loop  kbd_wrt_loop
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok:
   mov   al,dl
   out   60h,al
   xor   cx,cx

kbd_wrt_loop3:
   in    al,64h
   test  al,2
   jz    kbd_wrt_ok3
   loop  kbd_wrt_loop3
   mov   ah,1
   jmp   kbd_wrt_exit

kbd_wrt_ok3:
   mov   ah,8

kbd_wrt_loop4:
   xor   cx,cx

kbd_wrt_loop5:
   in    al,64h
   test  al,1
   jnz   kbd_wrt_ok4
   loop  kbd_wrt_loop5
   dec   ah
   jnz   kbd_wrt_loop4

kbd_wrt_ok4:
   xor   ah,ah

kbd_wrt_exit:
   pop   dx
   pop   cx
   ret

keyboard_cmd:
   xor   cx,cx

cmd_wait:
   in    al,64h
   test  al,2
   jz    cmd_send
   loop  cmd_wait
   jmp   cmd_error

cmd_send:
   mov   al,bl
   out   64h,al
   xor   cx,cx

cmd_accept:
   in    al,64h
   test  al,2
   jz    cmd_ok
   loop  cmd_accept

cmd_error:
   mov     ah,1
   jmp      cmd_exit

cmd_ok:
   xor     ah,ah

cmd_exit:
   ret


All help for correct the bug is welcome... or reply for why the bug is occurred.... thanks for all...

grunge


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 04, 2007 11:39 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
What bug are you getting? Have you made sure that the code is executing the right stuff (use jmp $ and text output to test)? Have you made sure that the mouse you are testing with is definitely PS2 - a USB mouse doesn't count here...

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 3:57 pm 
Offline

Joined: Sun Feb 25, 2007 5:16 pm
Posts: 6
The bug is when I run the source 2 out (not one int DOS)... the mouse reads is not correct(AX = mouse coord... but in pure mode it not correct)... but if I change for run with DOS int (source 1) the mouse reads is correct... my mouse is ps2... the bug must be in read the mouse without one Int(DOS)... why... the source 1 create one DOS int for the mouse codes... and the source 2 no... is in pure mode.... Thanks...

grunge


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 12:09 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Well, the DOS ints have been tried and tested. There's a high chance that they'll work. On the other hand, your code may not work. I have a similar problem, where the status byte gets mixed in with the movement data. I guess one of the ways you could test for this is find out which bytes are only 1 or 0 (the status byte isn't) or something like that.

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 11:16 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
I have tested your code and on my test PC (win98) the Dos ver does not even work ?,
Also code like this:
Code:
mov dx,dx
mov cx,cx

what is that for ?.
Also if i was you, i would code a text ver using a space block etc, untill you get it working then, move to mode 12h.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 4:13 pm 
Offline

Joined: Sun Feb 25, 2007 5:16 pm
Posts: 6
Hi All


pcmattman

thanks for yours sugestion... I go work for disable mouse and read byte mouse code correct (0 1)....

Dex

The DOS version (source 1) run correct... but when I change for not run in DOS (source 2) the mouse reads is not correct...

Code:
Mov  DX,DX
Mov  CX,CX

This code is only for remenber the coords (pixel)...

and is for remender the result of mouse position:
Code:
get_pos:
   mov   cx,word [pos_x]
   mov   dx,word [pos_y]
   ret



mode 12h is for happy work ;).... and is easy to look the cursor working... thanks

I go work for yours suggestion...

Thanks for all

grunge


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 3:11 pm 
Offline

Joined: Sun Feb 25, 2007 5:16 pm
Posts: 6
Hi all

I correct the mouse driver...
source1 (DOS)
Code:
   mov   ax,0x2574
   mov   dx,mouse_code
   int   21h


I have changed it for create one "Set Interrupt vector" without DOS, I only changed it... now... mouse runs correct in pure code!!! ;)

Thanks for all help...

grunge


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 107 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group