Constant Buttons
  None  = 0x0
  Down  = 0x1
  Up    = 0x2
  Right = 0x4
  Left  = 0x8
  A     = 0x10
  B     = 0x20
  X     = 0x40
  Y     = 0x80
End Constant

Constant ButtonIndex
  Down  = 0x1
  Up    = 0x2
  Right = 0x3
  Left  = 0x4
  A     = 0x5
  B     = 0x6
  X     = 0x7
  Y     = 0x8
End Constant

Procedure TestInput(state, button)
  Return (state And button) <> 0
End Input

Procedure WaitForOKOrCancel()
  Dim result = False
  Do
    Sleep(0)
    Dim curr = GetInputState()
    Dim diff = (GetPreviousInputState() Xor curr) And curr
    If TestInput(diff, Buttons.A) Then
      result = True
      Exit Do
    ElseIf TestInput(diff, Buttons.B) Then
      result = False
      Exit Do
    End If
  Loop
  Sleep(0)
  Return result
End Procedure
