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 EndIt

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

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

  mov ecx, esp
  push dword $20000
  push dword 0
  push ecx
  call [mPlaySoundA]

  EndItA:
  add esp, $104
  jmp EndIt

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

  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