⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 改的mouse.asm

📁 一个用C语言编写的汇编程序.可实现用鼠标控制进行游戏.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
       ;--------------- erase the old position
       
             mov ax,old_y
             mov cx,160
             mul cx
             mov bx,old_x
             shl bx,1
             add bx,ax        ;get the pointer
             mov [bx],20h    ;erase old point
             mov [bx+1],07h  ;set back groud to black white

       ;-------------- draw the new position
             mov ax,pos_y
             mov cx,160
             mul cx
             mov bx,pos_x
             shl bx,1
             add bx,ax        ;get the pointer
             mov byte ptr es:[bx],20h   ;draw new pointer
             mov byte ptr es:[bx+1],00011110b

             ret
  draw_mouse endp

mouse proc near
          push ax
          push bx
          push cx
          push dx
          push ds
          push es
          push di
          push si

;--------------------- set data segment
          mov ax,@data
          mov ds,ax

;----------------------- read from the mouse and save as re_code
                        ;then show re_code
          in al,60h
          mov re_code,al
;          call show    ; show return code of mouse to debug program
          inc re_number
          cmp ini_state,01h  ;if it is inital state then returen,else
                             ;move data to mouse_data buffer
          jz cont2
          call move_data

;----------------------- if mouse is in work state, then move data to mouse
;----------------------- data buffer



;------------------------- enbale  the mouse hardware intrrupte
cont2:
          mov al,20h
          out 20h,al
          out 0a0h,al

          pop si
          pop di
          pop es
          pop ds
          pop dx
          pop cx
          pop bx
          pop ax
          iret
mouse endp

;----------display ever time mouse int and show the reture code from mouse






ask_mouse proc near
          mov al,0d4h        ;require to  send command to mouse
          out 60h,al         ;send the  command in al register
          sti                ;enable the hardware intrrupte

   ;---------------- wait for the mouse reply
wait1:    wait
          mov ax,re_number
          cmp ax, reply_cmd_number
          jnz wait1
         
          ret
ask_mouse  endp

;------------------  use to clear the screen
clr_scr proc near
        mov ax,P_add
        mov es,ax
        mov bx,0
        mov cx,400h    ;

loop1:  mov byte ptr es:[bx],20h;----实现清屏功能
        inc bx
        inc bx
        loop loop1


        mov bx,60
        mov cx,20 
loop2:  mov byte ptr es:[bx],3h;---在屏幕上画爱心(第一行)
        inc bx
        mov byte ptr es:[bx],25h
        inc bx
        loop loop2

        mov bx,220
        mov cx,20 
loop3:  mov byte ptr es:[bx],3h;---在屏幕上画爱心(第2行)
        inc bx
        mov byte ptr es:[bx],25h
        inc bx
        loop loop3

        mov bx,380
        mov cx,20 
loop4:  mov byte ptr es:[bx],3h;---在屏幕上画爱心(第3行)
        inc bx
        mov byte ptr es:[bx],25h
        inc bx
        loop loop4


        ret
clr_scr endp

;--------------------- mov the receive data to the mouse data buffer

move_data proc near

          lea bx,mouse_data   ; set the bx to the right mouse_data
          mov cx,re_number
          dec cx
          add bx,cx

          mov al,re_code      ;move the data from re_code to mouse_data
          mov [bx],al

          mov ax,re_number    ;just if the receive data is the last data
          cmp ax,mouse_d_len
          jnz cont3

          ;----  data in mouse_data is full must modi
          
          mov re_number,0h    ; receive data clear
          mov ms_data_full,1h
          call draw


          
cont3:
          ret



move_data endp

;-------- inital the mouse
ini_mouse proc near
             mov ax,@data
             mov ds,ax               ;set the display model
             mov al,03h
             mov ah,0h
             int 10h

             cli

;------------ get the old mouse inttrupt and save
             mov ah,35h
             mov al,74h
             int 21h
             mov old_low,bx
             mov old_high,es

