OpenCores
URL https://opencores.org/ocsvn/z80control/z80control/trunk

Subversion Repositories z80control

[/] [z80control/] [trunk/] [CII_Starter_USB_API_v1/] [SW/] [Main.cpp] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 tylerapohl
// --------------------------------------------------------------------
2
// Copyright (c) 2005 by Terasic Technologies Inc. 
3
// --------------------------------------------------------------------
4
//
5
// Permission:
6
//
7
//   Terasic grants permission to use and modify this code for use
8
//   in synthesis for all Terasic Development Boards and Altera Development 
9
//   Kits made by Terasic.  Other use of this code, including the selling 
10
//   ,duplication, or modification of any portion is strictly prohibited.
11
//
12
// Disclaimer:
13
//
14
//   This VHDL/Verilog or C/C++ source code is intended as a design reference
15
//   which illustrates how these types of functions can be implemented.
16
//   It is the user's responsibility to verify their design for
17
//   consistency and functionality through the use of formal
18
//   verification methods.  Terasic provides no warranty regarding the use
19
//   or functionality of this code.
20
//
21
// --------------------------------------------------------------------
22
//           
23
//                     Terasic Technologies Inc
24
//                     356 Fu-Shin E. Rd Sec. 1. JhuBei City,
25
//                     HsinChu County, Taiwan
26
//                     302
27
//
28
//                     web: http://www.terasic.com/
29
//                     email: support@terasic.com
30
//
31
// --------------------------------------------------------------------
32
//
33
// Major Functions:     CII Starter Kit USB API Borland C++ Builder Code
34
//
35
// --------------------------------------------------------------------
36
//
37
// Revision History :
38
// --------------------------------------------------------------------
39
//   Ver  :| Author            :| Mod. Date :| Changes Made:
40
//   V1.0 :| Johnny Chen       :| 06/06/07  :| Initial Revision
41
// --------------------------------------------------------------------
42
//---------------------------------------------------------------------------
43
 
44
#include <vcl.h>
45
#pragma hdrstop
46
 
47
#include "Main.h"
48
#include "About.h"
49
#include "PS2_Thread.h"
50
#include "Test_Page.h"
51
//---------------------------------------------------------------------------
52
#pragma package(smart_init)
53
#pragma resource "*.dfm"
54
TForm1 *Form1;
55
 
56
int PS2_times=0;
57
bool USB_is_Open=false;
58
FILE *file1,*file2;
59
 
60
//---------------------------------------------------------------------------
61
__fastcall TForm1::TForm1(TComponent* Owner)
62
   : TForm(Owner)
63
{
64
   Form1->DoubleBuffered=true;
65
   // ToDo  :  Check Number Of FTDI Device In System
66
   int NumDev=USB1.Number_Of_Device();
67
   if(NumDev!=0)
68
   {
69
      NonUSBPort1->Visible=false;
70
      OpenUSBPort0->Visible=true;
71
      if(NumDev>1)
72
      OpenUSBPort1->Visible=true;
73
      if(NumDev>2)
74
      OpenUSBPort2->Visible=true;
75
      if(NumDev>3)
76
      OpenUSBPort3->Visible=true;
77
   }
78
}
79
//---------------------------------------------------------------------------
80
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
81
{
82
   // ToDo : Close Control Panel and Close USB JTAG Port
83
   Close_USB_Port();
84
}
85
//---------------------------------------------------------------------------
86
 
87
void __fastcall TForm1::Button2Click(TObject *Sender)
88
{
89
   // ToDo : Send LED Value To FPGA
90
   char x[8];
91
   x[0]=WRITE;
92
   x[1]=LED;
93
   x[2]=0x00;
94
   x[3]=(char(DR9->Checked)<<1)+(char(DR8->Checked));
95
   x[4]=(char(DR7->Checked)<<7)+(char(DR6->Checked)<<6)+(char(DR5->Checked)<<5)+(char(DR4->Checked)<<4)+
96
        (char(DR3->Checked)<<3)+(char(DR2->Checked)<<2)+(char(DR1->Checked)<<1)+(char(DR0->Checked));
97
   x[5]=0x00;
98
   x[6]=(char(D8->Checked)<<7)+(char(D7->Checked)<<6)+(char(D6->Checked)<<5)+(char(D5->Checked)<<4)+
99
        (char(D4->Checked)<<3)+(char(D3->Checked)<<2)+(char(D2->Checked)<<1)+(char(D1->Checked));
100
   x[7]=DISPLAY;
101
   PS2_REC->Suspend();
102
   USB1.Reset_Device(0);
103
   USB1.Write_Data(x,8,0,true);
104
   PS2_REC->Resume();
105
   Button1Click(this);
106
}
107
//---------------------------------------------------------------------------
108
void __fastcall TForm1::Button5Click(TObject *Sender)
109
{
110
   // ToDo : Flash Random Write
111
   char x[8];
112
   x[0]=WRITE;
113
   x[1]=FLASH;
114
   x[2]=char(HexToInt(oFL_ADDR->Text)>>16);
115
   x[3]=char(HexToInt(oFL_ADDR->Text)>>8);
116
   x[4]=char(HexToInt(oFL_ADDR->Text));
117
   x[5]=0xFF;
118
   x[6]=char(HexToInt(oFL_DATA->Text));
119
   x[7]=NORMAL;
120
   USB1.Reset_Device(0);
121
   USB1.Write_Data(x,8,0,true);
122
}
123
//---------------------------------------------------------------------------
124
 
125
void __fastcall TForm1::Button4Click(TObject *Sender)
126
{
127
   // ToDo : Flash Random Read
128
   char x[8];
129
   //-----------------------------------
130
   // T-Rex TXD Output Select to FLASH
131
   x[0]=SETUP;
132
   x[1]=SET_REG;
133
   x[2]=0x12;
134
   x[3]=0x34;
135
   x[4]=0x56;
136
   x[5]=0x00;
137
   x[6]=FLASH;
138
   x[7]=OUTSEL;
139
   USB1.Reset_Device(0);
140
   USB1.Write_Data(x,8,0,true);
141
   Sleep(10);
142
   //-----------------------------------
143
   // Send Flash Address To FPGA
144
   x[0]=READ;
145
   x[1]=FLASH;
146
   x[2]=char(HexToInt(oFL_ADDR->Text)>>16);
147
   x[3]=char(HexToInt(oFL_ADDR->Text)>>8);
148
   x[4]=char(HexToInt(oFL_ADDR->Text));
149
   x[5]=0xFF;
150
   x[6]=0x00;
151
   x[7]=NORMAL;
152
   USB1.Write_Data(x,8,1,true);
153
   Sleep(10);
154
   // Flash Random Read
155
   USB1.Read_Data(x,1);
156
   // Show Get Value To Text Filed
157
   iFL_DATA->Text=IntToHex((unsigned char)x[0],2);
158
   //-----------------------------------
159
   // T-Rex TXD Output Select to PS2
160
   x[0]=SETUP;
161
   x[1]=SET_REG;
162
   x[2]=0x12;
163
   x[3]=0x34;
164
   x[4]=0x56;
165
   x[5]=0x00;
166
   x[6]=PS2;
167
   x[7]=OUTSEL;
168
   USB1.Reset_Device(0);
169
   USB1.Write_Data(x,8,0,true);
170
   //-----------------------------------
171
}
172
//---------------------------------------------------------------------------
173
void __fastcall TForm1::Button3Click(TObject *Sender)
174
{
175
   // ToDo : Erase Flash
176
   Screen->Cursor=crHourGlass;
177
   // Show Busy Panel
178
   Panel1->Visible=true;
179
   // Disable All Button
180
   Show_All_Button(false);
181
   // Set ProgressBar
182
   ProgressBar1->Max=400;
183
   // Send Erase Command To FPGA
184
   char x[8];
185
   int wait=0;
186
   x[0]=ERASE;
187
   x[1]=FLASH;
188
   x[2]=0x00;
189
   x[3]=0x00;
190
   x[4]=0x00;
191
   x[5]=0xFF;
192
   x[6]=0x00;
193
   x[7]=NORMAL;
194
   USB1.Reset_Device(0);
195
   USB1.Write_Data(x,8,0,true);
196
   USB1.Write_Data(x,8,0,true);
197
   USB1.Write_Data(x,8,0,true);
198
   // Wait 40 Sec.....
199
   for(int i=0;i<400;i++)
200
   {
201
      // Display Process %
202
      Process_Label->Caption=IntToStr(i*100/400)+" %";
203
      ProgressBar1->Position=i;
204
      Application->ProcessMessages();
205
      // Waitting
206
      Sleep(100);
207
   }
208
   Form1->iFL_DATA->Text="00";
209
   // Max Wait 60 Sec...
210
   while((HexToInt(Form1->iFL_DATA->Text)!=255) && wait<600 )
211
   {
212
      Form1->Button4Click(this);
213
      Application->ProcessMessages();
214
      Sleep(100);
215
      wait++;
216
   }
217
   if(wait==600)
218
   ShowMessage("FLASH Erase TimeOut!!");
219
   Form1->iFL_DATA->Text="00";
220
   // Close Busy Panel
221
   Panel1->Visible=false;
222
   // Enable All Button
223
   Show_All_Button(true);
224
   Screen->Cursor=crArrow;
225
}
226
//---------------------------------------------------------------------------
227
 
228
void __fastcall TForm1::Button6Click(TObject *Sender)
229
{
230
   // TODO : Write File To Flash
231
   if(OpenDialog1->Execute())
232
   {
233
      char x[8];
234
      int File_Length,File_Type;
235
      int ADDR=HexToInt(iWR_ADDR->Text);
236
      Screen->Cursor=crHourGlass;
237
      // Show Busy Panel
238
      Panel1->Visible=true;
239
      // Disable All Button
240
      Show_All_Button(false);
241
      // Send Flash Write Command To FPGA
242
      x[0]=WRITE;
243
      x[1]=FLASH;
244
      x[5]=0xFF;
245
      x[7]=NORMAL;
246
      USB1.Reset_Device(0);
247
      // Check File Type and Open File
248
      if(Select_File(OpenDialog1->FileName)==1)
249
      {
250
         File_AscToHex(OpenDialog1->FileName,"123.tmp",1);
251
         Sleep(100);
252
         file1=fopen("123.tmp","rb");
253
      }
254
      else
255
      file1=fopen(OpenDialog1->FileName.c_str(),"rb");
256
      // Set File ptr To File End
257
      fseek(file1,0,SEEK_END);
258
      // Set Transport Length
259
      if(CheckBox1->Checked)
260
      {
261
         // Check File Length
262
         File_Length=ftell(file1);
263
         // Show File Length To Text Field
264
         iWR_Length->Text=IntToHex(File_Length,6);
265
      }
266
      else
267
      File_Length=HexToInt(iWR_Length->Text);
268
      // Set ProgressBar
269
      ProgressBar1->Max=File_Length;
270
      // Set File ptr To File Start
271
      fseek(file1,0,SEEK_SET);
272
      // Read File Data To Temp Memory
273
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,File_Length,MEM_COMMIT,PAGE_READWRITE);
274
      fread(a,sizeof(char),File_Length,file1);
275
      // Transport File To Flash
276
      for(int i=0;i<File_Length;i++)
277
      {
278
         // Display Process %
279
         Process_Label->Caption=IntToStr(i*100/File_Length)+" %";
280
         ProgressBar1->Position=i;
281
         Application->ProcessMessages();
282
         // Send Data and Address
283
         x[2]=char(ADDR>>16);
284
         x[3]=char(ADDR>>8);
285
         x[4]=char(ADDR);
286
         x[5]=0xFF;
287
         x[6]=a[i];
288
         if(i%MAX_TOTAL_PACKET==MAX_TOTAL_PACKET-1)
289
         USB1.Reset_Device(0);
290
         if(i<File_Length-1)
291
         USB1.Write_Data(x,8,0,false);
292
         else
293
         USB1.Write_Data(x,8,0,true);
294
         // Inc Address
295
         ADDR++;
296
      }
297
      USB1.Reset_Device(0);
298
      // Close File
299
      fclose(file1);
300
      // Delete Temp File
301
      if(FileExists("123.tmp"))
302
      DeleteFile("123.tmp");
303
      // Close Busy Panel
304
      Panel1->Visible=false;
305
      // Enable All Button
306
      Show_All_Button(true);
307
      // Free Temp Memory
308
      VirtualFree(a,0,MEM_RELEASE);
309
      Screen->Cursor=crArrow;
310
   }
311
}
312
//---------------------------------------------------------------------------
313
void __fastcall TForm1::Button7Click(TObject *Sender)
314
{
315
   // ToDo : Load Flash Content to File
316
   if(SaveDialog1->Execute())
317
   {
318
      char x[8];
319
      int DATA_Read=0;
320
      int Queue;
321
      int Flash_Length;
322
      int ADDR=HexToInt(iRD_ADDR->Text);
323
      Screen->Cursor=crHourGlass;
324
      // Show Busy Panel
325
      Panel1->Visible=true;
326
      // Disable All Button
327
      Show_All_Button(false);
328
      //-----------------------------------
329
      // T-Rex TXD Output Select to FLASH
330
      x[0]=SETUP;
331
      x[1]=SET_REG;
332
      x[2]=0x12;
333
      x[3]=0x34;
334
      x[4]=0x56;
335
      x[5]=0x00;
336
      x[6]=FLASH;;
337
      x[7]=OUTSEL;
338
      USB1.Reset_Device(0);
339
      USB1.Write_Data(x,8,0,true);
340
      Sleep(10);
341
      //-----------------------------------
342
      // Send Flash Read Command To FPGA
343
      x[0]=READ;
344
      x[1]=FLASH;
345
      x[5]=0xFF;
346
      x[6]=0x00;
347
      x[7]=NORMAL;
348
      // Set Transport Length
349
      if(CheckBox2->Checked)
350
      {
351
         // Set Transport Length = Flash Size = 4Mbyte
352
         Flash_Length=1048576*4;
353
         // Show Transport Length To Text Field
354
         iRD_Length->Text=IntToHex(Flash_Length,6);
355
      }
356
      else
357
      Flash_Length=HexToInt(iRD_Length->Text);
358
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,Flash_Length+MAX_RXD_PACKET,MEM_COMMIT,PAGE_READWRITE);
359
      // Set ProgressBar
360
      ProgressBar1->Max=Flash_Length;
361
      // Transport Flash Data To File
362
      for(int i=0;i<Flash_Length;i++)
363
      {
364
         // Display Process %
365
         Process_Label->Caption=IntToStr(i*100/Flash_Length)+" %";
366
         ProgressBar1->Position=i;
367
         Application->ProcessMessages();
368
         // Send Address
369
         x[2]=char(ADDR>>16);
370
         x[3]=char(ADDR>>8);
371
         x[4]=char(ADDR);
372
         if(i%ALMOST_FULL_SIZE==ALMOST_FULL_SIZE-1)
373
         USB1.Write_Data(x,8,1,true);
374
         else if(i==Flash_Length-1)
375
         USB1.Write_Data(x,8,1,true);
376
         else
377
         USB1.Write_Data(x,8,1,false);
378
         if(i%MAX_RXD_PACKET==MAX_RXD_PACKET-1)
379
         {
380
            // Flash Seq. Read
381
            USB1.Read_Data(&a[DATA_Read],MAX_RXD_PACKET);
382
            DATA_Read+=MAX_RXD_PACKET;
383
            USB1.Reset_Device(0);
384
         }
385
         // Inc Address
386
         ADDR++;
387
      }
388
      // Wait a short time to get Data Form USB JTAG
389
      USB1.Write_Data(x,0,8,true);
390
      Sleep(100);
391
      Queue=USB1.Number_Of_Queue_Data();
392
      USB1.Read_Data(&a[DATA_Read],Queue);
393
      // Check File and Write File
394
      if(Select_File(SaveDialog1->FileName)==1)
395
      {
396
         file2=fopen("123.tmp","w+b");
397
         fwrite(a,sizeof(char),Flash_Length,file2);
398
         fclose(file2);
399
         Sleep(100);
400
         File_HexToAsc("123.tmp",SaveDialog1->FileName,1);
401
      }
402
      else
403
      {
404
         file2=fopen(SaveDialog1->FileName.c_str(),"w+b");
405
         fwrite(a,sizeof(char),Flash_Length,file2);
406
         fclose(file2);
407
      }
408
      Sleep(100);
409
      VirtualFree(a,0,MEM_RELEASE);
410
      // Delete Temp File
411
      if(FileExists("123.tmp"))
412
      DeleteFile("123.tmp");
413
      //-----------------------------------
414
      // T-Rex TXD Output Select to PS2
415
      x[0]=SETUP;
416
      x[1]=SET_REG;
417
      x[2]=0x12;
418
      x[3]=0x34;
419
      x[4]=0x56;
420
      x[5]=0x00;
421
      x[6]=PS2;
422
      x[7]=OUTSEL;
423
      USB1.Reset_Device(0);
424
      USB1.Write_Data(x,8,0,true);
425
      //-----------------------------------
426
      // Close Busy Panel
427
      Panel1->Visible=false;
428
      // Enable All Button
429
      Show_All_Button(true);
430
      Screen->Cursor=crArrow;
431
   }
432
}
433
//---------------------------------------------------------------------------
434
 
435
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
436
{
437
   // ToDo : if( Flash Write Size == File Length )
438
   // Disable iWR_Length Text Field
439
   if(CheckBox1->Checked)
440
   iWR_Length->ReadOnly=true;
441
   else
442
   iWR_Length->ReadOnly=false;
443
}
444
//---------------------------------------------------------------------------
445
void __fastcall TForm1::CheckBox2Click(TObject *Sender)
446
{
447
   // ToDo : if( Flash Read Size = Entrie Flash )
448
   // Show iRD_Length = 4 MByte
449
   // And Disable iRD_Length Text Field
450
   if(CheckBox2->Checked)
451
   {
452
      iRD_Length->Text="400000";
453
      iRD_Length->ReadOnly=true;
454
   }
455
   else
456
   {
457
      iRD_Length->Text="0";
458
      iRD_Length->ReadOnly=false;
459
   }
460
}
461
//---------------------------------------------------------------------------
462
void __fastcall TForm1::OpenUSBPort0Click(TObject *Sender)
463
{
464
   // ToDo : Open USB JTAG Port 1 and Enable All Button
465
   if(USB_is_Open)
466
   {
467
      USB1.Close_Device();
468
      USB_is_Open=false;
469
   }
470
   USB1.Select_Device(0);
471
   if(USB1.Open_Device())
472
   {
473
      USB_is_Open=true;
474
      USB1.Reset_Device(0);
475
      PS2_REC = new TPS2_REC(true);
476
      PS2_REC->Resume();
477
      Show_All_Button(true);
478
      CloseUSBPort1->Visible=true;
479
   }
480
}
481
//---------------------------------------------------------------------------
482
void __fastcall TForm1::OpenUSBPort1Click(TObject *Sender)
483
{
484
   // ToDo : Open USB JTAG Port 2 and Enable All Button
485
   if(USB_is_Open)
486
   {
487
      USB1.Close_Device();
488
      USB_is_Open=false;
489
   }
490
   USB1.Select_Device(1);
491
   if(USB1.Open_Device())
492
   {
493
      USB_is_Open=true;
494
      USB1.Reset_Device(0);
495
      PS2_REC = new TPS2_REC(true);
496
      PS2_REC->Resume();
497
      Show_All_Button(true);
498
      CloseUSBPort1->Visible=true;
499
   }
500
}
501
//---------------------------------------------------------------------------
502
void __fastcall TForm1::OpenUSBPort2Click(TObject *Sender)
503
{
504
   // ToDo : Open USB JTAG Port 3 and Enable All Button
505
   if(USB_is_Open)
506
   {
507
      USB1.Close_Device();
508
      USB_is_Open=false;
509
   }
510
   USB1.Select_Device(2);
511
   if(USB1.Open_Device())
512
   {
513
      USB_is_Open=true;
514
      USB1.Reset_Device(0);
515
      PS2_REC = new TPS2_REC(true);
516
      PS2_REC->Resume();
517
      Show_All_Button(true);
518
      CloseUSBPort1->Visible=true;
519
   }
520
}
521
//---------------------------------------------------------------------------
522
void __fastcall TForm1::OpenUSBPort3Click(TObject *Sender)
523
{
524
   // ToDo : Open USB JTAG Port 4 and Enable All Button
525
   if(USB_is_Open)
526
   {
527
      USB1.Close_Device();
528
      USB_is_Open=false;
529
   }
530
   USB1.Select_Device(3);
531
   if(USB1.Open_Device())
532
   {
533
      USB_is_Open=true;
534
      USB1.Reset_Device(0);
535
      PS2_REC = new TPS2_REC(true);
536
      PS2_REC->Resume();
537
      Show_All_Button(true);
538
      CloseUSBPort1->Visible=true;
539
   }
540
}
541
//---------------------------------------------------------------------------
542
void __fastcall TForm1::About1Click(TObject *Sender)
543
{
544
   // ToDo : Show About Form
545
   AboutBox->Visible=true;
546
}
547
//---------------------------------------------------------------------------
548
void __fastcall TForm1::Help1Click(TObject *Sender)
549
{
550
   // ToDo : Open Help
551
   ShellExecute(NULL,NULL,"CII_Starter_Kit_UserGuide.pdf",NULL,NULL,SW_SHOWNORMAL);
552
}
553
//---------------------------------------------------------------------------
554
void __fastcall TForm1::Button8Click(TObject *Sender)
555
{
556
   // ToDo : Clear PS2 Text Windows
557
   Memo1->Clear();
558
}
559
//---------------------------------------------------------------------------
560
int __fastcall TForm1::HexToInt(AnsiString strHex)
561
{
562
  return StrToInt64("0x"+strHex);
563
}
564
//---------------------------------------------------------------------------
565
void __fastcall TForm1::Show_All_Button(bool Show)
566
{
567
   // ToDo : Enable / Disable All Button
568
   // Please add all button in this function
569
   Button1->Enabled=Show;
570
   Button2->Enabled=Show;
571
   Button3->Enabled=Show;
572
   Button4->Enabled=Show;
573
   Button5->Enabled=Show;
574
   Button6->Enabled=Show;
575
   Button7->Enabled=Show;
576
   Button8->Enabled=Show;
577
   Button9->Enabled=Show;
578
   Button10->Enabled=Show;
579
   Button11->Enabled=Show;
580
   Button12->Enabled=Show;
581
   Button13->Enabled=Show;
582
   Button14->Enabled=Show;
583
   Button15->Enabled=Show;
584
   Button16->Enabled=Show;
585
   Button17->Enabled=Show;
586
   Button18->Enabled=Show;
587
   Default_IMG->Enabled=Show;
588
   Cursor_EN->Enabled=Show;
589
   ScrollBar1->Enabled=Show;
590
   ScrollBar2->Enabled=Show;
591
 
592
}
593
//---------------------------------------------------------------------------
594
 
