-
Notifications
You must be signed in to change notification settings - Fork 5
/
GlobalUnit.pas
237 lines (190 loc) · 7.25 KB
/
GlobalUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
unit GlobalUnit;
interface
uses
SysUtils, WinTypes, WinProcs, Classes, Forms, Messages, Dialogs, ExtCtrls, Graphics;
const
kBackSpace = 8;
kInsert = 45;
kDelete = 46;
kLeft = 37;
kRight = 39;
kUp = 38;
kDown = 40;
kHome = 36;
kEnd = 35;
kPageUp = 33;
kPageDown = 34;
kSpace = 32;
kTab = 9;
kEnter = 13;
kEsc = 27;
HubLimit = $80000;
ObjLimit = $100000;
FileLimit = 32;
ParamLimit = 16;
InfoLimit = 1000;
DebugDataLimit = $4000;
DebugStringLimit = $8000;
DebugDisplayLimit = 1100; // allows 1k data elements + some commands
SourceLimit = 5000000;
ListLimit = 10000000;
DocLimit = 5000000;
ObjStackLimit = 16;
ObjFileLimit = FileLimit * ObjStackLimit;
type
TP2 = packed record
Error: boolean;
ErrorMsg: PChar;
PasmMode: boolean;
DebugMode: boolean;
Source: PByteArray;
SourceStart: integer;
SourceFinish: integer;
List: PByteArray;
ListLimit: integer;
ListLength: integer;
Doc: PByteArray;
DocLimit: integer;
DocLength: integer;
Params: integer;
ParamNames: array[0..ParamLimit*32-1] of byte;
ParamTypes: array[0..ParamLimit-1] of byte;
ParamValues: array[0..ParamLimit-1] of integer;
Obj: array[0..ObjLimit-1] of byte;
ObjLength: integer;
ObjFiles: integer;
ObjFilenames: array[0..FileLimit*256-1] of byte;
ObjFilenamesStart: array[0..FileLimit-1] of integer;
ObjFilenamesFinish: array[0..FileLimit-1] of integer;
ObjParams: array[0..FileLimit-1] of integer;
ObjParamNames: array[0..FileLimit*ParamLimit*32-1] of byte;
ObjParamTypes: array[0..FileLimit*ParamLimit-1] of byte;
ObjParamValues: array[0..FileLimit*ParamLimit-1] of integer;
ObjOffsets: array[0..FileLimit-1] of integer;
ObjLengths: array[0..FileLimit-1] of integer;
ObjData: array[0..ObjLimit -1] of byte;
ObjInstances: array[0..FileLimit-1] of integer;
ObjTitle: array[0..255] of byte;
DatFiles: integer;
DatFilenames: array[0..FileLimit*256-1] of byte;
DatFilenamesStart: array[0..FileLimit-1] of integer;
DatFilenamesFinish: array[0..FileLimit-1] of integer;
DatOffsets: array[0..FileLimit-1] of integer;
DatLengths: array[0..FileLimit-1] of integer;
DatData: array[0..ObjLimit -1] of byte;
InfoCount: integer; // used by PropellerTool
InfoStart: array[0..InfoLimit-1] of integer;
InfoFinish: array[0..InfoLimit-1] of integer;
InfoType: array[0..InfoLimit-1] of integer;
InfoData0: array[0..InfoLimit-1] of integer;
InfoData1: array[0..InfoLimit-1] of integer;
InfoData2: array[0..InfoLimit-1] of integer;
InfoData3: array[0..InfoLimit-1] of integer;
DownloadBaud: integer;
DebugPinTx: byte;
DebugPinRx: byte;
DebugBaud: integer;
DebugLeft: integer;
DebugTop: integer;
DebugWidth: integer;
DebugHeight: integer;
DebugDisplayLeft: integer;
DebugDisplayTop: integer;
DebugLogSize: integer;
DebugWindowsOff: integer;
DebugData: array[0..DebugDataLimit-1] of byte;
DebugDisplayEna: integer; // 32 bitwise enables
DebugDisplayNew: integer;
DebugDisplayStr: array[0..DebugStringLimit-1] of byte;
DebugDisplayType: array[0..DebugDisplayLimit-1] of byte;
DebugDisplayValue: array[0..DebugDisplayLimit-1] of integer;
DebugDisplayTargs: byte;
DisassemblerInst: integer;
DisassemblerAddr: integer;
DisassemblerString: array[0..255] of byte;
DistilledBytes: integer;
ClkMode: integer;
ClkFreq: integer;
XinFreq: integer;
SizeFlashLoader: integer;
SizeInterpreter: integer;
SizeObj: integer;
SizeVar: integer;
ObjStackPtr: integer; // recursion level
end;
// Assembly interface
function P2InitStruct: pointer; external;
procedure P2Compile1; external;
procedure P2Compile2; external;
procedure P2InsertInterpreter; external;
procedure P2InsertDebugger; external;
procedure P2InsertFlashLoader; external;
procedure P2InsertClockSetter; external;
procedure P2ResetDebugSymbols; external;
procedure P2ParseDebugString; external;
procedure P2Disassemble; external;
// Support routines
function ExtFilename(Filename, Ext: string): string;
procedure MinLimit(var Value: integer; Target: integer);
procedure MaxLimit(var Value: integer; Target: integer);
function IsWithin(Value, Minimum, Maximum: integer): boolean;
function Within(Value, Minimum, Maximum: integer): integer;
function IsWordChr(C: Char): boolean;
function Smaller(x, y: Integer): integer;
function Greater(x, y: Integer): integer;
var
P2: ^TP2;
SourceBuffer : array[0..SourceLimit] of byte; // +1 allows 0 end byte
ListBuffer : array[0..ListLimit] of byte; // +1 allows end reading
DocBuffer : array[0..DocLimit] of byte; // +1 allows end reading
ObjFilePtr : integer;
ObjFileBuff : array[0..ObjLimit] of byte;
ObjFileCount : integer;
ObjFileOffset : array[0..ObjFileLimit-1] of integer;
ObjFileLength : array[0..ObjFileLimit-1] of integer;
FontName : string;
FontSize : integer;
FontStyle : TFontStyles;
TopFile : string;
BatchMode : boolean;
DebugActive : boolean;
DebuggerID : integer;
LastDebugTick : integer;
RequestCOGBRK : integer;
implementation
{$L p2com.obj}
function ExtFilename(Filename, Ext: string): string;
begin
Result := (Copy(Filename, 1, Length(Filename) - Length(ExtractFileExt(Filename))) + '.' + Ext);
end;
procedure MinLimit(var Value: integer; Target: integer);
begin
if Value < Target then Value := Target;
end;
procedure MaxLimit(var Value: integer; Target: integer);
begin
if Value > Target then Value := Target;
end;
function IsWithin(Value, Minimum, Maximum: integer): boolean;
begin
Result := (Value >= Minimum) and (Value <= Maximum);
end;
function Within(Value, Minimum, Maximum: integer): integer;
begin
if Value < Minimum then Result := Minimum
else if Value > Maximum then Result := Maximum
else Result := Value;
end;
function IsWordChr(C: Char): boolean;
begin
Result := C in ['0'..'9', 'A'..'Z', 'a'..'z', '_'];
end;
function Smaller(x, y: Integer): integer;
begin
if x < y then Result := x else Result := y;
end;
function Greater(x, y: Integer): integer;
begin
if x > y then Result := x else Result := y;
end;
end.