format PE console on 'microwav.bin'
entry start
include '..\..\common\fasmw\win32a.inc' ; x for invoke createfilea...

section '.code' import data code readable writeable executable
  library kernel, 'KERNEL32.DLL',\
    winmm,'WINMM.DLL'

  import kernel,\
	 kExitProcess,'ExitProcess',\
	 kGetCommandLineW,'GetCommandLineW',\
	 kGetVersion,'GetVersion',\
	 kWideCharToMultiByte,'WideCharToMultiByte',\
	 klstrlenW,'lstrlenW'

  import winmm,\
	 mPlaySoundA,'PlaySoundA',\
	 mPlaySoundW,'PlaySoundW'


start:
  push ebx
  call dword [kGetCommandLineW]
  or eax, eax
  jz EndIt

  mov cx, [eax]
  cmp cx, 34
  jne NoQuote
  inc eax
  inc eax
  call FindIt
;  dec eax
;  dec eax

NoQuote:
  mov cx, 32
  call FindIt
  mov ebx, eax

  mov cx, [eax]
  cmp cx, 34
  jne NoQuote2
  inc eax
  inc eax
  mov ebx, eax
  call FindIt
  dec eax
  dec eax
  mov [eax], word 0
NoQuote2:
;  mov cx, 32
;  call FindIt






  call [kGetVersion]
  and eax, $800000ff
  cmp eax, $80000004
  jnz NTMode

  push ebx
  call [klstrlenW]
  or eax, eax
  jz EndIt
  cmp eax, $200
  ja EndItZ

  sub esp, $104
  mov ecx, esp
  mov [esp + eax], byte 0

  xor edx, edx
  push edx
  push edx
  push dword $102
  push ecx
  push eax
  push ebx
  push edx
  push edx
  call [kWideCharToMultiByte]
  or eax, eax
  jz EndItA

  mov ecx, esp
  push dword $20000
  push dword 0
  push ecx
  call [mPlaySoundA]
  add esp, $104
  jmp PostPlayOut

EndItA:
  add esp, $104
  jmp EndIt

NTMode:
  push dword $20000
  push dword 0
  push ebx
  call [mPlaySoundW]

PostPlayOut:
  or eax, eax
  jz EndIt
  mov eax, 1
  jmp EndIt

EndItZ:
  xor eax, eax
EndIt:
  push eax
  call dword [kExitProcess]
  pop ebx
  ret $c

proc FindIt
FindLoop:
  mov dx, [eax]
  or dx, dx
  jz FailFind
  inc eax
  inc eax
  cmp dx, cx
  jne FindLoop
  ret

FailFind:
  add esp, 4
  jmp EndIt
endp