Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rem BasicCard Sample Source Code
- Rem ------------------------------------------------------------------
- Rem Copyright (C) 1997-1999 ZeitControl GmbH
- Rem You have a royalty-free right to use, modify, reproduce and
- Rem distribute the Sample Application Files (and/or any modified
- Rem version) in any way you find useful, provided that you agree
- Rem that ZeitControl GmbH has no warranty, obligations or liability
- Rem for any Sample Application Files.
- Rem ------------------------------------------------------------------
- #Include CALCKEYS.BAS
- Declare ApplicationID = "BasicCard Mini-Calculator"
- Rem This BasicCard program contains recursive procedure calls, so the
- Rem compiler will allocate all available RAM to the P-Code stack unless
- Rem otherwise advised. This slows execution, because all strings have to
- Rem be allocated from EEPROM. So we specify a stack size here:
- #Stack 120
- ' Calculator Command (CLA = &H20, INS = &H01)
- '
- ' Input: an ASCII expression involving integers, and these operators:
- '
- ' * / % + - & ^ |
- '
- ' (Parentheses are also allowed.)
- '
- ' Output: the value of the expression, in ASCII.
- '
- ' P1 = 0: all numbers are decimal
- ' P1 <> 0: all numbers are hex
- ' Constants
- Const SyntaxError = &H81
- Const ParenthesisMismatch = &H82
- Const InvalidNumber = &H83
- Const BadOperator = &H84
- Rem <---------ZMIENNE DO LOGOWANIA--------->
- Const U1$ = "user1"
- Const U2$ = "user2"
- Const Admin$ = "admin"
- Eeprom U1Pasw$ As String = "1244"
- Eeprom U2Pasw$ As String = "1234"
- Eeprom AdminPasw$ As String = "1234"
- Public CzyAdmin As Byte = 0
- Public Zalogowany As Byte = 0
- ' Forward references
- Declare Function EvaluateExpression (S$, Precedence) As Long
- Declare Function EvaluateTerm (S$) As Long
- Declare Sub Error (Code@)
- Declare Command &H21 &H02 Login (UserName$ As String*64, Password$ As String)
- Rem Declare Command &H22 &H03 Password (UserName$ As String*64, Password$ As String)
- Rem Declare Command &H23 &H04 Logout()
- Command &H21 &H02 Login(Username$ As String *64, Password$ As String)
- CzyAdmin = 0
- Zalogowany = 0
- If (Username$ = Admin$) And (Password$ = AdminPasw$) Then
- CzyAdmin = 1
- Zalogowany = 1
- ElseIf (Username$ = U1$) And (Password$ = U1Pasw$) Then
- CzyAdmin = 0
- Zalogowany = 1
- ElseIf (Username$ = U2$) And (Password$ = U2Pasw$) Then
- CzyAdmin = 0
- Zalogowany = 1
- End If
- If (Zalogowany = 0) then
- Username$ = "Blad"
- End Command
- Command &H20 &H01 Calculator (S$)
- Private X As Long
- S$ = Trim$ (S$)
- X = EvaluateExpression (S$, 0)
- If Len (Trim$ (S$)) <> 0 Then Call Error (SyntaxError)
- If P1 = 0 Then S$ = Str$ (X) : Else S$ = Hex$ (X)
- End Command
- Function EvaluateExpression (S$, Precedence) As Long
- EvaluateExpression = EvaluateTerm (S$)
- Do
- S$ = LTrim$ (S$)
- If Len (S$) = 0 Then Exit Function
- Select Case S$(1)
- Case "*"
- If Precedence > 5 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression * _
- EvaluateExpression (S$, 6)
- Case "/"
- If Precedence > 5 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression / _
- EvaluateExpression (S$, 6)
- Case "%"
- If Precedence > 5 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression Mod _
- EvaluateExpression (S$, 6)
- Case "+"
- If Precedence > 4 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression + _
- EvaluateExpression (S$, 5)
- Case "-"
- If Precedence > 4 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression - _
- EvaluateExpression (S$, 5)
- Case "&"
- If Precedence > 3 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression And _
- EvaluateExpression (S$, 4)
- Case "^"
- If Precedence > 2 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression Xor _
- EvaluateExpression (S$, 3)
- Case "|"
- If Precedence > 1 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression Or _
- EvaluateExpression (S$, 2)
- Case "P"
- If Precedence > 6 Then Exit Function
- S$ = Mid$ (S$, 2)
- EvaluateExpression = EvaluateExpression * _
- EvaluateExpression
- Case Else
- Exit Function
- End Select
- Loop
- End Function
- Function EvaluateTerm (S$) As Long
- Do ' Ignore unary plus
- S$ = LTrim$ (S$)
- If Len (S$) = 0 Then Call Error (SyntaxError)
- If S$(1) <> "+" Then Exit Do
- S$ = Mid$ (S$, 2)
- Loop
- If S$(1) = "(" Then ' Expression in parentheses
- S$ = Mid$ (S$, 2)
- EvaluateTerm = EvaluateExpression (S$, 0)
- S$ = LTrim$ (S$)
- If S$(1) <> ")" Then Call Error (ParenthesisMismatch)
- S$ = Mid$ (S$, 2)
- Exit Function
- ElseIf S$(1) = "-" Then ' Unary minus
- S$ = Mid$ (S$, 2)
- EvaluateTerm = -EvaluateTerm (S$)
- Exit Function
- Else ' Must be a number
- If P1 = 0 Then ' If decimal
- EvaluateTerm = Val& (S$, L@)
- Else
- EvaluateTerm = ValH (S$, L@)
- End If
- If L@ = 0 Then Call Error (InvalidNumber)
- S$ = Mid$ (S$, L@ + 1)
- End If
- End Function
- Sub Error (Code@)
- SW1 = &H64
- SW2 = Code@
- Exit
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement