flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > Mouse driver (problem) (SOLVED)

Author
Thread Post new topic Reply to topic
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi All

This source load de mouse routines into DOS int... but... I have trying changed it... for load mouse out DOS int (for pure OS)... it's my problem... When I change for not use DOS codes.... the program not run... all help is welcome!!!

Thanks...

grunge

Code:

SEE 2 SOURCES BELOW! The post have a big size....

    


Last edited by grunge on 10 Mar 2007, 21:38; edited 5 times in total
Post 19 Feb 2007, 18:42
View user's profile Send private message Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi All

I have news tests.... but not success.... when I change for not load DOS int.... the program dead... looping forever!!! Smile ... I go continue my tests... as soon as I will have a solution I communicate to all…

grunge
Post 22 Feb 2007, 23:38
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
moderator, please move this to the DOS subforum (unless I misunderstood the poster's intentions).
Post 22 Feb 2007, 23:40
View user's profile Send private message Visit poster's website Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi rugxulo

No delete it... please!!! Smile
I have problem with change the code for "pure" code... one code that load and run the mouse without DOS...

Thanks and sorry for my explanation of problem...
Post 23 Feb 2007, 00:35
View user's profile Send private message Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi All

I happy... my mouse run without DOS... I have smalls bugs... but tomorrow I work for solution it...

Bugs:

Mouse run loop... (I not move the mouse... but the pixel run in screen (is one ghost bug Wink )


Last edited by grunge on 10 Mar 2007, 21:34; edited 1 time in total
Post 23 Feb 2007, 01:39
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
grunge wrote:
Hi rugxulo

No delete it... please!!! Smile
I have problem with change the code for "pure" code... one code that load and run the mouse without DOS...

Thanks and sorry for my explanation of problem...


I thought you'd said without DOS, but here's what confused me:

Quote:

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


Also, FYI, if you're writing 16-bit, 8086-compatible code, check out MCD's ONLY8086.INC include.

P.S. You can "push ax bx cx dx" all on one line (but, unlike Octasm, you'll have to pop in reverse: "pop dx cx bx ax"). Also, don't forget that local labels exist: "good_hor[12] and good_ver[12]" -> "good: .hor1: .hor2: .ver1: .ver2:".

(Not that it matters, but you may prefer a cleaner approach).
Post 23 Feb 2007, 20:37
View user's profile Send private message Visit poster's website Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Thanks for yours suggestions... the ps2 mouse runs in "pure mode"... but the source have few small (logical bug) problems... but I work for solution it... All help is Welcome!!!



Quote:

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

This block code is for my tests when I working in FreeDos. (for not have restart and boot the mouse program all time)


grunge
Post 24 Feb 2007, 02:07
View user's profile Send private message Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
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 Wink )


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 Wink )


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... and sorry for my problem... but I have much time in it... and not find one solution...

grunge
Post 05 Mar 2007, 03:02
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
I had a look at your code (did not anlyze the port accesses in detail,
use my hints with care) and tested it. The no-OS version ends up
in a hard freezer in text screen mode. Sad

Quote:
This block code is for my tests when I working in FreeDos. (for not have restart and boot the mouse program all time)


Quote:
but here's what confused me:
Code:
Mov AX,3h
Int 10h
Mov AX,0x4C00
Int 21h
    



It's perfectly possible and useful to test no-OS code in FreeDOS Smile

Also INT $21,$4C00 is no problem ... you just have to explain it better Shocked

Code:
Jmp   InstallMouse  ; Load the mouse

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


You probably should swap them:

1. Set video mode
2. Activate mouse

Code:
Mov   CX,CX
Mov   DX,DX 
    


What does this code do ? Laughing

Code:
 mov   ax,0x2574
 mov   dx,mouse_code 
 int   21h  
    


This is the problem. This must be kicked in the no-OS version, as you
found out Smile and commented it out with no replacement Confused Maybe an
unhandled IRQ occurs Confused

Code:
cli
    


Why do you ban interrupts ? Where do you re-allow them ? Seems to be
part of the problem as well Confused

Quote:

Mov AH,0Ch
Mov CX,CX
Mov DX,DX
Mov AL,15
Int 10h

Xor AX,AX
Mov AH,11h
Int 16h


This probably also contributes to the problem. After hacking on IRQ's
and ports you maybe should no longer use BIOS INT's either Confused

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 07 Mar 2007, 17:01
View user's profile Send private message Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi all

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


NTOSKRNL_VXE

Thanks for your help, your helps is correct!

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

Thanks for all help...

grunge
Post 10 Mar 2007, 21:37
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
There has been alot of people with mouse problem in the forum, so i have code a simple demo, of a working mouse driver, that does not use any OS code and is fully self contained.
Here is the fasm code and a bootable program to test it, (Note: it will run from dos, but not a dosbox under windows).
http://www.dex4u.com/tuts/MouseDemo.zip

I will add comment in the next day or two, but for now, the code is there.

PS: The demo is running in MiniDos, if you want the code let me know.
Post 11 Mar 2007, 19:44
View user's profile Send private message Reply with quote
grunge



Joined: 11 Sep 2005
Posts: 21
Location: Brasil
Hi Dex4u

Good idea... it help very developers... my mouse already runs correct... I use "Set Interrupt Vector" of "MiniDos" (I already the source)... Wink... this is very util... my code is very small... I think... thanks for you initiative and good work.

grunge
Post 12 Mar 2007, 22:57
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
@grunge, Thanks for you kind words and good luck with your OS Smile.
Post 13 Mar 2007, 00:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.