comparison LightClone/Source/Program.cpp @ 38:2caa7c7e2cb5

Refactored program; Added dialog
author koryspansel
date Wed, 21 Sep 2011 21:40:19 -0700
parents 58a16d529d95
children 8cefb65577cc
comparison
equal deleted inserted replaced
37:58a16d529d95 38:2caa7c7e2cb5
1 /* 1 /*
2 * Program 2 * Program
3 */ 3 */
4 4
5 #include "Program.h" 5 #include "Program.h"
6
7 /*
8 * CalculateSize
9 */
10 uint32 Program::Function::CalculateSize()
11 {
12 uint32 nSize = 0;
13
14 for(uint32 i = 0; i < MaximumInstructionCount; ++i)
15 {
16 if(nInstruction[i] > 0)
17 {
18 ++nSize;
19 }
20 }
21
22 return nSize;
23 }
24 6
25 /* 7 /*
26 * Program 8 * Program
27 */ 9 */
28 Program::Program() 10 Program::Program()
32 /* 14 /*
33 * Initialize 15 * Initialize
34 */ 16 */
35 ErrorCode Program::Initialize() 17 ErrorCode Program::Initialize()
36 { 18 {
37 return Error_Success; 19 return Clear(), Error_Success;
38 } 20 }
39 21
40 /* 22 /*
41 * Terminate 23 * Terminate
42 */ 24 */
43 void Program::Terminate() 25 void Program::Terminate()
44 { 26 {
45 } 27 }
46 28
47 /* 29 /*
30 * SetAction
31 */
32 void Program::SetAction(uint32 nFunction, uint32 nIndex, uint32 nAction)
33 {
34 if(nFunction < FunctionCount && nIndex < Function::MaximumInstructionCount)
35 {
36 kFunction[nFunction].nInstruction[nIndex] = nAction;
37 }
38 }
39
40 /*
48 * Clear 41 * Clear
49 */ 42 */
50 void Program::Clear() 43 void Program::Clear()
51 { 44 {
45 for(uint32 i = 0; i < FunctionCount; ++i)
46 {
47 for(uint32 j = 0; j < Function::MaximumInstructionCount; ++j)
48 {
49 kFunction[i].nInstruction[j] = Action_Default;
50 }
51 }
52 } 52 }
53 53
54 /* 54 /*
55 * Upload 55 * Upload
56 */ 56 */
57 ErrorCode Program::Upload(VirtualMachine& kMachine) 57 ErrorCode Program::Upload(VirtualMachine& kMachine) const
58 { 58 {
59 ErrorCode eCode = Error_Success; 59 ErrorCode eCode = Error_Success;
60 60
61 kMachine.Reset(); 61 kMachine.Reset();
62 kMachine.ClearMemory(); 62 kMachine.ClearMemory();
63 kMachine.RemoveAllFunctions(); 63 kMachine.RemoveAllFunctions();
64 64
65 for(uint32 i = 0; i < nFunctionCount && eCode == Error_Success; ++i) 65 for(uint32 i = 0; i < FunctionCount && eCode == Error_Success; ++i)
66 { 66 {
67 kMachine.AddFunction(i, kFunction[i].CalculateSize()); 67 kMachine.AddFunction(i, kFunction[i].CalculateSize());
68 68
69 uint32 nSize = kMachine.GetFunctionSize(i); 69 uint32 nSize = kMachine.GetFunctionSize(i);
70 uint8* pData = kMachine.GetFunctionMemory(i); 70 uint8* pData = kMachine.GetFunctionMemory(i);
76 } 76 }
77 77
78 /* 78 /*
79 * Compile 79 * Compile
80 */ 80 */
81 ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) 81 ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) const
82 { 82 {
83 for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i) 83 for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i)
84 { 84 {
85 const uint32 nAction = kFunction[nIndex].nInstruction[i]; 85 const uint32 nAction = kFunction[nIndex].nInstruction[i];
86 86