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

📄 改的mouse.asm

📁 一个用C语言编写的汇编程序.可实现用鼠标控制进行游戏.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;----auther 307
.model small
.386
.stack
.data
;------------------ mouse position
new_curso_x dw  0   ;-----添加的四个变量,主要用来获取光标位置
new_curso_y dw  0
old_curso_x dw  0     
old_curso_y dw  0

pos_x dw  40     ;current x position
pos_y dw  10
old_x dw  40     ;old x position
old_y dw  10

max_x dw 79    ; max width 
max_y dw 24    ;  max higt 

ms_inf1 db 'You mouse is 2d mouse!',0dh,0ah,'$'
ms_inf2 db 'You mouse is 3d mouse!',0dh,0ah,'$'
ms_inf3 db 'You mouse has been installed',0dh,0ah,'$'

old_high dw 0h   ; old intrrupt 
old_low  dw 0h

P_add dw 0b800h    ;video buffer segment adrress
pointer dw 0h      ;video buffer offset address

re_code db 0h      ;returned code from the mouse
re_number dw 0h    ;returned code number from the mouse

show_high db 0h    ;converted high part of re_code in ASIC code
show_low  db 0h    ;converted low part of re_code in ASIC code

mouse_cmd db 0h    ; the command set to mouse
reply_cmd_number dw 0h ; the expect number of mouse's reply

ini_state db 1h    ; inital state flag

ms_data_full db    0h   ;flag of if the mouse data vailde
mouse_type  dw '2d'  ; show the mouse type,default is 2d mouse
mouse_d_len dw 3h  ; the length of mouse movement data,defaut is 2d mouse 
mouse_data  db 0,0,0,0  ; the buffer of the mouse movement data 

.code
;--------- main program is use to inital mouse and wait for key,if f1 pressed  clear the screen
;---------- if f9 pressed then exit program         

main         proc far                   ; call for inital the mouse
             call ini_mouse
             sti

wait2:       mov ah,0h        
             int 16h

             cmp ah,43h            ;wait for f9 to exit
             jz restore
             cmp ah,3bh            ;wait for f1 to clear screen
             jnz wait2
             call clr_scr
             jmp wait2
     ;-------- restore mouse int_arrower
restore:
             push ds
             mov ax,old_high
             mov ds,ax
             mov dx,old_low
             mov ah,25h
             mov al,74h
             int 21h
             pop ds

             mov ax,4c00h
             int 21h
main endp


sheji 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;---设置循环次数
lop1:
 
           mov ah,08h;---取得光标位置的字符属性
           mov bh,00
           int 10h
           cmp al,01h;比较是否是01(笑脸),如果是跳出循环(从而实现一次打一个爱心)
           jz outtt
;mov cx ,0ffffh
;lop3: 
;nop


         

            call hua;---调用子程序“画”,实现在不是目标(爱心)的位置上画子弹;而在是目标的位置上画子弹(黑桃)
    
loop lop1  ;---循环指令

            outtt:

            ret
sheji endp






hua proc near;----子弹子程序

            push cx;--保存循环次数

;lop7:
;mov ah,2ch
;int 21h
;cmp dl,22
;jnz lop7

qugbwz1:            ;---取得当前光标位置
           mov ah,03h
           mov bh,00
           int  10h 

           push dx
           xchg dh,dl
           mov dh,0 

           cmp dx,0   ;---判断是不是0行,如果是说明子弹已经到达屏幕顶端
           jz outt    ;---如果是跳出子弹子程序

segbwz1:   pop dx ;----设置光标位置
           dec dh  ;使光标位置减1
            mov ah,02h
           mov bh,00
           int 10h            

panduan1:        ;---判断当前光标位置的字符是不是目标(爱心)
            mov ah,08h
            mov bh,00
           int 10h
           cmp al,3h;--比较是不是目标(爱心)

jnz gun1;---如果不是跳到gun1

call misplay1  ;---chu qu mu biao 除去当前光标位置的字符(不管是子弹还是目标)
qugbwz2:;---取得当前光标位置
           mov ah,03h
           mov bh,00
           int  10h  
