Mauszeiger malen



  • Hi,
    weiß jemand, wie ich einen Mauszeiger male? Meinen eigenen? Hat da jemand beispiel ciode? Arbeite in Vesa bei 16-Bit Farbtiefe und 1280x124 Bildpunkten. Danke! 😃



  • Hi.

    Wo ist dein Problem? Ich nehme mal an, du weisst inzwischen, wie das mit dem
    Eventhandler des DOS-Maustreibers funktioniert.
    Dann machst du dir halt ein 16Bit-Bitmap deines Mauszeigers, definierst eine
    Farbe als durchsichtig und pinselst dieses Bild immer an die aktuelle x/y-
    Position der Maus. Je nach Struktur deines Programms, musst du dann
    natuerlich vorher den Bildschirmteil, den du mit dem Mauszeiger uebermalst,
    in einen Puffer speichern, um beim Weiterbewegen der Maus die letzte Position
    des Cursors zu loeschen (so machen es die DOS-Treiber im VGA-Modus), oder
    du koenntest den ganzen Bildschirm neu aufbauen, bevor du den Mauszeiger
    zeichnen tust.

    Beispielcode habe ich nicht, und vor den naechsten Ferien werde ich ganz bestimmt auch keinen mehr fabrizieren, oder raussuchen -> Google ist dein Freund. 🕶

    BTW:
    Magst du den "[Morpheus]" nicht, oder weshalb musstest du fuer diese
    Frage einen neuen Thread starten? 😃
    Schau dir doch mal seinen Thread an: Mauszeiger im SVGA Modus (und >640x480)
    Augenscheinlich hat der IMHO das gleiche Thema. 😉



  • hast recht, was das thema angeht, allerdings ist da ein kleiner unterschied, ich nutze nicht den dos maustreiber, da ich ein eigenes OS code. das unterscheided die themen ein wenig.



  • Tja, das haette man zB. erwaehnen koennen. 😉
    Ich gehe aber davon aus, dass du dann schon einen Treiber fuer die Mouse-Hardware hast - dann faellt deine Frage doch wieder so ziemlich in das selbe Themengebiet. :p



  • Da es dein OS wird dir hier keiner helfen könne. Wir wissen nicht wie du dein framebuffer device aufgebaut hast.



  • Hi,
    hab mir den Treiber Code beio Programmers Haeven geklaut. Hier der Code, wenn er euch weiterbringt:

    [ORG 0x0100] 		;* YEP its a .COM file!
    
    JMP MAINP
    
    ;***********************************************************************
    ;Activate mouse port (PS/2)
    ;***********************************************************************
    PS2SET:
      mov  al, 0xa8		; enable mouse port
      out  0x64, al		; write to keyboardcontroller
      call CHKPRT		; check if command is progressed (demand!)
    ret
    
    ;***********************************************************************
    ;Check if command is accepted. (not got stuck in inputbuffer)
    ;***********************************************************************
    CHKPRT:
      xor  cx, cx		
     .again:
      in   al, 0x64		; read from keyboardcontroller
      test al, 2		; Check if input buffer is empty
      jz  .go
      jmp .again		; (demand!) This may couse hanging, use only when sure.
     .go
    ret
    
    ;***********************************************************************
    ;Write to mouse
    ;***********************************************************************
    WMOUS:
      mov  al, 0xd4		; write to mouse device instead of to keyboard
      out  0x64, al		; write to keyboardcontroller
      call CHKPRT		; check if command is progressed (demand!)
    ret
    
    ;***********************************************************************
    ;mouse output buffer full
    ;***********************************************************************
    MBUFFUL:
      xor  cx, cx
     .mn:
      in   al, 0x64		; read from keyboardcontroller
      test al, 0x20		; check if mouse output buffer is full
      jz  .mnn
      loop .mn
     .mnn:
    ret
    
    ;***********************************************************************
    ;Write activate Mouse HardWare
    ;***********************************************************************
    ACTMOUS:
      call WMOUS
      mov  al, 0xf4 	; Command to activate mouse itselve (Stream mode)
      out  0x60, al		; write ps/2 controller output port (activate mouse)
      call CHKPRT		; check if command is progressed (demand!)
      call CHKMOUS		; check if a byte is available
    ret
    
    ;***********************************************************************
    ;Check if mouse has info for us
    ;***********************************************************************
    CHKMOUS:
      mov  bl, 0
      xor  cx, cx
     .vrd:
      in   al, 0x64		; read from keyboardcontroller
      test al, 1		; check if controller buffer (60h) has data
      jnz .yy
      loop .vrd
      mov  bl, 1
     .yy:
    ret
    
    ;***********************************************************************
    ;Disable Keyboard
    ;***********************************************************************
    DKEYB:
      mov  al, 0xad		; Disable Keyboard
      out  0x64, al		; write to keyboardcontroller
      call CHKPRT		; check if command is progressed (demand!)
    ret
    
    ;***********************************************************************
    ;Enable Keyboard
    ;***********************************************************************
    EKEYB:
      mov  al, 0xae		; Enable Keyboard
      out  0x64, al		; write to keyboardcontroller
      call CHKPRT		; check if command is progressed (demand!)
    ret
    
    ;***********************************************************************
    ;Get Mouse Byte
    ;***********************************************************************
    GETB:
     .cagain
      call CHKMOUS		; check if a byte is available
      or   bl, bl
      jnz .cagain
      call DKEYB		; disable keyboard to read mouse byte
      xor  ax, ax
      in   al, 0x60		; read ps/2 controller output port (mousebyte)
      mov  dl, al
      call EKEYB		; enable keyboard
      mov  al, dl
    ret
    
    ;***********************************************************************
    ;Get 1ST Mouse Byte
    ;***********************************************************************
    GETFIRST:
      call GETB 		;Get byte1 of packet
      xor  ah, ah
      mov  bl, al
      and  bl, 1
      mov  BYTE [LBUTTON], bl
      mov  bl, al
      and  bl, 2
      shr  bl, 1
      mov  BYTE [RBUTTON], bl
      mov  bl, al
      and  bl, 4
      shr  bl, 2
      mov  BYTE [MBUTTON], bl
      mov  bl, al
      and  bl, 16
      shr  bl, 4
      mov  BYTE [XCOORDN], bl
      mov  bl, al
      and  bl, 32
      shr  bl, 5
      mov  BYTE [YCOORDN], bl
      mov  bl, al
      and  bl, 64
      shr  bl, 6
      mov  BYTE [XFLOW], bl
      mov  bl, al
      and  bl, 128
      shr  bl, 7
      mov  BYTE [YFLOW], bl
    ret
    
    ;***********************************************************************
    ;Get 2ND Mouse Byte
    ;***********************************************************************
    GETSECOND:
      call GETB 		;Get byte2 of packet
      xor  ah, ah
      mov  BYTE [XCOORD], al
    ret
    
    ;***********************************************************************
    ;Get 3RD Mouse Byte
    ;***********************************************************************
    GETTHIRD:
      call GETB 		;Get byte3 of packet
      xor  ah, ah
      mov  BYTE [YCOORD], al
    ret
    
    ;-----------------------------------------------------------------------
    ;***********************************************************************
    ;* MAIN PROGRAM
    ;***********************************************************************
    ;-----------------------------------------------------------------------
    
    MAINP:
      call PS2SET
      call ACTMOUS
      call GETB 	;Get the responce byte of the mouse (like: Hey i am active)  If the bytes are mixed up, remove this line or add another of this line.
    
    .main
      call GETFIRST
      call GETSECOND
      call GETTHIRD
    
    ;*NOW WE HAVE XCOORD & YCOORD* + the button status of L-butten and R-button and M-button allsow overflow + sign bits
    
    ;!!!
    ;! The Sign bit of X tells if the XCOORD is Negative or positive. (if 1 this means -256)
    ;! The XCOORD is allways positive
    ;!!!
    
    ;???
    ;? Like if:    X-Signbit = 1		Signbit
    ;? 					|
    ;?             XCOORD = 11111110 ---> -256 + 254 = -2  (the mouse cursor goes left)
    ;?                      \      /
    ;?                       \    /
    ;?                        \Positive
    ;???
    
    ;?? FOR MORE INFORMATION ON THE PS/2 PROTOCOL SEE BELOW!!!!
    
    ;!!!!!!!!!!!!!
    ;the rest of the source... (like move cursor) (i leave this up to you m8!)
    ;!!!!!!!!!!!!!
    
    ;*************************************************************
    ;Allright, Allright i'll give an example!  |EXAMPLE CODE|
    ;*************************************************************
    ;=============================
    ;**Mark a position on scr**
    ;=============================
     mov BYTE [row], 15
     mov BYTE [col], 0
    
    ;=============================
    ;**go to start position**
    ;=============================
     call GOTOXY
    
    ;=============================
    ;**Lets display the X coord**
    ;=============================
     mov  si, strcdx	; display the text for Xcoord
     call disp
     mov  al, BYTE [XCOORDN]
     or   al, al
     jz  .negative
     mov  si, strneg	; if the sign bit is 1 then display - sign
     call disp
     jmp .positive
    .negative
     mov  si, strsp		; else display a space
     call disp
    .positive
     xor  ah, ah
     mov  al, BYTE [XCOORD]
     call DISPDEC
     mov  si, stretr	; goto nextline on scr
     call disp
    
    ;=============================
    ;**Lets display the Y coord**
    ;=============================
     mov  si, strcdy	; display the text for Ycoord
     call disp
     mov  al, BYTE [YCOORDN]
     or   al, al
     jz  .negativex
     mov  si, strneg	; if the sign bit is 1 then display - sign
     call disp
     jmp .positivex
    .negativex
     mov  si, strsp		; else display a space
     call disp
    .positivex
     xor  ah, ah
     mov  al, BYTE [YCOORD]
     call DISPDEC
     mov  si, stretr	; goto nextline on scr
     call disp
    
    ;=============================
    ;**Lets display the L button**
    ;=============================
     mov  si, strlbt	; display the text for Lbutton
     call disp
     mov  al, BYTE [LBUTTON]
     xor  ah, ah
     call DISPDEC
     mov  si, stretr	; goto nextline on scr
     call disp
    
    ;=============================
    ;**Lets display the R button**
    ;=============================
     mov  si, strrbt	; display the text for Rbutton
     call disp
     mov  al, BYTE [RBUTTON]
     xor  ah, ah
     call DISPDEC
     mov  si, stretr	; goto nextline on scr
     call disp
    
    ;=============================
    ;**Lets display the M button**
    ;=============================
     mov  si, strmbt	; display the text for Mbutton
     call disp
     mov  al, BYTE [MBUTTON]
     xor  ah, ah
     call DISPDEC
     mov  si, stretr	; goto nextline on scr
     call disp
    
    ;=============================
    ;**stop program on keypress**	|Note: sometimes it takes a while for the program stops, or keyboard stalls|
    ;=============================  |due to more time is spend looking at the PS/2 mouse port (keyb disabled)  |
        xor  ax, ax
        mov  ah, 0x11
        int  0x16
        jnz quitprog
    ;*************************************************************
    
    jmp .main
    
    quitprog:
     MOV     AH, 0x4C  	;Return to OS
     INT     0x21		
    ;-----------------------------------------------------------------------
    ;***********************************************************************
    ;* END OF MAIN PROGRAM
    ;***********************************************************************
    ;-----------------------------------------------------------------------
    
    ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    ;X Dont Worry about this displaypart, its yust ripped of my os.
    ;X (I know it could be done nicer but this works :P)
    ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    ;XXX
    ;************************************************
    ;* Displays AX in a decimal way 
    ;************************************************
    DISPDEC:
        mov  BYTE [zerow], 0x00
        mov  WORD [varbuff], ax
        xor  ax, ax
        xor  cx, cx
        xor  dx, dx
        mov  bx, 10000
        mov  WORD [deel], bx
       .mainl    
        mov  bx, WORD [deel]
        mov  ax, WORD [varbuff]
        xor  dx, dx
        xor  cx, cx
        div  bx
        mov  WORD [varbuff], dx
        jmp .ydisp
    
       .vdisp
        cmp  BYTE [zerow], 0x00
        je .nodisp
    
       .ydisp
        mov  ah, 0x0E                            ; BIOS teletype
        add  al, 48                              ; lets make it a 0123456789 :D
        mov  bx, 1 
        int  0x10                                ; invoke BIOS
        mov  BYTE [zerow], 0x01
       jmp .yydis
    
       .nodisp
    
       .yydis
        xor  dx, dx
        xor  cx, cx
        xor  bx, bx
        mov  ax, WORD [deel]
        cmp  ax, 1
        je .bver
        cmp  ax, 0
        je .bver
        mov  bx, 10
        div  bx
        mov  WORD [deel], ax
       jmp .mainl
    
       .bver
       ret
    ;***************END of PROCEDURE*********************************
    ;****************************************************************
    ;* PROCEDURE disp      
    ;* display a string at ds:si via BIOS
    ;****************************************************************
    disp:
     .HEAD
        lodsb                                    ; load next character
        or   al, al                              ; test for NUL character
        jz   .DONE                               ; if NUL char found then goto done
        mov  ah, 0x0E                            ; BIOS teletype
        mov  bx, 1 				     ; make it a nice fluffy blue (mostly it will be grey but ok..)
        int  0x10                                ; invoke BIOS
        jmp  .HEAD
    
     .DONE: 
       ret
    ;*******************End Procedure ***********************
    ;*****************************
    ;*GOTOXY  go back to startpos
    ;*****************************
    GOTOXY:
        mov ah, 2
        mov bh, 0                  ;0:graphic mode 0-3: in modes 2&3 0-7: in modes 0&1
        mov dl, BYTE [col]
        mov dh, BYTE [row]
        int 0x10
    ret
    ;*******END********
    ;
    ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    ;XXX
    ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    ;***********************************************************************
    ;variables
    ;***********************************************************************
    LBUTTON db 0x00	;	Left   button status 1=PRESSED 0=RELEASED
    RBUTTON db 0x00	;	Right  button status 1=PRESSED 0=RELEASED
    MBUTTON db 0x00	;	Middle button status 1=PRESSED 0=RELEASED
    XCOORD  db 0x00	;	the moved distance  (horizontal)
    YCOORD  db 0x00	;	the moved distance  (vertical)
    XCOORDN db 0x00 ;       Sign bit (positive/negative) of X Coord
    YCOORDN db 0x00 ;       Sign bit (positive/negative) of Y Coord
    XFLOW   db 0x00 ;       Overflow bit (Movement too fast) of X Coord
    YFLOW   db 0x00 ;       Overflow bit (Movement too fast) of Y Coord
    
    ;************************************
    ;* Some var's of my display function
    ;************************************
    deel    dw 0x0000
    varbuff dw 0x0000
    zerow   db 0x00
    strlbt  db "Left button:   ", 0x00
    strrbt  db "Right button:  ", 0x00
    strmbt  db "Middle button: ", 0x00
    strcdx  db "Mouse moved (X): ", 0x00
    strcdy  db "Mouse moved (Y): ", 0x00
    stretr  db 0x0D, 0x0A, 0x00
    strneg  db "-", 0x00
    strsp   db " ", 0x00
    row     db 0x00
    col     db 0x00
    

    so...vielleicht hilft euch das weiter...oder mir.



  • Ok, also so wie der Code jetzt ist, kannst du den natuerlich nicht verwenden. Mal abgesehen davon, dass der nur PS/2-Maeuse unterstuetzt, taugt der wirklich nur als Anschauungsmaterial. Aber das war dir hoffentlich sowieso schon klar. 😃
    Da muesste zB. noch ein IRQ-Handler installiert werden etc.

    Aber das war deinem ersten Post zufolge IMHO eh nicht das Thema, sondern das Zeichnen des Mousecursors in einem VESA-GrafikModus im RM - und wie du hier BitMaps/Pixelreihen auf den Bildschirm bringst, solltest du irgendwie inzwischen begriffen haben... 😕
    Ansonsten bezieht sich "[Morpheus]"s Thread momentan genau auf dieses Thema.

    Whatever: Wenn du nur auf der Suche nach fertigem Code fuer ein MouseTreiberSystem mit verschiedenen Grafikcursors fuer hochaufloesende Grafikmodi etc. bist, muss ich dich leider enttaeuschen: Wirst du hier hoechstwahrscheinlich nicht finden... ...Solange du nicht bereit bist, was dafuer springen zu lassen. 🤡


Anmelden zum Antworten