proc Startup; (Flags.l)
  cmp byte [HasPreCalced], 0
  jne NoPreCalculation
  call PreCalcCode

NoPreCalculation:
  XOR eax, eax
  MOV ecx, [esp + 4]
  TEST ecx, $1000000
  JNZ StartThreaded
  TEST ecx, $f000000
  JZ StartClassic
;  ProcedureReturn
  RET 4

StartClassic:
;      If waveInOpen_(?hWaveIn, -1, ?WvFmtEx, 0, 0, 0) = 0
;        ProcedureReturn 1
;        EndIf
  PUSH eax
  PUSH eax
  PUSH eax
  PUSH WvFmtEx
  PUSH dword -1
  PUSH hWaveIn
  CALL dword [waveInOpen]
  OR eax, eax
  JNZ InitFail
  JMP InitSuccess


StartThreaded:
;      If waveInOpen_(?hWaveIn, -1, ?WvFmtEx, 0, 0, 0) = 0
  PUSH eax
  PUSH eax
  PUSH eax
  PUSH WvFmtEx
  PUSH dword -1
  PUSH hWaveIn
  CALL dword [waveInOpen]
  OR eax, eax
  JNZ InitFail

;        InitializeCriticalSection_(?CritSection)
  PUSH dword CritSection
  CALL dword [kInitializeCriticalSection]
;        PokeL(?hThread, CreateThread_(0, 0, @GrabThread(), 1, 0, ?ThreadID))
  XOR eax, eax
  PUSH dword ThreadID
  PUSH eax
  PUSH dword 1
  PUSH dword GrabThread
  PUSH eax
  PUSH eax
  CALL dword [kCreateThread]
  MOV [hThread], eax
;        If PeekL(?hThread)
;          ProcedureReturn 1
;          EndIf
  OR eax, eax
  JNZ InitSuccess
;        waveInClose_(PeekL(?hWaveIn))
  PUSH dword [hWaveIn]
  CALL dword [waveInClose]
;        EndIf

  InitFail:
  XOR eax, eax
;  ProcedureReturn
  RET 4
  
  InitSuccess:
  MOV eax, dword 1
;  ProcedureReturn
  RET 4
endp