-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathShell_back.cpp
2450 lines (2277 loc) · 64.6 KB
/
Shell_back.cpp
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Donald Peeke-Vout
// bg.cpp
// My first adventure with tile backgrounds! Yay! Looks like a bad
// case of parallax scrolling to me...
#include "stdlib.h"
#include "stdio.h"
#include "stdarg.h"
#include "string.h"
#include "md5.h"
#include "keypad.h"
#include "BGfunc.h"
#include "shell.h"
#include "viewtext.h"
#include "viewPic.h"
#include "screenmode.h"
#include "cmddefine.h"
#include "global.h"
#include "inram.h"
#include "hard.h"
#include "fat16.h"
#include "savermanage.h"
#include "lang.h"
#include "nandop.h"
#include "SDOpera.h"
extern res_struct res;
char CurrentDisk[32]; //当前所在磁盘
char CurrentPath[maxNameLen*2]; //当前路径
char CurrentFileName[maxNameLen]; //当前选择文件名
u16 CurrentIndexSelect ; //所选文件的索引
u16 CurrentIndexView ; //本页面文件开始的索引
FM_NOR_FS glNorFS ; //保留其信息在软复位时使用
u32 glTotalsize ;
u32 glCursize ;
u16 glhard ;
u16 glLoadsaver ;
u16 glExecFileTxt ;
extern u32 gl_norsize;
extern u32 gl_currentpage ;
extern u32 gl_norOffset;
extern EZ4_CARTTYPE g_EZ4CardType;
extern int gl_norgamecounter;
//******************************************************************************
//**** 返回一个路径中的斜杠数目
u16 getDirLayerNum(char* path)
{
u16 num=0,i;
for(i=0;i<strlen(path);i++)
{
if(path[i]=='\\')
num++;
}
return num;
}
//******************************************************************************
//**** 返回一个路径中的文件名
void getDirFileName(char* path, char* filename)
{
int i=0;
u16 len;
len=(u16)strlen(path);
for(i=len-2;i>=0;i--)
{
if(path[i]=='\\')
break;
}
strcpy(filename,path+i+1);
return;
}
//******************************************************************************
//**** 返回当前目录中ROM文件总数
u16 GetDirFileCount(char *path)
{
u8 *fsBase,*fsline;
char fname[MAX_PATH];
fsBase = GBAPAKLINE; //文件系统起始地址
RomFile *rf;
u16 count=0;
fsline=fsBase;
rf=(RomFile*)fsline;
while(rf->FileName[0]!=0)//未到文件末尾
{
u16 m,n;
rf=(RomFile*)fsline;
fsline=fsline + HEADSIZE + rf->size + rf->padsize;
m = getDirLayerNum(rf->FileName);
n = getDirLayerNum(path);
getDirFileName(rf->FileName,fname);
if((m==1)&&(n==1))
{
if(fname[0]!='.') //如果目录文件名非 .* 隐藏模式
count++;
continue;
}
if((n>1)&&(m == n))
{
if(memcmp(rf->FileName,path,strlen(path))==0)
if(fname[0]!='.') //如果目录文件名非 .* 隐藏模式
count++;
continue;
}
}
return count;
}
//******************************************************************************
//**** 根据文件索引号,在指定DIR的ROM中检索某文件,返回该文件地址
u8* GetCurRomFile(char *path,u16 index,u8 isgoon)
{
static u8* lastpRom=NULL;
u8 *fsBase,*fsline;
char fname[MAX_PATH];
fsBase = GBAPAKLINE; //文件系统起始地址
RomFile *rf;
u16 count=0;
u8 seek1stGoon=0;
if((isgoon!=0)&&(lastpRom==NULL))//连续模式的第一次循环
{
seek1stGoon=1;
}
if(lastpRom==NULL)
lastpRom=fsBase;
if(isgoon==0)//非连续读取形式
lastpRom=fsBase;
fsline=lastpRom;
rf=(RomFile*)fsline;
while(rf->FileName[0]!=0)//未到文件末尾
{
u16 m,n;
n = getDirLayerNum(path);
m = getDirLayerNum(rf->FileName);
getDirFileName(rf->FileName,fname);
if((m==1)&&(n==1))
{
if(((isgoon==0)&&(count==index)) || (seek1stGoon==0)&&(isgoon==1) ||(seek1stGoon==1)&&(count==index) )
{
if(isgoon==1)//连续读取形式
lastpRom=fsline+HEADSIZE + rf->size + rf->padsize;
else
lastpRom=NULL;
if(fname[0]!='.') //如果目录文件名非 .* 隐藏模式
return fsline;
}
if(fname[0]!='.') //如果目录文件名非 .* 隐藏模式
count++;
}
else if((n>1)&&(m == n))
{
if(memcmp(rf->FileName,path,strlen(path))==0)
{
if(((isgoon==0)&&(count==index)) || (seek1stGoon==0)&&(isgoon==1) ||(seek1stGoon==1)&&(count==index) )
{
if(isgoon==1)//连续读取形式
lastpRom=fsline+HEADSIZE + rf->size + rf->padsize;
else
lastpRom=NULL;
if(fname[0]!='.')
return fsline;
}
if(fname[0]!='.')
count++;
}
}
fsline += HEADSIZE + rf->size + rf->padsize;
rf=(RomFile*)fsline;
}
if(isgoon==1)//连续读取形式
lastpRom=fsline+HEADSIZE + rf->size + rf->padsize;
else
lastpRom=NULL;
//"系统没有找到任何文件!
//dbgPrint("未找到: %s, i=%d",path,index);
//exit(1);
return NULL;
}
//******************************************************************************
//**** 根据文件名和路径,确定并返回该文件指针
u8* GetRomFileByName(char *path, char *Name)
{
u8 *fsBase,*fsline;
fsBase = GBAPAKLINE; //文件系统起始地址
RomFile *rf;
char tmpbuf[MAX_PATH];
fsline=fsBase;
sprintf(tmpbuf,"%s%s",path,Name);
rf=(RomFile*)fsline;
while(rf->FileName[0]!=0)//未到文件末尾
{
if(strcmp(tmpbuf,rf->FileName)==0)
return fsline;
fsline += HEADSIZE + rf->size + rf->padsize;
rf=(RomFile*)fsline;
}
//dbgPrint("未找到:%s",Name);
//exit(1);
return NULL;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//******************************************************************************
//**** EZ3磁盘管理器主函数 ** 管理磁盘目录下的文件。
int runEz3DiskShell(void)
{
u32 shift =0 , orgtt = 123455, dwName = 0 ;
char msg[maxNameLen],path[maxNameLen*3];
u8 execgo ;
u8 bcreate=1,bchgpage=1,bscroll=0,bchg=0,needfade=0;
u16 shell_scr_totalH=0,shell_scr_H=0,shell_scr_Y=0;
int fi=0,viewfi=0,newfi=0,rfcount=0;
FM_NOR_FS *pNorFS = (FM_NOR_FS *)_UnusedVram ;
FM_NOR_FS tmpNorFS ;
FM_MD_FILE fmf;
int get,ret;
_stat stat;
register int i ;
u16 count=0;
int oldFi,newFi;
u32 ti = 0 , holdt = 0;
keypad keys;
int ctDir=0,ctFile=0 ;
u32 j;
u8* pReadCache = (u8*)_ramFatBlockCache ;
//比较当前保存的目录,以确定搜索地址
//sprintf(CurrentDisk,"EZ-Disk");
if(strcmp(CurrentDisk,"EZ-Disk"))
{
//首先得到文件列表.
rfcount = GetFileListFromNor() ;
gl_norgamecounter = rfcount-1;
//设定路径
sprintf(CurrentDisk,"Game Disk");
CurrentPath[0] = 0 ;
if(CurrentFileName[0]==0)
{
//计算数据显示
CurrentIndexSelect = 0 ;
CurrentIndexView = 0;
}
}
else
{//nand flash 的文件
FM_NOR_FS *pFile ;
if(CurrentPath[0]==0) //根目录,或者刚刚进入Nand
{
CurrentIndexSelect = 0 ;
CurrentIndexView = 0;
sprintf(CurrentPath,"\\");
}
get = fat_init(0); //不能使用erternal ram
if(get)
{
CreateWindow(gl_warning,gl_faterror,60,40,1);
while(1){
sleep(15); keys.update();
if(keys.press(KEY_A)||keys.release(KEY_B)) break;
}
sprintf(CurrentDisk,"Game Disk");
CurrentPath[0] = 0 ;
return PROC_ENTERDISKSHELL;//返回上级目录
}
count = 0 ;
ctDir = 0 ;
ctFile = 0;
pFile = (FM_NOR_FS*)_UnusedEram;
sprintf(path,"%s",CurrentPath);
get = fat_getfirst(path,msg);
while(!get)
{
if(!strcmp(CurrentPath,"\\"))
sprintf(path,"%s%s",CurrentPath,msg);
else
sprintf(path,"%s\\%s",CurrentPath,msg);
ret = fat_get_stat(path,&stat);
strcpy(tmpNorFS.filename,msg);
//sprintf(tmpNorFS.filename,"%s",msg);
tmpNorFS.rompage = 0 ;
tmpNorFS.saversize = 0 ;
if(ret)
{
tmpNorFS.filesize = 0;
tmpNorFS.savertype = 0x5AA5 ;
DmaCopy(3,&tmpNorFS,&pNorFS[ctDir],sizeof(FM_NOR_FS),32);
ctDir++;
}
else
{
tmpNorFS.filesize = stat.FileSize ;
if((stat.Attr == ATTR_DIRECTORY))
{
tmpNorFS.savertype = 0x5AA5 ;
DmaCopy(3,&tmpNorFS,&pNorFS[ctDir],sizeof(FM_NOR_FS),32);
ctDir++;
}
else
{
tmpNorFS.savertype = 0xA55A ;
DmaCopy(3,&tmpNorFS,&pFile[ctFile],sizeof(FM_NOR_FS),32);
ctFile++;
}
}
count ++ ;
get = fat_getnext(msg);
if(count>=336)
break;
}
//排序,找到的文件数据需要排序,仅仅文件排序
if(ctFile>1)
{
for(ret=0;ret<ctFile-1;ret++)
{
for(i=0;i<ctFile-ret-1;i++)
{
get = strcmp(pFile[i].filename,pFile[i+1].filename) ;
if(get>0)
{
DmaCopy(3,&pFile[i+1],&tmpNorFS,sizeof(FM_NOR_FS),32);
DmaCopy(3,&pFile[i],&pFile[i+1],sizeof(FM_NOR_FS),32);
DmaCopy(3,&tmpNorFS,&pFile[i],sizeof(FM_NOR_FS),32);
}
}
}
}
// 需要整理数据,文件夹放在前面,文件放在后面
if(ctFile)
DmaCopy(3,(u8*)pFile,(u8*)&pNorFS[ctDir],sizeof(FM_NOR_FS)*ctFile,32);
rfcount = count ; //count 至少为1
}
while(1)
{
ti++;
VBlankIntrWait(); // Complete V Blank interrupt
shift ++ ;
if(shift >16)
{ //循环显示
int namelen = strlen(fmf.sect[newFi].filename);
if(namelen >( FM_F_NAME_W/6 + 8) )
{
u32 tt = ((shift-16)/8)% namelen;
if(orgtt!= tt )
{
orgtt = tt ;
sprintf(msg,"%s ",fmf.sect[newFi].filename + tt);
strncpy(msg+strlen(msg) ,fmf.sect[newFi].filename , 256 - strlen(msg) );
msg[255] = 0 ;
if(fmf.sect[newFi].filename[tt] > 0x80)
{
if(dwName)
{
msg[0] = 0x20 ;
dwName = 0 ;
}
else
dwName = 1 ;
}
else
dwName = 0;
Clear(FM_F_NAME_X,FM_TITLE_H+1+newFi*FM_ROW_H,220-FM_F_NAME_X,FM_ROW_H-2,RGB(3,20,20),1);
DrawHZText12(msg,FM_F_NAME_W/6 + 8, FM_F_NAME_X, FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_WHITE,1);
}
}
}
//chsh初始化
count = 0 ;
if(bcreate)//////////////////////////////////////////////////////////////
{
newfi = CurrentIndexSelect ;
viewfi = CurrentIndexView ;
//头部信息
if(!strcmp(CurrentPath,"\\"))
sprintf(path,"%s%s",CurrentPath,CurrentFileName);
else
sprintf(path,"%s\\%s",CurrentPath,CurrentFileName);
sprintf(msg,"%s",path);
if(strlen(msg)>29) //每行最多显示29个字母
{
msg[29]=0; msg[28]='.'; msg[27]='.'; msg[26]='.';
}
//清空结构体数组
for(i=0;i<FM_MSN;i++)
{
fmf.sectnum=0;
strcpy(fmf.sect[i].filename,"\0");
fmf.sect[i].isDir=0;
fmf.sect[i].filesize=0;
}
//逐条设置文件信息
if(strcmp(CurrentDisk,"EZ-Disk"))
{//nor
for(i=viewfi;i<viewfi+FM_MSN;i++)
{
if(i>rfcount-1)
break;
DmaCopy(3,&pNorFS[i],&tmpNorFS,sizeof(FM_NOR_FS),32);
sprintf(fmf.sect[i-viewfi].filename,"%s",tmpNorFS.filename);
fmf.sect[i-viewfi].filesize=tmpNorFS.filesize ;
if(i==0)
fmf.sect[i-viewfi].isDir = 1;
else
fmf.sect[i-viewfi].isDir = 0;
count++;
}
}
else
{//nand flash
for(i=viewfi;i<viewfi+FM_MSN;i++)
{
if(i>rfcount-1)
break;
DmaCopy(3,&pNorFS[i],&tmpNorFS,sizeof(FM_NOR_FS),32);
sprintf(fmf.sect[i-viewfi].filename,"%s",tmpNorFS.filename);
fmf.sect[i-viewfi].filesize=tmpNorFS.filesize ;
if(tmpNorFS.savertype==0x5AA5)
fmf.sect[i-viewfi].isDir = 1;
else if(tmpNorFS.savertype==0xA55A)
fmf.sect[i-viewfi].isDir = 0;
count++;
}
}
fmf.sectnum=count;
//计算拉条数据
shell_scr_totalH = (160-FM_TITLE_H-FM_FOOT_H-3)*100;
if(rfcount>FM_MSN)
shell_scr_H=shell_scr_totalH*FM_MSN/rfcount;
else
shell_scr_H=shell_scr_totalH;
if(rfcount/FM_MSN == newfi/FM_MSN)
shell_scr_Y=(FM_TITLE_H+1)*100 + shell_scr_totalH*viewfi/rfcount + 200;
else
shell_scr_Y=(FM_TITLE_H+1)*100 + shell_scr_totalH*viewfi/rfcount;
bcreate = 0;
bchgpage = 1;
//DrawBG((u16*)res.res_TXTBG,0);
}
if(bchgpage)///////////////////换页//////////////////////////////////////
{
//刷新浏览器头
DrawPic(res.res_FILEBGHEAD,0,0,240,FM_TITLE_H,0,0,0);
//DrawHZText12(msg,0, 60,3, FM_CL_BG,0);
//画出背景图案
char FileStr[128];
u8 num=(fmf.sectnum>FM_MSN)?FM_MSN:fmf.sectnum;
for(u8 i=0;i<FM_MSN;i++)
{
DrawPic((u16*)res.res_FILEBG+((viewfi+i)%FM_MSN)*FM_ROW_H*240,0,FM_TITLE_H+(i)*FM_ROW_H,240,FM_ROW_H,0,0,0);
}
//DrawPic(res.res_FILEBG,0,FM_TITLE_H,240,(FM_ROW_H<<3),0,0,0);
//画icon,以及文件大小和文件名
for(u8 i=0;i<num;i++)
{
DrawHZText12(fmf.sect[i].filename,FM_F_NAME_W/6, FM_F_NAME_X, FM_TITLE_H+2+i*FM_ROW_H, FM_CL_BLACK,0);
if(fmf.sect[i].isDir)
DrawFileIcon(3, FM_TITLE_H+2+i*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+i*FM_ROW_H,GetFileType(fmf.sect[i].filename),0);
if(fmf.sect[i].isDir==0)
{
if(fmf.sect[i].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[i].filesize/1024)/1000,(fmf.sect[i].filesize/1024)%1000);
else if(fmf.sect[i].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[i].filesize/1024);
else if(fmf.sect[i].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[i].filesize/1000,fmf.sect[i].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[i].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr), FM_TITLE_H+2+i*FM_ROW_H, FM_CL_BLACK,0);
}
}
//刷新选中文件
oldFi = fi-viewfi;
newFi = newfi - viewfi;
////高亮显示选中文件
//u16 w = strlen(fmf.sect[newFi].filename)*6+2;
if(fmf.sect[newFi].isDir)
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,GetFileType(fmf.sect[newFi].filename),0);
Clear(FM_F_NAME_X,FM_TITLE_H+1+newFi*FM_ROW_H,220-FM_F_NAME_X,FM_ROW_H-2,RGB(3,20,20),0);
DrawHZText12(fmf.sect[newFi].filename,FM_F_NAME_W/6+8, FM_F_NAME_X,FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BG,0);
/*
if(fmf.sect[newFi].isDir==0)
{
if(fmf.sect[newFi].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[newFi].filesize/1024)/1000,(fmf.sect[newFi].filesize/1024)%1000);
else if(fmf.sect[newFi].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[newFi].filesize/1024);
else if(fmf.sect[newFi].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[newFi].filesize/1000,fmf.sect[newFi].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[newFi].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr),FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BLACK,0);
}
*/
syncVVram();
bchgpage = 0;
}
if(bscroll)//////////////////////////////////////////////////////////////
{
//刷新文件区
char FileStr[128];
u16 count = 0;
oldFi = fi-viewfi;
newFi = newfi - viewfi;
if(newFi == 0)//向上选择,屏幕下滚
{
for(u8 ii=FM_MSN-1;ii>0;ii--)
{
moveScreen(FM_TITLE_H + FM_ROW_H*(ii-1),FM_TITLE_H + FM_ROW_H*(ii),FM_ROW_H,0);
}
DrawPic((u16*)res.res_FILEBG+((viewfi)%FM_MSN)*FM_ROW_H*240,0,FM_TITLE_H+newFi*FM_ROW_H,240,FM_ROW_H,0,0,0);
}
else //向下选择,屏幕上滚
{
for(u8 ii=1;ii<FM_MSN;ii++)
{
moveScreen(FM_TITLE_H + FM_ROW_H*(ii),FM_TITLE_H + FM_ROW_H*(ii-1),FM_ROW_H,0);
}
DrawPic((u16*)res.res_FILEBG+((fi+1)%FM_MSN)*FM_ROW_H*240,0,FM_TITLE_H+newFi*FM_ROW_H,240,FM_ROW_H,0,0,0);
}
//逐条设置文件信息
for(u8 i=0;i<fmf.sectnum;i++)
{
if(i+viewfi>rfcount-1)
continue;
DmaCopy(3,&pNorFS[i+viewfi],&tmpNorFS,sizeof(FM_NOR_FS),32);
sprintf(fmf.sect[i%FM_MSN].filename,"%s",tmpNorFS.filename);
fmf.sect[i%FM_MSN].filesize=tmpNorFS.filesize ;
fmf.sect[i%FM_MSN].isDir = 0;
}
//取消高亮文件
u16 w = strlen(fmf.sect[oldFi].filename)*6+2;
DrawPic((u16*)res.res_FILEBG+((fi)%FM_MSN)*FM_ROW_H*240,0,FM_TITLE_H+FM_ROW_H*oldFi,240,FM_ROW_H,0,0,0);
if(fmf.sect[oldFi].isDir)
DrawFileIcon(3, FM_TITLE_H+2+oldFi*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+oldFi*FM_ROW_H,GetFileType(fmf.sect[oldFi].filename),0);
DrawHZText12(fmf.sect[oldFi].filename,FM_F_NAME_W/6, FM_F_NAME_X,FM_TITLE_H+2+oldFi*FM_ROW_H, FM_CL_BLACK,0);
if(fmf.sect[oldFi].isDir==0)
{
if(fmf.sect[oldFi].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[oldFi].filesize/1024)/1000,(fmf.sect[oldFi].filesize/1024)%1000);
else if(fmf.sect[oldFi].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[oldFi].filesize/1024);
else if(fmf.sect[oldFi].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[oldFi].filesize/1000,fmf.sect[oldFi].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[oldFi].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr),FM_TITLE_H+2+oldFi*FM_ROW_H, FM_CL_BLACK,0);
}
//高亮显示选中文件
//w = strlen(fmf.sect[newFi].filename)*6+2;
//Clear(FM_F_NAME_X,FM_TITLE_H+1+newFi*FM_ROW_H,w,FM_ROW_H-2,RGB(3,20,20),0);//画阴影
Clear(FM_F_NAME_X,FM_TITLE_H+1+newFi*FM_ROW_H,220-FM_F_NAME_X,FM_ROW_H-2,RGB(3,20,20),0);
if(fmf.sect[newFi].isDir)
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,GetFileType(fmf.sect[newFi].filename),0);
DrawHZText12(fmf.sect[newFi].filename,FM_F_NAME_W/6+8, FM_F_NAME_X,FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BG,0);//写新背景
/*
if(fmf.sect[newFi].isDir==0)
{
if(fmf.sect[newFi].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[newFi].filesize/1024)/1000,(fmf.sect[newFi].filesize/1024)%1000);
else if(fmf.sect[newFi].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[newFi].filesize/1024);
else if(fmf.sect[newFi].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[newFi].filesize/1000,fmf.sect[newFi].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[newFi].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr),FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BLACK,0);
} */
syncVVram();
bscroll = 0;
}
if(bchg)//////////////////////////////////////////////////////////////
{
//刷新选中文件
char FileStr[128];
oldFi = fi-viewfi;
newFi = newfi - viewfi;
////取消高亮文件
u16 w = strlen(fmf.sect[oldFi].filename)*6+2;
DrawPic((u16*)res.res_FILEBG+((fi)%FM_MSN)*FM_ROW_H*240,0,FM_TITLE_H+FM_ROW_H*oldFi,240,FM_ROW_H,0,0,0);
if(fmf.sect[oldFi].isDir)
DrawFileIcon(3, FM_TITLE_H+2+oldFi*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+oldFi*FM_ROW_H,GetFileType(fmf.sect[oldFi].filename),0);
DrawHZText12(fmf.sect[oldFi].filename,FM_F_NAME_W/6, FM_F_NAME_X,FM_TITLE_H+2+oldFi*FM_ROW_H, FM_CL_BLACK,0);
if(fmf.sect[oldFi].isDir==0)
{
if(fmf.sect[oldFi].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[oldFi].filesize/1024)/1000,(fmf.sect[oldFi].filesize/1024)%1000);
else if(fmf.sect[oldFi].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[oldFi].filesize/1024);
else if(fmf.sect[oldFi].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[oldFi].filesize/1000,fmf.sect[oldFi].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[oldFi].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr),FM_TITLE_H+2+oldFi*FM_ROW_H, FM_CL_BLACK,0);
}
////高亮显示选中文件
//w = strlen(fmf.sect[newFi].filename)*6+2;
if(fmf.sect[newFi].isDir)
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,PROC_DIR_VIEW,0);
else
DrawFileIcon(3, FM_TITLE_H+2+newFi*FM_ROW_H,GetFileType(fmf.sect[newFi].filename),0);
Clear(FM_F_NAME_X,FM_TITLE_H+1+newFi*FM_ROW_H,220-FM_F_NAME_X,FM_ROW_H-2,RGB(3,20,20),0);
DrawHZText12(fmf.sect[newFi].filename,FM_F_NAME_W/6+8, FM_F_NAME_X,FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BG,0);
/*
if(fmf.sect[newFi].isDir==0)
{
if(fmf.sect[newFi].filesize>999*1024)
sprintf(FileStr,"%d,%03d KB",(fmf.sect[newFi].filesize/1024)/1000,(fmf.sect[newFi].filesize/1024)%1000);
else if(fmf.sect[newFi].filesize>9999)
sprintf(FileStr,"%d KB",fmf.sect[newFi].filesize/1024);
else if(fmf.sect[newFi].filesize>999)
sprintf(FileStr,"%d,%03d",fmf.sect[newFi].filesize/1000,fmf.sect[newFi].filesize%1000);
else
sprintf(FileStr,"%d",fmf.sect[newFi].filesize);
DrawHZText12(FileStr,FM_F_SIZE_W/6, FM_F_SIZE_X2-6*strlen(FileStr),FM_TITLE_H+2+newFi*FM_ROW_H, FM_CL_BLACK,0);
} */
bchg = 0;
syncVVram();
}
fi=newfi;
if(needfade)
{
FadeInOut(1,0,50);//消雾
needfade=0;
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
glhard = 0 ;
keys.update();
/* if (keys.hold(KEY_L)&&keys.hold(KEY_R)&&keys.hold(KEY_SELECT) )
{
return PROC_EZWORD ;
}
*/
if ( keys.hold(KEY_L) && keys.hold(KEY_R))
{
shift =0 ;
return PROC_WRITESAVEREX ;
/*
FileIndexOfPath[layerIndex]=newfi; //纪录文件焦点
ViewIndexOfPath[layerIndex]=viewfi;
ScreenSaver("ezpdalogo.bmp");
shellflag=SHELL_FLAG_SCR;
bcreate = 1;
needfade = 1;
*/
}
if ( (keys.press(KEY_UP))&&(holdt=ti) || (keys.hold(KEY_UP)&&(ti-holdt>15)) )//向上移动鼠标
{
shift =0 ;
if(fi>0)
{
newfi--;
if(viewfi-newfi>0)
{
//翻屏上移一个文件
viewfi--;
bscroll = 1;
}
else
{
//本屏上移一个文件
bchg = 1;
}
}
CurrentIndexSelect = newfi ;
CurrentIndexView = viewfi ;
}
if ( (keys.press(KEY_DOWN))&&(holdt=ti) || (keys.hold(KEY_DOWN)&&(ti-holdt>15)) )//向下移动鼠标
{
shift =0 ;
if(fi<rfcount-1)
{
newfi++;
if(newfi-viewfi>FM_MSN-1)
{
//翻屏下移一个文件
viewfi++;
bscroll = 1;
}
else
{
//本屏下移一个文件
bchg = 1;
}
}
CurrentIndexSelect = newfi ;
CurrentIndexView = viewfi ;
}
if (keys.press(KEY_LEFT)&&(holdt=ti) )
{//上一页
shift =0 ;
if(fi>0)
{
newfi -= FM_MSN;
if(newfi <0) newfi = 0 ;
if(viewfi-newfi>0)
{
//翻屏上移一个文件
viewfi -= FM_MSN;
if(viewfi <0) viewfi = 0 ;
bcreate = 1;
}
else
{
//本屏上移一个文件
bcreate = 1;
}
CurrentIndexSelect = newfi ;
CurrentIndexView = viewfi ;
}
}
if (keys.press(KEY_RIGHT)&&(holdt=ti) )
{//下一页
shift =0 ;
if(fi<rfcount-1)
{
newfi+= FM_MSN;
if(newfi>rfcount-1) newfi = rfcount-1 ;
if(newfi-viewfi>FM_MSN-1)
{
//翻屏下移一个文件
viewfi+= FM_MSN;
if(viewfi>rfcount -FM_MSN) viewfi = rfcount -FM_MSN ;
bcreate = 1 ;
}
else
{
//本屏下移一个文件
bcreate = 1;
}
CurrentIndexSelect = newfi ;
CurrentIndexView = viewfi ;
}
}
if(keys.press(KEY_SELECT)&&(holdt=ti) )
{
/*blowfish add,modify data 2006-06-01,write gba or nds rom from nand to flash**********************/
DmaCopy(3,&pNorFS[CurrentIndexSelect],&tmpNorFS,sizeof(FM_NOR_FS),32);
if(!strcmp(CurrentPath,"\\"))
sprintf(path,"%s%s",CurrentPath,tmpNorFS.filename);
else
sprintf(path,"%s\\%s",CurrentPath,tmpNorFS.filename);
if(strcmp(CurrentDisk,"EZ-Disk"))
{
if(CurrentIndexSelect==gl_norgamecounter)
{
CreateWindow("","Delete",60,40,1);
while(1){
sleep(5); keys.update();
if(keys.press(KEY_A))
{
break;
}
if(keys.press(KEY_B))
{
sprintf(CurrentDisk,"Game Disk");
CurrentPath[0] = 0 ;
return PROC_ENTERDISKSHELL ;
}
}
OpenWrite();
SetSerialMode();
Block_Erase(gl_norOffset-tmpNorFS.filesize);
CloseWrite();
sprintf(CurrentDisk,"Game Disk");
CurrentPath[0] = 0 ;
return PROC_ENTERDISKSHELL ;
}
}
else
{
if(GetFileType(tmpNorFS.filename)!=PROC_GBA_VIEW)
{
CurrentFileName[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
OpenWrite();
CheckEz4Card();
CloseWrite();
if( (gl_norOffset+tmpNorFS.filesize)>gl_norsize)
{
CreateWindow("Info","Empty is not enough",60,40,1);
while(1){
sleep(5); keys.update();
if(keys.release(KEY_A))
{
//如果选择不写回到当前目录
CurrentFileName[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
}
}
//这里弹出提示是否写NOR Flash的
CreateWindow("","Write NOR Y/N?",60,40,1);
while(1){
sleep(5); keys.update();
if(keys.press(KEY_A))
{
break;
}
if(keys.press(KEY_B))
{
//如果选择不写回到当前目录
CurrentFileName[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
}
OpenWrite();
SetSerialMode();
CreateWindow("Info"," ",60,40,1);
for(j=gl_norOffset;j<(gl_norOffset+tmpNorFS.filesize);j+=0x40000)
{
chip_reset();
sprintf(msg,"Erasing%dMb",(j-gl_norOffset)/0x20000);
Clear(60+54,40+16,62,40,0x7FBB,1);
DrawHZTextRect(msg,0,60+54,40+16,62,56,14,0,2,1); //写消息
Block_Erase(j);
}
CloseWrite();
int hdfile;
get = fat_init(1);
if(get)
{
CreateWindow(gl_warning,gl_faterror,60,40,1);
while(1){
sleep(15); keys.update();
if(keys.press(KEY_A)||keys.release(KEY_B)) break;
}
continue ;
}
hdfile = fat_open(path);
for(i=gl_norOffset;i<(gl_norOffset+tmpNorFS.filesize);i+=0x20000)
{
fat_read(hdfile,pReadCache,0x20000);
OpenWrite();
SetSerialMode();
sprintf(msg,"Writing �%dMb",(i-gl_norOffset)/0x20000);
Clear(60+54,40+16,62,40,0x7FBB,1);
DrawHZTextRect(msg,0,60+54,40+16,62,56,14,0,2,1); //写消息
for(j=0;j<0x20000;j+=0x8000)
WriteEZ4Flash(i+j,pReadCache+j,0x8000);
CloseWrite();
}
fat_close(hdfile);
fat_deinit();
//写中文文件名
OpenWrite();
ldRead(pReadCache,0x10000);
if(gl_norgamecounter==0)
memset(pReadCache,0,0x1000);
for(i=gl_norgamecounter*256;i<(gl_norgamecounter*256+strlen(tmpNorFS.filename));i++)
pReadCache[i] = tmpNorFS.filename[i-gl_norgamecounter*256];
pReadCache[(gl_norgamecounter)*256+strlen(tmpNorFS.filename)]=0;
for(j=(gl_norgamecounter+1)*256;j<0x10000;j++)
{
pReadCache[j]=0;
}
ldWrite(_SRAMSaver,pReadCache,0x1000);
CloseWrite();
CurrentFileName[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
/*blowfish add,modify data 2006-06-01,write gba or nds rom from nand to flash***********************/
}
if ((keys.hold(KEY_A))&&(keys.hold(KEY_L)))
{//硬复位
shift =0 ;
glhard = 1 ;
}
if (keys.release(KEY_A)||glhard||(glExecFileTxt==EXEC_TXT))
{
shift =0 ;
DmaCopy(3,&pNorFS[CurrentIndexSelect],&tmpNorFS,sizeof(FM_NOR_FS),32);
if(strcmp(CurrentDisk,"Game Disk"))
{//不一样 , 在nand中
if(tmpNorFS.savertype == 0x5AA5)
{//dir
if(!strcmp(tmpNorFS.filename,"."))
{
continue ;
}
if(!strcmp(tmpNorFS.filename,".."))
{
if(strcmp(CurrentDisk,"Game Disk"))
{//不一样 , 在nand disk中 ,
if(strcmp(CurrentPath,"\\"))
{//回到上级目录
char *pt = strrchr(CurrentPath,'\\');
pt[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
else
{
sprintf(CurrentDisk,"Game Disk");
CurrentPath[0] = 0 ;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}
}
}
if(strcmp(CurrentPath,"\\"))
strcat(CurrentPath,"\\");
strcat(CurrentPath,tmpNorFS.filename);
CurrentFileName[0]=0;
CurrentIndexSelect = 0 ;
CurrentIndexView = 0 ;
return PROC_ENTERDISKSHELL ;
}