Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. Rem BasicCard Sample Source Code
  2. Rem ------------------------------------------------------------------
  3. Rem Copyright (C) 1997-1999 ZeitControl GmbH
  4. Rem You have a royalty-free right to use, modify, reproduce and
  5. Rem distribute the Sample Application Files (and/or any modified
  6. Rem version) in any way you find useful, provided that you agree
  7. Rem that ZeitControl GmbH has no warranty, obligations or liability
  8. Rem for any Sample Application Files.
  9. Rem ------------------------------------------------------------------
  10.  
  11. #Include CALCKEYS.BAS
  12.  
  13. Declare ApplicationID = "BasicCard Mini-Calculator"
  14.  
  15. Rem This BasicCard program contains recursive procedure calls, so the
  16. Rem compiler will allocate all available RAM to the P-Code stack unless
  17. Rem otherwise advised. This slows execution, because all strings have to
  18. Rem be allocated from EEPROM. So we specify a stack size here:
  19.  
  20. #Stack 120
  21.  
  22. ' Calculator Command (CLA = &H20, INS = &H01)
  23. '
  24. ' Input: an ASCII expression involving integers, and these operators:
  25. '
  26. ' * / % + - & ^ |
  27. '
  28. ' (Parentheses are also allowed.)
  29. '
  30. ' Output: the value of the expression, in ASCII.
  31. '
  32. ' P1 = 0: all numbers are decimal
  33. ' P1 <> 0: all numbers are hex
  34.  
  35. ' Constants
  36. Const SyntaxError = &H81
  37. Const ParenthesisMismatch = &H82
  38. Const InvalidNumber = &H83
  39. Const BadOperator = &H84
  40.  
  41.  
  42. Rem <---------ZMIENNE DO LOGOWANIA--------->
  43.  
  44.  
  45.  
  46. Const U1$ = "user1"
  47. Const U2$ = "user2"
  48. Const Admin$ = "admin"
  49.  
  50.  
  51.  
  52. Eeprom U1Pasw$ As String = "1244"
  53. Eeprom U2Pasw$ As String = "1234"
  54. Eeprom AdminPasw$ As String = "1234"
  55.  
  56.  
  57. Public CzyAdmin As Byte = 0
  58. Public Zalogowany As Byte = 0
  59.  
  60.  
  61. ' Forward references
  62. Declare Function EvaluateExpression (S$, Precedence) As Long
  63. Declare Function EvaluateTerm (S$) As Long
  64. Declare Sub Error (Code@)
  65. Declare Command &H21 &H02 Login (UserName$ As String*64, Password$ As String)
  66. Rem Declare Command &H22 &H03 Password (UserName$ As String*64, Password$ As String)
  67. Rem Declare Command &H23 &H04 Logout()
  68.  
  69.  
  70.  
  71. Command &H21 &H02 Login(Username$ As String *64, Password$ As String)
  72. CzyAdmin = 0
  73. Zalogowany = 0
  74.  
  75. If (Username$ = Admin$) And (Password$ = AdminPasw$) Then
  76.  
  77. CzyAdmin = 1
  78. Zalogowany = 1
  79. ElseIf (Username$ = U1$) And (Password$ = U1Pasw$) Then
  80.  
  81. CzyAdmin = 0
  82. Zalogowany = 1
  83. ElseIf (Username$ = U2$) And (Password$ = U2Pasw$) Then
  84.  
  85. CzyAdmin = 0
  86. Zalogowany = 1
  87. End If
  88.  
  89. If (Zalogowany = 0) then
  90. Username$ = "Blad"
  91. End Command
  92.  
  93.  
  94.  
  95.  
  96.  
  97. Command &H20 &H01 Calculator (S$)
  98.  
  99. Private X As Long
  100. S$ = Trim$ (S$)
  101. X = EvaluateExpression (S$, 0)
  102. If Len (Trim$ (S$)) <> 0 Then Call Error (SyntaxError)
  103. If P1 = 0 Then S$ = Str$ (X) : Else S$ = Hex$ (X)
  104.  
  105. End Command
  106.  
  107. Function EvaluateExpression (S$, Precedence) As Long
  108.  
  109. EvaluateExpression = EvaluateTerm (S$)
  110.  
  111. Do
  112. S$ = LTrim$ (S$)
  113. If Len (S$) = 0 Then Exit Function
  114.  
  115. Select Case S$(1)
  116.  
  117. Case "*"
  118. If Precedence > 5 Then Exit Function
  119. S$ = Mid$ (S$, 2)
  120. EvaluateExpression = EvaluateExpression * _
  121. EvaluateExpression (S$, 6)
  122. Case "/"
  123. If Precedence > 5 Then Exit Function
  124. S$ = Mid$ (S$, 2)
  125. EvaluateExpression = EvaluateExpression / _
  126. EvaluateExpression (S$, 6)
  127. Case "%"
  128. If Precedence > 5 Then Exit Function
  129. S$ = Mid$ (S$, 2)
  130. EvaluateExpression = EvaluateExpression Mod _
  131. EvaluateExpression (S$, 6)
  132. Case "+"
  133. If Precedence > 4 Then Exit Function
  134. S$ = Mid$ (S$, 2)
  135. EvaluateExpression = EvaluateExpression + _
  136. EvaluateExpression (S$, 5)
  137. Case "-"
  138. If Precedence > 4 Then Exit Function
  139. S$ = Mid$ (S$, 2)
  140. EvaluateExpression = EvaluateExpression - _
  141. EvaluateExpression (S$, 5)
  142. Case "&"
  143. If Precedence > 3 Then Exit Function
  144. S$ = Mid$ (S$, 2)
  145. EvaluateExpression = EvaluateExpression And _
  146. EvaluateExpression (S$, 4)
  147. Case "^"
  148. If Precedence > 2 Then Exit Function
  149. S$ = Mid$ (S$, 2)
  150. EvaluateExpression = EvaluateExpression Xor _
  151. EvaluateExpression (S$, 3)
  152. Case "|"
  153. If Precedence > 1 Then Exit Function
  154. S$ = Mid$ (S$, 2)
  155. EvaluateExpression = EvaluateExpression Or _
  156. EvaluateExpression (S$, 2)
  157. Case "P"
  158. If Precedence > 6 Then Exit Function
  159. S$ = Mid$ (S$, 2)
  160. EvaluateExpression = EvaluateExpression * _
  161. EvaluateExpression
  162. Case Else
  163. Exit Function
  164. End Select
  165.  
  166. Loop
  167.  
  168. End Function
  169.  
  170. Function EvaluateTerm (S$) As Long
  171.  
  172. Do ' Ignore unary plus
  173. S$ = LTrim$ (S$)
  174. If Len (S$) = 0 Then Call Error (SyntaxError)
  175. If S$(1) <> "+" Then Exit Do
  176. S$ = Mid$ (S$, 2)
  177. Loop
  178.  
  179. If S$(1) = "(" Then ' Expression in parentheses
  180. S$ = Mid$ (S$, 2)
  181. EvaluateTerm = EvaluateExpression (S$, 0)
  182. S$ = LTrim$ (S$)
  183. If S$(1) <> ")" Then Call Error (ParenthesisMismatch)
  184. S$ = Mid$ (S$, 2)
  185. Exit Function
  186.  
  187. ElseIf S$(1) = "-" Then ' Unary minus
  188. S$ = Mid$ (S$, 2)
  189. EvaluateTerm = -EvaluateTerm (S$)
  190. Exit Function
  191.  
  192. Else ' Must be a number
  193. If P1 = 0 Then ' If decimal
  194. EvaluateTerm = Val& (S$, L@)
  195. Else
  196. EvaluateTerm = ValH (S$, L@)
  197. End If
  198. If L@ = 0 Then Call Error (InvalidNumber)
  199. S$ = Mid$ (S$, L@ + 1)
  200. End If
  201.  
  202. End Function
  203.  
  204. Sub Error (Code@)
  205. SW1 = &H64
  206. SW2 = Code@
  207. Exit
  208. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement