-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.pas
561 lines (505 loc) · 17.8 KB
/
Unit1.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, cisco_2500, ScktComp ;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Memo1: TMemo;
Button3: TButton;
Button4: TButton;
ListBox1: TListBox;
Memo2: TMemo;
Memo3: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Memo4: TMemo;
Label5: TLabel;
Timer2: TTimer;
Button6: TButton;
Label6: TLabel;
Label7: TLabel;
Button7: TButton;
Button8: TButton;
Edit3: TEdit;
Button5: TButton;
Edit4: TEdit;
Button9: TButton;
Button10: TButton;
Edit5: TEdit;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button18: TButton;
Button19: TButton;
Label8: TLabel;
Label9: TLabel;
Memo5: TMemo;
Memo6: TMemo;
Label10: TLabel;
Label11: TLabel;
Timer3: TTimer;
Label12: TLabel;
Edit6: TEdit;
Label13: TLabel;
Button11: TButton;
Button20: TButton;
Label14: TLabel;
Label15: TLabel;
Button21: TButton;
Button22: TButton;
Edit7: TEdit;
Label16: TLabel;
ServerSocket1: TServerSocket;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Edit2Exit(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
// procedure Timer3Timer(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Memo4KeyPress(Sender: TObject; var Key: Char);
procedure Timer3Timer(Sender: TObject);
procedure Edit6Exit(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button20Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Edit5Exit(Sender: TObject);
procedure Button21Click(Sender: TObject);
procedure Button22Click(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
// cpu:cpu68k;
// console:uart2681;
// cookie2500:c2500cookie;
// sysregs2500:c2500sysregs;
Router: cisco2500;
view1addr,view2addr:longword;
breakpoint:longword;
thread:integer;
tid:longword;
// speed:longword;
ch:char;
implementation
{$R *.dfm}
procedure memoAddChar(memo:TMemo;c:char);
var l:word;
s:string;
begin
case c of
#$a: memo.lines.Add('');
#$8: begin
s:=memo.Lines[memo.Lines.Count-1];
l:=length(s)-1;
setlength(s,l);
memo.Lines[memo.Lines.Count-1]:=s;
end;
#$7: asm nop end;
else memo.Lines[memo.Lines.Count-1]:=memo.Lines[memo.Lines.Count-1]+c;
end;
{if ord(c)=$a then memo.lines.Add('')
else if ord(c)=8 then begin
s:=memo.Lines[memo.Lines.Count-1];
l:=length(s)-1;
setlength(s,l);
memo.Lines[memo.Lines.Count-1]:=s;
end
else memo.Lines[memo.Lines.Count-1]:=memo.Lines[memo.Lines.Count-1]+c;}
{if ord(c)=$a then memo.lines.Add('')
else memo.Lines.Text:=concat(memo.Lines.Text,c);}
end;
procedure tick(Sender: TObject); //TForm1.Timer3Timer
var b:longword;
var c:byte;
begin
b:=0;
while true do begin
if b and router.debug_speed =0 then begin
if router.cpu.regs.pc=breakpoint then router.cpu.regs.sr:=router.cpu.regs.sr or $c000;
//if router.cpu.regs.sr and $2000=0 then router.cpu.regs.sr:=router.cpu.regs.sr or $c000;
if router.cpu.regs.sr and $C000=0 then begin
router.cpu.fetch;
router.cpu.execute;
router.console.tick;
router.timer.tick;
router.Lance.SingleStetp;
router.Lance2.SingleStetp;
end;
if router.console.UserReadConsole(c) then begin
memoaddchar(form1.memo4,chr(c));
if form1.serversocket1.Socket.ActiveConnections>0 then form1.serversocket1.Socket.Connections[0].SendText(chr(c));
end;
ch:=#0;
end;
inc(b);
if router.cpu.regs.sr and $c000 =$c000 then sleep(10);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
button1.Enabled:=false;
listbox1.Items.LoadFromFile('C2500ROM64k.txt');
button3.Enabled:=true;
button7.Enabled:=true;
listbox1.Visible:=true;
edit6.Enabled:=true;
edit6.Text:=inttohex(router.cpu.MemoryRead16($2000002),4);
end;
function look4(a:longword):integer;
var s1,s2:string[8];
i:integer;
begin
result:=$ffff;
for i:=0 to form1.listbox1.Items.Count-1 do
begin
s1:=form1.listbox1.Items[i];
setlength(s1,8);
s2:=inttohex(a,8);
if s1=s2 then result:=i;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var i,j:byte;
l:longword;
s,s2:string[80];
begin
router.cpu.DebugNoCount:=false;
memo6.Clear;
memo6.Lines.Add('confreg: '+inttohex(router.cpu.memoryread16($02000002),4));
memo6.Lines.Add('control1: '+inttohex(router.cpu.memoryread16($02110000),4));
memo6.Lines.Add('control2: '+inttohex(router.cpu.memoryread16($02110002),4));
memo6.Lines.Add('reset: '+inttohex(router.cpu.memoryread16($02110004),4));
memo6.Lines.Add('interrupt:'+inttohex(router.cpu.memoryread16($02110006),4));
memo6.Lines.Add('unk: '+inttohex(router.cpu.memoryread16($02110008),4));
memo6.Lines.Add('NVRAM: '+inttohex(router.cpu.memoryread8($02110060),2));
memo6.Lines.Add('ce: '+inttohex(router.cookie.ce,1));
memo6.Lines.Add('clock: '+inttohex(router.cookie.clock,1));
memo6.Lines.Add('Bitno: '+inttohex(router.cookie.bitno,2));
memo6.Lines.Add('command: '+inttohex(router.cookie.command,2));
memo6.Lines.Add('read Addr: '+inttohex(router.cookie.nvramRaddr,2));
memo6.Lines.Add('DO: '+inttohex((router.cpu.memoryread8($02110060)and 2) shr 1 ,1));
memo6.Lines.Add('DI: '+inttohex(router.cpu.memoryread8($02110060)and 1,1));
memo6.Lines.Add('T0counter:'+inttohex(router.cpu.memoryread16($02120050),4));
memo6.Lines.Add('T2counter:'+inttohex(router.cpu.memoryread16($02120070),4));
memo6.Lines.Add('InitCount:'+inttohex(router.Lance.initCount,4));
memo6.Lines.Add('imr: '+inttohex(router.console.imr_copy,2));
memo6.Lines.Add('SrA: '+inttohex(router.console.sra,2));
//01007CC2
label11.Caption:=inttohex(router.cpu.CPUCycles,16);
if router.cpu.regs.pc and 1 <>0 then memo1.Font.Color:=3;
memo1.Lines.Clear;
for i:=0 to listbox1.Items.Count-1 do listbox1.Selected[i]:=false;
//memo1.Lines.add('--------------------------');
For i:=0 to 3 do begin
memo1.Lines.add('|A'+inttostr(i)+'='+inttohex(router.cpu.regs.a[i],8)+' A'+inttostr(i+4)+'='+inttohex(router.cpu.regs.a[i+4],8)+' |');
end;
memo1.Lines.add('--------------------------');
For i:=0 to 3 do begin
memo1.Lines.add('|D'+inttostr(i)+'='+inttohex(router.cpu.regs.d[i],8)+' D'+inttostr(i+4)+'='+inttohex(router.cpu.regs.d[i+4],8)+' |');
end;
memo1.Lines.add('PC ='+inttohex(router.cpu.regs.pc,8)+' prv='+inttohex(router.cpu.DoldPc,8)+', '+inttohex(router.cpu.mopc,8));
//memo1.Lines.add('OP='+inttohex(cpu.currentOPcode,4));
memo1.Lines.add('VBR='+inttohex(router.cpu.regs.VBR,8));
//memo1.Lines.add('OP='+inttohex(cpu.currentOPcode,4));
s:='Flags=';
if router.cpu.regs.sr and 1 <>0 then s:=s+'C' else s:=s+'c';
if router.cpu.regs.sr and 2 <>0 then s:=s+'V' else s:=s+'v';
if router.cpu.regs.sr and 4 <>0 then s:=s+'Z' else s:=s+'z';
if router.cpu.regs.sr and 8 <>0 then s:=s+'N' else s:=s+'n';
if router.cpu.regs.sr and $10 <>0 then s:=s+'X' else s:=s+'x';
if router.cpu.regs.sr and $1000 <>0 then s:=s+'M' else s:=s+'m';
if router.cpu.regs.sr and $2000 <>0 then s:=s+'S' else s:=s+'s';
s:=s+' int mask'+inttohex((router.cpu.regs.sr and $0700)shr 8,1);
memo1.Lines.Add(s);
if look4(router.cpu.regs.pc)<>$ffff then listbox1.Selected[look4(router.cpu.regs.pc)]:=true;
memo2.Lines.Clear;
memo3.Lines.Clear;
memo5.Lines.Clear;
for j:=0 to 4 do
begin
s:=inttohex(view1addr+16*j,8)+' ';
s2:=inttohex(view1addr+16*j,8)+' ';
for i:=0 to $f do begin
s:=s+inttohex(router.cpu.memoryRead8(view1addr+16*j+i),2)+' ';
s2:=s2+chr(router.cpu.memoryRead8(view1addr+16*j+i));
if i and 3 =3 then s:=s+' ';
end;
memo2.Lines.Add(s);
memo5.Lines.Add(s2);
end;
for j:=0 to 5 do
begin
s:=inttohex(view2addr+16*j,8)+' ';
for i:=0 to $f do begin
s:=s+inttohex(router.cpu.memoryRead8(view2addr+16*j+i),2)+' ';
if i and 3 =3 then s:=s+' ';
end;
memo3.Lines.Add(s);
end;
//listbox2.Clear;
l:=router.cpu.regs.a[7];
{for i:=1 to 6 do begin
listbox2.items.add(inttohex(cpu.memoryread32(l+4),8));
l:=l+4;
end;}
//clock2500.tick;
router.cpu.DebugNoCount:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
var error:string;
begin
error:='';
try
//router:=cisco2500.intit(c2511,'nvram.bin','rom.xin','ios.bin','cookie.bin',4,LoadIOS or LoadNVR or LoadROM or Loadcookie or IntCtrlInst);
router:=cisco2500.intit(c2511,'nvram.bin','rom.xin','ios11.1.24.bin','cookie.bin',8,LoadIOS or LoadNVR or LoadROM or Loadcookie or IntCtrlInst);
//router:=cisco2500.intit(c2511,'nvram.bin','bios.bin','linux.bin','cookie.bin',8,LoadIOS or LoadNVR or LoadROM or Loadcookie or IntCtrlInst or crypt);
//router:=cisco2500.intit(c2511,'nvram.bin','c2514.bin','ios11.1.24.bin','cookie.bin',8,LoadIOS or LoadNVR or LoadROM or Loadcookie or IntCtrlInst or crypt);
except
on e: C2500Ex do error:=e.Message;
end;
if error<>'' then begin
messagebox(0,PChar(error),PChar('Error notification'),2);
halt;
end;
router.debug_Speed:=$ffffff;
memo4.Lines.Add('');
//SetPriorityClass(thread, IDLE_PRIORITY_CLASS);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
router.cpu.regs.sr:=router.cpu.regs.sr and $3fff;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//router.cpu.regs.sr:=router.cpu.regs.sr or $c000;
router.cpu.fetch;
router.cpu.execute;
router.timer.tick;
router.console.tick;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i:byte;
begin
router.cpu.regs.pc:=$1000134;
memo4.Clear;
for i:=0 to 7 do router.cpu.regs.a[i]:=0;
for i:=0 to 6 do router.cpu.regs.d[i]:=0;
router.cpu.regs.a[7]:=$1000;
router.IntCtrl.reset;
//button4.Enabled:=false;
end;
procedure TForm1.Edit2Exit(Sender: TObject);
begin
if edit2.text[1]='$' then View2addr:=strtoint(edit2.text);
if edit7.Text[1]='$' then View2addr:=View2addr+strtoint(edit7.text);
if upcase(edit2.text[1])='A' then View2addr:=router.cpu.regs.a[ord(edit2.text[2])-48];
if upcase(edit2.text[1])='D' then View2addr:=router.cpu.regs.d[ord(edit2.text[2])-48];
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
if edit1.text[1]='$' then View1addr:=strtoint(edit1.text);
if upcase(edit1.text[1])='A' then View1addr:=router.cpu.regs.a[ord(edit1.text[2])-48];
if upcase(edit1.text[1])='D' then View1addr:=router.cpu.regs.d[ord(edit1.text[2])-48];
end;
procedure TForm1.Timer2Timer(Sender: TObject);
//var b:byte;
begin
//if router.console.UserReadConsole(b) then memoaddchar(memo4,chr(b));
//ch:=#0;
//router.console.UserWriteConsole($ff);
//router.console.intrq;
router.console.switchTxRDY;
label14.Caption:=inttohex(router.cpu.regs.pc,8);
label15.Caption:=router.cpu.currentINSTR;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
memoaddchar(memo4,chr(65));
memoaddchar(memo4,chr(66));
memoaddchar(memo4,chr($a));
memoaddchar(memo4,chr($d));
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
timer2.Enabled:= not timer2.Enabled;
if timer2.Enabled then begin
label7.Caption:='on';
button6.Caption:='Console &Off';
end
else begin
label7.Caption:='off';
button6.Caption:='Console &On';
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if tid=0 then begin
thread := BeginThread(nil,
0,
@tick,
nil,
0,
tid);
tid:=1;
end;
router.cpu.regs.sr:=router.cpu.regs.sr and $3fff;
timer2.Enabled:= true;
label7.Caption:='on';
button6.Caption:='Console &off';
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
//router.cpu.regs.sr:=router.cpu.regs.sr or $4000;
router.debug_speed:=$ffffff;
if tid=1 then begin
// CloseHandle(thread);
TerminateThread(thread,0);
tid:=0;
end;
timer1.Enabled:=true;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
router.cpu.Interrupt(strtoint(edit4.Text));
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
timer1.Enabled:=not timer1.Enabled;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
breakpoint:=strtoint(edit5.Text);
label9.Caption:=edit5.Text;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
router.cpu.regs.sr:=router.cpu.regs.sr xor 1;
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
router.cpu.regs.sr:=router.cpu.regs.sr xor 8;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
router.cpu.regs.sr:=router.cpu.regs.sr xor 2;
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
router.cpu.regs.sr:=router.cpu.regs.sr xor 4;
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
router.debug_speed:=$ffffff;
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
router.debug_speed:=$fffff;
end;
procedure TForm1.Button17Click(Sender: TObject);
begin
router.debug_speed:=$1;
timer1.Enabled:=false;
end;
procedure TForm1.Memo4KeyPress(Sender: TObject; var Key: Char);
begin
router.console.UserWriteConsole(ord(key));
end;
procedure TForm1.Timer3Timer(Sender: TObject);
begin
if router.cpu.regs.sr and $c000 =$c000 then label12.caption:='Cpu Status: Stopped'
else label12.caption:='Cpu Status: Running';
end;
procedure TForm1.Edit6Exit(Sender: TObject);
begin
try
router.cpu.MemoryWrite16($2000002,strtoint(edit6.Text));
except
on EConvertError do application.MessageBox('bla','bla',MB_OK);
end;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
router.cpu.savestat;
end;
procedure TForm1.Button20Click(Sender: TObject);
begin
router.cpu.dump;
router.cpu.CPUStatusSave;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
router.Lance.destroy;
end;
procedure TForm1.Edit5Exit(Sender: TObject);
begin
breakpoint:=strtoint(edit5.Text);
label9.Caption:=edit5.Text;
end;
procedure TForm1.Button21Click(Sender: TObject);
begin
router.cpu.dump;
router.cpu.CPUStatusSave;
router.Lance.StatusSave;
router.cookie.StatusSave;
router.IntCtrl.StatusSave;
router.nvram.StatusSave;
router.sysregs.StatusSave;
router.timer.StatusSave;
router.console.StatusSave;
memo4.Lines.SaveToFile('.\sav\screen.txt');
end;
procedure TForm1.Button22Click(Sender: TObject);
begin
router.cpu.RestoreMemory;
router.cpu.CPUStatusRestore;
router.Lance.StatusRestore;
router.cookie.StatusRestore;
router.IntCtrl.StatusRestore;
router.nvram.StatusRestore;
router.sysregs.StatusRestore;
router.timer.StatusRestore;
router.console.StatusRestore;
memo4.Lines.LoadFromFile('.\sav\screen.txt');
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var s:string;
i:byte;
begin
s:=Socket.ReceiveText;
for i:=1 to length(s) do router.console.UserWriteConsole(ord(s[i]));
end;
end.