home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / tsm.zip / Replay / Test_TSMReplay.asm < prev    next >
Assembly Source File  |  2004-10-05  |  6KB  |  194 lines

  1. ; ------------------------------------------
  2. ; Test for TRSI Sound Monitor replay routine
  3. ; Written by Franck 'hitchhikr' Charlet/TRSI
  4. ;
  5. ; MASM32 required.
  6. ; ------------------------------------------
  7. ; buildblock RELEASE
  8. ;     CAPT [BINDIR]\ml.exe /c /coff /I"[INCLUDEDIR]" "%2"
  9. ;     CAPT [BINDIR]\Link.exe /MERGE:.data=.text /LIBPATH:"[LIBDIR]" /MERGE:.rdata=.text /SECTION:.text,ERW /IGNORE:4078 /SUBSYSTEM:WINDOWS "%1.obj" "TSMReplay.obj"
  10. ; buildblockend
  11. ; buildblock DEBUG
  12. ;     CAPT [BINDIR]\ml.exe /Zd /Zi /c /coff /I"[INCLUDEDIR]" "%2"
  13. ;    CAPT [BINDIR]\Link.exe /DEBUG /DEBUGTYPE:CV /INCREMENTAL:NO /LIBPATH:"[LIBDIR]" /MERGE:.data=.text /MERGE:.rdata=.text /SECTION:.text,ERW /IGNORE:4078 /SUBSYSTEM:WINDOWS "%1.obj" "TSMReplay.obj"
  14. ; buildblockend
  15.  
  16. ; --------------- File model
  17.                 .386
  18.                 .model    flat,stdcall
  19.                 option    casemap:none
  20.  
  21. ; --------------- Includes
  22.                 include    windows.inc
  23.                  include kernel32.inc
  24.                  include user32.inc
  25.                 include dsound.inc
  26.                  include DSoundConst.inc
  27.  
  28. ; --------------- Libraries
  29.                 includelib kernel32.lib
  30.                 includelib user32.lib
  31.                 includelib dsound.lib
  32.  
  33.  
  34. ; --------------- External functions
  35. TSM_Init            PROTO    :DWORD,:HWND,:DWORD
  36. TSM_Stop            PROTO
  37. TSM_Play            PROTO
  38.  
  39. ; --------------- Datas section
  40.                 .data
  41.  
  42. Window_Name            db    "TRSI Sound Monitor replay routine.",0
  43. Window_Class_Name        db    "TSMReplay_Class",0
  44. hWnd                dd    0
  45. Module_Mem            dd    0
  46. Read_Bytes            dd    0
  47. Thread_Id            dd    0
  48. hReplay_Thread            dd    0
  49.  
  50. ; ***** Change this *****
  51. Module_Name            db    "..\Songs\wizardry.TSM",0
  52.  
  53. ; --------------- Code section
  54.                 .code
  55.  
  56. ; --------------- Handle song messages
  57. CallBack_Routine        proc    Datas:dword
  58.  
  59.                 ret
  60. CallBack_Routine        endp
  61.  
  62. ; --------------- Audio rendering
  63. Synth_Thread            proc    lpParameter:dword
  64. Synth_Loop:            invoke    TSM_Play
  65.                 invoke    Sleep,1
  66.                 jmp    Synth_Loop
  67. Synth_Thread            endp
  68.  
  69. ; --------------- Handle window messages
  70. Main_Loop            proc    hWin:dword,uMsg:dword,wParam:dword,lParam:dword
  71.                 .if uMsg == WM_DESTROY
  72.                     .if hReplay_Thread != 0
  73.                         invoke    TerminateThread, hReplay_Thread, 0
  74.                         invoke    CloseHandle, hReplay_Thread
  75.                     .endif
  76.                     invoke    TSM_Stop
  77.                     invoke    GlobalFree,Module_Mem
  78.                     invoke    PostQuitMessage,0
  79.                     xor    eax,eax
  80.                     ret
  81.                 .endif
  82.                 invoke    DefWindowProc,hWin,uMsg,wParam,lParam
  83.                 ret
  84. Main_Loop            endp
  85.  
  86. ; --- Open a file and load it into a memory block
  87. ; Returns the allocated memory block or 0
  88. ; (Free memory block with GlobalFree)
  89. Load_File            proc    FName:dword,File_Read_Bytes:dword
  90.                 local    FHandle:dword
  91.                 local    FSize:dword
  92.                 local    FPosition:dword
  93.  
  94.                 mov    FPosition,0
  95.                 invoke    CreateFile,FName,GENERIC_READ,0,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0
  96.                 inc    eax
  97.                 je    Error_OpenFile
  98.                 dec    eax
  99.                 mov    FHandle,eax
  100.                 invoke    GetFileSize,eax,0
  101.                 inc    eax
  102.                 je    Error_ReadFile
  103.                 dec    eax
  104.                 mov    FSize,eax
  105.                 inc    eax                ; Append a 0 char
  106.                 invoke    GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,eax
  107.                 test    eax,eax
  108.                 jz    Error_ReadFile
  109.                 mov    FPosition,eax
  110.                 invoke    ReadFile,FHandle,FPosition,FSize,File_Read_Bytes,0
  111. Error_ReadFile:            invoke    CloseHandle,FHandle
  112. Error_OpenFile:            mov    eax,FPosition            ; Return the memory block address
  113.                 ret
  114. Load_File            endp
  115.  
  116. ; --------------- Display main window
  117. DisplayWindow            proc    hInst:dword
  118.                 local    wc:WNDCLASSEX
  119.                     mov    wc.cbSize,sizeof WNDCLASSEX
  120.                 mov    wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
  121.                 mov    wc.lpfnWndProc,offset Main_Loop
  122.                 xor    eax,eax
  123.                 mov    wc.cbClsExtra,eax
  124.                 mov    wc.cbWndExtra,eax
  125.                 push    hInst
  126.                 pop    wc.hInstance
  127.                 mov    wc.hbrBackground,COLOR_BTNFACE+1
  128.                 mov    wc.lpszMenuName,eax
  129.                 mov    wc.lpszClassName,offset Window_Class_Name
  130.                 mov    wc.hIcon,eax
  131.                 mov    wc.hIconSm,eax
  132.                 invoke    LoadCursor,eax,IDC_ARROW
  133.                 mov    wc.hCursor,eax
  134.                 invoke    RegisterClassEx,addr wc
  135.                     invoke    CreateWindowEx,0,addr Window_Class_Name,addr Window_Name,WS_BORDER or WS_CAPTION or WS_SYSMENU,100,100,400,100,0,0,hInst,0
  136.                 mov    hWnd,eax
  137.                 invoke    ShowWindow,hWnd,SW_SHOWNORMAL
  138.                 invoke    UpdateWindow,hWnd
  139.                 mov    eax,hWnd
  140.                 ret
  141. DisplayWindow            endp
  142.  
  143. ; --------------- Process window messages
  144. DoEvents            proc
  145.                 local    msg:MSG
  146. StartLoop:            invoke    GetMessage,addr msg, 0, 0, 0
  147.                 test    eax,eax
  148.                 jz    ExitLoop
  149.                 invoke    DispatchMessage,addr msg
  150.                 jmp    StartLoop
  151. ExitLoop:            mov    eax,msg.wParam
  152.                 ret
  153. DoEvents            endp
  154.  
  155. ; -----------------
  156. ; --- WinMain() ---
  157. ; -----------------
  158. WinMain                proc    hInstance:dword,hPrevInstance:dword,lpCmdLine:dword,nCmdShow:dword
  159.                 ; Load the file into memory
  160.                 invoke    Load_File,addr Module_Name,addr Read_Bytes
  161.                 mov    Module_Mem,eax
  162.                 test    eax,eax
  163.                 jz    Err_LoadModule
  164.                 invoke    DisplayWindow,hInstance
  165.                 test    eax,eax
  166.                 jz    Err_InitModule
  167.                 ;CallBack_Routine can be NULL
  168.                 invoke    TSM_Init,Module_Mem,eax,addr CallBack_Routine
  169.                 test    eax,eax
  170.                 jz    Err_InitModule
  171.                 invoke    CreateThread,0, 0, addr Synth_Thread, 0, 0, addr Thread_Id
  172.                 mov    hReplay_Thread,eax
  173.                 test    eax,eax
  174.                 jz    Err_InitModule
  175.                 invoke    DoEvents
  176.                 ret
  177. Err_InitModule:            invoke    GlobalFree,Module_Mem
  178.                 invoke    TSM_Stop
  179. Err_LoadModule:            xor    eax,eax
  180.                 ret
  181. WinMain                endp
  182.  
  183. ; ---------------------
  184. ; --- Program start ---
  185. ; ---------------------
  186. start:                invoke    GetModuleHandle,NULL
  187.                 push    eax
  188.                 invoke    GetCommandLine
  189.                 pop    ebx
  190.                 invoke    WinMain,ebx,0,eax,SW_SHOWDEFAULT
  191.                 invoke    ExitProcess,eax
  192.  
  193. end start
  194.