segbwz2:;----设置光标位置
            inc dh   ;使光标位置减1
            mov ah,02h
           mov bh,00
           int 10h 
call misplay;---------chu qu gb   
          jmp  gun2          

gun1:       
           call display;除去当前光标位置的字符(不管是子弹还是目标)
           mov ah,03h
           mov bh,00
           int  10h 

           inc dh  
           mov ah,02h
           mov bh,00
           int 10h 
           call misplay;除去当前光标位置的字符(不管是子弹还是目标)
jmp gun3
           

gun2:                  ;---------she zhi gbwz wei mu biao wei zhi,yi bian xia ci pan duan
         
         jmp qugbwz3
gun3:
         
qugbwz3:;---取得当前光标位置
           mov ah,03h
           mov bh,00
           int  10h  
segbwz3:;----设置光标位置
           dec dh   ;使光标位置减1
           mov ah,02h
           mov bh,00
           int 10h 
outt: 
pop cx


            ret
  hua endp

display proc near ;画子弹的子程序

         mov ah,09h
         mov al,06h;---06 zhao jia 
         mov bh,0
         mov bl,50H;---07   
         mov cx,1         
         int 10h 
         ret

display endp


misplay proc near ;擦去子弹的子程序

         mov ah,09h
         mov al,20h
         mov bh,0
         mov bl,07H   
         mov cx,1         
         int 10h 
         ret

misplay endp

misplay1 proc near ;擦去目标的子程序(因为要在目标(爱心)原来的位置设置特定标志,以便后面程序好判断此点原来是不是爱心)

         mov ah,09h
         mov al,01h;---biao zhi作为以后用的标志(笑脸01)
         mov bh,0
         mov bl,00H   
         mov cx,1         
         int 10h 
         ret

misplay1 endp

gbwz proc near ;设置光标的子程序,使光标位置与鼠标位置一致
    mov ah,2
    mov dh,byte ptr new_curso_y
    mov dl,byte ptr new_curso_x
    int 10h
    ret 
gbwz endp


;---------------- draw the mouse in the screen
draw proc near
;-----------just if mouse had moved
     lea bx,mouse_data

     mov al,[bx]  
     test al,2h;---判断是不是右键被按下
     jz  tiao;---如果是调用sha子程序,一下子发射三个子弹
     call   sha

     jmp tiao1

tiao:    

     test  al,1h;---判断是不是左键被按下
     jz  tiao1;---如果是调用sheji子程序,一下子发射1个子弹
     call   sheji
tiao1:        
     mov al,[bx+1]         ;get x movement of mouse
     cmp al,0
     jnz just_x
     mov al,[bx+2]         ;get y movement of mouse
     cmp al,0
     jnz just_x        ; if there is no movement then exit 
     ret
;-------------  mouse had moved ,then get the new position

just_x:                              ; test x result
          movsx cx,byte ptr [bx+1]    ; add the old x with variable x
          mov ax,pos_x
          add ax,cx
neg_x_test:
          jns ovr_x_test             ;just if x result <0
          mov pos_x,0               ; if x result <0 ,then x result=0
          jmp just_y               ; goto test y result

ovr_x_test:
          cmp ax,max_x
          js set_x                 ;just if y result>79
          mov pos_x,79              ; if x result>79, then x result=79
          jmp just_y

set_x:    mov pos_x,ax             ;the x result between 0 and 79, it is ok
just_y:                            ; test y result
          mov pos_y,24
           ;---------------------   test if the old pos is same to old pos
just_move:
            mov ax,pos_x       ; just if old_x is same to new_x
            cmp ax,old_x       
            jnz pos_move       ;if they are differ , then show mouse

            mov ax,pos_y       ; just if old_y is same to new_y
            cmp ax,old_y
            jnz pos_move       ;if they are differ , then show mouse
            ret                ; pos is same  return the program

pos_move:
            call draw_mouse
            mov ax,pos_x         ; store the x and y position
            mov old_x,ax
            mov ax,pos_y
            mov old_y,ax
            ret
draw endp





;--------------------- draw mouse on screen
  draw_mouse proc near
             mov ax,P_add     ;set es to video buffer
             mov es,ax

⌨️ 快捷键说明

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