LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lms2012.c
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 
61 #include "lms2012.h"
62 #include "c_math.h"
63 #include "c_move.h"
64 #include "c_branch.h"
65 #include "c_compare.h"
66 #include "c_timer.h"
67 #include "c_output.h"
68 #include "c_input.h"
69 #include "c_ui.h"
70 #include "c_memory.h"
71 #include "c_com.h"
72 #include "c_sound.h"
73 #ifndef Linux_X86
74 #include "c_bt.h"
75 #include "c_i2c.h"
76 #endif
77 #include "validate.h"
78 
79 #if (HARDWARE != SIMULATION)
80 
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <string.h>
84 #include <unistd.h>
85 #include <time.h>
86 #include <syslog.h>
87 #include <math.h>
88 
89 #include <dirent.h>
90 #include <sys/stat.h>
91 #include <sys/statvfs.h>
92 #include <sys/types.h>
93 #include <sys/time.h>
94 #include <fcntl.h>
95 #include <sys/ioctl.h>
96 
97 #include <sys/mman.h>
98 
99 
100 #endif
101 
102 #ifdef DEBUG_VM
103 #define DEBUG
104 #endif
105 
106 #ifdef DEBUG
107 #define DEBUG_TRACE_TASK
108 #define DEBUG_TRACE_VM
109 #endif
110 
111 // Buttons are mapped differently in the enum BUTTONTYPE and in ButtonState.
112 #define IDX_BACK_BUTTON BACK_BUTTON-1
113 
114 //*****************************************************************************
115 // UI bootloader
116 //*****************************************************************************
117 
119 {
120  // IMAGE header
121  PROGRAMHeader(0,1,0), // VersionInfo,Objects,GlobalBytes
122  VMTHREADHeader(0,1), // OffsetToInstructions,LocalBytes
123 
124  opFILE,LC0(LOAD_IMAGE),LC0(GUI_SLOT),GV0(0),LV0(4),LV0(0),
125  opPROGRAM_START,LC0(GUI_SLOT),LC0(0),LV0(0),LC0(0),
126  opOBJECT_END,
127 
128 };
129 
130 #if (HARDWARE != SIMULATION)
132 #else
133  GLOBALS * gInstance;
134 
135  void setInstance(GLOBALS * _Instance)
136  {
137  gInstance= _Instance;
138  }
139 
140  GLOBALS* getInstance()
141  {
142  return gInstance;
143  }
144 
145 #endif
146 //*****************************************************************************
147 // Forward declarations
148 //*****************************************************************************
149 #define PRIMDISPATHTABLE_SIZE 256
150 
152 
153 void Error(void);
154 void Nop(void);
155 void ObjectStop(void);
156 void ObjectStart(void);
157 void ObjectTrig(void);
158 void ObjectWait(void);
159 void ObjectCall(void);
160 void ObjectReturn(void);
161 void ObjectEnd(void);
162 void ProgramStart(void);
163 void ProgramStop(void);
164 void Sleep(void);
165 void ProgramInfo(void);
166 void DefLabel(void);
167 void Do(void);
168 void Probe(void);
169 void BreakPoint(void);
170 void BreakSet(void);
171 void Random(void);
172 void Info(void);
173 void Strings(void);
174 void MemoryWrite(void);
175 void MemoryRead(void);
176 void cBranchJr(void);
177 void PortCnvOutput(void);
178 void PortCnvInput(void);
179 void NoteToFreq(void);
180 void System(void);
181 void Monitor(void);
182 
183 void TstClose(void);
184 void Tst(void);
185 
186 
187 //*****************************************************************************
188 // Interface for shared libraries
189 //*****************************************************************************
190 
197 {
198  return (VMInstance.ObjectId);
199 }
200 
201 
208 {
209  return (VMInstance.ProgramId);
210 }
211 
212 
219 {
220  return (VMInstance.Program[PrgId].Status);
221 }
222 
223 
230 {
231  OBJSTAT Status;
232 
233  Status = (DATA8)VMInstance.Program[PrgId].StatusChange;
234  VMInstance.Program[PrgId].StatusChange = 0;
235 
236  return (Status);
237 }
238 
239 
246 {
247  return (VMInstance.pImage);
248 }
249 
250 
257 {
258  VMInstance.DispatchStatus = DspStat;
259 
260  if (VMInstance.DispatchStatus != NOBREAK)
261  {
262  VMInstance.Priority = 0;
263  }
264 
265 }
266 
267 
273 void SetInstructions(ULONG Instructions)
274 {
275  if (Instructions <= PRG_PRIORITY)
276  {
277  VMInstance.Priority = Instructions;
278  }
279 }
280 
281 
288 {
289  VMInstance.ObjectIp += Value;
290 }
291 
292 
299 {
300  return (VMInstance.ObjectIp);
301 }
302 
303 
309 void SetObjectIp(IP Ip)
310 {
311  VMInstance.ObjectIp = Ip;
312 }
313 
314 
316 {
317  return (cTimerGetuS() - VMInstance.Program[VMInstance.ProgramId].RunTime);
318 }
319 
320 
322 {
323  return (cTimerGetmS());
324 }
325 
326 
328 {
329  return (cTimerGetuS());
330 }
331 
332 
334 {
335  return ((ULONG)(VMInstance.ObjectIp - VMInstance.pImage));
336 }
337 
338 
339 void VmPrint(char *pString)
340 {
341  if (VMInstance.TerminalEnabled)
342  {
343  printf("%s",pString);
344  }
345 }
346 
347 
349 {
350  VMInstance.TerminalEnabled = Value;
351 }
352 
353 
355 {
356  return (VMInstance.TerminalEnabled);
357 }
358 
359 
360 void GetResourcePath(char *pString,DATA8 MaxLength)
361 {
362  cMemoryGetResourcePath(VMInstance.ProgramId,pString,MaxLength);
363 }
364 
365 
366 void* VmMemoryResize(HANDLER Handle,DATA32 Elements)
367 {
368  return (cMemoryResize(VMInstance.ProgramId,Handle,Elements));
369 }
370 
371 
373 {
374  VMInstance.NonVol.VolumePercent = Volume;
375 }
376 
377 
379 {
380  return(VMInstance.NonVol.VolumePercent);
381 }
382 
383 
384 void SetSleepMinutes(DATA8 Minutes)
385 {
386  VMInstance.NonVol.SleepMinutes = Minutes;
387 }
388 
389 
391 {
392  return (VMInstance.NonVol.SleepMinutes);
393 }
394 
395 
396 void SetUiUpdate(void)
397 {
398  UiInstance.UiUpdate = 1;
399 }
400 
401 
402 #define ERROR(ErrorCode) [ErrorCode] = #ErrorCode
403 
405 {
406 
441 
442 };
443 
444 
446 {
447  UBYTE Tmp;
448 
449  if (Err > TOO_MANY_ERRORS_TO_BUFFER)
450  {
451  Tmp = VMInstance.ErrorIn;
452  if (++Tmp >= ERROR_BUFFER_SIZE)
453  {
454  Tmp = 0;
455  }
456  if (Tmp != VMInstance.ErrorOut)
457  {
458  VMInstance.Errors[VMInstance.ErrorIn] = Err;
459  VMInstance.ErrorIn = Tmp;
460  }
461  else
462  {
463  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"\r\n#### %s ####\r\n\n",ErrString[TOO_MANY_ERRORS_TO_BUFFER]);
464  VmPrint(VMInstance.PrintBuffer);
465  }
466  }
467 }
468 
469 
471 {
472  DATA8 Result = 0;
473  UBYTE Tmp;
474 
475  Tmp = VMInstance.ErrorOut;
476  while ((Tmp != VMInstance.ErrorIn) && (Result == 0))
477  {
478  if (VMInstance.Errors[Tmp] == Error)
479  {
480  Result = 1;
481  }
482  else
483  {
484  if (++Tmp >= ERROR_BUFFER_SIZE)
485  {
486  Tmp = 0;
487  }
488  }
489  }
490 
491  return (Result);
492 }
493 
494 
496 {
497  ERR Number = 0;
498 
499  if (VMInstance.ErrorIn != VMInstance.ErrorOut)
500  {
501  Number = VMInstance.Errors[VMInstance.ErrorOut];
502  if (++VMInstance.ErrorOut >= ERROR_BUFFER_SIZE)
503  {
504  VMInstance.ErrorOut = 0;
505  }
506  }
507 
508  return (Number);
509 }
510 
511 
512 void CleanLogErrors(void)
513 {
514  VMInstance.ErrorIn = 0;
515  VMInstance.ErrorOut = 0;
516 }
517 
518 
535 DSPSTAT ExecuteByteCode(IP pByteCode,GP pGlobals,LP pLocals)
536 {
537  DSPSTAT Result;
538  ULONG Time;
539 
540  // Save running object parameters
541  VMInstance.ObjIpSave = VMInstance.ObjectIp;
542  VMInstance.ObjGlobalSave = VMInstance.pGlobal;
543  VMInstance.ObjLocalSave = VMInstance.ObjectLocal;
544  VMInstance.DispatchStatusSave = VMInstance.DispatchStatus;
545  VMInstance.PrioritySave = VMInstance.Priority;
546 
547  // InitExecute special byte code stream
548  VMInstance.ObjectIp = pByteCode;
549  VMInstance.pGlobal = pGlobals;
550  VMInstance.ObjectLocal = pLocals;
551  VMInstance.Priority = 1;
552 
553  // Execute special byte code stream
555  while ((*VMInstance.ObjectIp != opOBJECT_END) && (!(UiInstance.ButtonState[IDX_BACK_BUTTON] & BUTTON_LONGPRESS)))
556  {
557  VMInstance.DispatchStatus = NOBREAK;
558  VMInstance.Priority = C_PRIORITY;
559 
560  while ((VMInstance.Priority) && (*VMInstance.ObjectIp != opOBJECT_END))
561  {
562  VMInstance.Priority--;
563  PrimDispatchTabel[*(VMInstance.ObjectIp++)]();
564  }
565 
566  VMInstance.NewTime = GetTimeMS();
567 
568  Time = VMInstance.NewTime - VMInstance.OldTime1;
569 
570  if (Time >= UPDATE_TIME1)
571  {
572  VMInstance.OldTime1 += Time;
573 
574  cComUpdate();
575  cSoundUpdate();
576  }
577 
578  Time = VMInstance.NewTime - VMInstance.OldTime2;
579 
580  if (Time >= UPDATE_TIME2)
581  {
582  VMInstance.OldTime2 += Time;
583 
584  usleep(10);
585  cInputUpdate((UWORD)Time);
586  cUiUpdate((UWORD)Time);
587  }
588  }
589  Result = VMInstance.DispatchStatus;
590 
591  UiInstance.ButtonState[IDX_BACK_BUTTON] &= ~BUTTON_LONGPRESS;
592 
593  // Restore running object parameters
594  VMInstance.Priority = VMInstance.PrioritySave;
595  VMInstance.DispatchStatus = VMInstance.DispatchStatusSave;
596  VMInstance.ObjectLocal = VMInstance.ObjLocalSave;
597  VMInstance.pGlobal = VMInstance.ObjGlobalSave;
598  VMInstance.ObjectIp = VMInstance.ObjIpSave;
599 
600  return (Result);
601 }
602 
603 
694 void* PrimParPointer(void)
695 {
696  void* Result;
697  IMGDATA Data;
698 
699  Result = (void*)&VMInstance.Value;
700  Data = *((IMGDATA*)VMInstance.ObjectIp++);
701  VMInstance.Handle = -1;
702 
703  if (Data & PRIMPAR_LONG)
704  { // long format
705 
706  if (Data & PRIMPAR_VARIABEL)
707  { // variabel
708 
709  switch(Data & PRIMPAR_BYTES)
710  {
711 
712  case PRIMPAR_1_BYTE :
713  { // One byte to follow
714 
715  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
716  }
717  break;
718 
719  case PRIMPAR_2_BYTES :
720  { // Two bytes to follow
721 
722  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
723  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 8);
724  }
725  break;
726 
727  case PRIMPAR_4_BYTES :
728  { // Four bytes to follow
729 
730  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
731  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 8);
732  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 16);
733  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 24);
734  }
735 
736  }
737  if (Data & PRIMPAR_GLOBAL)
738  { // global
739 
740  Result = (void*)(&VMInstance.pGlobal[VMInstance.Value]);
741  }
742  else
743  { // local
744 
745  Result = (void*)(&VMInstance.ObjectLocal[VMInstance.Value]);
746  }
747  }
748  else
749  { // constant
750 
751  if (Data & PRIMPAR_LABEL)
752  { // label
753 
754  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
755 
756  if ((VMInstance.Value > 0) && (VMInstance.Value < MAX_LABELS))
757  {
758  VMInstance.Value = (ULONG)VMInstance.Program[VMInstance.ProgramId].Label[VMInstance.Value].Addr;
759  VMInstance.Value -= ((ULONG)VMInstance.ObjectIp - (ULONG)VMInstance.Program[VMInstance.ProgramId].pImage);
760  Result = (void*)&VMInstance.Value;
761  }
762  }
763  else
764  { // value
765 
766  switch(Data & PRIMPAR_BYTES)
767  {
768  case PRIMPAR_STRING_OLD :
769  case PRIMPAR_STRING :
770  { // Zero terminated
771 
772  Result = (DATA8*)VMInstance.ObjectIp;
773  while (*((IMGDATA*)VMInstance.ObjectIp++))
774  { // Adjust Ip
775  }
776  }
777  break;
778 
779  case PRIMPAR_1_BYTE :
780  { // One byte to follow
781 
782  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
783  if (VMInstance.Value & 0x00000080)
784  { // Adjust if negative
785 
786  VMInstance.Value |= 0xFFFFFF00;
787  }
788  }
789  break;
790 
791  case PRIMPAR_2_BYTES :
792  { // Two bytes to follow
793 
794  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
795  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 8);
796  if (VMInstance.Value & 0x00008000)
797  { // Adjust if negative
798 
799  VMInstance.Value |= 0xFFFF0000;
800  }
801  }
802  break;
803 
804  case PRIMPAR_4_BYTES :
805  { // Four bytes to follow
806 
807  VMInstance.Value = (ULONG)*((IMGDATA*)VMInstance.ObjectIp++);
808  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 8);
809  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 16);
810  VMInstance.Value |= ((ULONG)*((IMGDATA*)VMInstance.ObjectIp++) << 24);
811  }
812 
813  }
814  }
815  }
816  if (Data & PRIMPAR_HANDLE)
817  {
818  VMInstance.Handle = *(HANDLER*)Result;
819  cMemoryArraryPointer(VMInstance.ProgramId,VMInstance.Handle,&Result);
820  }
821  else
822  {
823  if (Data & PRIMPAR_ADDR)
824  {
825  Result = (void*)*(DATA32*)Result;
826  VMInstance.Value = (DATA32)Result;
827  }
828  }
829  }
830  else
831  { // short format
832 
833  if (Data & PRIMPAR_VARIABEL)
834  { // variabel
835 
836  VMInstance.Value = (ULONG)(Data & PRIMPAR_INDEX);
837 
838  if (Data & PRIMPAR_GLOBAL)
839  { // global
840 
841  Result = (void*)(&VMInstance.pGlobal[VMInstance.Value]);
842  }
843  else
844  { // local
845 
846  Result = (void*)(&VMInstance.ObjectLocal[VMInstance.Value]);
847  }
848  }
849  else
850  { // constant
851 
852  VMInstance.Value = (ULONG)(Data & PRIMPAR_VALUE);
853 
854  if (Data & PRIMPAR_CONST_SIGN)
855  { // Adjust if negative
856 
857  VMInstance.Value |= ~(ULONG)(PRIMPAR_VALUE);
858  }
859  }
860  }
861 
862  return (Result);
863 }
864 
865 
870 void PrimParAdvance(void)
871 {
872  IMGDATA Data;
873 
874  Data = *((IMGDATA*)VMInstance.ObjectIp++);
875 
876  if (Data & PRIMPAR_LONG)
877  { // long format
878 
879  if (Data & PRIMPAR_VARIABEL)
880  { // variabel
881 
882  switch(Data & PRIMPAR_BYTES)
883  {
884 
885  case PRIMPAR_1_BYTE :
886  { // One byte to follow
887 
888  VMInstance.ObjectIp++;
889  }
890  break;
891 
892  case PRIMPAR_2_BYTES :
893  { // Two bytes to follow
894 
895  VMInstance.ObjectIp++;
896  VMInstance.ObjectIp++;
897  }
898  break;
899 
900  case PRIMPAR_4_BYTES :
901  { // Four bytes to follow
902 
903  VMInstance.ObjectIp++;
904  VMInstance.ObjectIp++;
905  VMInstance.ObjectIp++;
906  VMInstance.ObjectIp++;
907  }
908 
909  }
910  }
911  else
912  { // constant
913 
914  if (Data & PRIMPAR_LABEL)
915  { // label
916 
917  VMInstance.ObjectIp++;
918 
919  }
920  else
921  { // value
922 
923  switch(Data & PRIMPAR_BYTES)
924  {
925  case PRIMPAR_STRING_OLD :
926  case PRIMPAR_STRING :
927  { // Zero terminated
928 
929  while (*((IMGDATA*)VMInstance.ObjectIp++))
930  { // Adjust Ip
931  }
932  }
933  break;
934 
935  case PRIMPAR_1_BYTE :
936  { // One byte to follow
937 
938  VMInstance.ObjectIp++;
939  }
940  break;
941 
942  case PRIMPAR_2_BYTES :
943  { // Two bytes to follow
944 
945  VMInstance.ObjectIp++;
946  VMInstance.ObjectIp++;
947  }
948  break;
949 
950  case PRIMPAR_4_BYTES :
951  { // Four bytes to follow
952 
953  VMInstance.ObjectIp++;
954  VMInstance.ObjectIp++;
955  VMInstance.ObjectIp++;
956  VMInstance.ObjectIp++;
957  }
958 
959  }
960  }
961  }
962  }
963 }
964 
965 
996 {
997  IP TmpIp; // Save calling Ip
998  IP TypeIp; // Called Ip
999  void* pLocals; // Called locals
1000  PARS NoOfPars; // Called no of parameters
1001  IMGDATA Type; // Coded type
1002  void* Result; // Pointer to value
1003  DATA32 Size;
1004  DATA8 Flag;
1005 
1006  TmpIp = VMInstance.ObjectIp;
1007  TypeIp = VMInstance.Program[VMInstance.ProgramId].pImage;
1008  TypeIp = &TypeIp[(ULONG)VMInstance.pObjHead[Id].OffsetToInstructions];
1009  pLocals = (*VMInstance.pObjList[Id]).pLocal;
1010 
1011  NoOfPars = (PARS)*((IMGDATA*)TypeIp++);
1012 
1013  while (NoOfPars--)
1014  {
1015  // Get type from sub preamble
1016  Type = (IMGDATA)*((IMGDATA*)TypeIp++);
1017 
1018  // Get pointer to value and increment VMInstance.ObjectIP
1019 
1020  Result = PrimParPointer();
1021 
1022  if ((Type & CALLPAR_IN))
1023  { // Input
1024 
1025  switch (Type & CALLPAR_TYPE)
1026  {
1027 
1028  case CALLPAR_DATA8 :
1029  {
1030  (*(DATA8*)pLocals) = *(DATA8*)Result;
1031  pLocals = ((DATA8*)pLocals) + 1;
1032  }
1033  break;
1034 
1035  case CALLPAR_DATA16 :
1036  {
1037 #ifndef DISABLE_PAR_ALIGNMENT
1038  pLocals = (void*)(((IMINDEX)pLocals + 1) & ~1);
1039 #endif
1040  (*(DATA16*)pLocals) = *(DATA16*)Result;
1041  pLocals = ((DATA16*)pLocals) + 1;
1042  }
1043  break;
1044 
1045  case CALLPAR_DATA32 :
1046  {
1047 #ifndef DISABLE_PAR_ALIGNMENT
1048  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1049 #endif
1050  (*(DATA32*)pLocals) = *(DATA32*)Result;
1051  pLocals = ((DATA32*)pLocals) + 1;
1052  }
1053  break;
1054 
1055  case CALLPAR_DATAF :
1056  {
1057 #ifndef DISABLE_PAR_ALIGNMENT
1058  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1059 #endif
1060  (*(DATAF*)pLocals) = *(DATAF*)Result;
1061  pLocals = ((DATAF*)pLocals) + 1;
1062  }
1063  break;
1064 
1065  case CALLPAR_STRING :
1066  {
1067  Size = (DATA32)*((IMGDATA*)TypeIp++);
1068  Flag = 1;
1069  while (Size)
1070  {
1071  if (Flag)
1072  {
1073  Flag = *(DATA8*)Result;
1074  }
1075  (*(DATA8*)pLocals) = Flag;
1076  Result = ((DATA8*)Result) + 1;
1077  pLocals = ((DATA8*)pLocals) + 1;
1078  Size--;
1079  }
1080  pLocals = ((DATA8*)pLocals) - 1;
1081  (*(DATA8*)pLocals) = 0;
1082  pLocals = ((DATA8*)pLocals) + 1;
1083  }
1084  break;
1085 
1086  }
1087  }
1088  else
1089  {
1090  if ((Type & CALLPAR_OUT))
1091  { // Output
1092 
1093  switch (Type & CALLPAR_TYPE)
1094  {
1095 
1096  case CALLPAR_DATA8 :
1097  {
1098  pLocals = ((DATA8*)pLocals) + 1;
1099  }
1100  break;
1101 
1102  case CALLPAR_DATA16 :
1103  {
1104 #ifndef DISABLE_PAR_ALIGNMENT
1105  pLocals = (void*)(((IMINDEX)pLocals + 1) & ~1);
1106 #endif
1107  pLocals = ((DATA16*)pLocals) + 1;
1108  }
1109  break;
1110 
1111  case CALLPAR_DATA32 :
1112  {
1113 #ifndef DISABLE_PAR_ALIGNMENT
1114  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1115 #endif
1116  pLocals = ((DATA32*)pLocals) + 1;
1117  }
1118  break;
1119 
1120  case CALLPAR_DATAF :
1121  {
1122 #ifndef DISABLE_PAR_ALIGNMENT
1123  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1124 #endif
1125  pLocals = ((DATAF*)pLocals) + 1;
1126  }
1127  break;
1128 
1129  case CALLPAR_STRING :
1130  {
1131  Size = (DATA32)*((IMGDATA*)TypeIp++);
1132  pLocals = ((DATA8*)pLocals) + Size;
1133  }
1134  break;
1135 
1136  }
1137  }
1138  }
1139  }
1140  (*VMInstance.pObjList[Id]).Ip = TypeIp;
1141 
1142  // Rewind caller Ip
1143  VMInstance.ObjectIp = TmpIp;
1144 }
1145 
1146 
1154 {
1155  IP TmpIp; // Calling Ip
1156  IP TypeIp; // Called Ip
1157  void* pLocals; // Called locals
1158  PARS NoOfPars; // Called no of parameters
1159  IMGDATA Type; // Coded type
1160  void* Result; // Pointer to value
1161  DATA32 Size;
1162  DATA8 Flag;
1163 
1164  // Point to start of parameters
1165  TmpIp = VMInstance.ObjectIp;
1166  VMInstance.ObjectIp = (*VMInstance.pObjList[Id]).Ip;
1167 
1168  // Point to start of sub
1169  TypeIp = VMInstance.Program[VMInstance.ProgramId].pImage;
1170  TypeIp = &TypeIp[(ULONG)VMInstance.pObjHead[VMInstance.ObjectId].OffsetToInstructions];
1171  pLocals = (*VMInstance.pObjList[VMInstance.ObjectId]).pLocal;
1172 
1173  NoOfPars = (PARS)*((IMGDATA*)TypeIp++);
1174 
1175  while (NoOfPars--)
1176  {
1177  // Get type from sub preamble
1178  Type = (IMGDATA)*((IMGDATA*)TypeIp++);
1179 
1180  // Get pointer to value and increment VMInstance.ObjectIp
1181  Result = PrimParPointer();
1182 
1183  if ((Type & CALLPAR_OUT))
1184  { // Output
1185 
1186  switch (Type & CALLPAR_TYPE)
1187  {
1188 
1189  case CALLPAR_DATA8 :
1190  {
1191  *(DATA8*)Result = (*(DATA8*)pLocals);
1192  pLocals = ((DATA8*)pLocals) + 1;
1193  }
1194  break;
1195 
1196  case CALLPAR_DATA16 :
1197  {
1198 #ifndef DISABLE_PAR_ALIGNMENT
1199  pLocals = (void*)(((IMINDEX)pLocals + 1) & ~1);
1200 #endif
1201  *(DATA16*)Result = (*(DATA16*)pLocals);
1202  pLocals = ((DATA16*)pLocals) + 1;
1203  }
1204  break;
1205 
1206  case CALLPAR_DATA32 :
1207  {
1208 #ifndef DISABLE_PAR_ALIGNMENT
1209  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1210 #endif
1211  *(DATA32*)Result = (*(DATA32*)pLocals);
1212  pLocals = ((DATA32*)pLocals) + 1;
1213  }
1214  break;
1215 
1216  case CALLPAR_DATAF :
1217  {
1218 #ifndef DISABLE_PAR_ALIGNMENT
1219  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1220 #endif
1221  *(DATAF*)Result = (*(DATAF*)pLocals);
1222  pLocals = ((DATAF*)pLocals) + 1;
1223  }
1224  break;
1225 
1226  case CALLPAR_STRING :
1227  {
1228  Size = (DATA32)*((IMGDATA*)TypeIp++);
1229  Flag = 1;
1230  while (Size)
1231  {
1232  if (Flag)
1233  {
1234  Flag = (*(DATA8*)pLocals);
1235  }
1236  *(DATA8*)Result = Flag;
1237  Result = ((DATA8*)Result) + 1;
1238  pLocals = ((DATA8*)pLocals) + 1;
1239  Size--;
1240  }
1241  Result = ((DATA8*)Result) - 1;
1242  *(DATA8*)Result = 0;
1243  }
1244  break;
1245 
1246  }
1247  }
1248  else
1249  {
1250  if ((Type & CALLPAR_IN))
1251  { // Input
1252 
1253  switch (Type & CALLPAR_TYPE)
1254  {
1255 
1256  case CALLPAR_DATA8 :
1257  {
1258  pLocals = ((DATA8*)pLocals) + 1;
1259  }
1260  break;
1261 
1262  case CALLPAR_DATA16 :
1263  {
1264 #ifndef DISABLE_PAR_ALIGNMENT
1265  pLocals = (void*)(((IMINDEX)pLocals + 1) & ~1);
1266 #endif
1267  pLocals = ((DATA16*)pLocals) + 1;
1268  }
1269  break;
1270 
1271  case CALLPAR_DATA32 :
1272  {
1273 #ifndef DISABLE_PAR_ALIGNMENT
1274  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1275 #endif
1276  pLocals = ((DATA32*)pLocals) + 1;
1277  }
1278  break;
1279 
1280  case CALLPAR_DATAF :
1281  {
1282 #ifndef DISABLE_PAR_ALIGNMENT
1283  pLocals = (void*)(((IMINDEX)pLocals + 3) & ~3);
1284 #endif
1285  pLocals = ((DATAF*)pLocals) + 1;
1286  }
1287  break;
1288 
1289  case CALLPAR_STRING :
1290  {
1291  Size = (DATA32)*((IMGDATA*)TypeIp++);
1292  pLocals = ((DATA8*)pLocals) + Size;
1293  }
1294  break;
1295 
1296  }
1297  }
1298  }
1299  }
1300 
1301  // Adjust caller Ip
1302  (*VMInstance.pObjList[Id]).Ip = VMInstance.ObjectIp;
1303  // Restore calling Ip
1304  VMInstance.ObjectIp = TmpIp;
1305 }
1306 
1307 
1308 //*****************************************************************************
1309 // VM routines
1310 //*****************************************************************************
1311 
1317 void ObjectReset(OBJID ObjId)
1318 {
1319  (*VMInstance.pObjList[ObjId]).Ip = &VMInstance.pImage[(ULONG)VMInstance.pObjHead[ObjId].OffsetToInstructions];
1320 
1321  (*VMInstance.pObjList[ObjId]).u.TriggerCount = VMInstance.pObjHead[ObjId].TriggerCount;
1322 }
1323 
1324 
1331 {
1332  GBINDEX Bytes = 0;
1333  OBJID NoOfObj;
1334  OBJID ObjId;
1335  OBJHEAD *pHead;
1336 
1337  NoOfObj = (*(IMGHEAD*)pI).NumberOfObjects;
1338 
1339  Bytes += (*(IMGHEAD*)pI).GlobalBytes;
1340  Bytes = (Bytes + 3) & 0xFFFFFFFC;
1341  Bytes += sizeof(VMInstance.pObjList) * (NoOfObj + 1);
1342 
1343  pHead = (OBJHEAD*)&pI[sizeof(IMGHEAD)];
1344 
1345  for (ObjId = 1;ObjId <= NoOfObj;ObjId++)
1346  {
1347  Bytes = (Bytes + 3) & 0xFFFFFFFC;
1348  Bytes += sizeof(OBJ) + (*pHead).LocalBytes;
1349  pHead++;
1350  }
1351 
1352  Bytes = 0;
1353 
1354  NoOfObj = (*(IMGHEAD*)pI).NumberOfObjects;
1355 
1356  Bytes += (*(IMGHEAD*)pI).GlobalBytes;
1357  Bytes = (Bytes + 3) & 0xFFFFFFFC;
1358  Bytes += sizeof(VMInstance.pObjList) * (NoOfObj + 1);
1359 
1360  pHead = (OBJHEAD*)&pI[sizeof(IMGHEAD) - sizeof(OBJHEAD)];
1361 
1362  for (ObjId = 1;ObjId <= NoOfObj;ObjId++)
1363  {
1364  Bytes = (Bytes + 3) & 0xFFFFFFFC;
1365  Bytes += sizeof(OBJ) + pHead[ObjId].LocalBytes;
1366  }
1367 
1368  return (Bytes);
1369 }
1370 
1371 
1381 RESULT ProgramReset(PRGID PrgId,IP pI,GP pG,UBYTE Deb)
1382 {
1383 
1384  RESULT Result = FAIL;
1385  GBINDEX Index;
1386  GBINDEX RamSize;
1387  VARDATA *pData;
1388  OBJID ObjIndex;
1389  DATA8 No;
1390 
1391  VMInstance.Program[PrgId].Status = STOPPED;
1392  VMInstance.Program[PrgId].StatusChange = STOPPED;
1393  VMInstance.Program[PrgId].Result = FAIL;
1394 
1395  if (pI != NULL)
1396  {
1397 
1398  // Allocate memory for globals and objects
1399 
1400  RamSize = GetAmountOfRamForImage(pI);
1401 
1402  if (cMemoryOpen(PrgId,RamSize,(void**)&pData) == OK)
1403  { // Memory reserved
1404 
1405  // Save start of image
1406  if (Deb == 1)
1407  {
1408  VMInstance.Program[PrgId].Debug = 1;
1409  }
1410  else
1411  {
1412  VMInstance.Program[PrgId].Debug = 0;
1413  }
1414  VMInstance.Program[PrgId].pImage = pI;
1415 
1416  if (cValidateProgram(PrgId,pI,VMInstance.Program[PrgId].Label,VMInstance.TerminalEnabled) != OK)
1417  {
1418  if (PrgId != CMD_SLOT)
1419  {
1421  }
1422  }
1423  else
1424  {
1425 
1426  // Clear memory
1427 
1428  for (Index = 0;Index < RamSize;Index++)
1429  {
1430  pData[Index] = 0;
1431  }
1432 
1433  for (No = 0;No < MAX_BREAKPOINTS;No++)
1434  {
1435  VMInstance.Program[PrgId].Brkp[No].Addr = 0;
1436  VMInstance.Program[PrgId].Brkp[No].OpCode = 0;
1437  }
1438 
1439  // Get VMInstance.Objects
1440 
1441  VMInstance.Program[PrgId].Objects = (*(IMGHEAD*)pI).NumberOfObjects;
1442 
1443  // Allocate GlobalVariables
1444 
1445  VMInstance.Program[PrgId].pData = pData;
1446  if (pG != NULL)
1447  {
1448  VMInstance.Program[PrgId].pGlobal = pG;
1449  }
1450  else
1451  {
1452  VMInstance.Program[PrgId].pGlobal = pData;
1453  }
1454 
1455  pData = &pData[(*(IMGHEAD*)pI).GlobalBytes];
1456 
1457  // Align & allocate ObjectPointerList (+1)
1458 
1459  pData = (VARDATA*)(((ULONG)pData + 3) & 0xFFFFFFFC);
1460  VMInstance.Program[PrgId].pObjList = (OBJ**)pData;
1461  pData = &pData[sizeof(VMInstance.Program[PrgId].pObjList) * (VMInstance.Program[PrgId].Objects + 1)];
1462 
1463  // Make pointer to access object headers starting at one (not zero)
1464 
1465  VMInstance.Program[PrgId].pObjHead = (OBJHEAD*)&pI[sizeof(IMGHEAD) - sizeof(OBJHEAD)];
1466 
1467  for (ObjIndex = 1;ObjIndex <= VMInstance.Program[PrgId].Objects;ObjIndex++)
1468  {
1469  // Align
1470 
1471  pData = (VARDATA*)(((ULONG)pData + 3) & 0xFFFFFFFC);
1472 
1473  // Save object pointer in Object list
1474 
1475  VMInstance.Program[PrgId].pObjList[ObjIndex] = (OBJ*)pData;
1476 
1477  // Initialise instruction pointer, trigger counts and status
1478 
1479  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).Ip = &pI[(ULONG)VMInstance.Program[PrgId].pObjHead[ObjIndex].OffsetToInstructions];
1480 
1481  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).u.TriggerCount = VMInstance.Program[PrgId].pObjHead[ObjIndex].TriggerCount;
1482 
1483  if (((*VMInstance.Program[PrgId].pObjList[ObjIndex]).u.TriggerCount) || (ObjIndex > 1))
1484  {
1485  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).ObjStatus = STOPPED;
1486  }
1487  else
1488  {
1489  if (Deb == 2)
1490  {
1491  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).ObjStatus = WAITING;
1492  }
1493  else
1494  {
1495  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).ObjStatus = RUNNING;
1496  }
1497  }
1498 
1499 #ifndef DISABLE_NEW_CALL_MUTEX
1500  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).Blocked = 0;
1501 #endif
1502  if (VMInstance.Program[PrgId].pObjHead[ObjIndex].OwnerObjectId)
1503  {
1504  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).pLocal = (*VMInstance.Program[PrgId].pObjList[VMInstance.Program[PrgId].pObjHead[ObjIndex].OwnerObjectId]).Local;
1505  }
1506  else
1507  {
1508  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).pLocal = (*VMInstance.Program[PrgId].pObjList[ObjIndex]).Local;
1509  }
1510 
1511  // Advance data pointer
1512 
1513  pData = &pData[sizeof(OBJ) + VMInstance.Program[PrgId].pObjHead[ObjIndex].LocalBytes];
1514  }
1515 
1516  VMInstance.Program[PrgId].ObjectId = 1;
1517  VMInstance.Program[PrgId].Status = RUNNING;
1518  VMInstance.Program[PrgId].StatusChange = RUNNING;
1519 
1520  VMInstance.Program[PrgId].Result = BUSY;
1521 
1522  Result = OK;
1523 
1524  if (PrgId == USER_SLOT)
1525  {
1526 
1527  if (VMInstance.RefCount == 0)
1528  {
1529  Result = 0;
1530  Result |= cUiOpen();
1531  Result |= cOutputOpen();
1532  Result |= cInputOpen();
1533  Result |= cComOpen();
1534  Result |= cSoundOpen();
1535  }
1536  VMInstance.RefCount++;
1537  }
1538  VMInstance.Program[PrgId].InstrCnt = 0;
1539  VMInstance.Program[PrgId].StartTime = GetTimeMS();
1540  VMInstance.Program[PrgId].RunTime = cTimerGetuS();
1541  }
1542  }
1543  }
1544 
1545  return (Result);
1546 }
1547 
1548 
1555 void ProgramEnd(PRGID PrgId)
1556 {
1557  if (VMInstance.Program[PrgId].Status != STOPPED)
1558  {
1559 
1560  VMInstance.Program[PrgId].InstrTime = cTimerGetuS() - VMInstance.Program[PrgId].RunTime;
1561 
1562  VMInstance.Program[PrgId].Objects = 0;
1563  VMInstance.Program[PrgId].Status = STOPPED;
1564  VMInstance.Program[PrgId].StatusChange = STOPPED;
1565  if (PrgId != 0)
1566  {
1567  if (PrgId != VMInstance.ProgramId)
1568  {
1569  VMInstance.Program[PrgId].InstrCnt += VMInstance.InstrCnt;
1570  }
1571  }
1572 
1573  if (PrgId == USER_SLOT)
1574  {
1575  if (VMInstance.RefCount)
1576  {
1577  VMInstance.RefCount--;
1578  }
1579  if (VMInstance.RefCount == 0)
1580  {
1581  cSoundClose();
1582  cComClose();
1583  cInputClose();
1584  cOutputClose();
1585  cUiClose();
1586  }
1587  }
1588 
1589  cMemoryClose(PrgId);
1590 
1591  if (PrgId == VMInstance.ProgramId)
1592  {
1594  }
1595 
1596  VMInstance.Program[PrgId].Result = OK;
1597  }
1598 }
1599 
1600 
1605 void ProgramInit(void)
1606 {
1607  PRG *pProgram;
1608 
1609  if (VMInstance.ProgramId < MAX_PROGRAMS)
1610  {
1611  pProgram = &VMInstance.Program[VMInstance.ProgramId];
1612 
1613  if (((*pProgram).Status == RUNNING) || ((*pProgram).Status == WAITING))
1614  {
1615  VMInstance.pGlobal = (*pProgram).pGlobal;
1616  VMInstance.pImage = (*pProgram).pImage;
1617  VMInstance.pObjHead = (*pProgram).pObjHead;
1618  VMInstance.pObjList = (*pProgram).pObjList;
1619  VMInstance.Objects = (*pProgram).Objects;
1620  VMInstance.ObjectId = (*pProgram).ObjectId;
1621  VMInstance.ObjectIp = (*pProgram).ObjectIp;
1622  VMInstance.ObjectLocal = (*pProgram).ObjectLocal;
1623  VMInstance.InstrCnt = 0;
1624  VMInstance.Debug = (*pProgram).Debug;
1625 
1626  }
1627  }
1628 }
1629 
1630 
1635 void ProgramExit(void)
1636 {
1637  PRG *pProgram;
1638 
1639  if (VMInstance.ProgramId < MAX_PROGRAMS)
1640  {
1641  pProgram = &VMInstance.Program[VMInstance.ProgramId];
1642  (*pProgram).pGlobal = VMInstance.pGlobal;
1643  (*pProgram).pImage = VMInstance.pImage;
1644  (*pProgram).pObjHead = VMInstance.pObjHead;
1645  (*pProgram).pObjList = VMInstance.pObjList;
1646  (*pProgram).Objects = VMInstance.Objects;
1647  (*pProgram).ObjectId = VMInstance.ObjectId;
1648  (*pProgram).ObjectIp = VMInstance.ObjectIp;
1649  (*pProgram).ObjectLocal = VMInstance.ObjectLocal;
1650  (*pProgram).InstrCnt += VMInstance.InstrCnt;
1651  (*pProgram).Debug = VMInstance.Debug;
1652 
1653  VMInstance.InstrCnt = 0;
1654  (*pProgram).Debug = VMInstance.Debug;
1655  }
1656 }
1657 
1658 
1664 RESULT ProgramExec(void)
1665 {
1666  RESULT Result = STOP;
1667  OBJID TmpId = 0;
1668 
1669 
1670  for (TmpId = 0;(TmpId < MAX_PROGRAMS) && (Result == STOP);TmpId++)
1671  {
1672  if (VMInstance.Program[TmpId].Status != STOPPED)
1673  {
1674  Result = OK;
1675  }
1676  }
1677  if (Result == OK)
1678  {
1679  do
1680  {
1681  // next program
1682 
1683  if (++VMInstance.ProgramId >= MAX_PROGRAMS)
1684  {
1685  // wrap around
1686 
1687  VMInstance.ProgramId = 0;
1688  }
1689 
1690  }
1691  while (VMInstance.Program[VMInstance.ProgramId].Status == STOPPED);
1692  }
1693 
1694 
1695  return (Result);
1696 }
1697 
1698 
1711 {
1712  DSPSTAT Result = STOPBREAK;
1713 
1714  if ((VMInstance.ObjectId > 0) && (VMInstance.ObjectId <= VMInstance.Objects))
1715  { // object valid
1716 
1717  if ((*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus == RUNNING)
1718  { // Restore object context
1719 
1720  VMInstance.ObjectIp = (*VMInstance.pObjList[VMInstance.ObjectId]).Ip;
1721 
1722  VMInstance.ObjectLocal = (*VMInstance.pObjList[VMInstance.ObjectId]).pLocal;
1723 
1724  Result = NOBREAK;
1725  }
1726  }
1727 
1728  if((VMInstance.ProgramId == GUI_SLOT) || (VMInstance.ProgramId == DEBUG_SLOT))
1729  { // UI
1730 
1731  VMInstance.Priority = UI_PRIORITY;
1732  }
1733  else
1734  { // user program
1735 
1736  VMInstance.Priority = PRG_PRIORITY;
1737  }
1738 
1739  return (Result);
1740 }
1741 
1742 
1753 void ObjectExit(void)
1754 {
1755  if ((VMInstance.ObjectId > 0) && (VMInstance.ObjectId <= VMInstance.Objects) && (VMInstance.Program[VMInstance.ProgramId].Status != STOPPED))
1756  { // object valid
1757 
1758  if ((*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus == RUNNING)
1759  { // Save object context
1760 
1761  (*VMInstance.pObjList[VMInstance.ObjectId]).Ip = VMInstance.ObjectIp;
1762  }
1763  }
1764 }
1765 
1766 
1774 RESULT ObjectExec(void)
1775 {
1776  RESULT Result = OK;
1777  OBJID TmpId = 0;
1778 
1779 
1780  if ((VMInstance.ProgramId == GUI_SLOT) && (VMInstance.Program[USER_SLOT].Status != STOPPED))
1781  { // When user program is running - only schedule UI background task
1782 
1783  if ((VMInstance.Objects>= 3) && (VMInstance.Program[GUI_SLOT].Status != STOPPED))
1784  {
1785  if (VMInstance.ObjectId != 2)
1786  {
1787  VMInstance.ObjectId = 2;
1788  }
1789  else
1790  {
1791  VMInstance.ObjectId = 3;
1792  }
1793  }
1794  }
1795  else
1796  {
1797  do
1798  {
1799  // Next object
1800  if (++VMInstance.ObjectId > VMInstance.Objects)
1801  {
1802  // wrap around
1803 
1804  VMInstance.ObjectId = 1;
1805  }
1806 
1807  if (++TmpId > VMInstance.Objects)
1808  {
1809  // no programs running
1810 
1811  Result = STOP;
1812  }
1813 
1814  }
1815  while ((Result == OK) && ((*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus != RUNNING));
1816  }
1817 
1818  return (Result);
1819 }
1820 
1821 
1828 {
1829  if ((Id > 0) && (Id <= VMInstance.Objects))
1830  {
1831  (*VMInstance.pObjList[Id]).ObjStatus = RUNNING;
1832  (*VMInstance.pObjList[Id]).Ip = &VMInstance.pImage[(ULONG)VMInstance.pObjHead[Id].OffsetToInstructions];
1833  (*VMInstance.pObjList[Id]).u.TriggerCount = VMInstance.pObjHead[Id].TriggerCount;
1834  }
1835 }
1836 
1837 
1844 {
1845  if ((Id > 0) && (Id <= VMInstance.Objects))
1846  {
1847  (*VMInstance.pObjList[Id]).Ip = VMInstance.ObjectIp;
1848  (*VMInstance.pObjList[Id]).ObjStatus = STOPPED;
1849 
1851  }
1852 }
1853 
1854 
1855 DATA8 CheckSdcard(DATA8 *pChanged,DATA32 *pTotal,DATA32 *pFree,DATA8 Force)
1856 {
1857  DATA8 Result = 0;
1858  DATAF Tmp;
1859  char Name[vmNAMESIZE];
1860  char Buffer[250];
1861 
1862  *pChanged = 0;
1863  *pTotal = 0;
1864  *pFree = 0;
1865 
1866 #ifndef DISABLE_SDCARD_SUPPORT
1867  ULONG Time;
1868  struct statvfs Status;
1869 
1870  Time = VMInstance.NewTime - VMInstance.SdcardTimer;
1871 
1872  if ((Time >= UPDATE_SDCARD) || (VMInstance.SdcardTimer == 0) || (Force))
1873  { // Update values
1874 
1875  VMInstance.SdcardTimer += Time;
1876 
1877  if (cMemoryGetMediaName("m",Name) == OK)
1878  {
1879  if (VMInstance.SdcardOk == 0)
1880  {
1881  VMInstance.SdcardOk = 1;
1882  snprintf(Buffer,250,"ln -s /media/card %s &> /dev/null",vmSDCARD_FOLDER);
1883  system(Buffer);
1884  sync();
1885  *pChanged = 1;
1886 #ifdef DEBUG_SDCARD
1887  printf("system(%s)\r\n",Buffer);
1888 #endif
1889  }
1890  snprintf(Buffer,250,"/media/card");
1891  statvfs(Buffer,&Status);
1892 #ifdef DEBUG_SDCARD
1893  if (*pChanged)
1894  {
1895  printf("statvfs(%s)\r\n",Buffer);
1896 
1897  printf("f_bsize %ld\r\n",Status.f_bsize);
1898  printf("f_frsize %ld\r\n",Status.f_frsize);
1899  printf("f_blocks %ld\r\n",Status.f_blocks);
1900  printf("f_bavail %ld\r\n",Status.f_bavail);
1901  printf("f_files %ld\r\n",Status.f_files);
1902  printf("f_ffree %ld\r\n",Status.f_ffree);
1903  printf("f_favail %ld\r\n",Status.f_favail);
1904  printf("f_fside %ld\r\n",Status.f_fsid);
1905  printf("f_flag %ld\r\n",Status.f_flag);
1906  printf("f_namemax %ld\r\n",Status.f_namemax);
1907  }
1908 #endif
1909  Tmp = (DATAF)Status.f_blocks;
1910  Tmp = (Tmp + (DATAF)(KB - 1)) / (DATAF)KB;
1911  Tmp *= (DATAF)Status.f_bsize;
1912  VMInstance.SdcardSize = (DATA32)Tmp;
1913  Tmp = (DATAF)Status.f_bavail;
1914  Tmp = (Tmp + (DATAF)(KB - 1)) / (DATAF)KB;
1915  Tmp *= (DATAF)Status.f_bsize;
1916 
1917 #ifdef DEBUG_SDCARD
1918  if(VMInstance.SdcardFree != (DATA32)Tmp)
1919  {
1920  printf("%d T=%-8d F=%-8d\r\n",VMInstance.SdcardOk,VMInstance.SdcardSize,VMInstance.SdcardFree);
1921  }
1922 #endif
1923  VMInstance.SdcardFree = (DATA32)Tmp;
1924  }
1925  else
1926  {
1927  if (VMInstance.SdcardOk == 1)
1928  {
1929  VMInstance.SdcardOk = 0;
1930  snprintf(Buffer,250,"rm -r %s &> /dev/null",vmSDCARD_FOLDER);
1931  system(Buffer);
1932  *pChanged = 1;
1933 #ifdef DEBUG_SDCARD
1934  if (*pChanged)
1935  {
1936  printf("system(%s)\r\n",Buffer);
1937  }
1938 #endif
1939  }
1940  VMInstance.SdcardSize = 0;
1941  VMInstance.SdcardFree = 0;
1942  }
1943 #ifdef DEBUG_SDCARD
1944  if (*pChanged)
1945  {
1946  printf("%d T=%-8d F=%-8d\r\n",VMInstance.SdcardOk,VMInstance.SdcardSize,VMInstance.SdcardFree);
1947  }
1948 #endif
1949  }
1950  *pTotal = VMInstance.SdcardSize;
1951  *pFree = VMInstance.SdcardFree;
1952  Result = VMInstance.SdcardOk;
1953 #endif
1954 
1955  return (Result);
1956 }
1957 
1958 
1959 DATA8 CheckUsbstick(DATA8 *pChanged,DATA32 *pTotal,DATA32 *pFree,DATA8 Force)
1960 {
1961  DATA8 Result = 0;
1962 
1963  *pChanged = 0;
1964  *pTotal = 0;
1965  *pFree = 0;
1966 
1967 #ifndef DISABLE_USBSTICK_SUPPORT
1968  ULONG Time;
1969  struct statvfs Status;
1970  DATAF Tmp;
1971  char Name[vmNAMESIZE];
1972  char Buffer[250];
1973 
1974  Time = VMInstance.NewTime - VMInstance.UsbstickTimer;
1975 
1976  if ((Time >= UPDATE_USBSTICK) || (VMInstance.UsbstickTimer == 0) || (Force))
1977  { // Update values
1978 
1979  VMInstance.UsbstickTimer += Time;
1980 
1981  if (cMemoryGetMediaName("s",Name) == OK)
1982  {
1983  if (VMInstance.UsbstickOk == 0)
1984  {
1985  VMInstance.UsbstickOk = 1;
1986  snprintf(Buffer,250,"ln -s /media/usb %s &> /dev/null",vmUSBSTICK_FOLDER);
1987  system(Buffer);
1988  sync();
1989  *pChanged = 1;
1990 #ifdef DEBUG_USBSTICK
1991  printf("system(%s)\r\n",Buffer);
1992 #endif
1993  }
1994  snprintf(Buffer,250,"/media/usb");
1995  statvfs(Buffer,&Status);
1996 #ifdef DEBUG_USBSTICK
1997  if (*pChanged)
1998  {
1999  printf("statvfs(%s)\r\n",Buffer);
2000 
2001  printf("f_bsize %ld\r\n",Status.f_bsize);
2002  printf("f_frsize %ld\r\n",Status.f_frsize);
2003  printf("f_blocks %ld\r\n",Status.f_blocks);
2004  printf("f_bavail %ld\r\n",Status.f_bavail);
2005  printf("f_files %ld\r\n",Status.f_files);
2006  printf("f_ffree %ld\r\n",Status.f_ffree);
2007  printf("f_favail %ld\r\n",Status.f_favail);
2008  printf("f_fside %ld\r\n",Status.f_fsid);
2009  printf("f_flag %ld\r\n",Status.f_flag);
2010  printf("f_namemax %ld\r\n",Status.f_namemax);
2011  }
2012 #endif
2013  Tmp = (DATAF)Status.f_blocks;
2014  Tmp = (Tmp + (DATAF)(KB - 1)) / (DATAF)KB;
2015  Tmp *= (DATAF)Status.f_bsize;
2016  VMInstance.UsbstickSize = (DATA32)Tmp;
2017  Tmp = (DATAF)Status.f_bavail;
2018  Tmp = (Tmp + (DATAF)(KB - 1)) / (DATAF)KB;
2019  Tmp *= (DATAF)Status.f_bsize;
2020 
2021 #ifdef DEBUG_USBSTICK
2022  if(VMInstance.UsbstickFree != (DATA32)Tmp)
2023  {
2024  printf("%d T=%-8d F=%-8d\r\n",VMInstance.UsbstickOk,VMInstance.UsbstickSize,VMInstance.UsbstickFree);
2025  }
2026 #endif
2027  VMInstance.UsbstickFree = (DATA32)Tmp;
2028  }
2029  else
2030  {
2031  if (VMInstance.UsbstickOk == 1)
2032  {
2033  VMInstance.UsbstickOk = 0;
2034  snprintf(Buffer,250,"rm -r %s &> /dev/null",vmUSBSTICK_FOLDER);
2035  system(Buffer);
2036  *pChanged = 1;
2037 #ifdef DEBUG_USBSTICK
2038  if (*pChanged)
2039  {
2040  printf("system(%s)\r\n",Buffer);
2041  }
2042 #endif
2043  }
2044  VMInstance.UsbstickSize = 0;
2045  VMInstance.UsbstickFree = 0;
2046  }
2047 #ifdef DEBUG_USBSTICK
2048 // if (*pChanged)
2049  {
2050  printf("%d T=%-8d F=%-8d\r\n",VMInstance.UsbstickOk,VMInstance.UsbstickSize,VMInstance.UsbstickFree);
2051  }
2052 #endif
2053  }
2054  *pTotal = VMInstance.UsbstickSize;
2055  *pFree = VMInstance.UsbstickFree;
2056  Result = VMInstance.UsbstickOk;
2057 #endif
2058 
2059  return (Result);
2060 }
2061 
2062 
2063 RESULT mSchedInit(int argc,char *argv[])
2064 {
2065  DATA32 Result = OK;
2066  PRGID PrgId;
2067  IMGHEAD *pImgHead;
2068  DATA16 Loop;
2069  DATA8 Ok;
2070  DATA32 Total;
2071  DATA32 Free;
2072  float Tmp;
2073  int File;
2074  char PrgNameBuf[vmFILENAMESIZE];
2075  char ParBuf[255];
2076 
2077 #ifndef Linux_X86
2078  struct timeval tv;
2079 #endif
2080 
2081 #ifdef ENABLE_STATUS_TEST
2082  VMInstance.Status = 0x00;
2083 #endif
2084 
2085 #ifndef DISABLE_PREEMPTED_VM
2086  ANALOG *pAdcTmp;
2087 
2088  VMInstance.pAnalog = &VMInstance.Analog;
2089  VMInstance.AdcFile = open(ANALOG_DEVICE_NAME,O_RDWR | O_SYNC);
2090 
2091  if (VMInstance.AdcFile >= MIN_HANDLE)
2092  {
2093  pAdcTmp = (ANALOG*)mmap(0, sizeof(ANALOG), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, VMInstance.AdcFile, 0);
2094 
2095  if (pAdcTmp == MAP_FAILED)
2096  {
2097 //#ifndef Linux_X86
2099 //#endif
2100  }
2101  else
2102  {
2103  VMInstance.pAnalog = pAdcTmp;
2104  }
2105  close(VMInstance.AdcFile);
2106  }
2107  else
2108  {
2109 //#ifndef Linux_X86
2111 //#endif
2112  }
2113 #endif
2114 
2115  // Reset time
2116 #ifndef Linux_X86
2117  tv.tv_sec = 0;
2118  tv.tv_usec = 0;
2119  settimeofday(&tv,NULL);
2120 #endif
2121 
2122  // Fill holes in PrimDispatchTabel
2123  for (Loop = 0;Loop < PRIMDISPATHTABLE_SIZE;Loop++)
2124  {
2125  if (PrimDispatchTabel[Loop] == NULL)
2126  {
2127  PrimDispatchTabel[Loop] = &Error;
2128  }
2129  }
2130 
2131  // Be sure necessary folders exist
2132  if (mkdir(vmSETTINGS_DIR,DIRPERMISSIONS) == 0)
2133  {
2134  chmod(vmSETTINGS_DIR,DIRPERMISSIONS);
2135  }
2136 
2137  CheckUsbstick(&Ok,&Total,&Free,0);
2138  CheckSdcard(&Ok,&Total,&Free,0);
2139 
2140  // Be sure necessary files exist
2141  Ok = 0;
2142  snprintf(PrgNameBuf,vmFILENAMESIZE,"%s/%s%s",vmSETTINGS_DIR,vmWIFI_FILE_NAME,vmEXT_TEXT);
2143  File = open(PrgNameBuf,O_CREAT | O_WRONLY | O_TRUNC,SYSPERMISSIONS);
2144  if (File >= MIN_HANDLE)
2145  {
2146  sprintf(ParBuf,"-\t");
2147  write(File,ParBuf,strlen(ParBuf));
2148  close(File);
2149  }
2150 
2151  Ok = 0;
2152  snprintf(PrgNameBuf,vmFILENAMESIZE,"%s/%s%s",vmSETTINGS_DIR,vmBLUETOOTH_FILE_NAME,vmEXT_TEXT);
2153  File = open(PrgNameBuf,O_RDONLY);
2154  if (File >= MIN_HANDLE)
2155  {
2156  close(File);
2157  }
2158  else
2159  {
2160  File = open(PrgNameBuf,O_CREAT | O_WRONLY | O_TRUNC,SYSPERMISSIONS);
2161  if (File >= MIN_HANDLE)
2162  {
2163  sprintf(ParBuf,"-\t");
2164  write(File,ParBuf,strlen(ParBuf));
2165  close(File);
2166  }
2167  }
2168 
2169  Ok = 0;
2170  snprintf(PrgNameBuf,vmFILENAMESIZE,"%s/%s%s",vmSETTINGS_DIR,vmSLEEP_FILE_NAME,vmEXT_TEXT);
2171  File = open(PrgNameBuf,O_RDONLY);
2172  if (File >= MIN_HANDLE)
2173  {
2174  ParBuf[0] = 0;
2175  read(File,ParBuf,sizeof(ParBuf));
2176  if (sscanf(ParBuf,"%f",&Tmp) > 0)
2177  {
2178  if ((Tmp >= (float)0) && (Tmp <= (float)127))
2179  {
2180  SetSleepMinutes((DATA8)Tmp);
2181  Ok = 1;
2182  }
2183  }
2184  else
2185  {
2186  ParBuf[5] = 0;
2187  if (strcmp(ParBuf,"never") == 0)
2188  {
2189  SetSleepMinutes(0);
2190  Ok = 1;
2191  }
2192  }
2193  close(File);
2194  }
2195  if (!Ok)
2196  {
2197  File = open(PrgNameBuf,O_CREAT | O_WRONLY | O_TRUNC,SYSPERMISSIONS);
2198  if (File >= MIN_HANDLE)
2199  {
2200  SetSleepMinutes((DATA8)DEFAULT_SLEEPMINUTES);
2201  sprintf(ParBuf,"%dmin\t",DEFAULT_SLEEPMINUTES);
2202  write(File,ParBuf,strlen(ParBuf));
2203  close (File);
2204  }
2205  }
2206 
2207  Ok = 0;
2208  snprintf(PrgNameBuf,vmFILENAMESIZE,"%s/%s%s",vmSETTINGS_DIR,vmVOLUME_FILE_NAME,vmEXT_TEXT);
2209  File = open(PrgNameBuf,O_RDONLY);
2210  if (File >= MIN_HANDLE)
2211  {
2212  ParBuf[0] = 0;
2213  read(File,ParBuf,sizeof(ParBuf));
2214  if (sscanf(ParBuf,"%f",&Tmp) > 0)
2215  {
2216  if ((Tmp >= (float)0) && (Tmp <= (float)100))
2217  {
2218  SetVolumePercent((DATA8)Tmp);
2219  Ok = 1;
2220  }
2221  }
2222  close (File);
2223  }
2224 #ifdef DISABLE_SOUND
2225  SetVolumePercent((DATA8)0);
2226  File = open(PrgNameBuf,O_CREAT | O_WRONLY | O_TRUNC,SYSPERMISSIONS);
2227  if (File >= MIN_HANDLE)
2228  {
2229  sprintf(ParBuf,"%d%%\t",0);
2230  write(File,ParBuf,strlen(ParBuf));
2231  close (File);
2232  }
2233 #else
2234  if (!Ok)
2235  {
2236  SetVolumePercent((DATA8)DEFAULT_VOLUME);
2237  File = open(PrgNameBuf,O_CREAT | O_WRONLY | O_TRUNC,SYSPERMISSIONS);
2238  if (File >= MIN_HANDLE)
2239  {
2240  sprintf(ParBuf,"%d%%\t",DEFAULT_VOLUME);
2241  write(File,ParBuf,strlen(ParBuf));
2242  close (File);
2243  }
2244  }
2245 #endif
2246 
2247  VMInstance.RefCount = 0;
2248 
2249  Result |= cOutputInit();
2250  Result |= cInputInit();
2251  Result |= cUiInit();
2252  Result |= cMemoryInit();
2253  Result |= cComInit();
2254  Result |= cSoundInit();
2255 
2256  cValidateInit();
2257 
2258  for (PrgId = 0;PrgId < MAX_PROGRAMS;PrgId++)
2259  {
2260  VMInstance.Program[PrgId].Status = STOPPED;
2261  VMInstance.Program[PrgId].StatusChange = 0;
2262  }
2263 
2264  SetTerminalEnable(TERMINAL_ENABLED);
2265 
2266  VMInstance.Test = 0;
2267 
2268  VmPrint("\r\n\n\n\n\n\nLMS2012 VM STARTED\r\n{\r\n");
2269  VMInstance.ProgramId = DEBUG_SLOT;
2270  pImgHead = (IMGHEAD*)UiImage;
2271  (*pImgHead).ImageSize = sizeof(UiImage);
2272 
2273 #if (HARDWARE != SIMULATION)
2274  openlog(PROJECT,LOG_NDELAY,LOG_USER);
2275  syslog(LOG_INFO,"VM Started");
2276 
2277  if (argc >= 2)
2278  {
2279  snprintf((char*)VMInstance.FirstProgram,MAX_FILENAME_SIZE,"%s",argv[1]);
2280  }
2281  else
2282  {
2283  snprintf((char*)VMInstance.FirstProgram,MAX_FILENAME_SIZE,DEFAULT_UI);
2284  }
2285 
2286 #else
2287  //TBD
2288 #endif
2289 
2290  ProgramReset(VMInstance.ProgramId,UiImage,(GP)VMInstance.FirstProgram,0);
2291 
2292  return (RESULT)(Result);
2293 }
2294 
2295 
2296 RESULT mSchedCtrl(UBYTE *pRestart)
2297 {
2298  RESULT Result = FAIL;
2299  ULONG Time;
2300  IP TmpIp;
2301 #ifdef DEBUG_TRACE_VM
2302  IMINDEX Index;
2303 #endif
2304 #ifdef DEBUG_TRACE_FREEZE
2305  static ULONG Timer;
2306  IMINDEX Addr;
2307 #endif
2308 
2309 
2310  if (VMInstance.DispatchStatus != STOPBREAK)
2311  {
2312  ProgramInit();
2313  }
2314 
2316 
2317 #ifdef DEBUG_TRACE_TASK
2318  if (VMInstance.Program[USER_SLOT].Status != STOPPED)
2319  {
2320  printf("\r\n %d %2d",VMInstance.ProgramId,VMInstance.ObjectId);
2321  }
2322 #endif
2323 
2324 #ifdef ENABLE_PERFORMANCE_TEST
2325  Time = cTimerGetuS();
2326  Time -= VMInstance.PerformTimer;
2327  VMInstance.PerformTime *= (DATAF)199;
2328  VMInstance.PerformTime += (DATAF)Time;
2329  VMInstance.PerformTime /= (DATAF)200;
2330 #endif
2331 
2332 /*** Execute BYTECODES *******************************************************/
2333 
2334 #ifdef DEBUG_BYTECODE_TIME
2335  VMInstance.InstrCnt = 0;
2336 #endif
2337 
2338 #ifndef DISABLE_PREEMPTED_VM
2339  (*VMInstance.pAnalog).PreemptMilliSeconds = 0;
2340 
2341  while ((VMInstance.Priority) && ((*VMInstance.pAnalog).PreemptMilliSeconds < 2))
2342 #else
2343  while (VMInstance.Priority)
2344 #endif
2345  {
2346  if (VMInstance.Debug)
2347  {
2348  Monitor();
2349  }
2350  else
2351  {
2352  VMInstance.Priority--;
2353 #ifdef DEBUG_TRACE_VM
2354  if (VMInstance.ProgramId != GUI_SLOT)
2355  {
2356  Index = (IMINDEX)VMInstance.ObjectIp - (IMINDEX)VMInstance.pImage;
2357  cValidateDisassemble(VMInstance.pImage,&Index,VMInstance.Program[VMInstance.ProgramId].Label);
2358  }
2359 #endif
2360  PrimDispatchTabel[*(VMInstance.ObjectIp++)]();
2361  VMInstance.InstrCnt++;
2362 #ifdef DEBUG_TRACE_TASK
2363  if (VMInstance.Program[USER_SLOT].Status != STOPPED)
2364  {
2365  printf(".");
2366  }
2367 #endif
2368  }
2369  }
2370 
2371 /*****************************************************************************/
2372 
2373 #ifdef ENABLE_PERFORMANCE_TEST
2374  VMInstance.PerformTimer = cTimerGetuS();
2375 #endif
2376 
2377  VMInstance.NewTime = GetTimeMS();
2378 
2379  Time = VMInstance.NewTime - VMInstance.OldTime1;
2380 
2381  if (Time >= UPDATE_TIME1)
2382  {
2383  VMInstance.OldTime1 += Time;
2384 
2385 #ifdef DEBUG_BYTECODE_TIME
2386 #ifndef DISABLE_PREEMPTED_VM
2387  if (Time >= 3)
2388  {
2389  printf("%-6d %-3d %-3d\r\n",Time,(*VMInstance.pAnalog).PreemptMilliSeconds,VMInstance.InstrCnt);
2390  }
2391 #else
2392  if (Time >= 3)
2393  {
2394  printf("%-6d %-3d\r\n",Time,VMInstance.InstrCnt);
2395  }
2396 #endif
2397 #endif
2398  cComUpdate();
2399  cSoundUpdate();
2400  }
2401 
2402 
2403  Time = VMInstance.NewTime - VMInstance.OldTime2;
2404 
2405  if (Time >= UPDATE_TIME2)
2406  {
2407  VMInstance.OldTime2 += Time;
2408 
2409 #ifdef DEBUG_TRACE_FREEZE
2410 
2411  Timer += Time;
2412  if (Timer >= 100)
2413  {
2414  Timer -= 100;
2415  Addr = (IMINDEX)VMInstance.ObjectIp - (IMINDEX)VMInstance.pImage;
2416 
2417  printf("%10.3f P=%-1d A=%5d \r\n",(float)VMInstance.NewTime / (float)1000,VMInstance.ProgramId,Addr);
2418 
2419  }
2420 #endif
2421  usleep(10);
2422  cInputUpdate((UWORD)Time);
2423  cUiUpdate((UWORD)Time);
2424 
2425  if (VMInstance.Test)
2426  {
2427  if (VMInstance.Test > (UWORD)Time)
2428  {
2429  VMInstance.Test -= (UWORD)Time;
2430  }
2431  else
2432  {
2433  TstClose();
2434  }
2435  }
2436  }
2437 
2438  if (VMInstance.DispatchStatus == FAILBREAK)
2439  {
2440  if (VMInstance.ProgramId != GUI_SLOT)
2441  {
2442  if (VMInstance.ProgramId != CMD_SLOT)
2443  {
2444  UiInstance.Warning |= WARNING_DSPSTAT;
2445  }
2446  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"}\r\nPROGRAM \"%d\" FAIL BREAK just before %lu!\r\n",VMInstance.ProgramId,(unsigned long)(VMInstance.ObjectIp - VMInstance.Program[VMInstance.ProgramId].pImage));
2447  VmPrint(VMInstance.PrintBuffer);
2448  ProgramEnd(VMInstance.ProgramId);
2449  VMInstance.Program[VMInstance.ProgramId].Result = FAIL;
2450  }
2451  else
2452  {
2453  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"UI FAIL BREAK just before %lu!\r\n",(unsigned long)(VMInstance.ObjectIp - VMInstance.Program[VMInstance.ProgramId].pImage));
2454  VmPrint(VMInstance.PrintBuffer);
2456  *pRestart = 1;
2457  }
2458  }
2459  else
2460  {
2461 
2462  if (VMInstance.DispatchStatus == INSTRBREAK)
2463  {
2464  if (VMInstance.ProgramId != CMD_SLOT)
2465  {
2467  }
2468  TmpIp = VMInstance.ObjectIp - 1;
2469  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"\r\n%4u [%2d] ",(UWORD)(((ULONG)TmpIp) - (ULONG)VMInstance.pImage),VMInstance.ObjectId);
2470  VmPrint(VMInstance.PrintBuffer);
2471  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"VM ERROR [0x%02X]\r\n",*TmpIp);
2472  VmPrint(VMInstance.PrintBuffer);
2473  VMInstance.Program[VMInstance.ProgramId].Result = FAIL;
2474  }
2475 
2476  ObjectExit();
2477 
2478  Result = ObjectExec();
2479 
2480  if (Result == STOP)
2481  {
2482  ProgramExit();
2483  ProgramEnd(VMInstance.ProgramId);
2484  VMInstance.DispatchStatus = NOBREAK;
2485  }
2486  else
2487  {
2488  if (VMInstance.DispatchStatus != STOPBREAK)
2489  {
2490  ProgramExit();
2491  }
2492  }
2493  }
2494 
2495  if (VMInstance.DispatchStatus != STOPBREAK)
2496  {
2497  Result = ProgramExec();
2498  }
2499 
2500  if (*pRestart == 1)
2501  {
2502  Result = FAIL;
2503  }
2504 
2505 #ifdef Linux_X86
2506  usleep(1);
2507 #endif
2508 
2509  return (Result);
2510 }
2511 
2512 
2513 RESULT mSchedExit(void)
2514 {
2515  DATA32 Result = OK;
2516 
2517  VmPrint("}\r\nVM STOPPED\r\n\n");
2518 
2519 #ifndef DISABLE_SDCARD_SUPPORT
2520  char SDBuffer[250];
2521  if (VMInstance.SdcardOk == 1)
2522  {
2523  sync();
2524  VMInstance.SdcardOk = 0;
2525  snprintf(SDBuffer,250,"rm -r %s &> /dev/null",vmSDCARD_FOLDER);
2526  system(SDBuffer);
2527  }
2528 #endif
2529 
2530 #ifndef DISABLE_USBSTICK_SUPPORT
2531  char USBBuffer[250];
2532  if (VMInstance.UsbstickOk == 1)
2533  {
2534  sync();
2535  VMInstance.UsbstickOk = 0;
2536  snprintf(USBBuffer,250,"rm -r %s &> /dev/null",vmUSBSTICK_FOLDER);
2537  system(USBBuffer);
2538  }
2539 #endif
2540 
2541  Result |= cValidateExit();
2542  Result |= cSoundExit();
2543  Result |= cComExit();
2544  Result |= cMemoryExit();
2545  Result |= cUiExit();
2546  Result |= cInputExit();
2547  Result |= cOutputExit();
2548 
2549 #if (HARDWARE != SIMULATION)
2550  closelog();
2551 #else
2552 //TBD
2553 #endif
2554 
2555 #ifndef DISABLE_PREEMPTED_VM
2556  VMInstance.AdcFile = open(ANALOG_DEVICE_NAME,O_RDWR | O_SYNC);
2557  if (VMInstance.AdcFile >= MIN_HANDLE)
2558  {
2559  munmap(VMInstance.pAnalog,sizeof(ANALOG));
2560  close(VMInstance.AdcFile);
2561  }
2562 #endif
2563 
2564  return (RESULT)(Result);
2565 }
2566 
2567 
2568 #if (HARDWARE != SIMULATION)
2569 int main(int argc,char *argv[])
2570 {
2571  RESULT Result = FAIL;
2572  UBYTE Restart;
2573 
2574  do
2575  {
2576  Restart = 0;
2577  Result = mSchedInit(argc,argv);
2578 
2579  if (Result == OK)
2580  {
2581  do
2582  {
2583  Result = mSchedCtrl(&Restart);
2584 /*
2585  if ((*UiInstance.pUi).State[BACK_BUTTON] & BUTTON_LONGPRESS)
2586  {
2587  Restart = 1;
2588  Result = FAIL;
2589  }
2590 */
2591  }
2592  while (Result == OK);
2593 
2594  Result = mSchedExit();
2595  }
2596  else
2597  {
2598 //TCP system("reboot");
2599  }
2600  }
2601  while (Restart);
2602 
2603  return ((int)Result);
2604 }
2605 
2606 #endif
2607 
2608 
2610 {
2611  [opERROR] = &Error,
2612  [opNOP] = &Nop,
2613  [opPROGRAM_STOP] = &ProgramStop,
2614  [opPROGRAM_START] = &ProgramStart,
2615  [opOBJECT_STOP] = &ObjectStop,
2616  [opOBJECT_START] = &ObjectStart,
2617  [opOBJECT_TRIG] = &ObjectTrig,
2618  [opOBJECT_WAIT] = &ObjectWait,
2619  [opRETURN] = &ObjectReturn,
2620  [opCALL] = &ObjectCall,
2621  [opOBJECT_END] = &ObjectEnd,
2622  [opSLEEP] = &Sleep,
2623  [opPROGRAM_INFO] = &ProgramInfo,
2624  [opLABEL] = &DefLabel,
2625  [opPROBE] = &Probe,
2626  [opDO] = &Do,
2627  [opADD8] = &cMathAdd8,
2628  [opADD16] = &cMathAdd16,
2629  [opADD32] = &cMathAdd32,
2630  [opADDF] = &cMathAddF,
2631  [opSUB8] = &cMathSub8,
2632  [opSUB16] = &cMathSub16,
2633  [opSUB32] = &cMathSub32,
2634  [opSUBF] = &cMathSubF,
2635  [opMUL8] = &cMathMul8,
2636  [opMUL16] = &cMathMul16,
2637  [opMUL32] = &cMathMul32,
2638  [opMULF] = &cMathMulF,
2639  [opDIV8] = &cMathDiv8,
2640  [opDIV16] = &cMathDiv16,
2641  [opDIV32] = &cMathDiv32,
2642  [opDIVF] = &cMathDivF,
2643  [opOR8] = &cMathOr8,
2644  [opOR16] = &cMathOr16,
2645  [opOR32] = &cMathOr32,
2646 
2647  [opAND8] = &cMathAnd8,
2648  [opAND16] = &cMathAnd16,
2649  [opAND32] = &cMathAnd32,
2650 
2651  [opXOR8] = &cMathXor8,
2652  [opXOR16] = &cMathXor16,
2653  [opXOR32] = &cMathXor32,
2654 
2655  [opRL8] = &cMathRl8,
2656  [opRL16] = &cMathRl16,
2657  [opRL32] = &cMathRl32,
2658  [opINIT_BYTES] = &cMoveInitBytes,
2659  [opMOVE8_8] = &cMove8to8,
2660  [opMOVE8_16] = &cMove8to16,
2661  [opMOVE8_32] = &cMove8to32,
2662  [opMOVE8_F] = &cMove8toF,
2663  [opMOVE16_8] = &cMove16to8,
2664  [opMOVE16_16] = &cMove16to16,
2665  [opMOVE16_32] = &cMove16to32,
2666  [opMOVE16_F] = &cMove16toF,
2667  [opMOVE32_8] = &cMove32to8,
2668  [opMOVE32_16] = &cMove32to16,
2669  [opMOVE32_32] = &cMove32to32,
2670  [opMOVE32_F] = &cMove32toF,
2671  [opMOVEF_8] = &cMoveFto8,
2672  [opMOVEF_16] = &cMoveFto16,
2673  [opMOVEF_32] = &cMoveFto32,
2674  [opMOVEF_F] = &cMoveFtoF,
2675  [opJR] = &cBranchJr,
2676  [opJR_FALSE] = &cBranchJrFalse,
2677  [opJR_TRUE] = &cBranchJrTrue,
2678  [opJR_NAN] = &cBranchJrNan,
2679  [opCP_LT8] = &cCompareLt8,
2680  [opCP_LT16] = &cCompareLt16,
2681  [opCP_LT32] = &cCompareLt32,
2682  [opCP_LTF] = &cCompareLtF,
2683  [opCP_GT8] = &cCompareGt8,
2684  [opCP_GT16] = &cCompareGt16,
2685  [opCP_GT32] = &cCompareGt32,
2686  [opCP_GTF] = &cCompareGtF,
2687  [opCP_EQ8] = &cCompareEq8,
2688  [opCP_EQ16] = &cCompareEq16,
2689  [opCP_EQ32] = &cCompareEq32,
2690  [opCP_EQF] = &cCompareEqF,
2691  [opCP_NEQ8] = &cCompareNEq8,
2692  [opCP_NEQ16] = &cCompareNEq16,
2693  [opCP_NEQ32] = &cCompareNEq32,
2694  [opCP_NEQF] = &cCompareNEqF,
2695  [opCP_LTEQ8] = &cCompareLtEq8,
2696  [opCP_LTEQ16] = &cCompareLtEq16,
2697  [opCP_LTEQ32] = &cCompareLtEq32,
2698  [opCP_LTEQF] = &cCompareLtEqF,
2699  [opCP_GTEQ8] = &cCompareGtEq8,
2700  [opCP_GTEQ16] = &cCompareGtEq16,
2701  [opCP_GTEQ32] = &cCompareGtEq32,
2702  [opCP_GTEQF] = &cCompareGtEqF,
2703  [opSELECT8] = &cCompareSelect8,
2704  [opSELECT16] = &cCompareSelect16,
2705  [opSELECT32] = &cCompareSelect32,
2706  [opSELECTF] = &cCompareSelectF,
2707  [opSYSTEM] = &System,
2708  [opPORT_CNV_OUTPUT] = &PortCnvOutput,
2709  [opPORT_CNV_INPUT] = &PortCnvInput,
2710  [opNOTE_TO_FREQ] = &NoteToFreq,
2711 
2712  [opJR_LT8] = &cBranchJrLt8,
2713  [opJR_LT16] = &cBranchJrLt16,
2714  [opJR_LT32] = &cBranchJrLt32,
2715  [opJR_LTF] = &cBranchJrLtF,
2716  [opJR_GT8] = &cBranchJrGt8,
2717  [opJR_GT16] = &cBranchJrGt16,
2718  [opJR_GT32] = &cBranchJrGt32,
2719  [opJR_GTF] = &cBranchJrGtF,
2720  [opJR_EQ8] = &cBranchJrEq8,
2721  [opJR_EQ16] = &cBranchJrEq16,
2722  [opJR_EQ32] = &cBranchJrEq32,
2723  [opJR_EQF] = &cBranchJrEqF,
2724  [opJR_NEQ8] = &cBranchJrNEq8,
2725  [opJR_NEQ16] = &cBranchJrNEq16,
2726  [opJR_NEQ32] = &cBranchJrNEq32,
2727  [opJR_NEQF] = &cBranchJrNEqF,
2728  [opJR_LTEQ8] = &cBranchJrLtEq8,
2729  [opJR_LTEQ16] = &cBranchJrLtEq16,
2730  [opJR_LTEQ32] = &cBranchJrLtEq32,
2731  [opJR_LTEQF] = &cBranchJrLtEqF,
2732  [opJR_GTEQ8] = &cBranchJrGtEq8,
2733  [opJR_GTEQ16] = &cBranchJrGtEq16,
2734  [opJR_GTEQ32] = &cBranchJrGtEq32,
2735  [opJR_GTEQF] = &cBranchJrGtEqF,
2736  [opINFO] = &Info,
2737  [opSTRINGS] = &Strings,
2738  [opMEMORY_WRITE] = &MemoryWrite,
2739  [opMEMORY_READ] = &MemoryRead,
2740  [opUI_FLUSH] = &cUiFlush,
2741  [opUI_READ] = &cUiRead,
2742  [opUI_WRITE] = &cUiWrite,
2743  [opUI_BUTTON] = &cUiButton,
2744  [opUI_DRAW] = &cUiDraw,
2745  [opTIMER_WAIT] = &cTimerWait,
2746  [opTIMER_READY] = &cTimerReady,
2747  [opTIMER_READ] = &cTimerRead,
2748  [opBP0] = &BreakPoint,
2749  [opBP1] = &BreakPoint,
2750  [opBP2] = &BreakPoint,
2751  [opBP3] = &BreakPoint,
2752  [opBP_SET] = &BreakSet,
2753  [opMATH] = &cMath,
2754  [opRANDOM] = &Random,
2755  [opTIMER_READ_US] = &cTimerReaduS,
2756  [opKEEP_ALIVE] = &cUiKeepAlive,
2757  [opCOM_READ] = &cComRead,
2758  [opCOM_WRITE] = &cComWrite,
2759  [opSOUND] = &cSoundEntry,
2760  [opSOUND_TEST] = &cSoundTest,
2761  [opSOUND_READY] = &cSoundReady,
2762  [opINPUT_SAMPLE] = &cInputSample,
2763  [opINPUT_DEVICE_LIST] = &cInputDeviceList,
2764  [opINPUT_DEVICE] = &cInputDevice,
2765  [opINPUT_READ] = &cInputRead,
2766  [opINPUT_TEST] = &cInputTest,
2767  [opINPUT_READY] = &cInputReady,
2768  [opINPUT_READSI] = &cInputReadSi,
2769  [opINPUT_READEXT] = &cInputReadExt,
2770  [opINPUT_WRITE] = &cInputWrite,
2771  [opOUTPUT_SET_TYPE] = &cOutputSetType,
2772  [opOUTPUT_RESET] = &cOutputReset,
2773  [opOUTPUT_STOP] = &cOutputStop,
2774  [opOUTPUT_POWER] = &cOutputPower,
2775  [opOUTPUT_SPEED] = &cOutputSpeed,
2776  [opOUTPUT_START] = &cOutputStart,
2777  [opOUTPUT_POLARITY] = &cOutputPolarity,
2778  [opOUTPUT_READ] = &cOutputRead,
2779  [opOUTPUT_TEST] = &cOutputTest,
2780  [opOUTPUT_READY] = &cOutputReady,
2781  [opOUTPUT_STEP_POWER] = &cOutputStepPower,
2782  [opOUTPUT_TIME_POWER] = &cOutputTimePower,
2783  [opOUTPUT_STEP_SPEED] = &cOutputStepSpeed,
2784  [opOUTPUT_TIME_SPEED] = &cOutputTimeSpeed,
2785  [opOUTPUT_STEP_SYNC] = &cOutputStepSync,
2786  [opOUTPUT_TIME_SYNC] = &cOutputTimeSync,
2787  [opOUTPUT_CLR_COUNT] = &cOutputClrCount,
2788  [opOUTPUT_GET_COUNT] = &cOutputGetCount,
2789  [opOUTPUT_PRG_STOP] = &cOutputPrgStop,
2790  [opFILE] = &cMemoryFile,
2791  [opARRAY] = &cMemoryArray,
2792  [opARRAY_WRITE] = &cMemoryArrayWrite,
2793  [opARRAY_READ] = &cMemoryArrayRead,
2794  [opARRAY_APPEND] = &cMemoryArrayAppend,
2795  [opMEMORY_USAGE] = &cMemoryUsage,
2796  [opFILENAME] = &cMemoryFileName,
2797  [opREAD8] = &cMoveRead8,
2798  [opREAD16] = &cMoveRead16,
2799  [opREAD32] = &cMoveRead32,
2800  [opREADF] = &cMoveReadF,
2801  [opWRITE8] = &cMoveWrite8,
2802  [opWRITE16] = &cMoveWrite16,
2803  [opWRITE32] = &cMoveWrite32,
2804  [opWRITEF] = &cMoveWriteF,
2805  [opCOM_READY] = &cComReady,
2806  [opCOM_READDATA] = &Error,
2807  [opCOM_WRITEDATA] = &Error,
2808  [opCOM_GET] = &cComGet,
2809  [opCOM_SET] = &cComSet,
2810  [opCOM_TEST] = &cComTest,
2811  [opCOM_REMOVE] = &cComRemove,
2812  [opCOM_WRITEFILE] = &cComWriteFile,
2813  [opMAILBOX_OPEN] = &cComOpenMailBox,
2814  [opMAILBOX_WRITE] = &cComWriteMailBox,
2815  [opMAILBOX_READ] = &cComReadMailBox,
2816  [opMAILBOX_TEST] = &cComTestMailBox,
2817  [opMAILBOX_READY] = &cComReadyMailBox,
2818  [opMAILBOX_CLOSE] = &cComCloseMailBox,
2819 
2820  [opTST] = &Tst
2821 };
2822 
2823 //******* BYTE CODE SNIPPETS **************************************************
2824 
2825 
2839 void Error(void)
2840 {
2841  ProgramEnd(VMInstance.ProgramId);
2842  VMInstance.Program[VMInstance.ProgramId].Result = FAIL;
2844 }
2845 
2846 
2857 void Nop(void)
2858 {
2859 }
2860 
2861 
2879 void ProgramStop(void)
2880 {
2881  DATA16 PrgId;
2882 
2883  PrgId = *(DATA16*)PrimParPointer();
2884 
2885  if (PrgId == GUI_SLOT)
2886  {
2887  PrgId = MAX_PROGRAMS;
2888  do
2889  {
2890  PrgId--;
2891  ProgramEnd(PrgId);
2892  }
2893  while (PrgId);
2894  }
2895  else
2896  {
2897  if (PrgId == CURRENT_SLOT)
2898  {
2899  PrgId = CurrentProgramId();
2900  }
2901  ProgramEnd(PrgId);
2902  }
2903 }
2904 
2905 
2926 void ProgramStart(void)
2927 {
2928  PRGID PrgId;
2929  PRGID TmpPrgId;
2930  IP pI;
2931  UBYTE DB;
2932  UBYTE Flag = 0;
2933 
2934 
2935  PrgId = *(PRGID*)PrimParPointer();
2936 
2937  // Dummy
2938  pI = *(IP*)PrimParPointer();
2939 
2940  pI = *(IP*)PrimParPointer();
2941  DB = *(DATA8*)PrimParPointer();
2942 
2943 
2944  if (VMInstance.Program[PrgId].Status == STOPPED)
2945  {
2946  TmpPrgId = CurrentProgramId();
2947 
2948  if ((TmpPrgId == CMD_SLOT) || (TmpPrgId == TERM_SLOT))
2949  { // Direct command starting a program
2950 
2951  if ((VMInstance.Program[USER_SLOT].Status == STOPPED) && (VMInstance.Program[DEBUG_SLOT].Status == STOPPED))
2952  { // User and debug must be stooped
2953 
2954  if (ProgramReset(PrgId,pI,NULL,DB) == OK)
2955  {
2956  Flag = 1;
2957  }
2958  }
2959  }
2960  else
2961  { // Gui, user or debug starting a program
2962 
2963  if (ProgramReset(PrgId,pI,NULL,DB) == OK)
2964  {
2965  Flag = 1;
2966  }
2967  }
2968  }
2969  if (!Flag)
2970  {
2971 // LogErrorNumber(VM_PROGRAM_NOT_STARTED);
2972  }
2973 }
2974 
2975 
2993 void ObjectStop(void)
2994 {
2996 }
2997 
2998 
3016 void ObjectStart(void)
3017 {
3019 }
3020 
3021 
3039 void ObjectTrig(void)
3040 {
3041  OBJID TmpId;
3042 
3043  TmpId = *(OBJID*)PrimParPointer();
3044 
3045  (*VMInstance.pObjList[TmpId]).ObjStatus = WAITING;
3046  if ((*VMInstance.pObjList[TmpId]).u.TriggerCount)
3047  {
3048  ((*VMInstance.pObjList[TmpId]).u.TriggerCount)--;
3049  if ((*VMInstance.pObjList[TmpId]).u.TriggerCount == 0)
3050  {
3051  ObjectReset(TmpId);
3052  ObjectEnQueue(TmpId);
3053 /*
3054  #ifdef OLDCALL
3055  ObjectEnQueue(TmpId);
3056  #else
3057  (*VMInstance.pObjList[VMInstance.ObjectId]).Ip = VMInstance.ObjectIp;
3058  VMInstance.ObjectId = TmpId;
3059  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = RUNNING;
3060  VMInstance.ObjectIp = (*VMInstance.pObjList[VMInstance.ObjectId]).Ip;
3061  VMInstance.ObjectLocal = (*VMInstance.pObjList[VMInstance.ObjectId]).pLocal;
3062  #endif
3063 */
3064  }
3065  }
3066 }
3067 
3068 
3086 void ObjectWait(void)
3087 {
3088  OBJID TmpId;
3089  IP TmpIp;
3090 
3091  TmpIp = VMInstance.ObjectIp;
3092  TmpId = *(OBJID*)PrimParPointer();
3093 
3094  if ((*VMInstance.pObjList[TmpId]).ObjStatus != STOPPED)
3095  {
3096  VMInstance.ObjectIp = TmpIp - 1;
3098  }
3099 }
3100 
3101 
3118 void ObjectReturn(void)
3119 {
3120  OBJID ObjectIdCaller;
3121 
3122  // Get caller id from saved
3123  ObjectIdCaller = (*VMInstance.pObjList[VMInstance.ObjectId]).u.CallerId;
3124 
3125  // Copy local variables to parameters
3126  VMInstance.ObjectLocal = (*VMInstance.pObjList[ObjectIdCaller]).pLocal;
3127  CopyLocalsToPars(ObjectIdCaller);
3128 
3129  // Stop called object and start calling object
3130 #ifdef OLDCALL
3131  ObjectDeQueue(VMInstance.ObjectId);
3132  ObjectEnQueue(ObjectIdCaller);
3133 #else
3134  (*VMInstance.pObjList[VMInstance.ObjectId]).Ip = VMInstance.ObjectIp;
3135  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = STOPPED;
3136 
3137 #ifndef DISABLE_NEW_CALL_MUTEX
3138  if ((*VMInstance.pObjList[VMInstance.ObjectId]).Blocked)
3139  {
3140  (*VMInstance.pObjList[VMInstance.ObjectId]).Blocked = 0;
3142  }
3143 #endif
3144  VMInstance.ObjectId = ObjectIdCaller;
3145  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = RUNNING;
3146  VMInstance.ObjectIp = (*VMInstance.pObjList[VMInstance.ObjectId]).Ip;
3147  VMInstance.ObjectLocal = (*VMInstance.pObjList[VMInstance.ObjectId]).pLocal;
3148 #endif
3149 }
3150 
3151 
3173 void ObjectCall(void)
3174 {
3175  IP TmpIp;
3176  OBJID ObjectIdToCall;
3177 
3178  // Save IP in case object are locked
3179  TmpIp = GetObjectIp();
3180 
3181  // Get object to call from byte stream
3182  ObjectIdToCall = *(OBJID*)PrimParPointer();
3183  if ((*VMInstance.pObjList[ObjectIdToCall]).ObjStatus == STOPPED)
3184  { // Object free
3185 
3186  // Get number of parameters
3187  PrimParPointer();
3188 
3189  // Initialise object
3190  ObjectReset(ObjectIdToCall);
3191 
3192  // Save mother id
3193  (*VMInstance.pObjList[ObjectIdToCall]).u.CallerId = VMInstance.ObjectId;
3194 
3195  // Copy parameters to local variables
3196  CopyParsToLocals(ObjectIdToCall);
3197 
3198  // Halt calling object
3199  (*VMInstance.pObjList[VMInstance.ObjectId]).Ip = VMInstance.ObjectIp;
3200  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = HALTED;
3201 
3202  // Start called object
3203 #ifdef OLDCALL
3205  ObjectEnQueue(ObjectIdToCall);
3206 #else
3207  VMInstance.ObjectId = ObjectIdToCall;
3208  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = RUNNING;
3209  VMInstance.ObjectIp = (*VMInstance.pObjList[VMInstance.ObjectId]).Ip;
3210  VMInstance.ObjectLocal = (*VMInstance.pObjList[VMInstance.ObjectId]).pLocal;
3211 #endif
3212 
3213  }
3214  else
3215  { // Object locked - rewind IP
3216 
3217 #ifdef DEBUG
3218  printf("SUBCALL %u BUSY status = %u\r\n",ObjectIdToCall,(*VMInstance.pObjList[ObjectIdToCall]).ObjStatus);
3219 #endif
3220  SetObjectIp(TmpIp - 1);
3222 #ifndef DISABLE_NEW_CALL_MUTEX
3223  (*VMInstance.pObjList[ObjectIdToCall]).Blocked = 1;
3224 #endif
3225  }
3226 }
3227 
3228 
3245 void ObjectEnd(void)
3246 {
3247  (*VMInstance.pObjList[VMInstance.ObjectId]).Ip = &VMInstance.Program[VMInstance.ProgramId].pImage[(ULONG)VMInstance.Program[VMInstance.ProgramId].pObjHead[VMInstance.ObjectId].OffsetToInstructions];
3248  (*VMInstance.pObjList[VMInstance.ObjectId]).ObjStatus = STOPPED;
3250 }
3251 
3252 
3270 void Sleep(void)
3271 {
3273 }
3274 
3275 
3320 void ProgramInfo(void)
3321 {
3322  DATA8 Cmd;
3323  DATA16 Instr;
3324  PRGID PrgId;
3325  OBJID ObjIndex;
3326 
3327  Cmd = *(DATA8*)PrimParPointer();
3328  PrgId = *(PRGID*)PrimParPointer();
3329 
3330  switch (Cmd)
3331  {
3332  case OBJ_STOP :
3333  {
3334  ObjIndex = *(OBJID*)PrimParPointer();
3335  if ((ObjIndex > 0) && (ObjIndex <= VMInstance.Program[PrgId].Objects) && (VMInstance.Program[PrgId].Status != STOPPED))
3336  {
3337  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).ObjStatus = STOPPED;
3338  }
3339  }
3340  break;
3341 
3342  case OBJ_START :
3343  {
3344  ObjIndex = *(OBJID*)PrimParPointer();
3345  if ((ObjIndex > 0) && (ObjIndex <= VMInstance.Program[PrgId].Objects) && (VMInstance.Program[PrgId].Status != STOPPED))
3346  {
3347  if (ObjIndex == 1)
3348  {
3349  VMInstance.Program[PrgId].StartTime = GetTimeMS();
3350  VMInstance.Program[PrgId].RunTime = cTimerGetuS();
3351  }
3352  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).ObjStatus = RUNNING;
3353  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).Ip = &VMInstance.Program[PrgId].pImage[(ULONG)VMInstance.Program[PrgId].pObjHead[ObjIndex].OffsetToInstructions];
3354  (*VMInstance.Program[PrgId].pObjList[ObjIndex]).u.TriggerCount = VMInstance.Program[PrgId].pObjHead[ObjIndex].TriggerCount;
3355  }
3356  }
3357  break;
3358 
3359  case GET_STATUS :
3360  {
3361  *(DATA8*)PrimParPointer() = (DATA8)VMInstance.Program[PrgId].Status;
3362  }
3363  break;
3364 
3365  case GET_PRGRESULT :
3366  {
3367  *(DATA8*)PrimParPointer() = (DATA8)VMInstance.Program[PrgId].Result;
3368  }
3369  break;
3370 
3371  case GET_SPEED :
3372  {
3373  *(DATA32*)PrimParPointer() = (DATA32)(((float)VMInstance.Program[PrgId].InstrCnt * (float)1000000) / (float)VMInstance.Program[PrgId].InstrTime);
3374  }
3375  break;
3376 
3377  case SET_INSTR :
3378  {
3379  Instr = *(DATA16*)PrimParPointer();
3380  SetInstructions((ULONG)Instr);
3381  }
3382  break;
3383 
3384  default :
3385  {
3387  }
3388  break;
3389 
3390  }
3391 }
3392 
3393 
3405 void DefLabel(void)
3406 {
3407  PrimParPointer();
3408 }
3409 
3410 
3431 void Probe(void)
3432 {
3433  PRGID PrgId;
3434  OBJID ObjId;
3435  GBINDEX RamOffset;
3436  VARDATA *Ram;
3437  GBINDEX Size;
3438  GBINDEX Tmp;
3439  GBINDEX Lng;
3440 
3441  PrgId = *(PRGID*)PrimParPointer();
3442  ObjId = *(OBJID*)PrimParPointer();
3443  RamOffset = *(GBINDEX*)PrimParPointer();
3444  Size = *(GBINDEX*)PrimParPointer();
3445 
3446  if (VMInstance.Program[PrgId].Status != STOPPED)
3447  {
3448  if (ObjId == 0)
3449  {
3450  Ram = VMInstance.Program[PrgId].pGlobal;
3451  Lng = (*(IMGHEAD*)VMInstance.Program[PrgId].pImage).GlobalBytes;
3452  }
3453  else
3454  {
3455  Ram = (*VMInstance.Program[PrgId].pObjList[ObjId]).pLocal;
3456  Lng = VMInstance.Program[PrgId].pObjHead[ObjId].LocalBytes;
3457  }
3458  Ram += RamOffset;
3459  if (Size == 0)
3460  {
3461  Size = Lng;
3462  }
3463  if (Size)
3464  {
3465  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE," PROBE Prg=%d Obj=%d Offs=%ld Lng=%ld\r\n {\r\n ",PrgId,ObjId,(long unsigned int)RamOffset,(long unsigned int)Size);
3466  VmPrint(VMInstance.PrintBuffer);
3467 
3468  for (Tmp = 0;(Tmp < Size) && (Tmp < Lng) && (Tmp < 1024);Tmp++)
3469  {
3470  if ((Tmp & 0x0F) == 0)
3471  {
3472  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE," %08lX ",(long unsigned int)(RamOffset + (GBINDEX)Tmp));
3473  VmPrint(VMInstance.PrintBuffer);
3474  }
3475  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"%02X ",(UBYTE)(*Ram & 0xFF));
3476  VmPrint(VMInstance.PrintBuffer);
3477  if (((Tmp & 0x0F) == 0xF) && (Tmp < (Size - 1)))
3478  {
3479  VmPrint("\r\n ");
3480  }
3481  Ram++;
3482  }
3483 
3484  VmPrint("\r\n }\r\n");
3485  }
3486  }
3487 }
3488 
3489 
3509 void Do(void)
3510 {
3511  DATA16 PrgId;
3512  DATA32 pImage;
3513  DATA32 pGlobal;
3514 
3515  PrgId = *(DATA16*)PrimParPointer();
3516  pImage = *(DATA32*)PrimParPointer();
3517  pGlobal = *(DATA32*)PrimParPointer();
3518 
3519  if (ProgramStatus(PrgId) != STOPPED)
3520  {
3521  ProgramEnd(PrgId);
3522  }
3523  if (ProgramStatus(PrgId) == STOPPED)
3524  {
3525  if (ProgramReset(PrgId,(IP)pImage,(GP)pGlobal,0) != OK)
3526  {
3527  if (PrgId != CMD_SLOT)
3528  {
3530  }
3531  }
3532  }
3533  cUiAlive();
3534 
3535 }
3536 
3537 
3555 void BreakPoint(void)
3556 {
3557  IP TmpIp;
3558  DATA8 No;
3559  float Instr;
3560 
3561  TmpIp = (--VMInstance.ObjectIp);
3562  No = *(DATA8*)TmpIp;
3563 
3564  if (VMInstance.Program[VMInstance.ProgramId].Brkp[No & 0x03].OpCode)
3565  {
3566  *(DATA8*)TmpIp = VMInstance.Program[VMInstance.ProgramId].Brkp[No & 0x03].OpCode;
3567  }
3568  else
3569  {
3570  VMInstance.ObjectIp++;
3571  }
3572 
3573  if ((No & 0x03) == 3)
3574  {
3575  cUiTestpin(1);
3576  cUiTestpin(0);
3577  }
3578  else
3579  {
3580  Instr = VMInstance.Program[VMInstance.ProgramId].InstrCnt + VMInstance.InstrCnt;
3581 
3582  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"\r\nBREAKPOINT #%d (%.0f)",No & 0x03,Instr);
3583  VmPrint(VMInstance.PrintBuffer);
3584 
3585  VMInstance.Debug = 1;
3586  }
3587  PrimDispatchTabel[*(VMInstance.ObjectIp++)]();
3588  *(DATA8*)TmpIp = No;
3589 }
3590 
3591 
3611 void BreakSet(void)
3612 {
3613  PRGID PrgId;
3614  DATA8 No;
3615  DATA32 Addr;
3616 
3617  PrgId = *(PRGID*)PrimParPointer();
3618  No = *(DATA8*)PrimParPointer();
3619  Addr = *(IMINDEX*)PrimParPointer();
3620 
3621  if (No < MAX_BREAKPOINTS)
3622  {
3623  if (VMInstance.Program[PrgId].Status != STOPPED)
3624  {
3625  if (Addr)
3626  {
3627  VMInstance.Program[PrgId].Brkp[No].Addr = Addr;
3628  VMInstance.Program[PrgId].Brkp[No].OpCode = (OP)VMInstance.Program[PrgId].pImage[Addr];
3629  VMInstance.Program[PrgId].pImage[Addr] = opBP0 + No;
3630  }
3631  else
3632  {
3633  if ((VMInstance.Program[PrgId].Brkp[No].Addr != 0) && (VMInstance.Program[PrgId].Brkp[No].OpCode != 0))
3634  {
3635  Addr = VMInstance.Program[PrgId].Brkp[No].Addr;
3636  VMInstance.Program[PrgId].pImage[Addr] = VMInstance.Program[PrgId].Brkp[No].OpCode;
3637  }
3638  VMInstance.Program[PrgId].Brkp[No].Addr = 0;
3639  VMInstance.Program[PrgId].Brkp[No].OpCode = 0;
3640  }
3641  }
3642  }
3643 }
3644 
3645 
3665 void Random(void)
3666 {
3667  DATA16 Min;
3668  DATA16 Max;
3669  DATA16 Result;
3670 
3671  Min = *(DATA16*)PrimParPointer();
3672  Max = *(DATA16*)PrimParPointer();
3673 
3674  Result = (DATA16)rand();
3675 
3676  if (Result < 0)
3677  {
3678  Result = 0 - Result;
3679  }
3680 
3681  Result = (((Result * (Max - Min)) + 16383) / 32767);
3682  Result += Min;
3683 
3684  *(DATA16*)PrimParPointer() = Result;
3685 }
3686 
3687 
3734 void Info(void)
3735 {
3736  DATA8 Cmd;
3737  DATA8 Tmp;
3738  DATA8 Length;
3739  DATA8 *pDestination;
3740  DATA8 Number;
3741 
3742  Cmd = *(DATA8*)PrimParPointer();
3743  switch (Cmd)
3744  { // Function
3745 
3746  case SET_ERROR :
3747  {
3749  }
3750  break;
3751 
3752  case GET_ERROR :
3753  {
3754  *(DATA8*)PrimParPointer() = LogErrorGet();
3755  }
3756  break;
3757 
3758  case ERRORTEXT :
3759  {
3760  Number = *(DATA8*)PrimParPointer();
3761  Length = *(DATA8*)PrimParPointer();
3762  pDestination = (DATA8*)PrimParPointer();
3763 
3764  if (VMInstance.Handle >= 0)
3765  {
3766  if (Number < ERRORS)
3767  {
3768  Tmp = (DATA8)strlen(ErrString[Number]) + 1;
3769  }
3770  else
3771  {
3772  Tmp = 10;
3773  }
3774  if ((Length > Tmp) || (Length == -1))
3775  {
3776  Length = Tmp;
3777  }
3778  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,(DATA32)Length);
3779  }
3780  if (pDestination != NULL)
3781  {
3782  *pDestination = 0;
3783 
3784  if (Number)
3785  {
3786  if (Number < ERRORS)
3787  {
3788  snprintf((char*)pDestination,Length,"%s",ErrString[Number]);
3789  }
3790  else
3791  {
3792  snprintf((char*)pDestination,Length,"Number %02d",Number);
3793  }
3794  }
3795  }
3796  }
3797  break;
3798 
3799  case GET_VOLUME :
3800  {
3802  }
3803  break;
3804 
3805  case SET_VOLUME :
3806  {
3808  }
3809  break;
3810 
3811  case GET_MINUTES :
3812  {
3814  }
3815  break;
3816 
3817  case SET_MINUTES :
3818  {
3820  }
3821  break;
3822 
3823  }
3824 }
3825 
3826 
3919 void Strings(void)
3920 {
3921  DATA8 Cmd;
3922  DATA8 *pSource1;
3923  DATA8 *pSource2;
3924  DATA8 *pDestination;
3925  DATAF DataF;
3926  DATA16 Data16;
3927  DATA32 Data32;
3928  DATA32 Start;
3929  DATA8 Tmp;
3930  DATA8 Figures;
3931  DATA8 Decimals;
3932  char Buffer[1024];
3933 
3934  Cmd = *(DATA8*)PrimParPointer();
3935  switch (Cmd)
3936  { // Function
3937 
3938  case GET_SIZE :
3939  {
3940  pSource1 = (DATA8*)PrimParPointer();
3941  *(DATA16*)PrimParPointer() = (DATA16)strlen((char*)pSource1);
3942  }
3943  break;
3944 
3945  case ADD :
3946  {
3947  pSource1 = (DATA8*)PrimParPointer();
3948  pSource2 = (DATA8*)PrimParPointer();
3949  pDestination = (DATA8*)PrimParPointer();
3950  if (VMInstance.Handle >= 0)
3951  {
3952  Data32 = (DATA32)strlen((char*)pSource1);
3953  Data32 += (DATA32)strlen((char*)pSource2);
3954  Data32 += 1;
3955  if (Data32 > MIN_ARRAY_ELEMENTS)
3956  {
3957  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
3958  }
3959  }
3960  if (pDestination != NULL)
3961  {
3962  sprintf((char*)pDestination,"%s%s",(char*)pSource1,(char*)pSource2);
3963  }
3964  }
3965  break;
3966 
3967  case COMPARE :
3968  {
3969  pSource1 = (DATA8*)PrimParPointer();
3970  pSource2 = (DATA8*)PrimParPointer();
3971 
3972  if (strcmp((char*)pSource1,(char*)pSource2) == 0)
3973  {
3974  *(DATA8*)PrimParPointer() = 1;
3975  }
3976  else
3977  {
3978  *(DATA8*)PrimParPointer() = 0;
3979  }
3980  }
3981  break;
3982 
3983  case DUPLICATE :
3984  {
3985  pSource1 = (DATA8*)PrimParPointer();
3986  pDestination = (DATA8*)PrimParPointer();
3987  if (VMInstance.Handle >= 0)
3988  {
3989  Data32 = (DATA32)strlen((char*)pSource1);
3990  Data32 += 1;
3991  if (Data32 > MIN_ARRAY_ELEMENTS)
3992  {
3993  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
3994  }
3995  }
3996  if (pDestination != NULL)
3997  {
3998  strcpy((char*)pDestination,(char*)pSource1);
3999  }
4000  }
4001  break;
4002 
4003  case VALUE_TO_STRING :
4004  {
4005  DataF = *(DATAF*)PrimParPointer();
4006  Figures = *(DATA8*)PrimParPointer();
4007  Decimals = *(DATA8*)PrimParPointer();
4008  pDestination = (DATA8*)PrimParPointer();
4009  if (VMInstance.Handle >= 0)
4010  {
4011  if (Figures >= 0)
4012  {
4013  Data32 = (DATA32)Figures;
4014  }
4015  else
4016  {
4017  Data32 = (DATA32)(0 - Figures);
4018  }
4019  Data32 += 2;
4020  if (Data32 > MIN_ARRAY_ELEMENTS)
4021  {
4022  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4023  }
4024  }
4025  if (pDestination != NULL)
4026  {
4027  if (isnan(DataF))
4028  {
4029  if (Figures < 0)
4030  { // "---- "
4031  Figures = 0 - Figures;
4032 
4033  Tmp = 0;
4034  while ((Tmp < 4) && (Tmp < Figures))
4035  {
4036  pDestination[Tmp] = '-';
4037  Tmp++;
4038  }
4039  while (Tmp < Figures)
4040  {
4041  pDestination[Tmp] = ' ';
4042  Tmp++;
4043  }
4044  }
4045  else
4046  { // " ----"
4047 
4048  Tmp = 0;
4049  while (Tmp < (Figures - 4))
4050  {
4051  pDestination[Tmp] = ' ';
4052  Tmp++;
4053  }
4054  while (Tmp < Figures)
4055  {
4056  pDestination[Tmp] = '-';
4057  Tmp++;
4058  }
4059  }
4060  pDestination[Tmp] = 0;
4061  }
4062  else
4063  {
4064  if (Figures >= 0)
4065  {
4066  snprintf((char*)pDestination,Figures + 1,"%*.*f",Figures,Decimals,DataF);
4067  }
4068  else
4069  {
4070  Figures = 0 - Figures;
4071  snprintf((char*)pDestination,Figures + 1,"%.*f",Decimals,DataF);
4072  }
4073  if (Decimals)
4074  { // Strip trailing zeroes
4075 
4076  Figures = (DATA8)strlen((char*)pDestination);
4077 
4078  while ((Figures) && ((pDestination[Figures] == '0') || (pDestination[Figures] == 0)))
4079  {
4080  pDestination[Figures] = 0;
4081  Figures--;
4082  }
4083  if (pDestination[Figures] == '.')
4084  {
4085  pDestination[Figures] = 0;
4086  }
4087  }
4088  }
4089  }
4090  }
4091  break;
4092 
4093  case NUMBER_TO_STRING :
4094  {
4095  Data16 = *(DATA16*)PrimParPointer();
4096  Figures = *(DATA8*)PrimParPointer();
4097  pDestination = (DATA8*)PrimParPointer();
4098  if (VMInstance.Handle >= 0)
4099  {
4100  Data32 = (DATA32)Figures;
4101  Data32 += 2;
4102  if (Data32 > MIN_ARRAY_ELEMENTS)
4103  {
4104  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4105  }
4106  }
4107  if (pDestination != NULL)
4108  {
4109  snprintf((char*)pDestination,Figures + 1,"%0*d",Figures,Data16);
4110  }
4111  }
4112  break;
4113 
4114  case STRING_TO_VALUE :
4115  {
4116  pSource1 = (DATA8*)PrimParPointer();
4117 
4118  Data16 = 0;
4119  while (pSource1[Data16])
4120  {
4121  if (pSource1[Data16] == ',')
4122  {
4123  pSource1[Data16] = '.';
4124  }
4125  Data16++;
4126  }
4127 
4128  sscanf((char*)pSource1,"%f",&DataF);
4129 
4130  *(DATAF*)PrimParPointer() = DataF;
4131  }
4132  break;
4133 
4134  case STRIP :
4135  {
4136  pSource1 = (DATA8*)PrimParPointer();
4137  pDestination = (DATA8*)PrimParPointer();
4138  if (VMInstance.Handle >= 0)
4139  {
4140  Data32 = (DATA32)strlen((char*)pSource1);
4141  Data32 += 1;
4142  if (Data32 > MIN_ARRAY_ELEMENTS)
4143  {
4144  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4145  }
4146  }
4147  if (pDestination != NULL)
4148  {
4149  while (*pSource1)
4150  {
4151  if ((*pSource1 != ' '))
4152  {
4153  *pDestination = *pSource1;
4154  pDestination++;
4155  }
4156  pSource1++;
4157  }
4158  *pDestination = *pSource1;
4159  }
4160  }
4161  break;
4162 
4163  case SUB :
4164  {
4165  pSource1 = (DATA8*)PrimParPointer();
4166  pSource2 = (DATA8*)PrimParPointer();
4167  pDestination = (DATA8*)PrimParPointer();
4168 
4169  Start = (DATA32)strlen((char*)pSource2);
4170  if (VMInstance.Handle >= 0)
4171  {
4172  Data32 = (DATA32)strlen((char*)pSource1);
4173  Data32 += 1;
4174  if (Data32 > MIN_ARRAY_ELEMENTS)
4175  {
4176  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4177  }
4178  }
4179  if (pDestination != NULL)
4180  {
4181  snprintf(Buffer,1024,"%s",strstr((char*)pSource1,(char*)pSource2));
4182  sprintf((char*)pDestination,"%s",&Buffer[(DATA16)Start]);
4183  }
4184  }
4185  break;
4186 
4187  case VALUE_FORMATTED :
4188  {
4189  DataF = *(DATAF*)PrimParPointer();
4190  pSource1 = (DATA8*)PrimParPointer();
4191  Figures = *(DATA8*)PrimParPointer();
4192  pDestination = (DATA8*)PrimParPointer();
4193 
4194  snprintf(Buffer,1024,(char*)pSource1,DataF);
4195  if (VMInstance.Handle >= 0)
4196  {
4197  Data32 = (DATA32)strlen((char*)Buffer);
4198  Data32 += 1;
4199  if (Data32 > MIN_ARRAY_ELEMENTS)
4200  {
4201  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4202  }
4203  Figures = (DATA8)Data32;
4204  }
4205  if (pDestination != NULL)
4206  {
4207  snprintf((char*)pDestination,Figures,"%s",Buffer);
4208  }
4209 
4210  }
4211  break;
4212 
4213  case NUMBER_FORMATTED :
4214  {
4215  Data32 = *(DATA32*)PrimParPointer();
4216  pSource1 = (DATA8*)PrimParPointer();
4217  Figures = *(DATA8*)PrimParPointer();
4218  pDestination = (DATA8*)PrimParPointer();
4219 
4220  snprintf(Buffer,1024,(char*)pSource1,Data32);
4221  if (VMInstance.Handle >= 0)
4222  {
4223  Data32 = (DATA32)strlen((char*)Buffer);
4224  Data32 += 1;
4225  if (Data32 > MIN_ARRAY_ELEMENTS)
4226  {
4227  pDestination = (DATA8*)VmMemoryResize(VMInstance.Handle,Data32);
4228  }
4229  Figures = (DATA8)Data32;
4230  }
4231  if (pDestination != NULL)
4232  {
4233  snprintf((char*)pDestination,Figures,"%s",Buffer);
4234  }
4235 
4236  }
4237  break;
4238 
4239  }
4240 }
4241 
4242 
4266 void MemoryWrite(void)
4267 {
4268  PRGID PrgId;
4269  OBJID ObjId;
4270  GBINDEX Offset;
4271  GBINDEX Size;
4272  DATA8 *pArray;
4273  VARDATA *Ram;
4274  GBINDEX Tmp;
4275  GBINDEX Lng;
4276 
4277  PrgId = *(PRGID*)PrimParPointer();
4278  ObjId = *(OBJID*)PrimParPointer();
4279  Offset = *(GBINDEX*)PrimParPointer();
4280  Size = *(GBINDEX*)PrimParPointer();
4281  pArray = (DATA8*)PrimParPointer();
4282 
4283 // printf("p=%-1d o=%-2d f=%-4d s=%-4d d=0x%02X\r\n",PrgId,ObjId,Offset,Size,*pArray);
4284 
4285  if (PrgId < MAX_PROGRAMS)
4286  {
4287  if (VMInstance.Program[PrgId].Status != STOPPED)
4288  {
4289  if ((ObjId >= 0) && (ObjId <= VMInstance.Program[PrgId].Objects))
4290  {
4291  if (ObjId == 0)
4292  {
4293  Ram = VMInstance.Program[PrgId].pGlobal;
4294  Lng = (*(IMGHEAD*)VMInstance.Program[PrgId].pImage).GlobalBytes;
4295  }
4296  else
4297  {
4298  Ram = (*VMInstance.Program[PrgId].pObjList[ObjId]).pLocal;
4299  Lng = VMInstance.Program[PrgId].pObjHead[ObjId].LocalBytes;
4300  }
4301 
4302  for (Tmp = 0;Tmp < Size;Tmp++)
4303  {
4304  if ((Tmp + Offset) < Lng)
4305  {
4306  Ram[Tmp + Offset] = pArray[Tmp];
4307  }
4308  }
4309  }
4310  }
4311  }
4312 }
4313 
4314 
4338 void MemoryRead(void)
4339 {
4340  PRGID PrgId;
4341  OBJID ObjId;
4342  GBINDEX Offset;
4343  GBINDEX Size;
4344  DATA8 *pArray;
4345  VARDATA *Ram;
4346  GBINDEX Tmp;
4347  GBINDEX Lng;
4348 
4349  PrgId = *(PRGID*)PrimParPointer();
4350  ObjId = *(OBJID*)PrimParPointer();
4351  Offset = *(GBINDEX*)PrimParPointer();
4352  Size = *(GBINDEX*)PrimParPointer();
4353  pArray = (DATA8*)PrimParPointer();
4354 
4355  if (PrgId < MAX_PROGRAMS)
4356  {
4357  if (VMInstance.Program[PrgId].Status != STOPPED)
4358  {
4359  if ((ObjId >= 0) && (ObjId <= VMInstance.Program[PrgId].Objects))
4360  {
4361  if (ObjId == 0)
4362  {
4363  Ram = VMInstance.Program[PrgId].pGlobal;
4364  Lng = (*(IMGHEAD*)VMInstance.Program[PrgId].pImage).GlobalBytes;
4365  }
4366  else
4367  {
4368  Ram = (*VMInstance.Program[PrgId].pObjList[ObjId]).pLocal;
4369  Lng = VMInstance.Program[PrgId].pObjHead[ObjId].LocalBytes;
4370  }
4371 
4372  for (Tmp = 0;Tmp < Size;Tmp++)
4373  {
4374  if ((Tmp + Offset) < Lng)
4375  {
4376  pArray[Tmp] = Ram[Tmp + Offset];
4377  }
4378  else
4379  {
4380  pArray[Tmp] = 0;
4381  }
4382  }
4383  }
4384  }
4385  }
4386 }
4387 
4388 
4402 void PortCnvOutput(void)
4403 {
4404  DATA32 Ports = *(DATA32*)PrimParPointer();
4405  DATA32 inputPorts = Ports;
4406  DATA8 secondPortBitfield = (DATA8) 1 << ((inputPorts % 10) - 1);
4407  inputPorts /= 10;
4408  DATA8 firstPortBitfield = (DATA8) 1 << ((inputPorts % 10) - 1);
4409  inputPorts /= 10;
4410  DATA8 layer = (DATA8)(inputPorts % 10) - 1;
4411  if (layer < 0)
4412  {
4413  layer = 0;
4414  }
4415  DATA8 bitfield = firstPortBitfield | secondPortBitfield;
4416  *(DATA8*)PrimParPointer() = layer;
4417  *(DATA8*)PrimParPointer() = bitfield;
4418  *(DATA8*)PrimParPointer() = firstPortBitfield > secondPortBitfield;
4419 }
4420 
4421 
4434 void PortCnvInput(void)
4435 {
4436  DATA32 inputPorts = *(DATA32*)PrimParPointer();
4437  DATA8 port = (DATA8) (inputPorts % 10) - 1;
4438  inputPorts /= 100;
4439  DATA8 layer = (DATA8)(inputPorts % 10) - 1;
4440  if (layer < 0)
4441  {
4442  layer = 0;
4443  }
4444  *(DATA8*)PrimParPointer() = layer;
4445  *(DATA8*)PrimParPointer() = port;
4446 }
4447 
4448 
4449 typedef struct
4450 {
4451  DATA8 Note[4];
4453 }
4454 NOTEFREQ;
4455 
4456 #define NOTES 36
4457 
4459 {
4460  { "C4" , 262 },
4461  { "D4" , 294 },
4462  { "E4" , 330 },
4463  { "F4" , 349 },
4464  { "G4" , 392 },
4465  { "A4" , 440 },
4466  { "B4" , 494 },
4467  { "C5" , 523 },
4468  { "D5" , 587 },
4469  { "E5" , 659 },
4470  { "F5" , 698 },
4471  { "G5" , 784 },
4472  { "A5" , 880 },
4473  { "B5" , 988 },
4474  { "C6" , 1047 },
4475  { "D6" , 1175 },
4476  { "E6" , 1319 },
4477  { "F6" , 1397 },
4478  { "G6" , 1568 },
4479  { "A6" , 1760 },
4480  { "B6" , 1976 },
4481 
4482  { "C#4" , 277 },
4483  { "D#4" , 311 },
4484 
4485  { "F#4" , 370 },
4486  { "G#4" , 415 },
4487  { "A#4" , 466 },
4488 
4489  { "C#5" , 554 },
4490  { "D#5" , 622 },
4491 
4492  { "F#5" , 740 },
4493  { "G#5" , 831 },
4494  { "A#5" , 932 },
4495 
4496  { "C#6" , 1109 },
4497  { "D#6" , 1245 },
4498 
4499  { "F#6" , 1480 },
4500  { "G#6" , 1661 },
4501  { "A#6" , 1865 }
4502 };
4503 
4504 
4516 void NoteToFreq(void)
4517 {
4518  DATA8 *pNote;
4519  DATA16 Freq;
4520  DATA8 Note;
4521 
4522  Freq = 440;
4523 
4524  pNote = (DATA8*)PrimParPointer();
4525 
4526  for (Note = 0;Note < NOTES;Note++)
4527  {
4528  if (strcmp((char*)NoteFreq[Note].Note,(char*)pNote) == 0)
4529  {
4530  Freq = NoteFreq[Note].Freq;
4531  }
4532  }
4533 
4534  *(DATA16*)PrimParPointer() = Freq;
4535 }
4536 
4537 #ifndef DISABLE_SYSTEM_BYTECODE
4538 
4549 #endif
4550 void System(void)
4551 {
4552  DATA32 Status = -1;
4553  DATA8 *pCmd;
4554 
4555  pCmd = (DATA8*)PrimParPointer();
4556 
4557 #ifndef DISABLE_SYSTEM_BYTECODE
4558  Status = (DATA32)system((char*)pCmd);
4559 #endif
4560  sync();
4561 
4562  *(DATA32*)PrimParPointer() = Status;
4563 }
4564 
4565 
4566 //*****************************************************************************
4567 
4568 void Monitor(void)
4569 {
4570  static ULONG SavedPriority;
4571  IMINDEX Index;
4572  LBINDEX Lv,Ln;
4573  OBJID ObjId;
4574  OBJID OwnerObjId;
4575  LP pObjectLocal;
4576  char ObjStat;
4577  DATA8 Esc;
4578 
4579 
4580  if (VMInstance.Debug == 1)
4581  {
4582  SavedPriority = VMInstance.Priority;
4583 
4584  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"\r\n %d %2d IP=%08lX -> ",VMInstance.ProgramId,VMInstance.ObjectId,(unsigned long)VMInstance.ObjectIp);
4585  VmPrint(VMInstance.PrintBuffer);
4586 
4587  Ln = 16;
4588 
4589  for (Lv = 0;Lv < Ln;Lv++)
4590  {
4591  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"%02X ",VMInstance.ObjectIp[Lv] & 0xFF);
4592  VmPrint(VMInstance.PrintBuffer);
4593  if (((Lv & 0x3) == 0x3) && ((Lv & 0xF) != 0xF))
4594  {
4595  VmPrint(" ");
4596  }
4597  if (((Lv & 0xF) == 0xF) && (Lv < (Ln - 1)))
4598  {
4599  VmPrint("\r\n");
4600  }
4601  }
4602  VmPrint("\r\n");
4603 
4604  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE," GV=%08lX -> ",(unsigned long)VMInstance.pGlobal);
4605  VmPrint(VMInstance.PrintBuffer);
4606 
4607  Ln = (*(IMGHEAD*)VMInstance.pImage).GlobalBytes;
4608 
4609  for (Lv = 0;Lv < Ln;Lv++)
4610  {
4611  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"%02X ",VMInstance.pGlobal[Lv] & 0xFF);
4612  VmPrint(VMInstance.PrintBuffer);
4613  if (((Lv & 0x3) == 0x3) && ((Lv & 0xF) != 0xF))
4614  {
4615  VmPrint(" ");
4616  }
4617  if (((Lv & 0xF) == 0xF) && (Lv < (Ln - 1)))
4618  {
4619  VmPrint("\r\n ");
4620  }
4621  }
4622  VmPrint("\r\n");
4623 
4624  for (ObjId = 1;ObjId <= VMInstance.Objects;ObjId++)
4625  {
4626  switch ((*VMInstance.pObjList[ObjId]).ObjStatus)
4627  {
4628  case RUNNING :
4629  {
4630  ObjStat = 'r';
4631  }
4632  break;
4633 
4634  case WAITING :
4635  {
4636  ObjStat = 'w';
4637  }
4638  break;
4639 
4640  case STOPPED :
4641  {
4642  ObjStat = 's';
4643  }
4644  break;
4645 
4646  case HALTED :
4647  {
4648  ObjStat = 'h';
4649  }
4650  break;
4651 
4652  default :
4653  {
4654  ObjStat = '?';
4655  }
4656  break;
4657 
4658  }
4659  if (ObjId == VMInstance.ObjectId)
4660  {
4661  ObjStat = '>';
4662  }
4663 
4664  OwnerObjId = VMInstance.pObjHead[ObjId].OwnerObjectId;
4665  pObjectLocal = (*VMInstance.pObjList[ObjId]).pLocal;
4666 
4667  if (OwnerObjId)
4668  { // Reuse locals from owner
4669 
4670  Ln = VMInstance.pObjHead[OwnerObjId].LocalBytes;
4671 
4672  }
4673  else
4674  { // Use local allocated to object
4675 
4676  Ln = VMInstance.pObjHead[ObjId].LocalBytes;
4677  }
4678 
4679 
4680 
4681  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE," %c %2d LV=%08lX -> ",ObjStat,ObjId,(unsigned long)pObjectLocal);
4682  VmPrint(VMInstance.PrintBuffer);
4683 
4684  for (Lv = 0;Lv < Ln;Lv++)
4685  {
4686  snprintf(VMInstance.PrintBuffer,PRINTBUFFERSIZE,"%02X ",pObjectLocal[Lv] & 0xFF);
4687  VmPrint(VMInstance.PrintBuffer);
4688  if (((Lv & 0x3) == 0x3) && ((Lv & 0xF) != 0xF))
4689  {
4690  VmPrint(" ");
4691  }
4692  if (((Lv & 0xF) == 0xF) && (Lv < (Ln - 1)))
4693  {
4694  VmPrint("\r\n ");
4695  }
4696  }
4697  VmPrint("\r\n");
4698 
4699  }
4700 
4701  VmPrint("\r\n");
4702 
4703  Index = (IMINDEX)VMInstance.ObjectIp - (IMINDEX)VMInstance.pImage;
4704  cValidateDisassemble(VMInstance.pImage,&Index,VMInstance.Program[VMInstance.ProgramId].Label);
4705  VMInstance.Debug++;
4706  cUiEscape();
4707  }
4708  if (VMInstance.Debug == 2)
4709  {
4710  Esc = cUiEscape();
4711  switch (Esc)
4712  {
4713  case ' ' :
4714  {
4715  VMInstance.Priority = SavedPriority;
4716  VMInstance.Priority--;
4717  PrimDispatchTabel[*(VMInstance.ObjectIp++)]();
4718  VMInstance.Debug--;
4719  }
4720  break;
4721 
4722  case '<' :
4723  {
4724  VMInstance.Priority = SavedPriority;
4725  VMInstance.Priority--;
4726  PrimDispatchTabel[*(VMInstance.ObjectIp++)]();
4727  VMInstance.Debug = 0;
4728  }
4729  break;
4730 
4731  default :
4732  {
4733  VMInstance.Priority = 0;
4734  }
4735  break;
4736 
4737  }
4738  }
4739 }
4740 
4741 
4742 RESULT TstOpen(UWORD Time)
4743 {
4744  RESULT Result = FAIL;
4745  int File;
4746 
4747  if ((Time > 0) && (Time <= 30000))
4748  {
4749  if (VMInstance.Test == 0)
4750  {
4751  File = open(TEST_PIN_DEVICE_NAME,O_RDWR | O_SYNC);
4752  if (File >= MIN_HANDLE)
4753  {
4754  ioctl(File,TST_PIN_ON,NULL);
4755  close(File);
4756 
4757  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
4758  if (File >= MIN_HANDLE)
4759  {
4760  ioctl(File,TST_UART_ON,NULL);
4761  close(File);
4762  VMInstance.Test = Time;
4763  Result = OK;
4764  }
4765  }
4766  }
4767  else
4768  {
4769  VMInstance.Test = Time;
4770  Result = OK;
4771  }
4772  }
4773 
4774  return (Result);
4775 }
4776 
4777 
4778 void TstClose(void)
4779 {
4780  int File;
4781 
4782  if (VMInstance.Test != 0)
4783  {
4784  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
4785  if (File >= MIN_HANDLE)
4786  {
4787  ioctl(File,TST_UART_OFF,NULL);
4788  close(File);
4789 
4790  File = open(TEST_PIN_DEVICE_NAME,O_RDWR | O_SYNC);
4791  if (File >= MIN_HANDLE)
4792  {
4793  ioctl(File,TST_PIN_OFF,NULL);
4794  close(File);
4795  VMInstance.Test = 0;
4796  }
4797  }
4798  }
4799 }
4800 
4801 
5160 void Tst(void)
5161 {
5162  DATA8 Cmd;
5163  DATA8 *pPins;
5164  DATA8 Index;
5165  DATA8 Data8;
5166  DATA16 Value;
5167  DATA8 Buffer[2];
5168  TSTPIN Tstpin;
5169  TSTUART Tstuart;
5170  int File;
5171 
5172  Cmd = *(DATA8*)PrimParPointer();
5173 
5174  if (Cmd == TST_OPEN)
5175  { // Test open
5176 
5177  TstOpen(10000);
5178  }
5179  else
5180  {
5181  if (VMInstance.Test)
5182  {
5183  TstOpen(10000);
5184 
5185  switch (Cmd)
5186  { // Function
5187 
5188  case TST_READ_PINS :
5189  { // Read pins
5190 
5191  Tstpin.Port = *(DATA8*)PrimParPointer();
5192  Tstpin.Length = *(DATA8*)PrimParPointer();
5193  pPins = (DATA8*)PrimParPointer();
5194 
5195  File = open(TEST_PIN_DEVICE_NAME,O_RDWR | O_SYNC);
5196  if (File >= 0)
5197  {
5198  ioctl(File,TST_PIN_READ,&Tstpin);
5199  close(File);
5200  for (Index = 0;Index < Tstpin.Length;Index++)
5201  {
5202  pPins[Index] = Tstpin.String[Index];
5203  }
5204  }
5205  }
5206  break;
5207 
5208  case TST_WRITE_PINS :
5209  { // Write to pins
5210 
5211  Tstpin.Port = *(DATA8*)PrimParPointer();
5212  Tstpin.Length = *(DATA8*)PrimParPointer();
5213  pPins = (DATA8*)PrimParPointer();
5214 
5215  for (Index = 0;Index < Tstpin.Length;Index++)
5216  {
5217  Tstpin.String[Index] = pPins[Index];
5218  }
5219  File = open(TEST_PIN_DEVICE_NAME,O_RDWR | O_SYNC);
5220  if (File >= MIN_HANDLE)
5221  {
5222  ioctl(File,TST_PIN_WRITE,&Tstpin);
5223  close(File);
5224  }
5225 
5226  }
5227  break;
5228 
5229  case TST_READ_ADC :
5230  {
5231  Index = *(DATA8*)PrimParPointer();
5232  Value = DATA16_NAN;
5233 
5234  if ((Index >= 0) && (Index < 4))
5235  {
5236  Value = (*InputInstance.pAnalog).InPin1[Index];
5237  }
5238  if ((Index >= 4) && (Index < 8))
5239  {
5240  Value = (*InputInstance.pAnalog).InPin6[Index - 4];
5241  }
5242  if ((Index >= 8) && (Index < 12))
5243  {
5244  Value = (*InputInstance.pAnalog).OutPin5[Index - 8];
5245  }
5246  if (Index == 12)
5247  {
5248  Value = (*InputInstance.pAnalog).BatteryTemp;
5249  }
5250  if (Index == 13)
5251  {
5252  Value = (*InputInstance.pAnalog).MotorCurrent;
5253  }
5254  if (Index == 14)
5255  {
5256  Value = (*InputInstance.pAnalog).BatteryCurrent;
5257  }
5258  if (Index == 15)
5259  {
5260  Value = (*InputInstance.pAnalog).Cell123456;
5261  }
5262 
5263  *(DATA16*)PrimParPointer() = Value;
5264  }
5265  break;
5266 
5267  case TST_ENABLE_UART :
5268  {
5269  Tstuart.Bitrate = *(DATA32*)PrimParPointer();
5270  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
5271  if (File >= 0)
5272  {
5273  ioctl(File,TST_UART_EN,&Tstuart);
5274  close(File);
5275  }
5276  }
5277  break;
5278 
5279  case TST_DISABLE_UART :
5280  {
5281  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
5282  if (File >= MIN_HANDLE)
5283  {
5284  ioctl(File,TST_UART_DIS,&Tstuart);
5285  close(File);
5286  }
5287  }
5288  break;
5289 
5290  case TST_WRITE_UART :
5291  {
5292  Tstuart.Port = *(DATA8*)PrimParPointer();
5293  Tstuart.Length = *(DATA8*)PrimParPointer();
5294  pPins = (DATA8*)PrimParPointer();
5295 
5296  if (Tstuart.Port < INPUTS)
5297  {
5298  for (Index = 0;(Index < Tstuart.Length) && (Index < TST_UART_LENGTH);Index++)
5299  {
5300  Tstuart.String[Index] = pPins[Index];
5301  }
5302  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
5303  if (File >= MIN_HANDLE)
5304  {
5305  ioctl(File,TST_UART_WRITE,&Tstuart);
5306  close(File);
5307  }
5308  }
5309  }
5310  break;
5311 
5312  case TST_READ_UART :
5313  {
5314  Tstuart.Port = *(DATA8*)PrimParPointer();
5315  Tstuart.Length = *(DATA8*)PrimParPointer();
5316  pPins = (DATA8*)PrimParPointer();
5317 
5318  for (Index = 0;(Index < Tstuart.Length) && (Index < TST_UART_LENGTH);Index++)
5319  {
5320  Tstuart.String[Index] = 0;
5321  }
5322  if (Tstuart.Port < INPUTS)
5323  {
5324  File = open(TEST_UART_DEVICE_NAME,O_RDWR | O_SYNC);
5325  if (File >= MIN_HANDLE)
5326  {
5327  ioctl(File,TST_UART_READ,&Tstuart);
5328  close(File);
5329  }
5330  }
5331  for (Index = 0;(Index < Tstuart.Length) && (Index < TST_UART_LENGTH);Index++)
5332  {
5333  pPins[Index] = Tstuart.String[Index];
5334  }
5335  }
5336  break;
5337 
5338  case TST_ACCU_SWITCH :
5339  {
5340  Data8 = 0;
5341  if (UiInstance.PowerFile >= MIN_HANDLE)
5342  {
5343  read(UiInstance.PowerFile,Buffer,2);
5344  if (Buffer[0] == '1')
5345  {
5346  Data8 = 1;
5347  }
5348  }
5349  *(DATA8*)PrimParPointer() = Data8;
5350  }
5351  break;
5352 
5353 #ifndef Linux_X86
5354  case TST_BOOT_MODE2:
5355  {
5356  I2cStart();
5357  }
5358  break;
5359 
5360  case TST_POLL_MODE2:
5361  {
5362  Data8 = I2cGetBootStatus();
5363  *(DATA8*)PrimParPointer() = Data8;
5364  }
5365  break;
5366 
5367  case TST_CLOSE_MODE2:
5368  {
5369  I2cStop();
5370  }
5371  break;
5372 #endif
5373 
5374  case TST_RAM_CHECK:
5375  {
5376  ULONG RamCheckFile;
5377  UBYTE RamStatus[2];
5378 
5379  RamCheckFile = open(UPDATE_DEVICE_NAME,O_RDWR);
5380  Data8 = FAIL;
5381  if (RamCheckFile >= 0)
5382  {
5383  read(RamCheckFile,RamStatus,2);
5384  close(RamCheckFile);
5385 
5386  if ((RamStatus[0] == ((UBYTE)(~(RamStatus[1])))) && (0 == RamStatus[0]))
5387  {
5388  Data8 = OK;
5389  }
5390  }
5391  *(DATA8*)PrimParPointer() = Data8;
5392  }
5393  break;
5394 
5395  default :
5396  { // Test close
5397 
5398  TstClose();
5399  }
5400  break;
5401 
5402  }
5403  }
5404  else
5405  {
5406  ProgramEnd(VMInstance.ProgramId);
5407  VMInstance.Program[VMInstance.ProgramId].Result = FAIL;
5409  }
5410  }
5411 }
5412 
5413 #ifdef BUFPRINTSIZE
5414 
5415 #include <stdarg.h>
5416 
5417 void BufPrint(char Cmd,char *pFormat, ...)
5418 {
5419  static char Buf[BUFPRINTSIZE];
5420  static ULONG BufIn = 0;
5421  static char Full = 0;
5422  char Format[16];
5423  int FormatIn = 0;
5424  int FormatOut = 0;
5425  char Par = 0;
5426  char Char;
5427 #ifdef DEBUG_D_UART_ERROR
5428  int File;
5429 #endif
5430  va_list pArg;
5431 
5432  va_start(pArg,pFormat);
5433 
5434  switch (Cmd)
5435  {
5436  case 'p' :
5437  {
5438  if (!Full)
5439  {
5440  while ((pFormat[FormatIn]) && (BufIn < (BUFPRINTSIZE - 250)))
5441  {
5442  Char = pFormat[FormatIn];
5443  if ((Char != '%') && (Par == 0))
5444  {
5445  Buf[BufIn] = Char;
5446  BufIn++;
5447  FormatIn++;
5448  }
5449  else
5450  {
5451  Par = 1;
5452  Format[FormatOut] = Char;
5453  FormatOut++;
5454  FormatIn++;
5455  Format[FormatOut] = 0;
5456  switch (Char)
5457  {
5458  case 'c' :
5459  case 'd' :
5460  case 'x' :
5461  case 'X' :
5462  {
5463  BufIn += sprintf(&Buf[BufIn],"%-3d",va_arg(pArg, int));
5464  Par = 0;
5465  }
5466  break;
5467 
5468  case 'f' :
5469  {
5470  BufIn += sprintf(&Buf[BufIn],Format,va_arg(pArg, double));
5471  Par = 0;
5472  }
5473  break;
5474 
5475  case 's' :
5476  {
5477  BufIn += sprintf(&Buf[BufIn],Format,va_arg(pArg, char *));
5478  Par = 0;
5479  }
5480  break;
5481 
5482  default :
5483  {
5484 
5485  }
5486  break;
5487 
5488  }
5489  if (Par == 0)
5490  {
5491  FormatOut = 0;
5492  }
5493  }
5494  }
5495  if (BufIn >= (BUFPRINTSIZE - 250))
5496  {
5497  sprintf(&Buf[BufIn],"\r\nBUFFER FULL\r\n");
5498  }
5499  }
5500  }
5501  break;
5502 
5503  case 'w' :
5504  {
5505  Buf[BufIn] = 0;
5506  printf("\r\n------------------------------------------------------------\r\n");
5507  printf("%s",Buf);
5508  if ((BufIn > 0) && (Buf[BufIn - 1] != '\n'))
5509  {
5510  printf("\r\n");
5511  }
5512  printf("------------------------------------------------------------\r\n\n");
5513  Par = 0;
5514  BufIn = 0;
5515  FormatOut = 0;
5516  Full = 0;
5517 
5518 #ifdef DEBUG_D_UART_ERROR
5519  Buf[BufIn] = 0;
5520  File = open(UART_DEVICE_NAME,O_RDONLY);
5521  if (File >= MIN_HANDLE)
5522  {
5523  read(File,Buf,BUFPRINTSIZE);
5524  printf("%s",Buf);
5525 
5526  close(File);
5527  }
5528 #endif
5529  }
5530  break;
5531 
5532  }
5533 
5534  va_end(pArg);
5535 }
5536 
5537 #endif
5538 
5539 /*
5540 #define vmCHARSET_NAME 0x01 //!< Character set allowed in brick name and raw filenames
5541 #define vmCHARSET_FILENAME 0x02 //!< Character set allowed in file names
5542 #define vmCHARSET_BTPASSKEY 0x04 //!< Character set allowed in bluetooth pass key
5543 #define vmCHARSET_WIFIPASSKEY 0x08 //!< Character set allowed in WiFi pass key
5544 #define vmCHARSET_WIFISSID 0x10 //!< Character set allowed in WiFi ssid
5545 */
5546 
5548 {
5549  0x00, // 0x00 NUL
5550  0x00, // 0x01 SOH
5551  0x00, // 0x02 STX
5552  0x00, // 0x03 ETX
5553  0x00, // 0x04 EOT
5554  0x00, // 0x05 ENQ
5555  0x00, // 0x06 ACK
5556  0x00, // 0x07 BEL
5557  0x00, // 0x08 BS
5558  0x00, // 0x09 TAB
5559  0x00, // 0x0A LF
5560  0x00, // 0x0B VT
5561  0x00, // 0x0C FF
5562  0x00, // 0x0D CR
5563  0x00, // 0x0E SO
5564  0x00, // 0x0F SI
5565  0x00, // 0x10 DLE
5566  0x00, // 0x11 DC1
5567  0x00, // 0x12 DC2
5568  0x00, // 0x13 DC3
5569  0x00, // 0x14 DC4
5570  0x00, // 0x15 NAK
5571  0x00, // 0x16 SYN
5572  0x00, // 0x17 ETB
5573  0x00, // 0x18 CAN
5574  0x00, // 0x19 EM
5575  0x00, // 0x1A SUB
5576  0x00, // 0x1B ESC
5577  0x00, // 0x1C FS
5578  0x00, // 0x1D GS
5579  0x00, // 0x1E RS
5580  0x00, // 0x1F US
5581  0x12, // 0x20 (space)
5582  0x00, // 0x21 !
5583  0x00, // 0x22 "
5584  0x00, // 0x23 #
5585  0x00, // 0x24 $
5586  0x00, // 0x25 %
5587  0x00, // 0x26 &
5588  0x00, // 0x27 '
5589  0x00, // 0x28 (
5590  0x00, // 0x29 )
5591  0x00, // 0x2A *
5592  0x00, // 0x2B +
5593  0x00, // 0x2C ,
5594  0x03, // 0x2D -
5595  0x02, // 0x2E .
5596  0x02, // 0x2F /
5597  0x1F, // 0x30 0
5598  0x1F, // 0x31 1
5599  0x1F, // 0x32 2
5600  0x1F, // 0x33 3
5601  0x1F, // 0x34 4
5602  0x1F, // 0x35 5
5603  0x1F, // 0x36 6
5604  0x1F, // 0x37 7
5605  0x1F, // 0x38 8
5606  0x1F, // 0x39 9
5607  0x00, // 0x3A :
5608  0x00, // 0x3B ;
5609  0x00, // 0x3C <
5610  0x00, // 0x3D =
5611  0x00, // 0x3E >
5612  0x00, // 0x3F ?
5613  0x00, // 0x40 @
5614  0x1F, // 0x41 A
5615  0x1F, // 0x42 B
5616  0x1F, // 0x43 C
5617  0x1F, // 0x44 D
5618  0x1F, // 0x45 E
5619  0x1F, // 0x46 F
5620  0x1F, // 0x47 G
5621  0x1F, // 0x48 H
5622  0x1F, // 0x49 I
5623  0x1F, // 0x4A J
5624  0x1F, // 0x4B K
5625  0x1F, // 0x4C L
5626  0x1F, // 0x4D M
5627  0x1F, // 0x4E N
5628  0x1F, // 0x4F O
5629  0x1F, // 0x50 P
5630  0x1F, // 0x51 Q
5631  0x1F, // 0x52 R
5632  0x1F, // 0x53 S
5633  0x1F, // 0x54 T
5634  0x1F, // 0x55 U
5635  0x1F, // 0x56 V
5636  0x1F, // 0x57 W
5637  0x1F, // 0x58 X
5638  0x1F, // 0x59 Y
5639  0x1F, // 0x5A Z
5640  0x00, // 0x5B [
5641  0x00, // 0x5C '\'
5642  0x00, // 0x5D ]
5643  0x00, // 0x5E ^
5644  0x1F, // 0x5F _
5645  0x00, // 0x60 `
5646  0x1F, // 0x61 a
5647  0x1F, // 0x62 b
5648  0x1F, // 0x63 c
5649  0x1F, // 0x64 d
5650  0x1F, // 0x65 e
5651  0x1F, // 0x66 f
5652  0x1F, // 0x67 g
5653  0x1F, // 0x68 h
5654  0x1F, // 0x69 i
5655  0x1F, // 0x6A j
5656  0x1F, // 0x6B k
5657  0x1F, // 0x6C l
5658  0x1F, // 0x6D m
5659  0x1F, // 0x6E n
5660  0x1F, // 0x6F o
5661  0x1F, // 0x70 p
5662  0x1F, // 0x71 q
5663  0x1F, // 0x72 r
5664  0x1F, // 0x73 s
5665  0x1F, // 0x74 t
5666  0x1F, // 0x75 u
5667  0x1F, // 0x76 v
5668  0x1F, // 0x77 w
5669  0x1F, // 0x78 x
5670  0x1F, // 0x79 y
5671  0x1F, // 0x7A z
5672  0x00, // 0x7B {
5673  0x00, // 0x7C |
5674  0x00, // 0x7D }
5675  0x02, // 0x7E ~
5676  0x00 // 0x7F 
5677 };
5678 
5679 
5680 RESULT ValidateChar(DATA8 *pChar,DATA8 Set)
5681 {
5682  RESULT Result = OK;
5683 
5684  if ((ValidChars[*pChar] & Set) == 0)
5685  {
5686  *pChar = '_';
5687  Result = FAIL;
5688  }
5689 
5690  return (Result);
5691 }
5692 
5693 
5694 RESULT ValidateString(DATA8 *pString,DATA8 Set)
5695 {
5696  RESULT Result = OK;
5697 
5698  while (*pString)
5699  {
5700  Result |= ValidateChar(pString,Set);
5701  pString++;
5702  }
5703 
5704  return (Result);
5705 }
void cMove32to32(void)
opMOVE32_32
Definition: c_move.c:374
DATA8 LogErrorNumberExists(ERR Error)
Definition: lms2012.c:470
RESULT cOutputInit(void)
Definition: c_output.c:196
DATA32 Bitrate
Definition: lms2012.h:1196
void cMathAnd16(void)
opAND16
Definition: c_math.c:592
void ObjectDeQueue(OBJID Id)
Remove object from run queue.
Definition: lms2012.c:1843
void cMathSub16(void)
opSUB16
Definition: c_math.c:171
void cMoveWriteF(void)
opWRITEF
Definition: c_move.c:740
void ObjectCall(void)
opCALL byte code
Definition: lms2012.c:3173
DATA32 SdcardSize
Definition: lms2012.h:1485
DSPSTAT ExecuteByteCode(IP pByteCode, GP pGlobals, LP pLocals)
Execute byte code stream (C-call)
Definition: lms2012.c:535
RESULT Result
Program result (OK, BUSY, FAIL)
Definition: lms2012.h:755
void SetDispatchStatus(DSPSTAT DspStat)
Set object (dispatch) status.
Definition: lms2012.c:256
void cCompareLtEq16(void)
opCP_LTEQ16 byte code
Definition: c_compare.c:571
void cComRead(void)
opCOM_READ byte code
Definition: c_com.c:3416
void cInputDeviceList(void)
opINPUT_DEVICE_LIST byte code
Definition: c_input.c:3678
UBYTE PARS
NoOfParameters type.
Definition: lmstypes.h:82
DATA8 Port
Definition: lms2012.h:1178
void cComWriteMailBox(void)
opMAILBOX_WRITE byte code
Definition: c_com.c:3628
Object is halted because a call is in progress.
Definition: bytecodes.h:1518
RESULT cValidateDisassemble(IP pI, IMINDEX *pIndex, LABEL *pLabel)
Definition: validate.c:251
char Char
Definition: tistdtypes.h:54
void cBranchJrTrue(void)
opJR_TRUE byte code
Definition: c_branch.c:89
DATA8 Port
Definition: lms2012.h:1197
void PrimParAdvance(void)
Skip next encoded parameter from byte code stream.
Definition: lms2012.c:870
void ObjectEnQueue(OBJID Id)
Put object on run queue.
Definition: lms2012.c:1827
#define OP(a, b, c, d, s, T)
void cOutputSetType(void)
opOUTPUT_SET_TYPE byte code
Definition: c_output.c:458
#define TST_PIN_ON
Definition: lms2012.h:1184
#define PRIMPAR_HANDLE
Definition: bytecodes.h:1591
void AdjustObjectIp(IMOFFS Value)
Adjust current instruction pointer.
Definition: lms2012.c:287
char PrintBuffer[PRINTBUFFERSIZE+1]
Definition: lms2012.h:1426
void cBranchJrNEq16(void)
opJR_NEQ16 byte code
Definition: c_branch.c:552
ULONG IMINDEX
ImageData index type.
Definition: lmstypes.h:78
#define snprintf
Definition: c_input.c:141
GP pGlobal
Pointer to start of global bytes.
Definition: lms2012.h:1436
RESULT cOutputOpen(void)
Definition: c_output.c:234
void cBranchJrGtEqF(void)
opJR_GTEQF byte code
Definition: c_branch.c:862
void(* PRIM)(void)
Prototype for all byte codes.
Definition: lms2012.h:678
RESULT cValidateExit(void)
Definition: validate.c:222
#define PRIMPAR_BYTES
Definition: bytecodes.h:1598
void cBranchJrLtEq8(void)
opJR_LTEQ8 byte code
Definition: c_branch.c:645
void cMemoryFile(void)
opFILE byte code
Definition: c_memory.c:2303
void cBranchJrNEq32(void)
opJR_NEQ32 byte code
Definition: c_branch.c:583
void cOutputTimeSync(void)
opOUTPUT_STEP_SYNC byte code
Definition: c_output.c:1440
IP pImage
Pointer to start of image.
Definition: lms2012.h:742
void cCompareLtEq8(void)
opCP_LTEQ8 byte code
Definition: c_compare.c:540
void cMath(void)
opMATH
Definition: c_math.c:925
void cSoundEntry(void)
opSOUND byte code
Definition: c_sound.c:440
void cCompareSelect8(void)
opSELECT8 byte code
Definition: c_compare.c:789
void ProgramInit(void)
Switch in current program ProgramId holds program to switch to.
Definition: lms2012.c:1605
LABEL Label[MAX_LABELS]
Storage for labels.
Definition: lms2012.h:759
void cMove16to8(void)
opMOVE16_8
Definition: c_move.c:183
UBYTE VARDATA
Variable base type.
Definition: lmstypes.h:68
ULONG GetTimeUS(void)
Definition: lms2012.c:327
void cCompareGtEq32(void)
opCP_GTEQ32 byte code
Definition: c_compare.c:726
void CleanLogErrors(void)
Definition: lms2012.c:512
RESULT cMemoryInit(void)
Definition: c_memory.c:375
DATA8 GetTerminalEnable(void)
Definition: lms2012.c:354
OBJHEAD * pObjHead
Pointer to start of object headers.
Definition: lms2012.h:1437
#define PRIMPAR_INDEX
Definition: bytecodes.h:1594
Break because of fail.
Definition: lms2012.h:674
ULONG cTimerGetuS(void)
Definition: c_timer.c:49
void cUiButton(void)
opUI_BUTTON byte code
Definition: c_ui.c:7487
void cComUpdate(void)
Definition: c_com.c:2448
void cCompareEq16(void)
opCP_EQ16 byte code
Definition: c_compare.c:323
DATA8 CheckUsbstick(DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
Definition: lms2012.c:1959
void cTimerReaduS(void)
opTIMER_READ_US byte code
Definition: c_timer.c:152
void cCompareLtF(void)
opCP_LTF byte code
Definition: c_compare.c:137
SWORD DATA16
VM Type for 2 byte signed value.
Definition: lmstypes.h:62
void cBranchJrGt8(void)
opJR_GT8 byte code
Definition: c_branch.c:273
void cMathDiv16(void)
opDIV16
Definition: c_math.c:386
void Random(void)
opRANDOM byte code
Definition: lms2012.c:3665
#define PRIMPAR_LONG
Definition: bytecodes.h:1585
void Probe(void)
opPROBE byte code
Definition: lms2012.c:3431
void LogErrorNumber(ERR Err)
Definition: lms2012.c:445
void Do(void)
opDO byte code
Definition: lms2012.c:3509
#define PRIMPAR_GLOBAL
Definition: bytecodes.h:1590
void cBranchJrEq32(void)
opJR_EQ32 byte code
Definition: c_branch.c:459
#define PRIMPAR_1_BYTE
Definition: bytecodes.h:1601
void cCompareNEq16(void)
opCP_NEQ16 byte code
Definition: c_compare.c:447
void cMemoryArrayWrite(void)
opARRAY_WRITE byte code
Definition: c_memory.c:3935
OBJID ObjectId
Active object id.
Definition: lms2012.h:751
void Tst(void)
opTST byte code
Definition: lms2012.c:5160
void cCompareGtEq8(void)
opCP_GTEQ8 byte code
Definition: c_compare.c:664
void cCompareSelect16(void)
opSELECT16 byte code
Definition: c_compare.c:825
void Nop(void)
opNOP byte code
Definition: lms2012.c:2857
SLONG DATA32
VM Type for 4 byte signed value.
Definition: lmstypes.h:63
void ObjectStart(void)
opOBJECT_START byte code
Definition: lms2012.c:3016
#define TST_UART_ON
Definition: lms2012.h:1203
UBYTE I2cGetBootStatus(void)
Definition: c_i2c.c:809
RESULT cMemoryGetMediaName(char *pChar, char *pName)
Definition: c_memory.c:1504
void NoteToFreq(void)
Definition: lms2012.c:4516
OBJSTAT StatusChange
Program status change.
Definition: lms2012.h:754
RESULT cInputClose(void)
Definition: c_input.c:3574
RESULT cOutputExit(void)
Definition: c_output.c:259
void cMove32toF(void)
opMOVE32_F
Definition: c_move.c:396
void cBranchJrLtF(void)
opJR_LTF byte code
Definition: c_branch.c:242
#define CALLPAR_OUT
Definition: bytecodes.h:1637
RESULT cMemoryArraryPointer(PRGID PrgId, HANDLER Handle, void **pMemory)
Definition: c_memory.c:277
Object is waiting for final trigger.
Definition: bytecodes.h:1516
void cInputDevice(void)
opINPUT_DEVICE byte code
Definition: c_input.c:3887
#define TST_PIN_OFF
Definition: lms2012.h:1185
void cCompareSelect32(void)
opSELECT32 byte code
Definition: c_compare.c:862
#define IDX_BACK_BUTTON
Definition: lms2012.c:112
void cMathMulF(void)
opMULF
Definition: c_math.c:321
UWORD OBJID
Object id type.
Definition: lmstypes.h:73
void cMove8to16(void)
opMOVE8_16
Definition: c_move.c:95
#define KB
Definition: lms2012.h:553
OP OpCode
Saved substituted opcode.
Definition: lms2012.h:727
void cMove8to32(void)
opMOVE8_32
Definition: c_move.c:125
void SetObjectIp(IP Ip)
Set current instruction pointer.
Definition: lms2012.c:309
void cMathAdd8(void)
opADD8
Definition: c_math.c:46
RESULT ValidateChar(DATA8 *pChar, DATA8 Set)
Definition: lms2012.c:5680
int AdcFile
Definition: lms2012.h:1503
DATA8 Length
Definition: lms2012.h:1198
void cCompareGt16(void)
opCP_GT16 byte code
Definition: c_compare.c:199
void cBranchJrNEq8(void)
opJR_NEQ8 byte code
Definition: c_branch.c:521
void cBranchJrLt8(void)
opJR_LT8 byte code
Definition: c_branch.c:149
DATA8 cUiEscape(void)
Definition: c_ui.c:1091
void cInputReadExt(void)
opINPUT_READEXT byte code
Definition: c_input.c:4950
UWORD RefCount
Definition: lms2012.h:1458
void cMathAddF(void)
opADDF
Definition: c_math.c:121
void cUiRead(void)
opUI_READ byte code
Definition: c_ui.c:6614
void cMemoryFileName(void)
opFILENAME byte code
Definition: c_memory.c:4347
void cOutputReset(void)
opOUTPUT_RESET byte code
Definition: c_output.c:538
DATA16 HANDLER
Memory list index.
Definition: lmstypes.h:85
RESULT mSchedExit(void)
Definition: lms2012.c:2513
#define PRIMPAR_VALUE
Definition: bytecodes.h:1596
void cUiFlush(void)
opUI_FLUSH byte code
Definition: c_ui.c:6497
DATA8 TerminalEnabled
Definition: lms2012.h:1427
void cBranchJrLtEqF(void)
opJR_LTEQF byte code
Definition: c_branch.c:738
ULONG Priority
Object priority.
Definition: lms2012.h:1471
void cCompareLtEq32(void)
opCP_LTEQ32 byte code
Definition: c_compare.c:602
void cCompareSelectF(void)
opSELECTF byte code
Definition: c_compare.c:898
#define TST_UART_LENGTH
Definition: lms2012.h:1192
void cBranchJrEq8(void)
opJR_EQ8 byte code
Definition: c_branch.c:397
void cMove8to8(void)
opMOVE8_8
Definition: c_move.c:73
void cCompareGt8(void)
opCP_GT8 byte code
Definition: c_compare.c:168
void * PrimParPointer(void)
Get next encoded parameter from byte code stream.
Definition: lms2012.c:694
#define PRIMPAR_VARIABEL
Definition: bytecodes.h:1588
void cBranchJrEqF(void)
opJR_EQF byte code
Definition: c_branch.c:490
void cInputRead(void)
opINPUT_READ byte code
Definition: c_input.c:4688
void cOutputStepSpeed(void)
opOUTPUT_STEP_SPEED byte code
Definition: c_output.c:1155
UWORD Debug
Debug flag.
Definition: lms2012.h:760
GP pData
Pointer to start of data.
Definition: lms2012.h:743
void System(void)
Definition: lms2012.c:4550
ULONG RunTime
Program run time [uS].
Definition: lms2012.h:740
IP GetObjectIp(void)
Get current instruction pointer.
Definition: lms2012.c:298
#define TST_PIN_WRITE
Definition: lms2012.h:1187
OBJHEAD * pObjHead
Pointer to start of object headers.
Definition: lms2012.h:745
void cMemoryArray(void)
opARRAY byte code
Definition: c_memory.c:3392
void cInputWrite(void)
opINPUT_WRITE byte code
Definition: c_input.c:4827
void ObjectWait(void)
opOBJECT_WAIT byte code
Definition: lms2012.c:3086
void cMemoryUsage(void)
opMEMORY_USAGE byte code
Definition: c_memory.c:4257
RESULT cInputExit(void)
Definition: c_input.c:3584
void MemoryWrite(void)
opMEMORY_WRITE byte code
Definition: lms2012.c:4266
#define ERR_STRING_SIZE
Definition: lms2012.h:921
ULONG Value
Definition: lms2012.h:1473
DSPSTAT DispatchStatus
Dispatch status.
Definition: lms2012.h:1470
RESULT ObjectExec(void)
Find next object to run.
Definition: lms2012.c:1774
void cBranchJrNEqF(void)
opJR_NEQF byte code
Definition: c_branch.c:614
GP ObjGlobalSave
Definition: lms2012.h:1446
void SetInstructions(ULONG Instructions)
Set instructions.
Definition: lms2012.c:273
ULONG cTimerGetmS(void)
Definition: c_timer.c:36
Break because of opcode break.
Definition: lms2012.h:670
void cMoveRead16(void)
opREAD16
Definition: c_move.c:584
#define TST_PIN_READ
Definition: lms2012.h:1186
UBYTE ErrorIn
Definition: lms2012.h:1477
#define VMTHREADHeader(OffsetToInstructions, LocalBytes)
Definition: bytecodes.h:1573
void cMathXor16(void)
opXOR16
Definition: c_math.c:667
void cMove16to16(void)
opMOVE16_16
Definition: c_move.c:220
OBJID CallingObjectId(void)
Get calling object id.
Definition: lms2012.c:196
#define NOTES
Definition: lms2012.c:4456
Break because of program stop.
Definition: lms2012.h:668
RESULT cSoundOpen(void)
Definition: c_sound.c:105
RESULT cMemoryExit(void)
Definition: c_memory.c:448
void cMoveReadF(void)
opREADF
Definition: c_move.c:634
DATA8 String[TST_PIN_LENGTH+1]
Definition: lms2012.h:1180
DSPSTAT DispatchStatusSave
Definition: lms2012.h:1448
ULONG InstrCnt
Instruction counter (performance test)
Definition: lms2012.h:1434
#define PROGRAMHeader(VersionInfo, NumberOfObjects, GlobalBytes)
Definition: bytecodes.h:1570
RESULT cComClose(void)
Definition: c_com.c:213
void SetSleepMinutes(DATA8 Minutes)
Definition: lms2012.c:384
RESULT cInputOpen(void)
Definition: c_input.c:3564
void I2cStop(void)
Definition: c_i2c.c:213
void cMoveFtoF(void)
opMOVEF_F
Definition: c_move.c:536
OBJSTAT ProgramStatus(PRGID PrgId)
Get program status.
Definition: lms2012.c:218
OBJID Objects
No of objects in image.
Definition: lms2012.h:1442
DATA32 SdcardFree
Definition: lms2012.h:1486
void cUiWrite(void)
opUI_WRITE byte code
Definition: c_ui.c:7115
#define UPDATE_TIME2
Update repeat time2 [mS].
Definition: lms2012.h:521
void Info(void)
opINFO byte code
Definition: lms2012.c:3734
#define Timer
IMGDATA * IP
Instruction pointer type.
Definition: lmstypes.h:74
RESULT TstOpen(UWORD Time)
Definition: lms2012.c:4742
void cMathRl32(void)
opRL32
Definition: c_math.c:767
IP GetImageStart(void)
Get pointer to actual start of byte code image.
Definition: lms2012.c:245
RESULT cMemoryOpen(PRGID PrgId, GBINDEX Size, void **pMemory)
Definition: c_memory.c:426
void BreakSet(void)
opBP_SET byte code
Definition: lms2012.c:3611
void cMathOr8(void)
opOR8
Definition: c_math.c:492
ULONG CurrentObjectIp(void)
Definition: lms2012.c:333
void cOutputClrCount(void)
opOUTPUT_CLR_COUNT byte code
Definition: c_output.c:1705
#define PRIMPAR_STRING
Definition: bytecodes.h:1604
void GetResourcePath(char *pString, DATA8 MaxLength)
Definition: lms2012.c:360
DATA8 GetSleepMinutes(void)
Definition: lms2012.c:390
void PortCnvInput(void)
Definition: lms2012.c:4434
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
Definition: lmstypes.h:31
void cBranchJrEq16(void)
opJR_EQ16 byte code
Definition: c_branch.c:428
void cInputReady(void)
opINPUT_READY byte code
Definition: c_input.c:4793
void cTimerReady(void)
opTIMER_READY byte code
Definition: c_timer.c:101
ULONG InstrCnt
Instruction counter used for performance analyses.
Definition: lms2012.h:736
#define PRIMPAR_2_BYTES
Definition: bytecodes.h:1602
void cComRemove(void)
Definition: c_com.c:5516
void cUiKeepAlive(void)
opKEEP_ALIVE byte code
Definition: c_ui.c:7697
void cMathAnd32(void)
opAND32
Definition: c_math.c:617
ULONG OldTime2
Definition: lms2012.h:1463
void cTimerRead(void)
opTIMER_READ byte code
Definition: c_timer.c:134
void cMemoryArrayRead(void)
opARRAY_READ byte code
Definition: c_memory.c:4047
void cComOpenMailBox(void)
opMAILBOX_OPEN byte code
Definition: c_com.c:3573
ULONG GBINDEX
GlobalBytes index type.
Definition: lmstypes.h:79
void cOutputStepPower(void)
opOUTPUT_STEP_POWER byte code
Definition: c_output.c:978
void cUiTestpin(DATA8 State)
Definition: c_ui.c:1102
void ObjectReturn(void)
opRETURN byte code
Definition: lms2012.c:3118
ULONG StartTime
Program start time [mS].
Definition: lms2012.h:739
void cMoveRead8(void)
opREAD8
Definition: c_move.c:559
void cComReady(void)
opCOM_READY byte code
Definition: c_com.c:3281
#define PRIMPAR_CONST_SIGN
Definition: bytecodes.h:1595
void cMoveFto8(void)
opMOVEF_8
Definition: c_move.c:425
RESULT mSchedInit(int argc, char *argv[])
Definition: lms2012.c:2063
#define PRIMPAR_STRING_OLD
Definition: bytecodes.h:1600
void ObjectStop(void)
opOBJECT_STOP byte code
Definition: lms2012.c:2993
void ProgramExit(void)
Switch out current program ProgramId holds program to switch from.
Definition: lms2012.c:1635
Definition: lms2012.h:734
LP ObjLocalSave
Definition: lms2012.h:1447
LBINDEX LocalBytes
Number of bytes to allocate for local variables.
Definition: lmstypes.h:172
#define GV0(i)
Definition: bytecodes.h:1627
void cComCloseMailBox(void)
opMAILBOX_CLOSE byte code
Definition: c_com.c:3958
void cMemoryArrayAppend(void)
opARRAY_APPEND byte code
Definition: c_memory.c:4134
#define TST_UART_READ
Definition: lms2012.h:1207
void cInputUpdate(UWORD Time)
Definition: c_input.c:3356
RESULT cValidateInit(void)
Definition: validate.c:164
#define UiInstance
Definition: c_ui.h:460
void cMoveFto32(void)
opMOVEF_32
Definition: c_move.c:499
void cMathDivF(void)
opDIVF
Definition: c_math.c:466
DATA8 String[TST_UART_LENGTH]
Definition: lms2012.h:1199
void ProgramStart(void)
opPROGRAM_START byte code
Definition: lms2012.c:2926
void cCompareLt16(void)
opCP_LT16 byte code
Definition: c_compare.c:75
RESULT cSoundClose(void)
Definition: c_sound.c:114
void cSoundTest(void)
opSOUND_TEST byte code
Definition: c_sound.c:773
#define UPDATE_USBSTICK
Update usbstick size [mS].
Definition: lms2012.h:524
Break because of program break.
Definition: lms2012.h:672
void PortCnvOutput(void)
Definition: lms2012.c:4402
void cOutputStepSync(void)
opOUTPUT_STEP_SYNC byte code
Definition: c_output.c:1355
void cOutputRead(void)
opOUTPUT_READ byte code
Definition: c_output.c:1520
void cMathXor8(void)
opXOR8
Definition: c_math.c:642
RESULT cOutputClose(void)
Definition: c_output.c:253
DATA8 SdcardOk
Definition: lms2012.h:1488
void cBranchJrGtEq16(void)
opJR_GTEQ16 byte code
Definition: c_branch.c:800
RESULT cMemoryClose(PRGID PrgId)
Definition: c_memory.c:437
void cOutputPower(void)
opOUTPUT_POWER byte code
Definition: c_output.c:751
ANALOG Analog
Definition: lms2012.h:1501
RESULT cUiExit(void)
Definition: c_ui.c:898
#define BUTTON_LONGPRESS
button long press detected
Definition: c_ui.h:304
#define PRIMPAR_4_BYTES
Definition: bytecodes.h:1603
void cComWrite(void)
opCOM_WRITE byte code
Definition: c_com.c:3472
int main(int argc, char *argv[])
Definition: lms2012.c:2569
TRIGGER TriggerCount
Trigger count used by BLOCK's trigger logic.
Definition: lms2012.h:714
void cCompareLt8(void)
opCP_LT8 byte code
Definition: c_compare.c:44
void * cMemoryResize(PRGID PrgId, HANDLER TmpHandle, DATA32 Elements)
Definition: c_memory.c:468
TRIGGER TriggerCount
Used to determine how many triggers needed before the BLOCK object is activated.
Definition: lmstypes.h:171
void cOutputPolarity(void)
opOUTPUT_POLARITY byte code
Definition: c_output.c:909
void cSoundReady(void)
opSOUND_READY byte code
Definition: c_sound.c:797
void cBranchJrLtEq16(void)
opJR_LTEQ16 byte code
Definition: c_branch.c:676
ULONG InstrTime
Instruction time used for performance analyses.
Definition: lms2012.h:737
void cCompareEq32(void)
opCP_EQ32 byte code
Definition: c_compare.c:354
RESULT cComOpen(void)
Definition: c_com.c:203
void Sleep(void)
opSLEEP byte code
Definition: lms2012.c:3270
#define CALLPAR_TYPE
Definition: bytecodes.h:1639
ULONG OldTime1
Definition: lms2012.h:1462
void cBranchJrGt32(void)
opJR_GT32 byte code
Definition: c_branch.c:335
#define PRINTBUFFERSIZE
Definition: lms2012.h:1419
void cMathRl8(void)
opRL8
Definition: c_math.c:717
RESULT cUiOpen(void)
Definition: c_ui.c:859
OBJID OwnerObjectId
Used by BLOCK's to hold the owner id.
Definition: lmstypes.h:170
#define LC0(v)
Definition: bytecodes.h:1615
void cMove16toF(void)
opMOVE16_F
Definition: c_move.c:271
void cMathDiv32(void)
opDIV32
Definition: c_math.c:426
SLONG IMOFFS
ImageData offset type.
Definition: lmstypes.h:83
void cMoveRead32(void)
opREAD32
Definition: c_move.c:609
DSPSTAT ObjectInit(void)
Restore object context.
Definition: lms2012.c:1710
void cMathSub32(void)
opSUB32
Definition: c_math.c:196
void cInputTest(void)
opINPUT_TEST byte code
Definition: c_input.c:4758
void CopyLocalsToPars(OBJID Id)
Copy local variables to encoded parameters.
Definition: lms2012.c:1153
#define PRIMPAR_LABEL
Definition: bytecodes.h:1606
ULONG GetTimeMS(void)
Definition: lms2012.c:321
OBJ ** pObjList
Pointer to object pointer list.
Definition: lms2012.h:746
#define TST_UART_OFF
Definition: lms2012.h:1204
void cMove32to8(void)
opMOVE32_8
Definition: c_move.c:300
void cMathOr32(void)
opOR32
Definition: c_math.c:542
void cMathMul8(void)
opMUL8
Definition: c_math.c:246
void TstClose(void)
Definition: lms2012.c:4778
RESULT cComExit(void)
Definition: c_com.c:233
void cMove8toF(void)
opMOVE8_F
Definition: c_move.c:154
#define LV0(i)
Definition: bytecodes.h:1621
#define CALLPAR_DATA16
Definition: bytecodes.h:1641
char ErrString[ERRORS][ERR_STRING_SIZE]
Definition: lms2012.c:404
void cBranchJrGtEq32(void)
opJR_GTEQ32 byte code
Definition: c_branch.c:831
RESULT cSoundExit(void)
Definition: c_sound.c:396
NONVOL NonVol
Definition: lms2012.h:1423
void cCompareNEq32(void)
opCP_NEQ32 byte code
Definition: c_compare.c:478
void ProgramEnd(PRGID PrgId)
Exit program nicely (freeing up memory)
Definition: lms2012.c:1555
RESULT ValidateString(DATA8 *pString, DATA8 Set)
Definition: lms2012.c:5694
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
void cCompareGt32(void)
opCP_GT32 byte code
Definition: c_compare.c:230
void cMathSub8(void)
opSUB8
Definition: c_math.c:146
void SetTerminalEnable(DATA8 Value)
Definition: lms2012.c:348
PRG Program[MAX_PROGRAMS]
Program[0] is the UI byte codes running.
Definition: lms2012.h:1431
void cMathDiv8(void)
opDIV8
Definition: c_math.c:346
void cMathMul16(void)
opMUL16
Definition: c_math.c:271
void cBranchJrGtF(void)
opJR_GTF byte code
Definition: c_branch.c:366
void cCompareLt32(void)
opCP_LT32 byte code
Definition: c_compare.c:106
#define ERROR(ErrorCode)
Definition: lms2012.c:402
RESULT cSoundInit(void)
Definition: c_sound.c:71
#define UPDATE_SDCARD
Update sdcard size [mS].
Definition: lms2012.h:523
void ObjectEnd(void)
opOBJECT_END byte code
Definition: lms2012.c:3245
void MemoryRead(void)
opMEMORY_READ byte code
Definition: lms2012.c:4338
HANDLER Handle
Definition: lms2012.h:1474
void cBranchJr(void)
opJR byte code
Definition: c_branch.c:42
void cCompareGtEq16(void)
opCP_GTEQ16 byte code
Definition: c_compare.c:695
void cBranchJrLtEq32(void)
opJR_LTEQ32 byte code
Definition: c_branch.c:707
FLOAT DATAF
VM Type for 4 byte floating point value.
Definition: lmstypes.h:64
VARDATA * LP
Local variable pointer type.
Definition: lmstypes.h:75
UBYTE ErrorOut
Definition: lms2012.h:1478
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
Definition: lmstypes.h:30
void cOutputStop(void)
opOUTPUT_STOP byte code
Definition: c_output.c:606
void SetUiUpdate(void)
Definition: lms2012.c:396
UBYTE IMGDATA
Image base type.
Definition: lmstypes.h:69
char Buffer[1024]
Definition: c_wifi.c:102
BRKP Brkp[MAX_BREAKPOINTS]
Storage for breakpoint logic.
Definition: lms2012.h:757
void ProgramInfo(void)
opPROGRAM_INFO byte code
Definition: lms2012.c:3320
GBINDEX GetAmountOfRamForImage(IP pI)
Get amount of ram to allocate for program.
Definition: lms2012.c:1330
DATA8 Length
Definition: lms2012.h:1179
#define UPDATE_TIME1
Update repeat time1 [mS].
Definition: lms2012.h:520
IMINDEX Addr
Offset to breakpoint address from image start.
Definition: lmstypes.h:182
void cOutputStart(void)
opOUTPUT_START byte code
Definition: c_output.c:824
void cOutputPrgStop(void)
opOUTPUT_PRG_STOP byte code
Definition: c_output.c:430
ULONG LBINDEX
LocalBytes index type.
Definition: lmstypes.h:80
void cComTestMailBox(void)
opMAILBOX_TEST byte code
Definition: c_com.c:3891
#define TST_UART_DIS
Definition: lms2012.h:1206
Object code is running.
Definition: bytecodes.h:1515
IP ObjectIp
Working object Ip.
Definition: lms2012.h:1440
#define DataF
#define DATA16_NAN
Definition: bytecodes.h:1493
void cComTest(void)
opCOM_TEST byte code
Definition: c_com.c:3350
GP pGlobal
Pointer to start of global bytes.
Definition: lms2012.h:744
#define CALLPAR_DATA8
Definition: bytecodes.h:1640
DATA8 CheckSdcard(DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
Definition: lms2012.c:1855
void cCompareNEqF(void)
opCP_NEQF byte code
Definition: c_compare.c:509
PRGID CurrentProgramId(void)
Get current program id.
Definition: lms2012.c:207
void cMathRl16(void)
opRL16
Definition: c_math.c:742
void ObjectTrig(void)
opOBJECT_TRIG byte code
Definition: lms2012.c:3039
Definition: lms2012.h:701
IP ObjIpSave
Definition: lms2012.h:1445
void Strings(void)
opSTRINGS byte code
Definition: lms2012.c:3919
void cBranchJrGtEq8(void)
opJR_GTEQ8 byte code
Definition: c_branch.c:769
RESULT cUiClose(void)
Definition: c_ui.c:878
void cInputReadSi(void)
opINPUT_READSI byte code
Definition: c_input.c:4722
void cBranchJrLt16(void)
opJR_LT16 byte code
Definition: c_branch.c:180
void cBranchJrLt32(void)
opJR_LT16 byte code
Definition: c_branch.c:211
RESULT ProgramReset(PRGID PrgId, IP pI, GP pG, UBYTE Deb)
Initialise program for execution.
Definition: lms2012.c:1381
void * VmMemoryResize(HANDLER Handle, DATA32 Elements)
Definition: lms2012.c:366
UWORD Debug
Definition: lms2012.h:1454
UWORD Test
Definition: lms2012.h:1456
UWORD PRGID
Program id type.
Definition: lmstypes.h:71
void cCompareEqF(void)
opCP_EQF byte code
Definition: c_compare.c:385
void cInputSample(void)
opINPUT_SAMPLE byte code
Definition: c_input.c:5065
IP pImage
Pointer to start of image.
Definition: lms2012.h:1435
#define TST_UART_WRITE
Definition: lms2012.h:1208
void cCompareLtEqF(void)
opCP_LTEQF byte code
Definition: c_compare.c:633
RESULT cComInit(void)
Definition: c_com.c:104
void cOutputTest(void)
opOUTPUT_TEST byte code
Definition: c_output.c:1654
OBJ ** pObjList
Pointer to object pointer list.
Definition: lms2012.h:1438
void cTimerWait(void)
opTIMER_WAIT byte code
Definition: c_timer.c:79
#define TST_UART_EN
Definition: lms2012.h:1205
void cMove32to16(void)
opMOVE32_16
Definition: c_move.c:337
#define CALLPAR_DATA32
Definition: bytecodes.h:1642
void cOutputTimePower(void)
opOUTPUT_TIME_POWER byte code
Definition: c_output.c:1069
void cMemoryGetResourcePath(PRGID PrgId, char *pString, DATA8 MaxLength)
Definition: c_memory.c:1065
LP ObjectLocal
Working object locals.
Definition: lms2012.h:1441
void cMove16to32(void)
opMOVE16_32
Definition: c_move.c:242
DATA8 ValidChars[]
Definition: lms2012.c:5547
SBYTE DATA8
VM Type for 1 byte signed value.
Definition: lmstypes.h:61
void cComReadyMailBox(void)
opMAILBOX_READY byte code
Definition: c_com.c:3923
ULONG GetTime(void)
Definition: lms2012.c:315
IMINDEX Addr
Offset to breakpoint address from image start.
Definition: lms2012.h:726
RESULT cSoundUpdate(void)
Definition: c_sound.c:199
void cComReadMailBox(void)
opMAILBOX_READ byte code
Definition: c_com.c:3781
void cOutputSpeed(void)
opOUTPUT_SPEED byte code
Definition: c_output.c:679
void cComGet(void)
opCOM_GET byte code
Definition: c_com.c:4208
void ProgramStop(void)
opPROGRAM_STOP byte code
Definition: lms2012.c:2879
void I2cStart(void)
Definition: c_i2c.c:198
void cComSet(void)
opCOM_SET byte code
Definition: c_com.c:5045
ERR Errors[ERROR_BUFFER_SIZE]
Definition: lms2012.h:1476
Break because of sleeping.
Definition: lms2012.h:669
OBJID Objects
No of objects in image.
Definition: lms2012.h:750
void cOutputTimeSpeed(void)
opOUTPUT_TIME_SPEED byte code
Definition: c_output.c:1269
DATA8 FirstProgram[MAX_FILENAME_SIZE]
Definition: lms2012.h:1424
ERR LogErrorGet(void)
Definition: lms2012.c:495
OBJID ObjectId
Active object id.
Definition: lms2012.h:1443
UBYTE UiImage[]
Definition: lms2012.c:118
#define InputInstance
Definition: c_input.h:174
DATA8 GetVolumePercent(void)
Definition: lms2012.c:378
void cCompareGtEqF(void)
opCP_GTEQF byte code
Definition: c_compare.c:757
void DefLabel(void)
opLABEL byte code
Definition: lms2012.c:3405
void cBranchJrFalse(void)
opJR_FALSE byte code
Definition: c_branch.c:62
ANALOG * pAnalog
Definition: lms2012.h:1502
void cMathMul32(void)
opMUL32
Definition: c_math.c:296
void cOutputGetCount(void)
opOUTPUT_GET_COUNT byte code
Definition: c_output.c:1779
void cMathAnd8(void)
opAND8
Definition: c_math.c:567
NOTEFREQ NoteFreq[NOTES]
Definition: lms2012.c:4458
RESULT mSchedCtrl(UBYTE *pRestart)
Definition: lms2012.c:2296
DSPSTAT
Definition: lms2012.h:665
OBJSTAT Status
Program status.
Definition: lms2012.h:753
#define PRIMDISPATHTABLE_SIZE
Definition: lms2012.c:149
void cMathAdd32(void)
opADD32
Definition: c_math.c:96
ULONG PrioritySave
Definition: lms2012.h:1449
#define INPUTS
Number of input ports in the system.
Definition: lms2012.h:192
void cMoveWrite16(void)
opWRITE16
Definition: c_move.c:686
Object is stopped or not triggered yet.
Definition: bytecodes.h:1517
ERR
Definition: lms2012.h:807
#define CALLPAR_DATAF
Definition: bytecodes.h:1643
void cMoveFto16(void)
opMOVEF_16
Definition: c_move.c:462
void ObjectExit(void)
Save object context.
Definition: lms2012.c:1753
void cCompareGtF(void)
opCP_GTF byte code
Definition: c_compare.c:261
void VmPrint(char *pString)
Definition: lms2012.c:339
void cOutputReady(void)
opOUTPUT_READY byte code
Definition: c_output.c:1561
void Error(void)
opOUTPUT_READY byte code
Definition: lms2012.c:2839
void cComWriteFile(void)
Definition: c_com.c:3970
void CopyParsToLocals(OBJID Id)
Copy encoded parameters to local variables.
Definition: lms2012.c:995
VARDATA * GP
global variable pointer type
Definition: lmstypes.h:76
GLOBALS VMInstance
Definition: lms2012.c:131
void BreakPoint(void)
opBP0 - opBP3 byte code
Definition: lms2012.c:3555
void cCompareEq8(void)
opCP_EQ8 byte code
Definition: c_compare.c:292
Break because of waiting for completion.
Definition: lms2012.h:671
void cMathOr16(void)
opOR16
Definition: c_math.c:517
void cMathSubF(void)
opSUBF
Definition: c_math.c:221
OBJSTAT ProgramStatusChange(PRGID PrgId)
Get program status change.
Definition: lms2012.c:229
#define MAX_LABELS
Max number of labels per program.
Definition: bytecodes.c:24
OBJSTAT
Definition: bytecodes.h:1513
RESULT cValidateProgram(PRGID PrgId, IP pI, LABEL *pLabel, DATA8 Disassemble)
Definition: validate.c:1649
Dispatcher running (looping)
Definition: lms2012.h:667
void cMathAdd16(void)
opADD16
Definition: c_math.c:71
void cCompareNEq8(void)
opCP_NEQ8 byte code
Definition: c_compare.c:416
PRGID ProgramId
Program id running.
Definition: lms2012.h:1430
void cUiAlive(void)
Definition: c_ui.c:636
PRIM PrimDispatchTabel[PRIMDISPATHTABLE_SIZE]
Dispatch table.
Definition: lms2012.c:2609
void cUiDraw(void)
opUI_DRAW byte code
Definition: c_ui.c:5545
void cBranchJrNan(void)
opJR_NAN byte code
Definition: c_branch.c:117
#define CALLPAR_STRING
Definition: bytecodes.h:1644
DATA16 Freq
Definition: lms2012.c:4452
void cUiUpdate(UWORD Time)
Definition: c_ui.c:2464
RESULT cInputInit(void)
Definition: c_input.c:3415
void cMoveInitBytes(void)
opINIT_BYTES
Definition: c_move.c:43
void cMoveWrite8(void)
opWRITE8
Definition: c_move.c:659
ULONG SdcardTimer
Definition: lms2012.h:1487
RESULT ProgramExec(void)
Find a program to run ProgramId holds found program.
Definition: lms2012.c:1664
void cMoveWrite32(void)
opWRITE32
Definition: c_move.c:713
#define PRIMPAR_ADDR
Definition: bytecodes.h:1592
void SetVolumePercent(DATA8 Volume)
Definition: lms2012.c:372
IP OffsetToInstructions
Offset to instructions from image start.
Definition: lmstypes.h:169
RESULT cUiInit(void)
Definition: c_ui.c:642
void Monitor(void)
Definition: lms2012.c:4568
void ObjectReset(OBJID ObjId)
Initialise object instruction pointer and trigger counter.
Definition: lms2012.c:1317
void cBranchJrGt16(void)
opJR_GT16 byte code
Definition: c_branch.c:304
ULONG NewTime
Definition: lms2012.h:1464
#define CALLPAR_IN
Definition: bytecodes.h:1636
#define NULL
void cMathXor32(void)
opXOR32
Definition: c_math.c:692