masm32的midi模拟发音源码

发布时间:2011年3月4日 作者:未知 查看次数:1607

masm32的midi模拟发音源码


midi模拟发音

.386
.model flat,stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib

 

.data
ClassName db "SimpleWinClass",0
AppName  db "SimpleVirtualPiano",0
szText   db 'This is a Simple VirtualPiano----------->made bu liuwei  2003.11.19',0h

.data?
hInstance HINSTANCE ?
hdc HDC ?
midiFlag BYTE ?
midiPu DWORD ?
midiYu DWORD ?
midiPlayFlag BYTE ?


.code
start:
 invoke GetModuleHandle, NULL
 mov    hInstance,eax
 invoke WinMain, hInstance,NULL,NULL,SW_SHOWDEFAULT
 invoke ExitProcess,eax     

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
 LOCAL wc:WNDCLASSEX
 LOCAL msg:MSG
 LOCAL hwnd:HWND
 mov   wc.cbSize,SIZEOF WNDCLASSEX
 mov   wc.style, CS_HREDRAW or CS_VREDRAW
 mov   wc.lpfnWndProc, OFFSET WndProc
 mov   wc.cbClsExtra,NULL
 mov   wc.cbWndExtra,NULL
 push  hInst
 pop   wc.hInstance
 mov   wc.hbrBackground,COLOR_WINDOW+1
 mov   wc.lpszMenuName,NULL
 mov   wc.lpszClassName,OFFSET ClassName
 invoke LoadIcon,NULL,IDI_APPLICATION
 mov   wc.hIcon,eax
 mov   wc.hIconSm,eax
 invoke LoadCursor,NULL,IDC_ARROW
 mov   wc.hCursor,eax
 invoke RegisterClassEx, addr wc
 INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
 mov   hwnd,eax
 INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
 INVOKE UpdateWindow, hwnd
      invoke midiOutOpen,ADDR hdc,-1,NULL,NULL,NULL
      mov   midiYu,0h
      mov   midiPlayFlag,1h
 .WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
 .ENDW
 mov     eax,msg.wParam
 ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
  local  @stPs:PAINTSTRUCT
  local  @stRect:RECT
  local  @hDc 
            local   @playf:WORD

 .IF uMsg==WM_DESTROY
                  invoke midiOutClose,hdc
      invoke PostQuitMessage,NULL
                   
      .ELSEIF uMsg ==WM_PAINT
   invoke BeginPaint,hWnd,addr @stPs
   mov       @hDc,eax
   invoke GetClientRect,hWnd,addr @stRect
   invoke DrawText,@hDc,addr szText,-1,\
    addr @stRect,\
    DT_SINGLELINE or DT_CENTER or DT_VCENTER
   invoke EndPaint,hWnd,addr @stPs
      .ELSEIF uMsg==WM_CHAR
      mov @playf,0h
      push wParam
      pop midiPu
;===============ESC键的功能================
          .if midiPu==WM_DEVMODECHANGE                   ;1bh
           invoke midiOutClose,hdc
     invoke PostQuitMessage,NULL
          .ENDIF
;----------------------------------------


        .if midiPu==61h
        mov midiYu,-24
        .elseif midiPu==62h
        mov midiYu,-12
        .elseif midiPu==63h
        mov midiYu,0
        .elseif midiPu==64h
        mov midiYu,12
        .elseif midiPu==65h
        mov midiYu,24
     
        ;===============全音============================
        .elseif midiPu==31h
        mov midiPu,3ch
        mov @playf,1
        .elseif midiPu==32h
        mov midiPu,3eh
        mov @playf,1
        .elseif midiPu==33h
        mov midiPu,40h
        mov @playf,1
        .elseif midiPu==34h
        mov midiPu,41h
        mov @playf,1
        .elseif midiPu==35h
        mov midiPu,43h
        mov @playf,1
        .elseif midiPu==36h
        mov midiPu,45h
        mov @playf,1
        .elseif midiPu==37h
        mov midiPu,47h
        mov @playf,1
        ;================半音===========================
         .elseif  midiPu==71h
         mov midiPu,3dh
         mov @playf,1
         .elseif  midiPu==77h
         mov midiPu,3fh
         mov @playf,1
         .elseif  midiPu==72h
         mov midiPu,42h
         mov @playf,1
         .elseif  midiPu==74h
         mov midiPu,44h
         mov @playf,1
         .elseif  midiPu==79h
         mov midiPu,46h
         mov @playf,1
         .endif
        ;-------------------------------------------
          .if @playf==1
            mov eax,midiYu
            add midiPu,eax
            mov cl,8
            shl midiPu,cl
            and midiPu,0ff00h
            add midiPu,680090h
           .if midiPlayFlag==1h
            ;================调用声卡的代码======================     
       
            invoke midiOutShortMsg,hdc,midiPu
            mov  midiPlayFlag,0h
            ;-------------------声卡代码结束------------------------
            .endif
            .endif
 .ELSEIF uMsg==WM_KEYUP
           mov midiPlayFlag,1h
 .ELSE
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  ret
 .ENDIF
 xor    eax,eax
 ret
WndProc endp
end start



版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110