Mercurial > LightClone
view LightClone/Source/Program.cpp @ 37:58a16d529d95
Refactoring code and adding events for drag and drop
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Wed, 21 Sep 2011 20:30:29 -0700 |
parents | b60cbf3fa894 |
children | 2caa7c7e2cb5 |
line wrap: on
line source
/* * Program */ #include "Program.h" /* * CalculateSize */ uint32 Program::Function::CalculateSize() { uint32 nSize = 0; for(uint32 i = 0; i < MaximumInstructionCount; ++i) { if(nInstruction[i] > 0) { ++nSize; } } return nSize; } /* * Program */ Program::Program() { } /* * Initialize */ ErrorCode Program::Initialize() { return Error_Success; } /* * Terminate */ void Program::Terminate() { } /* * Clear */ void Program::Clear() { } /* * Upload */ ErrorCode Program::Upload(VirtualMachine& kMachine) { ErrorCode eCode = Error_Success; kMachine.Reset(); kMachine.ClearMemory(); kMachine.RemoveAllFunctions(); for(uint32 i = 0; i < nFunctionCount && eCode == Error_Success; ++i) { kMachine.AddFunction(i, kFunction[i].CalculateSize()); uint32 nSize = kMachine.GetFunctionSize(i); uint8* pData = kMachine.GetFunctionMemory(i); eCode = Compile(i, pData, nSize); } return eCode; } /* * Compile */ ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) { for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i) { const uint32 nAction = kFunction[nIndex].nInstruction[i]; if(Action_Forward <= nAction && nAction <= Action_Light) { if(nSize < 2) return Error_Fail; *pData++ = Instruction_Action; *pData++ = nAction; nSize -= 2; } else if(Action_FunctionA <= nAction && nAction <= Action_FunctionB) { if(nSize < 2) return Error_Fail; *pData++ = Instruction_Call; *pData++ = nAction - Action_FunctionA + 1; nSize -= 2; } } return Error_Success; }