595
void __fastcall TForm1::CheckBox4Click(TObject *Sender)
596
{
597
   // ToDo : if( Sdram Read Size = Entrie Sdram )
598
   // Show iSDR_SRD_Length = 8 MByte
599
   // And Disable iSDR_SRD_Length Text Field
600
   if(CheckBox4->Checked)
601
   {
602
      iSDR_SRD_Length->Text="800000";
603
      iSDR_SRD_Length->ReadOnly=true;
604
   }
605
   else
606
   {
607
      iSDR_SRD_Length->Text="0";
608
      iSDR_SRD_Length->ReadOnly=false;
609
   }
610
}
611
//---------------------------------------------------------------------------
612
void __fastcall TForm1::CheckBox3Click(TObject *Sender)
613
{
614
   // ToDo : if( Sdram Write Size == File Length )
615
   // Disable iSDR_SWR_Length Text Field
616
   if(CheckBox3->Checked)
617
   iSDR_SWR_Length->ReadOnly=true;
618
   else
619
   iSDR_SWR_Length->ReadOnly=false;
620
}
621
//---------------------------------------------------------------------------
622
void __fastcall TForm1::Button9Click(TObject *Sender)
623
{
624
   // ToDo : Sdram Random Write
625
   char x[8];
626
   x[0]=WRITE;
627
   x[1]=SDRAM;
628
   x[2]=char(HexToInt(oSDR_ADDR->Text)>>16);
629
   x[3]=char(HexToInt(oSDR_ADDR->Text)>>8);
630
   x[4]=char(HexToInt(oSDR_ADDR->Text));
631
   x[5]=char(HexToInt(oSDR_DATA->Text)>>8);
632
   x[6]=char(HexToInt(oSDR_DATA->Text));
633
   x[7]=NORMAL;
634
   USB1.Reset_Device(0);
635
   USB1.Write_Data(x,8,0,true);
636
}
637
//---------------------------------------------------------------------------
638
void __fastcall TForm1::Button10Click(TObject *Sender)
639
{
640
   // ToDo : Sdram Random Read
641
   char x[8];
642
   //-----------------------------------
643
   // T-Rex TXD Output Select to SDRAM
644
   x[0]=SETUP;
645
   x[1]=SET_REG;
646
   x[2]=0x12;
647
   x[3]=0x34;
648
   x[4]=0x56;
649
   x[5]=0x00;
650
   x[6]=SDRAM;
651
   x[7]=OUTSEL;
652
   USB1.Reset_Device(0);
653
   USB1.Write_Data(x,8,0,true);
654
   Sleep(10);
655
   //-----------------------------------
656
   // Send SDRAM Address To FPGA
657
   x[0]=READ;
658
   x[1]=SDRAM;
659
   x[2]=char(HexToInt(oSDR_ADDR->Text)>>16);
660
   x[3]=char(HexToInt(oSDR_ADDR->Text)>>8);
661
   x[4]=char(HexToInt(oSDR_ADDR->Text));
662
   x[5]=0x00;
663
   x[6]=0x00;
664
   x[7]=NORMAL;
665
   USB1.Write_Data(x,8,2,true);
666
   Sleep(10);
667
   // Sdram Random Read
668
   USB1.Read_Data(x,2);
669
   // Show Get Value To Text Filed
670
   iSDR_DATA->Text=IntToHex((unsigned char)x[0]+(unsigned char)x[1]*256,4);
671
   //-----------------------------------
672
   // T-Rex TXD Output Select to PS2
673
   x[0]=SETUP;
674
   x[1]=SET_REG;
675
   x[2]=0x12;
676
   x[3]=0x34;
677
   x[4]=0x56;
678
   x[5]=0x00;
679
   x[6]=PS2;
680
   x[7]=OUTSEL;
681
   USB1.Reset_Device(0);
682
   USB1.Write_Data(x,8,0,true);
683
   //-----------------------------------
684
}
685
//---------------------------------------------------------------------------
686
void __fastcall TForm1::Button11Click(TObject *Sender)
687
{
688
   // TODO : Write File To Sdram
689
   if(OpenDialog2->Execute())
690
   {
691
      char x[8];
692
      int File_Length;
693
      int ADDR=HexToInt(iSDR_SWR_ADDR->Text);
694
      Screen->Cursor=crHourGlass;
695
      // Show Busy Panel
696
      Panel1->Visible=true;
697
      // Disable All Button
698
      Show_All_Button(false);
699
      // Send Sdram Write Command To FPGA
700
      x[0]=WRITE;
701
      x[1]=SDRAM;
702
      x[7]=NORMAL;
703
      USB1.Reset_Device(0);
704
      // Check File Type and Open File
705
      if(Select_File(OpenDialog2->FileName)==1)
706
      {
707
         File_AscToHex(OpenDialog2->FileName,"123.tmp",2);
708
         Sleep(100);
709
         file1=fopen("123.tmp","rb");
710
      }
711
      else
712
      file1=fopen(OpenDialog2->FileName.c_str(),"rb");
713
      // Set File ptr To File End
714
      fseek(file1,0,SEEK_END);
715
      // Set Transport Length
716
      if(CheckBox3->Checked)
717
      {
718
         // Check File Length
719
         File_Length=ftell(file1);
720
         // Show File Length To Text Field
721
         iSDR_SWR_Length->Text=IntToHex(File_Length,6);
722
      }
723
      else
724
      File_Length=HexToInt(iSDR_SWR_Length->Text);
725
      // Set ProgressBar
726
      ProgressBar1->Max=File_Length;
727
      // Set File ptr To File Start
728
      fseek(file1,0,SEEK_SET);
729
      // Read File Data To Temp Memory
730
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,File_Length+1,MEM_COMMIT,PAGE_READWRITE);
731
      fread(a,sizeof(char),File_Length,file1);
732
      // Transport File To Sdram
733
      for(int i=0;i<File_Length;i+=2)
734
      {
735
         // Display Process %
736
         Process_Label->Caption=IntToStr(i*100/File_Length)+" %";
737
         ProgressBar1->Position=i;
738
         Application->ProcessMessages();
739
         // Send Data and Address
740
         x[2]=char(ADDR>>16);
741
         x[3]=char(ADDR>>8);
742
         x[4]=char(ADDR);
743
         x[5]=a[i+1];
744
         x[6]=a[i];
745
         if(i%MAX_TOTAL_PACKET==MAX_TOTAL_PACKET-2)
746
         USB1.Reset_Device(0);
747
         if(i<File_Length-2)
748
         USB1.Write_Data(x,8,0,false);
749
         else
750
         USB1.Write_Data(x,8,0,true);
751
         // Inc Address
752
         ADDR++;
753
      }
754
      USB1.Reset_Device(0);
755
      // Close File
756
      fclose(file1);
757
      // Close Busy Panel
758
      Panel1->Visible=false;
759
      // Enable All Button
760
      Show_All_Button(true);
761
      // Free Temp Memory
762
      VirtualFree(a,0,MEM_RELEASE);
763
      Screen->Cursor=crArrow;
764
   }