;------------ enable mouse_int
            
            mov ax,seg mouse_int
            mov ds, ax
            mov dx,offset mouse_int
            mov al,74h
            mov ah,25h
            int 21h

;------------------------ reset mouse
          mov ax,@data         ; get the ds register
          mov ds,ax
          mov mouse_cmd,0ffh
          mov reply_cmd_number,03h
          call ask_mouse

;------------------------   set the mouse to sample rate 200

          mov mouse_cmd,0f3h          ; ask to set rate
          mov reply_cmd_number,01h
          call ask_mouse

          mov mouse_cmd,0c8h         ;rate data of 200
          mov reply_cmd_number,01h
          call ask_mouse

;------------------------   set the mouse to 100

          mov mouse_cmd,0f3h          ; ask to set rate
          mov reply_cmd_number,01h
          call ask_mouse

          mov mouse_cmd,64h         ;rate data of 100
          mov reply_cmd_number,01h
          call ask_mouse

;------------------------   set the mouse to 80

          mov mouse_cmd,0f3h          ; ask to set rate
          mov reply_cmd_number,01h
          call ask_mouse

          mov mouse_cmd,50h         ;rate data of 80
          mov reply_cmd_number,01h
          call ask_mouse

;-------------------------- get the mouse type 2d or 3d
          mov mouse_cmd,0f2h          ; ask mouse to tell mouse type
          mov reply_cmd_number,02h
          call ask_mouse

;------------------------- tell the user the mouse type 3d/2d,and set data
          mov byte ptr es:[0],0h  ;disable application of mouse

          cmp re_code,03h         ;just if mouse is 3d or 2d
          jnz mouse_2d
mouse_3d:
          mov mouse_type,'3d'     ;set the mouse tyep to 3d
          mov mouse_d_len,04h     ;set the mouse data length to 4.(3d mouse)
          lea dx,ms_inf2
          jmp cont1
mouse_2d:
          mov mouse_type,'2d'     ;set the mouse tyep to 3d
          mov mouse_d_len,03h     ;set the mouse data length to 4.(3d mouse)

          lea dx,ms_inf1

cont1:
          mov ah,9                ;show the mouse type on screen
          int 21h
;-------------------------- set reslution to 8 counts/mm

          mov mouse_cmd,0e8h          ; requre to set reslution
          mov reply_cmd_number,01h
          call ask_mouse

          mov mouse_cmd,03h          ;  set reslution data 
          mov reply_cmd_number,01h
          call ask_mouse

;-------------------------- set scal to 1:1
          mov mouse_cmd,0e6h          ; requre to set scal
          mov reply_cmd_number,01h
          call ask_mouse

;------------------------   set the mouse to sample rate 40

          mov mouse_cmd,0f3h          ; ask to set rate
          mov reply_cmd_number,01h
          call ask_mouse

          mov mouse_cmd,28h         ;rate data of 40
          mov reply_cmd_number,01h
          call ask_mouse

;-------------------------- enable mouse device
          mov mouse_cmd,0f4h          ; requre enable mouse
          mov reply_cmd_number,01h
          call ask_mouse


;----------------------------------- end inital state
          mov ini_state,0h
          lea dx,ms_inf3           ; tell user mouse driver installed
          mov ah,09h
          int 21h
;---------------------------------- set the curso to the end
          mov dh,24
          mov dl,79
          mov bh,0
          mov ah,2
          int 10h
          ret
ini_mouse endp

sha proc near;----鼠标右键发射的子程序,与左键差不多

    mov ah,2
    mov dh,byte ptr pos_y
    mov dl,byte ptr pos_x
    int 10h

   
    mov ax,pos_y
    sub ax,1
    mov new_curso_y,ax
    mov ax,pos_x
    mov new_curso_x,ax

   ;gbwz  new_curso_y, new_curso_x
    call gbwz  

    call display 


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

    mov cx,23
    lop2:
 
    call hua
    
    loop lop2



     ret
sha endp

prg_length equ $-main
end  main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -