LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lms2012.c File Reference
#include "lms2012.h"
#include "c_math.h"
#include "c_move.h"
#include "c_branch.h"
#include "c_compare.h"
#include "c_timer.h"
#include "c_output.h"
#include "c_input.h"
#include "c_ui.h"
#include "c_memory.h"
#include "c_com.h"
#include "c_sound.h"
#include "c_bt.h"
#include "c_i2c.h"
#include "validate.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <syslog.h>
#include <math.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

Go to the source code of this file.

Data Structures

struct  NOTEFREQ
 

Macros

#define IDX_BACK_BUTTON   BACK_BUTTON-1
 
#define PRIMDISPATHTABLE_SIZE   256
 
#define ERROR(ErrorCode)   [ErrorCode] = #ErrorCode
 
#define NOTES   36
 

Functions

void Error (void)
 opOUTPUT_READY byte code More...
 
void Nop (void)
 opNOP byte code More...
 
void ObjectStop (void)
 opOBJECT_STOP byte code More...
 
void ObjectStart (void)
 opOBJECT_START byte code More...
 
void ObjectTrig (void)
 opOBJECT_TRIG byte code More...
 
void ObjectWait (void)
 opOBJECT_WAIT byte code More...
 
void ObjectCall (void)
 opCALL byte code More...
 
void ObjectReturn (void)
 opRETURN byte code More...
 
void ObjectEnd (void)
 opOBJECT_END byte code More...
 
void ProgramStart (void)
 opPROGRAM_START byte code More...
 
void ProgramStop (void)
 opPROGRAM_STOP byte code More...
 
void Sleep (void)
 opSLEEP byte code More...
 
void ProgramInfo (void)
 opPROGRAM_INFO byte code More...
 
void DefLabel (void)
 opLABEL byte code More...
 
void Do (void)
 opDO byte code More...
 
void Probe (void)
 opPROBE byte code More...
 
void BreakPoint (void)
 opBP0 - opBP3 byte code More...
 
void BreakSet (void)
 opBP_SET byte code More...
 
void Random (void)
 opRANDOM byte code More...
 
void Info (void)
 opINFO byte code More...
 
void Strings (void)
 opSTRINGS byte code More...
 
void MemoryWrite (void)
 opMEMORY_WRITE byte code More...
 
void MemoryRead (void)
 opMEMORY_READ byte code More...
 
void cBranchJr (void)
 opJR byte code More...
 
void PortCnvOutput (void)
 
void PortCnvInput (void)
 
void NoteToFreq (void)
 
void System (void)
 
void Monitor (void)
 
void TstClose (void)
 
void Tst (void)
 opTST byte code More...
 
OBJID CallingObjectId (void)
 Get calling object id. More...
 
PRGID CurrentProgramId (void)
 Get current program id. More...
 
OBJSTAT ProgramStatus (PRGID PrgId)
 Get program status. More...
 
OBJSTAT ProgramStatusChange (PRGID PrgId)
 Get program status change. More...
 
IP GetImageStart (void)
 Get pointer to actual start of byte code image. More...
 
void SetDispatchStatus (DSPSTAT DspStat)
 Set object (dispatch) status. More...
 
void SetInstructions (ULONG Instructions)
 Set instructions. More...
 
void AdjustObjectIp (IMOFFS Value)
 Adjust current instruction pointer. More...
 
IP GetObjectIp (void)
 Get current instruction pointer. More...
 
void SetObjectIp (IP Ip)
 Set current instruction pointer. More...
 
ULONG GetTime (void)
 
ULONG GetTimeMS (void)
 
ULONG GetTimeUS (void)
 
ULONG CurrentObjectIp (void)
 
void VmPrint (char *pString)
 
void SetTerminalEnable (DATA8 Value)
 
DATA8 GetTerminalEnable (void)
 
void GetResourcePath (char *pString, DATA8 MaxLength)
 
void * VmMemoryResize (HANDLER Handle, DATA32 Elements)
 
void SetVolumePercent (DATA8 Volume)
 
DATA8 GetVolumePercent (void)
 
void SetSleepMinutes (DATA8 Minutes)
 
DATA8 GetSleepMinutes (void)
 
void SetUiUpdate (void)
 
void LogErrorNumber (ERR Err)
 
DATA8 LogErrorNumberExists (ERR Error)
 
ERR LogErrorGet (void)
 
void CleanLogErrors (void)
 
DSPSTAT ExecuteByteCode (IP pByteCode, GP pGlobals, LP pLocals)
 Execute byte code stream (C-call) More...
 
void * PrimParPointer (void)
 Get next encoded parameter from byte code stream. More...
 
void PrimParAdvance (void)
 Skip next encoded parameter from byte code stream. More...
 
void CopyParsToLocals (OBJID Id)
 Copy encoded parameters to local variables. More...
 
void CopyLocalsToPars (OBJID Id)
 Copy local variables to encoded parameters. More...
 
void ObjectReset (OBJID ObjId)
 Initialise object instruction pointer and trigger counter. More...
 
GBINDEX GetAmountOfRamForImage (IP pI)
 Get amount of ram to allocate for program. More...
 
RESULT ProgramReset (PRGID PrgId, IP pI, GP pG, UBYTE Deb)
 Initialise program for execution. More...
 
void ProgramEnd (PRGID PrgId)
 Exit program nicely (freeing up memory) More...
 
void ProgramInit (void)
 Switch in current program ProgramId holds program to switch to. More...
 
void ProgramExit (void)
 Switch out current program ProgramId holds program to switch from. More...
 
RESULT ProgramExec (void)
 Find a program to run ProgramId holds found program. More...
 
DSPSTAT ObjectInit (void)
 Restore object context. More...
 
void ObjectExit (void)
 Save object context. More...
 
RESULT ObjectExec (void)
 Find next object to run. More...
 
void ObjectEnQueue (OBJID Id)
 Put object on run queue. More...
 
void ObjectDeQueue (OBJID Id)
 Remove object from run queue. More...
 
DATA8 CheckSdcard (DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
 
DATA8 CheckUsbstick (DATA8 *pChanged, DATA32 *pTotal, DATA32 *pFree, DATA8 Force)
 
RESULT mSchedInit (int argc, char *argv[])
 
RESULT mSchedCtrl (UBYTE *pRestart)
 
RESULT mSchedExit (void)
 
int main (int argc, char *argv[])
 
RESULT TstOpen (UWORD Time)
 
RESULT ValidateChar (DATA8 *pChar, DATA8 Set)
 
RESULT ValidateString (DATA8 *pString, DATA8 Set)
 

Variables

UBYTE UiImage []
 
GLOBALS VMInstance
 
PRIM PrimDispatchTabel [PRIMDISPATHTABLE_SIZE]
 Dispatch table. More...
 
char ErrString [ERRORS][ERR_STRING_SIZE]
 
NOTEFREQ NoteFreq [NOTES]
 
DATA8 ValidChars []
 

Macro Definition Documentation

#define ERROR (   ErrorCode)    [ErrorCode] = #ErrorCode

Definition at line 402 of file lms2012.c.

#define IDX_BACK_BUTTON   BACK_BUTTON-1

Definition at line 112 of file lms2012.c.

#define NOTES   36

Definition at line 4456 of file lms2012.c.

#define PRIMDISPATHTABLE_SIZE   256

Definition at line 149 of file lms2012.c.

Function Documentation

void AdjustObjectIp ( IMOFFS  Value)

Adjust current instruction pointer.

Parameters
ValueSigned offset to add

Definition at line 287 of file lms2012.c.

void BreakPoint ( void  )

opBP0 - opBP3 byte code

Display globals or object locals on terminal

Uses following from current program context: pObjHead, ObjectIp, ProgramId

Definition at line 3555 of file lms2012.c.

void BreakSet ( void  )

opBP_SET byte code

Set break point in byte code program

Uses following from current program context: None

Definition at line 3611 of file lms2012.c.

OBJID CallingObjectId ( void  )

Get calling object id.

Returns
OBJID Current object id

Definition at line 196 of file lms2012.c.

void cBranchJr ( void  )

opJR byte code

Definition at line 42 of file c_branch.c.

DATA8 CheckSdcard ( DATA8 pChanged,
DATA32 pTotal,
DATA32 pFree,
DATA8  Force 
)

Definition at line 1855 of file lms2012.c.

DATA8 CheckUsbstick ( DATA8 pChanged,
DATA32 pTotal,
DATA32 pFree,
DATA8  Force 
)

Definition at line 1959 of file lms2012.c.

void CleanLogErrors ( void  )

Definition at line 512 of file lms2012.c.

void CopyLocalsToPars ( OBJID  Id)

Copy local variables to encoded parameters.

Parameters
IdObject to copy to

Definition at line 1153 of file lms2012.c.

void CopyParsToLocals ( OBJID  Id)

Copy encoded parameters to local variables.

Parameters
IdObject to copy to

Definition at line 995 of file lms2012.c.

ULONG CurrentObjectIp ( void  )

Definition at line 333 of file lms2012.c.

PRGID CurrentProgramId ( void  )

Get current program id.

Returns
PRGID Current program id

Definition at line 207 of file lms2012.c.

void DefLabel ( void  )

opLABEL byte code

Definition at line 3405 of file lms2012.c.

void Do ( void  )

opDO byte code

Run byte code snippet

Uses following from current program context: ObjectIp, ProgramId

Definition at line 3509 of file lms2012.c.

void Error ( void  )

opOUTPUT_READY byte code

Uses following from current program context: DispatchStatus

Definition at line 2839 of file lms2012.c.

DSPSTAT ExecuteByteCode ( IP  pByteCode,
GP  pGlobals,
LP  pLocals 
)

Execute byte code stream (C-call)

This call is able to execute up to "C_PRIORITY" byte codes instructions (no header necessary)

Parameters
(IP)Pointer to byte code stream (last byte code must be "opOBJECT_END")
(GP)Pointer to global variables to use (if none -> NULL)
(LP)Pointer to Local variables to use (if none -> NULL)
Returns
(DSPSTAT) Dispatch status

Example:

IMGDATA BC1[] = { opUI_WRITE,PUT_STRING,LCS,'L','E','G','O','','
',0,opUI_WRITE,WRITE_FLUSH,opOBJECT_END }; ExecuteByteCode(BC1,NULL,NULL);

Definition at line 535 of file lms2012.c.

GBINDEX GetAmountOfRamForImage ( IP  pI)

Get amount of ram to allocate for program.

Parameters
pIPointer to image

Definition at line 1330 of file lms2012.c.

IP GetImageStart ( void  )

Get pointer to actual start of byte code image.

Returns
IP Pointer to image

Definition at line 245 of file lms2012.c.

IP GetObjectIp ( void  )

Get current instruction pointer.

Returns
Current instruction pointer

Definition at line 298 of file lms2012.c.

void GetResourcePath ( char *  pString,
DATA8  MaxLength 
)

Definition at line 360 of file lms2012.c.

DATA8 GetSleepMinutes ( void  )

Definition at line 390 of file lms2012.c.

DATA8 GetTerminalEnable ( void  )

Definition at line 354 of file lms2012.c.

ULONG GetTime ( void  )

Definition at line 315 of file lms2012.c.

ULONG GetTimeMS ( void  )

Definition at line 321 of file lms2012.c.

ULONG GetTimeUS ( void  )

Definition at line 327 of file lms2012.c.

DATA8 GetVolumePercent ( void  )

Definition at line 378 of file lms2012.c.

void Info ( void  )

opINFO byte code

Definition at line 3734 of file lms2012.c.

ERR LogErrorGet ( void  )

Definition at line 495 of file lms2012.c.

void LogErrorNumber ( ERR  Err)

Definition at line 445 of file lms2012.c.

DATA8 LogErrorNumberExists ( ERR  Error)

Definition at line 470 of file lms2012.c.

int main ( int  argc,
char *  argv[] 
)

Definition at line 2569 of file lms2012.c.

void MemoryRead ( void  )

opMEMORY_READ byte code

Read VM memory

Uses following from current program context: None

Definition at line 4338 of file lms2012.c.

void MemoryWrite ( void  )

opMEMORY_WRITE byte code

Write to VM memory

Uses following from current program context: None

Definition at line 4266 of file lms2012.c.

void Monitor ( void  )

Definition at line 4568 of file lms2012.c.

RESULT mSchedCtrl ( UBYTE pRestart)

Definition at line 2296 of file lms2012.c.

RESULT mSchedExit ( void  )

Definition at line 2513 of file lms2012.c.

RESULT mSchedInit ( int  argc,
char *  argv[] 
)

Definition at line 2063 of file lms2012.c.

void Nop ( void  )

opNOP byte code

Definition at line 2857 of file lms2012.c.

void NoteToFreq ( void  )

Definition at line 4516 of file lms2012.c.

void ObjectCall ( void  )

opCALL byte code

Calls byte code subroutine

Uses following from current program context: ObjectIp, pObjList, pObjHead, DispatchStatus

Definition at line 3173 of file lms2012.c.

void ObjectDeQueue ( OBJID  Id)

Remove object from run queue.

Parameters
IdObject to enqueue

Definition at line 1843 of file lms2012.c.

void ObjectEnd ( void  )

opOBJECT_END byte code

Stops current object

Uses following from current program context: pObjectList, ObjectIp, DispatchStatus

Definition at line 3245 of file lms2012.c.

void ObjectEnQueue ( OBJID  Id)

Put object on run queue.

Parameters
IdObject to queue

Definition at line 1827 of file lms2012.c.

RESULT ObjectExec ( void  )

Find next object to run.

Uses following from current program context: ObjectId, Objects, pObjList

Returns
RESULT Succes [OK or STOP]

Definition at line 1774 of file lms2012.c.

void ObjectExit ( void  )

Save object context.

ObjectId holds object to switch from

Save object context if id is valid and running by saving current IP

Uses following from current program context: ObjectId, Objects, pObjList, ObjectIp

Definition at line 1753 of file lms2012.c.

DSPSTAT ObjectInit ( void  )

Restore object context.

Restore object context if id is valid and running by loading current IP and current pointer to Locals

Uses following from current program context: ObjectId, Objects, pObjList, pObjHead, ObjectIp, ObjectLocal

Returns
DSPSTAT New value for dispatch status [NOBREAK, STOPBREAK]

Definition at line 1710 of file lms2012.c.

void ObjectReset ( OBJID  ObjId)

Initialise object instruction pointer and trigger counter.

Parameters
ObjIdObject to reset

Definition at line 1317 of file lms2012.c.

void ObjectReturn ( void  )

opRETURN byte code

Return from byte code subroutine

Uses following from current program context: ObjectId, pObjList, DispatchStatus

Definition at line 3118 of file lms2012.c.

void ObjectStart ( void  )

opOBJECT_START byte code

Start specific object

Uses following from current program context: pObjectList

Definition at line 3016 of file lms2012.c.

void ObjectStop ( void  )

opOBJECT_STOP byte code

Stops specific object

Uses following from current program context: pObjectList, ObjectIp, DispatchStatus

Definition at line 2993 of file lms2012.c.

void ObjectTrig ( void  )

opOBJECT_TRIG byte code

Triggers object and run the object if fully triggered

Uses following from current program context: pObjList

Definition at line 3039 of file lms2012.c.

void ObjectWait ( void  )

opOBJECT_WAIT byte code

Wait until object has run

Uses following from current program context: ObjectIp, pObjList, DispatchStatus

Definition at line 3086 of file lms2012.c.

void PortCnvInput ( void  )

Definition at line 4434 of file lms2012.c.

void PortCnvOutput ( void  )

Definition at line 4402 of file lms2012.c.

void PrimParAdvance ( void  )

Skip next encoded parameter from byte code stream.

Definition at line 870 of file lms2012.c.

void* PrimParPointer ( void  )

Get next encoded parameter from byte code stream.

Returns
void Pointer to value

Definition at line 694 of file lms2012.c.

void Probe ( void  )

opPROBE byte code

Display globals or object locals on terminal

Uses following from current program context: None

Definition at line 3431 of file lms2012.c.

void ProgramEnd ( PRGID  PrgId)

Exit program nicely (freeing up memory)

Parameters
PrgIdProgram id (index)

Definition at line 1555 of file lms2012.c.

RESULT ProgramExec ( void  )

Find a program to run ProgramId holds found program.

Returns
RESULT Succes [OK or STOP]

Definition at line 1664 of file lms2012.c.

void ProgramExit ( void  )

Switch out current program ProgramId holds program to switch from.

Definition at line 1635 of file lms2012.c.

void ProgramInfo ( void  )

opPROGRAM_INFO byte code

Get program informations

Uses following from current program context: None

Definition at line 3320 of file lms2012.c.

void ProgramInit ( void  )

Switch in current program ProgramId holds program to switch to.

Definition at line 1605 of file lms2012.c.

RESULT ProgramReset ( PRGID  PrgId,
IP  pI,
GP  pG,
UBYTE  Deb 
)

Initialise program for execution.

Parameters
PrgIdProgram id (index)
pIPointer to image
pGPointer to global variables
Debdebug flag

Definition at line 1381 of file lms2012.c.

void ProgramStart ( void  )

opPROGRAM_START byte code

Start program id slot

Uses following from current program context: Program[], DispatchStatus

Definition at line 2926 of file lms2012.c.

OBJSTAT ProgramStatus ( PRGID  PrgId)

Get program status.

Returns
OBJSTAT Program status

Definition at line 218 of file lms2012.c.

OBJSTAT ProgramStatusChange ( PRGID  PrgId)

Get program status change.

Returns
OBJSTAT Program status change

Definition at line 229 of file lms2012.c.

void ProgramStop ( void  )

opPROGRAM_STOP byte code

Stops specific program id slot

Uses following from current program context: Program[], DispatchStatus

Definition at line 2879 of file lms2012.c.

void Random ( void  )

opRANDOM byte code

Get random VALUE between MIN and MAX

Uses following from current program context: None

Definition at line 3665 of file lms2012.c.

void SetDispatchStatus ( DSPSTAT  DspStat)

Set object (dispatch) status.

Parameters
DspStatNew dispatch status

Definition at line 256 of file lms2012.c.

void SetInstructions ( ULONG  Instructions)

Set instructions.

Parameters
ULONGInstructions

Definition at line 273 of file lms2012.c.

void SetObjectIp ( IP  Ip)

Set current instruction pointer.

Parameters
IpNew instruction pointer value

Definition at line 309 of file lms2012.c.

void SetSleepMinutes ( DATA8  Minutes)

Definition at line 384 of file lms2012.c.

void SetTerminalEnable ( DATA8  Value)

Definition at line 348 of file lms2012.c.

void SetUiUpdate ( void  )

Definition at line 396 of file lms2012.c.

void SetVolumePercent ( DATA8  Volume)

Definition at line 372 of file lms2012.c.

void Sleep ( void  )

opSLEEP byte code

Breaks execution of current VMTHREAD

Uses following from current program context: DispatchStatus

Definition at line 3270 of file lms2012.c.

void Strings ( void  )

opSTRINGS byte code

Definition at line 3919 of file lms2012.c.

void System ( void  )

Definition at line 4550 of file lms2012.c.

void Tst ( void  )

opTST byte code

Definition at line 5160 of file lms2012.c.

void TstClose ( void  )

Definition at line 4778 of file lms2012.c.

RESULT TstOpen ( UWORD  Time)

Definition at line 4742 of file lms2012.c.

RESULT ValidateChar ( DATA8 pChar,
DATA8  Set 
)

Definition at line 5680 of file lms2012.c.

RESULT ValidateString ( DATA8 pString,
DATA8  Set 
)

Definition at line 5694 of file lms2012.c.

void* VmMemoryResize ( HANDLER  Handle,
DATA32  Elements 
)

Definition at line 366 of file lms2012.c.

void VmPrint ( char *  pString)

Definition at line 339 of file lms2012.c.

Variable Documentation

char ErrString[ERRORS][ERR_STRING_SIZE]

Definition at line 404 of file lms2012.c.

NOTEFREQ NoteFreq[NOTES]

Definition at line 4458 of file lms2012.c.

PRIM PrimDispatchTabel

Dispatch table.

Definition at line 2609 of file lms2012.c.

UBYTE UiImage[]
Initial value:
=
{
PROGRAMHeader(0,1,0),
opFILE,LC0(LOAD_IMAGE),LC0(GUI_SLOT),GV0(0),LV0(4),LV0(0),
opPROGRAM_START,LC0(GUI_SLOT),LC0(0),LV0(0),LC0(0),
opOBJECT_END,
}
#define VMTHREADHeader(OffsetToInstructions, LocalBytes)
Definition: bytecodes.h:1573
#define PROGRAMHeader(VersionInfo, NumberOfObjects, GlobalBytes)
Definition: bytecodes.h:1570
#define GV0(i)
Definition: bytecodes.h:1627
#define LC0(v)
Definition: bytecodes.h:1615
#define LV0(i)
Definition: bytecodes.h:1621

Definition at line 118 of file lms2012.c.

DATA8 ValidChars[]

Definition at line 5547 of file lms2012.c.

GLOBALS VMInstance

Definition at line 131 of file lms2012.c.