765
}
766
//---------------------------------------------------------------------------
767
void __fastcall TForm1::Button12Click(TObject *Sender)
768
{
769
   int t1,t2;
770
   // ToDo : Load Sdram Content to File
771
   if(SaveDialog2->Execute())
772
   {
773
      char x[8];
774
      int Sdram_Length;
775
      int DATA_Read=0;
776
      int Queue;
777
      int ADDR=HexToInt(iSDR_SRD_ADDR->Text);
778
      Screen->Cursor=crHourGlass;
779
      // Show Busy Panel
780
      Panel1->Visible=true;
781
      // Disable All Button
782
      Show_All_Button(false);
783
      //-----------------------------------
784
      // T-Rex TXD Output Select to SDRAM
785
      x[0]=SETUP;
786
      x[1]=SET_REG;
787
      x[2]=0x12;
788
      x[3]=0x34;
789
      x[4]=0x56;
790
      x[5]=0x00;
791
      x[6]=SDRAM;;
792
      x[7]=OUTSEL;
793
      USB1.Reset_Device(0);
794
      USB1.Write_Data(x,8,0,true);
795
      Sleep(10);
796
      //-----------------------------------
797
      // Send Sdram Read Command To FPGA
798
      x[0]=READ;
799
      x[1]=SDRAM;
800
      x[5]=0x00;
801
      x[6]=0x00;
802
      x[7]=NORMAL;
803
      // Set Transport Length
804
      if(CheckBox4->Checked)
805
      {
806
         // Set Transport Length = Sdram Size = 8Mbyte
807
         Sdram_Length=8388608;
808
         // Show Transport Length To Text Field
809
         iSDR_SRD_Length->Text=IntToHex(Sdram_Length,6);
810
      }
811
      else
812
      Sdram_Length=HexToInt(iSDR_SRD_Length->Text);
813
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,Sdram_Length+MAX_RXD_PACKET,MEM_COMMIT,PAGE_READWRITE);
814
      // Set ProgressBar
815
      ProgressBar1->Max=Sdram_Length;
816
      // Transport Sdram Data To File
817
      for(int i=0;i<Sdram_Length;i+=2)
818
      {
819
         // Display Process %
820
         Process_Label->Caption=IntToStr(i*100/Sdram_Length)+" %";
821
         ProgressBar1->Position=i;
822
         Application->ProcessMessages();
823
         // Send Address
824
         x[2]=char(ADDR>>16);
825
         x[3]=char(ADDR>>8);
826
         x[4]=char(ADDR);
827
         if(i%ALMOST_FULL_SIZE==ALMOST_FULL_SIZE-2)
828
         USB1.Write_Data(x,8,2,true);
829
         else if(i==Sdram_Length-2)
830
         USB1.Write_Data(x,8,2,true);
831
         else
832
         USB1.Write_Data(x,8,2,false);
833
         if(i%MAX_RXD_PACKET==MAX_RXD_PACKET-2)
834
         {
835
            // Sdram Seq. Read
836
            USB1.Read_Data(&a[DATA_Read],MAX_RXD_PACKET);
837
            DATA_Read+=MAX_RXD_PACKET;
838
            USB1.Reset_Device(0);
839
         }
840
         // Inc Address
841
         ADDR++;
842
      }
843
      // Wait a short time to get Data Form USB JTAG
844
      USB1.Write_Data(x,0,8,true);
845
      Sleep(100);
846
      Queue=USB1.Number_Of_Queue_Data();
847
      USB1.Read_Data(&a[DATA_Read],Queue);
848
      // Check File and Write File
849
      if(Select_File(SaveDialog2->FileName)==1)
850
      {
851
         file2=fopen("123.tmp","w+b");
852
         fwrite(a,sizeof(char),Sdram_Length,file2);
853
         fclose(file2);
854
         Sleep(100);
855
         File_HexToAsc("123.tmp",SaveDialog2->FileName,2);
856
      }
857
      else
858
      {
859
         file2=fopen(SaveDialog2->FileName.c_str(),"w+b");
860
         fwrite(a,sizeof(char),Sdram_Length,file2);
861
         fclose(file2);
862
      }
863
      Sleep(100);
864
      VirtualFree(a,0,MEM_RELEASE);
865
      // Delete Temp File
866
      if(FileExists("123.tmp"))
867
      DeleteFile("123.tmp");
868
      //-----------------------------------
869
      // T-Rex TXD Output Select to PS2
870
      x[0]=SETUP;
871
      x[1]=SET_REG;
872
      x[2]=0x12;
873
      x[3]=0x34;
874
      x[4]=0x56;
875
      x[5]=0x00;
876
      x[6]=PS2;
877
      x[7]=OUTSEL;
878
      USB1.Reset_Device(0);
879
      USB1.Write_Data(x,8,0,true);
880
      //-----------------------------------
881
      // Close Busy Panel
882
      Panel1->Visible=false;
883
      // Enable All Button
884
      Show_All_Button(true);
885
      Screen->Cursor=crArrow;
886
   }
887
}
888
//---------------------------------------------------------------------------
889
void __fastcall TForm1::TabSheet1Show(TObject *Sender)
890
{
891
   // ToDo  :  Enable PS2_REC Thread
892
   if(USB_is_Open)
893
   {
894
      USB1.Reset_Device(0);
895
      PS2_REC->Resume();
896
   }
897
}
898
//---------------------------------------------------------------------------
899
void __fastcall TForm1::Button13Click(TObject *Sender)
900
{
901
   // ToDo : Send External IO Value To FPGA
902
   char x[8];
903
   x[0]=WRITE;
904
   x[1]=EXTIO;
905
   x[2]=0x12;
906
   x[3]=0x34;
907
   x[4]=0x56;
908
   x[5]=0x00;
909
   x[6]=0x00;
910
   x[7]=NORMAL;
911
   USB1.Write_Data(x,8,0,true);
912
   // ToDo : Send Sdram Multiplexer To FPGA
913
   x[0]=SETUP;
914
   x[1]=SDRSEL;
915
   x[6]=char(Sdram_Multi->ItemIndex);
916
   x[7]=OUTSEL;
917
   USB1.Write_Data(x,8,0,true);
918
   // ToDo : Send Flash Multiplexer To FPGA
919
   x[0]=SETUP;
920
   x[1]=FLSEL;
921
   x[6]=char(Flash_Multi->ItemIndex);
922
   x[7]=OUTSEL;
923
   USB1.Write_Data(x,8,0,true);
924
   // ToDo : Send SRAM Multiplexer To FPGA
925
   x[0]=SETUP;
926
   x[1]=SRSEL;
927
   x[6]=char(Sram_Multi->ItemIndex);
928
   x[7]=OUTSEL;
929
   USB1.Write_Data(x,8,0,true);
930
}
931
//---------------------------------------------------------------------------
932
void __fastcall TForm1::Close_USB_Port()
933
{
934
   // ToDo : Close USB Port
935
   if(USB_is_Open)
936
   {
937
      PS2_REC->Terminate();
938
      USB1.Close_Device();
939
      Show_All_Button(false);
940
      CloseUSBPort1->Visible=false;
941
      USB_is_Open=false;
942
   }
943
}
944
//---------------------------------------------------------------------------
945
void __fastcall TForm1::CloseUSBPort1Click(TObject *Sender)
946
{
947
   Close_USB_Port();
948
}
949
//---------------------------------------------------------------------------
950
void __fastcall TForm1::Button14Click(TObject *Sender)
951
{
952
   // ToDo : Board Test
953
   Form4->Visible=true;
954
}
955
//---------------------------------------------------------------------------
956
void __fastcall TForm1::TabSheet2Show(TObject *Sender)
957
{
958
   // ToDo  :  Disable PS2_REC Thread
959
   if(USB_is_Open)
960
   {
961
      PS2_REC->Suspend();
962
      USB1.Reset_Device(0);
963
   }
964
}
965
//---------------------------------------------------------------------------
966
void __fastcall TForm1::TabSheet3Show(TObject *Sender)
967
{
968
   // ToDo  :  Disable PS2_REC Thread
969
   if(USB_is_Open)
970
   {
971
      PS2_REC->Suspend();
972
      USB1.Reset_Device(0);
973
   }
974
}
975
//---------------------------------------------------------------------------
976
void __fastcall TForm1::TabSheet4Show(TObject *Sender)
977
{
978
   // ToDo  :  Disable PS2_REC Thread
979
   if(USB_is_Open)
980
   {
981
      PS2_REC->Suspend();
982
      USB1.Reset_Device(0);
983
   }
984
}
985
//---------------------------------------------------------------------------
986
void __fastcall TForm1::TabSheet5Show(TObject *Sender)
987
{
988
   // ToDo  :  Disable PS2_REC Thread
989
   if(USB_is_Open)
990
   {
991
      PS2_REC->Suspend();
992
      USB1.Reset_Device(0);
993
   }
994
}
995
//---------------------------------------------------------------------------
996
void __fastcall TForm1::TabSheet6Show(TObject *Sender)
997
{
998
   // ToDo  :  Disable PS2_REC Thread
999
   if(USB_is_Open)
1000
   {
1001
      PS2_REC->Suspend();
1002
      USB1.Reset_Device(0);
1003
   }
1004
}
1005
//---------------------------------------------------------------------------
1006
void __fastcall TForm1::TabSheet7Show(TObject *Sender)
1007
{
1008
   // ToDo  :  Disable PS2_REC Thread
1009
   if(USB_is_Open)
1010
   {
1011
      PS2_REC->Suspend();
1012
      USB1.Reset_Device(0);
1013
   }
1014
}
1015
//---------------------------------------------------------------------------
1016
void __fastcall TForm1::Button16Click(TObject *Sender)
1017
{
1018
   // ToDo : SRAM Random Write
1019
   char x[8];
1020
   x[0]=WRITE;
1021
   x[1]=SRAM;
1022
   x[2]=char(HexToInt(oSR_ADDR->Text)>>16);
1023
   x[3]=char(HexToInt(oSR_ADDR->Text)>>8);
1024
   x[4]=char(HexToInt(oSR_ADDR->Text));
1025
   x[5]=char(HexToInt(oSR_DATA->Text)>>8);
1026
   x[6]=char(HexToInt(oSR_DATA->Text));
1027
   x[7]=NORMAL;
1028
   USB1.Reset_Device(0);
1029
   USB1.Write_Data(x,8,0,true);
1030
}
1031
//---------------------------------------------------------------------------
1032
void __fastcall TForm1::Button17Click(TObject *Sender)
1033
{
1034
   // ToDo : SRAM Random Read
1035
   char x[8];
1036
   //-----------------------------------
1037
   // T-Rex TXD Output Select to SRAM
1038
   x[0]=SETUP;
1039
   x[1]=SET_REG;
1040
   x[2]=0x12;
1041
   x[3]=0x34;
1042
   x[4]=0x56;
1043
   x[5]=0x00;
1044
   x[6]=SRAM;
1045
   x[7]=OUTSEL;
1046
   USB1.Reset_Device(0);
1047
   USB1.Write_Data(x,8,0,true);
1048
   Sleep(10);
1049
   //-----------------------------------
1050
   // Send SRAM Address To FPGA
1051
   x[0]=READ;
1052
   x[1]=SRAM;
1053
   x[2]=char(HexToInt(oSR_ADDR->Text)>>16);
1054
   x[3]=char(HexToInt(oSR_ADDR->Text)>>8);
1055
   x[4]=char(HexToInt(oSR_ADDR->Text));
1056
   x[5]=0x00;
1057
   x[6]=0x00;
1058
   x[7]=NORMAL;
1059
   USB1.Write_Data(x,8,2,true);
1060
   Sleep(10);
1061
   // SRAM Random Read
1062
   USB1.Read_Data(x,2);
1063
   // Show Get Value To Text Filed
1064
   iSR_DATA->Text=IntToHex((unsigned char)x[0]+(unsigned char)x[1]*256,4);
1065
   //-----------------------------------
1066
   // T-Rex TXD Output Select to PS2
1067
   x[0]=SETUP;
1068
   x[1]=SET_REG;
1069
   x[2]=0x12;
1070
   x[3]=0x34;
1071
   x[4]=0x56;
1072
   x[5]=0x00;
1073
   x[6]=PS2;
1074
   x[7]=OUTSEL;
1075
   USB1.Reset_Device(0);
1076
   USB1.Write_Data(x,8,0,true);
1077
   //-----------------------------------
1078
}
1079
//---------------------------------------------------------------------------
1080
void __fastcall TForm1::CheckBox5Click(TObject *Sender)
1081
{
1082
   // ToDo : if( Sram Write Size == File Length )
1083
   // Disable iSR_SWR_Length Text Field
1084
   if(CheckBox5->Checked)
1085
   iSR_SWR_Length->ReadOnly=true;
1086
   else
1087
   iSR_SWR_Length->ReadOnly=false;
1088
}
1089
//---------------------------------------------------------------------------
1090
void __fastcall TForm1::CheckBox6Click(TObject *Sender)
1091
{
1092
   // ToDo : if( Sram Read Size = Entrie Sram )
1093
   // Show iSR_SRD_Length = 512 KByte
1094
   // And Disable iSR_SRD_Length Text Field
1095
   if(CheckBox6->Checked)
1096
   {
1097
      iSR_SRD_Length->Text="80000";
1098
      iSR_SRD_Length->ReadOnly=true;
1099
   }
1100
   else
1101
   {
1102
      iSR_SRD_Length->Text="0";
1103
      iSR_SRD_Length->ReadOnly=false;
1104
   }
1105
}
1106
//---------------------------------------------------------------------------
1107
void __fastcall TForm1::Button15Click(TObject *Sender)
1108
{
1109
   // TODO : Write File To Sram
1110
   if(OpenDialog3->Execute())
1111
   {
1112
      char x[8];
1113
      int File_Length;
1114
      int ADDR=HexToInt(iSR_SWR_ADDR->Text);
1115
      Screen->Cursor=crHourGlass;
1116
      // Show Busy Panel
1117
      Panel1->Visible=true;
1118
      // Disable All Button
1119
      Show_All_Button(false);
1120
      // Send Sram Write Command To FPGA
1121
      x[0]=WRITE;
1122
      x[1]=SRAM;
1123
      x[7]=NORMAL;
1124
      USB1.Reset_Device(0);
1125
      // Check File Type and Open File
1126
      if(Select_File(OpenDialog3->FileName)==1)
1127
      {
1128
         File_AscToHex(OpenDialog3->FileName,"123.tmp",2);
1129
         Sleep(100);
1130
         file1=fopen("123.tmp","rb");
1131
      }
1132
      else
1133
      file1=fopen(OpenDialog3->FileName.c_str(),"rb");
1134
      // Set File ptr To File End
1135
      fseek(file1,0,SEEK_END);
1136
      // Set Transport Length
1137
      if(CheckBox5->Checked)
1138
      {
1139
         // Check File Length
1140
         File_Length=ftell(file1);
1141
         // Show File Length To Text Field
1142
         iSR_SWR_Length->Text=IntToHex(File_Length,6);
1143
      }
1144
      else
1145
      File_Length=HexToInt(iSR_SWR_Length->Text);
1146
      // Set ProgressBar
1147
      ProgressBar1->Max=File_Length;
1148
      // Set File ptr To File Start
1149
      fseek(file1,0,SEEK_SET);
1150
      // Read File Data To Temp Memory
1151
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,File_Length+1,MEM_COMMIT,PAGE_READWRITE);
1152
      fread(a,sizeof(char),File_Length,file1);
1153
      // Transport File To Sram
1154
      for(int i=0;i<File_Length;i+=2)
1155
      {
1156
         // Display Process %
1157
         Process_Label->Caption=IntToStr(i*100/File_Length)+" %";
1158
         ProgressBar1->Position=i;
1159
         Application->ProcessMessages();
1160
         // Send Data and Address
1161
         x[2]=char(ADDR>>16);
1162
         x[3]=char(ADDR>>8);
1163
         x[4]=char(ADDR);
1164
         x[5]=a[i+1];
1165
         x[6]=a[i];
1166
         if(i%MAX_TOTAL_PACKET==MAX_TOTAL_PACKET-2)
1167
         USB1.Reset_Device(0);
1168
         if(i<File_Length-2)
1169
         USB1.Write_Data(x,8,0,false);
1170
         else
1171
         USB1.Write_Data(x,8,0,true);
1172
         // Inc Address
1173
         ADDR++;
1174
      }
1175
      USB1.Reset_Device(0);
1176
      // Close File
1177
      fclose(file1);
1178
      // Close Busy Panel
1179
      Panel1->Visible=false;
1180
      // Enable All Button
1181
      Show_All_Button(true);
1182
      // Free Temp Memory
1183
      VirtualFree(a,0,MEM_RELEASE);
1184
      Screen->Cursor=crArrow;
1185
   }
1186
}
1187
//---------------------------------------------------------------------------
1188
void __fastcall TForm1::Button18Click(TObject *Sender)
1189
{
1190
   // ToDo : Load Sram Content to File
1191
   if(SaveDialog3->Execute())
1192
   {
1193
      char x[8];
1194
      int Sram_Length;
1195
      int DATA_Read=0;
1196
      int Queue;
1197
      int ADDR=HexToInt(iSR_SRD_ADDR->Text);
1198
      Screen->Cursor=crHourGlass;
1199
      // Show Busy Panel
1200
      Panel1->Visible=true;
1201
      // Disable All Button
1202
      Show_All_Button(false);
1203
      //-----------------------------------
1204
      // T-Rex TXD Output Select to SRAM
1205
      x[0]=SETUP;
1206
      x[1]=SET_REG;
1207
      x[2]=0x12;
1208
      x[3]=0x34;
1209
      x[4]=0x56;
1210
      x[5]=0x00;
1211
      x[6]=SRAM;;
1212
      x[7]=OUTSEL;
1213
      USB1.Reset_Device(0);
1214
      USB1.Write_Data(x,8,0,true);
1215
      Sleep(10);
1216
      //-----------------------------------
1217
      // Send Sram Read Command To FPGA
1218
      x[0]=READ;
1219
      x[1]=SRAM;
1220
      x[5]=0x00;
1221
      x[6]=0x00;
1222
      x[7]=NORMAL;
1223
      // Set Transport Length
1224
      if(CheckBox6->Checked)
1225
      {
1226
         // Set Transport Length = Sram Size = 512KByte
1227
         Sram_Length=524288;
1228
         // Show Transport Length To Text Field
1229
         iSR_SRD_Length->Text=IntToHex(Sram_Length,6);
1230
      }
1231
      else
1232
      Sram_Length=HexToInt(iSR_SRD_Length->Text);
1233
      unsigned char* a=(unsigned char*)VirtualAlloc(NULL,Sram_Length+MAX_RXD_PACKET,MEM_COMMIT,PAGE_READWRITE);
1234
      // Set ProgressBar
1235
      ProgressBar1->Max=Sram_Length;
1236
      // Transport Sram Data To File
1237
      for(int i=0;i<Sram_Length;i+=2)
1238
      {
1239
         // Display Process %
1240
         Process_Label->Caption=IntToStr(i*100/Sram_Length)+" %";
1241
         ProgressBar1->Position=i;
1242
         Application->ProcessMessages();
1243
         // Send Address
1244
         x[2]=char(ADDR>>16);
1245
         x[3]=char(ADDR>>8);
1246
         x[4]=char(ADDR);
1247
         if(i%ALMOST_FULL_SIZE==ALMOST_FULL_SIZE-2)
1248
         USB1.Write_Data(x,8,2,true);
1249
         else if(i==Sram_Length-2)
1250
         USB1.Write_Data(x,8,2,true);
1251
         else
1252
         USB1.Write_Data(x,8,2,false);
1253
         if(i%MAX_RXD_PACKET==MAX_RXD_PACKET-2)
1254
         {
1255
            // Sram Seq. Read
1256
            USB1.Read_Data(&a[DATA_Read],MAX_RXD_PACKET);
1257
            DATA_Read+=MAX_RXD_PACKET;
1258
            USB1.Reset_Device(0);
1259
         }
1260
         // Inc Address
1261
         ADDR++;
1262
      }
1263
      // Wait a short time to get Data Form USB JTAG
1264
      USB1.Write_Data(x,0,8,true);
1265
      Sleep(100);
1266
      Queue=USB1.Number_Of_Queue_Data();
1267
      USB1.Read_Data(&a[DATA_Read],Queue);
1268
      // Check File and Write File
1269
      if(Select_File(SaveDialog3->FileName)==1)
1270
      {
1271
         file2=fopen("123.tmp","w+b");
1272
         fwrite(a,sizeof(char),Sram_Length,file2);
1273
         fclose(file2);
1274
         Sleep(100);
1275
         File_HexToAsc("123.tmp",SaveDialog3->FileName,2);
1276
      }
1277
      else
1278
      {
1279
         file2=fopen(SaveDialog3->FileName.c_str(),"w+b");
1280
         fwrite(a,sizeof(char),Sram_Length,file2);
1281
         fclose(file2);
1282
      }
1283
      Sleep(100);
1284
      VirtualFree(a,0,MEM_RELEASE);
1285
      // Delete Temp File
1286
      if(FileExists("123.tmp"))
1287
      DeleteFile("123.tmp");
1288
      //-----------------------------------
1289
      // T-Rex TXD Output Select to PS2
1290
      x[0]=SETUP;
1291
      x[1]=SET_REG;
1292
      x[2]=0x12;
1293
      x[3]=0x34;
1294
      x[4]=0x56;
1295
      x[5]=0x00;
1296
      x[6]=PS2;
1297
      x[7]=OUTSEL;
1298
      USB1.Reset_Device(0);
1299
      USB1.Write_Data(x,8,0,true);
1300
      //-----------------------------------
1301
      // Close Busy Panel
1302
      Panel1->Visible=false;
1303
      // Enable All Button
1304
      Show_All_Button(true);
1305
      Screen->Cursor=crArrow;
1306
   }
1307
}
1308
//---------------------------------------------------------------------------
1309
void __fastcall TForm1::ScrollBar2Change(TObject *Sender)
1310
{
1311
   Cur_Y->Caption=IntToStr(ScrollBar2->Position);
1312
   // ToDo : Send VGA Value To FPGA
1313
   char x[8];
1314
   x[0]=WRITE;
1315
   x[1]=VGA;
1316
   x[2]=0x00;
1317
   x[3]=0x00;
1318
   x[7]=DISPLAY;
1319
   PS2_REC->Suspend();
1320
   USB1.Reset_Device(0);
1321
   x[4]=0x01;
1322
   x[5]=char(ScrollBar1->Position/256);
1323
   x[6]=char(ScrollBar1->Position%256);
1324
   USB1.Write_Data(x,8,0,true);
1325
   x[4]=0x02;
1326
   x[5]=char(ScrollBar2->Position/256);
1327
   x[6]=char(ScrollBar2->Position%256);
1328
   USB1.Write_Data(x,8,0,true);
1329
   PS2_REC->Resume();
1330
}
1331
//---------------------------------------------------------------------------
1332
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
1333
{
1334
   Cur_X->Caption=IntToStr(ScrollBar1->Position);
1335
   // ToDo : Send VGA Value To FPGA
1336
   char x[8];
1337
   x[0]=WRITE;
1338
   x[1]=VGA;
1339
   x[2]=0x00;
1340
   x[3]=0x00;
1341
   x[7]=DISPLAY;
1342
   PS2_REC->Suspend();
1343
   USB1.Reset_Device(0);
1344
   x[4]=0x01;
1345
   x[5]=char(ScrollBar1->Position/256);
1346
   x[6]=char(ScrollBar1->Position%256);
1347
   USB1.Write_Data(x,8,0,true);
1348
   x[4]=0x02;
1349
   x[5]=char(ScrollBar2->Position/256);
1350
   x[6]=char(ScrollBar2->Position%256);
1351
   USB1.Write_Data(x,8,0,true);
1352
   PS2_REC->Resume();
1353
}
1354
//---------------------------------------------------------------------------
1355
void __fastcall TForm1::Default_IMGClick(TObject *Sender)
1356
{
1357
   // ToDo : Send VGA Value To FPGA
1358
   char x[8];
1359
   x[0]=WRITE;
1360
   x[1]=VGA;
1361
   x[2]=0x00;
1362
   x[3]=0x00;
1363
   x[4]=0x00;
1364
   x[5]=0x00;
1365
   x[6]=(char(!Default_IMG->Checked)<<1)+char(Cursor_EN->Checked);
1366
   x[7]=DISPLAY;
1367
   PS2_REC->Suspend();
1368
   USB1.Reset_Device(0);
1369
   USB1.Write_Data(x,8,0,true);
1370
   PS2_REC->Resume();
1371
}
1372
//---------------------------------------------------------------------------
1373
void __fastcall TForm1::Cursor_ENClick(TObject *Sender)
1374
{
1375
   // ToDo : Send VGA Value To FPGA
1376
   char x[8];
1377
   x[0]=WRITE;
1378
   x[1]=VGA;
1379
   x[2]=0x00;
1380
   x[3]=0x00;
1381
   x[4]=0x00;
1382
   x[5]=0x00;
1383
   x[6]=(char(!Default_IMG->Checked)<<1)+char(Cursor_EN->Checked);
1384
   x[7]=DISPLAY;
1385
   PS2_REC->Suspend();
1386
   USB1.Reset_Device(0);
1387
   USB1.Write_Data(x,8,0,true);
1388
   x[4]=0x03;
1389
   x[5]=0x00;
1390
   x[6]=0x00;
1391
   USB1.Write_Data(x,8,0,true);
1392
   x[4]=0x04;
1393
   x[5]=char(1023/256);
1394
   x[6]=char(1023%256);
1395
   USB1.Write_Data(x,8,0,true);
1396
   x[4]=0x05;
1397
   x[5]=0x00;
1398
   x[6]=0x00;
1399
   USB1.Write_Data(x,8,0,true);
1400
   PS2_REC->Resume();
1401
}
1402
//---------------------------------------------------------------------------
1403
int __fastcall TForm1::Select_File(String File_Name)
1404
{
1405
   int i;
1406
   int File_Type;
1407
   String Sub_Name;
1408
   for(i=File_Name.Length()-3;i<=File_Name.Length();i++)
1409
   Sub_Name=Sub_Name+File_Name[i];
1410
   if(Sub_Name==".hex" || Sub_Name==".HEX")
1411
   File_Type=1;
1412
   else
1413
   File_Type=0;
1414
   return File_Type;
1415
}
1416
//---------------------------------------------------------------------------
1417
int __fastcall TForm1::AscToHex(unsigned char a)
1418
{
1419
   int Out_Hex;
1420
   if(a>=0x30 && a<=0x39)
1421
   Out_Hex=a-0x30;
1422
   else if(a>=0x41 && a<=0x46)
1423
   Out_Hex=a-0x40+9;
1424
   else if(a>=0x61 && a<=0x66)
1425
   Out_Hex=a-0x60+9;
1426
   else if( (a==0x20) || (a==0x09) || (a==0x0A) || (a==0x0D) )
1427
   Out_Hex=100;
1428
   else
1429
   Out_Hex=200;
1430
   return Out_Hex;
1431
}
1432
//---------------------------------------------------------------------------
1433
int __fastcall TForm1::File_AscToHex(String File_Input,String File_Output,int File_Type)
1434
{
1435
   unsigned int File_Length;
1436
   unsigned int tmp=0;
1437
   unsigned int i,j,k;
1438
   unsigned char *hex08;
1439
   unsigned short *hex16;
1440
   unsigned int *hex32;
1441
 
1442
   file1=fopen(File_Input.c_str(),"rb");
1443
   file2=fopen(File_Output.c_str(),"w+b");
1444
   fseek(file1,0,SEEK_END);
1445
   File_Length=ftell(file1);
1446
   fseek(file1,0,SEEK_SET);
1447
   unsigned char* a=(unsigned char*)VirtualAlloc(NULL,File_Length+1,MEM_COMMIT,PAGE_READWRITE);
1448
   hex08=a;
1449
   hex16=(unsigned short*)a;
1450
   hex32=(unsigned int*)a;
1451
   fread(a,sizeof(char),File_Length,file1);
1452
   j=0;
1453
   k=0;
1454
   for(i=0;i<File_Length;i++)
1455
   {
1456
      if(AscToHex(a[i])==200 && File_Type!=0)
1457
      {
1458
         ShowMessage("Invalid Character Detected!!");
1459
         fclose(file1);
1460
         VirtualFree(a,0,MEM_RELEASE);
1461
         return 0;
1462
      }
1463
      else if(AscToHex(a[i])==100)
1464
      {
1465
         /*
1466
         if(k!=0)
1467
         {
1468
            if(File_Type==1)
1469
            hex08[j]=tmp;
1470
            else if(File_Type==2)
1471
            hex16[j]=tmp;
1472
            else if(File_Type==3)
1473
            hex32[j]=tmp;
1474
            tmp=0;
1475
            j++;
1476
         }
1477
         k=0;
1478
         */
1479
      }
1480
      else
1481
      {
1482
         tmp=(tmp<<4)+AscToHex(a[i]);
1483
         if(k==1 && File_Type==1)
1484
         {
1485
            hex08[j]=tmp;
1486
            tmp=0;
1487
            j++;
1488
            k=0;
1489
         }
1490
         else if(k==3 && File_Type==2)
1491
         {
1492
            hex16[j]=tmp;
1493
            tmp=0;
1494
            j++;
1495
            k=0;
1496
         }
1497
         else if(k==7 && File_Type==3)
1498
         {
1499
            hex32[j]=tmp;
1500
            tmp=0;
1501
            j++;
1502
            k=0;
1503
         }
1504
         else
1505
         k++;
1506
      }
1507
   }
1508
   if(k!=0)
1509
   {
1510
      if(File_Type==1)
1511
      hex08[j]=tmp;
1512
      else if(File_Type==2)
1513
      hex16[j]=tmp;
1514
      else if(File_Type==3)
1515
      hex32[j]=tmp;
1516
      tmp=0;
1517
      j++;
1518
      k=0;
1519
   }
1520
   if(File_Type==1)
1521
   fwrite(hex08,sizeof(char),j,file2);
1522
   else if(File_Type==2)
1523
   fwrite(hex16,sizeof(short),j,file2);
1524
   else if(File_Type==3)
1525
   fwrite(hex32,sizeof(int),j,file2);
1526
   fclose(file1);
1527
   fclose(file2);
1528
   VirtualFree(a,0,MEM_RELEASE);
1529
   return 1;
1530
}
1531
//---------------------------------------------------------------------------
1532
int __fastcall TForm1::File_HexToAsc(String File_Input,String File_Output,int File_Type)
1533
{
1534
   unsigned int File_Length;
1535
   unsigned int i;
1536
   String   tmp;
1537
 
1538
   file1=fopen(File_Input.c_str(),"rb");
1539
   file2=fopen(File_Output.c_str(),"w+");
1540
   fseek(file1,0,SEEK_END);
1541
   File_Length=ftell(file1);
1542
   fseek(file1,0,SEEK_SET);
1543
   unsigned char* a=(unsigned char*)VirtualAlloc(NULL,File_Length+16,MEM_COMMIT,PAGE_READWRITE);
1544
   fread(a,sizeof(char),File_Length,file1);
1545
   i=0;
1546
   while(i<File_Length)
1547
   {
1548
      if(File_Type==1)
1549
      {
1550
         tmp=IntToHex(a[i],2)+"\n";
1551
         fputs(tmp.c_str(),file2);
1552
         i++;
1553
      }
1554
      else if(File_Type==2)
1555
      {
1556
         tmp=IntToHex((a[i+1]<<8)+a[i],4)+"\n";
1557
         fputs(tmp.c_str(),file2);
1558
         i+=2;
1559
      }
1560
      else if(File_Type==3)
1561
      {
1562
         tmp=IntToHex((a[i+3]<<24)+(a[i+2]<<16)+(a[i+1]<<8)+a[i],8)+"\n";
1563
         fputs(tmp.c_str(),file2);
1564
         i+=4;
1565
      }
1566
   }
1567
   fclose(file1);
1568
   fclose(file2);
1569
   VirtualFree(a,0,MEM_RELEASE);
1570
   return 1;
1571
}
1572
//---------------------------------------------------------------------------
1573
void __fastcall TForm1::Button1Click(TObject *Sender)
1574
{
1575
   // ToDo : Send 7-SEG Value To FPGA
1576
   char x[8];
1577
   x[0]=WRITE;
1578
   x[1]=SEG7;
1579
   x[2]=0x00;
1580
   x[3]=0x00;
1581
   x[4]=0x00;
1582
   x[5]=(DIG_4->ItemIndex<<4)+DIG_3->ItemIndex;
1583
   x[6]=(DIG_2->ItemIndex<<4)+DIG_1->ItemIndex;
1584
   x[7]=DISPLAY;
1585
   PS2_REC->Suspend();
1586
   USB1.Reset_Device(0);
1587
   USB1.Write_Data(x,8,0,true);
1588
   PS2_REC->Resume();
1589
}
1590
//---------------------------------------------------------------------------
1591
 
1592
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.